The bounds to check against when intersecting the scene is now being properly expanded and 0 sized component bounds are being taken care of (#3450)

This commit is contained in:
Alexandru Popovici
2024-11-07 09:55:27 +02:00
committed by GitHub
parent 1acc6fde66
commit a48ec073a1
3 changed files with 32 additions and 9 deletions
+3
View File
@@ -447,6 +447,9 @@ const getStream = () => {
// Far away house section tool
// 'https://app.speckle.systems/projects/817c4e8daa/models/f0601ef5f9@80db5ff26a'
// Perfectly flat
// 'https://app.speckle.systems/projects/344f803f81/models/5582ab673e'
)
}
+2 -9
View File
@@ -17,6 +17,7 @@ import {
SpeckleRaycaster
} from './objects/SpeckleRaycaster.js'
import { ObjectLayers } from '../IViewer.js'
import { World } from './World.js'
export class Intersections {
protected raycaster: SpeckleRaycaster
@@ -197,21 +198,13 @@ export class Intersections {
return a.distance - b.distance
})
if (bounds) {
this.boundsBuffer.copy(bounds)
/** We slightly increase the tested bounds to account for fp precision issues which
* have proven to arise exactly at the edge of the bounds. Our BVH returns intersection
* points ever so slightly off the actual surface, so for very thin geometries it might
* fall outside of the bounds
*/
const offsetSize = new Vector3(
0.001 * (this.boundsBuffer.max.x - this.boundsBuffer.min.x),
0.001 * (this.boundsBuffer.max.y - this.boundsBuffer.min.y),
0.001 * (this.boundsBuffer.max.z - this.boundsBuffer.min.z)
)
this.boundsBuffer.copy(World.expandBoxRelative(bounds))
this.boundsBuffer.expandByVector(
new Vector3(offsetSize.x, offsetSize.y, offsetSize.z)
)
results = results.filter((result) => {
return (
this.boundsBuffer.containsPoint(result.point) ||
+27
View File
@@ -98,4 +98,31 @@ export class World {
offsetBox.applyMatrix4(MatBuff1)
return offsetBox
}
public static expandBoxRelative(box: Box3, offsetAmount: number = 0.001) {
const center = box.getCenter(new Vector3())
const size = box.getSize(new Vector3())
MatBuff1.makeTranslation(center.x, center.y, center.z)
MatBuff2.copy(MatBuff1).invert()
MatBuff0.identity()
MatBuff0.makeScale(1 + offsetAmount, 1 + offsetAmount, 1 + offsetAmount)
const offsetBox = new Box3().copy(box)
if (size.x === 0) {
offsetBox.min.x += -offsetAmount * 0.5
offsetBox.max.x += offsetAmount * 0.5
}
if (size.y === 0) {
offsetBox.min.y += -offsetAmount * 0.5
offsetBox.max.y += offsetAmount * 0.5
}
if (size.z === 0) {
offsetBox.min.z += -offsetAmount * 0.5
offsetBox.max.z += offsetAmount * 0.5
}
offsetBox.applyMatrix4(MatBuff2)
offsetBox.applyMatrix4(MatBuff0)
offsetBox.applyMatrix4(MatBuff1)
return offsetBox
}
}