@needle-tools/three-mesh-effects 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +93 -2
- package/build/deformation-runtime.js +2143 -0
- package/build/deformation-runtime.js.map +7 -0
- package/build/impostor-runtime-needle-engine.js +42 -0
- package/build/impostor-runtime-needle-engine.js.map +7 -0
- package/build/impostor-runtime.js +1333 -0
- package/build/impostor-runtime.js.map +7 -0
- package/build/internal/deformation/cloth-surface.js +288 -0
- package/build/internal/deformation/cloth-surface.js.map +7 -0
- package/build/internal/deformation/fur-surface.js +130 -0
- package/build/internal/deformation/fur-surface.js.map +7 -0
- package/build/internal/deformation/ik-constraints.js +44 -0
- package/build/internal/deformation/ik-constraints.js.map +7 -0
- package/build/internal/deformation/joints-json.js +197 -0
- package/build/internal/deformation/joints-json.js.map +7 -0
- package/build/internal/deformation/limits.js +16 -0
- package/build/internal/deformation/limits.js.map +7 -0
- package/build/internal/deformation/motion-settings.js +12 -0
- package/build/internal/deformation/motion-settings.js.map +7 -0
- package/build/internal/deformation/pin-cloth.js +196 -0
- package/build/internal/deformation/pin-cloth.js.map +7 -0
- package/build/internal/deformation/pin-ik.js +650 -0
- package/build/internal/deformation/pin-ik.js.map +7 -0
- package/build/internal/deformation/pin-types.js +12 -0
- package/build/internal/deformation/pin-types.js.map +7 -0
- package/build/internal/deformation/pin-wiggle.js +249 -0
- package/build/internal/deformation/pin-wiggle.js.map +7 -0
- package/build/internal/deformation/pose-slots.js +84 -0
- package/build/internal/deformation/pose-slots.js.map +7 -0
- package/build/internal/deformation/pose-timeline.js +210 -0
- package/build/internal/deformation/pose-timeline.js.map +7 -0
- package/build/internal/deformation/rig-drivers.js +48 -0
- package/build/internal/deformation/rig-drivers.js.map +7 -0
- package/build/internal/deformation/rig-extension.js +334 -0
- package/build/internal/deformation/rig-extension.js.map +7 -0
- package/build/internal/deformation/rig-runtime.js +2141 -0
- package/build/internal/deformation/rig-runtime.js.map +7 -0
- package/build/internal/deformation/wind.js +34 -0
- package/build/internal/deformation/wind.js.map +7 -0
- package/build/internal/impostor/impostor-metadata.js +77 -0
- package/build/internal/impostor/impostor-metadata.js.map +7 -0
- package/build/internal/impostor/impostor-node-material.js +1331 -0
- package/build/internal/impostor/impostor-node-material.js.map +7 -0
- package/build/internal/impostor/impostor-runtime-support.js +162 -0
- package/build/internal/impostor/impostor-runtime-support.js.map +7 -0
- package/build/internal/impostor/octahedral.js +232 -0
- package/build/internal/impostor/octahedral.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-display.js +728 -0
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js +71 -0
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js +150 -0
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +7 -0
- package/build/internal/rendering/skin-projection.js +4630 -0
- package/build/internal/rendering/skin-projection.js.map +7 -0
- package/build/internal/rendering/surface-query.js +4519 -0
- package/build/internal/rendering/surface-query.js.map +7 -0
- package/build/internal/rendering/wireframe.js +112 -0
- package/build/internal/rendering/wireframe.js.map +7 -0
- package/build/internal/rendering/wrap-preview-settings.js +126 -0
- package/build/internal/rendering/wrap-preview-settings.js.map +7 -0
- package/build/internal/rendering/wrap-preview.js +5610 -0
- package/build/internal/rendering/wrap-preview.js.map +7 -0
- package/build/internal/rendering/wrap-skin.js +4746 -0
- package/build/internal/rendering/wrap-skin.js.map +7 -0
- package/build/pixel-impostor-runtime.js +876 -0
- package/build/pixel-impostor-runtime.js.map +7 -0
- package/build/types/deformation/cloth-surface.d.ts +39 -0
- package/build/types/deformation/cloth-surface.js +1 -0
- package/build/types/deformation/fur-surface.d.ts +27 -0
- package/build/types/deformation/fur-surface.js +1 -0
- package/build/types/deformation/ik-constraints.d.ts +18 -0
- package/build/types/deformation/ik-constraints.js +1 -0
- package/build/types/deformation/joints-json.d.ts +17 -0
- package/build/types/deformation/joints-json.js +1 -0
- package/build/types/deformation/limits.d.ts +23 -0
- package/build/types/deformation/limits.js +1 -0
- package/build/types/deformation/motion-settings.d.ts +9 -0
- package/build/types/deformation/motion-settings.js +1 -0
- package/build/types/deformation/pin-cloth.d.ts +28 -0
- package/build/types/deformation/pin-cloth.js +1 -0
- package/build/types/deformation/pin-ik.d.ts +37 -0
- package/build/types/deformation/pin-ik.js +1 -0
- package/build/types/deformation/pin-types.d.ts +53 -0
- package/build/types/deformation/pin-types.js +1 -0
- package/build/types/deformation/pin-wiggle.d.ts +16 -0
- package/build/types/deformation/pin-wiggle.js +1 -0
- package/build/types/deformation/pose-slots.d.ts +41 -0
- package/build/types/deformation/pose-slots.js +1 -0
- package/build/types/deformation/pose-timeline.d.ts +65 -0
- package/build/types/deformation/pose-timeline.js +1 -0
- package/build/types/deformation/rig-drivers.d.ts +19 -0
- package/build/types/deformation/rig-drivers.js +1 -0
- package/build/types/deformation/rig-extension.d.ts +33 -0
- package/build/types/deformation/rig-extension.js +1 -0
- package/build/types/deformation/rig-runtime.d.ts +95 -0
- package/build/types/deformation/rig-runtime.js +1 -0
- package/build/types/deformation/wind.d.ts +16 -0
- package/build/types/deformation/wind.js +1 -0
- package/build/types/impostor/impostor-metadata.d.ts +61 -0
- package/build/types/impostor/impostor-metadata.js +1 -0
- package/build/types/impostor/impostor-node-material.d.ts +140 -0
- package/build/types/impostor/impostor-node-material.js +1 -0
- package/build/types/impostor/impostor-runtime-support.d.ts +52 -0
- package/build/types/impostor/impostor-runtime-support.js +1 -0
- package/build/types/impostor/octahedral.d.ts +84 -0
- package/build/types/impostor/octahedral.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-display.d.ts +48 -0
- package/build/types/pixel-impostor/pixel-impostor-display.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-metadata.d.ts +34 -0
- package/build/types/pixel-impostor/pixel-impostor-metadata.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-runtime.d.ts +18 -0
- package/build/types/pixel-impostor/pixel-impostor-runtime.js +1 -0
- package/build/types/public/deformation-runtime.d.ts +3 -0
- package/build/types/public/deformation-runtime.js +1 -0
- package/build/types/public/impostor-runtime-needle-engine.d.ts +31 -0
- package/build/types/public/impostor-runtime-needle-engine.js +1 -0
- package/build/types/public/impostor-runtime.d.ts +6 -0
- package/build/types/public/impostor-runtime.js +1 -0
- package/build/types/public/pixel-impostor-runtime.d.ts +3 -0
- package/build/types/public/pixel-impostor-runtime.js +1 -0
- package/build/types/public/wrap-effects.d.ts +4 -0
- package/build/types/public/wrap-effects.js +1 -0
- package/build/types/rendering/skin-projection.d.ts +44 -0
- package/build/types/rendering/skin-projection.js +1 -0
- package/build/types/rendering/surface-query.d.ts +66 -0
- package/build/types/rendering/surface-query.js +1 -0
- package/build/types/rendering/wireframe.d.ts +25 -0
- package/build/types/rendering/wireframe.js +1 -0
- package/build/types/rendering/wrap-preview-settings.d.ts +22 -0
- package/build/types/rendering/wrap-preview-settings.js +1 -0
- package/build/types/rendering/wrap-preview.d.ts +39 -0
- package/build/types/rendering/wrap-preview.js +1 -0
- package/build/types/rendering/wrap-skin.d.ts +14 -0
- package/build/types/rendering/wrap-skin.js +1 -0
- package/build/wrap-effects.js +5640 -0
- package/build/wrap-effects.js.map +7 -0
- package/package.json +105 -4
- package/src/deformation/cloth-surface.ts +223 -0
- package/src/deformation/fur-surface.ts +129 -0
- package/src/deformation/ik-constraints.ts +37 -0
- package/src/deformation/joints-json.ts +94 -0
- package/src/deformation/limits.ts +25 -0
- package/src/deformation/motion-settings.ts +9 -0
- package/src/deformation/pin-cloth.ts +149 -0
- package/src/deformation/pin-ik.ts +582 -0
- package/src/deformation/pin-types.ts +22 -0
- package/src/deformation/pin-wiggle.ts +119 -0
- package/src/deformation/pose-slots.ts +106 -0
- package/src/deformation/pose-timeline.ts +242 -0
- package/src/deformation/rig-drivers.ts +32 -0
- package/src/deformation/rig-extension.ts +87 -0
- package/src/deformation/rig-runtime.ts +416 -0
- package/src/deformation/wind.ts +36 -0
- package/src/impostor/impostor-metadata.js +137 -0
- package/src/impostor/impostor-node-material.js +1581 -0
- package/src/impostor/impostor-runtime-support.js +139 -0
- package/src/impostor/octahedral.js +280 -0
- package/src/pixel-impostor/pixel-impostor-display.js +794 -0
- package/src/pixel-impostor/pixel-impostor-metadata.js +74 -0
- package/src/pixel-impostor/pixel-impostor-runtime.js +78 -0
- package/src/public/deformation-runtime.ts +3 -0
- package/src/public/impostor-runtime-needle-engine.js +56 -0
- package/src/public/impostor-runtime.js +21 -0
- package/src/public/pixel-impostor-runtime.js +5 -0
- package/src/public/wrap-effects.js +21 -0
- package/src/rendering/skin-projection.js +113 -0
- package/src/rendering/surface-query.js +88 -0
- package/src/rendering/wireframe.js +115 -0
- package/src/rendering/wrap-preview-settings.js +123 -0
- package/src/rendering/wrap-preview.js +645 -0
- package/src/rendering/wrap-skin.js +109 -0
|
@@ -0,0 +1,4519 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// src/rendering/surface-query.js
|
|
4
|
+
import { BackSide as BackSide2, BufferAttribute as BufferAttribute3, BufferGeometry, FrontSide as FrontSide2, Ray as Ray2, Vector3 as Vector311 } from "three";
|
|
5
|
+
|
|
6
|
+
// node_modules/three-mesh-bvh/src/core/BVH.js
|
|
7
|
+
import { Box3 as Box33 } from "three";
|
|
8
|
+
|
|
9
|
+
// node_modules/three-mesh-bvh/src/core/Constants.js
|
|
10
|
+
var CENTER = 0;
|
|
11
|
+
var AVERAGE = 1;
|
|
12
|
+
var SAH = 2;
|
|
13
|
+
var CONTAINED = 2;
|
|
14
|
+
var PRIMITIVE_INTERSECT_COST = 1.25;
|
|
15
|
+
var TRAVERSAL_COST = 1;
|
|
16
|
+
var BYTES_PER_NODE = 6 * 4 + 4 + 4;
|
|
17
|
+
var UINT32_PER_NODE = BYTES_PER_NODE / 4;
|
|
18
|
+
var IS_LEAFNODE_FLAG = 65535;
|
|
19
|
+
var LEAFNODE_MASK_32 = IS_LEAFNODE_FLAG << 16;
|
|
20
|
+
var FLOAT32_EPSILON = Math.pow(2, -24);
|
|
21
|
+
var SKIP_GENERATION = Symbol("SKIP_GENERATION");
|
|
22
|
+
var DEFAULT_OPTIONS = {
|
|
23
|
+
strategy: CENTER,
|
|
24
|
+
maxDepth: 40,
|
|
25
|
+
targetLeafSize: 10,
|
|
26
|
+
useSharedArrayBuffer: false,
|
|
27
|
+
setBoundingBox: true,
|
|
28
|
+
onProgress: null,
|
|
29
|
+
indirect: false,
|
|
30
|
+
verbose: true,
|
|
31
|
+
range: null,
|
|
32
|
+
[SKIP_GENERATION]: false
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// node_modules/three-mesh-bvh/src/utils/ArrayBoxUtilities.js
|
|
36
|
+
function arrayToBox(nodeIndex32, array, target) {
|
|
37
|
+
target.min.x = array[nodeIndex32];
|
|
38
|
+
target.min.y = array[nodeIndex32 + 1];
|
|
39
|
+
target.min.z = array[nodeIndex32 + 2];
|
|
40
|
+
target.max.x = array[nodeIndex32 + 3];
|
|
41
|
+
target.max.y = array[nodeIndex32 + 4];
|
|
42
|
+
target.max.z = array[nodeIndex32 + 5];
|
|
43
|
+
return target;
|
|
44
|
+
}
|
|
45
|
+
function getLongestEdgeIndex(bounds) {
|
|
46
|
+
let splitDimIdx = -1;
|
|
47
|
+
let splitDist = -Infinity;
|
|
48
|
+
for (let i = 0; i < 3; i++) {
|
|
49
|
+
const dist = bounds[i + 3] - bounds[i];
|
|
50
|
+
if (dist > splitDist) {
|
|
51
|
+
splitDist = dist;
|
|
52
|
+
splitDimIdx = i;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return splitDimIdx;
|
|
56
|
+
}
|
|
57
|
+
function copyBounds(source, target) {
|
|
58
|
+
target.set(source);
|
|
59
|
+
}
|
|
60
|
+
function unionBounds(a, b, target) {
|
|
61
|
+
let aVal, bVal;
|
|
62
|
+
for (let d = 0; d < 3; d++) {
|
|
63
|
+
const d3 = d + 3;
|
|
64
|
+
aVal = a[d];
|
|
65
|
+
bVal = b[d];
|
|
66
|
+
target[d] = aVal < bVal ? aVal : bVal;
|
|
67
|
+
aVal = a[d3];
|
|
68
|
+
bVal = b[d3];
|
|
69
|
+
target[d3] = aVal > bVal ? aVal : bVal;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function expandByPrimitiveBounds(startIndex, primitiveBounds, bounds) {
|
|
73
|
+
for (let d = 0; d < 3; d++) {
|
|
74
|
+
const tCenter = primitiveBounds[startIndex + 2 * d];
|
|
75
|
+
const tHalf = primitiveBounds[startIndex + 2 * d + 1];
|
|
76
|
+
const tMin = tCenter - tHalf;
|
|
77
|
+
const tMax = tCenter + tHalf;
|
|
78
|
+
if (tMin < bounds[d]) {
|
|
79
|
+
bounds[d] = tMin;
|
|
80
|
+
}
|
|
81
|
+
if (tMax > bounds[d + 3]) {
|
|
82
|
+
bounds[d + 3] = tMax;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function computeSurfaceArea(bounds) {
|
|
87
|
+
const d0 = bounds[3] - bounds[0];
|
|
88
|
+
const d1 = bounds[4] - bounds[1];
|
|
89
|
+
const d2 = bounds[5] - bounds[2];
|
|
90
|
+
return 2 * (d0 * d1 + d1 * d2 + d2 * d0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// node_modules/three-mesh-bvh/src/core/utils/nodeBufferUtils.js
|
|
94
|
+
function IS_LEAF(n16, uint16Array2) {
|
|
95
|
+
return uint16Array2[n16 + 15] === IS_LEAFNODE_FLAG;
|
|
96
|
+
}
|
|
97
|
+
function OFFSET(n32, uint32Array2) {
|
|
98
|
+
return uint32Array2[n32 + 6];
|
|
99
|
+
}
|
|
100
|
+
function COUNT(n16, uint16Array2) {
|
|
101
|
+
return uint16Array2[n16 + 14];
|
|
102
|
+
}
|
|
103
|
+
function LEFT_NODE(n32) {
|
|
104
|
+
return n32 + UINT32_PER_NODE;
|
|
105
|
+
}
|
|
106
|
+
function RIGHT_NODE(n32, uint32Array2) {
|
|
107
|
+
const relativeOffset = uint32Array2[n32 + 6];
|
|
108
|
+
return n32 + relativeOffset * UINT32_PER_NODE;
|
|
109
|
+
}
|
|
110
|
+
function SPLIT_AXIS(n32, uint32Array2) {
|
|
111
|
+
return uint32Array2[n32 + 7];
|
|
112
|
+
}
|
|
113
|
+
function BOUNDING_DATA_INDEX(n32) {
|
|
114
|
+
return n32;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// node_modules/three-mesh-bvh/src/core/build/computeBoundsUtils.js
|
|
118
|
+
function getBounds(primitiveBounds, offset, count, target, centroidTarget) {
|
|
119
|
+
let minx = Infinity;
|
|
120
|
+
let miny = Infinity;
|
|
121
|
+
let minz = Infinity;
|
|
122
|
+
let maxx = -Infinity;
|
|
123
|
+
let maxy = -Infinity;
|
|
124
|
+
let maxz = -Infinity;
|
|
125
|
+
let cminx = Infinity;
|
|
126
|
+
let cminy = Infinity;
|
|
127
|
+
let cminz = Infinity;
|
|
128
|
+
let cmaxx = -Infinity;
|
|
129
|
+
let cmaxy = -Infinity;
|
|
130
|
+
let cmaxz = -Infinity;
|
|
131
|
+
const boundsOffset = primitiveBounds.offset || 0;
|
|
132
|
+
for (let i = (offset - boundsOffset) * 6, end = (offset + count - boundsOffset) * 6; i < end; i += 6) {
|
|
133
|
+
const cx = primitiveBounds[i + 0];
|
|
134
|
+
const hx = primitiveBounds[i + 1];
|
|
135
|
+
const lx = cx - hx;
|
|
136
|
+
const rx = cx + hx;
|
|
137
|
+
if (lx < minx) minx = lx;
|
|
138
|
+
if (rx > maxx) maxx = rx;
|
|
139
|
+
if (cx < cminx) cminx = cx;
|
|
140
|
+
if (cx > cmaxx) cmaxx = cx;
|
|
141
|
+
const cy = primitiveBounds[i + 2];
|
|
142
|
+
const hy = primitiveBounds[i + 3];
|
|
143
|
+
const ly = cy - hy;
|
|
144
|
+
const ry = cy + hy;
|
|
145
|
+
if (ly < miny) miny = ly;
|
|
146
|
+
if (ry > maxy) maxy = ry;
|
|
147
|
+
if (cy < cminy) cminy = cy;
|
|
148
|
+
if (cy > cmaxy) cmaxy = cy;
|
|
149
|
+
const cz = primitiveBounds[i + 4];
|
|
150
|
+
const hz = primitiveBounds[i + 5];
|
|
151
|
+
const lz = cz - hz;
|
|
152
|
+
const rz = cz + hz;
|
|
153
|
+
if (lz < minz) minz = lz;
|
|
154
|
+
if (rz > maxz) maxz = rz;
|
|
155
|
+
if (cz < cminz) cminz = cz;
|
|
156
|
+
if (cz > cmaxz) cmaxz = cz;
|
|
157
|
+
}
|
|
158
|
+
target[0] = minx;
|
|
159
|
+
target[1] = miny;
|
|
160
|
+
target[2] = minz;
|
|
161
|
+
target[3] = maxx;
|
|
162
|
+
target[4] = maxy;
|
|
163
|
+
target[5] = maxz;
|
|
164
|
+
centroidTarget[0] = cminx;
|
|
165
|
+
centroidTarget[1] = cminy;
|
|
166
|
+
centroidTarget[2] = cminz;
|
|
167
|
+
centroidTarget[3] = cmaxx;
|
|
168
|
+
centroidTarget[4] = cmaxy;
|
|
169
|
+
centroidTarget[5] = cmaxz;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// node_modules/three-mesh-bvh/src/core/build/splitUtils.js
|
|
173
|
+
var BIN_COUNT = 32;
|
|
174
|
+
var binsSort = (a, b) => a.candidate - b.candidate;
|
|
175
|
+
var sahBins = /* @__PURE__ */ new Array(BIN_COUNT).fill().map(() => {
|
|
176
|
+
return {
|
|
177
|
+
count: 0,
|
|
178
|
+
bounds: new Float32Array(6),
|
|
179
|
+
rightCacheBounds: new Float32Array(6),
|
|
180
|
+
leftCacheBounds: new Float32Array(6),
|
|
181
|
+
candidate: 0
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
var leftBounds = /* @__PURE__ */ new Float32Array(6);
|
|
185
|
+
function getOptimalSplit(nodeBoundingData, centroidBoundingData, primitiveBounds, offset, count, strategy) {
|
|
186
|
+
let axis = -1;
|
|
187
|
+
let pos = 0;
|
|
188
|
+
if (strategy === CENTER) {
|
|
189
|
+
axis = getLongestEdgeIndex(centroidBoundingData);
|
|
190
|
+
if (axis !== -1) {
|
|
191
|
+
pos = (centroidBoundingData[axis] + centroidBoundingData[axis + 3]) / 2;
|
|
192
|
+
}
|
|
193
|
+
} else if (strategy === AVERAGE) {
|
|
194
|
+
axis = getLongestEdgeIndex(nodeBoundingData);
|
|
195
|
+
if (axis !== -1) {
|
|
196
|
+
pos = getAverage(primitiveBounds, offset, count, axis);
|
|
197
|
+
}
|
|
198
|
+
} else if (strategy === SAH) {
|
|
199
|
+
const rootSurfaceArea = computeSurfaceArea(nodeBoundingData);
|
|
200
|
+
let bestCost = PRIMITIVE_INTERSECT_COST * count;
|
|
201
|
+
const boundsOffset = primitiveBounds.offset || 0;
|
|
202
|
+
const cStart = (offset - boundsOffset) * 6;
|
|
203
|
+
const cEnd = (offset + count - boundsOffset) * 6;
|
|
204
|
+
for (let a = 0; a < 3; a++) {
|
|
205
|
+
const axisLeft = centroidBoundingData[a];
|
|
206
|
+
const axisRight = centroidBoundingData[a + 3];
|
|
207
|
+
const axisLength = axisRight - axisLeft;
|
|
208
|
+
const binWidth = axisLength / BIN_COUNT;
|
|
209
|
+
if (count < BIN_COUNT / 4) {
|
|
210
|
+
const truncatedBins = [...sahBins];
|
|
211
|
+
truncatedBins.length = count;
|
|
212
|
+
let b = 0;
|
|
213
|
+
for (let c = cStart; c < cEnd; c += 6, b++) {
|
|
214
|
+
const bin = truncatedBins[b];
|
|
215
|
+
bin.candidate = primitiveBounds[c + 2 * a];
|
|
216
|
+
bin.count = 0;
|
|
217
|
+
const {
|
|
218
|
+
bounds,
|
|
219
|
+
leftCacheBounds,
|
|
220
|
+
rightCacheBounds
|
|
221
|
+
} = bin;
|
|
222
|
+
for (let d = 0; d < 3; d++) {
|
|
223
|
+
rightCacheBounds[d] = Infinity;
|
|
224
|
+
rightCacheBounds[d + 3] = -Infinity;
|
|
225
|
+
leftCacheBounds[d] = Infinity;
|
|
226
|
+
leftCacheBounds[d + 3] = -Infinity;
|
|
227
|
+
bounds[d] = Infinity;
|
|
228
|
+
bounds[d + 3] = -Infinity;
|
|
229
|
+
}
|
|
230
|
+
expandByPrimitiveBounds(c, primitiveBounds, bounds);
|
|
231
|
+
}
|
|
232
|
+
truncatedBins.sort(binsSort);
|
|
233
|
+
let splitCount = count;
|
|
234
|
+
for (let bi = 0; bi < splitCount; bi++) {
|
|
235
|
+
const bin = truncatedBins[bi];
|
|
236
|
+
while (bi + 1 < splitCount && truncatedBins[bi + 1].candidate === bin.candidate) {
|
|
237
|
+
truncatedBins.splice(bi + 1, 1);
|
|
238
|
+
splitCount--;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
for (let c = cStart; c < cEnd; c += 6) {
|
|
242
|
+
const center = primitiveBounds[c + 2 * a];
|
|
243
|
+
for (let bi = 0; bi < splitCount; bi++) {
|
|
244
|
+
const bin = truncatedBins[bi];
|
|
245
|
+
if (center >= bin.candidate) {
|
|
246
|
+
expandByPrimitiveBounds(c, primitiveBounds, bin.rightCacheBounds);
|
|
247
|
+
} else {
|
|
248
|
+
expandByPrimitiveBounds(c, primitiveBounds, bin.leftCacheBounds);
|
|
249
|
+
bin.count++;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (let bi = 0; bi < splitCount; bi++) {
|
|
254
|
+
const bin = truncatedBins[bi];
|
|
255
|
+
const leftCount = bin.count;
|
|
256
|
+
const rightCount = count - bin.count;
|
|
257
|
+
const leftBounds2 = bin.leftCacheBounds;
|
|
258
|
+
const rightBounds = bin.rightCacheBounds;
|
|
259
|
+
let leftProb = 0;
|
|
260
|
+
if (leftCount !== 0) {
|
|
261
|
+
leftProb = computeSurfaceArea(leftBounds2) / rootSurfaceArea;
|
|
262
|
+
}
|
|
263
|
+
let rightProb = 0;
|
|
264
|
+
if (rightCount !== 0) {
|
|
265
|
+
rightProb = computeSurfaceArea(rightBounds) / rootSurfaceArea;
|
|
266
|
+
}
|
|
267
|
+
const cost = TRAVERSAL_COST + PRIMITIVE_INTERSECT_COST * (leftProb * leftCount + rightProb * rightCount);
|
|
268
|
+
if (cost < bestCost) {
|
|
269
|
+
axis = a;
|
|
270
|
+
bestCost = cost;
|
|
271
|
+
pos = bin.candidate;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
for (let i = 0; i < BIN_COUNT; i++) {
|
|
276
|
+
const bin = sahBins[i];
|
|
277
|
+
bin.count = 0;
|
|
278
|
+
bin.candidate = axisLeft + binWidth + i * binWidth;
|
|
279
|
+
const bounds = bin.bounds;
|
|
280
|
+
for (let d = 0; d < 3; d++) {
|
|
281
|
+
bounds[d] = Infinity;
|
|
282
|
+
bounds[d + 3] = -Infinity;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
for (let c = cStart; c < cEnd; c += 6) {
|
|
286
|
+
const triCenter = primitiveBounds[c + 2 * a];
|
|
287
|
+
const relativeCenter = triCenter - axisLeft;
|
|
288
|
+
let binIndex = ~~(relativeCenter / binWidth);
|
|
289
|
+
if (binIndex >= BIN_COUNT) binIndex = BIN_COUNT - 1;
|
|
290
|
+
const bin = sahBins[binIndex];
|
|
291
|
+
bin.count++;
|
|
292
|
+
expandByPrimitiveBounds(c, primitiveBounds, bin.bounds);
|
|
293
|
+
}
|
|
294
|
+
const lastBin = sahBins[BIN_COUNT - 1];
|
|
295
|
+
copyBounds(lastBin.bounds, lastBin.rightCacheBounds);
|
|
296
|
+
for (let i = BIN_COUNT - 2; i >= 0; i--) {
|
|
297
|
+
const bin = sahBins[i];
|
|
298
|
+
const nextBin = sahBins[i + 1];
|
|
299
|
+
unionBounds(bin.bounds, nextBin.rightCacheBounds, bin.rightCacheBounds);
|
|
300
|
+
}
|
|
301
|
+
let leftCount = 0;
|
|
302
|
+
for (let i = 0; i < BIN_COUNT - 1; i++) {
|
|
303
|
+
const bin = sahBins[i];
|
|
304
|
+
const binCount = bin.count;
|
|
305
|
+
const bounds = bin.bounds;
|
|
306
|
+
const nextBin = sahBins[i + 1];
|
|
307
|
+
const rightBounds = nextBin.rightCacheBounds;
|
|
308
|
+
if (binCount !== 0) {
|
|
309
|
+
if (leftCount === 0) {
|
|
310
|
+
copyBounds(bounds, leftBounds);
|
|
311
|
+
} else {
|
|
312
|
+
unionBounds(bounds, leftBounds, leftBounds);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
leftCount += binCount;
|
|
316
|
+
let leftProb = 0;
|
|
317
|
+
let rightProb = 0;
|
|
318
|
+
if (leftCount !== 0) {
|
|
319
|
+
leftProb = computeSurfaceArea(leftBounds) / rootSurfaceArea;
|
|
320
|
+
}
|
|
321
|
+
const rightCount = count - leftCount;
|
|
322
|
+
if (rightCount !== 0) {
|
|
323
|
+
rightProb = computeSurfaceArea(rightBounds) / rootSurfaceArea;
|
|
324
|
+
}
|
|
325
|
+
const cost = TRAVERSAL_COST + PRIMITIVE_INTERSECT_COST * (leftProb * leftCount + rightProb * rightCount);
|
|
326
|
+
if (cost < bestCost) {
|
|
327
|
+
axis = a;
|
|
328
|
+
bestCost = cost;
|
|
329
|
+
pos = bin.candidate;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
console.warn(`BVH: Invalid build strategy value ${strategy} used.`);
|
|
336
|
+
}
|
|
337
|
+
return { axis, pos };
|
|
338
|
+
}
|
|
339
|
+
function getAverage(primitiveBounds, offset, count, axis) {
|
|
340
|
+
let avg = 0;
|
|
341
|
+
const boundsOffset = primitiveBounds.offset;
|
|
342
|
+
for (let i = offset, end = offset + count; i < end; i++) {
|
|
343
|
+
avg += primitiveBounds[(i - boundsOffset) * 6 + axis * 2];
|
|
344
|
+
}
|
|
345
|
+
return avg / count;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// node_modules/three-mesh-bvh/src/core/BVHNode.js
|
|
349
|
+
var BVHNode = class {
|
|
350
|
+
constructor() {
|
|
351
|
+
this.boundingData = new Float32Array(6);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// node_modules/three-mesh-bvh/src/core/build/sortUtils.js
|
|
356
|
+
function partition(buffer, stride, primitiveBounds, offset, count, split) {
|
|
357
|
+
let left = offset;
|
|
358
|
+
let right = offset + count - 1;
|
|
359
|
+
const pos = split.pos;
|
|
360
|
+
const axisOffset = split.axis * 2;
|
|
361
|
+
const boundsOffset = primitiveBounds.offset || 0;
|
|
362
|
+
while (true) {
|
|
363
|
+
while (left <= right && primitiveBounds[(left - boundsOffset) * 6 + axisOffset] < pos) {
|
|
364
|
+
left++;
|
|
365
|
+
}
|
|
366
|
+
while (left <= right && primitiveBounds[(right - boundsOffset) * 6 + axisOffset] >= pos) {
|
|
367
|
+
right--;
|
|
368
|
+
}
|
|
369
|
+
if (left < right) {
|
|
370
|
+
for (let i = 0; i < stride; i++) {
|
|
371
|
+
let t0 = buffer[left * stride + i];
|
|
372
|
+
buffer[left * stride + i] = buffer[right * stride + i];
|
|
373
|
+
buffer[right * stride + i] = t0;
|
|
374
|
+
}
|
|
375
|
+
for (let i = 0; i < 6; i++) {
|
|
376
|
+
const l = left - boundsOffset;
|
|
377
|
+
const r = right - boundsOffset;
|
|
378
|
+
const tb = primitiveBounds[l * 6 + i];
|
|
379
|
+
primitiveBounds[l * 6 + i] = primitiveBounds[r * 6 + i];
|
|
380
|
+
primitiveBounds[r * 6 + i] = tb;
|
|
381
|
+
}
|
|
382
|
+
left++;
|
|
383
|
+
right--;
|
|
384
|
+
} else {
|
|
385
|
+
return left;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// node_modules/three-mesh-bvh/src/core/build/buildUtils.js
|
|
391
|
+
var float32Array;
|
|
392
|
+
var uint32Array;
|
|
393
|
+
var uint16Array;
|
|
394
|
+
var uint8Array;
|
|
395
|
+
var MAX_POINTER = Math.pow(2, 32);
|
|
396
|
+
function countNodes(node) {
|
|
397
|
+
if ("count" in node) {
|
|
398
|
+
return 1;
|
|
399
|
+
} else {
|
|
400
|
+
return 1 + countNodes(node.left) + countNodes(node.right);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function populateBuffer(byteOffset, node, buffer) {
|
|
404
|
+
float32Array = new Float32Array(buffer);
|
|
405
|
+
uint32Array = new Uint32Array(buffer);
|
|
406
|
+
uint16Array = new Uint16Array(buffer);
|
|
407
|
+
uint8Array = new Uint8Array(buffer);
|
|
408
|
+
return _populateBuffer(byteOffset, node);
|
|
409
|
+
}
|
|
410
|
+
function _populateBuffer(byteOffset, node) {
|
|
411
|
+
const node32Index = byteOffset / 4;
|
|
412
|
+
const node16Index = byteOffset / 2;
|
|
413
|
+
const isLeaf = "count" in node;
|
|
414
|
+
const boundingData = node.boundingData;
|
|
415
|
+
for (let i = 0; i < 6; i++) {
|
|
416
|
+
float32Array[node32Index + i] = boundingData[i];
|
|
417
|
+
}
|
|
418
|
+
if (isLeaf) {
|
|
419
|
+
if (node.buffer) {
|
|
420
|
+
uint8Array.set(new Uint8Array(node.buffer), byteOffset);
|
|
421
|
+
return byteOffset + node.buffer.byteLength;
|
|
422
|
+
} else {
|
|
423
|
+
uint32Array[node32Index + 6] = node.offset;
|
|
424
|
+
uint16Array[node16Index + 14] = node.count;
|
|
425
|
+
uint16Array[node16Index + 15] = IS_LEAFNODE_FLAG;
|
|
426
|
+
return byteOffset + BYTES_PER_NODE;
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
const { left, right, splitAxis } = node;
|
|
430
|
+
const leftByteOffset = byteOffset + BYTES_PER_NODE;
|
|
431
|
+
let rightByteOffset = _populateBuffer(leftByteOffset, left);
|
|
432
|
+
const currentNodeIndex = byteOffset / BYTES_PER_NODE;
|
|
433
|
+
const rightNodeIndex = rightByteOffset / BYTES_PER_NODE;
|
|
434
|
+
const relativeRightIndex = rightNodeIndex - currentNodeIndex;
|
|
435
|
+
if (relativeRightIndex > MAX_POINTER) {
|
|
436
|
+
throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");
|
|
437
|
+
}
|
|
438
|
+
uint32Array[node32Index + 6] = relativeRightIndex;
|
|
439
|
+
uint32Array[node32Index + 7] = splitAxis;
|
|
440
|
+
return _populateBuffer(rightByteOffset, right);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// node_modules/three-mesh-bvh/src/core/build/buildTree.js
|
|
445
|
+
function buildTree(bvh, primitiveBounds, offset, count, options, loadRange) {
|
|
446
|
+
const {
|
|
447
|
+
maxDepth,
|
|
448
|
+
verbose,
|
|
449
|
+
targetLeafSize,
|
|
450
|
+
_strictLeafSize = Infinity,
|
|
451
|
+
strategy,
|
|
452
|
+
onProgress
|
|
453
|
+
} = options;
|
|
454
|
+
const partitionBuffer = bvh.primitiveBuffer;
|
|
455
|
+
const partitionStride = bvh.primitiveBufferStride;
|
|
456
|
+
const cacheCentroidBoundingData = new Float32Array(6);
|
|
457
|
+
let reachedMaxDepth = false;
|
|
458
|
+
const root = new BVHNode();
|
|
459
|
+
getBounds(primitiveBounds, offset, count, root.boundingData, cacheCentroidBoundingData);
|
|
460
|
+
splitNode(root, offset, count, cacheCentroidBoundingData);
|
|
461
|
+
return root;
|
|
462
|
+
function triggerProgress(primitivesProcessed) {
|
|
463
|
+
if (onProgress) {
|
|
464
|
+
onProgress((primitivesProcessed - loadRange.offset) / loadRange.count);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function splitNode(node, offset2, count2, centroidBoundingData = null, depth = 0) {
|
|
468
|
+
if (!reachedMaxDepth && depth >= maxDepth) {
|
|
469
|
+
reachedMaxDepth = true;
|
|
470
|
+
if (verbose) {
|
|
471
|
+
console.warn(`BVH: Max depth of ${maxDepth} reached when generating BVH. Consider increasing maxDepth.`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const mustSplit = count2 > _strictLeafSize;
|
|
475
|
+
if (count2 <= targetLeafSize && !mustSplit || depth >= maxDepth) {
|
|
476
|
+
triggerProgress(offset2 + count2);
|
|
477
|
+
node.offset = offset2;
|
|
478
|
+
node.count = count2;
|
|
479
|
+
return node;
|
|
480
|
+
}
|
|
481
|
+
const split = getOptimalSplit(node.boundingData, centroidBoundingData, primitiveBounds, offset2, count2, strategy);
|
|
482
|
+
let splitOffset = split.axis === -1 ? -1 : partition(partitionBuffer, partitionStride, primitiveBounds, offset2, count2, split);
|
|
483
|
+
if (split.axis === -1 || splitOffset === offset2 || splitOffset === offset2 + count2) {
|
|
484
|
+
if (!mustSplit) {
|
|
485
|
+
triggerProgress(offset2 + count2);
|
|
486
|
+
node.offset = offset2;
|
|
487
|
+
node.count = count2;
|
|
488
|
+
return node;
|
|
489
|
+
}
|
|
490
|
+
split.axis = Math.max(0, getLongestEdgeIndex(node.boundingData));
|
|
491
|
+
splitOffset = offset2 + Math.max(1, Math.floor(count2 / 2));
|
|
492
|
+
}
|
|
493
|
+
node.splitAxis = split.axis;
|
|
494
|
+
const left = new BVHNode();
|
|
495
|
+
const lstart = offset2;
|
|
496
|
+
const lcount = splitOffset - offset2;
|
|
497
|
+
node.left = left;
|
|
498
|
+
getBounds(primitiveBounds, lstart, lcount, left.boundingData, cacheCentroidBoundingData);
|
|
499
|
+
splitNode(left, lstart, lcount, cacheCentroidBoundingData, depth + 1);
|
|
500
|
+
const right = new BVHNode();
|
|
501
|
+
const rstart = splitOffset;
|
|
502
|
+
const rcount = count2 - lcount;
|
|
503
|
+
node.right = right;
|
|
504
|
+
getBounds(primitiveBounds, rstart, rcount, right.boundingData, cacheCentroidBoundingData);
|
|
505
|
+
splitNode(right, rstart, rcount, cacheCentroidBoundingData, depth + 1);
|
|
506
|
+
return node;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function buildPackedTree(bvh, options) {
|
|
510
|
+
const BufferConstructor = options.useSharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer;
|
|
511
|
+
const rootRanges = bvh.getRootRanges(options.range);
|
|
512
|
+
const firstRange = rootRanges[0];
|
|
513
|
+
const lastRange = rootRanges[rootRanges.length - 1];
|
|
514
|
+
const fullRange = {
|
|
515
|
+
offset: firstRange.offset,
|
|
516
|
+
count: lastRange.offset + lastRange.count - firstRange.offset
|
|
517
|
+
};
|
|
518
|
+
const primitiveBounds = new Float32Array(6 * fullRange.count);
|
|
519
|
+
primitiveBounds.offset = fullRange.offset;
|
|
520
|
+
bvh.computePrimitiveBounds(fullRange.offset, fullRange.count, primitiveBounds);
|
|
521
|
+
bvh._roots = rootRanges.map((range) => {
|
|
522
|
+
const root = buildTree(bvh, primitiveBounds, range.offset, range.count, options, fullRange);
|
|
523
|
+
const nodeCount = countNodes(root);
|
|
524
|
+
const buffer = new BufferConstructor(BYTES_PER_NODE * nodeCount);
|
|
525
|
+
populateBuffer(0, root, buffer);
|
|
526
|
+
return buffer;
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// node_modules/three-mesh-bvh/src/core/cast/shapecast.js
|
|
531
|
+
import { Box3 } from "three";
|
|
532
|
+
|
|
533
|
+
// node_modules/three-mesh-bvh/src/utils/PrimitivePool.js
|
|
534
|
+
var PrimitivePool = class {
|
|
535
|
+
constructor(getNewPrimitive) {
|
|
536
|
+
this._getNewPrimitive = getNewPrimitive;
|
|
537
|
+
this._primitives = [];
|
|
538
|
+
}
|
|
539
|
+
getPrimitive() {
|
|
540
|
+
const primitives = this._primitives;
|
|
541
|
+
if (primitives.length === 0) {
|
|
542
|
+
return this._getNewPrimitive();
|
|
543
|
+
} else {
|
|
544
|
+
return primitives.pop();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
releasePrimitive(primitive) {
|
|
548
|
+
this._primitives.push(primitive);
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
// node_modules/three-mesh-bvh/src/core/utils/BufferStack.js
|
|
553
|
+
var _BufferStack = class {
|
|
554
|
+
constructor() {
|
|
555
|
+
this.float32Array = null;
|
|
556
|
+
this.uint16Array = null;
|
|
557
|
+
this.uint32Array = null;
|
|
558
|
+
const stack = [];
|
|
559
|
+
let prevBuffer = null;
|
|
560
|
+
this.setBuffer = (buffer) => {
|
|
561
|
+
if (prevBuffer) {
|
|
562
|
+
stack.push(prevBuffer);
|
|
563
|
+
}
|
|
564
|
+
prevBuffer = buffer;
|
|
565
|
+
this.float32Array = new Float32Array(buffer);
|
|
566
|
+
this.uint16Array = new Uint16Array(buffer);
|
|
567
|
+
this.uint32Array = new Uint32Array(buffer);
|
|
568
|
+
};
|
|
569
|
+
this.clearBuffer = () => {
|
|
570
|
+
prevBuffer = null;
|
|
571
|
+
this.float32Array = null;
|
|
572
|
+
this.uint16Array = null;
|
|
573
|
+
this.uint32Array = null;
|
|
574
|
+
if (stack.length !== 0) {
|
|
575
|
+
this.setBuffer(stack.pop());
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
var BufferStack = /* @__PURE__ */ new _BufferStack();
|
|
581
|
+
|
|
582
|
+
// node_modules/three-mesh-bvh/src/core/cast/shapecast.js
|
|
583
|
+
var _box1;
|
|
584
|
+
var _box2;
|
|
585
|
+
var boxStack = [];
|
|
586
|
+
var boxPool = /* @__PURE__ */ new PrimitivePool(() => new Box3());
|
|
587
|
+
function shapecast(bvh, root, intersectsBounds, intersectsRange, boundsTraverseOrder, nodeOffset) {
|
|
588
|
+
_box1 = boxPool.getPrimitive();
|
|
589
|
+
_box2 = boxPool.getPrimitive();
|
|
590
|
+
boxStack.push(_box1, _box2);
|
|
591
|
+
BufferStack.setBuffer(bvh._roots[root]);
|
|
592
|
+
const result = shapecastTraverse(0, bvh.geometry, intersectsBounds, intersectsRange, boundsTraverseOrder, nodeOffset);
|
|
593
|
+
BufferStack.clearBuffer();
|
|
594
|
+
boxPool.releasePrimitive(_box1);
|
|
595
|
+
boxPool.releasePrimitive(_box2);
|
|
596
|
+
boxStack.pop();
|
|
597
|
+
boxStack.pop();
|
|
598
|
+
const length = boxStack.length;
|
|
599
|
+
if (length > 0) {
|
|
600
|
+
_box2 = boxStack[length - 1];
|
|
601
|
+
_box1 = boxStack[length - 2];
|
|
602
|
+
}
|
|
603
|
+
return result;
|
|
604
|
+
}
|
|
605
|
+
function shapecastTraverse(nodeIndex32, geometry, intersectsBoundsFunc, intersectsRangeFunc, nodeScoreFunc = null, nodeIndexOffset = 0, depth = 0) {
|
|
606
|
+
const { float32Array: float32Array2, uint16Array: uint16Array2, uint32Array: uint32Array2 } = BufferStack;
|
|
607
|
+
let nodeIndex16 = nodeIndex32 * 2;
|
|
608
|
+
const isLeaf = IS_LEAF(nodeIndex16, uint16Array2);
|
|
609
|
+
if (isLeaf) {
|
|
610
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
611
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
612
|
+
arrayToBox(BOUNDING_DATA_INDEX(nodeIndex32), float32Array2, _box1);
|
|
613
|
+
return intersectsRangeFunc(offset, count, false, depth, nodeIndexOffset + nodeIndex32 / UINT32_PER_NODE, _box1);
|
|
614
|
+
} else {
|
|
615
|
+
let getLeftOffset = function(nodeIndex322) {
|
|
616
|
+
const { uint16Array: uint16Array3, uint32Array: uint32Array3 } = BufferStack;
|
|
617
|
+
let nodeIndex162 = nodeIndex322 * 2;
|
|
618
|
+
while (!IS_LEAF(nodeIndex162, uint16Array3)) {
|
|
619
|
+
nodeIndex322 = LEFT_NODE(nodeIndex322);
|
|
620
|
+
nodeIndex162 = nodeIndex322 * 2;
|
|
621
|
+
}
|
|
622
|
+
return OFFSET(nodeIndex322, uint32Array3);
|
|
623
|
+
}, getRightEndOffset = function(nodeIndex322) {
|
|
624
|
+
const { uint16Array: uint16Array3, uint32Array: uint32Array3 } = BufferStack;
|
|
625
|
+
let nodeIndex162 = nodeIndex322 * 2;
|
|
626
|
+
while (!IS_LEAF(nodeIndex162, uint16Array3)) {
|
|
627
|
+
nodeIndex322 = RIGHT_NODE(nodeIndex322, uint32Array3);
|
|
628
|
+
nodeIndex162 = nodeIndex322 * 2;
|
|
629
|
+
}
|
|
630
|
+
return OFFSET(nodeIndex322, uint32Array3) + COUNT(nodeIndex162, uint16Array3);
|
|
631
|
+
};
|
|
632
|
+
const left = LEFT_NODE(nodeIndex32);
|
|
633
|
+
const right = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
634
|
+
let c1 = left;
|
|
635
|
+
let c2 = right;
|
|
636
|
+
let score1, score2;
|
|
637
|
+
let box1, box2;
|
|
638
|
+
if (nodeScoreFunc) {
|
|
639
|
+
box1 = _box1;
|
|
640
|
+
box2 = _box2;
|
|
641
|
+
arrayToBox(BOUNDING_DATA_INDEX(c1), float32Array2, box1);
|
|
642
|
+
arrayToBox(BOUNDING_DATA_INDEX(c2), float32Array2, box2);
|
|
643
|
+
score1 = nodeScoreFunc(box1);
|
|
644
|
+
score2 = nodeScoreFunc(box2);
|
|
645
|
+
if (score2 < score1) {
|
|
646
|
+
c1 = right;
|
|
647
|
+
c2 = left;
|
|
648
|
+
const temp5 = score1;
|
|
649
|
+
score1 = score2;
|
|
650
|
+
score2 = temp5;
|
|
651
|
+
box1 = box2;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (!box1) {
|
|
655
|
+
box1 = _box1;
|
|
656
|
+
arrayToBox(BOUNDING_DATA_INDEX(c1), float32Array2, box1);
|
|
657
|
+
}
|
|
658
|
+
const isC1Leaf = IS_LEAF(c1 * 2, uint16Array2);
|
|
659
|
+
const c1Intersection = intersectsBoundsFunc(box1, isC1Leaf, score1, depth + 1, nodeIndexOffset + c1 / UINT32_PER_NODE);
|
|
660
|
+
let c1StopTraversal;
|
|
661
|
+
if (c1Intersection === CONTAINED) {
|
|
662
|
+
const offset = getLeftOffset(c1);
|
|
663
|
+
const end = getRightEndOffset(c1);
|
|
664
|
+
const count = end - offset;
|
|
665
|
+
c1StopTraversal = intersectsRangeFunc(offset, count, true, depth + 1, nodeIndexOffset + c1 / UINT32_PER_NODE, box1);
|
|
666
|
+
} else {
|
|
667
|
+
c1StopTraversal = c1Intersection && shapecastTraverse(
|
|
668
|
+
c1,
|
|
669
|
+
geometry,
|
|
670
|
+
intersectsBoundsFunc,
|
|
671
|
+
intersectsRangeFunc,
|
|
672
|
+
nodeScoreFunc,
|
|
673
|
+
nodeIndexOffset,
|
|
674
|
+
depth + 1
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
if (c1StopTraversal) return true;
|
|
678
|
+
box2 = _box2;
|
|
679
|
+
arrayToBox(BOUNDING_DATA_INDEX(c2), float32Array2, box2);
|
|
680
|
+
const isC2Leaf = IS_LEAF(c2 * 2, uint16Array2);
|
|
681
|
+
const c2Intersection = intersectsBoundsFunc(box2, isC2Leaf, score2, depth + 1, nodeIndexOffset + c2 / UINT32_PER_NODE);
|
|
682
|
+
let c2StopTraversal;
|
|
683
|
+
if (c2Intersection === CONTAINED) {
|
|
684
|
+
const offset = getLeftOffset(c2);
|
|
685
|
+
const end = getRightEndOffset(c2);
|
|
686
|
+
const count = end - offset;
|
|
687
|
+
c2StopTraversal = intersectsRangeFunc(offset, count, true, depth + 1, nodeIndexOffset + c2 / UINT32_PER_NODE, box2);
|
|
688
|
+
} else {
|
|
689
|
+
c2StopTraversal = c2Intersection && shapecastTraverse(
|
|
690
|
+
c2,
|
|
691
|
+
geometry,
|
|
692
|
+
intersectsBoundsFunc,
|
|
693
|
+
intersectsRangeFunc,
|
|
694
|
+
nodeScoreFunc,
|
|
695
|
+
nodeIndexOffset,
|
|
696
|
+
depth + 1
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
if (c2StopTraversal) return true;
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// node_modules/three-mesh-bvh/src/core/cast/bvhcast.js
|
|
705
|
+
import { Box3 as Box32, Matrix4 } from "three";
|
|
706
|
+
var _bufferStack1 = /* @__PURE__ */ new BufferStack.constructor();
|
|
707
|
+
var _bufferStack2 = /* @__PURE__ */ new BufferStack.constructor();
|
|
708
|
+
var _boxPool = /* @__PURE__ */ new PrimitivePool(() => new Box32());
|
|
709
|
+
var _leftBox1 = /* @__PURE__ */ new Box32();
|
|
710
|
+
var _rightBox1 = /* @__PURE__ */ new Box32();
|
|
711
|
+
var _leftBox2 = /* @__PURE__ */ new Box32();
|
|
712
|
+
var _rightBox2 = /* @__PURE__ */ new Box32();
|
|
713
|
+
var _active = false;
|
|
714
|
+
function bvhcast(bvh, otherBvh, matrixToLocal, intersectsRanges) {
|
|
715
|
+
if (_active) {
|
|
716
|
+
throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");
|
|
717
|
+
}
|
|
718
|
+
_active = true;
|
|
719
|
+
const roots = bvh._roots;
|
|
720
|
+
const otherRoots = otherBvh._roots;
|
|
721
|
+
let result;
|
|
722
|
+
let nodeOffset1 = 0;
|
|
723
|
+
let nodeOffset2 = 0;
|
|
724
|
+
const invMat = new Matrix4().copy(matrixToLocal).invert();
|
|
725
|
+
for (let i = 0, il = roots.length; i < il; i++) {
|
|
726
|
+
_bufferStack1.setBuffer(roots[i]);
|
|
727
|
+
nodeOffset2 = 0;
|
|
728
|
+
const localBox = _boxPool.getPrimitive();
|
|
729
|
+
arrayToBox(BOUNDING_DATA_INDEX(0), _bufferStack1.float32Array, localBox);
|
|
730
|
+
localBox.applyMatrix4(invMat);
|
|
731
|
+
for (let j = 0, jl = otherRoots.length; j < jl; j++) {
|
|
732
|
+
_bufferStack2.setBuffer(otherRoots[j]);
|
|
733
|
+
result = _traverse(
|
|
734
|
+
0,
|
|
735
|
+
0,
|
|
736
|
+
matrixToLocal,
|
|
737
|
+
invMat,
|
|
738
|
+
intersectsRanges,
|
|
739
|
+
nodeOffset1,
|
|
740
|
+
nodeOffset2,
|
|
741
|
+
0,
|
|
742
|
+
0,
|
|
743
|
+
localBox
|
|
744
|
+
);
|
|
745
|
+
_bufferStack2.clearBuffer();
|
|
746
|
+
nodeOffset2 += otherRoots[j].byteLength / BYTES_PER_NODE;
|
|
747
|
+
if (result) {
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
_boxPool.releasePrimitive(localBox);
|
|
752
|
+
_bufferStack1.clearBuffer();
|
|
753
|
+
nodeOffset1 += roots[i].byteLength / BYTES_PER_NODE;
|
|
754
|
+
if (result) {
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
_active = false;
|
|
759
|
+
return result;
|
|
760
|
+
}
|
|
761
|
+
function _traverse(node1Index32, node2Index32, matrix2to1, matrix1to2, intersectsRangesFunc, node1IndexOffset = 0, node2IndexOffset = 0, depth1 = 0, depth2 = 0, currBox = null, reversed = false) {
|
|
762
|
+
let bufferStack1, bufferStack2;
|
|
763
|
+
if (reversed) {
|
|
764
|
+
bufferStack1 = _bufferStack2;
|
|
765
|
+
bufferStack2 = _bufferStack1;
|
|
766
|
+
} else {
|
|
767
|
+
bufferStack1 = _bufferStack1;
|
|
768
|
+
bufferStack2 = _bufferStack2;
|
|
769
|
+
}
|
|
770
|
+
const float32Array1 = bufferStack1.float32Array, uint32Array1 = bufferStack1.uint32Array, uint16Array1 = bufferStack1.uint16Array, float32Array2 = bufferStack2.float32Array, uint32Array2 = bufferStack2.uint32Array, uint16Array2 = bufferStack2.uint16Array;
|
|
771
|
+
const node1Index16 = node1Index32 * 2;
|
|
772
|
+
const node2Index16 = node2Index32 * 2;
|
|
773
|
+
const isLeaf1 = IS_LEAF(node1Index16, uint16Array1);
|
|
774
|
+
const isLeaf2 = IS_LEAF(node2Index16, uint16Array2);
|
|
775
|
+
let result = false;
|
|
776
|
+
if (isLeaf2 && isLeaf1) {
|
|
777
|
+
if (reversed) {
|
|
778
|
+
result = intersectsRangesFunc(
|
|
779
|
+
OFFSET(node2Index32, uint32Array2),
|
|
780
|
+
COUNT(node2Index32 * 2, uint16Array2),
|
|
781
|
+
OFFSET(node1Index32, uint32Array1),
|
|
782
|
+
COUNT(node1Index32 * 2, uint16Array1),
|
|
783
|
+
depth2,
|
|
784
|
+
node2IndexOffset + node2Index32 / UINT32_PER_NODE,
|
|
785
|
+
depth1,
|
|
786
|
+
node1IndexOffset + node1Index32 / UINT32_PER_NODE
|
|
787
|
+
);
|
|
788
|
+
} else {
|
|
789
|
+
result = intersectsRangesFunc(
|
|
790
|
+
OFFSET(node1Index32, uint32Array1),
|
|
791
|
+
COUNT(node1Index32 * 2, uint16Array1),
|
|
792
|
+
OFFSET(node2Index32, uint32Array2),
|
|
793
|
+
COUNT(node2Index32 * 2, uint16Array2),
|
|
794
|
+
depth1,
|
|
795
|
+
node1IndexOffset + node1Index32 / UINT32_PER_NODE,
|
|
796
|
+
depth2,
|
|
797
|
+
node2IndexOffset + node2Index32 / UINT32_PER_NODE
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
} else if (isLeaf2) {
|
|
801
|
+
const newBox = _boxPool.getPrimitive();
|
|
802
|
+
arrayToBox(BOUNDING_DATA_INDEX(node2Index32), float32Array2, newBox);
|
|
803
|
+
newBox.applyMatrix4(matrix2to1);
|
|
804
|
+
const cl1 = LEFT_NODE(node1Index32);
|
|
805
|
+
const cr1 = RIGHT_NODE(node1Index32, uint32Array1);
|
|
806
|
+
arrayToBox(BOUNDING_DATA_INDEX(cl1), float32Array1, _leftBox1);
|
|
807
|
+
arrayToBox(BOUNDING_DATA_INDEX(cr1), float32Array1, _rightBox1);
|
|
808
|
+
const intersectCl1 = newBox.intersectsBox(_leftBox1);
|
|
809
|
+
const intersectCr1 = newBox.intersectsBox(_rightBox1);
|
|
810
|
+
result = intersectCl1 && _traverse(
|
|
811
|
+
node2Index32,
|
|
812
|
+
cl1,
|
|
813
|
+
matrix1to2,
|
|
814
|
+
matrix2to1,
|
|
815
|
+
intersectsRangesFunc,
|
|
816
|
+
node2IndexOffset,
|
|
817
|
+
node1IndexOffset,
|
|
818
|
+
depth2,
|
|
819
|
+
depth1 + 1,
|
|
820
|
+
newBox,
|
|
821
|
+
!reversed
|
|
822
|
+
) || intersectCr1 && _traverse(
|
|
823
|
+
node2Index32,
|
|
824
|
+
cr1,
|
|
825
|
+
matrix1to2,
|
|
826
|
+
matrix2to1,
|
|
827
|
+
intersectsRangesFunc,
|
|
828
|
+
node2IndexOffset,
|
|
829
|
+
node1IndexOffset,
|
|
830
|
+
depth2,
|
|
831
|
+
depth1 + 1,
|
|
832
|
+
newBox,
|
|
833
|
+
!reversed
|
|
834
|
+
);
|
|
835
|
+
_boxPool.releasePrimitive(newBox);
|
|
836
|
+
} else {
|
|
837
|
+
const cl2 = LEFT_NODE(node2Index32);
|
|
838
|
+
const cr2 = RIGHT_NODE(node2Index32, uint32Array2);
|
|
839
|
+
arrayToBox(BOUNDING_DATA_INDEX(cl2), float32Array2, _leftBox2);
|
|
840
|
+
arrayToBox(BOUNDING_DATA_INDEX(cr2), float32Array2, _rightBox2);
|
|
841
|
+
const leftIntersects = currBox.intersectsBox(_leftBox2);
|
|
842
|
+
const rightIntersects = currBox.intersectsBox(_rightBox2);
|
|
843
|
+
if (leftIntersects && rightIntersects) {
|
|
844
|
+
result = _traverse(
|
|
845
|
+
node1Index32,
|
|
846
|
+
cl2,
|
|
847
|
+
matrix2to1,
|
|
848
|
+
matrix1to2,
|
|
849
|
+
intersectsRangesFunc,
|
|
850
|
+
node1IndexOffset,
|
|
851
|
+
node2IndexOffset,
|
|
852
|
+
depth1,
|
|
853
|
+
depth2 + 1,
|
|
854
|
+
currBox,
|
|
855
|
+
reversed
|
|
856
|
+
) || _traverse(
|
|
857
|
+
node1Index32,
|
|
858
|
+
cr2,
|
|
859
|
+
matrix2to1,
|
|
860
|
+
matrix1to2,
|
|
861
|
+
intersectsRangesFunc,
|
|
862
|
+
node1IndexOffset,
|
|
863
|
+
node2IndexOffset,
|
|
864
|
+
depth1,
|
|
865
|
+
depth2 + 1,
|
|
866
|
+
currBox,
|
|
867
|
+
reversed
|
|
868
|
+
);
|
|
869
|
+
} else if (leftIntersects) {
|
|
870
|
+
if (isLeaf1) {
|
|
871
|
+
result = _traverse(
|
|
872
|
+
node1Index32,
|
|
873
|
+
cl2,
|
|
874
|
+
matrix2to1,
|
|
875
|
+
matrix1to2,
|
|
876
|
+
intersectsRangesFunc,
|
|
877
|
+
node1IndexOffset,
|
|
878
|
+
node2IndexOffset,
|
|
879
|
+
depth1,
|
|
880
|
+
depth2 + 1,
|
|
881
|
+
currBox,
|
|
882
|
+
reversed
|
|
883
|
+
);
|
|
884
|
+
} else {
|
|
885
|
+
const newBox = _boxPool.getPrimitive();
|
|
886
|
+
newBox.copy(_leftBox2).applyMatrix4(matrix2to1);
|
|
887
|
+
const cl1 = LEFT_NODE(node1Index32);
|
|
888
|
+
const cr1 = RIGHT_NODE(node1Index32, uint32Array1);
|
|
889
|
+
arrayToBox(BOUNDING_DATA_INDEX(cl1), float32Array1, _leftBox1);
|
|
890
|
+
arrayToBox(BOUNDING_DATA_INDEX(cr1), float32Array1, _rightBox1);
|
|
891
|
+
const intersectCl1 = newBox.intersectsBox(_leftBox1);
|
|
892
|
+
const intersectCr1 = newBox.intersectsBox(_rightBox1);
|
|
893
|
+
result = intersectCl1 && _traverse(
|
|
894
|
+
cl2,
|
|
895
|
+
cl1,
|
|
896
|
+
matrix1to2,
|
|
897
|
+
matrix2to1,
|
|
898
|
+
intersectsRangesFunc,
|
|
899
|
+
node2IndexOffset,
|
|
900
|
+
node1IndexOffset,
|
|
901
|
+
depth2,
|
|
902
|
+
depth1 + 1,
|
|
903
|
+
newBox,
|
|
904
|
+
!reversed
|
|
905
|
+
) || intersectCr1 && _traverse(
|
|
906
|
+
cl2,
|
|
907
|
+
cr1,
|
|
908
|
+
matrix1to2,
|
|
909
|
+
matrix2to1,
|
|
910
|
+
intersectsRangesFunc,
|
|
911
|
+
node2IndexOffset,
|
|
912
|
+
node1IndexOffset,
|
|
913
|
+
depth2,
|
|
914
|
+
depth1 + 1,
|
|
915
|
+
newBox,
|
|
916
|
+
!reversed
|
|
917
|
+
);
|
|
918
|
+
_boxPool.releasePrimitive(newBox);
|
|
919
|
+
}
|
|
920
|
+
} else if (rightIntersects) {
|
|
921
|
+
if (isLeaf1) {
|
|
922
|
+
result = _traverse(
|
|
923
|
+
node1Index32,
|
|
924
|
+
cr2,
|
|
925
|
+
matrix2to1,
|
|
926
|
+
matrix1to2,
|
|
927
|
+
intersectsRangesFunc,
|
|
928
|
+
node1IndexOffset,
|
|
929
|
+
node2IndexOffset,
|
|
930
|
+
depth1,
|
|
931
|
+
depth2 + 1,
|
|
932
|
+
currBox,
|
|
933
|
+
reversed
|
|
934
|
+
);
|
|
935
|
+
} else {
|
|
936
|
+
const newBox = _boxPool.getPrimitive();
|
|
937
|
+
newBox.copy(_rightBox2).applyMatrix4(matrix2to1);
|
|
938
|
+
const cl1 = LEFT_NODE(node1Index32);
|
|
939
|
+
const cr1 = RIGHT_NODE(node1Index32, uint32Array1);
|
|
940
|
+
arrayToBox(BOUNDING_DATA_INDEX(cl1), float32Array1, _leftBox1);
|
|
941
|
+
arrayToBox(BOUNDING_DATA_INDEX(cr1), float32Array1, _rightBox1);
|
|
942
|
+
const intersectCl1 = newBox.intersectsBox(_leftBox1);
|
|
943
|
+
const intersectCr1 = newBox.intersectsBox(_rightBox1);
|
|
944
|
+
result = intersectCl1 && _traverse(
|
|
945
|
+
cr2,
|
|
946
|
+
cl1,
|
|
947
|
+
matrix1to2,
|
|
948
|
+
matrix2to1,
|
|
949
|
+
intersectsRangesFunc,
|
|
950
|
+
node2IndexOffset,
|
|
951
|
+
node1IndexOffset,
|
|
952
|
+
depth2,
|
|
953
|
+
depth1 + 1,
|
|
954
|
+
newBox,
|
|
955
|
+
!reversed
|
|
956
|
+
) || intersectCr1 && _traverse(
|
|
957
|
+
cr2,
|
|
958
|
+
cr1,
|
|
959
|
+
matrix1to2,
|
|
960
|
+
matrix2to1,
|
|
961
|
+
intersectsRangesFunc,
|
|
962
|
+
node2IndexOffset,
|
|
963
|
+
node1IndexOffset,
|
|
964
|
+
depth2,
|
|
965
|
+
depth1 + 1,
|
|
966
|
+
newBox,
|
|
967
|
+
!reversed
|
|
968
|
+
);
|
|
969
|
+
_boxPool.releasePrimitive(newBox);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
return result;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// node_modules/three-mesh-bvh/src/core/BVHTraversalHelper.js
|
|
977
|
+
var BVHTraversalHelper = new class {
|
|
978
|
+
constructor() {
|
|
979
|
+
let buffer = null;
|
|
980
|
+
let uint32Array2 = null;
|
|
981
|
+
let uint16Array2 = null;
|
|
982
|
+
let traversing = false;
|
|
983
|
+
this.root = null;
|
|
984
|
+
this.buffer = null;
|
|
985
|
+
this.uint32Array = null;
|
|
986
|
+
this.uint16Array = null;
|
|
987
|
+
this.setBVH = (bvh, root) => {
|
|
988
|
+
if (traversing) {
|
|
989
|
+
throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");
|
|
990
|
+
}
|
|
991
|
+
this.root = root;
|
|
992
|
+
this.buffer = buffer = bvh._roots[root];
|
|
993
|
+
this.uint16Array = uint16Array2 = new Uint16Array(buffer);
|
|
994
|
+
this.uint32Array = uint32Array2 = new Uint32Array(buffer);
|
|
995
|
+
};
|
|
996
|
+
this.reset = () => {
|
|
997
|
+
this.root = null;
|
|
998
|
+
this.buffer = buffer = null;
|
|
999
|
+
this.uint16Array = uint16Array2 = null;
|
|
1000
|
+
this.uint32Array = uint32Array2 = null;
|
|
1001
|
+
};
|
|
1002
|
+
this.getRangeStart = (node32Index) => {
|
|
1003
|
+
let node16Index = node32Index * 2;
|
|
1004
|
+
while (!IS_LEAF(node16Index, uint16Array2)) {
|
|
1005
|
+
node32Index = LEFT_NODE(node32Index);
|
|
1006
|
+
node16Index = node32Index * 2;
|
|
1007
|
+
}
|
|
1008
|
+
return OFFSET(node32Index, uint32Array2);
|
|
1009
|
+
};
|
|
1010
|
+
this.getRangeEnd = (node32Index) => {
|
|
1011
|
+
let node16Index = node32Index * 2;
|
|
1012
|
+
while (!IS_LEAF(node16Index, uint16Array2)) {
|
|
1013
|
+
node32Index = RIGHT_NODE(node32Index, uint32Array2);
|
|
1014
|
+
node16Index = node32Index * 2;
|
|
1015
|
+
}
|
|
1016
|
+
return OFFSET(node32Index, uint32Array2) + COUNT(node16Index, uint16Array2);
|
|
1017
|
+
};
|
|
1018
|
+
const walk = (callback, node32Index, depth) => {
|
|
1019
|
+
const node16Index = node32Index * 2;
|
|
1020
|
+
const isLeaf = IS_LEAF(node16Index, uint16Array2);
|
|
1021
|
+
const stopTraversal = callback(depth, isLeaf, node32Index);
|
|
1022
|
+
if (!stopTraversal && !isLeaf) {
|
|
1023
|
+
const left = LEFT_NODE(node32Index);
|
|
1024
|
+
const right = RIGHT_NODE(node32Index, uint32Array2);
|
|
1025
|
+
walk(callback, left, depth + 1);
|
|
1026
|
+
walk(callback, right, depth + 1);
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
this.traverseBuffer = (callback) => {
|
|
1030
|
+
if (traversing) {
|
|
1031
|
+
throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");
|
|
1032
|
+
}
|
|
1033
|
+
traversing = true;
|
|
1034
|
+
try {
|
|
1035
|
+
walk(callback, 0, 0);
|
|
1036
|
+
} finally {
|
|
1037
|
+
traversing = false;
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
this.traverse = (callback) => {
|
|
1041
|
+
this.traverseBuffer((depth, isLeaf, node32Index) => {
|
|
1042
|
+
if (isLeaf) {
|
|
1043
|
+
const node16Index = node32Index * 2;
|
|
1044
|
+
const offset = uint32Array2[node32Index + 6];
|
|
1045
|
+
const count = uint16Array2[node16Index + 14];
|
|
1046
|
+
return callback(depth, isLeaf, new Float32Array(buffer, node32Index * 4, 6), offset, count);
|
|
1047
|
+
} else {
|
|
1048
|
+
const splitAxis = SPLIT_AXIS(node32Index, uint32Array2);
|
|
1049
|
+
return callback(depth, isLeaf, new Float32Array(buffer, node32Index * 4, 6), splitAxis);
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
}();
|
|
1055
|
+
|
|
1056
|
+
// node_modules/three-mesh-bvh/src/core/BVH.js
|
|
1057
|
+
var _tempBox = /* @__PURE__ */ new Box33();
|
|
1058
|
+
var _tempBuffer = /* @__PURE__ */ new Float32Array(6);
|
|
1059
|
+
var BVH = class {
|
|
1060
|
+
constructor() {
|
|
1061
|
+
this._roots = null;
|
|
1062
|
+
this.primitiveBuffer = null;
|
|
1063
|
+
this.primitiveBufferStride = null;
|
|
1064
|
+
}
|
|
1065
|
+
init(options) {
|
|
1066
|
+
options = {
|
|
1067
|
+
...DEFAULT_OPTIONS,
|
|
1068
|
+
...options
|
|
1069
|
+
};
|
|
1070
|
+
if ("maxLeafSize" in options) {
|
|
1071
|
+
console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.');
|
|
1072
|
+
options = {
|
|
1073
|
+
...options,
|
|
1074
|
+
targetLeafSize: options.maxLeafSize
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
buildPackedTree(this, options);
|
|
1078
|
+
}
|
|
1079
|
+
getRootRanges() {
|
|
1080
|
+
throw new Error("BVH: getRootRanges() not implemented");
|
|
1081
|
+
}
|
|
1082
|
+
// write the i-th primitive bounds in a 6-value min / max format to the buffer
|
|
1083
|
+
// starting at the given "writeOffset"
|
|
1084
|
+
writePrimitiveBounds() {
|
|
1085
|
+
throw new Error("BVH: writePrimitiveBounds() not implemented");
|
|
1086
|
+
}
|
|
1087
|
+
// writes the union bounds of all primitives in the given range in a min / max format
|
|
1088
|
+
// to the buffer
|
|
1089
|
+
writePrimitiveRangeBounds(offset, count, targetBuffer, baseIndex) {
|
|
1090
|
+
let minX = Infinity;
|
|
1091
|
+
let minY = Infinity;
|
|
1092
|
+
let minZ = Infinity;
|
|
1093
|
+
let maxX = -Infinity;
|
|
1094
|
+
let maxY = -Infinity;
|
|
1095
|
+
let maxZ = -Infinity;
|
|
1096
|
+
for (let i = offset, end = offset + count; i < end; i++) {
|
|
1097
|
+
this.writePrimitiveBounds(i, _tempBuffer, 0);
|
|
1098
|
+
const [lx, ly, lz, rx, ry, rz] = _tempBuffer;
|
|
1099
|
+
if (lx < minX) minX = lx;
|
|
1100
|
+
if (rx > maxX) maxX = rx;
|
|
1101
|
+
if (ly < minY) minY = ly;
|
|
1102
|
+
if (ry > maxY) maxY = ry;
|
|
1103
|
+
if (lz < minZ) minZ = lz;
|
|
1104
|
+
if (rz > maxZ) maxZ = rz;
|
|
1105
|
+
}
|
|
1106
|
+
targetBuffer[baseIndex + 0] = minX;
|
|
1107
|
+
targetBuffer[baseIndex + 1] = minY;
|
|
1108
|
+
targetBuffer[baseIndex + 2] = minZ;
|
|
1109
|
+
targetBuffer[baseIndex + 3] = maxX;
|
|
1110
|
+
targetBuffer[baseIndex + 4] = maxY;
|
|
1111
|
+
targetBuffer[baseIndex + 5] = maxZ;
|
|
1112
|
+
return targetBuffer;
|
|
1113
|
+
}
|
|
1114
|
+
computePrimitiveBounds(offset, count, targetBuffer) {
|
|
1115
|
+
const boundsOffset = targetBuffer.offset || 0;
|
|
1116
|
+
for (let i = offset, end = offset + count; i < end; i++) {
|
|
1117
|
+
this.writePrimitiveBounds(i, _tempBuffer, 0);
|
|
1118
|
+
const [lx, ly, lz, rx, ry, rz] = _tempBuffer;
|
|
1119
|
+
const cx = (lx + rx) / 2;
|
|
1120
|
+
const cy = (ly + ry) / 2;
|
|
1121
|
+
const cz = (lz + rz) / 2;
|
|
1122
|
+
const hx = (rx - lx) / 2;
|
|
1123
|
+
const hy = (ry - ly) / 2;
|
|
1124
|
+
const hz = (rz - lz) / 2;
|
|
1125
|
+
const baseIndex = (i - boundsOffset) * 6;
|
|
1126
|
+
targetBuffer[baseIndex + 0] = cx;
|
|
1127
|
+
targetBuffer[baseIndex + 1] = hx + (Math.abs(cx) + hx) * FLOAT32_EPSILON;
|
|
1128
|
+
targetBuffer[baseIndex + 2] = cy;
|
|
1129
|
+
targetBuffer[baseIndex + 3] = hy + (Math.abs(cy) + hy) * FLOAT32_EPSILON;
|
|
1130
|
+
targetBuffer[baseIndex + 4] = cz;
|
|
1131
|
+
targetBuffer[baseIndex + 5] = hz + (Math.abs(cz) + hz) * FLOAT32_EPSILON;
|
|
1132
|
+
}
|
|
1133
|
+
return targetBuffer;
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Adjusts all primitive offsets stored in the BVH leaf nodes by the given value. Useful when
|
|
1137
|
+
* geometry buffers have been shifted or compacted (e.g. when merging geometries).
|
|
1138
|
+
* @param {number} offset
|
|
1139
|
+
*/
|
|
1140
|
+
shiftPrimitiveOffsets(offset) {
|
|
1141
|
+
const indirectBuffer = this._indirectBuffer;
|
|
1142
|
+
if (indirectBuffer) {
|
|
1143
|
+
for (let i = 0, l = indirectBuffer.length; i < l; i++) {
|
|
1144
|
+
indirectBuffer[i] += offset;
|
|
1145
|
+
}
|
|
1146
|
+
} else {
|
|
1147
|
+
const roots = this._roots;
|
|
1148
|
+
for (let rootIndex = 0; rootIndex < roots.length; rootIndex++) {
|
|
1149
|
+
const root = roots[rootIndex];
|
|
1150
|
+
const uint32Array2 = new Uint32Array(root);
|
|
1151
|
+
const uint16Array2 = new Uint16Array(root);
|
|
1152
|
+
const totalNodes = root.byteLength / BYTES_PER_NODE;
|
|
1153
|
+
for (let node = 0; node < totalNodes; node++) {
|
|
1154
|
+
const node32Index = UINT32_PER_NODE * node;
|
|
1155
|
+
const node16Index = 2 * node32Index;
|
|
1156
|
+
if (IS_LEAF(node16Index, uint16Array2)) {
|
|
1157
|
+
uint32Array2[node32Index + 6] += offset;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Traverses all nodes of the BVH, invoking a callback for each node.
|
|
1165
|
+
*
|
|
1166
|
+
* For leaf nodes the callback receives `( depth, isLeaf, boundingData, offset, count )`.
|
|
1167
|
+
* For internal nodes it receives `( depth, isLeaf, boundingData, splitAxis )` and may
|
|
1168
|
+
* return `true` to stop descending into that node's children.
|
|
1169
|
+
*
|
|
1170
|
+
* @param {Function} callback
|
|
1171
|
+
* @param {number} [rootIndex=0]
|
|
1172
|
+
*/
|
|
1173
|
+
traverse(callback, rootIndex = 0) {
|
|
1174
|
+
BVHTraversalHelper.setBVH(this, rootIndex);
|
|
1175
|
+
BVHTraversalHelper.traverse(callback);
|
|
1176
|
+
BVHTraversalHelper.reset();
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Refits all BVH node bounds to reflect the current primitive positions. Faster than
|
|
1180
|
+
* rebuilding the BVH but produces a less optimal tree after large vertex deformations.
|
|
1181
|
+
*/
|
|
1182
|
+
refit() {
|
|
1183
|
+
const roots = this._roots;
|
|
1184
|
+
for (let rootIndex = 0, rootCount = roots.length; rootIndex < rootCount; rootIndex++) {
|
|
1185
|
+
const buffer = roots[rootIndex];
|
|
1186
|
+
const uint32Array2 = new Uint32Array(buffer);
|
|
1187
|
+
const uint16Array2 = new Uint16Array(buffer);
|
|
1188
|
+
const float32Array2 = new Float32Array(buffer);
|
|
1189
|
+
const totalNodes = buffer.byteLength / BYTES_PER_NODE;
|
|
1190
|
+
for (let nodeIndex = totalNodes - 1; nodeIndex >= 0; nodeIndex--) {
|
|
1191
|
+
const nodeIndex32 = nodeIndex * UINT32_PER_NODE;
|
|
1192
|
+
const nodeIndex16 = nodeIndex32 * 2;
|
|
1193
|
+
const isLeaf = IS_LEAF(nodeIndex16, uint16Array2);
|
|
1194
|
+
if (isLeaf) {
|
|
1195
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
1196
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
1197
|
+
this.writePrimitiveRangeBounds(offset, count, _tempBuffer, 0);
|
|
1198
|
+
float32Array2.set(_tempBuffer, nodeIndex32);
|
|
1199
|
+
} else {
|
|
1200
|
+
const left = LEFT_NODE(nodeIndex32);
|
|
1201
|
+
const right = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
1202
|
+
for (let i = 0; i < 3; i++) {
|
|
1203
|
+
const leftMin = float32Array2[left + i];
|
|
1204
|
+
const leftMax = float32Array2[left + i + 3];
|
|
1205
|
+
const rightMin = float32Array2[right + i];
|
|
1206
|
+
const rightMax = float32Array2[right + i + 3];
|
|
1207
|
+
float32Array2[nodeIndex32 + i] = leftMin < rightMin ? leftMin : rightMin;
|
|
1208
|
+
float32Array2[nodeIndex32 + i + 3] = leftMax > rightMax ? leftMax : rightMax;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Computes the axis-aligned bounding box of all primitives in the BVH.
|
|
1216
|
+
* @param {Box3} target - Target box to write the result into.
|
|
1217
|
+
* @returns {Box3}
|
|
1218
|
+
*/
|
|
1219
|
+
getBoundingBox(target) {
|
|
1220
|
+
target.makeEmpty();
|
|
1221
|
+
const roots = this._roots;
|
|
1222
|
+
roots.forEach((buffer) => {
|
|
1223
|
+
arrayToBox(0, new Float32Array(buffer), _tempBox);
|
|
1224
|
+
target.union(_tempBox);
|
|
1225
|
+
});
|
|
1226
|
+
return target;
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* A generalized traversal function for performing spatial queries against the BVH. Returns
|
|
1230
|
+
* `true` as soon as a primitive has been reported as intersected. The tree is traversed
|
|
1231
|
+
* depth-first; `boundsTraverseOrder` controls which child is visited first. Returning
|
|
1232
|
+
* `CONTAINED` from `intersectsBounds` skips further child traversal and intersects all
|
|
1233
|
+
* primitives in that subtree immediately.
|
|
1234
|
+
*
|
|
1235
|
+
* @param {Object} callbacks
|
|
1236
|
+
* @param {IntersectsBoundsCallback} callbacks.intersectsBounds
|
|
1237
|
+
* @param {IntersectsRangeCallback} [callbacks.intersectsRange]
|
|
1238
|
+
* @param {BoundsTraverseOrderCallback} [callbacks.boundsTraverseOrder]
|
|
1239
|
+
* @returns {boolean}
|
|
1240
|
+
*/
|
|
1241
|
+
// TODO: see if we can get rid of "iterateFunc" here as well as the primitive so the function
|
|
1242
|
+
// API aligns with the "shapecast" implementation
|
|
1243
|
+
shapecast(callbacks) {
|
|
1244
|
+
let {
|
|
1245
|
+
boundsTraverseOrder,
|
|
1246
|
+
intersectsBounds,
|
|
1247
|
+
intersectsRange,
|
|
1248
|
+
intersectsPrimitive,
|
|
1249
|
+
scratchPrimitive,
|
|
1250
|
+
iterate
|
|
1251
|
+
} = callbacks;
|
|
1252
|
+
if (intersectsRange && intersectsPrimitive) {
|
|
1253
|
+
const originalIntersectsRange = intersectsRange;
|
|
1254
|
+
intersectsRange = (offset, count, contained, depth, nodeIndex) => {
|
|
1255
|
+
if (!originalIntersectsRange(offset, count, contained, depth, nodeIndex)) {
|
|
1256
|
+
return iterate(offset, count, this, intersectsPrimitive, contained, depth, scratchPrimitive);
|
|
1257
|
+
}
|
|
1258
|
+
return true;
|
|
1259
|
+
};
|
|
1260
|
+
} else if (!intersectsRange) {
|
|
1261
|
+
if (intersectsPrimitive) {
|
|
1262
|
+
intersectsRange = (offset, count, contained, depth) => {
|
|
1263
|
+
return iterate(offset, count, this, intersectsPrimitive, contained, depth, scratchPrimitive);
|
|
1264
|
+
};
|
|
1265
|
+
} else {
|
|
1266
|
+
intersectsRange = (offset, count, contained) => {
|
|
1267
|
+
return contained;
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
let result = false;
|
|
1272
|
+
let nodeOffset = 0;
|
|
1273
|
+
const roots = this._roots;
|
|
1274
|
+
for (let i = 0, l = roots.length; i < l; i++) {
|
|
1275
|
+
const root = roots[i];
|
|
1276
|
+
result = shapecast(this, i, intersectsBounds, intersectsRange, boundsTraverseOrder, nodeOffset);
|
|
1277
|
+
if (result) {
|
|
1278
|
+
break;
|
|
1279
|
+
}
|
|
1280
|
+
nodeOffset += root.byteLength / BYTES_PER_NODE;
|
|
1281
|
+
}
|
|
1282
|
+
return result;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Simultaneously traverses two BVH structures to find intersecting primitive pairs. Returns
|
|
1286
|
+
* `true` as soon as any intersection is reported. Both trees are traversed depth-first with
|
|
1287
|
+
* alternating descent. `matrixToLocal` transforms `otherBvh` into the local space of this BVH.
|
|
1288
|
+
*
|
|
1289
|
+
* @param {BVH} otherBvh
|
|
1290
|
+
* @param {Matrix4} matrixToLocal
|
|
1291
|
+
* @param {Object} callbacks
|
|
1292
|
+
* @param {IntersectsRangesCallback} callbacks.intersectsRanges
|
|
1293
|
+
* @returns {boolean}
|
|
1294
|
+
*/
|
|
1295
|
+
bvhcast(otherBvh, matrixToLocal, callbacks) {
|
|
1296
|
+
let { intersectsRanges } = callbacks;
|
|
1297
|
+
return bvhcast(this, otherBvh, matrixToLocal, intersectsRanges);
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
// node_modules/three-mesh-bvh/src/core/GeometryBVH.js
|
|
1302
|
+
import { Box3 as Box34 } from "three";
|
|
1303
|
+
|
|
1304
|
+
// node_modules/three-mesh-bvh/src/utils/BufferUtils.js
|
|
1305
|
+
function isSharedArrayBufferSupported() {
|
|
1306
|
+
return typeof SharedArrayBuffer !== "undefined";
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// node_modules/three-mesh-bvh/src/core/build/geometryUtils.js
|
|
1310
|
+
import { BufferAttribute } from "three";
|
|
1311
|
+
function getVertexCount(geo) {
|
|
1312
|
+
return geo.index ? geo.index.count : geo.attributes.position.count;
|
|
1313
|
+
}
|
|
1314
|
+
function getTriCount(geo) {
|
|
1315
|
+
return getVertexCount(geo) / 3;
|
|
1316
|
+
}
|
|
1317
|
+
function getIndexArray(vertexCount, BufferConstructor = ArrayBuffer) {
|
|
1318
|
+
if (vertexCount > 65535) {
|
|
1319
|
+
return new Uint32Array(new BufferConstructor(4 * vertexCount));
|
|
1320
|
+
} else {
|
|
1321
|
+
return new Uint16Array(new BufferConstructor(2 * vertexCount));
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
function ensureIndex(geo, options) {
|
|
1325
|
+
if (!geo.index) {
|
|
1326
|
+
const vertexCount = geo.attributes.position.count;
|
|
1327
|
+
const BufferConstructor = options.useSharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer;
|
|
1328
|
+
const index = getIndexArray(vertexCount, BufferConstructor);
|
|
1329
|
+
geo.setIndex(new BufferAttribute(index, 1));
|
|
1330
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
1331
|
+
index[i] = i;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
function getFullPrimitiveRange(geo, range, stride) {
|
|
1336
|
+
const primitiveCount = getVertexCount(geo) / stride;
|
|
1337
|
+
const drawRange = range ? range : geo.drawRange;
|
|
1338
|
+
const start = drawRange.start / stride;
|
|
1339
|
+
const end = (drawRange.start + drawRange.count) / stride;
|
|
1340
|
+
const offset = Math.max(0, start);
|
|
1341
|
+
const count = Math.min(primitiveCount, end) - offset;
|
|
1342
|
+
return {
|
|
1343
|
+
offset: Math.floor(offset),
|
|
1344
|
+
count: Math.floor(count)
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
function getPrimitiveGroupRanges(geo, stride) {
|
|
1348
|
+
return geo.groups.map((group) => ({
|
|
1349
|
+
offset: group.start / stride,
|
|
1350
|
+
count: group.count / stride
|
|
1351
|
+
}));
|
|
1352
|
+
}
|
|
1353
|
+
function getRootPrimitiveRanges(geo, range, stride) {
|
|
1354
|
+
const drawRange = getFullPrimitiveRange(geo, range, stride);
|
|
1355
|
+
const primitiveRanges = getPrimitiveGroupRanges(geo, stride);
|
|
1356
|
+
if (!primitiveRanges.length) {
|
|
1357
|
+
return [drawRange];
|
|
1358
|
+
}
|
|
1359
|
+
const ranges = [];
|
|
1360
|
+
const drawRangeStart = drawRange.offset;
|
|
1361
|
+
const drawRangeEnd = drawRange.offset + drawRange.count;
|
|
1362
|
+
const primitiveCount = getVertexCount(geo) / stride;
|
|
1363
|
+
const events = [];
|
|
1364
|
+
for (const group of primitiveRanges) {
|
|
1365
|
+
const { offset, count } = group;
|
|
1366
|
+
const groupStart = offset;
|
|
1367
|
+
const groupCount = isFinite(count) ? count : primitiveCount - offset;
|
|
1368
|
+
const groupEnd = offset + groupCount;
|
|
1369
|
+
if (groupStart < drawRangeEnd && groupEnd > drawRangeStart) {
|
|
1370
|
+
events.push({ pos: Math.max(drawRangeStart, groupStart), isStart: true });
|
|
1371
|
+
events.push({ pos: Math.min(drawRangeEnd, groupEnd), isStart: false });
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
events.sort((a, b) => {
|
|
1375
|
+
if (a.pos !== b.pos) {
|
|
1376
|
+
return a.pos - b.pos;
|
|
1377
|
+
} else {
|
|
1378
|
+
return a.type === "end" ? -1 : 1;
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
let activeGroups = 0;
|
|
1382
|
+
let lastPos = null;
|
|
1383
|
+
for (const event of events) {
|
|
1384
|
+
const newPos = event.pos;
|
|
1385
|
+
if (activeGroups !== 0 && newPos !== lastPos) {
|
|
1386
|
+
ranges.push({
|
|
1387
|
+
offset: lastPos,
|
|
1388
|
+
count: newPos - lastPos
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
activeGroups += event.isStart ? 1 : -1;
|
|
1392
|
+
lastPos = newPos;
|
|
1393
|
+
}
|
|
1394
|
+
return ranges;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// node_modules/three-mesh-bvh/src/core/GeometryBVH.js
|
|
1398
|
+
function generateIndirectBuffer(ranges, useSharedArrayBuffer) {
|
|
1399
|
+
const lastRange = ranges[ranges.length - 1];
|
|
1400
|
+
const useUint32 = lastRange.offset + lastRange.count > 2 ** 16;
|
|
1401
|
+
const length = ranges.reduce((acc, val) => acc + val.count, 0);
|
|
1402
|
+
const byteCount = useUint32 ? 4 : 2;
|
|
1403
|
+
const buffer = useSharedArrayBuffer ? new SharedArrayBuffer(length * byteCount) : new ArrayBuffer(length * byteCount);
|
|
1404
|
+
const indirectBuffer = useUint32 ? new Uint32Array(buffer) : new Uint16Array(buffer);
|
|
1405
|
+
let index = 0;
|
|
1406
|
+
for (let r = 0; r < ranges.length; r++) {
|
|
1407
|
+
const { offset, count } = ranges[r];
|
|
1408
|
+
for (let i = 0; i < count; i++) {
|
|
1409
|
+
indirectBuffer[index + i] = offset + i;
|
|
1410
|
+
}
|
|
1411
|
+
index += count;
|
|
1412
|
+
}
|
|
1413
|
+
return indirectBuffer;
|
|
1414
|
+
}
|
|
1415
|
+
var GeometryBVH = class extends BVH {
|
|
1416
|
+
/**
|
|
1417
|
+
* Whether the BVH was built in indirect mode.
|
|
1418
|
+
* @type {boolean}
|
|
1419
|
+
* @readonly
|
|
1420
|
+
*/
|
|
1421
|
+
get indirect() {
|
|
1422
|
+
return !!this._indirectBuffer;
|
|
1423
|
+
}
|
|
1424
|
+
get primitiveStride() {
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
get primitiveBufferStride() {
|
|
1428
|
+
return this.indirect ? 1 : this.primitiveStride;
|
|
1429
|
+
}
|
|
1430
|
+
set primitiveBufferStride(v) {
|
|
1431
|
+
}
|
|
1432
|
+
get primitiveBuffer() {
|
|
1433
|
+
return this.indirect ? this._indirectBuffer : this.geometry.index.array;
|
|
1434
|
+
}
|
|
1435
|
+
set primitiveBuffer(v) {
|
|
1436
|
+
}
|
|
1437
|
+
constructor(geometry, options = {}) {
|
|
1438
|
+
if (!geometry.isBufferGeometry) {
|
|
1439
|
+
throw new Error("BVH: Only BufferGeometries are supported.");
|
|
1440
|
+
} else if (geometry.index && geometry.index.isInterleavedBufferAttribute) {
|
|
1441
|
+
throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.");
|
|
1442
|
+
}
|
|
1443
|
+
if (options.useSharedArrayBuffer && !isSharedArrayBufferSupported()) {
|
|
1444
|
+
throw new Error("BVH: SharedArrayBuffer is not available.");
|
|
1445
|
+
}
|
|
1446
|
+
super();
|
|
1447
|
+
this.geometry = geometry;
|
|
1448
|
+
this.resolvePrimitiveIndex = options.indirect ? (i) => this._indirectBuffer[i] : (i) => i;
|
|
1449
|
+
this.primitiveBuffer = null;
|
|
1450
|
+
this.primitiveBufferStride = null;
|
|
1451
|
+
this._indirectBuffer = null;
|
|
1452
|
+
options = {
|
|
1453
|
+
...DEFAULT_OPTIONS,
|
|
1454
|
+
...options
|
|
1455
|
+
};
|
|
1456
|
+
if (!options[SKIP_GENERATION]) {
|
|
1457
|
+
this.init(options);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
init(options) {
|
|
1461
|
+
const { geometry, primitiveStride } = this;
|
|
1462
|
+
if (options.indirect) {
|
|
1463
|
+
const ranges = getRootPrimitiveRanges(geometry, options.range, primitiveStride);
|
|
1464
|
+
const indirectBuffer = generateIndirectBuffer(ranges, options.useSharedArrayBuffer);
|
|
1465
|
+
this._indirectBuffer = indirectBuffer;
|
|
1466
|
+
} else {
|
|
1467
|
+
ensureIndex(geometry, options);
|
|
1468
|
+
}
|
|
1469
|
+
super.init(options);
|
|
1470
|
+
if (!geometry.boundingBox && options.setBoundingBox) {
|
|
1471
|
+
geometry.boundingBox = this.getBoundingBox(new Box34());
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
// Abstract methods to be implemented by subclasses
|
|
1475
|
+
getRootRanges(range) {
|
|
1476
|
+
if (this.indirect) {
|
|
1477
|
+
return [{ offset: 0, count: this._indirectBuffer.length }];
|
|
1478
|
+
} else {
|
|
1479
|
+
return getRootPrimitiveRanges(this.geometry, range, this.primitiveStride);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
raycastObject3D() {
|
|
1483
|
+
throw new Error("BVH: raycastObject3D() not implemented");
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
// node_modules/three-mesh-bvh/src/core/MeshBVH.js
|
|
1488
|
+
import { BufferAttribute as BufferAttribute2, FrontSide, Ray, Vector3 as Vector310, Matrix4 as Matrix47 } from "three";
|
|
1489
|
+
|
|
1490
|
+
// node_modules/three-mesh-bvh/src/math/OrientedBox.js
|
|
1491
|
+
import { Vector3 as Vector34, Matrix4 as Matrix42, Line3 as Line33 } from "three";
|
|
1492
|
+
|
|
1493
|
+
// node_modules/three-mesh-bvh/src/math/SeparatingAxisBounds.js
|
|
1494
|
+
import { Vector3 } from "three";
|
|
1495
|
+
var SeparatingAxisBounds = class {
|
|
1496
|
+
constructor() {
|
|
1497
|
+
this.min = Infinity;
|
|
1498
|
+
this.max = -Infinity;
|
|
1499
|
+
}
|
|
1500
|
+
setFromPointsField(points, field) {
|
|
1501
|
+
let min = Infinity;
|
|
1502
|
+
let max = -Infinity;
|
|
1503
|
+
for (let i = 0, l = points.length; i < l; i++) {
|
|
1504
|
+
const p = points[i];
|
|
1505
|
+
const val = p[field];
|
|
1506
|
+
min = val < min ? val : min;
|
|
1507
|
+
max = val > max ? val : max;
|
|
1508
|
+
}
|
|
1509
|
+
this.min = min;
|
|
1510
|
+
this.max = max;
|
|
1511
|
+
}
|
|
1512
|
+
setFromPoints(axis, points) {
|
|
1513
|
+
let min = Infinity;
|
|
1514
|
+
let max = -Infinity;
|
|
1515
|
+
for (let i = 0, l = points.length; i < l; i++) {
|
|
1516
|
+
const p = points[i];
|
|
1517
|
+
const val = axis.dot(p);
|
|
1518
|
+
min = val < min ? val : min;
|
|
1519
|
+
max = val > max ? val : max;
|
|
1520
|
+
}
|
|
1521
|
+
this.min = min;
|
|
1522
|
+
this.max = max;
|
|
1523
|
+
}
|
|
1524
|
+
isSeparated(other) {
|
|
1525
|
+
return this.min > other.max || other.min > this.max;
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
SeparatingAxisBounds.prototype.setFromBox = /* @__PURE__ */ (function() {
|
|
1529
|
+
const p = /* @__PURE__ */ new Vector3();
|
|
1530
|
+
return function setFromBox(axis, box) {
|
|
1531
|
+
const boxMin = box.min;
|
|
1532
|
+
const boxMax = box.max;
|
|
1533
|
+
let min = Infinity;
|
|
1534
|
+
let max = -Infinity;
|
|
1535
|
+
for (let x = 0; x <= 1; x++) {
|
|
1536
|
+
for (let y = 0; y <= 1; y++) {
|
|
1537
|
+
for (let z = 0; z <= 1; z++) {
|
|
1538
|
+
p.x = boxMin.x * x + boxMax.x * (1 - x);
|
|
1539
|
+
p.y = boxMin.y * y + boxMax.y * (1 - y);
|
|
1540
|
+
p.z = boxMin.z * z + boxMax.z * (1 - z);
|
|
1541
|
+
const val = axis.dot(p);
|
|
1542
|
+
min = Math.min(val, min);
|
|
1543
|
+
max = Math.max(val, max);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
this.min = min;
|
|
1548
|
+
this.max = max;
|
|
1549
|
+
};
|
|
1550
|
+
})();
|
|
1551
|
+
|
|
1552
|
+
// node_modules/three-mesh-bvh/src/math/ExtendedTriangle.js
|
|
1553
|
+
import { Triangle, Vector3 as Vector33, Vector2 as Vector22, Line3 as Line32, Plane as Plane2 } from "three";
|
|
1554
|
+
|
|
1555
|
+
// node_modules/three-mesh-bvh/src/math/MathUtilities.js
|
|
1556
|
+
import { Vector3 as Vector32, Vector2, Plane, Line3 } from "three";
|
|
1557
|
+
var closestPointLineToLine = /* @__PURE__ */ (function() {
|
|
1558
|
+
const dir1 = /* @__PURE__ */ new Vector32();
|
|
1559
|
+
const dir2 = /* @__PURE__ */ new Vector32();
|
|
1560
|
+
const v02 = /* @__PURE__ */ new Vector32();
|
|
1561
|
+
return function closestPointLineToLine2(l1, l2, result) {
|
|
1562
|
+
const v0 = l1.start;
|
|
1563
|
+
const v10 = dir1;
|
|
1564
|
+
const v2 = l2.start;
|
|
1565
|
+
const v32 = dir2;
|
|
1566
|
+
v02.subVectors(v0, v2);
|
|
1567
|
+
dir1.subVectors(l1.end, l1.start);
|
|
1568
|
+
dir2.subVectors(l2.end, l2.start);
|
|
1569
|
+
const d0232 = v02.dot(v32);
|
|
1570
|
+
const d3210 = v32.dot(v10);
|
|
1571
|
+
const d3232 = v32.dot(v32);
|
|
1572
|
+
const d0210 = v02.dot(v10);
|
|
1573
|
+
const d1010 = v10.dot(v10);
|
|
1574
|
+
const denom = d1010 * d3232 - d3210 * d3210;
|
|
1575
|
+
let d, d2;
|
|
1576
|
+
if (denom !== 0) {
|
|
1577
|
+
d = (d0232 * d3210 - d0210 * d3232) / denom;
|
|
1578
|
+
} else {
|
|
1579
|
+
d = 0;
|
|
1580
|
+
}
|
|
1581
|
+
d2 = (d0232 + d * d3210) / d3232;
|
|
1582
|
+
result.x = d;
|
|
1583
|
+
result.y = d2;
|
|
1584
|
+
};
|
|
1585
|
+
})();
|
|
1586
|
+
var closestPointsSegmentToSegment = /* @__PURE__ */ (function() {
|
|
1587
|
+
const paramResult = /* @__PURE__ */ new Vector2();
|
|
1588
|
+
const temp14 = /* @__PURE__ */ new Vector32();
|
|
1589
|
+
const temp23 = /* @__PURE__ */ new Vector32();
|
|
1590
|
+
return function closestPointsSegmentToSegment2(l1, l2, target1, target2) {
|
|
1591
|
+
closestPointLineToLine(l1, l2, paramResult);
|
|
1592
|
+
let d = paramResult.x;
|
|
1593
|
+
let d2 = paramResult.y;
|
|
1594
|
+
if (d >= 0 && d <= 1 && d2 >= 0 && d2 <= 1) {
|
|
1595
|
+
l1.at(d, target1);
|
|
1596
|
+
l2.at(d2, target2);
|
|
1597
|
+
return;
|
|
1598
|
+
} else if (d >= 0 && d <= 1) {
|
|
1599
|
+
if (d2 < 0) {
|
|
1600
|
+
l2.at(0, target2);
|
|
1601
|
+
} else {
|
|
1602
|
+
l2.at(1, target2);
|
|
1603
|
+
}
|
|
1604
|
+
l1.closestPointToPoint(target2, true, target1);
|
|
1605
|
+
return;
|
|
1606
|
+
} else if (d2 >= 0 && d2 <= 1) {
|
|
1607
|
+
if (d < 0) {
|
|
1608
|
+
l1.at(0, target1);
|
|
1609
|
+
} else {
|
|
1610
|
+
l1.at(1, target1);
|
|
1611
|
+
}
|
|
1612
|
+
l2.closestPointToPoint(target1, true, target2);
|
|
1613
|
+
return;
|
|
1614
|
+
} else {
|
|
1615
|
+
let p;
|
|
1616
|
+
if (d < 0) {
|
|
1617
|
+
p = l1.start;
|
|
1618
|
+
} else {
|
|
1619
|
+
p = l1.end;
|
|
1620
|
+
}
|
|
1621
|
+
let p2;
|
|
1622
|
+
if (d2 < 0) {
|
|
1623
|
+
p2 = l2.start;
|
|
1624
|
+
} else {
|
|
1625
|
+
p2 = l2.end;
|
|
1626
|
+
}
|
|
1627
|
+
const closestPoint = temp14;
|
|
1628
|
+
const closestPoint2 = temp23;
|
|
1629
|
+
l1.closestPointToPoint(p2, true, temp14);
|
|
1630
|
+
l2.closestPointToPoint(p, true, temp23);
|
|
1631
|
+
if (closestPoint.distanceToSquared(p2) <= closestPoint2.distanceToSquared(p)) {
|
|
1632
|
+
target1.copy(closestPoint);
|
|
1633
|
+
target2.copy(p2);
|
|
1634
|
+
return;
|
|
1635
|
+
} else {
|
|
1636
|
+
target1.copy(p);
|
|
1637
|
+
target2.copy(closestPoint2);
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
})();
|
|
1643
|
+
var sphereIntersectTriangle = /* @__PURE__ */ (function() {
|
|
1644
|
+
const closestPointTemp = /* @__PURE__ */ new Vector32();
|
|
1645
|
+
const projectedPointTemp = /* @__PURE__ */ new Vector32();
|
|
1646
|
+
const planeTemp = /* @__PURE__ */ new Plane();
|
|
1647
|
+
const lineTemp = /* @__PURE__ */ new Line3();
|
|
1648
|
+
return function sphereIntersectTriangle2(sphere, triangle4) {
|
|
1649
|
+
const { radius, center } = sphere;
|
|
1650
|
+
const { a, b, c } = triangle4;
|
|
1651
|
+
lineTemp.start = a;
|
|
1652
|
+
lineTemp.end = b;
|
|
1653
|
+
const closestPoint1 = lineTemp.closestPointToPoint(center, true, closestPointTemp);
|
|
1654
|
+
if (closestPoint1.distanceTo(center) <= radius) return true;
|
|
1655
|
+
lineTemp.start = a;
|
|
1656
|
+
lineTemp.end = c;
|
|
1657
|
+
const closestPoint2 = lineTemp.closestPointToPoint(center, true, closestPointTemp);
|
|
1658
|
+
if (closestPoint2.distanceTo(center) <= radius) return true;
|
|
1659
|
+
lineTemp.start = b;
|
|
1660
|
+
lineTemp.end = c;
|
|
1661
|
+
const closestPoint3 = lineTemp.closestPointToPoint(center, true, closestPointTemp);
|
|
1662
|
+
if (closestPoint3.distanceTo(center) <= radius) return true;
|
|
1663
|
+
const plane = triangle4.getPlane(planeTemp);
|
|
1664
|
+
const dp = Math.abs(plane.distanceToPoint(center));
|
|
1665
|
+
if (dp <= radius) {
|
|
1666
|
+
const pp = plane.projectPoint(center, projectedPointTemp);
|
|
1667
|
+
const cp = triangle4.containsPoint(pp);
|
|
1668
|
+
if (cp) return true;
|
|
1669
|
+
}
|
|
1670
|
+
return false;
|
|
1671
|
+
};
|
|
1672
|
+
})();
|
|
1673
|
+
|
|
1674
|
+
// node_modules/three-mesh-bvh/src/math/ExtendedTriangle.js
|
|
1675
|
+
var componentKeys = ["x", "y", "z"];
|
|
1676
|
+
var ZERO_EPSILON = 1e-15;
|
|
1677
|
+
var ZERO_EPSILON_SQR = ZERO_EPSILON * ZERO_EPSILON;
|
|
1678
|
+
function isNearZero(value) {
|
|
1679
|
+
return Math.abs(value) < ZERO_EPSILON;
|
|
1680
|
+
}
|
|
1681
|
+
var ExtendedTriangle = class extends Triangle {
|
|
1682
|
+
constructor(...args) {
|
|
1683
|
+
super(...args);
|
|
1684
|
+
this.isExtendedTriangle = true;
|
|
1685
|
+
this.satAxes = new Array(4).fill().map(() => new Vector33());
|
|
1686
|
+
this.satBounds = new Array(4).fill().map(() => new SeparatingAxisBounds());
|
|
1687
|
+
this.points = [this.a, this.b, this.c];
|
|
1688
|
+
this.plane = new Plane2();
|
|
1689
|
+
this.isDegenerateIntoSegment = false;
|
|
1690
|
+
this.isDegenerateIntoPoint = false;
|
|
1691
|
+
this.degenerateSegment = new Line32();
|
|
1692
|
+
this.needsUpdate = true;
|
|
1693
|
+
}
|
|
1694
|
+
/**
|
|
1695
|
+
* Returns whether the triangle intersects the given sphere.
|
|
1696
|
+
* @param {Sphere} sphere
|
|
1697
|
+
* @returns {boolean}
|
|
1698
|
+
*/
|
|
1699
|
+
intersectsSphere(sphere) {
|
|
1700
|
+
return sphereIntersectTriangle(sphere, this);
|
|
1701
|
+
}
|
|
1702
|
+
update() {
|
|
1703
|
+
const a = this.a;
|
|
1704
|
+
const b = this.b;
|
|
1705
|
+
const c = this.c;
|
|
1706
|
+
const points = this.points;
|
|
1707
|
+
const satAxes = this.satAxes;
|
|
1708
|
+
const satBounds = this.satBounds;
|
|
1709
|
+
const axis0 = satAxes[0];
|
|
1710
|
+
const sab0 = satBounds[0];
|
|
1711
|
+
this.getNormal(axis0);
|
|
1712
|
+
sab0.setFromPoints(axis0, points);
|
|
1713
|
+
const axis1 = satAxes[1];
|
|
1714
|
+
const sab1 = satBounds[1];
|
|
1715
|
+
axis1.subVectors(a, b);
|
|
1716
|
+
sab1.setFromPoints(axis1, points);
|
|
1717
|
+
const axis2 = satAxes[2];
|
|
1718
|
+
const sab2 = satBounds[2];
|
|
1719
|
+
axis2.subVectors(b, c);
|
|
1720
|
+
sab2.setFromPoints(axis2, points);
|
|
1721
|
+
const axis3 = satAxes[3];
|
|
1722
|
+
const sab3 = satBounds[3];
|
|
1723
|
+
axis3.subVectors(c, a);
|
|
1724
|
+
sab3.setFromPoints(axis3, points);
|
|
1725
|
+
const lengthAB = axis1.length();
|
|
1726
|
+
const lengthBC = axis2.length();
|
|
1727
|
+
const lengthCA = axis3.length();
|
|
1728
|
+
this.isDegenerateIntoPoint = false;
|
|
1729
|
+
this.isDegenerateIntoSegment = false;
|
|
1730
|
+
if (lengthAB < ZERO_EPSILON) {
|
|
1731
|
+
if (lengthBC < ZERO_EPSILON || lengthCA < ZERO_EPSILON) {
|
|
1732
|
+
this.isDegenerateIntoPoint = true;
|
|
1733
|
+
} else {
|
|
1734
|
+
this.isDegenerateIntoSegment = true;
|
|
1735
|
+
this.degenerateSegment.start.copy(a);
|
|
1736
|
+
this.degenerateSegment.end.copy(c);
|
|
1737
|
+
}
|
|
1738
|
+
} else if (lengthBC < ZERO_EPSILON) {
|
|
1739
|
+
if (lengthCA < ZERO_EPSILON) {
|
|
1740
|
+
this.isDegenerateIntoPoint = true;
|
|
1741
|
+
} else {
|
|
1742
|
+
this.isDegenerateIntoSegment = true;
|
|
1743
|
+
this.degenerateSegment.start.copy(b);
|
|
1744
|
+
this.degenerateSegment.end.copy(a);
|
|
1745
|
+
}
|
|
1746
|
+
} else if (lengthCA < ZERO_EPSILON) {
|
|
1747
|
+
this.isDegenerateIntoSegment = true;
|
|
1748
|
+
this.degenerateSegment.start.copy(c);
|
|
1749
|
+
this.degenerateSegment.end.copy(b);
|
|
1750
|
+
}
|
|
1751
|
+
this.plane.setFromNormalAndCoplanarPoint(axis0, a);
|
|
1752
|
+
this.needsUpdate = false;
|
|
1753
|
+
}
|
|
1754
|
+
};
|
|
1755
|
+
ExtendedTriangle.prototype.closestPointToSegment = /* @__PURE__ */ (function() {
|
|
1756
|
+
const point1 = /* @__PURE__ */ new Vector33();
|
|
1757
|
+
const point2 = /* @__PURE__ */ new Vector33();
|
|
1758
|
+
const edge = /* @__PURE__ */ new Line32();
|
|
1759
|
+
return function distanceToSegment(segment, target1 = null, target2 = null) {
|
|
1760
|
+
const { start, end } = segment;
|
|
1761
|
+
const points = this.points;
|
|
1762
|
+
let distSq;
|
|
1763
|
+
let closestDistanceSq = Infinity;
|
|
1764
|
+
for (let i = 0; i < 3; i++) {
|
|
1765
|
+
const nexti = (i + 1) % 3;
|
|
1766
|
+
edge.start.copy(points[i]);
|
|
1767
|
+
edge.end.copy(points[nexti]);
|
|
1768
|
+
closestPointsSegmentToSegment(edge, segment, point1, point2);
|
|
1769
|
+
distSq = point1.distanceToSquared(point2);
|
|
1770
|
+
if (distSq < closestDistanceSq) {
|
|
1771
|
+
closestDistanceSq = distSq;
|
|
1772
|
+
if (target1) target1.copy(point1);
|
|
1773
|
+
if (target2) target2.copy(point2);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
this.closestPointToPoint(start, point1);
|
|
1777
|
+
distSq = start.distanceToSquared(point1);
|
|
1778
|
+
if (distSq < closestDistanceSq) {
|
|
1779
|
+
closestDistanceSq = distSq;
|
|
1780
|
+
if (target1) target1.copy(point1);
|
|
1781
|
+
if (target2) target2.copy(start);
|
|
1782
|
+
}
|
|
1783
|
+
this.closestPointToPoint(end, point1);
|
|
1784
|
+
distSq = end.distanceToSquared(point1);
|
|
1785
|
+
if (distSq < closestDistanceSq) {
|
|
1786
|
+
closestDistanceSq = distSq;
|
|
1787
|
+
if (target1) target1.copy(point1);
|
|
1788
|
+
if (target2) target2.copy(end);
|
|
1789
|
+
}
|
|
1790
|
+
return Math.sqrt(closestDistanceSq);
|
|
1791
|
+
};
|
|
1792
|
+
})();
|
|
1793
|
+
ExtendedTriangle.prototype.intersectsTriangle = /* @__PURE__ */ (function() {
|
|
1794
|
+
const saTri2 = /* @__PURE__ */ new ExtendedTriangle();
|
|
1795
|
+
const cachedSatBounds = /* @__PURE__ */ new SeparatingAxisBounds();
|
|
1796
|
+
const cachedSatBounds2 = /* @__PURE__ */ new SeparatingAxisBounds();
|
|
1797
|
+
const tmpVec = /* @__PURE__ */ new Vector33();
|
|
1798
|
+
const dir1 = /* @__PURE__ */ new Vector33();
|
|
1799
|
+
const dir2 = /* @__PURE__ */ new Vector33();
|
|
1800
|
+
const tempDir = /* @__PURE__ */ new Vector33();
|
|
1801
|
+
const edge1 = /* @__PURE__ */ new Line32();
|
|
1802
|
+
const edge2 = /* @__PURE__ */ new Line32();
|
|
1803
|
+
const tempPoint = /* @__PURE__ */ new Vector33();
|
|
1804
|
+
const bounds1 = /* @__PURE__ */ new Vector22();
|
|
1805
|
+
const bounds2 = /* @__PURE__ */ new Vector22();
|
|
1806
|
+
function coplanarIntersectsTriangle(self, other, target, suppressLog) {
|
|
1807
|
+
const planeNormal = tmpVec;
|
|
1808
|
+
if (!self.isDegenerateIntoPoint && !self.isDegenerateIntoSegment) {
|
|
1809
|
+
planeNormal.copy(self.plane.normal);
|
|
1810
|
+
} else {
|
|
1811
|
+
planeNormal.copy(other.plane.normal);
|
|
1812
|
+
}
|
|
1813
|
+
const satBounds1 = self.satBounds;
|
|
1814
|
+
const satAxes1 = self.satAxes;
|
|
1815
|
+
for (let i = 1; i < 4; i++) {
|
|
1816
|
+
const sb = satBounds1[i];
|
|
1817
|
+
const sa = satAxes1[i];
|
|
1818
|
+
cachedSatBounds.setFromPoints(sa, other.points);
|
|
1819
|
+
if (sb.isSeparated(cachedSatBounds)) return false;
|
|
1820
|
+
tempDir.copy(planeNormal).cross(sa);
|
|
1821
|
+
cachedSatBounds.setFromPoints(tempDir, self.points);
|
|
1822
|
+
cachedSatBounds2.setFromPoints(tempDir, other.points);
|
|
1823
|
+
if (cachedSatBounds.isSeparated(cachedSatBounds2)) return false;
|
|
1824
|
+
}
|
|
1825
|
+
const satBounds2 = other.satBounds;
|
|
1826
|
+
const satAxes2 = other.satAxes;
|
|
1827
|
+
for (let i = 1; i < 4; i++) {
|
|
1828
|
+
const sb = satBounds2[i];
|
|
1829
|
+
const sa = satAxes2[i];
|
|
1830
|
+
cachedSatBounds.setFromPoints(sa, self.points);
|
|
1831
|
+
if (sb.isSeparated(cachedSatBounds)) return false;
|
|
1832
|
+
tempDir.crossVectors(planeNormal, sa);
|
|
1833
|
+
cachedSatBounds.setFromPoints(tempDir, self.points);
|
|
1834
|
+
cachedSatBounds2.setFromPoints(tempDir, other.points);
|
|
1835
|
+
if (cachedSatBounds.isSeparated(cachedSatBounds2)) return false;
|
|
1836
|
+
}
|
|
1837
|
+
if (target) {
|
|
1838
|
+
if (!suppressLog) {
|
|
1839
|
+
console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0.");
|
|
1840
|
+
}
|
|
1841
|
+
target.start.set(0, 0, 0);
|
|
1842
|
+
target.end.set(0, 0, 0);
|
|
1843
|
+
}
|
|
1844
|
+
return true;
|
|
1845
|
+
}
|
|
1846
|
+
function findSingleBounds(a, b, c, aProj, bProj, cProj, aDist, bDist, cDist, bounds, edge) {
|
|
1847
|
+
let t = aDist / (aDist - bDist);
|
|
1848
|
+
bounds.x = aProj + (bProj - aProj) * t;
|
|
1849
|
+
edge.start.subVectors(b, a).multiplyScalar(t).add(a);
|
|
1850
|
+
t = aDist / (aDist - cDist);
|
|
1851
|
+
bounds.y = aProj + (cProj - aProj) * t;
|
|
1852
|
+
edge.end.subVectors(c, a).multiplyScalar(t).add(a);
|
|
1853
|
+
}
|
|
1854
|
+
function findIntersectionLineBounds(self, aProj, bProj, cProj, abDist, acDist, aDist, bDist, cDist, bounds, edge) {
|
|
1855
|
+
if (abDist > 0) {
|
|
1856
|
+
findSingleBounds(self.c, self.a, self.b, cProj, aProj, bProj, cDist, aDist, bDist, bounds, edge);
|
|
1857
|
+
} else if (acDist > 0) {
|
|
1858
|
+
findSingleBounds(self.b, self.a, self.c, bProj, aProj, cProj, bDist, aDist, cDist, bounds, edge);
|
|
1859
|
+
} else if (bDist * cDist > 0 || aDist != 0) {
|
|
1860
|
+
findSingleBounds(self.a, self.b, self.c, aProj, bProj, cProj, aDist, bDist, cDist, bounds, edge);
|
|
1861
|
+
} else if (bDist != 0) {
|
|
1862
|
+
findSingleBounds(self.b, self.a, self.c, bProj, aProj, cProj, bDist, aDist, cDist, bounds, edge);
|
|
1863
|
+
} else if (cDist != 0) {
|
|
1864
|
+
findSingleBounds(self.c, self.a, self.b, cProj, aProj, bProj, cDist, aDist, bDist, bounds, edge);
|
|
1865
|
+
} else {
|
|
1866
|
+
return true;
|
|
1867
|
+
}
|
|
1868
|
+
return false;
|
|
1869
|
+
}
|
|
1870
|
+
function intersectTriangleSegment(triangle4, degenerateTriangle, target, suppressLog) {
|
|
1871
|
+
const segment = degenerateTriangle.degenerateSegment;
|
|
1872
|
+
const startDist = triangle4.plane.distanceToPoint(segment.start);
|
|
1873
|
+
const endDist = triangle4.plane.distanceToPoint(segment.end);
|
|
1874
|
+
if (isNearZero(startDist)) {
|
|
1875
|
+
if (isNearZero(endDist)) {
|
|
1876
|
+
return coplanarIntersectsTriangle(triangle4, degenerateTriangle, target, suppressLog);
|
|
1877
|
+
} else {
|
|
1878
|
+
if (target) {
|
|
1879
|
+
target.start.copy(segment.start);
|
|
1880
|
+
target.end.copy(segment.start);
|
|
1881
|
+
}
|
|
1882
|
+
return triangle4.containsPoint(segment.start);
|
|
1883
|
+
}
|
|
1884
|
+
} else if (isNearZero(endDist)) {
|
|
1885
|
+
if (target) {
|
|
1886
|
+
target.start.copy(segment.end);
|
|
1887
|
+
target.end.copy(segment.end);
|
|
1888
|
+
}
|
|
1889
|
+
return triangle4.containsPoint(segment.end);
|
|
1890
|
+
} else {
|
|
1891
|
+
if (triangle4.plane.intersectLine(segment, tmpVec) != null) {
|
|
1892
|
+
if (target) {
|
|
1893
|
+
target.start.copy(tmpVec);
|
|
1894
|
+
target.end.copy(tmpVec);
|
|
1895
|
+
}
|
|
1896
|
+
return triangle4.containsPoint(tmpVec);
|
|
1897
|
+
} else {
|
|
1898
|
+
return false;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
function intersectTrianglePoint(triangle4, degenerateTriangle, target) {
|
|
1903
|
+
const point = degenerateTriangle.a;
|
|
1904
|
+
if (isNearZero(triangle4.plane.distanceToPoint(point)) && triangle4.containsPoint(point)) {
|
|
1905
|
+
if (target) {
|
|
1906
|
+
target.start.copy(point);
|
|
1907
|
+
target.end.copy(point);
|
|
1908
|
+
}
|
|
1909
|
+
return true;
|
|
1910
|
+
} else {
|
|
1911
|
+
return false;
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
function intersectSegmentPoint(segmentTri, pointTri, target) {
|
|
1915
|
+
const segment = segmentTri.degenerateSegment;
|
|
1916
|
+
const point = pointTri.a;
|
|
1917
|
+
segment.closestPointToPoint(point, true, tmpVec);
|
|
1918
|
+
if (point.distanceToSquared(tmpVec) < ZERO_EPSILON_SQR) {
|
|
1919
|
+
if (target) {
|
|
1920
|
+
target.start.copy(point);
|
|
1921
|
+
target.end.copy(point);
|
|
1922
|
+
}
|
|
1923
|
+
return true;
|
|
1924
|
+
} else {
|
|
1925
|
+
return false;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
function handleDegenerateCases(self, other, target, suppressLog) {
|
|
1929
|
+
if (self.isDegenerateIntoSegment) {
|
|
1930
|
+
if (other.isDegenerateIntoSegment) {
|
|
1931
|
+
const segment1 = self.degenerateSegment;
|
|
1932
|
+
const segment2 = other.degenerateSegment;
|
|
1933
|
+
const delta1 = dir1;
|
|
1934
|
+
const delta2 = dir2;
|
|
1935
|
+
segment1.delta(delta1);
|
|
1936
|
+
segment2.delta(delta2);
|
|
1937
|
+
const startDelta = tmpVec.subVectors(segment2.start, segment1.start);
|
|
1938
|
+
const denom = delta1.x * delta2.y - delta1.y * delta2.x;
|
|
1939
|
+
if (isNearZero(denom)) {
|
|
1940
|
+
return false;
|
|
1941
|
+
}
|
|
1942
|
+
const t = (startDelta.x * delta2.y - startDelta.y * delta2.x) / denom;
|
|
1943
|
+
const u = -(delta1.x * startDelta.y - delta1.y * startDelta.x) / denom;
|
|
1944
|
+
if (t < 0 || t > 1 || u < 0 || u > 1) {
|
|
1945
|
+
return false;
|
|
1946
|
+
}
|
|
1947
|
+
const z1 = segment1.start.z + delta1.z * t;
|
|
1948
|
+
const z2 = segment2.start.z + delta2.z * u;
|
|
1949
|
+
if (isNearZero(z1 - z2)) {
|
|
1950
|
+
if (target) {
|
|
1951
|
+
target.start.copy(segment1.start).addScaledVector(delta1, t);
|
|
1952
|
+
target.end.copy(segment1.start).addScaledVector(delta1, t);
|
|
1953
|
+
}
|
|
1954
|
+
return true;
|
|
1955
|
+
} else {
|
|
1956
|
+
return false;
|
|
1957
|
+
}
|
|
1958
|
+
} else if (other.isDegenerateIntoPoint) {
|
|
1959
|
+
return intersectSegmentPoint(self, other, target);
|
|
1960
|
+
} else {
|
|
1961
|
+
return intersectTriangleSegment(other, self, target, suppressLog);
|
|
1962
|
+
}
|
|
1963
|
+
} else if (self.isDegenerateIntoPoint) {
|
|
1964
|
+
if (other.isDegenerateIntoPoint) {
|
|
1965
|
+
if (other.a.distanceToSquared(self.a) < ZERO_EPSILON_SQR) {
|
|
1966
|
+
if (target) {
|
|
1967
|
+
target.start.copy(self.a);
|
|
1968
|
+
target.end.copy(self.a);
|
|
1969
|
+
}
|
|
1970
|
+
return true;
|
|
1971
|
+
} else {
|
|
1972
|
+
return false;
|
|
1973
|
+
}
|
|
1974
|
+
} else if (other.isDegenerateIntoSegment) {
|
|
1975
|
+
return intersectSegmentPoint(other, self, target);
|
|
1976
|
+
} else {
|
|
1977
|
+
return intersectTrianglePoint(other, self, target);
|
|
1978
|
+
}
|
|
1979
|
+
} else {
|
|
1980
|
+
if (other.isDegenerateIntoPoint) {
|
|
1981
|
+
return intersectTrianglePoint(self, other, target);
|
|
1982
|
+
} else if (other.isDegenerateIntoSegment) {
|
|
1983
|
+
return intersectTriangleSegment(self, other, target, suppressLog);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
return function intersectsTriangle(other, target = null, suppressLog = false) {
|
|
1988
|
+
if (this.needsUpdate) {
|
|
1989
|
+
this.update();
|
|
1990
|
+
}
|
|
1991
|
+
if (!other.isExtendedTriangle) {
|
|
1992
|
+
saTri2.copy(other);
|
|
1993
|
+
saTri2.update();
|
|
1994
|
+
other = saTri2;
|
|
1995
|
+
} else if (other.needsUpdate) {
|
|
1996
|
+
other.update();
|
|
1997
|
+
}
|
|
1998
|
+
const res = handleDegenerateCases(this, other, target, suppressLog);
|
|
1999
|
+
if (res !== void 0) {
|
|
2000
|
+
return res;
|
|
2001
|
+
}
|
|
2002
|
+
const plane1 = this.plane;
|
|
2003
|
+
const plane2 = other.plane;
|
|
2004
|
+
let a1Dist = plane2.distanceToPoint(this.a);
|
|
2005
|
+
let b1Dist = plane2.distanceToPoint(this.b);
|
|
2006
|
+
let c1Dist = plane2.distanceToPoint(this.c);
|
|
2007
|
+
if (isNearZero(a1Dist))
|
|
2008
|
+
a1Dist = 0;
|
|
2009
|
+
if (isNearZero(b1Dist))
|
|
2010
|
+
b1Dist = 0;
|
|
2011
|
+
if (isNearZero(c1Dist))
|
|
2012
|
+
c1Dist = 0;
|
|
2013
|
+
const a1b1Dist = a1Dist * b1Dist;
|
|
2014
|
+
const a1c1Dist = a1Dist * c1Dist;
|
|
2015
|
+
if (a1b1Dist > 0 && a1c1Dist > 0) {
|
|
2016
|
+
return false;
|
|
2017
|
+
}
|
|
2018
|
+
let a2Dist = plane1.distanceToPoint(other.a);
|
|
2019
|
+
let b2Dist = plane1.distanceToPoint(other.b);
|
|
2020
|
+
let c2Dist = plane1.distanceToPoint(other.c);
|
|
2021
|
+
if (isNearZero(a2Dist))
|
|
2022
|
+
a2Dist = 0;
|
|
2023
|
+
if (isNearZero(b2Dist))
|
|
2024
|
+
b2Dist = 0;
|
|
2025
|
+
if (isNearZero(c2Dist))
|
|
2026
|
+
c2Dist = 0;
|
|
2027
|
+
const a2b2Dist = a2Dist * b2Dist;
|
|
2028
|
+
const a2c2Dist = a2Dist * c2Dist;
|
|
2029
|
+
if (a2b2Dist > 0 && a2c2Dist > 0) {
|
|
2030
|
+
return false;
|
|
2031
|
+
}
|
|
2032
|
+
dir1.copy(plane1.normal);
|
|
2033
|
+
dir2.copy(plane2.normal);
|
|
2034
|
+
const intersectionLine = dir1.cross(dir2);
|
|
2035
|
+
let componentIndex = 0;
|
|
2036
|
+
let maxComponent = Math.abs(intersectionLine.x);
|
|
2037
|
+
const comp1 = Math.abs(intersectionLine.y);
|
|
2038
|
+
if (comp1 > maxComponent) {
|
|
2039
|
+
maxComponent = comp1;
|
|
2040
|
+
componentIndex = 1;
|
|
2041
|
+
}
|
|
2042
|
+
const comp2 = Math.abs(intersectionLine.z);
|
|
2043
|
+
if (comp2 > maxComponent) {
|
|
2044
|
+
componentIndex = 2;
|
|
2045
|
+
}
|
|
2046
|
+
const key = componentKeys[componentIndex];
|
|
2047
|
+
const a1Proj = this.a[key];
|
|
2048
|
+
const b1Proj = this.b[key];
|
|
2049
|
+
const c1Proj = this.c[key];
|
|
2050
|
+
const a2Proj = other.a[key];
|
|
2051
|
+
const b2Proj = other.b[key];
|
|
2052
|
+
const c2Proj = other.c[key];
|
|
2053
|
+
if (findIntersectionLineBounds(this, a1Proj, b1Proj, c1Proj, a1b1Dist, a1c1Dist, a1Dist, b1Dist, c1Dist, bounds1, edge1)) {
|
|
2054
|
+
return coplanarIntersectsTriangle(this, other, target, suppressLog);
|
|
2055
|
+
}
|
|
2056
|
+
if (findIntersectionLineBounds(other, a2Proj, b2Proj, c2Proj, a2b2Dist, a2c2Dist, a2Dist, b2Dist, c2Dist, bounds2, edge2)) {
|
|
2057
|
+
return coplanarIntersectsTriangle(this, other, target, suppressLog);
|
|
2058
|
+
}
|
|
2059
|
+
if (bounds1.y < bounds1.x) {
|
|
2060
|
+
const tmp = bounds1.y;
|
|
2061
|
+
bounds1.y = bounds1.x;
|
|
2062
|
+
bounds1.x = tmp;
|
|
2063
|
+
tempPoint.copy(edge1.start);
|
|
2064
|
+
edge1.start.copy(edge1.end);
|
|
2065
|
+
edge1.end.copy(tempPoint);
|
|
2066
|
+
}
|
|
2067
|
+
if (bounds2.y < bounds2.x) {
|
|
2068
|
+
const tmp = bounds2.y;
|
|
2069
|
+
bounds2.y = bounds2.x;
|
|
2070
|
+
bounds2.x = tmp;
|
|
2071
|
+
tempPoint.copy(edge2.start);
|
|
2072
|
+
edge2.start.copy(edge2.end);
|
|
2073
|
+
edge2.end.copy(tempPoint);
|
|
2074
|
+
}
|
|
2075
|
+
if (bounds1.y < bounds2.x || bounds2.y < bounds1.x) {
|
|
2076
|
+
return false;
|
|
2077
|
+
}
|
|
2078
|
+
if (target) {
|
|
2079
|
+
if (bounds2.x > bounds1.x) {
|
|
2080
|
+
target.start.copy(edge2.start);
|
|
2081
|
+
} else {
|
|
2082
|
+
target.start.copy(edge1.start);
|
|
2083
|
+
}
|
|
2084
|
+
if (bounds2.y < bounds1.y) {
|
|
2085
|
+
target.end.copy(edge2.end);
|
|
2086
|
+
} else {
|
|
2087
|
+
target.end.copy(edge1.end);
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
return true;
|
|
2091
|
+
};
|
|
2092
|
+
})();
|
|
2093
|
+
ExtendedTriangle.prototype.distanceToPoint = /* @__PURE__ */ (function() {
|
|
2094
|
+
const target = /* @__PURE__ */ new Vector33();
|
|
2095
|
+
return function distanceToPoint(point) {
|
|
2096
|
+
this.closestPointToPoint(point, target);
|
|
2097
|
+
return point.distanceTo(target);
|
|
2098
|
+
};
|
|
2099
|
+
})();
|
|
2100
|
+
ExtendedTriangle.prototype.distanceToTriangle = /* @__PURE__ */ (function() {
|
|
2101
|
+
const point = /* @__PURE__ */ new Vector33();
|
|
2102
|
+
const point2 = /* @__PURE__ */ new Vector33();
|
|
2103
|
+
const cornerFields = ["a", "b", "c"];
|
|
2104
|
+
const line1 = /* @__PURE__ */ new Line32();
|
|
2105
|
+
const line2 = /* @__PURE__ */ new Line32();
|
|
2106
|
+
return function distanceToTriangle(other, target1 = null, target2 = null) {
|
|
2107
|
+
const lineTarget = target1 || target2 ? line1 : null;
|
|
2108
|
+
if (this.intersectsTriangle(other, lineTarget, true)) {
|
|
2109
|
+
if (target1 || target2) {
|
|
2110
|
+
if (target1) lineTarget.getCenter(target1);
|
|
2111
|
+
if (target2) lineTarget.getCenter(target2);
|
|
2112
|
+
}
|
|
2113
|
+
return 0;
|
|
2114
|
+
}
|
|
2115
|
+
let closestDistanceSq = Infinity;
|
|
2116
|
+
for (let i = 0; i < 3; i++) {
|
|
2117
|
+
let dist;
|
|
2118
|
+
const field = cornerFields[i];
|
|
2119
|
+
const otherVec = other[field];
|
|
2120
|
+
this.closestPointToPoint(otherVec, point);
|
|
2121
|
+
dist = otherVec.distanceToSquared(point);
|
|
2122
|
+
if (dist < closestDistanceSq) {
|
|
2123
|
+
closestDistanceSq = dist;
|
|
2124
|
+
if (target1) target1.copy(point);
|
|
2125
|
+
if (target2) target2.copy(otherVec);
|
|
2126
|
+
}
|
|
2127
|
+
const thisVec = this[field];
|
|
2128
|
+
other.closestPointToPoint(thisVec, point);
|
|
2129
|
+
dist = thisVec.distanceToSquared(point);
|
|
2130
|
+
if (dist < closestDistanceSq) {
|
|
2131
|
+
closestDistanceSq = dist;
|
|
2132
|
+
if (target1) target1.copy(thisVec);
|
|
2133
|
+
if (target2) target2.copy(point);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
for (let i = 0; i < 3; i++) {
|
|
2137
|
+
const f11 = cornerFields[i];
|
|
2138
|
+
const f12 = cornerFields[(i + 1) % 3];
|
|
2139
|
+
line1.set(this[f11], this[f12]);
|
|
2140
|
+
for (let i2 = 0; i2 < 3; i2++) {
|
|
2141
|
+
const f21 = cornerFields[i2];
|
|
2142
|
+
const f22 = cornerFields[(i2 + 1) % 3];
|
|
2143
|
+
line2.set(other[f21], other[f22]);
|
|
2144
|
+
closestPointsSegmentToSegment(line1, line2, point, point2);
|
|
2145
|
+
const dist = point.distanceToSquared(point2);
|
|
2146
|
+
if (dist < closestDistanceSq) {
|
|
2147
|
+
closestDistanceSq = dist;
|
|
2148
|
+
if (target1) target1.copy(point);
|
|
2149
|
+
if (target2) target2.copy(point2);
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
return Math.sqrt(closestDistanceSq);
|
|
2154
|
+
};
|
|
2155
|
+
})();
|
|
2156
|
+
|
|
2157
|
+
// node_modules/three-mesh-bvh/src/math/OrientedBox.js
|
|
2158
|
+
var OrientedBox = class {
|
|
2159
|
+
constructor(min, max, matrix) {
|
|
2160
|
+
this.isOrientedBox = true;
|
|
2161
|
+
this.min = new Vector34();
|
|
2162
|
+
this.max = new Vector34();
|
|
2163
|
+
this.matrix = new Matrix42();
|
|
2164
|
+
this.invMatrix = new Matrix42();
|
|
2165
|
+
this.points = new Array(8).fill().map(() => new Vector34());
|
|
2166
|
+
this.satAxes = new Array(3).fill().map(() => new Vector34());
|
|
2167
|
+
this.satBounds = new Array(3).fill().map(() => new SeparatingAxisBounds());
|
|
2168
|
+
this.alignedSatBounds = new Array(3).fill().map(() => new SeparatingAxisBounds());
|
|
2169
|
+
this.needsUpdate = false;
|
|
2170
|
+
if (min) this.min.copy(min);
|
|
2171
|
+
if (max) this.max.copy(max);
|
|
2172
|
+
if (matrix) this.matrix.copy(matrix);
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* Sets the oriented box parameters.
|
|
2176
|
+
* @param {Vector3} min
|
|
2177
|
+
* @param {Vector3} max
|
|
2178
|
+
* @param {Matrix4} matrix
|
|
2179
|
+
*/
|
|
2180
|
+
set(min, max, matrix) {
|
|
2181
|
+
this.min.copy(min);
|
|
2182
|
+
this.max.copy(max);
|
|
2183
|
+
this.matrix.copy(matrix);
|
|
2184
|
+
this.needsUpdate = true;
|
|
2185
|
+
}
|
|
2186
|
+
copy(other) {
|
|
2187
|
+
this.min.copy(other.min);
|
|
2188
|
+
this.max.copy(other.max);
|
|
2189
|
+
this.matrix.copy(other.matrix);
|
|
2190
|
+
this.needsUpdate = true;
|
|
2191
|
+
}
|
|
2192
|
+
};
|
|
2193
|
+
OrientedBox.prototype.update = /* @__PURE__ */ (function() {
|
|
2194
|
+
return function update() {
|
|
2195
|
+
const matrix = this.matrix;
|
|
2196
|
+
const min = this.min;
|
|
2197
|
+
const max = this.max;
|
|
2198
|
+
const points = this.points;
|
|
2199
|
+
for (let x = 0; x <= 1; x++) {
|
|
2200
|
+
for (let y = 0; y <= 1; y++) {
|
|
2201
|
+
for (let z = 0; z <= 1; z++) {
|
|
2202
|
+
const i = (1 << 0) * x | (1 << 1) * y | (1 << 2) * z;
|
|
2203
|
+
const v = points[i];
|
|
2204
|
+
v.x = x ? max.x : min.x;
|
|
2205
|
+
v.y = y ? max.y : min.y;
|
|
2206
|
+
v.z = z ? max.z : min.z;
|
|
2207
|
+
v.applyMatrix4(matrix);
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
const satBounds = this.satBounds;
|
|
2212
|
+
const satAxes = this.satAxes;
|
|
2213
|
+
const minVec = points[0];
|
|
2214
|
+
for (let i = 0; i < 3; i++) {
|
|
2215
|
+
const axis = satAxes[i];
|
|
2216
|
+
const sb = satBounds[i];
|
|
2217
|
+
const index = 1 << i;
|
|
2218
|
+
const pi = points[index];
|
|
2219
|
+
axis.subVectors(minVec, pi);
|
|
2220
|
+
sb.setFromPoints(axis, points);
|
|
2221
|
+
}
|
|
2222
|
+
const alignedSatBounds = this.alignedSatBounds;
|
|
2223
|
+
alignedSatBounds[0].setFromPointsField(points, "x");
|
|
2224
|
+
alignedSatBounds[1].setFromPointsField(points, "y");
|
|
2225
|
+
alignedSatBounds[2].setFromPointsField(points, "z");
|
|
2226
|
+
this.invMatrix.copy(this.matrix).invert();
|
|
2227
|
+
this.needsUpdate = false;
|
|
2228
|
+
};
|
|
2229
|
+
})();
|
|
2230
|
+
OrientedBox.prototype.intersectsBox = /* @__PURE__ */ (function() {
|
|
2231
|
+
const aabbBounds = /* @__PURE__ */ new SeparatingAxisBounds();
|
|
2232
|
+
return function intersectsBox(box) {
|
|
2233
|
+
if (this.needsUpdate) {
|
|
2234
|
+
this.update();
|
|
2235
|
+
}
|
|
2236
|
+
const min = box.min;
|
|
2237
|
+
const max = box.max;
|
|
2238
|
+
const satBounds = this.satBounds;
|
|
2239
|
+
const satAxes = this.satAxes;
|
|
2240
|
+
const alignedSatBounds = this.alignedSatBounds;
|
|
2241
|
+
aabbBounds.min = min.x;
|
|
2242
|
+
aabbBounds.max = max.x;
|
|
2243
|
+
if (alignedSatBounds[0].isSeparated(aabbBounds)) return false;
|
|
2244
|
+
aabbBounds.min = min.y;
|
|
2245
|
+
aabbBounds.max = max.y;
|
|
2246
|
+
if (alignedSatBounds[1].isSeparated(aabbBounds)) return false;
|
|
2247
|
+
aabbBounds.min = min.z;
|
|
2248
|
+
aabbBounds.max = max.z;
|
|
2249
|
+
if (alignedSatBounds[2].isSeparated(aabbBounds)) return false;
|
|
2250
|
+
for (let i = 0; i < 3; i++) {
|
|
2251
|
+
const axis = satAxes[i];
|
|
2252
|
+
const sb = satBounds[i];
|
|
2253
|
+
aabbBounds.setFromBox(axis, box);
|
|
2254
|
+
if (sb.isSeparated(aabbBounds)) return false;
|
|
2255
|
+
}
|
|
2256
|
+
return true;
|
|
2257
|
+
};
|
|
2258
|
+
})();
|
|
2259
|
+
OrientedBox.prototype.intersectsTriangle = /* @__PURE__ */ (function() {
|
|
2260
|
+
const saTri = /* @__PURE__ */ new ExtendedTriangle();
|
|
2261
|
+
const pointsArr = /* @__PURE__ */ new Array(3);
|
|
2262
|
+
const cachedSatBounds = /* @__PURE__ */ new SeparatingAxisBounds();
|
|
2263
|
+
const cachedSatBounds2 = /* @__PURE__ */ new SeparatingAxisBounds();
|
|
2264
|
+
const cachedAxis = /* @__PURE__ */ new Vector34();
|
|
2265
|
+
return function intersectsTriangle(triangle4) {
|
|
2266
|
+
if (this.needsUpdate) {
|
|
2267
|
+
this.update();
|
|
2268
|
+
}
|
|
2269
|
+
if (!triangle4.isExtendedTriangle) {
|
|
2270
|
+
saTri.copy(triangle4);
|
|
2271
|
+
saTri.update();
|
|
2272
|
+
triangle4 = saTri;
|
|
2273
|
+
} else if (triangle4.needsUpdate) {
|
|
2274
|
+
triangle4.update();
|
|
2275
|
+
}
|
|
2276
|
+
const satBounds = this.satBounds;
|
|
2277
|
+
const satAxes = this.satAxes;
|
|
2278
|
+
pointsArr[0] = triangle4.a;
|
|
2279
|
+
pointsArr[1] = triangle4.b;
|
|
2280
|
+
pointsArr[2] = triangle4.c;
|
|
2281
|
+
for (let i = 0; i < 3; i++) {
|
|
2282
|
+
const sb = satBounds[i];
|
|
2283
|
+
const sa = satAxes[i];
|
|
2284
|
+
cachedSatBounds.setFromPoints(sa, pointsArr);
|
|
2285
|
+
if (sb.isSeparated(cachedSatBounds)) return false;
|
|
2286
|
+
}
|
|
2287
|
+
const triSatBounds = triangle4.satBounds;
|
|
2288
|
+
const triSatAxes = triangle4.satAxes;
|
|
2289
|
+
const points = this.points;
|
|
2290
|
+
for (let i = 0; i < 3; i++) {
|
|
2291
|
+
const sb = triSatBounds[i];
|
|
2292
|
+
const sa = triSatAxes[i];
|
|
2293
|
+
cachedSatBounds.setFromPoints(sa, points);
|
|
2294
|
+
if (sb.isSeparated(cachedSatBounds)) return false;
|
|
2295
|
+
}
|
|
2296
|
+
for (let i = 0; i < 3; i++) {
|
|
2297
|
+
const sa1 = satAxes[i];
|
|
2298
|
+
for (let i2 = 0; i2 < 4; i2++) {
|
|
2299
|
+
const sa2 = triSatAxes[i2];
|
|
2300
|
+
cachedAxis.crossVectors(sa1, sa2);
|
|
2301
|
+
cachedSatBounds.setFromPoints(cachedAxis, pointsArr);
|
|
2302
|
+
cachedSatBounds2.setFromPoints(cachedAxis, points);
|
|
2303
|
+
if (cachedSatBounds.isSeparated(cachedSatBounds2)) return false;
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
return true;
|
|
2307
|
+
};
|
|
2308
|
+
})();
|
|
2309
|
+
OrientedBox.prototype.closestPointToPoint = /* @__PURE__ */ (function() {
|
|
2310
|
+
return function closestPointToPoint2(point, target1) {
|
|
2311
|
+
if (this.needsUpdate) {
|
|
2312
|
+
this.update();
|
|
2313
|
+
}
|
|
2314
|
+
target1.copy(point).applyMatrix4(this.invMatrix).clamp(this.min, this.max).applyMatrix4(this.matrix);
|
|
2315
|
+
return target1;
|
|
2316
|
+
};
|
|
2317
|
+
})();
|
|
2318
|
+
OrientedBox.prototype.distanceToPoint = (function() {
|
|
2319
|
+
const target = new Vector34();
|
|
2320
|
+
return function distanceToPoint(point) {
|
|
2321
|
+
this.closestPointToPoint(point, target);
|
|
2322
|
+
return point.distanceTo(target);
|
|
2323
|
+
};
|
|
2324
|
+
})();
|
|
2325
|
+
OrientedBox.prototype.distanceToBox = /* @__PURE__ */ (function() {
|
|
2326
|
+
const xyzFields = ["x", "y", "z"];
|
|
2327
|
+
const segments1 = /* @__PURE__ */ new Array(12).fill().map(() => new Line33());
|
|
2328
|
+
const segments2 = /* @__PURE__ */ new Array(12).fill().map(() => new Line33());
|
|
2329
|
+
const point1 = /* @__PURE__ */ new Vector34();
|
|
2330
|
+
const point2 = /* @__PURE__ */ new Vector34();
|
|
2331
|
+
return function distanceToBox(box, threshold = 0, target1 = null, target2 = null) {
|
|
2332
|
+
if (this.needsUpdate) {
|
|
2333
|
+
this.update();
|
|
2334
|
+
}
|
|
2335
|
+
if (this.intersectsBox(box)) {
|
|
2336
|
+
if (target1 || target2) {
|
|
2337
|
+
box.getCenter(point2);
|
|
2338
|
+
this.closestPointToPoint(point2, point1);
|
|
2339
|
+
box.closestPointToPoint(point1, point2);
|
|
2340
|
+
if (target1) target1.copy(point1);
|
|
2341
|
+
if (target2) target2.copy(point2);
|
|
2342
|
+
}
|
|
2343
|
+
return 0;
|
|
2344
|
+
}
|
|
2345
|
+
const threshold2 = threshold * threshold;
|
|
2346
|
+
const min = box.min;
|
|
2347
|
+
const max = box.max;
|
|
2348
|
+
const points = this.points;
|
|
2349
|
+
let closestDistanceSq = Infinity;
|
|
2350
|
+
for (let i = 0; i < 8; i++) {
|
|
2351
|
+
const p = points[i];
|
|
2352
|
+
point2.copy(p).clamp(min, max);
|
|
2353
|
+
const dist = p.distanceToSquared(point2);
|
|
2354
|
+
if (dist < closestDistanceSq) {
|
|
2355
|
+
closestDistanceSq = dist;
|
|
2356
|
+
if (target1) target1.copy(p);
|
|
2357
|
+
if (target2) target2.copy(point2);
|
|
2358
|
+
if (dist < threshold2) return Math.sqrt(dist);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
let count = 0;
|
|
2362
|
+
for (let i = 0; i < 3; i++) {
|
|
2363
|
+
for (let i1 = 0; i1 <= 1; i1++) {
|
|
2364
|
+
for (let i2 = 0; i2 <= 1; i2++) {
|
|
2365
|
+
const nextIndex = (i + 1) % 3;
|
|
2366
|
+
const nextIndex2 = (i + 2) % 3;
|
|
2367
|
+
const index = i1 << nextIndex | i2 << nextIndex2;
|
|
2368
|
+
const index2 = 1 << i | i1 << nextIndex | i2 << nextIndex2;
|
|
2369
|
+
const p1 = points[index];
|
|
2370
|
+
const p2 = points[index2];
|
|
2371
|
+
const line1 = segments1[count];
|
|
2372
|
+
line1.set(p1, p2);
|
|
2373
|
+
const f1 = xyzFields[i];
|
|
2374
|
+
const f2 = xyzFields[nextIndex];
|
|
2375
|
+
const f3 = xyzFields[nextIndex2];
|
|
2376
|
+
const line2 = segments2[count];
|
|
2377
|
+
const start = line2.start;
|
|
2378
|
+
const end = line2.end;
|
|
2379
|
+
start[f1] = min[f1];
|
|
2380
|
+
start[f2] = i1 ? min[f2] : max[f2];
|
|
2381
|
+
start[f3] = i2 ? min[f3] : max[f2];
|
|
2382
|
+
end[f1] = max[f1];
|
|
2383
|
+
end[f2] = i1 ? min[f2] : max[f2];
|
|
2384
|
+
end[f3] = i2 ? min[f3] : max[f2];
|
|
2385
|
+
count++;
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
for (let x = 0; x <= 1; x++) {
|
|
2390
|
+
for (let y = 0; y <= 1; y++) {
|
|
2391
|
+
for (let z = 0; z <= 1; z++) {
|
|
2392
|
+
point2.x = x ? max.x : min.x;
|
|
2393
|
+
point2.y = y ? max.y : min.y;
|
|
2394
|
+
point2.z = z ? max.z : min.z;
|
|
2395
|
+
this.closestPointToPoint(point2, point1);
|
|
2396
|
+
const dist = point2.distanceToSquared(point1);
|
|
2397
|
+
if (dist < closestDistanceSq) {
|
|
2398
|
+
closestDistanceSq = dist;
|
|
2399
|
+
if (target1) target1.copy(point1);
|
|
2400
|
+
if (target2) target2.copy(point2);
|
|
2401
|
+
if (dist < threshold2) return Math.sqrt(dist);
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
for (let i = 0; i < 12; i++) {
|
|
2407
|
+
const l1 = segments1[i];
|
|
2408
|
+
for (let i2 = 0; i2 < 12; i2++) {
|
|
2409
|
+
const l2 = segments2[i2];
|
|
2410
|
+
closestPointsSegmentToSegment(l1, l2, point1, point2);
|
|
2411
|
+
const dist = point1.distanceToSquared(point2);
|
|
2412
|
+
if (dist < closestDistanceSq) {
|
|
2413
|
+
closestDistanceSq = dist;
|
|
2414
|
+
if (target1) target1.copy(point1);
|
|
2415
|
+
if (target2) target2.copy(point2);
|
|
2416
|
+
if (dist < threshold2) return Math.sqrt(dist);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
return Math.sqrt(closestDistanceSq);
|
|
2421
|
+
};
|
|
2422
|
+
})();
|
|
2423
|
+
|
|
2424
|
+
// node_modules/three-mesh-bvh/src/utils/ExtendedTrianglePool.js
|
|
2425
|
+
var ExtendedTrianglePoolBase = class extends PrimitivePool {
|
|
2426
|
+
constructor() {
|
|
2427
|
+
super(() => new ExtendedTriangle());
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
var ExtendedTrianglePool = /* @__PURE__ */ new ExtendedTrianglePoolBase();
|
|
2431
|
+
|
|
2432
|
+
// node_modules/three-mesh-bvh/src/core/cast/closestPointToPoint.js
|
|
2433
|
+
import { Vector3 as Vector35 } from "three";
|
|
2434
|
+
var temp = /* @__PURE__ */ new Vector35();
|
|
2435
|
+
var temp1 = /* @__PURE__ */ new Vector35();
|
|
2436
|
+
function closestPointToPoint(bvh, point, target = {}, minThreshold = 0, maxThreshold = Infinity) {
|
|
2437
|
+
const minThresholdSq = minThreshold * minThreshold;
|
|
2438
|
+
const maxThresholdSq = maxThreshold * maxThreshold;
|
|
2439
|
+
let closestDistanceSq = Infinity;
|
|
2440
|
+
let closestDistanceTriIndex = null;
|
|
2441
|
+
bvh.shapecast(
|
|
2442
|
+
{
|
|
2443
|
+
boundsTraverseOrder: (box) => {
|
|
2444
|
+
temp.copy(point).clamp(box.min, box.max);
|
|
2445
|
+
return temp.distanceToSquared(point);
|
|
2446
|
+
},
|
|
2447
|
+
intersectsBounds: (box, isLeaf, score) => {
|
|
2448
|
+
return score < closestDistanceSq && score < maxThresholdSq;
|
|
2449
|
+
},
|
|
2450
|
+
intersectsTriangle: (tri, triIndex) => {
|
|
2451
|
+
tri.closestPointToPoint(point, temp);
|
|
2452
|
+
const distSq = point.distanceToSquared(temp);
|
|
2453
|
+
if (distSq < closestDistanceSq) {
|
|
2454
|
+
temp1.copy(temp);
|
|
2455
|
+
closestDistanceSq = distSq;
|
|
2456
|
+
closestDistanceTriIndex = triIndex;
|
|
2457
|
+
}
|
|
2458
|
+
if (distSq < minThresholdSq) {
|
|
2459
|
+
return true;
|
|
2460
|
+
} else {
|
|
2461
|
+
return false;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
);
|
|
2466
|
+
if (closestDistanceSq === Infinity) return null;
|
|
2467
|
+
const closestDistance = Math.sqrt(closestDistanceSq);
|
|
2468
|
+
if (!target.point) target.point = temp1.clone();
|
|
2469
|
+
else target.point.copy(temp1);
|
|
2470
|
+
target.distance = closestDistance, target.faceIndex = closestDistanceTriIndex;
|
|
2471
|
+
return target;
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
// node_modules/three-mesh-bvh/src/utils/ThreeRayIntersectUtilities.js
|
|
2475
|
+
import { Vector3 as Vector36, Vector2 as Vector23, Triangle as Triangle2, DoubleSide, BackSide, REVISION } from "three";
|
|
2476
|
+
var IS_GT_REVISION_169 = parseInt(REVISION) >= 169;
|
|
2477
|
+
var IS_LT_REVISION_161 = parseInt(REVISION) <= 161;
|
|
2478
|
+
var _vA = /* @__PURE__ */ new Vector36();
|
|
2479
|
+
var _vB = /* @__PURE__ */ new Vector36();
|
|
2480
|
+
var _vC = /* @__PURE__ */ new Vector36();
|
|
2481
|
+
var _uvA = /* @__PURE__ */ new Vector23();
|
|
2482
|
+
var _uvB = /* @__PURE__ */ new Vector23();
|
|
2483
|
+
var _uvC = /* @__PURE__ */ new Vector23();
|
|
2484
|
+
var _normalA = /* @__PURE__ */ new Vector36();
|
|
2485
|
+
var _normalB = /* @__PURE__ */ new Vector36();
|
|
2486
|
+
var _normalC = /* @__PURE__ */ new Vector36();
|
|
2487
|
+
var _intersectionPoint = /* @__PURE__ */ new Vector36();
|
|
2488
|
+
function checkIntersection(ray, pA, pB, pC, point, side, near, far) {
|
|
2489
|
+
let intersect;
|
|
2490
|
+
if (side === BackSide) {
|
|
2491
|
+
intersect = ray.intersectTriangle(pC, pB, pA, true, point);
|
|
2492
|
+
} else {
|
|
2493
|
+
intersect = ray.intersectTriangle(pA, pB, pC, side !== DoubleSide, point);
|
|
2494
|
+
}
|
|
2495
|
+
if (intersect === null) return null;
|
|
2496
|
+
const distance = ray.origin.distanceTo(point);
|
|
2497
|
+
if (distance < near || distance > far) return null;
|
|
2498
|
+
return {
|
|
2499
|
+
distance,
|
|
2500
|
+
point: point.clone()
|
|
2501
|
+
};
|
|
2502
|
+
}
|
|
2503
|
+
function checkBufferGeometryIntersection(ray, position, normal, uv, uv1, a, b, c, side, near, far) {
|
|
2504
|
+
_vA.fromBufferAttribute(position, a);
|
|
2505
|
+
_vB.fromBufferAttribute(position, b);
|
|
2506
|
+
_vC.fromBufferAttribute(position, c);
|
|
2507
|
+
const intersection = checkIntersection(ray, _vA, _vB, _vC, _intersectionPoint, side, near, far);
|
|
2508
|
+
if (intersection) {
|
|
2509
|
+
if (uv) {
|
|
2510
|
+
_uvA.fromBufferAttribute(uv, a);
|
|
2511
|
+
_uvB.fromBufferAttribute(uv, b);
|
|
2512
|
+
_uvC.fromBufferAttribute(uv, c);
|
|
2513
|
+
intersection.uv = new Vector23();
|
|
2514
|
+
const res = Triangle2.getInterpolation(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, intersection.uv);
|
|
2515
|
+
if (!IS_GT_REVISION_169) {
|
|
2516
|
+
intersection.uv = res;
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
if (uv1) {
|
|
2520
|
+
_uvA.fromBufferAttribute(uv1, a);
|
|
2521
|
+
_uvB.fromBufferAttribute(uv1, b);
|
|
2522
|
+
_uvC.fromBufferAttribute(uv1, c);
|
|
2523
|
+
intersection.uv1 = new Vector23();
|
|
2524
|
+
const res = Triangle2.getInterpolation(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, intersection.uv1);
|
|
2525
|
+
if (!IS_GT_REVISION_169) {
|
|
2526
|
+
intersection.uv1 = res;
|
|
2527
|
+
}
|
|
2528
|
+
if (IS_LT_REVISION_161) {
|
|
2529
|
+
intersection.uv2 = intersection.uv1;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
if (normal) {
|
|
2533
|
+
_normalA.fromBufferAttribute(normal, a);
|
|
2534
|
+
_normalB.fromBufferAttribute(normal, b);
|
|
2535
|
+
_normalC.fromBufferAttribute(normal, c);
|
|
2536
|
+
intersection.normal = new Vector36();
|
|
2537
|
+
const res = Triangle2.getInterpolation(_intersectionPoint, _vA, _vB, _vC, _normalA, _normalB, _normalC, intersection.normal);
|
|
2538
|
+
if (intersection.normal.dot(ray.direction) > 0) {
|
|
2539
|
+
intersection.normal.multiplyScalar(-1);
|
|
2540
|
+
}
|
|
2541
|
+
if (!IS_GT_REVISION_169) {
|
|
2542
|
+
intersection.normal = res;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
const face = {
|
|
2546
|
+
a,
|
|
2547
|
+
b,
|
|
2548
|
+
c,
|
|
2549
|
+
normal: new Vector36(),
|
|
2550
|
+
materialIndex: 0
|
|
2551
|
+
};
|
|
2552
|
+
Triangle2.getNormal(_vA, _vB, _vC, face.normal);
|
|
2553
|
+
intersection.face = face;
|
|
2554
|
+
intersection.faceIndex = a;
|
|
2555
|
+
if (IS_GT_REVISION_169) {
|
|
2556
|
+
const barycoord = new Vector36();
|
|
2557
|
+
Triangle2.getBarycoord(_intersectionPoint, _vA, _vB, _vC, barycoord);
|
|
2558
|
+
intersection.barycoord = barycoord;
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
return intersection;
|
|
2562
|
+
}
|
|
2563
|
+
function getSide(materialOrSide) {
|
|
2564
|
+
return materialOrSide && materialOrSide.isMaterial ? materialOrSide.side : materialOrSide;
|
|
2565
|
+
}
|
|
2566
|
+
function intersectTri(geometry, materialOrSide, ray, tri, intersections, near, far) {
|
|
2567
|
+
const triOffset = tri * 3;
|
|
2568
|
+
let a = triOffset + 0;
|
|
2569
|
+
let b = triOffset + 1;
|
|
2570
|
+
let c = triOffset + 2;
|
|
2571
|
+
const { index, groups } = geometry;
|
|
2572
|
+
if (geometry.index) {
|
|
2573
|
+
a = index.getX(a);
|
|
2574
|
+
b = index.getX(b);
|
|
2575
|
+
c = index.getX(c);
|
|
2576
|
+
}
|
|
2577
|
+
const { position, normal, uv, uv1 } = geometry.attributes;
|
|
2578
|
+
if (Array.isArray(materialOrSide)) {
|
|
2579
|
+
const firstIndex = tri * 3;
|
|
2580
|
+
for (let i = 0, l = groups.length; i < l; i++) {
|
|
2581
|
+
const { start, count, materialIndex } = groups[i];
|
|
2582
|
+
if (firstIndex >= start && firstIndex < start + count) {
|
|
2583
|
+
const side = getSide(materialOrSide[materialIndex]);
|
|
2584
|
+
const intersection = checkBufferGeometryIntersection(ray, position, normal, uv, uv1, a, b, c, side, near, far);
|
|
2585
|
+
if (intersection) {
|
|
2586
|
+
intersection.faceIndex = tri;
|
|
2587
|
+
intersection.face.materialIndex = materialIndex;
|
|
2588
|
+
if (intersections) {
|
|
2589
|
+
intersections.push(intersection);
|
|
2590
|
+
} else {
|
|
2591
|
+
return intersection;
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
} else {
|
|
2597
|
+
const side = getSide(materialOrSide);
|
|
2598
|
+
const intersection = checkBufferGeometryIntersection(ray, position, normal, uv, uv1, a, b, c, side, near, far);
|
|
2599
|
+
if (intersection) {
|
|
2600
|
+
intersection.faceIndex = tri;
|
|
2601
|
+
intersection.face.materialIndex = 0;
|
|
2602
|
+
if (intersections) {
|
|
2603
|
+
intersections.push(intersection);
|
|
2604
|
+
} else {
|
|
2605
|
+
return intersection;
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
return null;
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
// node_modules/three-mesh-bvh/src/utils/TriangleUtilities.js
|
|
2613
|
+
import { Vector2 as Vector24, Vector3 as Vector37, Triangle as Triangle3 } from "three";
|
|
2614
|
+
function setTriangle(tri, i, index, pos) {
|
|
2615
|
+
const ta = tri.a;
|
|
2616
|
+
const tb = tri.b;
|
|
2617
|
+
const tc = tri.c;
|
|
2618
|
+
let i0 = i;
|
|
2619
|
+
let i1 = i + 1;
|
|
2620
|
+
let i2 = i + 2;
|
|
2621
|
+
if (index) {
|
|
2622
|
+
i0 = index.getX(i0);
|
|
2623
|
+
i1 = index.getX(i1);
|
|
2624
|
+
i2 = index.getX(i2);
|
|
2625
|
+
}
|
|
2626
|
+
ta.x = pos.getX(i0);
|
|
2627
|
+
ta.y = pos.getY(i0);
|
|
2628
|
+
ta.z = pos.getZ(i0);
|
|
2629
|
+
tb.x = pos.getX(i1);
|
|
2630
|
+
tb.y = pos.getY(i1);
|
|
2631
|
+
tb.z = pos.getZ(i1);
|
|
2632
|
+
tc.x = pos.getX(i2);
|
|
2633
|
+
tc.y = pos.getY(i2);
|
|
2634
|
+
tc.z = pos.getZ(i2);
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
// node_modules/three-mesh-bvh/src/core/utils/iterationUtils.generated.js
|
|
2638
|
+
function intersectTris(bvh, materialOrSide, ray, offset, count, intersections, near, far) {
|
|
2639
|
+
const { geometry, _indirectBuffer } = bvh;
|
|
2640
|
+
for (let i = offset, end = offset + count; i < end; i++) {
|
|
2641
|
+
intersectTri(geometry, materialOrSide, ray, i, intersections, near, far);
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
function intersectClosestTri(bvh, materialOrSide, ray, offset, count, near, far) {
|
|
2645
|
+
const { geometry, _indirectBuffer } = bvh;
|
|
2646
|
+
let dist = Infinity;
|
|
2647
|
+
let res = null;
|
|
2648
|
+
for (let i = offset, end = offset + count; i < end; i++) {
|
|
2649
|
+
let intersection;
|
|
2650
|
+
intersection = intersectTri(geometry, materialOrSide, ray, i, null, near, far);
|
|
2651
|
+
if (intersection && intersection.distance < dist) {
|
|
2652
|
+
res = intersection;
|
|
2653
|
+
dist = intersection.distance;
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
return res;
|
|
2657
|
+
}
|
|
2658
|
+
function iterateOverTriangles(offset, count, bvh, intersectsTriangleFunc, contained, depth, triangle4) {
|
|
2659
|
+
const { geometry } = bvh;
|
|
2660
|
+
const { index } = geometry;
|
|
2661
|
+
const pos = geometry.attributes.position;
|
|
2662
|
+
for (let i = offset, l = count + offset; i < l; i++) {
|
|
2663
|
+
let tri;
|
|
2664
|
+
tri = i;
|
|
2665
|
+
setTriangle(triangle4, tri * 3, index, pos);
|
|
2666
|
+
triangle4.needsUpdate = true;
|
|
2667
|
+
if (intersectsTriangleFunc(triangle4, tri, contained, depth)) {
|
|
2668
|
+
return true;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
return false;
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2674
|
+
// node_modules/three-mesh-bvh/src/core/cast/refit.generated.js
|
|
2675
|
+
function refit(bvh, nodeIndices = null) {
|
|
2676
|
+
if (nodeIndices && Array.isArray(nodeIndices)) {
|
|
2677
|
+
nodeIndices = new Set(nodeIndices);
|
|
2678
|
+
}
|
|
2679
|
+
const geometry = bvh.geometry;
|
|
2680
|
+
const indexArr = geometry.index ? geometry.index.array : null;
|
|
2681
|
+
const posAttr = geometry.attributes.position;
|
|
2682
|
+
let buffer, uint32Array2, uint16Array2, float32Array2;
|
|
2683
|
+
let byteOffset = 0;
|
|
2684
|
+
const roots = bvh._roots;
|
|
2685
|
+
for (let i = 0, l = roots.length; i < l; i++) {
|
|
2686
|
+
buffer = roots[i];
|
|
2687
|
+
uint32Array2 = new Uint32Array(buffer);
|
|
2688
|
+
uint16Array2 = new Uint16Array(buffer);
|
|
2689
|
+
float32Array2 = new Float32Array(buffer);
|
|
2690
|
+
_traverse2(0, byteOffset);
|
|
2691
|
+
byteOffset += buffer.byteLength;
|
|
2692
|
+
}
|
|
2693
|
+
function _traverse2(nodeIndex32, byteOffset2, force = false) {
|
|
2694
|
+
const nodeIndex16 = nodeIndex32 * 2;
|
|
2695
|
+
if (IS_LEAF(nodeIndex16, uint16Array2)) {
|
|
2696
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
2697
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
2698
|
+
let minx = Infinity;
|
|
2699
|
+
let miny = Infinity;
|
|
2700
|
+
let minz = Infinity;
|
|
2701
|
+
let maxx = -Infinity;
|
|
2702
|
+
let maxy = -Infinity;
|
|
2703
|
+
let maxz = -Infinity;
|
|
2704
|
+
for (let i = 3 * offset, l = 3 * (offset + count); i < l; i++) {
|
|
2705
|
+
let index = indexArr[i];
|
|
2706
|
+
const x = posAttr.getX(index);
|
|
2707
|
+
const y = posAttr.getY(index);
|
|
2708
|
+
const z = posAttr.getZ(index);
|
|
2709
|
+
if (x < minx) minx = x;
|
|
2710
|
+
if (x > maxx) maxx = x;
|
|
2711
|
+
if (y < miny) miny = y;
|
|
2712
|
+
if (y > maxy) maxy = y;
|
|
2713
|
+
if (z < minz) minz = z;
|
|
2714
|
+
if (z > maxz) maxz = z;
|
|
2715
|
+
}
|
|
2716
|
+
if (float32Array2[nodeIndex32 + 0] !== minx || float32Array2[nodeIndex32 + 1] !== miny || float32Array2[nodeIndex32 + 2] !== minz || float32Array2[nodeIndex32 + 3] !== maxx || float32Array2[nodeIndex32 + 4] !== maxy || float32Array2[nodeIndex32 + 5] !== maxz) {
|
|
2717
|
+
float32Array2[nodeIndex32 + 0] = minx;
|
|
2718
|
+
float32Array2[nodeIndex32 + 1] = miny;
|
|
2719
|
+
float32Array2[nodeIndex32 + 2] = minz;
|
|
2720
|
+
float32Array2[nodeIndex32 + 3] = maxx;
|
|
2721
|
+
float32Array2[nodeIndex32 + 4] = maxy;
|
|
2722
|
+
float32Array2[nodeIndex32 + 5] = maxz;
|
|
2723
|
+
return true;
|
|
2724
|
+
} else {
|
|
2725
|
+
return false;
|
|
2726
|
+
}
|
|
2727
|
+
} else {
|
|
2728
|
+
const left = LEFT_NODE(nodeIndex32);
|
|
2729
|
+
const right = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
2730
|
+
let forceChildren = force;
|
|
2731
|
+
let includesLeft = false;
|
|
2732
|
+
let includesRight = false;
|
|
2733
|
+
if (nodeIndices) {
|
|
2734
|
+
if (!forceChildren) {
|
|
2735
|
+
const leftNodeId = left / UINT32_PER_NODE + byteOffset2 / BYTES_PER_NODE;
|
|
2736
|
+
const rightNodeId = right / UINT32_PER_NODE + byteOffset2 / BYTES_PER_NODE;
|
|
2737
|
+
includesLeft = nodeIndices.has(leftNodeId);
|
|
2738
|
+
includesRight = nodeIndices.has(rightNodeId);
|
|
2739
|
+
forceChildren = !includesLeft && !includesRight;
|
|
2740
|
+
}
|
|
2741
|
+
} else {
|
|
2742
|
+
includesLeft = true;
|
|
2743
|
+
includesRight = true;
|
|
2744
|
+
}
|
|
2745
|
+
const traverseLeft = forceChildren || includesLeft;
|
|
2746
|
+
const traverseRight = forceChildren || includesRight;
|
|
2747
|
+
let leftChange = false;
|
|
2748
|
+
if (traverseLeft) {
|
|
2749
|
+
leftChange = _traverse2(left, byteOffset2, forceChildren);
|
|
2750
|
+
}
|
|
2751
|
+
let rightChange = false;
|
|
2752
|
+
if (traverseRight) {
|
|
2753
|
+
rightChange = _traverse2(right, byteOffset2, forceChildren);
|
|
2754
|
+
}
|
|
2755
|
+
const didChange = leftChange || rightChange;
|
|
2756
|
+
if (didChange) {
|
|
2757
|
+
for (let i = 0; i < 3; i++) {
|
|
2758
|
+
const left_i = left + i;
|
|
2759
|
+
const right_i = right + i;
|
|
2760
|
+
const minLeftValue = float32Array2[left_i];
|
|
2761
|
+
const maxLeftValue = float32Array2[left_i + 3];
|
|
2762
|
+
const minRightValue = float32Array2[right_i];
|
|
2763
|
+
const maxRightValue = float32Array2[right_i + 3];
|
|
2764
|
+
float32Array2[nodeIndex32 + i] = minLeftValue < minRightValue ? minLeftValue : minRightValue;
|
|
2765
|
+
float32Array2[nodeIndex32 + i + 3] = maxLeftValue > maxRightValue ? maxLeftValue : maxRightValue;
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
return didChange;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
// node_modules/three-mesh-bvh/src/core/utils/intersectUtils.js
|
|
2774
|
+
function intersectsNodeBounds(nodeIndex32, array, ray, near, far) {
|
|
2775
|
+
let tmin, tmax, tymin, tymax, tzmin, tzmax;
|
|
2776
|
+
const invdirx = 1 / ray.direction.x, invdiry = 1 / ray.direction.y, invdirz = 1 / ray.direction.z;
|
|
2777
|
+
const ox = ray.origin.x;
|
|
2778
|
+
const oy = ray.origin.y;
|
|
2779
|
+
const oz = ray.origin.z;
|
|
2780
|
+
let minx = array[nodeIndex32];
|
|
2781
|
+
let maxx = array[nodeIndex32 + 3];
|
|
2782
|
+
let miny = array[nodeIndex32 + 1];
|
|
2783
|
+
let maxy = array[nodeIndex32 + 3 + 1];
|
|
2784
|
+
let minz = array[nodeIndex32 + 2];
|
|
2785
|
+
let maxz = array[nodeIndex32 + 3 + 2];
|
|
2786
|
+
if (invdirx >= 0) {
|
|
2787
|
+
tmin = (minx - ox) * invdirx;
|
|
2788
|
+
tmax = (maxx - ox) * invdirx;
|
|
2789
|
+
} else {
|
|
2790
|
+
tmin = (maxx - ox) * invdirx;
|
|
2791
|
+
tmax = (minx - ox) * invdirx;
|
|
2792
|
+
}
|
|
2793
|
+
if (invdiry >= 0) {
|
|
2794
|
+
tymin = (miny - oy) * invdiry;
|
|
2795
|
+
tymax = (maxy - oy) * invdiry;
|
|
2796
|
+
} else {
|
|
2797
|
+
tymin = (maxy - oy) * invdiry;
|
|
2798
|
+
tymax = (miny - oy) * invdiry;
|
|
2799
|
+
}
|
|
2800
|
+
if (tmin > tymax || tymin > tmax) return false;
|
|
2801
|
+
if (tymin > tmin || isNaN(tmin)) tmin = tymin;
|
|
2802
|
+
if (tymax < tmax || isNaN(tmax)) tmax = tymax;
|
|
2803
|
+
if (invdirz >= 0) {
|
|
2804
|
+
tzmin = (minz - oz) * invdirz;
|
|
2805
|
+
tzmax = (maxz - oz) * invdirz;
|
|
2806
|
+
} else {
|
|
2807
|
+
tzmin = (maxz - oz) * invdirz;
|
|
2808
|
+
tzmax = (minz - oz) * invdirz;
|
|
2809
|
+
}
|
|
2810
|
+
if (tmin > tzmax || tzmin > tmax) return false;
|
|
2811
|
+
if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
|
|
2812
|
+
if (tzmax < tmax || tmax !== tmax) tmax = tzmax;
|
|
2813
|
+
return tmin <= far && tmax >= near;
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
// node_modules/three-mesh-bvh/src/core/utils/iterationUtils_indirect.generated.js
|
|
2817
|
+
function intersectTris_indirect(bvh, materialOrSide, ray, offset, count, intersections, near, far) {
|
|
2818
|
+
const { geometry, _indirectBuffer } = bvh;
|
|
2819
|
+
for (let i = offset, end = offset + count; i < end; i++) {
|
|
2820
|
+
let vi = _indirectBuffer ? _indirectBuffer[i] : i;
|
|
2821
|
+
intersectTri(geometry, materialOrSide, ray, vi, intersections, near, far);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
function intersectClosestTri_indirect(bvh, materialOrSide, ray, offset, count, near, far) {
|
|
2825
|
+
const { geometry, _indirectBuffer } = bvh;
|
|
2826
|
+
let dist = Infinity;
|
|
2827
|
+
let res = null;
|
|
2828
|
+
for (let i = offset, end = offset + count; i < end; i++) {
|
|
2829
|
+
let intersection;
|
|
2830
|
+
intersection = intersectTri(geometry, materialOrSide, ray, _indirectBuffer ? _indirectBuffer[i] : i, null, near, far);
|
|
2831
|
+
if (intersection && intersection.distance < dist) {
|
|
2832
|
+
res = intersection;
|
|
2833
|
+
dist = intersection.distance;
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
return res;
|
|
2837
|
+
}
|
|
2838
|
+
function iterateOverTriangles_indirect(offset, count, bvh, intersectsTriangleFunc, contained, depth, triangle4) {
|
|
2839
|
+
const { geometry } = bvh;
|
|
2840
|
+
const { index } = geometry;
|
|
2841
|
+
const pos = geometry.attributes.position;
|
|
2842
|
+
for (let i = offset, l = count + offset; i < l; i++) {
|
|
2843
|
+
let tri;
|
|
2844
|
+
tri = bvh.resolveTriangleIndex(i);
|
|
2845
|
+
setTriangle(triangle4, tri * 3, index, pos);
|
|
2846
|
+
triangle4.needsUpdate = true;
|
|
2847
|
+
if (intersectsTriangleFunc(triangle4, tri, contained, depth)) {
|
|
2848
|
+
return true;
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
return false;
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
// node_modules/three-mesh-bvh/src/core/cast/raycast.generated.js
|
|
2855
|
+
function raycast(bvh, root, materialOrSide, ray, intersects, near, far) {
|
|
2856
|
+
BufferStack.setBuffer(bvh._roots[root]);
|
|
2857
|
+
_raycast(0, bvh, materialOrSide, ray, intersects, near, far);
|
|
2858
|
+
BufferStack.clearBuffer();
|
|
2859
|
+
}
|
|
2860
|
+
function _raycast(nodeIndex32, bvh, materialOrSide, ray, intersects, near, far) {
|
|
2861
|
+
const { float32Array: float32Array2, uint16Array: uint16Array2, uint32Array: uint32Array2 } = BufferStack;
|
|
2862
|
+
const nodeIndex16 = nodeIndex32 * 2;
|
|
2863
|
+
const isLeaf = IS_LEAF(nodeIndex16, uint16Array2);
|
|
2864
|
+
if (isLeaf) {
|
|
2865
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
2866
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
2867
|
+
intersectTris(bvh, materialOrSide, ray, offset, count, intersects, near, far);
|
|
2868
|
+
} else {
|
|
2869
|
+
const leftIndex = LEFT_NODE(nodeIndex32);
|
|
2870
|
+
if (intersectsNodeBounds(leftIndex, float32Array2, ray, near, far)) {
|
|
2871
|
+
_raycast(leftIndex, bvh, materialOrSide, ray, intersects, near, far);
|
|
2872
|
+
}
|
|
2873
|
+
const rightIndex = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
2874
|
+
if (intersectsNodeBounds(rightIndex, float32Array2, ray, near, far)) {
|
|
2875
|
+
_raycast(rightIndex, bvh, materialOrSide, ray, intersects, near, far);
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2880
|
+
// node_modules/three-mesh-bvh/src/core/cast/raycastFirst.generated.js
|
|
2881
|
+
var _xyzFields = ["x", "y", "z"];
|
|
2882
|
+
function raycastFirst(bvh, root, materialOrSide, ray, near, far) {
|
|
2883
|
+
BufferStack.setBuffer(bvh._roots[root]);
|
|
2884
|
+
const result = _raycastFirst(0, bvh, materialOrSide, ray, near, far);
|
|
2885
|
+
BufferStack.clearBuffer();
|
|
2886
|
+
return result;
|
|
2887
|
+
}
|
|
2888
|
+
function _raycastFirst(nodeIndex32, bvh, materialOrSide, ray, near, far) {
|
|
2889
|
+
const { float32Array: float32Array2, uint16Array: uint16Array2, uint32Array: uint32Array2 } = BufferStack;
|
|
2890
|
+
let nodeIndex16 = nodeIndex32 * 2;
|
|
2891
|
+
const isLeaf = IS_LEAF(nodeIndex16, uint16Array2);
|
|
2892
|
+
if (isLeaf) {
|
|
2893
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
2894
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
2895
|
+
return intersectClosestTri(bvh, materialOrSide, ray, offset, count, near, far);
|
|
2896
|
+
} else {
|
|
2897
|
+
const splitAxis = SPLIT_AXIS(nodeIndex32, uint32Array2);
|
|
2898
|
+
const xyzAxis = _xyzFields[splitAxis];
|
|
2899
|
+
const rayDir = ray.direction[xyzAxis];
|
|
2900
|
+
const leftToRight = rayDir >= 0;
|
|
2901
|
+
let c1, c2;
|
|
2902
|
+
if (leftToRight) {
|
|
2903
|
+
c1 = LEFT_NODE(nodeIndex32);
|
|
2904
|
+
c2 = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
2905
|
+
} else {
|
|
2906
|
+
c1 = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
2907
|
+
c2 = LEFT_NODE(nodeIndex32);
|
|
2908
|
+
}
|
|
2909
|
+
const c1Intersection = intersectsNodeBounds(c1, float32Array2, ray, near, far);
|
|
2910
|
+
const c1Result = c1Intersection ? _raycastFirst(c1, bvh, materialOrSide, ray, near, far) : null;
|
|
2911
|
+
if (c1Result) {
|
|
2912
|
+
const point = c1Result.point[xyzAxis];
|
|
2913
|
+
const isOutside = leftToRight ? point <= float32Array2[c2 + splitAxis] : (
|
|
2914
|
+
// min bounding data
|
|
2915
|
+
point >= float32Array2[c2 + splitAxis + 3]
|
|
2916
|
+
);
|
|
2917
|
+
if (isOutside) {
|
|
2918
|
+
return c1Result;
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
const c2Intersection = intersectsNodeBounds(c2, float32Array2, ray, near, far);
|
|
2922
|
+
const c2Result = c2Intersection ? _raycastFirst(c2, bvh, materialOrSide, ray, near, far) : null;
|
|
2923
|
+
if (c1Result && c2Result) {
|
|
2924
|
+
return c1Result.distance <= c2Result.distance ? c1Result : c2Result;
|
|
2925
|
+
} else {
|
|
2926
|
+
return c1Result || c2Result || null;
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2931
|
+
// node_modules/three-mesh-bvh/src/core/cast/intersectsGeometry.generated.js
|
|
2932
|
+
import { Box3 as Box35, Matrix4 as Matrix43 } from "three";
|
|
2933
|
+
var boundingBox = /* @__PURE__ */ new Box35();
|
|
2934
|
+
var triangle = /* @__PURE__ */ new ExtendedTriangle();
|
|
2935
|
+
var triangle2 = /* @__PURE__ */ new ExtendedTriangle();
|
|
2936
|
+
var invertedMat = /* @__PURE__ */ new Matrix43();
|
|
2937
|
+
var obb = /* @__PURE__ */ new OrientedBox();
|
|
2938
|
+
var obb2 = /* @__PURE__ */ new OrientedBox();
|
|
2939
|
+
function intersectsGeometry(bvh, root, otherGeometry, geometryToBvh) {
|
|
2940
|
+
BufferStack.setBuffer(bvh._roots[root]);
|
|
2941
|
+
const result = _intersectsGeometry(0, bvh, otherGeometry, geometryToBvh);
|
|
2942
|
+
BufferStack.clearBuffer();
|
|
2943
|
+
return result;
|
|
2944
|
+
}
|
|
2945
|
+
function _intersectsGeometry(nodeIndex32, bvh, otherGeometry, geometryToBvh, cachedObb = null) {
|
|
2946
|
+
const { float32Array: float32Array2, uint16Array: uint16Array2, uint32Array: uint32Array2 } = BufferStack;
|
|
2947
|
+
let nodeIndex16 = nodeIndex32 * 2;
|
|
2948
|
+
if (cachedObb === null) {
|
|
2949
|
+
if (!otherGeometry.boundingBox) {
|
|
2950
|
+
otherGeometry.computeBoundingBox();
|
|
2951
|
+
}
|
|
2952
|
+
obb.set(otherGeometry.boundingBox.min, otherGeometry.boundingBox.max, geometryToBvh);
|
|
2953
|
+
cachedObb = obb;
|
|
2954
|
+
}
|
|
2955
|
+
const isLeaf = IS_LEAF(nodeIndex16, uint16Array2);
|
|
2956
|
+
if (isLeaf) {
|
|
2957
|
+
const thisGeometry = bvh.geometry;
|
|
2958
|
+
const thisIndex = thisGeometry.index;
|
|
2959
|
+
const thisPos = thisGeometry.attributes.position;
|
|
2960
|
+
const otherIndex = otherGeometry.index;
|
|
2961
|
+
const otherPos = otherGeometry.attributes.position;
|
|
2962
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
2963
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
2964
|
+
invertedMat.copy(geometryToBvh).invert();
|
|
2965
|
+
if (otherGeometry.boundsTree) {
|
|
2966
|
+
arrayToBox(BOUNDING_DATA_INDEX(nodeIndex32), float32Array2, obb2);
|
|
2967
|
+
obb2.matrix.copy(invertedMat);
|
|
2968
|
+
obb2.needsUpdate = true;
|
|
2969
|
+
const res = otherGeometry.boundsTree.shapecast({
|
|
2970
|
+
intersectsBounds: (box) => obb2.intersectsBox(box),
|
|
2971
|
+
intersectsTriangle: (tri) => {
|
|
2972
|
+
tri.a.applyMatrix4(geometryToBvh);
|
|
2973
|
+
tri.b.applyMatrix4(geometryToBvh);
|
|
2974
|
+
tri.c.applyMatrix4(geometryToBvh);
|
|
2975
|
+
tri.needsUpdate = true;
|
|
2976
|
+
for (let i = offset * 3, l = (count + offset) * 3; i < l; i += 3) {
|
|
2977
|
+
setTriangle(triangle2, i, thisIndex, thisPos);
|
|
2978
|
+
triangle2.needsUpdate = true;
|
|
2979
|
+
if (tri.intersectsTriangle(triangle2)) {
|
|
2980
|
+
return true;
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
return false;
|
|
2984
|
+
}
|
|
2985
|
+
});
|
|
2986
|
+
return res;
|
|
2987
|
+
} else {
|
|
2988
|
+
const otherTriangleCount = getTriCount(otherGeometry);
|
|
2989
|
+
for (let i = offset * 3, l = (count + offset) * 3; i < l; i += 3) {
|
|
2990
|
+
setTriangle(triangle, i, thisIndex, thisPos);
|
|
2991
|
+
triangle.a.applyMatrix4(invertedMat);
|
|
2992
|
+
triangle.b.applyMatrix4(invertedMat);
|
|
2993
|
+
triangle.c.applyMatrix4(invertedMat);
|
|
2994
|
+
triangle.needsUpdate = true;
|
|
2995
|
+
for (let i2 = 0, l2 = otherTriangleCount * 3; i2 < l2; i2 += 3) {
|
|
2996
|
+
setTriangle(triangle2, i2, otherIndex, otherPos);
|
|
2997
|
+
triangle2.needsUpdate = true;
|
|
2998
|
+
if (triangle.intersectsTriangle(triangle2)) {
|
|
2999
|
+
return true;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
} else {
|
|
3005
|
+
const left = LEFT_NODE(nodeIndex32);
|
|
3006
|
+
const right = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
3007
|
+
arrayToBox(BOUNDING_DATA_INDEX(left), float32Array2, boundingBox);
|
|
3008
|
+
const leftIntersection = cachedObb.intersectsBox(boundingBox) && _intersectsGeometry(left, bvh, otherGeometry, geometryToBvh, cachedObb);
|
|
3009
|
+
if (leftIntersection) return true;
|
|
3010
|
+
arrayToBox(BOUNDING_DATA_INDEX(right), float32Array2, boundingBox);
|
|
3011
|
+
const rightIntersection = cachedObb.intersectsBox(boundingBox) && _intersectsGeometry(right, bvh, otherGeometry, geometryToBvh, cachedObb);
|
|
3012
|
+
if (rightIntersection) return true;
|
|
3013
|
+
return false;
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
// node_modules/three-mesh-bvh/src/core/cast/closestPointToGeometry.generated.js
|
|
3018
|
+
import { Matrix4 as Matrix44, Vector3 as Vector38 } from "three";
|
|
3019
|
+
var tempMatrix = /* @__PURE__ */ new Matrix44();
|
|
3020
|
+
var obb3 = /* @__PURE__ */ new OrientedBox();
|
|
3021
|
+
var obb22 = /* @__PURE__ */ new OrientedBox();
|
|
3022
|
+
var temp12 = /* @__PURE__ */ new Vector38();
|
|
3023
|
+
var temp2 = /* @__PURE__ */ new Vector38();
|
|
3024
|
+
var temp3 = /* @__PURE__ */ new Vector38();
|
|
3025
|
+
var temp4 = /* @__PURE__ */ new Vector38();
|
|
3026
|
+
function closestPointToGeometry(bvh, otherGeometry, geometryToBvh, target1 = {}, target2 = {}, minThreshold = 0, maxThreshold = Infinity) {
|
|
3027
|
+
if (!otherGeometry.boundingBox) {
|
|
3028
|
+
otherGeometry.computeBoundingBox();
|
|
3029
|
+
}
|
|
3030
|
+
obb3.set(otherGeometry.boundingBox.min, otherGeometry.boundingBox.max, geometryToBvh);
|
|
3031
|
+
obb3.needsUpdate = true;
|
|
3032
|
+
const geometry = bvh.geometry;
|
|
3033
|
+
const pos = geometry.attributes.position;
|
|
3034
|
+
const index = geometry.index;
|
|
3035
|
+
const otherPos = otherGeometry.attributes.position;
|
|
3036
|
+
const otherIndex = otherGeometry.index;
|
|
3037
|
+
const triangle4 = ExtendedTrianglePool.getPrimitive();
|
|
3038
|
+
const triangle23 = ExtendedTrianglePool.getPrimitive();
|
|
3039
|
+
let tempTarget1 = temp12;
|
|
3040
|
+
let tempTargetDest1 = temp2;
|
|
3041
|
+
let tempTarget2 = null;
|
|
3042
|
+
let tempTargetDest2 = null;
|
|
3043
|
+
if (target2) {
|
|
3044
|
+
tempTarget2 = temp3;
|
|
3045
|
+
tempTargetDest2 = temp4;
|
|
3046
|
+
}
|
|
3047
|
+
let closestDistance = Infinity;
|
|
3048
|
+
let closestDistanceTriIndex = null;
|
|
3049
|
+
let closestDistanceOtherTriIndex = null;
|
|
3050
|
+
tempMatrix.copy(geometryToBvh).invert();
|
|
3051
|
+
obb22.matrix.copy(tempMatrix);
|
|
3052
|
+
bvh.shapecast(
|
|
3053
|
+
{
|
|
3054
|
+
boundsTraverseOrder: (box) => {
|
|
3055
|
+
return obb3.distanceToBox(box);
|
|
3056
|
+
},
|
|
3057
|
+
intersectsBounds: (box, isLeaf, score) => {
|
|
3058
|
+
if (score < closestDistance && score < maxThreshold) {
|
|
3059
|
+
if (isLeaf) {
|
|
3060
|
+
obb22.min.copy(box.min);
|
|
3061
|
+
obb22.max.copy(box.max);
|
|
3062
|
+
obb22.needsUpdate = true;
|
|
3063
|
+
}
|
|
3064
|
+
return true;
|
|
3065
|
+
}
|
|
3066
|
+
return false;
|
|
3067
|
+
},
|
|
3068
|
+
intersectsRange: (offset, count) => {
|
|
3069
|
+
if (otherGeometry.boundsTree) {
|
|
3070
|
+
const otherBvh = otherGeometry.boundsTree;
|
|
3071
|
+
return otherBvh.shapecast({
|
|
3072
|
+
boundsTraverseOrder: (box) => {
|
|
3073
|
+
return obb22.distanceToBox(box);
|
|
3074
|
+
},
|
|
3075
|
+
intersectsBounds: (box, isLeaf, score) => {
|
|
3076
|
+
return score < closestDistance && score < maxThreshold;
|
|
3077
|
+
},
|
|
3078
|
+
intersectsRange: (otherOffset, otherCount) => {
|
|
3079
|
+
for (let i2 = otherOffset, l2 = otherOffset + otherCount; i2 < l2; i2++) {
|
|
3080
|
+
setTriangle(triangle23, 3 * i2, otherIndex, otherPos);
|
|
3081
|
+
triangle23.a.applyMatrix4(geometryToBvh);
|
|
3082
|
+
triangle23.b.applyMatrix4(geometryToBvh);
|
|
3083
|
+
triangle23.c.applyMatrix4(geometryToBvh);
|
|
3084
|
+
triangle23.needsUpdate = true;
|
|
3085
|
+
for (let i = offset, l = offset + count; i < l; i++) {
|
|
3086
|
+
setTriangle(triangle4, 3 * i, index, pos);
|
|
3087
|
+
triangle4.needsUpdate = true;
|
|
3088
|
+
const dist = triangle4.distanceToTriangle(triangle23, tempTarget1, tempTarget2);
|
|
3089
|
+
if (dist < closestDistance) {
|
|
3090
|
+
tempTargetDest1.copy(tempTarget1);
|
|
3091
|
+
if (tempTargetDest2) {
|
|
3092
|
+
tempTargetDest2.copy(tempTarget2);
|
|
3093
|
+
}
|
|
3094
|
+
closestDistance = dist;
|
|
3095
|
+
closestDistanceTriIndex = i;
|
|
3096
|
+
closestDistanceOtherTriIndex = i2;
|
|
3097
|
+
}
|
|
3098
|
+
if (dist < minThreshold) {
|
|
3099
|
+
return true;
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
});
|
|
3105
|
+
} else {
|
|
3106
|
+
const triCount = getTriCount(otherGeometry);
|
|
3107
|
+
for (let i2 = 0, l2 = triCount; i2 < l2; i2++) {
|
|
3108
|
+
setTriangle(triangle23, 3 * i2, otherIndex, otherPos);
|
|
3109
|
+
triangle23.a.applyMatrix4(geometryToBvh);
|
|
3110
|
+
triangle23.b.applyMatrix4(geometryToBvh);
|
|
3111
|
+
triangle23.c.applyMatrix4(geometryToBvh);
|
|
3112
|
+
triangle23.needsUpdate = true;
|
|
3113
|
+
for (let i = offset, l = offset + count; i < l; i++) {
|
|
3114
|
+
setTriangle(triangle4, 3 * i, index, pos);
|
|
3115
|
+
triangle4.needsUpdate = true;
|
|
3116
|
+
const dist = triangle4.distanceToTriangle(triangle23, tempTarget1, tempTarget2);
|
|
3117
|
+
if (dist < closestDistance) {
|
|
3118
|
+
tempTargetDest1.copy(tempTarget1);
|
|
3119
|
+
if (tempTargetDest2) {
|
|
3120
|
+
tempTargetDest2.copy(tempTarget2);
|
|
3121
|
+
}
|
|
3122
|
+
closestDistance = dist;
|
|
3123
|
+
closestDistanceTriIndex = i;
|
|
3124
|
+
closestDistanceOtherTriIndex = i2;
|
|
3125
|
+
}
|
|
3126
|
+
if (dist < minThreshold) {
|
|
3127
|
+
return true;
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
);
|
|
3135
|
+
ExtendedTrianglePool.releasePrimitive(triangle4);
|
|
3136
|
+
ExtendedTrianglePool.releasePrimitive(triangle23);
|
|
3137
|
+
if (closestDistance === Infinity) {
|
|
3138
|
+
return null;
|
|
3139
|
+
}
|
|
3140
|
+
if (!target1.point) {
|
|
3141
|
+
target1.point = tempTargetDest1.clone();
|
|
3142
|
+
} else {
|
|
3143
|
+
target1.point.copy(tempTargetDest1);
|
|
3144
|
+
}
|
|
3145
|
+
target1.distance = closestDistance, target1.faceIndex = closestDistanceTriIndex;
|
|
3146
|
+
if (target2) {
|
|
3147
|
+
if (!target2.point) target2.point = tempTargetDest2.clone();
|
|
3148
|
+
else target2.point.copy(tempTargetDest2);
|
|
3149
|
+
target2.point.applyMatrix4(tempMatrix);
|
|
3150
|
+
tempTargetDest1.applyMatrix4(tempMatrix);
|
|
3151
|
+
target2.distance = tempTargetDest1.sub(target2.point).length();
|
|
3152
|
+
target2.faceIndex = closestDistanceOtherTriIndex;
|
|
3153
|
+
}
|
|
3154
|
+
return target1;
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3157
|
+
// node_modules/three-mesh-bvh/src/core/cast/refit_indirect.generated.js
|
|
3158
|
+
function refit_indirect(bvh, nodeIndices = null) {
|
|
3159
|
+
if (nodeIndices && Array.isArray(nodeIndices)) {
|
|
3160
|
+
nodeIndices = new Set(nodeIndices);
|
|
3161
|
+
}
|
|
3162
|
+
const geometry = bvh.geometry;
|
|
3163
|
+
const indexArr = geometry.index ? geometry.index.array : null;
|
|
3164
|
+
const posAttr = geometry.attributes.position;
|
|
3165
|
+
let buffer, uint32Array2, uint16Array2, float32Array2;
|
|
3166
|
+
let byteOffset = 0;
|
|
3167
|
+
const roots = bvh._roots;
|
|
3168
|
+
for (let i = 0, l = roots.length; i < l; i++) {
|
|
3169
|
+
buffer = roots[i];
|
|
3170
|
+
uint32Array2 = new Uint32Array(buffer);
|
|
3171
|
+
uint16Array2 = new Uint16Array(buffer);
|
|
3172
|
+
float32Array2 = new Float32Array(buffer);
|
|
3173
|
+
_traverse2(0, byteOffset);
|
|
3174
|
+
byteOffset += buffer.byteLength;
|
|
3175
|
+
}
|
|
3176
|
+
function _traverse2(nodeIndex32, byteOffset2, force = false) {
|
|
3177
|
+
const nodeIndex16 = nodeIndex32 * 2;
|
|
3178
|
+
if (IS_LEAF(nodeIndex16, uint16Array2)) {
|
|
3179
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
3180
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
3181
|
+
let minx = Infinity;
|
|
3182
|
+
let miny = Infinity;
|
|
3183
|
+
let minz = Infinity;
|
|
3184
|
+
let maxx = -Infinity;
|
|
3185
|
+
let maxy = -Infinity;
|
|
3186
|
+
let maxz = -Infinity;
|
|
3187
|
+
for (let i = offset, l = offset + count; i < l; i++) {
|
|
3188
|
+
const t = 3 * bvh.resolveTriangleIndex(i);
|
|
3189
|
+
for (let j = 0; j < 3; j++) {
|
|
3190
|
+
let index = t + j;
|
|
3191
|
+
index = indexArr ? indexArr[index] : index;
|
|
3192
|
+
const x = posAttr.getX(index);
|
|
3193
|
+
const y = posAttr.getY(index);
|
|
3194
|
+
const z = posAttr.getZ(index);
|
|
3195
|
+
if (x < minx) minx = x;
|
|
3196
|
+
if (x > maxx) maxx = x;
|
|
3197
|
+
if (y < miny) miny = y;
|
|
3198
|
+
if (y > maxy) maxy = y;
|
|
3199
|
+
if (z < minz) minz = z;
|
|
3200
|
+
if (z > maxz) maxz = z;
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
if (float32Array2[nodeIndex32 + 0] !== minx || float32Array2[nodeIndex32 + 1] !== miny || float32Array2[nodeIndex32 + 2] !== minz || float32Array2[nodeIndex32 + 3] !== maxx || float32Array2[nodeIndex32 + 4] !== maxy || float32Array2[nodeIndex32 + 5] !== maxz) {
|
|
3204
|
+
float32Array2[nodeIndex32 + 0] = minx;
|
|
3205
|
+
float32Array2[nodeIndex32 + 1] = miny;
|
|
3206
|
+
float32Array2[nodeIndex32 + 2] = minz;
|
|
3207
|
+
float32Array2[nodeIndex32 + 3] = maxx;
|
|
3208
|
+
float32Array2[nodeIndex32 + 4] = maxy;
|
|
3209
|
+
float32Array2[nodeIndex32 + 5] = maxz;
|
|
3210
|
+
return true;
|
|
3211
|
+
} else {
|
|
3212
|
+
return false;
|
|
3213
|
+
}
|
|
3214
|
+
} else {
|
|
3215
|
+
const left = LEFT_NODE(nodeIndex32);
|
|
3216
|
+
const right = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
3217
|
+
let forceChildren = force;
|
|
3218
|
+
let includesLeft = false;
|
|
3219
|
+
let includesRight = false;
|
|
3220
|
+
if (nodeIndices) {
|
|
3221
|
+
if (!forceChildren) {
|
|
3222
|
+
const leftNodeId = left / UINT32_PER_NODE + byteOffset2 / BYTES_PER_NODE;
|
|
3223
|
+
const rightNodeId = right / UINT32_PER_NODE + byteOffset2 / BYTES_PER_NODE;
|
|
3224
|
+
includesLeft = nodeIndices.has(leftNodeId);
|
|
3225
|
+
includesRight = nodeIndices.has(rightNodeId);
|
|
3226
|
+
forceChildren = !includesLeft && !includesRight;
|
|
3227
|
+
}
|
|
3228
|
+
} else {
|
|
3229
|
+
includesLeft = true;
|
|
3230
|
+
includesRight = true;
|
|
3231
|
+
}
|
|
3232
|
+
const traverseLeft = forceChildren || includesLeft;
|
|
3233
|
+
const traverseRight = forceChildren || includesRight;
|
|
3234
|
+
let leftChange = false;
|
|
3235
|
+
if (traverseLeft) {
|
|
3236
|
+
leftChange = _traverse2(left, byteOffset2, forceChildren);
|
|
3237
|
+
}
|
|
3238
|
+
let rightChange = false;
|
|
3239
|
+
if (traverseRight) {
|
|
3240
|
+
rightChange = _traverse2(right, byteOffset2, forceChildren);
|
|
3241
|
+
}
|
|
3242
|
+
const didChange = leftChange || rightChange;
|
|
3243
|
+
if (didChange) {
|
|
3244
|
+
for (let i = 0; i < 3; i++) {
|
|
3245
|
+
const left_i = left + i;
|
|
3246
|
+
const right_i = right + i;
|
|
3247
|
+
const minLeftValue = float32Array2[left_i];
|
|
3248
|
+
const maxLeftValue = float32Array2[left_i + 3];
|
|
3249
|
+
const minRightValue = float32Array2[right_i];
|
|
3250
|
+
const maxRightValue = float32Array2[right_i + 3];
|
|
3251
|
+
float32Array2[nodeIndex32 + i] = minLeftValue < minRightValue ? minLeftValue : minRightValue;
|
|
3252
|
+
float32Array2[nodeIndex32 + i + 3] = maxLeftValue > maxRightValue ? maxLeftValue : maxRightValue;
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
return didChange;
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
// node_modules/three-mesh-bvh/src/core/cast/raycast_indirect.generated.js
|
|
3261
|
+
function raycast_indirect(bvh, root, materialOrSide, ray, intersects, near, far) {
|
|
3262
|
+
BufferStack.setBuffer(bvh._roots[root]);
|
|
3263
|
+
_raycast2(0, bvh, materialOrSide, ray, intersects, near, far);
|
|
3264
|
+
BufferStack.clearBuffer();
|
|
3265
|
+
}
|
|
3266
|
+
function _raycast2(nodeIndex32, bvh, materialOrSide, ray, intersects, near, far) {
|
|
3267
|
+
const { float32Array: float32Array2, uint16Array: uint16Array2, uint32Array: uint32Array2 } = BufferStack;
|
|
3268
|
+
const nodeIndex16 = nodeIndex32 * 2;
|
|
3269
|
+
const isLeaf = IS_LEAF(nodeIndex16, uint16Array2);
|
|
3270
|
+
if (isLeaf) {
|
|
3271
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
3272
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
3273
|
+
intersectTris_indirect(bvh, materialOrSide, ray, offset, count, intersects, near, far);
|
|
3274
|
+
} else {
|
|
3275
|
+
const leftIndex = LEFT_NODE(nodeIndex32);
|
|
3276
|
+
if (intersectsNodeBounds(leftIndex, float32Array2, ray, near, far)) {
|
|
3277
|
+
_raycast2(leftIndex, bvh, materialOrSide, ray, intersects, near, far);
|
|
3278
|
+
}
|
|
3279
|
+
const rightIndex = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
3280
|
+
if (intersectsNodeBounds(rightIndex, float32Array2, ray, near, far)) {
|
|
3281
|
+
_raycast2(rightIndex, bvh, materialOrSide, ray, intersects, near, far);
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
|
|
3286
|
+
// node_modules/three-mesh-bvh/src/core/cast/raycastFirst_indirect.generated.js
|
|
3287
|
+
var _xyzFields2 = ["x", "y", "z"];
|
|
3288
|
+
function raycastFirst_indirect(bvh, root, materialOrSide, ray, near, far) {
|
|
3289
|
+
BufferStack.setBuffer(bvh._roots[root]);
|
|
3290
|
+
const result = _raycastFirst2(0, bvh, materialOrSide, ray, near, far);
|
|
3291
|
+
BufferStack.clearBuffer();
|
|
3292
|
+
return result;
|
|
3293
|
+
}
|
|
3294
|
+
function _raycastFirst2(nodeIndex32, bvh, materialOrSide, ray, near, far) {
|
|
3295
|
+
const { float32Array: float32Array2, uint16Array: uint16Array2, uint32Array: uint32Array2 } = BufferStack;
|
|
3296
|
+
let nodeIndex16 = nodeIndex32 * 2;
|
|
3297
|
+
const isLeaf = IS_LEAF(nodeIndex16, uint16Array2);
|
|
3298
|
+
if (isLeaf) {
|
|
3299
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
3300
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
3301
|
+
return intersectClosestTri_indirect(bvh, materialOrSide, ray, offset, count, near, far);
|
|
3302
|
+
} else {
|
|
3303
|
+
const splitAxis = SPLIT_AXIS(nodeIndex32, uint32Array2);
|
|
3304
|
+
const xyzAxis = _xyzFields2[splitAxis];
|
|
3305
|
+
const rayDir = ray.direction[xyzAxis];
|
|
3306
|
+
const leftToRight = rayDir >= 0;
|
|
3307
|
+
let c1, c2;
|
|
3308
|
+
if (leftToRight) {
|
|
3309
|
+
c1 = LEFT_NODE(nodeIndex32);
|
|
3310
|
+
c2 = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
3311
|
+
} else {
|
|
3312
|
+
c1 = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
3313
|
+
c2 = LEFT_NODE(nodeIndex32);
|
|
3314
|
+
}
|
|
3315
|
+
const c1Intersection = intersectsNodeBounds(c1, float32Array2, ray, near, far);
|
|
3316
|
+
const c1Result = c1Intersection ? _raycastFirst2(c1, bvh, materialOrSide, ray, near, far) : null;
|
|
3317
|
+
if (c1Result) {
|
|
3318
|
+
const point = c1Result.point[xyzAxis];
|
|
3319
|
+
const isOutside = leftToRight ? point <= float32Array2[c2 + splitAxis] : (
|
|
3320
|
+
// min bounding data
|
|
3321
|
+
point >= float32Array2[c2 + splitAxis + 3]
|
|
3322
|
+
);
|
|
3323
|
+
if (isOutside) {
|
|
3324
|
+
return c1Result;
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
const c2Intersection = intersectsNodeBounds(c2, float32Array2, ray, near, far);
|
|
3328
|
+
const c2Result = c2Intersection ? _raycastFirst2(c2, bvh, materialOrSide, ray, near, far) : null;
|
|
3329
|
+
if (c1Result && c2Result) {
|
|
3330
|
+
return c1Result.distance <= c2Result.distance ? c1Result : c2Result;
|
|
3331
|
+
} else {
|
|
3332
|
+
return c1Result || c2Result || null;
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3337
|
+
// node_modules/three-mesh-bvh/src/core/cast/intersectsGeometry_indirect.generated.js
|
|
3338
|
+
import { Box3 as Box36, Matrix4 as Matrix45 } from "three";
|
|
3339
|
+
var boundingBox2 = /* @__PURE__ */ new Box36();
|
|
3340
|
+
var triangle3 = /* @__PURE__ */ new ExtendedTriangle();
|
|
3341
|
+
var triangle22 = /* @__PURE__ */ new ExtendedTriangle();
|
|
3342
|
+
var invertedMat2 = /* @__PURE__ */ new Matrix45();
|
|
3343
|
+
var obb4 = /* @__PURE__ */ new OrientedBox();
|
|
3344
|
+
var obb23 = /* @__PURE__ */ new OrientedBox();
|
|
3345
|
+
function intersectsGeometry_indirect(bvh, root, otherGeometry, geometryToBvh) {
|
|
3346
|
+
BufferStack.setBuffer(bvh._roots[root]);
|
|
3347
|
+
const result = _intersectsGeometry2(0, bvh, otherGeometry, geometryToBvh);
|
|
3348
|
+
BufferStack.clearBuffer();
|
|
3349
|
+
return result;
|
|
3350
|
+
}
|
|
3351
|
+
function _intersectsGeometry2(nodeIndex32, bvh, otherGeometry, geometryToBvh, cachedObb = null) {
|
|
3352
|
+
const { float32Array: float32Array2, uint16Array: uint16Array2, uint32Array: uint32Array2 } = BufferStack;
|
|
3353
|
+
let nodeIndex16 = nodeIndex32 * 2;
|
|
3354
|
+
if (cachedObb === null) {
|
|
3355
|
+
if (!otherGeometry.boundingBox) {
|
|
3356
|
+
otherGeometry.computeBoundingBox();
|
|
3357
|
+
}
|
|
3358
|
+
obb4.set(otherGeometry.boundingBox.min, otherGeometry.boundingBox.max, geometryToBvh);
|
|
3359
|
+
cachedObb = obb4;
|
|
3360
|
+
}
|
|
3361
|
+
const isLeaf = IS_LEAF(nodeIndex16, uint16Array2);
|
|
3362
|
+
if (isLeaf) {
|
|
3363
|
+
const thisGeometry = bvh.geometry;
|
|
3364
|
+
const thisIndex = thisGeometry.index;
|
|
3365
|
+
const thisPos = thisGeometry.attributes.position;
|
|
3366
|
+
const otherIndex = otherGeometry.index;
|
|
3367
|
+
const otherPos = otherGeometry.attributes.position;
|
|
3368
|
+
const offset = OFFSET(nodeIndex32, uint32Array2);
|
|
3369
|
+
const count = COUNT(nodeIndex16, uint16Array2);
|
|
3370
|
+
invertedMat2.copy(geometryToBvh).invert();
|
|
3371
|
+
if (otherGeometry.boundsTree) {
|
|
3372
|
+
arrayToBox(BOUNDING_DATA_INDEX(nodeIndex32), float32Array2, obb23);
|
|
3373
|
+
obb23.matrix.copy(invertedMat2);
|
|
3374
|
+
obb23.needsUpdate = true;
|
|
3375
|
+
const res = otherGeometry.boundsTree.shapecast({
|
|
3376
|
+
intersectsBounds: (box) => obb23.intersectsBox(box),
|
|
3377
|
+
intersectsTriangle: (tri) => {
|
|
3378
|
+
tri.a.applyMatrix4(geometryToBvh);
|
|
3379
|
+
tri.b.applyMatrix4(geometryToBvh);
|
|
3380
|
+
tri.c.applyMatrix4(geometryToBvh);
|
|
3381
|
+
tri.needsUpdate = true;
|
|
3382
|
+
for (let i = offset, l = count + offset; i < l; i++) {
|
|
3383
|
+
setTriangle(triangle22, 3 * bvh.resolveTriangleIndex(i), thisIndex, thisPos);
|
|
3384
|
+
triangle22.needsUpdate = true;
|
|
3385
|
+
if (tri.intersectsTriangle(triangle22)) {
|
|
3386
|
+
return true;
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
return false;
|
|
3390
|
+
}
|
|
3391
|
+
});
|
|
3392
|
+
return res;
|
|
3393
|
+
} else {
|
|
3394
|
+
const otherTriangleCount = getTriCount(otherGeometry);
|
|
3395
|
+
for (let i = offset, l = count + offset; i < l; i++) {
|
|
3396
|
+
const ti = bvh.resolveTriangleIndex(i);
|
|
3397
|
+
setTriangle(triangle3, 3 * ti, thisIndex, thisPos);
|
|
3398
|
+
triangle3.a.applyMatrix4(invertedMat2);
|
|
3399
|
+
triangle3.b.applyMatrix4(invertedMat2);
|
|
3400
|
+
triangle3.c.applyMatrix4(invertedMat2);
|
|
3401
|
+
triangle3.needsUpdate = true;
|
|
3402
|
+
for (let i2 = 0, l2 = otherTriangleCount * 3; i2 < l2; i2 += 3) {
|
|
3403
|
+
setTriangle(triangle22, i2, otherIndex, otherPos);
|
|
3404
|
+
triangle22.needsUpdate = true;
|
|
3405
|
+
if (triangle3.intersectsTriangle(triangle22)) {
|
|
3406
|
+
return true;
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
} else {
|
|
3412
|
+
const left = LEFT_NODE(nodeIndex32);
|
|
3413
|
+
const right = RIGHT_NODE(nodeIndex32, uint32Array2);
|
|
3414
|
+
arrayToBox(BOUNDING_DATA_INDEX(left), float32Array2, boundingBox2);
|
|
3415
|
+
const leftIntersection = cachedObb.intersectsBox(boundingBox2) && _intersectsGeometry2(left, bvh, otherGeometry, geometryToBvh, cachedObb);
|
|
3416
|
+
if (leftIntersection) return true;
|
|
3417
|
+
arrayToBox(BOUNDING_DATA_INDEX(right), float32Array2, boundingBox2);
|
|
3418
|
+
const rightIntersection = cachedObb.intersectsBox(boundingBox2) && _intersectsGeometry2(right, bvh, otherGeometry, geometryToBvh, cachedObb);
|
|
3419
|
+
if (rightIntersection) return true;
|
|
3420
|
+
return false;
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3424
|
+
// node_modules/three-mesh-bvh/src/core/cast/closestPointToGeometry_indirect.generated.js
|
|
3425
|
+
import { Matrix4 as Matrix46, Vector3 as Vector39 } from "three";
|
|
3426
|
+
var tempMatrix2 = /* @__PURE__ */ new Matrix46();
|
|
3427
|
+
var obb5 = /* @__PURE__ */ new OrientedBox();
|
|
3428
|
+
var obb24 = /* @__PURE__ */ new OrientedBox();
|
|
3429
|
+
var temp13 = /* @__PURE__ */ new Vector39();
|
|
3430
|
+
var temp22 = /* @__PURE__ */ new Vector39();
|
|
3431
|
+
var temp32 = /* @__PURE__ */ new Vector39();
|
|
3432
|
+
var temp42 = /* @__PURE__ */ new Vector39();
|
|
3433
|
+
function closestPointToGeometry_indirect(bvh, otherGeometry, geometryToBvh, target1 = {}, target2 = {}, minThreshold = 0, maxThreshold = Infinity) {
|
|
3434
|
+
if (!otherGeometry.boundingBox) {
|
|
3435
|
+
otherGeometry.computeBoundingBox();
|
|
3436
|
+
}
|
|
3437
|
+
obb5.set(otherGeometry.boundingBox.min, otherGeometry.boundingBox.max, geometryToBvh);
|
|
3438
|
+
obb5.needsUpdate = true;
|
|
3439
|
+
const geometry = bvh.geometry;
|
|
3440
|
+
const pos = geometry.attributes.position;
|
|
3441
|
+
const index = geometry.index;
|
|
3442
|
+
const otherPos = otherGeometry.attributes.position;
|
|
3443
|
+
const otherIndex = otherGeometry.index;
|
|
3444
|
+
const triangle4 = ExtendedTrianglePool.getPrimitive();
|
|
3445
|
+
const triangle23 = ExtendedTrianglePool.getPrimitive();
|
|
3446
|
+
let tempTarget1 = temp13;
|
|
3447
|
+
let tempTargetDest1 = temp22;
|
|
3448
|
+
let tempTarget2 = null;
|
|
3449
|
+
let tempTargetDest2 = null;
|
|
3450
|
+
if (target2) {
|
|
3451
|
+
tempTarget2 = temp32;
|
|
3452
|
+
tempTargetDest2 = temp42;
|
|
3453
|
+
}
|
|
3454
|
+
let closestDistance = Infinity;
|
|
3455
|
+
let closestDistanceTriIndex = null;
|
|
3456
|
+
let closestDistanceOtherTriIndex = null;
|
|
3457
|
+
tempMatrix2.copy(geometryToBvh).invert();
|
|
3458
|
+
obb24.matrix.copy(tempMatrix2);
|
|
3459
|
+
bvh.shapecast(
|
|
3460
|
+
{
|
|
3461
|
+
boundsTraverseOrder: (box) => {
|
|
3462
|
+
return obb5.distanceToBox(box);
|
|
3463
|
+
},
|
|
3464
|
+
intersectsBounds: (box, isLeaf, score) => {
|
|
3465
|
+
if (score < closestDistance && score < maxThreshold) {
|
|
3466
|
+
if (isLeaf) {
|
|
3467
|
+
obb24.min.copy(box.min);
|
|
3468
|
+
obb24.max.copy(box.max);
|
|
3469
|
+
obb24.needsUpdate = true;
|
|
3470
|
+
}
|
|
3471
|
+
return true;
|
|
3472
|
+
}
|
|
3473
|
+
return false;
|
|
3474
|
+
},
|
|
3475
|
+
intersectsRange: (offset, count) => {
|
|
3476
|
+
if (otherGeometry.boundsTree) {
|
|
3477
|
+
const otherBvh = otherGeometry.boundsTree;
|
|
3478
|
+
return otherBvh.shapecast({
|
|
3479
|
+
boundsTraverseOrder: (box) => {
|
|
3480
|
+
return obb24.distanceToBox(box);
|
|
3481
|
+
},
|
|
3482
|
+
intersectsBounds: (box, isLeaf, score) => {
|
|
3483
|
+
return score < closestDistance && score < maxThreshold;
|
|
3484
|
+
},
|
|
3485
|
+
intersectsRange: (otherOffset, otherCount) => {
|
|
3486
|
+
for (let i2 = otherOffset, l2 = otherOffset + otherCount; i2 < l2; i2++) {
|
|
3487
|
+
const ti2 = otherBvh.resolveTriangleIndex(i2);
|
|
3488
|
+
setTriangle(triangle23, 3 * ti2, otherIndex, otherPos);
|
|
3489
|
+
triangle23.a.applyMatrix4(geometryToBvh);
|
|
3490
|
+
triangle23.b.applyMatrix4(geometryToBvh);
|
|
3491
|
+
triangle23.c.applyMatrix4(geometryToBvh);
|
|
3492
|
+
triangle23.needsUpdate = true;
|
|
3493
|
+
for (let i = offset, l = offset + count; i < l; i++) {
|
|
3494
|
+
const ti = bvh.resolveTriangleIndex(i);
|
|
3495
|
+
setTriangle(triangle4, 3 * ti, index, pos);
|
|
3496
|
+
triangle4.needsUpdate = true;
|
|
3497
|
+
const dist = triangle4.distanceToTriangle(triangle23, tempTarget1, tempTarget2);
|
|
3498
|
+
if (dist < closestDistance) {
|
|
3499
|
+
tempTargetDest1.copy(tempTarget1);
|
|
3500
|
+
if (tempTargetDest2) {
|
|
3501
|
+
tempTargetDest2.copy(tempTarget2);
|
|
3502
|
+
}
|
|
3503
|
+
closestDistance = dist;
|
|
3504
|
+
closestDistanceTriIndex = i;
|
|
3505
|
+
closestDistanceOtherTriIndex = i2;
|
|
3506
|
+
}
|
|
3507
|
+
if (dist < minThreshold) {
|
|
3508
|
+
return true;
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
});
|
|
3514
|
+
} else {
|
|
3515
|
+
const triCount = getTriCount(otherGeometry);
|
|
3516
|
+
for (let i2 = 0, l2 = triCount; i2 < l2; i2++) {
|
|
3517
|
+
setTriangle(triangle23, 3 * i2, otherIndex, otherPos);
|
|
3518
|
+
triangle23.a.applyMatrix4(geometryToBvh);
|
|
3519
|
+
triangle23.b.applyMatrix4(geometryToBvh);
|
|
3520
|
+
triangle23.c.applyMatrix4(geometryToBvh);
|
|
3521
|
+
triangle23.needsUpdate = true;
|
|
3522
|
+
for (let i = offset, l = offset + count; i < l; i++) {
|
|
3523
|
+
const ti = bvh.resolveTriangleIndex(i);
|
|
3524
|
+
setTriangle(triangle4, 3 * ti, index, pos);
|
|
3525
|
+
triangle4.needsUpdate = true;
|
|
3526
|
+
const dist = triangle4.distanceToTriangle(triangle23, tempTarget1, tempTarget2);
|
|
3527
|
+
if (dist < closestDistance) {
|
|
3528
|
+
tempTargetDest1.copy(tempTarget1);
|
|
3529
|
+
if (tempTargetDest2) {
|
|
3530
|
+
tempTargetDest2.copy(tempTarget2);
|
|
3531
|
+
}
|
|
3532
|
+
closestDistance = dist;
|
|
3533
|
+
closestDistanceTriIndex = i;
|
|
3534
|
+
closestDistanceOtherTriIndex = i2;
|
|
3535
|
+
}
|
|
3536
|
+
if (dist < minThreshold) {
|
|
3537
|
+
return true;
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
);
|
|
3545
|
+
ExtendedTrianglePool.releasePrimitive(triangle4);
|
|
3546
|
+
ExtendedTrianglePool.releasePrimitive(triangle23);
|
|
3547
|
+
if (closestDistance === Infinity) {
|
|
3548
|
+
return null;
|
|
3549
|
+
}
|
|
3550
|
+
if (!target1.point) {
|
|
3551
|
+
target1.point = tempTargetDest1.clone();
|
|
3552
|
+
} else {
|
|
3553
|
+
target1.point.copy(tempTargetDest1);
|
|
3554
|
+
}
|
|
3555
|
+
target1.distance = closestDistance, target1.faceIndex = closestDistanceTriIndex;
|
|
3556
|
+
if (target2) {
|
|
3557
|
+
if (!target2.point) target2.point = tempTargetDest2.clone();
|
|
3558
|
+
else target2.point.copy(tempTargetDest2);
|
|
3559
|
+
target2.point.applyMatrix4(tempMatrix2);
|
|
3560
|
+
tempTargetDest1.applyMatrix4(tempMatrix2);
|
|
3561
|
+
target2.distance = tempTargetDest1.sub(target2.point).length();
|
|
3562
|
+
target2.faceIndex = closestDistanceOtherTriIndex;
|
|
3563
|
+
}
|
|
3564
|
+
return target1;
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3567
|
+
// node_modules/three-mesh-bvh/src/utils/GeometryRayIntersectUtilities.js
|
|
3568
|
+
function convertRaycastIntersect(hit, object, raycaster) {
|
|
3569
|
+
if (hit === null) {
|
|
3570
|
+
return null;
|
|
3571
|
+
}
|
|
3572
|
+
hit.point.applyMatrix4(object.matrixWorld);
|
|
3573
|
+
hit.distance = hit.point.distanceTo(raycaster.ray.origin);
|
|
3574
|
+
hit.object = object;
|
|
3575
|
+
return hit;
|
|
3576
|
+
}
|
|
3577
|
+
|
|
3578
|
+
// node_modules/three-mesh-bvh/src/core/MeshBVH.js
|
|
3579
|
+
var _obb = /* @__PURE__ */ new OrientedBox();
|
|
3580
|
+
var _ray = /* @__PURE__ */ new Ray();
|
|
3581
|
+
var _direction = /* @__PURE__ */ new Vector310();
|
|
3582
|
+
var _inverseMatrix = /* @__PURE__ */ new Matrix47();
|
|
3583
|
+
var _worldScale = /* @__PURE__ */ new Vector310();
|
|
3584
|
+
var _getters = ["getX", "getY", "getZ"];
|
|
3585
|
+
var MeshBVH = class _MeshBVH extends GeometryBVH {
|
|
3586
|
+
/**
|
|
3587
|
+
* Generates a representation of the complete bounds tree and the geometry index buffer which
|
|
3588
|
+
* can be used to recreate a bounds tree using the `deserialize` function. The `serialize` and
|
|
3589
|
+
* `deserialize` functions can be used to generate a MeshBVH asynchronously in a background web
|
|
3590
|
+
* worker to prevent the main thread from stuttering. The BVH roots buffer stored in the
|
|
3591
|
+
* serialized representation are the same as the ones used by the original BVH so they should
|
|
3592
|
+
* not be modified. If `SharedArrayBuffers` are used then the same BVH memory can be used for
|
|
3593
|
+
* multiple BVH in multiple WebWorkers.
|
|
3594
|
+
*
|
|
3595
|
+
* @static
|
|
3596
|
+
* @param {MeshBVH} bvh - The BVH to serialize.
|
|
3597
|
+
* @param {Object} [options]
|
|
3598
|
+
* @param {boolean} [options.cloneBuffers=true] - If `true`, the index and BVH root buffers
|
|
3599
|
+
* are cloned so the serialized data is independent of the live BVH.
|
|
3600
|
+
* @returns {SerializedBVH}
|
|
3601
|
+
*/
|
|
3602
|
+
static serialize(bvh, options = {}) {
|
|
3603
|
+
options = {
|
|
3604
|
+
cloneBuffers: true,
|
|
3605
|
+
...options
|
|
3606
|
+
};
|
|
3607
|
+
const geometry = bvh.geometry;
|
|
3608
|
+
const rootData = bvh._roots;
|
|
3609
|
+
const indirectBuffer = bvh._indirectBuffer;
|
|
3610
|
+
const indexAttribute = geometry.getIndex();
|
|
3611
|
+
const result = {
|
|
3612
|
+
version: 1,
|
|
3613
|
+
roots: null,
|
|
3614
|
+
index: null,
|
|
3615
|
+
indirectBuffer: null
|
|
3616
|
+
};
|
|
3617
|
+
if (options.cloneBuffers) {
|
|
3618
|
+
result.roots = rootData.map((root) => root.slice());
|
|
3619
|
+
result.index = indexAttribute ? indexAttribute.array.slice() : null;
|
|
3620
|
+
result.indirectBuffer = indirectBuffer ? indirectBuffer.slice() : null;
|
|
3621
|
+
} else {
|
|
3622
|
+
result.roots = rootData;
|
|
3623
|
+
result.index = indexAttribute ? indexAttribute.array : null;
|
|
3624
|
+
result.indirectBuffer = indirectBuffer;
|
|
3625
|
+
}
|
|
3626
|
+
return result;
|
|
3627
|
+
}
|
|
3628
|
+
/**
|
|
3629
|
+
* Returns a new MeshBVH instance from the serialized data. `geometry` is the geometry used
|
|
3630
|
+
* to generate the original BVH `data` was derived from. The root buffers stored in `data`
|
|
3631
|
+
* are set directly on the new BVH so the memory is shared.
|
|
3632
|
+
*
|
|
3633
|
+
* @static
|
|
3634
|
+
* @param {SerializedBVH} data - Serialized BVH data.
|
|
3635
|
+
* @param {BufferGeometry} geometry - The geometry the BVH was originally built from.
|
|
3636
|
+
* @param {Object} [options]
|
|
3637
|
+
* @param {boolean} [options.setIndex=true] - If `true`, sets `geometry.index` from the
|
|
3638
|
+
* serialized index buffer (creating one if none exists).
|
|
3639
|
+
* @returns {MeshBVH}
|
|
3640
|
+
*/
|
|
3641
|
+
static deserialize(data, geometry, options = {}) {
|
|
3642
|
+
options = {
|
|
3643
|
+
setIndex: true,
|
|
3644
|
+
indirect: Boolean(data.indirectBuffer),
|
|
3645
|
+
...options
|
|
3646
|
+
};
|
|
3647
|
+
const { index, roots, indirectBuffer } = data;
|
|
3648
|
+
if (!data.version) {
|
|
3649
|
+
console.warn(
|
|
3650
|
+
"MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."
|
|
3651
|
+
);
|
|
3652
|
+
fixupVersion0(roots);
|
|
3653
|
+
}
|
|
3654
|
+
const bvh = new _MeshBVH(geometry, { ...options, [SKIP_GENERATION]: true });
|
|
3655
|
+
bvh._roots = roots;
|
|
3656
|
+
bvh._indirectBuffer = indirectBuffer || null;
|
|
3657
|
+
if (options.setIndex) {
|
|
3658
|
+
const indexAttribute = geometry.getIndex();
|
|
3659
|
+
if (indexAttribute === null) {
|
|
3660
|
+
const newIndex = new BufferAttribute2(data.index, 1, false);
|
|
3661
|
+
geometry.setIndex(newIndex);
|
|
3662
|
+
} else if (indexAttribute.array !== index) {
|
|
3663
|
+
indexAttribute.array.set(index);
|
|
3664
|
+
indexAttribute.needsUpdate = true;
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
return bvh;
|
|
3668
|
+
function fixupVersion0(roots2) {
|
|
3669
|
+
for (let rootIndex = 0; rootIndex < roots2.length; rootIndex++) {
|
|
3670
|
+
const root = roots2[rootIndex];
|
|
3671
|
+
const uint32Array2 = new Uint32Array(root);
|
|
3672
|
+
const uint16Array2 = new Uint16Array(root);
|
|
3673
|
+
for (let node = 0, l = root.byteLength / BYTES_PER_NODE; node < l; node++) {
|
|
3674
|
+
const node32Index = UINT32_PER_NODE * node;
|
|
3675
|
+
const node16Index = 2 * node32Index;
|
|
3676
|
+
if (!IS_LEAF(node16Index, uint16Array2)) {
|
|
3677
|
+
uint32Array2[node32Index + 6] = uint32Array2[node32Index + 6] / UINT32_PER_NODE - node;
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
get primitiveStride() {
|
|
3684
|
+
return 3;
|
|
3685
|
+
}
|
|
3686
|
+
/**
|
|
3687
|
+
* Helper function for use when `indirect` is set to true. This function takes a triangle
|
|
3688
|
+
* index in the BVH layout and returns the associated triangle index in the geometry index
|
|
3689
|
+
* buffer or position attribute.
|
|
3690
|
+
* @type {function(number): number}
|
|
3691
|
+
* @readonly
|
|
3692
|
+
*/
|
|
3693
|
+
get resolveTriangleIndex() {
|
|
3694
|
+
return this.resolvePrimitiveIndex;
|
|
3695
|
+
}
|
|
3696
|
+
constructor(geometry, options = {}) {
|
|
3697
|
+
if (options.maxLeafTris) {
|
|
3698
|
+
console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.');
|
|
3699
|
+
options = {
|
|
3700
|
+
...options,
|
|
3701
|
+
targetLeafSize: options.maxLeafTris
|
|
3702
|
+
};
|
|
3703
|
+
}
|
|
3704
|
+
super(geometry, options);
|
|
3705
|
+
}
|
|
3706
|
+
/**
|
|
3707
|
+
* Adjusts all triangle offsets stored in the BVH by the given offset. This is useful when the
|
|
3708
|
+
* triangle data has been compacted or shifted in the geometry buffers (e.g. in `BatchedMesh`
|
|
3709
|
+
* when geometries are compacted using the 'optimize' function or constructing a 'merged' BVH).
|
|
3710
|
+
* This function only adjusts the BVH to point to different triangles in the geometry. The
|
|
3711
|
+
* geometry's index buffer and/or position attributes must be updated separately to match.
|
|
3712
|
+
*
|
|
3713
|
+
* @param {number} offset
|
|
3714
|
+
* @returns {void}
|
|
3715
|
+
*/
|
|
3716
|
+
// implement abstract methods from BVH base class
|
|
3717
|
+
shiftTriangleOffsets(offset) {
|
|
3718
|
+
return super.shiftPrimitiveOffsets(offset);
|
|
3719
|
+
}
|
|
3720
|
+
// write primitive bounds to the buffer - used only for validateBounds at the moment
|
|
3721
|
+
writePrimitiveBounds(i, targetBuffer, baseIndex) {
|
|
3722
|
+
const geometry = this.geometry;
|
|
3723
|
+
const indirectBuffer = this._indirectBuffer;
|
|
3724
|
+
const posAttr = geometry.attributes.position;
|
|
3725
|
+
const index = geometry.index ? geometry.index.array : null;
|
|
3726
|
+
const tri = indirectBuffer ? indirectBuffer[i] : i;
|
|
3727
|
+
const tri3 = tri * 3;
|
|
3728
|
+
let ai = tri3 + 0;
|
|
3729
|
+
let bi = tri3 + 1;
|
|
3730
|
+
let ci = tri3 + 2;
|
|
3731
|
+
if (index) {
|
|
3732
|
+
ai = index[ai];
|
|
3733
|
+
bi = index[bi];
|
|
3734
|
+
ci = index[ci];
|
|
3735
|
+
}
|
|
3736
|
+
for (let el = 0; el < 3; el++) {
|
|
3737
|
+
const a = posAttr[_getters[el]](ai);
|
|
3738
|
+
const b = posAttr[_getters[el]](bi);
|
|
3739
|
+
const c = posAttr[_getters[el]](ci);
|
|
3740
|
+
let min = a;
|
|
3741
|
+
if (b < min) min = b;
|
|
3742
|
+
if (c < min) min = c;
|
|
3743
|
+
let max = a;
|
|
3744
|
+
if (b > max) max = b;
|
|
3745
|
+
if (c > max) max = c;
|
|
3746
|
+
targetBuffer[baseIndex + el] = min;
|
|
3747
|
+
targetBuffer[baseIndex + el + 3] = max;
|
|
3748
|
+
}
|
|
3749
|
+
return targetBuffer;
|
|
3750
|
+
}
|
|
3751
|
+
// precomputes the bounding box for each triangle; required for quickly calculating tree splits.
|
|
3752
|
+
// result is an array of size count * 6 where triangle i maps to a
|
|
3753
|
+
// [x_center, x_delta, y_center, y_delta, z_center, z_delta] tuple starting at index (i - offset) * 6,
|
|
3754
|
+
// representing the center and half-extent in each dimension of triangle i
|
|
3755
|
+
computePrimitiveBounds(offset, count, targetBuffer) {
|
|
3756
|
+
const geometry = this.geometry;
|
|
3757
|
+
const indirectBuffer = this._indirectBuffer;
|
|
3758
|
+
const posAttr = geometry.attributes.position;
|
|
3759
|
+
const index = geometry.index ? geometry.index.array : null;
|
|
3760
|
+
const normalized = posAttr.normalized;
|
|
3761
|
+
if (offset < 0 || count + offset - targetBuffer.offset > targetBuffer.length / 6) {
|
|
3762
|
+
throw new Error("MeshBVH: compute triangle bounds range is invalid.");
|
|
3763
|
+
}
|
|
3764
|
+
const posArr = posAttr.array;
|
|
3765
|
+
const bufferOffset = posAttr.offset || 0;
|
|
3766
|
+
let stride = 3;
|
|
3767
|
+
if (posAttr.isInterleavedBufferAttribute) {
|
|
3768
|
+
stride = posAttr.data.stride;
|
|
3769
|
+
}
|
|
3770
|
+
const getters = ["getX", "getY", "getZ"];
|
|
3771
|
+
const writeOffset = targetBuffer.offset;
|
|
3772
|
+
for (let i = offset, l = offset + count; i < l; i++) {
|
|
3773
|
+
const tri = indirectBuffer ? indirectBuffer[i] : i;
|
|
3774
|
+
const tri3 = tri * 3;
|
|
3775
|
+
const boundsIndexOffset = (i - writeOffset) * 6;
|
|
3776
|
+
let ai = tri3 + 0;
|
|
3777
|
+
let bi = tri3 + 1;
|
|
3778
|
+
let ci = tri3 + 2;
|
|
3779
|
+
if (index) {
|
|
3780
|
+
ai = index[ai];
|
|
3781
|
+
bi = index[bi];
|
|
3782
|
+
ci = index[ci];
|
|
3783
|
+
}
|
|
3784
|
+
if (!normalized) {
|
|
3785
|
+
ai = ai * stride + bufferOffset;
|
|
3786
|
+
bi = bi * stride + bufferOffset;
|
|
3787
|
+
ci = ci * stride + bufferOffset;
|
|
3788
|
+
}
|
|
3789
|
+
for (let el = 0; el < 3; el++) {
|
|
3790
|
+
let a, b, c;
|
|
3791
|
+
if (normalized) {
|
|
3792
|
+
a = posAttr[getters[el]](ai);
|
|
3793
|
+
b = posAttr[getters[el]](bi);
|
|
3794
|
+
c = posAttr[getters[el]](ci);
|
|
3795
|
+
} else {
|
|
3796
|
+
a = posArr[ai + el];
|
|
3797
|
+
b = posArr[bi + el];
|
|
3798
|
+
c = posArr[ci + el];
|
|
3799
|
+
}
|
|
3800
|
+
let min = a;
|
|
3801
|
+
if (b < min) min = b;
|
|
3802
|
+
if (c < min) min = c;
|
|
3803
|
+
let max = a;
|
|
3804
|
+
if (b > max) max = b;
|
|
3805
|
+
if (c > max) max = c;
|
|
3806
|
+
const halfExtents = (max - min) / 2;
|
|
3807
|
+
const el2 = el * 2;
|
|
3808
|
+
targetBuffer[boundsIndexOffset + el2 + 0] = min + halfExtents;
|
|
3809
|
+
targetBuffer[boundsIndexOffset + el2 + 1] = halfExtents + (Math.abs(min) + halfExtents) * FLOAT32_EPSILON;
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
return targetBuffer;
|
|
3813
|
+
}
|
|
3814
|
+
/**
|
|
3815
|
+
* A convenience function for performing a raycast based on a mesh. Results are formed like
|
|
3816
|
+
* three.js raycast results in world frame.
|
|
3817
|
+
*
|
|
3818
|
+
* @param {Object3D} object
|
|
3819
|
+
* @param {Raycaster} raycaster
|
|
3820
|
+
* @param {Array<Intersection>} [intersects=[]]
|
|
3821
|
+
* @returns {Array<Intersection>}
|
|
3822
|
+
*/
|
|
3823
|
+
raycastObject3D(object, raycaster, intersects = []) {
|
|
3824
|
+
const { material } = object;
|
|
3825
|
+
if (material === void 0) {
|
|
3826
|
+
return;
|
|
3827
|
+
}
|
|
3828
|
+
_inverseMatrix.copy(object.matrixWorld).invert();
|
|
3829
|
+
_ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix);
|
|
3830
|
+
_worldScale.setFromMatrixScale(object.matrixWorld);
|
|
3831
|
+
_direction.copy(_ray.direction).multiply(_worldScale);
|
|
3832
|
+
const scaleFactor = _direction.length();
|
|
3833
|
+
const near = raycaster.near / scaleFactor;
|
|
3834
|
+
const far = raycaster.far / scaleFactor;
|
|
3835
|
+
if (raycaster.firstHitOnly === true) {
|
|
3836
|
+
let hit = this.raycastFirst(_ray, material, near, far);
|
|
3837
|
+
hit = convertRaycastIntersect(hit, object, raycaster);
|
|
3838
|
+
if (hit) {
|
|
3839
|
+
intersects.push(hit);
|
|
3840
|
+
}
|
|
3841
|
+
} else {
|
|
3842
|
+
const hits = this.raycast(_ray, material, near, far);
|
|
3843
|
+
for (let i = 0, l = hits.length; i < l; i++) {
|
|
3844
|
+
const hit = convertRaycastIntersect(hits[i], object, raycaster);
|
|
3845
|
+
if (hit) {
|
|
3846
|
+
intersects.push(hit);
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
return intersects;
|
|
3851
|
+
}
|
|
3852
|
+
/**
|
|
3853
|
+
* Refit the node bounds to the current triangle positions. This is quicker than regenerating
|
|
3854
|
+
* a new BVH but will not be optimal after significant changes to the vertices. `nodeIndices`
|
|
3855
|
+
* is a set of node indices (provided by the `shapecast` function) that need to be refit
|
|
3856
|
+
* including all internal nodes.
|
|
3857
|
+
*
|
|
3858
|
+
* @param {Set<number>|Array<number>|null} [nodeIndices=null]
|
|
3859
|
+
*/
|
|
3860
|
+
refit(nodeIndices = null) {
|
|
3861
|
+
const refitFunc = this.indirect ? refit_indirect : refit;
|
|
3862
|
+
return refitFunc(this, nodeIndices);
|
|
3863
|
+
}
|
|
3864
|
+
/* Core Cast Functions */
|
|
3865
|
+
/**
|
|
3866
|
+
* Returns all raycast triangle hits in unsorted order. It is expected that `ray` is in the
|
|
3867
|
+
* frame of the BVH already. Likewise the returned results are also provided in the local
|
|
3868
|
+
* frame of the BVH. The `side` identifier is used to determine the side to check when
|
|
3869
|
+
* raycasting or a material with the given side field can be passed. If an array of materials
|
|
3870
|
+
* is provided then it is expected that the geometry has groups and the appropriate material
|
|
3871
|
+
* side is used per group.
|
|
3872
|
+
*
|
|
3873
|
+
* Note that unlike three.js' Raycaster results the points and distances in the intersections
|
|
3874
|
+
* returned from this function are relative to the local frame of the MeshBVH. When using the
|
|
3875
|
+
* `acceleratedRaycast` function as an override for `Mesh.raycast` they are transformed into
|
|
3876
|
+
* world space to be consistent with three's results.
|
|
3877
|
+
*
|
|
3878
|
+
* @param {Ray} ray
|
|
3879
|
+
* @param {number|Material|Array<Material>} [materialOrSide=FrontSide]
|
|
3880
|
+
* @param {number} [near=0]
|
|
3881
|
+
* @param {number} [far=Infinity]
|
|
3882
|
+
* @returns {Array<Intersection>}
|
|
3883
|
+
*/
|
|
3884
|
+
raycast(ray, materialOrSide = FrontSide, near = 0, far = Infinity) {
|
|
3885
|
+
const roots = this._roots;
|
|
3886
|
+
const intersects = [];
|
|
3887
|
+
const raycastFunc = this.indirect ? raycast_indirect : raycast;
|
|
3888
|
+
for (let i = 0, l = roots.length; i < l; i++) {
|
|
3889
|
+
raycastFunc(this, i, materialOrSide, ray, intersects, near, far);
|
|
3890
|
+
}
|
|
3891
|
+
return intersects;
|
|
3892
|
+
}
|
|
3893
|
+
/**
|
|
3894
|
+
* Returns the first raycast hit in the model. This is typically much faster than returning
|
|
3895
|
+
* all hits. See `raycast` for information on the side and material options as well as the
|
|
3896
|
+
* frame of the returned intersections.
|
|
3897
|
+
*
|
|
3898
|
+
* @param {Ray} ray
|
|
3899
|
+
* @param {number|Material|Array<Material>} [materialOrSide=FrontSide]
|
|
3900
|
+
* @param {number} [near=0]
|
|
3901
|
+
* @param {number} [far=Infinity]
|
|
3902
|
+
* @returns {Intersection|null}
|
|
3903
|
+
*/
|
|
3904
|
+
raycastFirst(ray, materialOrSide = FrontSide, near = 0, far = Infinity) {
|
|
3905
|
+
const roots = this._roots;
|
|
3906
|
+
let closestResult = null;
|
|
3907
|
+
const raycastFirstFunc = this.indirect ? raycastFirst_indirect : raycastFirst;
|
|
3908
|
+
for (let i = 0, l = roots.length; i < l; i++) {
|
|
3909
|
+
const result = raycastFirstFunc(this, i, materialOrSide, ray, near, far);
|
|
3910
|
+
if (result != null && (closestResult == null || result.distance < closestResult.distance)) {
|
|
3911
|
+
closestResult = result;
|
|
3912
|
+
}
|
|
3913
|
+
}
|
|
3914
|
+
return closestResult;
|
|
3915
|
+
}
|
|
3916
|
+
/**
|
|
3917
|
+
* Returns whether or not the mesh intersects the given geometry.
|
|
3918
|
+
*
|
|
3919
|
+
* The `geometryToBvh` parameter is the transform of the geometry in the BVH's local frame.
|
|
3920
|
+
*
|
|
3921
|
+
* Performance improves considerably if the provided geometry also has a `boundsTree`.
|
|
3922
|
+
*
|
|
3923
|
+
* @param {BufferGeometry} otherGeometry
|
|
3924
|
+
* @param {Matrix4} geometryToBvh - Transform of `otherGeometry` into the local space of
|
|
3925
|
+
* this BVH.
|
|
3926
|
+
* @returns {boolean}
|
|
3927
|
+
*/
|
|
3928
|
+
intersectsGeometry(otherGeometry, geomToMesh) {
|
|
3929
|
+
let result = false;
|
|
3930
|
+
const roots = this._roots;
|
|
3931
|
+
const intersectsGeometryFunc = this.indirect ? intersectsGeometry_indirect : intersectsGeometry;
|
|
3932
|
+
for (let i = 0, l = roots.length; i < l; i++) {
|
|
3933
|
+
result = intersectsGeometryFunc(this, i, otherGeometry, geomToMesh);
|
|
3934
|
+
if (result) {
|
|
3935
|
+
break;
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
return result;
|
|
3939
|
+
}
|
|
3940
|
+
/**
|
|
3941
|
+
* A generalized cast function that can be used to implement intersection logic for custom
|
|
3942
|
+
* shapes. This is used internally for `intersectsBox`, `intersectsSphere`, and more. The
|
|
3943
|
+
* function returns as soon as a triangle has been reported as intersected and returns `true`
|
|
3944
|
+
* if a triangle has been intersected.
|
|
3945
|
+
*
|
|
3946
|
+
* @param {Object} callbacks
|
|
3947
|
+
* @param {IntersectsBoundsCallback} callbacks.intersectsBounds
|
|
3948
|
+
* @param {IntersectsTriangleCallback} [callbacks.intersectsTriangle]
|
|
3949
|
+
* @param {IntersectsRangeCallback} [callbacks.intersectsRange]
|
|
3950
|
+
* @param {BoundsTraverseOrderCallback} [callbacks.boundsTraverseOrder]
|
|
3951
|
+
* @returns {boolean}
|
|
3952
|
+
*/
|
|
3953
|
+
shapecast(callbacks) {
|
|
3954
|
+
const triangle4 = ExtendedTrianglePool.getPrimitive();
|
|
3955
|
+
const result = super.shapecast(
|
|
3956
|
+
{
|
|
3957
|
+
...callbacks,
|
|
3958
|
+
intersectsPrimitive: callbacks.intersectsTriangle,
|
|
3959
|
+
scratchPrimitive: triangle4,
|
|
3960
|
+
// TODO: is the performance significant enough for the added complexity here?
|
|
3961
|
+
// can we just use one function?
|
|
3962
|
+
iterate: this.indirect ? iterateOverTriangles_indirect : iterateOverTriangles
|
|
3963
|
+
}
|
|
3964
|
+
);
|
|
3965
|
+
ExtendedTrianglePool.releasePrimitive(triangle4);
|
|
3966
|
+
return result;
|
|
3967
|
+
}
|
|
3968
|
+
/**
|
|
3969
|
+
* A generalized cast function that traverses two BVH structures simultaneously to perform
|
|
3970
|
+
* intersection tests between them. This is used internally by `intersectsGeometry`. The
|
|
3971
|
+
* function returns `true` as soon as a triangle pair has been reported as intersected by
|
|
3972
|
+
* the callbacks.
|
|
3973
|
+
*
|
|
3974
|
+
* `matrixToLocal` is a Matrix4 that transforms `otherBvh` into the local space of this BVH.
|
|
3975
|
+
* The other BVH's triangles are transformed by this matrix before intersection tests.
|
|
3976
|
+
*
|
|
3977
|
+
* @param {MeshBVH} otherBvh
|
|
3978
|
+
* @param {Matrix4} matrixToLocal - Transforms `otherBvh` into the local space of this BVH.
|
|
3979
|
+
* @param {Object} callbacks
|
|
3980
|
+
* @param {IntersectsRangesCallback} [callbacks.intersectsRanges]
|
|
3981
|
+
* @param {IntersectsTrianglesCallback} [callbacks.intersectsTriangles]
|
|
3982
|
+
* @returns {boolean}
|
|
3983
|
+
*/
|
|
3984
|
+
bvhcast(otherBvh, matrixToLocal, callbacks) {
|
|
3985
|
+
let {
|
|
3986
|
+
intersectsRanges,
|
|
3987
|
+
intersectsTriangles
|
|
3988
|
+
} = callbacks;
|
|
3989
|
+
const triangle1 = ExtendedTrianglePool.getPrimitive();
|
|
3990
|
+
const indexAttr1 = this.geometry.index;
|
|
3991
|
+
const positionAttr1 = this.geometry.attributes.position;
|
|
3992
|
+
const assignTriangle1 = this.indirect ? (i1) => {
|
|
3993
|
+
const ti = this.resolveTriangleIndex(i1);
|
|
3994
|
+
setTriangle(triangle1, ti * 3, indexAttr1, positionAttr1);
|
|
3995
|
+
} : (i1) => {
|
|
3996
|
+
setTriangle(triangle1, i1 * 3, indexAttr1, positionAttr1);
|
|
3997
|
+
};
|
|
3998
|
+
const triangle23 = ExtendedTrianglePool.getPrimitive();
|
|
3999
|
+
const indexAttr2 = otherBvh.geometry.index;
|
|
4000
|
+
const positionAttr2 = otherBvh.geometry.attributes.position;
|
|
4001
|
+
const assignTriangle2 = otherBvh.indirect ? (i2) => {
|
|
4002
|
+
const ti2 = otherBvh.resolveTriangleIndex(i2);
|
|
4003
|
+
setTriangle(triangle23, ti2 * 3, indexAttr2, positionAttr2);
|
|
4004
|
+
} : (i2) => {
|
|
4005
|
+
setTriangle(triangle23, i2 * 3, indexAttr2, positionAttr2);
|
|
4006
|
+
};
|
|
4007
|
+
if (intersectsTriangles) {
|
|
4008
|
+
if (!(otherBvh instanceof _MeshBVH)) {
|
|
4009
|
+
throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');
|
|
4010
|
+
}
|
|
4011
|
+
const iterateOverDoubleTriangles = (offset1, count1, offset2, count2, depth1, nodeIndex1, depth2, nodeIndex2) => {
|
|
4012
|
+
for (let i2 = offset2, l2 = offset2 + count2; i2 < l2; i2++) {
|
|
4013
|
+
assignTriangle2(i2);
|
|
4014
|
+
triangle23.a.applyMatrix4(matrixToLocal);
|
|
4015
|
+
triangle23.b.applyMatrix4(matrixToLocal);
|
|
4016
|
+
triangle23.c.applyMatrix4(matrixToLocal);
|
|
4017
|
+
triangle23.needsUpdate = true;
|
|
4018
|
+
for (let i1 = offset1, l1 = offset1 + count1; i1 < l1; i1++) {
|
|
4019
|
+
assignTriangle1(i1);
|
|
4020
|
+
triangle1.needsUpdate = true;
|
|
4021
|
+
if (intersectsTriangles(triangle1, triangle23, i1, i2, depth1, nodeIndex1, depth2, nodeIndex2)) {
|
|
4022
|
+
return true;
|
|
4023
|
+
}
|
|
4024
|
+
}
|
|
4025
|
+
}
|
|
4026
|
+
return false;
|
|
4027
|
+
};
|
|
4028
|
+
if (intersectsRanges) {
|
|
4029
|
+
const originalIntersectsRanges = intersectsRanges;
|
|
4030
|
+
intersectsRanges = function(offset1, count1, offset2, count2, depth1, nodeIndex1, depth2, nodeIndex2) {
|
|
4031
|
+
if (!originalIntersectsRanges(offset1, count1, offset2, count2, depth1, nodeIndex1, depth2, nodeIndex2)) {
|
|
4032
|
+
return iterateOverDoubleTriangles(offset1, count1, offset2, count2, depth1, nodeIndex1, depth2, nodeIndex2);
|
|
4033
|
+
}
|
|
4034
|
+
return true;
|
|
4035
|
+
};
|
|
4036
|
+
} else {
|
|
4037
|
+
intersectsRanges = iterateOverDoubleTriangles;
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
return super.bvhcast(otherBvh, matrixToLocal, { intersectsRanges });
|
|
4041
|
+
}
|
|
4042
|
+
/* Derived Cast Functions */
|
|
4043
|
+
/**
|
|
4044
|
+
* Returns whether or not the mesh intersects the given box.
|
|
4045
|
+
*
|
|
4046
|
+
* The `boxToBvh` parameter is the transform of the box in the meshes frame.
|
|
4047
|
+
*
|
|
4048
|
+
* @param {Box3} box
|
|
4049
|
+
* @param {Matrix4} boxToBvh - Transform of the box in the local space of this BVH.
|
|
4050
|
+
* @returns {boolean}
|
|
4051
|
+
*/
|
|
4052
|
+
intersectsBox(box, boxToMesh) {
|
|
4053
|
+
_obb.set(box.min, box.max, boxToMesh);
|
|
4054
|
+
_obb.needsUpdate = true;
|
|
4055
|
+
return this.shapecast(
|
|
4056
|
+
{
|
|
4057
|
+
intersectsBounds: (box2) => _obb.intersectsBox(box2),
|
|
4058
|
+
intersectsTriangle: (tri) => _obb.intersectsTriangle(tri)
|
|
4059
|
+
}
|
|
4060
|
+
);
|
|
4061
|
+
}
|
|
4062
|
+
/**
|
|
4063
|
+
* Returns whether or not the mesh intersects the given sphere.
|
|
4064
|
+
*
|
|
4065
|
+
* @param {Sphere} sphere
|
|
4066
|
+
* @returns {boolean}
|
|
4067
|
+
*/
|
|
4068
|
+
intersectsSphere(sphere) {
|
|
4069
|
+
return this.shapecast(
|
|
4070
|
+
{
|
|
4071
|
+
intersectsBounds: (box) => sphere.intersectsBox(box),
|
|
4072
|
+
intersectsTriangle: (tri) => tri.intersectsSphere(sphere)
|
|
4073
|
+
}
|
|
4074
|
+
);
|
|
4075
|
+
}
|
|
4076
|
+
/**
|
|
4077
|
+
* Computes the closest distance from the geometry to the mesh and puts the closest point on
|
|
4078
|
+
* the mesh in `target1` (in the frame of the BVH) and the closest point on the other
|
|
4079
|
+
* geometry in `target2` (in the geometry frame). If `target1` is not provided a new Object
|
|
4080
|
+
* is created and returned from the function.
|
|
4081
|
+
*
|
|
4082
|
+
* The `geometryToBvh` parameter is the transform of the geometry in the BVH's local frame.
|
|
4083
|
+
*
|
|
4084
|
+
* If a point is found that is closer than `minThreshold` then the function will return that
|
|
4085
|
+
* result early. Any triangles or points outside of `maxThreshold` are ignored. If no point
|
|
4086
|
+
* is found within the min / max thresholds then `null` is returned and the target objects
|
|
4087
|
+
* are not modified.
|
|
4088
|
+
*
|
|
4089
|
+
* The returned faceIndex in `target1` and `target2` can be used with the standalone function
|
|
4090
|
+
* `getTriangleHitPointInfo` to obtain more information like UV coordinates, triangle normal
|
|
4091
|
+
* and materialIndex.
|
|
4092
|
+
*
|
|
4093
|
+
* @note This function can be very slow if `geometry` does not have a `geometry.boundsTree`
|
|
4094
|
+
* computed.
|
|
4095
|
+
*
|
|
4096
|
+
* @param {BufferGeometry} otherGeometry
|
|
4097
|
+
* @param {Matrix4} geometryToBvh - Transform of `otherGeometry` into the local space of
|
|
4098
|
+
* this BVH.
|
|
4099
|
+
* @param {HitPointInfo} [target1={}]
|
|
4100
|
+
* @param {HitPointInfo} [target2={}]
|
|
4101
|
+
* @param {number} [minThreshold=0]
|
|
4102
|
+
* @param {number} [maxThreshold=Infinity]
|
|
4103
|
+
* @returns {HitPointInfo|null}
|
|
4104
|
+
*/
|
|
4105
|
+
closestPointToGeometry(otherGeometry, geometryToBvh, target1 = {}, target2 = {}, minThreshold = 0, maxThreshold = Infinity) {
|
|
4106
|
+
const closestPointToGeometryFunc = this.indirect ? closestPointToGeometry_indirect : closestPointToGeometry;
|
|
4107
|
+
return closestPointToGeometryFunc(
|
|
4108
|
+
this,
|
|
4109
|
+
otherGeometry,
|
|
4110
|
+
geometryToBvh,
|
|
4111
|
+
target1,
|
|
4112
|
+
target2,
|
|
4113
|
+
minThreshold,
|
|
4114
|
+
maxThreshold
|
|
4115
|
+
);
|
|
4116
|
+
}
|
|
4117
|
+
/**
|
|
4118
|
+
* Computes the closest distance from the point to the mesh and gives additional information
|
|
4119
|
+
* in `target`. The target can be left undefined to default to a new object which is
|
|
4120
|
+
* ultimately returned by the function.
|
|
4121
|
+
*
|
|
4122
|
+
* If a point is found that is closer than `minThreshold` then the function will return that
|
|
4123
|
+
* result early. Any triangles or points outside of `maxThreshold` are ignored. If no point
|
|
4124
|
+
* is found within the min / max thresholds then `null` is returned and the `target` object
|
|
4125
|
+
* is not modified.
|
|
4126
|
+
*
|
|
4127
|
+
* The returned faceIndex can be used with the standalone function `getTriangleHitPointInfo`
|
|
4128
|
+
* to obtain more information like UV coordinates, triangle normal and materialIndex.
|
|
4129
|
+
*
|
|
4130
|
+
* @param {Vector3} point
|
|
4131
|
+
* @param {HitPointInfo} [target={}]
|
|
4132
|
+
* @param {number} [minThreshold=0]
|
|
4133
|
+
* @param {number} [maxThreshold=Infinity]
|
|
4134
|
+
* @returns {HitPointInfo|null}
|
|
4135
|
+
*/
|
|
4136
|
+
closestPointToPoint(point, target = {}, minThreshold = 0, maxThreshold = Infinity) {
|
|
4137
|
+
return closestPointToPoint(
|
|
4138
|
+
this,
|
|
4139
|
+
point,
|
|
4140
|
+
target,
|
|
4141
|
+
minThreshold,
|
|
4142
|
+
maxThreshold
|
|
4143
|
+
);
|
|
4144
|
+
}
|
|
4145
|
+
};
|
|
4146
|
+
|
|
4147
|
+
// node_modules/three-mesh-bvh/src/webgl/glsl/common_functions.glsl.js
|
|
4148
|
+
var common_functions = (
|
|
4149
|
+
/* glsl */
|
|
4150
|
+
`
|
|
4151
|
+
|
|
4152
|
+
// A stack of uint32 indices can can store the indices for
|
|
4153
|
+
// a perfectly balanced tree with a depth up to 31. Lower stack
|
|
4154
|
+
// depth gets higher performance.
|
|
4155
|
+
//
|
|
4156
|
+
// However not all trees are balanced. Best value to set this to
|
|
4157
|
+
// is the trees max depth.
|
|
4158
|
+
#ifndef BVH_STACK_DEPTH
|
|
4159
|
+
#define BVH_STACK_DEPTH 60
|
|
4160
|
+
#endif
|
|
4161
|
+
|
|
4162
|
+
#ifndef INFINITY
|
|
4163
|
+
#define INFINITY 1e20
|
|
4164
|
+
#endif
|
|
4165
|
+
|
|
4166
|
+
// Utilities
|
|
4167
|
+
uvec4 uTexelFetch1D( usampler2D tex, uint index ) {
|
|
4168
|
+
|
|
4169
|
+
uint width = uint( textureSize( tex, 0 ).x );
|
|
4170
|
+
uvec2 uv;
|
|
4171
|
+
uv.x = index % width;
|
|
4172
|
+
uv.y = index / width;
|
|
4173
|
+
|
|
4174
|
+
return texelFetch( tex, ivec2( uv ), 0 );
|
|
4175
|
+
|
|
4176
|
+
}
|
|
4177
|
+
|
|
4178
|
+
ivec4 iTexelFetch1D( isampler2D tex, uint index ) {
|
|
4179
|
+
|
|
4180
|
+
uint width = uint( textureSize( tex, 0 ).x );
|
|
4181
|
+
uvec2 uv;
|
|
4182
|
+
uv.x = index % width;
|
|
4183
|
+
uv.y = index / width;
|
|
4184
|
+
|
|
4185
|
+
return texelFetch( tex, ivec2( uv ), 0 );
|
|
4186
|
+
|
|
4187
|
+
}
|
|
4188
|
+
|
|
4189
|
+
vec4 texelFetch1D( sampler2D tex, uint index ) {
|
|
4190
|
+
|
|
4191
|
+
uint width = uint( textureSize( tex, 0 ).x );
|
|
4192
|
+
uvec2 uv;
|
|
4193
|
+
uv.x = index % width;
|
|
4194
|
+
uv.y = index / width;
|
|
4195
|
+
|
|
4196
|
+
return texelFetch( tex, ivec2( uv ), 0 );
|
|
4197
|
+
|
|
4198
|
+
}
|
|
4199
|
+
|
|
4200
|
+
vec4 textureSampleBarycoord( sampler2D tex, vec3 barycoord, uvec3 faceIndices ) {
|
|
4201
|
+
|
|
4202
|
+
return
|
|
4203
|
+
barycoord.x * texelFetch1D( tex, faceIndices.x ) +
|
|
4204
|
+
barycoord.y * texelFetch1D( tex, faceIndices.y ) +
|
|
4205
|
+
barycoord.z * texelFetch1D( tex, faceIndices.z );
|
|
4206
|
+
|
|
4207
|
+
}
|
|
4208
|
+
|
|
4209
|
+
void ndcToCameraRay(
|
|
4210
|
+
vec2 coord, mat4 cameraWorld, mat4 invProjectionMatrix,
|
|
4211
|
+
out vec3 rayOrigin, out vec3 rayDirection
|
|
4212
|
+
) {
|
|
4213
|
+
|
|
4214
|
+
// get camera look direction and near plane for camera clipping
|
|
4215
|
+
vec4 lookDirection = cameraWorld * vec4( 0.0, 0.0, - 1.0, 0.0 );
|
|
4216
|
+
vec4 nearVector = invProjectionMatrix * vec4( 0.0, 0.0, - 1.0, 1.0 );
|
|
4217
|
+
float near = abs( nearVector.z / nearVector.w );
|
|
4218
|
+
|
|
4219
|
+
// get the camera direction and position from camera matrices
|
|
4220
|
+
vec4 origin = cameraWorld * vec4( 0.0, 0.0, 0.0, 1.0 );
|
|
4221
|
+
vec4 direction = invProjectionMatrix * vec4( coord, 0.5, 1.0 );
|
|
4222
|
+
direction /= direction.w;
|
|
4223
|
+
direction = cameraWorld * direction - origin;
|
|
4224
|
+
|
|
4225
|
+
// slide the origin along the ray until it sits at the near clip plane position
|
|
4226
|
+
origin.xyz += direction.xyz * near / dot( direction, lookDirection );
|
|
4227
|
+
|
|
4228
|
+
rayOrigin = origin.xyz;
|
|
4229
|
+
rayDirection = direction.xyz;
|
|
4230
|
+
|
|
4231
|
+
}
|
|
4232
|
+
`
|
|
4233
|
+
);
|
|
4234
|
+
|
|
4235
|
+
// node_modules/three-mesh-bvh/src/webgl/glsl/bvh_ray_functions.glsl.js
|
|
4236
|
+
var bvh_ray_functions = (
|
|
4237
|
+
/* glsl */
|
|
4238
|
+
`
|
|
4239
|
+
|
|
4240
|
+
#ifndef TRI_INTERSECT_EPSILON
|
|
4241
|
+
#define TRI_INTERSECT_EPSILON 1e-5
|
|
4242
|
+
#endif
|
|
4243
|
+
|
|
4244
|
+
// Raycasting
|
|
4245
|
+
bool intersectsBounds( vec3 rayOrigin, vec3 rayDirection, vec3 boundsMin, vec3 boundsMax, out float dist ) {
|
|
4246
|
+
|
|
4247
|
+
// https://www.reddit.com/r/opengl/comments/8ntzz5/fast_glsl_ray_box_intersection/
|
|
4248
|
+
// https://tavianator.com/2011/ray_box.html
|
|
4249
|
+
vec3 invDir = 1.0 / rayDirection;
|
|
4250
|
+
|
|
4251
|
+
// find intersection distances for each plane
|
|
4252
|
+
vec3 tMinPlane = invDir * ( boundsMin - rayOrigin );
|
|
4253
|
+
vec3 tMaxPlane = invDir * ( boundsMax - rayOrigin );
|
|
4254
|
+
|
|
4255
|
+
// get the min and max distances from each intersection
|
|
4256
|
+
vec3 tMinHit = min( tMaxPlane, tMinPlane );
|
|
4257
|
+
vec3 tMaxHit = max( tMaxPlane, tMinPlane );
|
|
4258
|
+
|
|
4259
|
+
// get the furthest hit distance
|
|
4260
|
+
vec2 t = max( tMinHit.xx, tMinHit.yz );
|
|
4261
|
+
float t0 = max( t.x, t.y );
|
|
4262
|
+
|
|
4263
|
+
// get the minimum hit distance
|
|
4264
|
+
t = min( tMaxHit.xx, tMaxHit.yz );
|
|
4265
|
+
float t1 = min( t.x, t.y );
|
|
4266
|
+
|
|
4267
|
+
// set distance to 0.0 if the ray starts inside the box
|
|
4268
|
+
dist = max( t0, 0.0 );
|
|
4269
|
+
|
|
4270
|
+
return t1 >= dist;
|
|
4271
|
+
|
|
4272
|
+
}
|
|
4273
|
+
|
|
4274
|
+
bool intersectsTriangle(
|
|
4275
|
+
vec3 rayOrigin, vec3 rayDirection, vec3 a, vec3 b, vec3 c,
|
|
4276
|
+
out vec3 barycoord, out vec3 norm, out float dist, out float side
|
|
4277
|
+
) {
|
|
4278
|
+
|
|
4279
|
+
// https://stackoverflow.com/questions/42740765/intersection-between-line-and-triangle-in-3d
|
|
4280
|
+
vec3 edge1 = b - a;
|
|
4281
|
+
vec3 edge2 = c - a;
|
|
4282
|
+
norm = cross( edge1, edge2 );
|
|
4283
|
+
|
|
4284
|
+
float det = - dot( rayDirection, norm );
|
|
4285
|
+
float invdet = 1.0 / det;
|
|
4286
|
+
|
|
4287
|
+
vec3 AO = rayOrigin - a;
|
|
4288
|
+
vec3 DAO = cross( AO, rayDirection );
|
|
4289
|
+
|
|
4290
|
+
vec4 uvt;
|
|
4291
|
+
uvt.x = dot( edge2, DAO ) * invdet;
|
|
4292
|
+
uvt.y = - dot( edge1, DAO ) * invdet;
|
|
4293
|
+
uvt.z = dot( AO, norm ) * invdet;
|
|
4294
|
+
uvt.w = 1.0 - uvt.x - uvt.y;
|
|
4295
|
+
|
|
4296
|
+
// set the hit information
|
|
4297
|
+
barycoord = uvt.wxy; // arranged in A, B, C order
|
|
4298
|
+
dist = uvt.z;
|
|
4299
|
+
side = sign( det );
|
|
4300
|
+
norm = side * normalize( norm );
|
|
4301
|
+
|
|
4302
|
+
// add an epsilon to avoid misses between triangles
|
|
4303
|
+
uvt += vec4( TRI_INTERSECT_EPSILON );
|
|
4304
|
+
|
|
4305
|
+
return all( greaterThanEqual( uvt, vec4( 0.0 ) ) );
|
|
4306
|
+
|
|
4307
|
+
}
|
|
4308
|
+
|
|
4309
|
+
bool intersectTriangles(
|
|
4310
|
+
// geometry info and triangle range
|
|
4311
|
+
sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count,
|
|
4312
|
+
|
|
4313
|
+
// ray
|
|
4314
|
+
vec3 rayOrigin, vec3 rayDirection,
|
|
4315
|
+
|
|
4316
|
+
// outputs
|
|
4317
|
+
inout float minDistance, inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
|
|
4318
|
+
inout float side, inout float dist
|
|
4319
|
+
) {
|
|
4320
|
+
|
|
4321
|
+
bool found = false;
|
|
4322
|
+
vec3 localBarycoord, localNormal;
|
|
4323
|
+
float localDist, localSide;
|
|
4324
|
+
for ( uint i = offset, l = offset + count; i < l; i ++ ) {
|
|
4325
|
+
|
|
4326
|
+
uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz;
|
|
4327
|
+
vec3 a = texelFetch1D( positionAttr, indices.x ).rgb;
|
|
4328
|
+
vec3 b = texelFetch1D( positionAttr, indices.y ).rgb;
|
|
4329
|
+
vec3 c = texelFetch1D( positionAttr, indices.z ).rgb;
|
|
4330
|
+
|
|
4331
|
+
if (
|
|
4332
|
+
intersectsTriangle( rayOrigin, rayDirection, a, b, c, localBarycoord, localNormal, localDist, localSide )
|
|
4333
|
+
&& localDist < minDistance
|
|
4334
|
+
) {
|
|
4335
|
+
|
|
4336
|
+
found = true;
|
|
4337
|
+
minDistance = localDist;
|
|
4338
|
+
|
|
4339
|
+
faceIndices = uvec4( indices.xyz, i );
|
|
4340
|
+
faceNormal = localNormal;
|
|
4341
|
+
|
|
4342
|
+
side = localSide;
|
|
4343
|
+
barycoord = localBarycoord;
|
|
4344
|
+
dist = localDist;
|
|
4345
|
+
|
|
4346
|
+
}
|
|
4347
|
+
|
|
4348
|
+
}
|
|
4349
|
+
|
|
4350
|
+
return found;
|
|
4351
|
+
|
|
4352
|
+
}
|
|
4353
|
+
|
|
4354
|
+
bool intersectsBVHNodeBounds( vec3 rayOrigin, vec3 rayDirection, sampler2D bvhBounds, uint currNodeIndex, out float dist ) {
|
|
4355
|
+
|
|
4356
|
+
uint cni2 = currNodeIndex * 2u;
|
|
4357
|
+
vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz;
|
|
4358
|
+
vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz;
|
|
4359
|
+
return intersectsBounds( rayOrigin, rayDirection, boundsMin, boundsMax, dist );
|
|
4360
|
+
|
|
4361
|
+
}
|
|
4362
|
+
|
|
4363
|
+
// use a macro to hide the fact that we need to expand the struct into separate fields
|
|
4364
|
+
#define bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ) _bvhIntersectFirstHit( bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist )
|
|
4365
|
+
|
|
4366
|
+
bool _bvhIntersectFirstHit(
|
|
4367
|
+
// bvh info
|
|
4368
|
+
sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents,
|
|
4369
|
+
|
|
4370
|
+
// ray
|
|
4371
|
+
vec3 rayOrigin, vec3 rayDirection,
|
|
4372
|
+
|
|
4373
|
+
// output variables split into separate variables due to output precision
|
|
4374
|
+
inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
|
|
4375
|
+
inout float side, inout float dist
|
|
4376
|
+
) {
|
|
4377
|
+
|
|
4378
|
+
// stack needs to be twice as long as the deepest tree we expect because
|
|
4379
|
+
// we push both the left and right child onto the stack every traversal
|
|
4380
|
+
int pointer = 0;
|
|
4381
|
+
uint stack[ BVH_STACK_DEPTH ];
|
|
4382
|
+
stack[ 0 ] = 0u;
|
|
4383
|
+
|
|
4384
|
+
float triangleDistance = INFINITY;
|
|
4385
|
+
bool found = false;
|
|
4386
|
+
while ( pointer > - 1 && pointer < BVH_STACK_DEPTH ) {
|
|
4387
|
+
|
|
4388
|
+
uint currNodeIndex = stack[ pointer ];
|
|
4389
|
+
pointer --;
|
|
4390
|
+
|
|
4391
|
+
// check if we intersect the current bounds
|
|
4392
|
+
float boundsHitDistance;
|
|
4393
|
+
if (
|
|
4394
|
+
! intersectsBVHNodeBounds( rayOrigin, rayDirection, bvh_bvhBounds, currNodeIndex, boundsHitDistance )
|
|
4395
|
+
|| boundsHitDistance > triangleDistance
|
|
4396
|
+
) {
|
|
4397
|
+
|
|
4398
|
+
continue;
|
|
4399
|
+
|
|
4400
|
+
}
|
|
4401
|
+
|
|
4402
|
+
uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy;
|
|
4403
|
+
bool isLeaf = bool( boundsInfo.x & 0xffff0000u );
|
|
4404
|
+
|
|
4405
|
+
if ( isLeaf ) {
|
|
4406
|
+
|
|
4407
|
+
uint count = boundsInfo.x & 0x0000ffffu;
|
|
4408
|
+
uint offset = boundsInfo.y;
|
|
4409
|
+
|
|
4410
|
+
found = intersectTriangles(
|
|
4411
|
+
bvh_position, bvh_index, offset, count,
|
|
4412
|
+
rayOrigin, rayDirection, triangleDistance,
|
|
4413
|
+
faceIndices, faceNormal, barycoord, side, dist
|
|
4414
|
+
) || found;
|
|
4415
|
+
|
|
4416
|
+
} else {
|
|
4417
|
+
|
|
4418
|
+
uint leftIndex = currNodeIndex + 1u;
|
|
4419
|
+
uint splitAxis = boundsInfo.x & 0x0000ffffu;
|
|
4420
|
+
uint rightIndex = currNodeIndex + boundsInfo.y;
|
|
4421
|
+
|
|
4422
|
+
bool leftToRight = rayDirection[ splitAxis ] >= 0.0;
|
|
4423
|
+
uint c1 = leftToRight ? leftIndex : rightIndex;
|
|
4424
|
+
uint c2 = leftToRight ? rightIndex : leftIndex;
|
|
4425
|
+
|
|
4426
|
+
// set c2 in the stack so we traverse it later. We need to keep track of a pointer in
|
|
4427
|
+
// the stack while we traverse. The second pointer added is the one that will be
|
|
4428
|
+
// traversed first
|
|
4429
|
+
pointer ++;
|
|
4430
|
+
stack[ pointer ] = c2;
|
|
4431
|
+
|
|
4432
|
+
pointer ++;
|
|
4433
|
+
stack[ pointer ] = c1;
|
|
4434
|
+
|
|
4435
|
+
}
|
|
4436
|
+
|
|
4437
|
+
}
|
|
4438
|
+
|
|
4439
|
+
return found;
|
|
4440
|
+
|
|
4441
|
+
}
|
|
4442
|
+
`
|
|
4443
|
+
);
|
|
4444
|
+
|
|
4445
|
+
// node_modules/three-mesh-bvh/src/index.js
|
|
4446
|
+
var shaderIntersectFunction = `
|
|
4447
|
+
${common_functions}
|
|
4448
|
+
${bvh_ray_functions}
|
|
4449
|
+
`;
|
|
4450
|
+
|
|
4451
|
+
// src/rendering/surface-query.js
|
|
4452
|
+
function assertQueryMesh(mesh) {
|
|
4453
|
+
if (!(mesh.positions instanceof Float32Array) || mesh.positions.length % 3) throw new TypeError("Invalid mesh positions.");
|
|
4454
|
+
if (!(mesh.indices instanceof Uint32Array) || mesh.indices.length % 3) throw new TypeError("Invalid mesh indices.");
|
|
4455
|
+
const count = mesh.positions.length / 3;
|
|
4456
|
+
for (const index of mesh.indices) if (index >= count) throw new RangeError("Mesh index exceeds vertex count.");
|
|
4457
|
+
}
|
|
4458
|
+
function createSurfaceQuery(mesh, options = {}) {
|
|
4459
|
+
assertQueryMesh(mesh);
|
|
4460
|
+
const geometry = new BufferGeometry();
|
|
4461
|
+
geometry.setAttribute("position", new BufferAttribute3(mesh.positions, 3));
|
|
4462
|
+
if (mesh.normals && !options.geometryOnly) geometry.setAttribute("normal", new BufferAttribute3(mesh.normals, 3));
|
|
4463
|
+
if (mesh.uvs && !options.geometryOnly) geometry.setAttribute("uv", new BufferAttribute3(mesh.uvs, 2));
|
|
4464
|
+
geometry.setIndex(new BufferAttribute3(mesh.indices, 1));
|
|
4465
|
+
const bvh = new MeshBVH(geometry, {
|
|
4466
|
+
strategy: options.fastBuild ? AVERAGE : SAH,
|
|
4467
|
+
indirect: true,
|
|
4468
|
+
verbose: false
|
|
4469
|
+
});
|
|
4470
|
+
return createSurfaceQueryFromBvh(geometry, bvh);
|
|
4471
|
+
}
|
|
4472
|
+
function createSurfaceQueryFromBvh(geometry, bvh) {
|
|
4473
|
+
const point = new Vector311();
|
|
4474
|
+
const direction = new Vector311();
|
|
4475
|
+
const ray = new Ray2(point, direction);
|
|
4476
|
+
const closestTarget = {
|
|
4477
|
+
point: new Vector311(),
|
|
4478
|
+
distance: Infinity,
|
|
4479
|
+
faceIndex: -1
|
|
4480
|
+
};
|
|
4481
|
+
return {
|
|
4482
|
+
geometry,
|
|
4483
|
+
bvh,
|
|
4484
|
+
/**
|
|
4485
|
+
* @param {ArrayLike<number>} value
|
|
4486
|
+
* @param {number=} maxDistance
|
|
4487
|
+
*/
|
|
4488
|
+
closestPoint(value, maxDistance = Infinity) {
|
|
4489
|
+
point.set(value[0], value[1], value[2]);
|
|
4490
|
+
const hit = bvh.closestPointToPoint(point, closestTarget, 0, maxDistance);
|
|
4491
|
+
if (!hit || hit.distance === void 0 || hit.faceIndex === void 0 || !hit.point) return null;
|
|
4492
|
+
return {
|
|
4493
|
+
point: [hit.point.x, hit.point.y, hit.point.z],
|
|
4494
|
+
distance: hit.distance,
|
|
4495
|
+
faceIndex: hit.faceIndex
|
|
4496
|
+
};
|
|
4497
|
+
},
|
|
4498
|
+
/**
|
|
4499
|
+
* @param {ArrayLike<number>} origin
|
|
4500
|
+
* @param {ArrayLike<number>} rayDirection
|
|
4501
|
+
* @param {number} near
|
|
4502
|
+
* @param {number} far
|
|
4503
|
+
* @param {'front' | 'back'} side
|
|
4504
|
+
*/
|
|
4505
|
+
raycastFirst(origin, rayDirection, near, far, side = "front") {
|
|
4506
|
+
point.set(origin[0], origin[1], origin[2]);
|
|
4507
|
+
direction.set(rayDirection[0], rayDirection[1], rayDirection[2]).normalize();
|
|
4508
|
+
return bvh.raycastFirst(ray, side === "front" ? FrontSide2 : BackSide2, near, far);
|
|
4509
|
+
},
|
|
4510
|
+
dispose() {
|
|
4511
|
+
geometry.dispose();
|
|
4512
|
+
}
|
|
4513
|
+
};
|
|
4514
|
+
}
|
|
4515
|
+
export {
|
|
4516
|
+
createSurfaceQuery,
|
|
4517
|
+
createSurfaceQueryFromBvh
|
|
4518
|
+
};
|
|
4519
|
+
//# sourceMappingURL=surface-query.js.map
|