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

v0.4.0 changes #205

Merged
merged 163 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
6eb35ac
Fix changelog
gkjohnson Mar 1, 2021
59ae260
Delete generateAsync.js
gkjohnson Mar 1, 2021
89f5562
Merge pull request #195 from gkjohnson/remove-generate-async
gkjohnson Mar 1, 2021
843a426
Update CHANGELOG.md
gkjohnson Mar 1, 2021
65c4584
Update MeshBVH.js
gkjohnson Mar 2, 2021
cfec46a
Update buildFunctions.js
gkjohnson Mar 2, 2021
9a82957
Update castFunctions.js
gkjohnson Mar 2, 2021
7499920
Update README.md
gkjohnson Mar 2, 2021
0552efa
Update Debug.js
gkjohnson Mar 2, 2021
f5d41ab
Update MeshBVH.js
gkjohnson Mar 2, 2021
e4c89df
use type: module
gkjohnson Mar 2, 2021
934d35d
Update CHANGELOG.md
gkjohnson Mar 2, 2021
1e70de6
Update CHANGELOG.md
gkjohnson Mar 2, 2021
e6b4984
Update CHANGELOG.md
gkjohnson Mar 2, 2021
813346b
Update node.js.yml
gkjohnson Mar 2, 2021
11f8d11
Fix cast function generation
gkjohnson Mar 2, 2021
6fbecbf
Revert "Fix cast function generation"
gkjohnson Mar 2, 2021
f4ba422
fix buffer functions
gkjohnson Mar 2, 2021
3b11703
fix configs
gkjohnson Mar 2, 2021
837da0b
Merge branch 'type-module' of github.com:gkjohnson/three-mesh-bvh int…
gkjohnson Mar 2, 2021
9bb84e5
Merge pull request #197 from gkjohnson/type-module
gkjohnson Mar 2, 2021
e671802
Merge remote-tracking branch 'origin/master' into remove-lazy-generation
gkjohnson Mar 2, 2021
a13662b
Update README.md
gkjohnson Mar 2, 2021
65cc923
Remove lazyGeneration flags from tests
gkjohnson Mar 2, 2021
6abc8de
remove obsolete tests
gkjohnson Mar 2, 2021
785f991
Remove more lazyGeneration references from tests
gkjohnson Mar 2, 2021
4810c6b
Fix buffer functions
gkjohnson Mar 2, 2021
3b15327
Update benchmark
gkjohnson Mar 2, 2021
a813614
Merge pull request #196 from gkjohnson/remove-lazy-generation
gkjohnson Mar 2, 2021
a67e0e9
Remove support for the non packed bvh option
gkjohnson Mar 2, 2021
eca9514
Remove generate cast function
gkjohnson Mar 2, 2021
c38fbc9
Update CHANGELOG.md
gkjohnson Mar 2, 2021
ab0381f
Update README.md
gkjohnson Mar 2, 2021
23bc84e
Separate buffer packing logic
gkjohnson Mar 2, 2021
b899264
Remove tests reliant on packed data
gkjohnson Mar 2, 2021
0503250
Remove packData references from tests
gkjohnson Mar 2, 2021
3cb0689
Clean up cast functions
gkjohnson Mar 2, 2021
a138d6a
Add cast function generation
gkjohnson Mar 4, 2021
9bd40fe
lint fix
gkjohnson Mar 4, 2021
d6267cd
Fix tests
gkjohnson Mar 4, 2021
632a643
Merge pull request #204 from gkjohnson/templatized-cast-functions
gkjohnson Mar 4, 2021
6b0ba86
Merge branch 'master' into remove-non-packed-option
gkjohnson Mar 4, 2021
016c4f5
strideOffset -> nodeIndex
gkjohnson Mar 4, 2021
773b8ed
regenerate cast functions
gkjohnson Mar 4, 2021
ab32007
comments
gkjohnson Mar 4, 2021
a583d73
Merge pull request #201 from gkjohnson/remove-non-packed-option
gkjohnson Mar 4, 2021
e8b6aa7
Add sculpt demo
gkjohnson Mar 4, 2021
6408091
add initial refit function
gkjohnson Mar 4, 2021
13452bf
Fix refit function
gkjohnson Mar 5, 2021
5aff1db
Add error if the buffer gets too big
gkjohnson Mar 5, 2021
c6af24f
sculpt update
gkjohnson Mar 5, 2021
7270396
refit benchmark
gkjohnson Mar 5, 2021
02481a8
comments
gkjohnson Mar 5, 2021
ae9ac63
Remove `Buffer` from cast function names
gkjohnson Mar 5, 2021
5e77273
Update README.md
gkjohnson Mar 5, 2021
3d1e81c
update sculpt brush
gkjohnson Mar 5, 2021
a6d8a8f
Update CHANGELOG.md
gkjohnson Mar 5, 2021
c5a67d0
remove wireframe
gkjohnson Mar 5, 2021
007c32e
Merge branch 'dev-v0.4.0' of github.com:gkjohnson/three-mesh-bvh into…
gkjohnson Mar 5, 2021
44def87
add sculpt build
gkjohnson Mar 5, 2021
781d4ce
title
gkjohnson Mar 5, 2021
b6a1324
Merge branch 'dev-v0.4.0' of github.com:gkjohnson/three-mesh-bvh into…
gkjohnson Mar 5, 2021
e6645e8
Improve sculpt brush
gkjohnson Mar 5, 2021
c70ca7f
improve brush
gkjohnson Mar 5, 2021
6e30e1e
Improve bvh visualizer
gkjohnson Mar 5, 2021
fc95b9a
Update CHANGELOG.md
gkjohnson Mar 5, 2021
0e610c4
add cast distance check
gkjohnson Mar 6, 2021
bd1f9ef
Multiple brush steps
gkjohnson Mar 6, 2021
7bb2323
Merge branch 'dev-v0.4.0' of github.com:gkjohnson/three-mesh-bvh into…
gkjohnson Mar 6, 2021
211a353
comments
gkjohnson Mar 6, 2021
ef61af8
update
gkjohnson Mar 6, 2021
7ac7810
Add LGTM classification
gkjohnson Mar 6, 2021
d6f9f83
fix brushes
gkjohnson Mar 6, 2021
4a59a41
spaces to tabs
gkjohnson Mar 6, 2021
57afdb5
comment
gkjohnson Mar 6, 2021
646f5ec
Updates
gkjohnson Mar 6, 2021
b86cae1
comment
gkjohnson Mar 6, 2021
a63884d
more tabs to spaces
gkjohnson Mar 6, 2021
b6b88b3
Merge remote-tracking branch 'origin/master' into dev-v0.4.0
gkjohnson Mar 6, 2021
244e1c0
sculpt update
gkjohnson Mar 6, 2021
c1eb85a
lint fix
gkjohnson Mar 6, 2021
e33b0b7
update lgtm yml
gkjohnson Mar 6, 2021
28a8e1e
Merge remote-tracking branch 'origin/master' into dev-v0.4.0
gkjohnson Mar 6, 2021
0b74ba6
better sculpting, multiple steps
gkjohnson Mar 7, 2021
317c146
Add symmetry option
gkjohnson Mar 7, 2021
80f0989
Update build
gkjohnson Mar 7, 2021
769cacc
Update settings
gkjohnson Mar 8, 2021
461a727
improve normal generation
gkjohnson Mar 8, 2021
c6a5670
simplify triangles
gkjohnson Mar 8, 2021
f8052e0
improve sculpt performance / correctness
gkjohnson Mar 8, 2021
21a6a29
Separate normals update
gkjohnson Mar 8, 2021
e192656
Only update the normals once
gkjohnson Mar 8, 2021
10a0604
Merge remote-tracking branch 'origin/master' into dev-v0.4.0
gkjohnson Mar 8, 2021
ec578a6
Remove ability to shapecast triangle function to be null
gkjohnson Mar 8, 2021
5371351
update cast functions
gkjohnson Mar 8, 2021
397e0fe
build
gkjohnson Mar 8, 2021
1ef789e
add necessary quotes to lgtm.yml
gkjohnson Mar 8, 2021
2e4bf9f
Update CHANGELOG.md
gkjohnson Mar 8, 2021
f70c328
retain buffer references
gkjohnson Mar 9, 2021
1beea65
Fix all cast functions
gkjohnson Mar 9, 2021
cb142e5
README update
gkjohnson Mar 9, 2021
1fe41a2
Merge pull request #221 from gkjohnson/retain-buffers
gkjohnson Mar 9, 2021
cf6564b
Update comments
gkjohnson Mar 9, 2021
1467598
Add bounding box benchmark
gkjohnson Mar 9, 2021
62bd707
Add getBoundingBox function
gkjohnson Mar 10, 2021
d12e1f5
Create the bounding box from MeshBVH Worker
gkjohnson Mar 10, 2021
efd2b4d
CHANGELOG, README update, benchmark update
gkjohnson Mar 10, 2021
4fe248c
Add tests, update castFunctions
gkjohnson Mar 10, 2021
77f6c3e
sculpt update
gkjohnson Mar 10, 2021
08b196c
README update
gkjohnson Mar 10, 2021
53af38a
benchmark spacing
gkjohnson Mar 10, 2021
e42dfc9
Merge pull request #223 from gkjohnson/get-bounding-shape-functions
gkjohnson Mar 10, 2021
b4f96dd
fix variable naming
gkjohnson Mar 10, 2021
925355d
Add missing file
gkjohnson Mar 10, 2021
7cc9903
build
gkjohnson Mar 10, 2021
3af4c26
new shapecast signature
gkjohnson Mar 10, 2021
dac9890
Add callback object
gkjohnson Mar 11, 2021
b618d1f
Enable testing
gkjohnson Mar 11, 2021
0b9cb2f
Update import
gkjohnson Mar 11, 2021
c47ca1a
Remove sqrt calls from closest point to point
gkjohnson Mar 11, 2021
a92d62a
Fix bounds
gkjohnson Mar 11, 2021
d7ecd9b
Update geometry intersect function
gkjohnson Mar 11, 2021
c144c16
Fix tests
gkjohnson Mar 11, 2021
74742bf
fix cast functions
gkjohnson Mar 11, 2021
9dc9013
README update, warning
gkjohnson Mar 11, 2021
00ea880
Update tests
gkjohnson Mar 11, 2021
0687d97
Update examples
gkjohnson Mar 11, 2021
5e567fa
enable touch
gkjohnson Mar 11, 2021
a8d0142
Enable touch support for sculpt example
gkjohnson Mar 11, 2021
5e5d128
build update
gkjohnson Mar 11, 2021
11d3385
Add refit test
gkjohnson Mar 11, 2021
2785067
Update package.json
gkjohnson Mar 11, 2021
d4d0d46
Merge pull request #228 from gkjohnson/shapecast-update
gkjohnson Mar 11, 2021
b3e0cfb
Update CHANGELOG.md
gkjohnson Mar 11, 2021
4467e26
fix bvh helper performance
gkjohnson Mar 12, 2021
124a83a
Update intersectTriangle signature
gkjohnson Mar 12, 2021
6e208e9
Fix tests
gkjohnson Mar 12, 2021
9b3fc98
README, CHANGELOG update
gkjohnson Mar 12, 2021
6cc6e09
fix examples
gkjohnson Mar 12, 2021
06891e4
Merge pull request #230 from gkjohnson/shapecast-index
gkjohnson Mar 12, 2021
d1078b1
Pass through node indices
gkjohnson Mar 12, 2021
7655e84
README update
gkjohnson Mar 12, 2021
8dd5263
update benchmark
gkjohnson Mar 12, 2021
b03b8f3
Add more optimal refit, add benchmark
gkjohnson Mar 13, 2021
83b3988
refit update
gkjohnson Mar 13, 2021
0dc0478
README update, fix collect triangles brush
gkjohnson Mar 13, 2021
7b04f03
sculpt example fast refit
gkjohnson Mar 13, 2021
5027285
Fix shapecast
gkjohnson Mar 13, 2021
8527f67
Merge pull request #231 from gkjohnson/node-index-update
gkjohnson Mar 13, 2021
ba464b8
npm run build
gkjohnson Mar 13, 2021
964b557
Merge branch 'master' into dev-v0.4.0
gkjohnson May 13, 2021
bc110c2
Add node index byte offset
gkjohnson May 13, 2021
7b0aadd
update variable name
gkjohnson May 13, 2021
ed309d2
Run build
gkjohnson May 13, 2021
388d66d
Merge remote-tracking branch 'origin/master' into dev-v0.4.0
gkjohnson May 20, 2021
fee34e0
move umd and esm builds to /build
gkjohnson May 20, 2021
002c939
Merge branch 'master' into dev-v0.4.0
gkjohnson May 20, 2021
7d47541
Merge branch 'dev-v0.4.0' of github.com:gkjohnson/three-mesh-bvh into…
gkjohnson May 21, 2021
7c51e2a
Merge remote-tracking branch 'origin' into dev-v0.4.0
gkjohnson May 21, 2021
425531b
update
gkjohnson May 21, 2021
0d8b9d5
npm run build
gkjohnson May 21, 2021
83729d5
remove lazy generation flag
gkjohnson May 22, 2021
080ff1e
npm run build
gkjohnson May 22, 2021
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
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ master, dev-v0.4.0 ]

