From 6a5f7bb031669bbd4a543fd94961dfb36b33babf Mon Sep 17 00:00:00 2001 From: Alexandru Popovici Date: Wed, 7 Feb 2024 23:29:05 +0200 Subject: [PATCH] Added a default null text material to Materials. TextBatch now returns correct bounds (#2016) --- packages/viewer-sandbox/src/main.ts | 5 +++- .../viewer/src/modules/batching/TextBatch.ts | 2 +- .../viewer/src/modules/materials/Materials.ts | 26 ++++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/viewer-sandbox/src/main.ts b/packages/viewer-sandbox/src/main.ts index 9232fd360c..cb5cd45e41 100644 --- a/packages/viewer-sandbox/src/main.ts +++ b/packages/viewer-sandbox/src/main.ts @@ -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' ) } diff --git a/packages/viewer/src/modules/batching/TextBatch.ts b/packages/viewer/src/modules/batching/TextBatch.ts index e640ec1d55..98a8c0de33 100644 --- a/packages/viewer/src/modules/batching/TextBatch.ts +++ b/packages/viewer/src/modules/batching/TextBatch.ts @@ -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 { diff --git a/packages/viewer/src/modules/materials/Materials.ts b/packages/viewer/src/modules/materials/Materials.ts index 1d4ad1d5a2..09751cc4f2 100644 --- a/packages/viewer/src/modules/materials/Materials.ts +++ b/packages/viewer/src/modules/materials/Materials.ts @@ -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() ) @@ -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) } @@ -533,6 +538,21 @@ export default class Materials { ;(this.materialMap[hash]).pixelThreshold = 0.5 ;(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, @@ -699,7 +719,7 @@ export default class Materials { mat.toneMapped = false mat.color.convertSRGBToLinear() - return mat.getDerivedMaterial() + return mat } public getMaterial( @@ -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(