* WIP on computing a general purpose relative offset

* Implemented a size-invariant way of getting relative offsets that relies on the world size for the offset value

* Relative offset is now calculated based on relative size instead if world bounds. This makes it work correctly for streams with small far away from origin objects
This commit is contained in:
Alexandru Popovici
2024-04-25 15:48:18 +03:00
committed by GitHub
parent 9b93a5a944
commit ab56bc1abc
4 changed files with 47 additions and 10 deletions
+5 -2
View File
@@ -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'
)
}
+23 -1
View File
@@ -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<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() {
@@ -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
}
}
@@ -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
@@ -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