Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEB-770 #2227

Merged
merged 5 commits into from
Apr 25, 2024
Merged

WEB-770 #2227

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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'
)
}

Expand Down
24 changes: 23 additions & 1 deletion packages/viewer/src/modules/World.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box3, Vector3 } from 'three'
import { Box3, Vector3, Matrix4 } from 'three'

export class AsyncPause {
private lastPauseTime: number = 0
Expand All @@ -23,6 +23,10 @@ export class AsyncPause {
export class World {
private readonly boxes: Array<Box3> = new Array<Box3>()
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() {
Expand Down Expand Up @@ -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
}
}
22 changes: 15 additions & 7 deletions packages/viewer/src/modules/extensions/SectionOutlines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/viewer/src/modules/extensions/SectionTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down