jobs:
build:
Expand All @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [14.x]

steps:
- uses: actions/checkout@v2
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- `MeshBVH.refit` function to refit the bounds to modified vertices.
- `setBoundingBox` MeshBVH construction option.
- `MeshBVH.getBoundingBox` function.
- `intersectsRange` callback option to `MeshBVH.shapecast`.

### Changed
- Removed `src/worker/generateAsync.js` function. Use `GenerateMeshBVHWorker` instead.
- Use `type: module` in package.json to enable use of es6 modules in node.
- Add `sideEffects: false` to package.json.
- Remove ability to generate an unpacked BVH.
- Improved "closestPointToPoint" performance slightly.
- `MeshBVH.shapecast` to take an object of callback functions instead of a list of function arguments and the triangle intersection callback has been changed to take a single triangle index. See README for new API. Calls using the old function will log a warning.

### Fixed
- `MeshBVHVisualizer` not using the new geometry BVH if one was generated.
- `MeshBVHVisualizer` not using the new mesh if it was set.
- Case where passing in null `intersectsTriangleFunc` to `MeshBVH.shapecast` could throw an error.
- Case where the buffer being raycast against was not cleared correctly if a BVH had multiple roots.

## [0.3.7] - 2021-03-06
### Fixed
- Include built umd file including v0.3.6 changes.
Expand Down
178 changes: 136 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Casting 500 rays against an 80,000 polygon model at 60fps!

