Skip to content

Commit

Permalink
The bounds to check against when intersecting the scene is now being …
Browse files Browse the repository at this point in the history
…properly expanded and 0 sized component bounds are being taken care of (#3450)
  • Loading branch information
AlexandruPopovici authored Nov 7, 2024
1 parent 1acc6fd commit a48ec07
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
}

Expand Down
11 changes: 2 additions & 9 deletions packages/viewer/src/modules/Intersections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) ||
Expand Down
27 changes: 27 additions & 0 deletions packages/viewer/src/modules/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit a48ec07

Please sign in to comment.