@woosh/meep-engine 2.119.34 → 2.119.36
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/package.json +1 -1
- package/src/core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.js +2 -2
- package/src/engine/graphics/geometry/buffered/query/query_bvh_geometry_nearest.d.ts +14 -0
- package/src/engine/graphics/geometry/buffered/query/query_bvh_geometry_nearest.d.ts.map +1 -0
- package/src/engine/graphics/geometry/buffered/query/query_bvh_geometry_nearest.js +202 -0
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js +3 -165
package/package.json
CHANGED
|
@@ -80,7 +80,7 @@ export function computeTriangleClosestPointToPointBarycentric(
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const vc = d1 * d4 - d3 * d2;
|
|
83
|
-
if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
|
|
83
|
+
if ( vc <= 0 && d1 >= 0 && d3 <= 0 && d1 !== d3) {
|
|
84
84
|
|
|
85
85
|
v = d1 / ( d1 - d3 );
|
|
86
86
|
// edge region of AB; barycentric coords (1-v, v, 0)
|
|
@@ -111,7 +111,7 @@ export function computeTriangleClosestPointToPointBarycentric(
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
const vb = d5 * d2 - d1 * d6;
|
|
114
|
-
if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
|
|
114
|
+
if ( vb <= 0 && d2 >= 0 && d6 <= 0 && d2 !== d6 ) {
|
|
115
115
|
|
|
116
116
|
w = d2 / ( d2 - d6 );
|
|
117
117
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {SurfacePoint3} result
|
|
4
|
+
* @param {BVH} bvh
|
|
5
|
+
* @param {number[]|Float32Array} positions
|
|
6
|
+
* @param {number[]|Uint32Array|Uint16Array} indices
|
|
7
|
+
* @param {number} x
|
|
8
|
+
* @param {number} y
|
|
9
|
+
* @param {number} z
|
|
10
|
+
* @param {number} max_distance
|
|
11
|
+
* @return {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export function query_bvh_geometry_nearest(result: SurfacePoint3, bvh: BVH, positions: number[] | Float32Array, indices: number[] | Uint32Array | Uint16Array, x: number, y: number, z: number, max_distance: number): boolean;
|
|
14
|
+
//# sourceMappingURL=query_bvh_geometry_nearest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query_bvh_geometry_nearest.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/query_bvh_geometry_nearest.js"],"names":[],"mappings":"AAwBA;;;;;;;;;;;GAWG;AACH,uFARW,MAAM,EAAE,GAAC,YAAY,WACrB,MAAM,EAAE,GAAC,WAAW,GAAC,WAAW,KAChC,MAAM,KACN,MAAM,KACN,MAAM,gBACN,MAAM,GACL,OAAO,CAuKlB"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COLUMN_CHILD_1,
|
|
3
|
+
COLUMN_CHILD_2,
|
|
4
|
+
COLUMN_USER_DATA,
|
|
5
|
+
ELEMENT_WORD_COUNT,
|
|
6
|
+
NULL_NODE
|
|
7
|
+
} from "../../../../../core/bvh2/bvh3/BVH.js";
|
|
8
|
+
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../../../core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
9
|
+
import {
|
|
10
|
+
aabb3_unsigned_distance_sqr_to_point
|
|
11
|
+
} from "../../../../../core/geom/3d/aabb/aabb3_unsigned_distance_sqr_to_point.js";
|
|
12
|
+
import {
|
|
13
|
+
computeTriangleClosestPointToPointBarycentric
|
|
14
|
+
} from "../../../../../core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.js";
|
|
15
|
+
import { v3_compute_triangle_normal } from "../../../../../core/geom/3d/triangle/v3_compute_triangle_normal.js";
|
|
16
|
+
import { v3_distance_sqr } from "../../../../../core/geom/vec3/v3_distance_sqr.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @type {number[]}
|
|
21
|
+
*/
|
|
22
|
+
const v3_scratch_0 = [];
|
|
23
|
+
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {SurfacePoint3} result
|
|
28
|
+
* @param {BVH} bvh
|
|
29
|
+
* @param {number[]|Float32Array} positions
|
|
30
|
+
* @param {number[]|Uint32Array|Uint16Array} indices
|
|
31
|
+
* @param {number} x
|
|
32
|
+
* @param {number} y
|
|
33
|
+
* @param {number} z
|
|
34
|
+
* @param {number} max_distance
|
|
35
|
+
* @return {boolean}
|
|
36
|
+
*/
|
|
37
|
+
export function query_bvh_geometry_nearest(
|
|
38
|
+
result,
|
|
39
|
+
bvh,
|
|
40
|
+
positions,
|
|
41
|
+
indices,
|
|
42
|
+
x, y, z,
|
|
43
|
+
max_distance
|
|
44
|
+
) {
|
|
45
|
+
|
|
46
|
+
const root = bvh.root;
|
|
47
|
+
|
|
48
|
+
if (root === NULL_NODE) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Move stack pointer to local variable scope to avoid de-referencing inside the loop
|
|
55
|
+
* @type {number}
|
|
56
|
+
*/
|
|
57
|
+
let pointer = stack.pointer;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @type {number}
|
|
62
|
+
*/
|
|
63
|
+
const stack_top = pointer;
|
|
64
|
+
|
|
65
|
+
stack[pointer++] = root;
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
For performance, we bind data directly to avoid extra copies required to read out AABB
|
|
69
|
+
*/
|
|
70
|
+
const float32 = bvh.__data_float32;
|
|
71
|
+
const uint32 = bvh.__data_uint32;
|
|
72
|
+
|
|
73
|
+
let nearest_distance_sqr = max_distance * max_distance;
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
do {
|
|
77
|
+
--pointer;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @type {number}
|
|
82
|
+
*/
|
|
83
|
+
const node = stack[pointer];
|
|
84
|
+
|
|
85
|
+
const address = node * ELEMENT_WORD_COUNT;
|
|
86
|
+
|
|
87
|
+
// test node against the ray
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
// get fist child to check if this is a leaf node or not
|
|
91
|
+
const child_1 = uint32[address + COLUMN_CHILD_1];
|
|
92
|
+
|
|
93
|
+
if (child_1 !== NULL_NODE) {
|
|
94
|
+
|
|
95
|
+
// this is not a leaf node, push children onto traversal stack
|
|
96
|
+
const child_2 = uint32[address + COLUMN_CHILD_2];
|
|
97
|
+
|
|
98
|
+
// to achieve faster convergence, we sort children before adding them to the stack by their proximity to the reference point
|
|
99
|
+
const child_1_address = child_1 * ELEMENT_WORD_COUNT;
|
|
100
|
+
|
|
101
|
+
const distance_sqr_to_child1 = aabb3_unsigned_distance_sqr_to_point(
|
|
102
|
+
float32[child_1_address], float32[child_1_address + 1], float32[child_1_address + 2],
|
|
103
|
+
float32[child_1_address + 3], float32[child_1_address + 4], float32[child_1_address + 5],
|
|
104
|
+
x, y, z
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const child_2_address = child_2 * ELEMENT_WORD_COUNT;
|
|
108
|
+
|
|
109
|
+
const distance_sqr_to_child2 = aabb3_unsigned_distance_sqr_to_point(
|
|
110
|
+
float32[child_2_address], float32[child_2_address + 1], float32[child_2_address + 2],
|
|
111
|
+
float32[child_2_address + 3], float32[child_2_address + 4], float32[child_2_address + 5],
|
|
112
|
+
x, y, z
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (distance_sqr_to_child1 < distance_sqr_to_child2) {
|
|
116
|
+
|
|
117
|
+
if (distance_sqr_to_child2 < nearest_distance_sqr) {
|
|
118
|
+
stack[pointer++] = child_2;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (distance_sqr_to_child1 < nearest_distance_sqr) {
|
|
122
|
+
stack[pointer++] = child_1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
} else {
|
|
126
|
+
|
|
127
|
+
if (distance_sqr_to_child1 < nearest_distance_sqr) {
|
|
128
|
+
stack[pointer++] = child_1;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (distance_sqr_to_child2 < nearest_distance_sqr) {
|
|
132
|
+
stack[pointer++] = child_2;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
} else {
|
|
139
|
+
// leaf node
|
|
140
|
+
// read triangle data
|
|
141
|
+
const triangle_index = uint32[address + COLUMN_USER_DATA];
|
|
142
|
+
|
|
143
|
+
const a = indices[triangle_index];
|
|
144
|
+
const b = indices[triangle_index + 1];
|
|
145
|
+
const c = indices[triangle_index + 2];
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
const a_address = a * 3;
|
|
149
|
+
const b_address = b * 3;
|
|
150
|
+
const c_address = c * 3;
|
|
151
|
+
|
|
152
|
+
const ax = positions[a_address];
|
|
153
|
+
const ay = positions[a_address + 1];
|
|
154
|
+
const az = positions[a_address + 2];
|
|
155
|
+
|
|
156
|
+
const bx = positions[b_address];
|
|
157
|
+
const by = positions[b_address + 1];
|
|
158
|
+
const bz = positions[b_address + 2];
|
|
159
|
+
|
|
160
|
+
const cx = positions[c_address];
|
|
161
|
+
const cy = positions[c_address + 1];
|
|
162
|
+
const cz = positions[c_address + 2];
|
|
163
|
+
|
|
164
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
165
|
+
v3_scratch_0, 0,
|
|
166
|
+
x, y, z,
|
|
167
|
+
ax, ay, az,
|
|
168
|
+
bx, by, bz,
|
|
169
|
+
cx, cy, cz
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const u = v3_scratch_0[0];
|
|
173
|
+
const v = v3_scratch_0[1];
|
|
174
|
+
|
|
175
|
+
// construct edge
|
|
176
|
+
|
|
177
|
+
const contact_x = (bx - ax) * u + (cx - ax) * v + ax;
|
|
178
|
+
const contact_y = (by - ay) * u + (cy - ay) * v + ay;
|
|
179
|
+
const contact_z = (bz - az) * u + (cz - az) * v + az;
|
|
180
|
+
|
|
181
|
+
const distance_to_triangle_sqr = v3_distance_sqr(contact_x, contact_y, contact_z, x, y, z);
|
|
182
|
+
|
|
183
|
+
if (distance_to_triangle_sqr >= nearest_distance_sqr) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
nearest_distance_sqr = distance_to_triangle_sqr;
|
|
188
|
+
|
|
189
|
+
result.position.set(contact_x, contact_y, contact_z);
|
|
190
|
+
|
|
191
|
+
v3_compute_triangle_normal(result.normal, 0,
|
|
192
|
+
ax, ay, az,
|
|
193
|
+
bx, by, bz,
|
|
194
|
+
cx, cy, cz
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
result.index = triangle_index;
|
|
198
|
+
}
|
|
199
|
+
} while (pointer > stack_top);
|
|
200
|
+
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"AAuCA;IAkBI;;;OAGG;IACH,eAFW,KAAK,GAAC,MAAM,EAAE,QAIxB;IAIG;;;;OAIG;IACH,mBAAsB;IAEtB;;;;OAIG;IACH,yBAA4B;IAE5B;;;;OAIG;IACH,6BAAgC;IAGhC;;;;OAIG;IACH,yBAAyB;IAG7B;;;OAGG;IACH,WAFW,MAAM,cAAc,QA2C9B;IAED;;;;;OAKG;IACH,qBAFa,OAAO,CAmHnB;IAED;;;;;;;OAOG;IACH,4BANW,aAAa,KACb,MAAM,KACN,MAAM,KACN,MAAM,GACJ,OAAO,CAUnB;IAGD;;;;;;OAMG;IACH,iBAJW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,GACX,MAAM,CAoIlB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,GACX,MAAM,CA2ElB;;CACJ;sBA3eqB,wCAAwC;8BAGhC,2CAA2C"}
|
|
@@ -13,21 +13,14 @@ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../../core/collection/SCRA
|
|
|
13
13
|
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
14
14
|
import { aabb3_from_v3_array } from "../../../../core/geom/3d/aabb/aabb3_from_v3_array.js";
|
|
15
15
|
import { aabb3_intersects_ray_segment } from "../../../../core/geom/3d/aabb/aabb3_intersects_ray_segment.js";
|
|
16
|
-
import {
|
|
17
|
-
aabb3_unsigned_distance_sqr_to_point
|
|
18
|
-
} from "../../../../core/geom/3d/aabb/aabb3_unsigned_distance_sqr_to_point.js";
|
|
19
16
|
import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
20
|
-
import {
|
|
21
|
-
computeTriangleClosestPointToPointBarycentric
|
|
22
|
-
} from "../../../../core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.js";
|
|
23
17
|
|
|
24
18
|
import {
|
|
25
19
|
computeTriangleRayIntersectionBarycentricGeometry
|
|
26
20
|
} from "../../../../core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricGeometry.js";
|
|
27
|
-
import { v3_compute_triangle_normal } from "../../../../core/geom/3d/triangle/v3_compute_triangle_normal.js";
|
|
28
|
-
import { v3_distance_sqr } from "../../../../core/geom/vec3/v3_distance_sqr.js";
|
|
29
21
|
import Vector4 from "../../../../core/geom/Vector4.js";
|
|
30
22
|
import { makeGeometryIndexed } from "../../geometry/buffered/makeGeometryIndexed.js";
|
|
23
|
+
import { query_bvh_geometry_nearest } from "../../geometry/buffered/query/query_bvh_geometry_nearest.js";
|
|
31
24
|
import { computeBoundingSphereFromVertexData } from "../../geometry/computeBoundingSphereFromVertexData.js";
|
|
32
25
|
import { construct_ray_hit_from_geometry } from "./geometry/construct_ray_hit_from_geometry.js";
|
|
33
26
|
|
|
@@ -127,7 +120,7 @@ export class BufferedGeometryBVH {
|
|
|
127
120
|
|
|
128
121
|
const bvh = this.#bvh;
|
|
129
122
|
|
|
130
|
-
aabb3_from_v3_array(
|
|
123
|
+
aabb3_from_v3_array(this.#bounds, array_positions, array_positions.length);
|
|
131
124
|
|
|
132
125
|
ebvh_build_for_geometry_morton(
|
|
133
126
|
bvh,
|
|
@@ -285,162 +278,7 @@ export class BufferedGeometryBVH {
|
|
|
285
278
|
|
|
286
279
|
const bvh = this.#bvh;
|
|
287
280
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (root === NULL_NODE) {
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Move stack pointer to local variable scope to avoid de-referencing inside the loop
|
|
296
|
-
* @type {number}
|
|
297
|
-
*/
|
|
298
|
-
let pointer = stack.pointer;
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
*
|
|
302
|
-
* @type {number}
|
|
303
|
-
*/
|
|
304
|
-
const stack_top = pointer;
|
|
305
|
-
|
|
306
|
-
stack[pointer++] = root;
|
|
307
|
-
|
|
308
|
-
/*
|
|
309
|
-
For performance, we bind data directly to avoid extra copies required to read out AABB
|
|
310
|
-
*/
|
|
311
|
-
const float32 = bvh.__data_float32;
|
|
312
|
-
const uint32 = bvh.__data_uint32;
|
|
313
|
-
|
|
314
|
-
let nearest_distance_sqr = Infinity;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
do {
|
|
318
|
-
--pointer;
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
*
|
|
322
|
-
* @type {number}
|
|
323
|
-
*/
|
|
324
|
-
const node = stack[pointer];
|
|
325
|
-
|
|
326
|
-
const address = node * ELEMENT_WORD_COUNT;
|
|
327
|
-
|
|
328
|
-
// test node against the ray
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
// get fist child to check if this is a leaf node or not
|
|
332
|
-
const child_1 = uint32[address + COLUMN_CHILD_1];
|
|
333
|
-
|
|
334
|
-
if (child_1 !== NULL_NODE) {
|
|
335
|
-
|
|
336
|
-
// this is not a leaf node, push children onto traversal stack
|
|
337
|
-
const child_2 = uint32[address + COLUMN_CHILD_2];
|
|
338
|
-
|
|
339
|
-
// to achieve faster convergence, we sort children before adding them to the stack by their proximity to the reference point
|
|
340
|
-
const child_1_address = child_1 * ELEMENT_WORD_COUNT;
|
|
341
|
-
|
|
342
|
-
const distance_sqr_to_child1 = aabb3_unsigned_distance_sqr_to_point(
|
|
343
|
-
float32[child_1_address], float32[child_1_address + 1], float32[child_1_address + 2],
|
|
344
|
-
float32[child_1_address + 3], float32[child_1_address + 4], float32[child_1_address + 5],
|
|
345
|
-
x, y, z
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
const child_2_address = child_2 * ELEMENT_WORD_COUNT;
|
|
349
|
-
|
|
350
|
-
const distance_sqr_to_child2 = aabb3_unsigned_distance_sqr_to_point(
|
|
351
|
-
float32[child_2_address], float32[child_2_address + 1], float32[child_2_address + 2],
|
|
352
|
-
float32[child_2_address + 3], float32[child_2_address + 4], float32[child_2_address + 5],
|
|
353
|
-
x, y, z
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
if (distance_sqr_to_child1 < distance_sqr_to_child2) {
|
|
357
|
-
|
|
358
|
-
if (distance_sqr_to_child2 < nearest_distance_sqr) {
|
|
359
|
-
stack[pointer++] = child_2;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
if (distance_sqr_to_child1 < nearest_distance_sqr) {
|
|
363
|
-
stack[pointer++] = child_1;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
} else {
|
|
367
|
-
|
|
368
|
-
if (distance_sqr_to_child1 < nearest_distance_sqr) {
|
|
369
|
-
stack[pointer++] = child_1;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (distance_sqr_to_child2 < nearest_distance_sqr) {
|
|
373
|
-
stack[pointer++] = child_2;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
} else {
|
|
380
|
-
// leaf node
|
|
381
|
-
// read triangle data
|
|
382
|
-
const triangle_index = uint32[address + COLUMN_USER_DATA];
|
|
383
|
-
|
|
384
|
-
const a = indices[triangle_index];
|
|
385
|
-
const b = indices[triangle_index + 1];
|
|
386
|
-
const c = indices[triangle_index + 2];
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
const a_address = a * 3;
|
|
390
|
-
const b_address = b * 3;
|
|
391
|
-
const c_address = c * 3;
|
|
392
|
-
|
|
393
|
-
const ax = positions[a_address];
|
|
394
|
-
const ay = positions[a_address + 1];
|
|
395
|
-
const az = positions[a_address + 2];
|
|
396
|
-
|
|
397
|
-
const bx = positions[b_address];
|
|
398
|
-
const by = positions[b_address + 1];
|
|
399
|
-
const bz = positions[b_address + 2];
|
|
400
|
-
|
|
401
|
-
const cx = positions[c_address];
|
|
402
|
-
const cy = positions[c_address + 1];
|
|
403
|
-
const cz = positions[c_address + 2];
|
|
404
|
-
|
|
405
|
-
computeTriangleClosestPointToPointBarycentric(
|
|
406
|
-
v3_scratch_0, 0,
|
|
407
|
-
x, y, z,
|
|
408
|
-
ax, ay, az,
|
|
409
|
-
bx, by, bz,
|
|
410
|
-
cx, cy, cz
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
const u = v3_scratch_0[0];
|
|
414
|
-
const v = v3_scratch_0[1];
|
|
415
|
-
|
|
416
|
-
// construct edge
|
|
417
|
-
|
|
418
|
-
const contact_x = (bx - ax) * u + (cx - ax) * v + ax;
|
|
419
|
-
const contact_y = (by - ay) * u + (cy - ay) * v + ay;
|
|
420
|
-
const contact_z = (bz - az) * u + (cz - az) * v + az;
|
|
421
|
-
|
|
422
|
-
const distance_to_triangle_sqr = v3_distance_sqr(contact_x, contact_y, contact_z, x, y, z);
|
|
423
|
-
|
|
424
|
-
if (distance_to_triangle_sqr >= nearest_distance_sqr) {
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
nearest_distance_sqr = distance_to_triangle_sqr;
|
|
429
|
-
|
|
430
|
-
result.position.set(contact_x, contact_y, contact_z);
|
|
431
|
-
|
|
432
|
-
v3_compute_triangle_normal(result.normal, 0,
|
|
433
|
-
ax, ay, az,
|
|
434
|
-
bx, by, bz,
|
|
435
|
-
cx, cy, cz
|
|
436
|
-
);
|
|
437
|
-
|
|
438
|
-
result.index = triangle_index;
|
|
439
|
-
}
|
|
440
|
-
} while (pointer > stack_top);
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return true;
|
|
281
|
+
return query_bvh_geometry_nearest(result, bvh, positions, indices, x, y, z, Infinity);
|
|
444
282
|
}
|
|
445
283
|
|
|
446
284
|
|