[Shape intersection demo](https://gkjohnson.github.io/three-mesh-bvh/example/bundle/shapecast.html)

[Sculpting demo](https://gkjohnson.github.io/three-mesh-bvh/example/bundle/sculpt.html)

[Triangle painting demo](https://gkjohnson.github.io/three-mesh-bvh/example/bundle/collectTriangles.html)

[Distance comparison demo](https://gkjohnson.github.io/three-mesh-bvh/example/bundle/distancecast.html)
Expand Down Expand Up @@ -48,8 +50,8 @@ THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree;
THREE.Mesh.prototype.raycast = acceleratedRaycast;

// Generate geometry and associated BVH
const geom = new THREE.TorusKnotBufferGeometry(10, 3, 400, 100);
const mesh = new THREE.Mesh(geom, material);
const geom = new THREE.TorusKnotBufferGeometry( 10, 3, 400, 100 );
const mesh = new THREE.Mesh( geom, material );
geom.computeBoundsTree();
```

Expand Down Expand Up @@ -97,7 +99,7 @@ const invMat = new THREE.Matrix4();

// ...

const bvh = new MeshBVH( geometry, { lazyGeneration: false } );
const bvh = new MeshBVH( geometry );
invMat.copy( mesh.matrixWorld ).invert();

// raycasting
Expand Down Expand Up @@ -126,6 +128,8 @@ geometry.boundsTree = deserializedBVH;

## Asynchronous Generation

_NOTE WebWorker syntax is inconsistently supported across bundlers and sometimes not supported at all so the GenereateMeshBVHWorker class is not exported from the package root. If needed the code from `src/worker` can be copied and modified to accomodate a particular build process._

```js
import { GenerateMeshBVHWorker } from 'three-mesh-bvh/src/workers/GenerateMeshBVHWorker.js';

Expand Down Expand Up @@ -208,7 +212,7 @@ _NOTE: The returned MeshBVH is a fully generated, buffer packed BVH instance to
constructor( geometry : BufferGeometry, options : Object )
```

Constructs the bounds tree for the given geometry and produces a new index attribute buffer. The available options are
Constructs the bounds tree for the given geometry and produces a new index attribute buffer. A reference to the passed geometry is retained. The available options are

```js
{
Expand All @@ -223,19 +227,13 @@ Constructs the bounds tree for the given geometry and produces a new index attri
// The number of triangles to aim for in a leaf node.
maxLeafTris: 10,

// If true then the bounding box for the geometry is set once the BVH
// has been constructed.
setBoundingBox: true,

// Print out warnings encountered during tree construction.
verbose: true,

// If true the bounds tree is generated progressively as the tree is used allowing
// for a fast initialization time and memory allocation as needed but a higher memory
// footprint once the tree is completed. The initial raycasts are also slower until the
// tree is built up.
// If false then the bounds tree will be completely generated up front and packed into
// an array buffer for a lower final memory footprint and long initialization time.
// Note that this will keep intermediate buffers needed for generation in scope until
// the tree has been fully generated.
lazyGeneration: true

}
```

Expand Down Expand Up @@ -329,38 +327,112 @@ If a point is found that is closer than `minThreshold` then the function will re
shapecast(
mesh : Mesh,

intersectsBoundsFunc : (
box : Box3,
isLeaf : Boolean,
score : Number | undefined,
depth : Number
) => NOT_INTERSECTED | INTERSECTED | CONTAINED,

intersectsTriangleFunc : (
triangle : Triangle,
index1 : Number,
index2 : Number,
index3 : Number,
contained : Boolean,
depth : Number
) => Boolean = null,

orderNodesFunc : (
box: Box3
) => Number = null
callbacks : {

traverseBoundsOrder : (
box: Box3
) => Number = null,

intersectsBounds : (
box : Box3,
isLeaf : Boolean,
score : Number | undefined,
depth : Number,
nodeIndex : Number
) => NOT_INTERSECTED | INTERSECTED | CONTAINED,

intersectsRange : (
triangleOffset : Number,
triangleCount : Number
contained : Boolean,
depth : Number,
nodeIndex : Number
) => Boolean = null,

intersectsTriangle : (
triangle : Triangle,
triangleIndex : Number,
contained : Boolean,
depth : Number
) => Boolean = null,

}

) : Boolean
```

A generalized cast function that can be used to implement intersection logic for custom shapes. This is used internally for [intersectsBox](#intersectsBox) and [intersectsSphere](#intersectsSphere). The function returns as soon as a triangle has been reported as intersected and returns `true` if a triangle has been intersected. The bounds are traversed in depth first order calling `orderNodesFunc`, `intersectsBoundsFunc` and `intersectsTrianglesFunc` for each node and using the results to determine traversal depth. The `depth` value passed to `intersectsBoundsFunc` and `intersectsTriangleFunc` indicates the depth of the bounds the provided box or bounds belongs to unless the triangles are indicated to be `CONTAINED`, in which case depth is the depth of the parent bounds that were contained. It can be used to precompute, cache, and then read information about a parent bound to improve performance while traversing.
A generalized cast function that can be used to implement intersection logic for custom shapes. This is used internally for [intersectsBox](#intersectsBox) and [intersectsSphere](#intersectsSphere). The function returns as soon as a triangle has been reported as intersected and returns `true` if a triangle has been intersected. The bounds are traversed in depth first order calling `traverseBoundsOrder`, `intersectsBoundsFunc`, `intersectsRange`, and intersectsTriangle for each node and using the results to determine traversal depth. The `depth` value passed to callbacks indicates the depth of the bounds the provided box or bounds belongs to unless the triangles are indicated to be `CONTAINED`, in which case depth is the depth of the parent bounds that were contained. It can be used to precompute, cache, and then read information about a parent bound to improve performance while traversing.

`mesh` is the is the object this BVH is representing.

`intersectsBoundsFunc` takes the axis aligned bounding box representing an internal node local to the bvh, whether or not the node is a leaf, and the score calculated by `orderNodesFunc` and returns a constant indicating whether or not the bounds is intersected or contained and traversal should continue. If `CONTAINED` is returned then and optimization is triggered allowing all child triangles to be checked immediately rather than traversing the rest of the child bounds.
`callbacks` is a list of callback functions (defined below) used for traversing the tree. All functions except for `intersectsBounds` are optional.

`traverseBoundsOrder` takes the axis aligned bounding box representing an internal node local to the bvh and returns a score (often distance) used to determine whether the left or right node should be traversed first. The shape with the lowest score is traversed first.

`intersectsBounds` takes the axis aligned bounding box representing an internal node local to the bvh, whether or not the node is a leaf, and the score calculated by `orderNodesFunc`, the node depth, and the node index (for use with the [refit](#refit) function) and returns a constant indicating whether or not the bounds is intersected or contained meaning traversal should continue. If `CONTAINED` is returned then and optimization is triggered allowing the range and / or triangle intersection callbacks to be run immediately rather than traversing the rest of the child bounds.

`intersectsRange` takes a triangle offset and count representing the number of triangles to be iterated over. 1 triangle from this range represents 3 values in the geometry's index buffer. If this function returns true then traversal is stopped and `intersectsTriangle` is not called if provided.

`intersectsTriangle` takes a triangle and the index buffer indices used by the triangle from the geometry and returns whether or not the triangle has been intersected with. If the triangle is reported to be intersected the traversal ends and the `shapecast` function completes. If multiple triangles need to be collected or intersected return false here and push results onto an array. `contained` is set to `true` if one of the parent bounds was marked as entirely contained in the `intersectsBoundsFunc` function.


### .refit

```js
refit(
traversedNodeIndices : Array<Number> | Set<Number> = null,
endNodeIndices : Array<Number> | Set<Number> = null
) : void
```

Refit the node bounds to the current triangle positions. This is quicker than regenerating a new BVH but will not be optimal after significant changes to the vertices. `traversedNodeIndices` is a set of node indices (provided by the [shapecast](#shapecast) function) that need to be refit including all internal nodes. `endNodeIndices` is the set of nodes that traversal ended at and that triangles need to be updated for. If neither index set is provided then the whole BVH is updated which is significantly slower than surgically updating the nodes that need to be updated.

Here's how to get the set of indices that need to be refit:

```js
const traversedNodeIndices = new Set();
const endNodeIndices = new Set();
bvh.shapecast(

mesh,
{

intersectsBounds: ( box, isLeaf, score, depth, nodeIndex ) => {

if ( /* intersects shape */ ) {

traversedNodeIndices.add( nodeIndex );
return INTERSECTED;

}

return NOT_INTERSECTED;

},

intersectsRange: ( offset, count, contained, depth, nodeIndex ) => {

`intersectsTriangleFunc` takes a triangle and the vertex indices used by the triangle from the geometry and returns whether or not the triangle has been intersected with. If the triangle is reported to be intersected the traversal ends and the `shapecast` function completes. If multiple triangles need to be collected or intersected return false here and push results onto an array. `contained` is set to `true` if one of the parent bounds was marked as entirely contained in the `intersectsBoundsFunc` function.
// collect triangles to update
endNodeIndices.add( nodeIndex );

`orderNodesFunc` takes the axis aligned bounding box representing an internal node local to the bvh and returns a score or distance representing the distance to the shape being intersected with. The shape with the lowest score is traversed first.
}

}

);

// update the positions of the triangle vertices

bvh.refit( traversedNodeIndices, endNodeIndices );
```

### .getBoundingBox

```js
getBoundingBox( target : Box3 ) : Box3
```

Get the bounding box of the geometry computed from the root node bounds of the BVH. Significantly faster than `BufferGeometry.computeBoundingBox`.

## SerializedBVH

Expand Down Expand Up @@ -456,23 +528,33 @@ THREE.Mesh.prototype.raycast = acceleratedRaycast;

## GenerateMeshBVHWorker

Class for generating a MeshBVH asynchronously in a WebWorker to avoid it blocking the main thread. The class is not exported via index.js because they require extra effort to integrate with some build processes due to Worker sytax being inconsistently supported. UMD variants of these functions are not provided. The class must be imported from the `src/workers/GenerateMeshWorker.js` file.
Helper class for generating a MeshBVH for a given geometry in asynchronously in a worker. The geometry position and index buffer attribute `ArrayBuffers` are transferred to the Worker while the BVH is being generated meaning the geometry will be unavailable to use while the BVH is being processed unless `SharedArrayBuffers` are used. They will be automatically replaced when the MeshBVH is finished generating.

_NOTE It's best to reuse a single instance of this class to avoid the overhead of instantiating a new Worker._

### .running

```js
running : Boolean;
```

Flag indicating whether or not a BVH is already being generated in the worker.

### .generate

```js
generate( geometry : BufferGeometry, options : Object ) : Promise<MeshBVH>
generate( geometry : BufferGeometry, options : Object ) : Promise< MeshBVH >;
```

Generates a BVH for the given geometry in a WebWorker so it can be created asynchronously. A Promise is returned that resolves with the generated BVH. During the generation the `geometry.attributes.position` array and `geometry.index` array (if it exists) are transferred to the worker so the geometry will not be usable until the BVH generation is complete and the arrays are transferred back.
Generates a MeshBVH instance for the given geometry with the given options in a WebWorker. Returns a promise that resolves with the generated MeshBVH. This function will throw an error if it is already running.

### .terminate

```js
terminate() : void
terminate() : Boolean;
```

Disposes of the web worker.
Terminates the worker.

## Debug Functions

Expand Down Expand Up @@ -500,6 +582,18 @@ Measures the min and max extremes of the tree including node depth, leaf triangl
}
```

## Extra Functions

List of functions stored in the `src/workers/` and are not exported via index.js because they require extra effort to integrate with some build processes. UMD variants of these functions are not provided.

### generateAsync

```js
generateAsync( geometry : BufferGeometry, options : Object ) : Promise<MeshBVH>
```

Generates a BVH for the given geometry in a WebWorker so it can be created asynchronously. A Promise is returned that resolves with the generated BVH. During the generation the `geometry.attributes.position` array and `geometry.index` array (if it exists) are transferred to the worker so the geometry will not be usable until the BVH generation is complete and the arrays are transferred back.

## Gotchas

- This is intended to be used with complicated, high-poly meshes. With less complex meshes, the benefits are negligible.
Expand Down
4 changes: 2 additions & 2 deletions babel.config.js → babel.config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
{
"presets": [ "@babel/preset-env" ]
};
}
2 changes: 0 additions & 2 deletions benchmark/index.js

This file was deleted.

Loading