@react-three/drei 9.54.2 → 9.55.0
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/README.md +44 -16
- package/core/Caustics.cjs.js +1 -1
- package/core/Caustics.d.ts +3 -3
- package/core/Caustics.js +5 -5
- package/core/MeshTransmissionMaterial.cjs.js +1 -1
- package/core/MeshTransmissionMaterial.d.ts +3 -1
- package/core/MeshTransmissionMaterial.js +34 -11
- package/core/PointerLockControls.d.ts +1 -1
- package/core/Reflector.js +4 -0
- package/core/index.cjs.js +1 -1
- package/core/index.js +1 -1
- package/core/useBVH.cjs.js +1 -1
- package/core/useBVH.d.ts +27 -1
- package/core/useBVH.js +62 -1
- package/index.cjs.js +1 -1
- package/index.js +1 -1
- package/native/index.cjs.js +1 -1
- package/native/index.js +1 -1
- package/package.json +5 -5
- package/web/index.cjs.js +1 -1
- package/web/index.js +1 -1
package/core/useBVH.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import { useThree } from '@react-three/fiber';
|
|
1
3
|
import * as React from 'react';
|
|
4
|
+
import { Mesh } from 'three';
|
|
2
5
|
import { acceleratedRaycast, computeBoundsTree, disposeBoundsTree } from 'three-mesh-bvh';
|
|
3
6
|
|
|
7
|
+
const isMesh = child => child.isMesh;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use the Bvh component instead
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
4
13
|
function useBVH(mesh, options) {
|
|
5
14
|
options = {
|
|
6
15
|
splitStrategy: 'SAH',
|
|
@@ -25,5 +34,57 @@ function useBVH(mesh, options) {
|
|
|
25
34
|
}
|
|
26
35
|
}, [mesh, JSON.stringify(options)]);
|
|
27
36
|
}
|
|
37
|
+
const Bvh = /*#__PURE__*/React.forwardRef(({
|
|
38
|
+
enabled = true,
|
|
39
|
+
firstHitOnly = false,
|
|
40
|
+
children,
|
|
41
|
+
splitStrategy = 'SAH',
|
|
42
|
+
verbose = false,
|
|
43
|
+
setBoundingBox = true,
|
|
44
|
+
maxDepth = 40,
|
|
45
|
+
maxLeafTris = 10,
|
|
46
|
+
...props
|
|
47
|
+
}, fref) => {
|
|
48
|
+
const ref = React.useRef(null);
|
|
49
|
+
const raycaster = useThree(state => state.raycaster);
|
|
50
|
+
React.useImperativeHandle(fref, () => ref.current, []);
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
if (enabled) {
|
|
53
|
+
const options = {
|
|
54
|
+
splitStrategy,
|
|
55
|
+
verbose,
|
|
56
|
+
setBoundingBox,
|
|
57
|
+
maxDepth,
|
|
58
|
+
maxLeafTris
|
|
59
|
+
};
|
|
60
|
+
const group = ref.current; // This can only safely work if the component is used once, but there is no alternative.
|
|
61
|
+
// Hijacking the raycast method to do it for individual meshes is not an option as it would
|
|
62
|
+
// cost too much memory ...
|
|
63
|
+
|
|
64
|
+
raycaster.firstHitOnly = firstHitOnly;
|
|
65
|
+
group.traverse(child => {
|
|
66
|
+
// Only include meshes that do not yet have a boundsTree and whose raycast is standard issue
|
|
67
|
+
if (isMesh(child) && !child.geometry.boundsTree && child.raycast === Mesh.prototype.raycast) {
|
|
68
|
+
child.raycast = acceleratedRaycast;
|
|
69
|
+
child.geometry.computeBoundsTree = computeBoundsTree;
|
|
70
|
+
child.geometry.disposeBoundsTree = disposeBoundsTree;
|
|
71
|
+
child.geometry.computeBoundsTree(options);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return () => {
|
|
75
|
+
delete raycaster.firstHitOnly;
|
|
76
|
+
group.traverse(child => {
|
|
77
|
+
if (isMesh(child) && child.geometry.boundsTree) {
|
|
78
|
+
child.geometry.disposeBoundsTree();
|
|
79
|
+
child.raycast = Mesh.prototype.raycast;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return /*#__PURE__*/React.createElement("group", _extends({
|
|
86
|
+
ref: ref
|
|
87
|
+
}, props), children);
|
|
88
|
+
});
|
|
28
89
|
|
|
29
|
-
export { useBVH };
|
|
90
|
+
export { Bvh, useBVH };
|