diff --git a/packages/viewer-sandbox/src/main.ts b/packages/viewer-sandbox/src/main.ts index 7212906ca..cc790b096 100644 --- a/packages/viewer-sandbox/src/main.ts +++ b/packages/viewer-sandbox/src/main.ts @@ -121,7 +121,7 @@ const getStream = () => { // prettier-ignore // 'https://speckle.xyz/streams/da9e320dad/commits/5388ef24b8?c=%5B-7.66134,10.82932,6.41935,-0.07739,-13.88552,1.8697,0,1%5D' // Revit sample house (good for bim-like stuff with many display meshes) - 'https://speckle.xyz/streams/da9e320dad/commits/5388ef24b8' + // 'https://speckle.xyz/streams/da9e320dad/commits/5388ef24b8' // 'https://latest.speckle.dev/streams/58b5648c4d/commits/60371ecb2d' // 'Super' heavy revit shit // 'https://speckle.xyz/streams/e6f9156405/commits/0694d53bb5' @@ -141,7 +141,7 @@ const getStream = () => { // AutoCAD NEW // 'https://latest.speckle.dev/streams/3ed8357f29/commits/46905429f6' //Blizzard world - // 'https://latest.speckle.dev/streams/0c6ad366c4/commits/aa1c393aec' + 'https://latest.speckle.dev/streams/0c6ad366c4/commits/aa1c393aec' //Car // 'https://latest.speckle.dev/streams/17d2e25a97/commits/6b6cf3d43e' // Jonathon's @@ -386,6 +386,9 @@ const getStream = () => { // 'https://latest.speckle.dev/streams/a64b432b34/commits/99d809460a' // Bunch a doors // 'https://latest.speckle.dev/streams/a64b432b34/commits/c184ba7d88' + // 'https://speckle.xyz/streams/8f73d360e7/commits/2cb768cecd' + // Tiny cube + // 'https://speckle.xyz/streams/8f73d360e7/commits/2cb768cecd' ) } diff --git a/packages/viewer/src/modules/World.ts b/packages/viewer/src/modules/World.ts index f4e4f8533..804a18c12 100644 --- a/packages/viewer/src/modules/World.ts +++ b/packages/viewer/src/modules/World.ts @@ -1,4 +1,4 @@ -import { Box3, Vector3 } from 'three' +import { Box3, Vector3, Matrix4 } from 'three' export class AsyncPause { private lastPauseTime: number = 0 @@ -23,6 +23,10 @@ export class AsyncPause { export class World { private readonly boxes: Array = new Array() public readonly worldBox: Box3 = new Box3() + private readonly VecBuff: Vector3 = new Vector3() + private readonly BoxBuff0: Box3 = new Box3() + private readonly BoxBuff1: Box3 = new Box3() + private readonly MatBuff: Matrix4 = new Matrix4() private _worldOrigin: Vector3 = new Vector3() public get worldSize() { @@ -60,4 +64,22 @@ export class World { this.worldBox.makeEmpty() this.boxes.length = 0 } + + public getRelativeOffset(offsetAmount: number = 0.001): number { + this.MatBuff.identity() + this.MatBuff.makeScale(1 + offsetAmount, 1 + offsetAmount, 1 + offsetAmount) + const worldSize = this.VecBuff.set( + this.worldSize.x * 0.5, + this.worldSize.y * 0.5, + this.worldSize.z * 0.5 + ) + this.BoxBuff0.min.set(0, 0, 0) + this.BoxBuff0.max.set(0, 0, 0) + this.BoxBuff1.min.set(0, 0, 0) + this.BoxBuff1.max.set(0, 0, 0) + const sizeBox = this.BoxBuff0.expandByVector(worldSize) + const offsetBox = this.BoxBuff1.copy(sizeBox).applyMatrix4(this.MatBuff) + const dist = offsetBox.max.distanceTo(sizeBox.max) + return dist + } } diff --git a/packages/viewer/src/modules/extensions/SectionOutlines.ts b/packages/viewer/src/modules/extensions/SectionOutlines.ts index b9e6cdbff..2a7abe199 100644 --- a/packages/viewer/src/modules/extensions/SectionOutlines.ts +++ b/packages/viewer/src/modules/extensions/SectionOutlines.ts @@ -39,8 +39,8 @@ export class SectionOutlines extends Extension { public get inject() { return [SectionTool] } + private static readonly OUTLINE_Z_OFFSET = 0.0001 private static readonly INITIAL_BUFFER_SIZE = 60000 // Must be a multiple of 6 - private static readonly Z_OFFSET = -0.001 private tmpVec: Vector3 = new Vector3() private tmpVec2: Vector3 = new Vector3() @@ -117,7 +117,11 @@ export class SectionOutlines extends Extension { } } - private updatePlaneOutline(batches: MeshBatch[], _plane: Plane) { + private updatePlaneOutline( + batches: MeshBatch[], + _plane: Plane, + outlineOffset: number + ) { const tempVector = new Vector3() const tempVector1 = new Vector3() const tempVector2 = new Vector3() @@ -170,7 +174,7 @@ export class SectionOutlines extends Extension { tempLine.end.copy(tri.b) if (localPlane.intersectLine(tempLine, tempVector)) { tempVector.add( - tempVector4.copy(plane.normal).multiplyScalar(SectionOutlines.Z_OFFSET) + tempVector4.copy(plane.normal).multiplyScalar(-outlineOffset) ) scratchBuffer[index * 3] = tempVector.x scratchBuffer[index * 3 + 1] = tempVector.y @@ -182,7 +186,7 @@ export class SectionOutlines extends Extension { tempLine.end.copy(tri.c) if (localPlane.intersectLine(tempLine, tempVector)) { tempVector.add( - tempVector4.copy(plane.normal).multiplyScalar(SectionOutlines.Z_OFFSET) + tempVector4.copy(plane.normal).multiplyScalar(-outlineOffset) ) scratchBuffer[index * 3] = tempVector.x scratchBuffer[index * 3 + 1] = tempVector.y @@ -194,7 +198,7 @@ export class SectionOutlines extends Extension { tempLine.end.copy(tri.a) if (localPlane.intersectLine(tempLine, tempVector)) { tempVector.add( - tempVector4.copy(plane.normal).multiplyScalar(SectionOutlines.Z_OFFSET) + tempVector4.copy(plane.normal).multiplyScalar(-outlineOffset) ) scratchBuffer[index * 3] = tempVector.x scratchBuffer[index * 3 + 1] = tempVector.y @@ -228,7 +232,7 @@ export class SectionOutlines extends Extension { // Set the penultimate point as a distinct point and delete the last point tempVector3.set(tempVector.x, tempVector.y, tempVector.z) tempVector3.add( - tempVector4.copy(plane.normal).multiplyScalar(SectionOutlines.Z_OFFSET) + tempVector4.copy(plane.normal).multiplyScalar(-outlineOffset) ) scratchBuffer[(index - 2) * 3] = tempVector3.x scratchBuffer[(index - 2) * 3 + 1] = tempVector3.y @@ -340,12 +344,16 @@ export class SectionOutlines extends Extension { private updateOutlines(planes: Plane[]) { const start = performance.now() + const outlineOffset = this.viewer.World.getRelativeOffset( + SectionOutlines.OUTLINE_Z_OFFSET + ) for (let k = 0; k < planes.length; k++) { this.updatePlaneOutline( this.viewer .getRenderer() .batcher.getBatches(undefined, GeometryType.MESH) as MeshBatch[], - planes[k] + planes[k], + outlineOffset ) } this.enabled = this.sectionProvider.enabled diff --git a/packages/viewer/src/modules/extensions/SectionTool.ts b/packages/viewer/src/modules/extensions/SectionTool.ts index 2d5517e1a..561daa942 100644 --- a/packages/viewer/src/modules/extensions/SectionTool.ts +++ b/packages/viewer/src/modules/extensions/SectionTool.ts @@ -430,6 +430,10 @@ export class SectionTool extends Extension { box = new Box3(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)) } + if (offset === 0) { + offset = this.viewer.World.getRelativeOffset() + } + const x1 = box.min.x - (box.max.x - box.min.x) * offset const y1 = box.min.y - (box.max.y - box.min.y) * offset const z1 = box.min.z - (box.max.z - box.min.z) * offset