@pmndrs/viverse 0.2.16 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/physics/world.js +21 -13
- package/package.json +1 -1
package/dist/physics/world.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Box3, DoubleSide, InstancedMesh, Matrix4, Ray, Vector3 } from 'three';
|
|
1
|
+
import { Box3, DoubleSide, InstancedMesh, Matrix4, Mesh, Ray, Vector3 } from 'three';
|
|
2
2
|
import { computeBoundsTree, StaticGeometryGenerator, ExtendedTriangle } from 'three-mesh-bvh';
|
|
3
3
|
const rayHelper = new Ray();
|
|
4
4
|
const farPointHelper = new Vector3();
|
|
@@ -29,7 +29,24 @@ export class BvhPhysicsWorld {
|
|
|
29
29
|
}
|
|
30
30
|
computeBvhEntries(object, isStatic) {
|
|
31
31
|
object.updateWorldMatrix(true, true);
|
|
32
|
-
|
|
32
|
+
const result = [];
|
|
33
|
+
let hasNonInstancedMeshes = false;
|
|
34
|
+
object.traverse((entry) => {
|
|
35
|
+
if (entry instanceof InstancedMesh) {
|
|
36
|
+
const bvh = computeBoundsTree.apply(entry.geometry);
|
|
37
|
+
result.push(...new Array(entry.instanceMatrix.count).fill(undefined).map((_, i) => ({
|
|
38
|
+
object: entry,
|
|
39
|
+
bvh,
|
|
40
|
+
instanceIndex: i,
|
|
41
|
+
isStatic,
|
|
42
|
+
})));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (entry instanceof Mesh) {
|
|
46
|
+
hasNonInstancedMeshes = true;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (hasNonInstancedMeshes) {
|
|
33
50
|
const parent = object.parent;
|
|
34
51
|
if (!isStatic) {
|
|
35
52
|
object.parent = null;
|
|
@@ -41,18 +58,9 @@ export class BvhPhysicsWorld {
|
|
|
41
58
|
object.parent = parent;
|
|
42
59
|
object.updateMatrixWorld(true);
|
|
43
60
|
}
|
|
44
|
-
|
|
61
|
+
result.push({ object, bvh, isStatic });
|
|
45
62
|
}
|
|
46
|
-
|
|
47
|
-
throw new Error(`cannot add InstancedMesh with children`);
|
|
48
|
-
}
|
|
49
|
-
const bvh = computeBoundsTree.apply(object.geometry);
|
|
50
|
-
return new Array(object.instanceMatrix.count).fill(undefined).map((_, i) => ({
|
|
51
|
-
object,
|
|
52
|
-
bvh,
|
|
53
|
-
instanceIndex: i,
|
|
54
|
-
isStatic,
|
|
55
|
-
}));
|
|
63
|
+
return result;
|
|
56
64
|
}
|
|
57
65
|
removeBody(object) {
|
|
58
66
|
this.bodies = this.bodies.filter((entry) => entry.object != object);
|