Skip to content

Commit

Permalink
Added a default null text material to Materials. TextBatch now return…
Browse files Browse the repository at this point in the history
…s correct bounds (specklesystems#2016)
  • Loading branch information
AlexandruPopovici authored Feb 7, 2024
1 parent 666aa2d commit 6a5f7bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ const getStream = () => {
// 'https://latest.speckle.dev/streams/ee5346d3e1/commits/489d42ca8c'
// 'https://latest.speckle.dev/streams/97750296c2/objects/11a7752e40b4ef0620affc55ce9fdf5a'

// 'https://latest.speckle.dev/streams/92b620fb17/objects/7118603b197c00944f53be650ce721ec'
// Text and Dimensions
'https://latest.speckle.dev/streams/3f895e614f/commits/fbc78286c9'
// 'https://latest.speckle.dev/streams/55cc1cbf0a/commits/aa72674507'
// 'https://latest.speckle.dev/streams/55cc1cbf0a/commits/a7f74b6524'
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/viewer/src/modules/batching/TextBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class TextBatch implements Batch {
public mesh: SpeckleText

public get bounds(): Box3 {
return new Box3() //this.mesh.BVH.getBoundingBox(new Box3())
return new Box3().setFromObject(this.mesh)
}

public get drawCalls(): number {
Expand Down
26 changes: 23 additions & 3 deletions packages/viewer/src/modules/materials/Materials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export default class Materials {
private static readonly NullDisplayStyleHash = this.hashCode(
GeometryType.LINE.toString()
)
private static readonly NullTextDisplayStyle = this.hashCode(
GeometryType.TEXT.toString()
)
private static readonly NullPointMaterialHash = this.hashCode(
GeometryType.POINT.toString()
)
Expand Down Expand Up @@ -242,7 +245,9 @@ export default class Materials {
renderView.geometryType.toString() +
geometry +
mat +
(renderView.geometryType === GeometryType.TEXT ? renderView.renderData.id : '') +
(renderView.geometryType === GeometryType.TEXT && materialData
? renderView.renderData.id
: '') +
(renderView.renderData.geometry.instanced ? 'instanced' : '')
return Materials.hashCode(s)
}
Expand Down Expand Up @@ -533,6 +538,21 @@ export default class Materials {
;(<SpeckleLineMaterial>this.materialMap[hash]).pixelThreshold = 0.5
;(<SpeckleLineMaterial>this.materialMap[hash]).resolution = new Vector2()

this.materialMap[Materials.NullTextDisplayStyle] = new SpeckleTextMaterial(
{
color: 0x7f7f7f,
opacity: 1,
side: DoubleSide
},
['USE_RTE']
)
this.materialMap[Materials.NullTextDisplayStyle].transparent = false
this.materialMap[Materials.NullTextDisplayStyle].depthWrite = true
this.materialMap[Materials.NullTextDisplayStyle].toneMapped = false
;(
this.materialMap[Materials.NullTextDisplayStyle] as SpeckleTextMaterial
).color.convertSRGBToLinear()

this.materialMap[Materials.NullPointMaterialHash] = new SpecklePointMaterial(
{
color: 0x7f7f7f,
Expand Down Expand Up @@ -699,7 +719,7 @@ export default class Materials {
mat.toneMapped = false
mat.color.convertSRGBToLinear()

return mat.getDerivedMaterial()
return mat
}

public getMaterial(
Expand Down Expand Up @@ -766,7 +786,7 @@ export default class Materials {
if (!this.materialMap[hash]) {
this.materialMap[hash] = this.makeTextMaterial(material as DisplayStyle)
}
return this.materialMap[hash]
return (this.materialMap[hash] as SpeckleTextMaterial).getDerivedMaterial()
}

public getGhostMaterial(
Expand Down

0 comments on commit 6a5f7bb

Please sign in to comment.