@woosh/meep-engine 2.131.32 → 2.131.34
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/bvh2/binary/2/bvh32_query_user_data_ray.d.ts +2 -1
- package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.d.ts.map +1 -1
- package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +24 -6
- package/src/core/geom/3d/aabb/aabb3_near_distance_to_intersection_ray_segment.d.ts.map +1 -1
- package/src/core/geom/3d/aabb/aabb3_near_distance_to_intersection_ray_segment.js +1 -0
- package/src/engine/ecs/terrain/tiles/TerrainTile.d.ts.map +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +2 -1
- package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.d.ts.map +1 -1
- package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +12 -1
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.d.ts.map +1 -1
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.js +14 -2
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.d.ts +8 -7
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.d.ts.map +1 -1
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js +21 -17
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"description": "Pure JavaScript game engine. Fully featured and production ready.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.131.
|
|
8
|
+
"version": "2.131.34",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* @param {number} direction_x
|
|
10
10
|
* @param {number} direction_y
|
|
11
11
|
* @param {number} direction_z
|
|
12
|
+
* @param {number} max_distance tMax for the ray, can set to Infinity if you don't care.
|
|
12
13
|
* @returns {number}
|
|
13
14
|
*/
|
|
14
|
-
export function bvh32_query_user_data_ray(result: number[], result_offset: number, bvh: BinaryUint32BVH, origin_x: number, origin_y: number, origin_z: number, direction_x: number, direction_y: number, direction_z: number): number;
|
|
15
|
+
export function bvh32_query_user_data_ray(result: number[], result_offset: number, bvh: BinaryUint32BVH, origin_x: number, origin_y: number, origin_z: number, direction_x: number, direction_y: number, direction_z: number, max_distance: number): number;
|
|
15
16
|
//# sourceMappingURL=bvh32_query_user_data_ray.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bvh32_query_user_data_ray.d.ts","sourceRoot":"","sources":["../../../../../../src/core/bvh2/binary/2/bvh32_query_user_data_ray.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bvh32_query_user_data_ray.d.ts","sourceRoot":"","sources":["../../../../../../src/core/bvh2/binary/2/bvh32_query_user_data_ray.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;GAaG;AACH,kDAZW,MAAM,EAAE,iBACR,MAAM,kCAEN,MAAM,YACN,MAAM,YACN,MAAM,eACN,MAAM,eACN,MAAM,eACN,MAAM,gBACN,MAAM,GACJ,MAAM,CA8FlB"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { assert } from "../../../assert.js";
|
|
1
2
|
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
aabb3_near_distance_to_intersection_ray_segment
|
|
5
|
+
} from "../../../geom/3d/aabb/aabb3_near_distance_to_intersection_ray_segment.js";
|
|
3
6
|
|
|
4
7
|
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
5
8
|
|
|
@@ -14,14 +17,19 @@ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
|
14
17
|
* @param {number} direction_x
|
|
15
18
|
* @param {number} direction_y
|
|
16
19
|
* @param {number} direction_z
|
|
20
|
+
* @param {number} max_distance tMax for the ray, can set to Infinity if you don't care.
|
|
17
21
|
* @returns {number}
|
|
18
22
|
*/
|
|
19
23
|
export function bvh32_query_user_data_ray(
|
|
20
24
|
result, result_offset,
|
|
21
25
|
bvh,
|
|
22
26
|
origin_x, origin_y, origin_z,
|
|
23
|
-
direction_x, direction_y, direction_z
|
|
27
|
+
direction_x, direction_y, direction_z,
|
|
28
|
+
max_distance,
|
|
24
29
|
) {
|
|
30
|
+
|
|
31
|
+
assert.isNumber(max_distance, "max_distance");
|
|
32
|
+
|
|
25
33
|
let hit_count = 0;
|
|
26
34
|
|
|
27
35
|
const binary_node_count = bvh.binary_node_count;
|
|
@@ -48,6 +56,11 @@ export function bvh32_query_user_data_ray(
|
|
|
48
56
|
const float32 = bvh.float32;
|
|
49
57
|
const uint32 = bvh.uint32;
|
|
50
58
|
|
|
59
|
+
|
|
60
|
+
const inv_direction_x = 1 / direction_x;
|
|
61
|
+
const inv_direction_y = 1 / direction_y;
|
|
62
|
+
const inv_direction_z = 1 / direction_z;
|
|
63
|
+
|
|
51
64
|
do {
|
|
52
65
|
stack.pointer--;
|
|
53
66
|
|
|
@@ -56,11 +69,16 @@ export function bvh32_query_user_data_ray(
|
|
|
56
69
|
|
|
57
70
|
const node_address = bvh.getNodeAddress(node_index);
|
|
58
71
|
|
|
59
|
-
|
|
60
|
-
float32, node_address,
|
|
72
|
+
const t = aabb3_near_distance_to_intersection_ray_segment(
|
|
73
|
+
float32[node_address], float32[node_address + 1], float32[node_address + 2],
|
|
74
|
+
float32[node_address + 3], float32[node_address + 4], float32[node_address + 5],
|
|
61
75
|
origin_x, origin_y, origin_z,
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
inv_direction_x, inv_direction_y, inv_direction_z,
|
|
77
|
+
0,
|
|
78
|
+
max_distance
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
if (t >= max_distance) {
|
|
64
82
|
continue;
|
|
65
83
|
}
|
|
66
84
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aabb3_near_distance_to_intersection_ray_segment.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/aabb/aabb3_near_distance_to_intersection_ray_segment.js"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,oEAhBW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,YACN,MAAM,YACN,MAAM,YACN,MAAM,mBACN,MAAM,mBACN,MAAM,mBACN,MAAM,gBACN,MAAM,gBACN,MAAM,GACJ,MAAM,
|
|
1
|
+
{"version":3,"file":"aabb3_near_distance_to_intersection_ray_segment.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/aabb/aabb3_near_distance_to_intersection_ray_segment.js"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,oEAhBW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,YACN,MAAM,YACN,MAAM,YACN,MAAM,mBACN,MAAM,mBACN,MAAM,mBACN,MAAM,gBACN,MAAM,gBACN,MAAM,GACJ,MAAM,CAgDlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TerrainTile.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/ecs/terrain/tiles/TerrainTile.js"],"names":[],"mappings":";AAgCA;;GAEG;AACH;IACI,sBAA6B;IAC7B,eAA0B;IAC1B,cAAyB;IACzB,kBAAyB;IACzB,4BAAoC;IAEpC;;;OAGG;IACH,mBAAgB;IAChB,uGAAiE;IAGjE;;;OAGG;IACH,UAFU,MAAM,cAAc,CAEd;IAEhB;;;OAGG;IACH,WAFU,OAAO,CAEA;IAEjB;;;OAGG;IACH,cAFU,SAAS,CAEY;IAE/B;;;OAGG;IACH,KAFU,eAAe,CAEd;IAEX;;;OAGG;IACH,SAFU,OAAO,CAED;IAChB;;;OAGG;IACH,mBAFU,OAAO,CAES;IAC1B,uBAAmB;IAEnB;;;OAGG;IACH,SAFU,OAAO,WAAW,CAAC,CAEN;IACvB,4DAA2B;IAE3B;;;;OAIG;IACH,kBAWE;IAEF;;;;;OAKG;IACH,+BAAiG;IAEjG;;;OAGG;IACH,SAFU,MAAM,CAEJ;IAqBZ;;;OAGG;IACH,6BAGC;IAfD;;;OAGG;IACH,0BAEC;IAWD;;;;;;;;;;OAUG;IACH,yBATW,aAAa,WACb,MAAM,WACN,MAAM,WACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,GACL,OAAO,
|
|
1
|
+
{"version":3,"file":"TerrainTile.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/ecs/terrain/tiles/TerrainTile.js"],"names":[],"mappings":";AAgCA;;GAEG;AACH;IACI,sBAA6B;IAC7B,eAA0B;IAC1B,cAAyB;IACzB,kBAAyB;IACzB,4BAAoC;IAEpC;;;OAGG;IACH,mBAAgB;IAChB,uGAAiE;IAGjE;;;OAGG;IACH,UAFU,MAAM,cAAc,CAEd;IAEhB;;;OAGG;IACH,WAFU,OAAO,CAEA;IAEjB;;;OAGG;IACH,cAFU,SAAS,CAEY;IAE/B;;;OAGG;IACH,KAFU,eAAe,CAEd;IAEX;;;OAGG;IACH,SAFU,OAAO,CAED;IAChB;;;OAGG;IACH,mBAFU,OAAO,CAES;IAC1B,uBAAmB;IAEnB;;;OAGG;IACH,SAFU,OAAO,WAAW,CAAC,CAEN;IACvB,4DAA2B;IAE3B;;;;OAIG;IACH,kBAWE;IAEF;;;;;OAKG;IACH,+BAAiG;IAEjG;;;OAGG;IACH,SAFU,MAAM,CAEJ;IAqBZ;;;OAGG;IACH,6BAGC;IAfD;;;OAGG;IACH,0BAEC;IAWD;;;;;;;;;;OAUG;IACH,yBATW,aAAa,WACb,MAAM,WACN,MAAM,WACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,GACL,OAAO,CAmDlB;IAED,+CAKC;IAED,8CAOC;IAED;;;;;;;;;;OAUG;IACH,mBATW,WAAW,GAAC,SAAS,UACrB,WAAW,GAAC,SAAS,QACrB,WAAW,GAAC,SAAS,SACrB,WAAW,GAAC,SAAS,WACrB,WAAW,GAAC,SAAS,YACrB,WAAW,GAAC,SAAS,cACrB,WAAW,GAAC,SAAS,eACrB,WAAW,GAAC,SAAS,QAsN/B;IAED,2BAmFC;IAED;;;;OAIG;IACH,mCAHW,MAAM,cACN,MAAM,QAIhB;IAED,gBAYC;IAED;;;;OAIG;IACH,gBAHW;QAAC,QAAQ,CAAC;QAAC,GAAG,CAAC,EAAC;YAAC,UAAU,EAAC,MAAM,CAAC;YAAC,IAAI,EAAC,WAAW,CAAA;SAAC,CAAA;KAAC,QAoDhE;CACJ;oBA1lBmB,kCAAkC;4BAG1B,2CAA2C;sDAZhE,OAAO;0BAEY,yCAAyC;gCADnC,mDAAmD;mBAGhE,0CAA0C;8BAI/B,2CAA2C"}
|
package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeometrySpatialQueryAccelerator.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js"],"names":[],"mappings":"AAiBA;IACI,iCA4BC;IArBG;;;OAGG;IACH,cAeE;IAIN;;;OAGG;IACH,4BAEC;IAED;;;OAGG;IACH,yBAEC;IAED;;;;;OAKG;IACH,4CAJW,MAAM,cAAc,UACpB,OAAO,GACL,OAAO,CAuCnB;IAED;;;;;;OAMG;IACH,gEAJW,MAAM,cAAc,OACpB,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,GACtC,OAAO,CASlB;IAED;;;;;;;;;;;OAWG;IACH,oEATW,MAAM,cAAc,gBACpB,MAAM,gBACN,MAAM,gBACN,MAAM,mBACN,MAAM,mBACN,MAAM,mBACN,MAAM,GACL,OAAO,
|
|
1
|
+
{"version":3,"file":"GeometrySpatialQueryAccelerator.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js"],"names":[],"mappings":"AAiBA;IACI,iCA4BC;IArBG;;;OAGG;IACH,cAeE;IAIN;;;OAGG;IACH,4BAEC;IAED;;;OAGG;IACH,yBAEC;IAED;;;;;OAKG;IACH,4CAJW,MAAM,cAAc,UACpB,OAAO,GACL,OAAO,CAuCnB;IAED;;;;;;OAMG;IACH,gEAJW,MAAM,cAAc,OACpB,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,GACtC,OAAO,CASlB;IAED;;;;;;;;;;;OAWG;IACH,oEATW,MAAM,cAAc,gBACpB,MAAM,gBACN,MAAM,gBACN,MAAM,mBACN,MAAM,mBACN,MAAM,mBACN,MAAM,GACL,OAAO,CAyDlB;IAED;;;;;;;OAOG;IACH,0DALW,MAAM,cAAc,gDAGlB,OAAO,CAcnB;IAED;;;;OAIG;IACH,gCAHW,MAAM,cAAc,GAClB,OAAO,CAMnB;IAED;;;;OAIG;IACH,sBAHW,MAAM,cAAc,GAClB,eAAe,CAiB3B;IAED;;;;OAIG;IACH,oBAyBC;CAEJ;;kBAIS,+BAA+B;;gCA5RT,sDAAsD"}
|
|
@@ -177,7 +177,18 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
177
177
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
return bvh32_geometry_raycast(
|
|
180
|
+
return bvh32_geometry_raycast(
|
|
181
|
+
destination,
|
|
182
|
+
bvh,
|
|
183
|
+
position_data,
|
|
184
|
+
position_data_offset,
|
|
185
|
+
stride,
|
|
186
|
+
position_attribute.normalized,
|
|
187
|
+
geometryIndices,
|
|
188
|
+
ray_origin_x, ray_origin_y, ray_origin_z,
|
|
189
|
+
ray_direction_x, ray_direction_y, ray_direction_z,
|
|
190
|
+
Infinity
|
|
191
|
+
);
|
|
181
192
|
|
|
182
193
|
}
|
|
183
194
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bvh32_geometry_nearest.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.js"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;;;;GAeG;AACH,8FAXW,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,iBAC1B,MAAM,iBACN,MAAM,0BACN,OAAO,WACP,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,SAAS,KACpC,MAAM,KACN,MAAM,KACN,MAAM,iBACN,MAAM,GACJ,OAAO,
|
|
1
|
+
{"version":3,"file":"bvh32_geometry_nearest.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.js"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;;;;GAeG;AACH,8FAXW,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,iBAC1B,MAAM,iBACN,MAAM,0BACN,OAAO,WACP,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,SAAS,KACpC,MAAM,KACN,MAAM,KACN,MAAM,iBACN,MAAM,GACJ,OAAO,CAmOnB"}
|
|
@@ -63,6 +63,7 @@ export function bvh32_geometry_nearest(
|
|
|
63
63
|
*/
|
|
64
64
|
const stack_top = stack.pointer++;
|
|
65
65
|
|
|
66
|
+
|
|
66
67
|
/**
|
|
67
68
|
* After performing empirical tests, stack-based depth-first traversal turns out faster than using a queue
|
|
68
69
|
* @type {number}
|
|
@@ -130,7 +131,18 @@ export function bvh32_geometry_nearest(
|
|
|
130
131
|
|
|
131
132
|
}
|
|
132
133
|
} else if (left_index < last_valid_index) {
|
|
133
|
-
|
|
134
|
+
|
|
135
|
+
const child_1_address = bvh.getNodeAddress(left_index);
|
|
136
|
+
|
|
137
|
+
const distance_sqr_to_child1 = aabb3_unsigned_distance_sqr_to_point(
|
|
138
|
+
float32[child_1_address], float32[child_1_address + 1], float32[child_1_address + 2],
|
|
139
|
+
float32[child_1_address + 3], float32[child_1_address + 4], float32[child_1_address + 5],
|
|
140
|
+
x, y, z
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
if(distance_sqr_to_child1 < nearest_distance_sqr) {
|
|
144
|
+
stack[stack.pointer++] = left_index;
|
|
145
|
+
}
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
|
|
@@ -207,7 +219,7 @@ export function bvh32_geometry_nearest(
|
|
|
207
219
|
|
|
208
220
|
computeTriangleClosestPointToPointBarycentric(
|
|
209
221
|
v3_scratch_0, 0,
|
|
210
|
-
x,
|
|
222
|
+
x, y, z,
|
|
211
223
|
ax, ay, az,
|
|
212
224
|
bx, by, bz,
|
|
213
225
|
cx, cy, cz
|
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
* @param {number} vertex_stride Unless you're using an interleaved buffer, this should be 3
|
|
8
8
|
* @param {boolean} vertex_data_normalized do we need to denormalize vertex data?
|
|
9
9
|
* @param {number[]|ArrayLike<number>|undefined} indices if this is set to undefined - implicit indexing will be used
|
|
10
|
-
* @param {number}
|
|
11
|
-
* @param {number}
|
|
12
|
-
* @param {number}
|
|
13
|
-
* @param {number}
|
|
14
|
-
* @param {number}
|
|
15
|
-
* @param {number}
|
|
10
|
+
* @param {number} origin_x
|
|
11
|
+
* @param {number} origin_y
|
|
12
|
+
* @param {number} origin_z
|
|
13
|
+
* @param {number} direction_x
|
|
14
|
+
* @param {number} direction_y
|
|
15
|
+
* @param {number} direction_z
|
|
16
|
+
* @param {number} max_distance How far can the ray travel from origin? tMax
|
|
16
17
|
* @returns {boolean}
|
|
17
18
|
*/
|
|
18
|
-
export function bvh32_geometry_raycast(result: SurfacePoint3, bvh: BinaryUint32BVH, vertices: number[] | ArrayLike<number>, vertex_offset: number, vertex_stride: number, vertex_data_normalized: boolean, indices: number[] | ArrayLike<number> | undefined,
|
|
19
|
+
export function bvh32_geometry_raycast(result: SurfacePoint3, bvh: BinaryUint32BVH, vertices: number[] | ArrayLike<number>, vertex_offset: number, vertex_stride: number, vertex_data_normalized: boolean, indices: number[] | ArrayLike<number> | undefined, origin_x: number, origin_y: number, origin_z: number, direction_x: number, direction_y: number, direction_z: number, max_distance: number): boolean;
|
|
19
20
|
import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
|
|
20
21
|
//# sourceMappingURL=bvh32_geometry_raycast.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bvh32_geometry_raycast.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js"],"names":[],"mappings":"AAWA
|
|
1
|
+
{"version":3,"file":"bvh32_geometry_raycast.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;GAiBG;AACH,+CAhBW,aAAa,kCAEb,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,iBAC1B,MAAM,iBACN,MAAM,0BACN,OAAO,WACP,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,SAAS,YACpC,MAAM,YACN,MAAM,YACN,MAAM,eACN,MAAM,eACN,MAAM,eACN,MAAM,gBACN,MAAM,GACJ,OAAO,CA2GnB;8BAjI6B,8CAA8C"}
|
|
@@ -18,12 +18,13 @@ const scratch_hit = new SurfacePoint3()
|
|
|
18
18
|
* @param {number} vertex_stride Unless you're using an interleaved buffer, this should be 3
|
|
19
19
|
* @param {boolean} vertex_data_normalized do we need to denormalize vertex data?
|
|
20
20
|
* @param {number[]|ArrayLike<number>|undefined} indices if this is set to undefined - implicit indexing will be used
|
|
21
|
-
* @param {number}
|
|
22
|
-
* @param {number}
|
|
23
|
-
* @param {number}
|
|
24
|
-
* @param {number}
|
|
25
|
-
* @param {number}
|
|
26
|
-
* @param {number}
|
|
21
|
+
* @param {number} origin_x
|
|
22
|
+
* @param {number} origin_y
|
|
23
|
+
* @param {number} origin_z
|
|
24
|
+
* @param {number} direction_x
|
|
25
|
+
* @param {number} direction_y
|
|
26
|
+
* @param {number} direction_z
|
|
27
|
+
* @param {number} max_distance How far can the ray travel from origin? tMax
|
|
27
28
|
* @returns {boolean}
|
|
28
29
|
*/
|
|
29
30
|
export function bvh32_geometry_raycast(
|
|
@@ -32,22 +33,25 @@ export function bvh32_geometry_raycast(
|
|
|
32
33
|
vertices, vertex_offset, vertex_stride,
|
|
33
34
|
vertex_data_normalized,
|
|
34
35
|
indices,
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
origin_x, origin_y, origin_z,
|
|
37
|
+
direction_x, direction_y, direction_z,
|
|
38
|
+
max_distance
|
|
37
39
|
) {
|
|
38
40
|
|
|
39
41
|
assert.isBoolean(vertex_data_normalized, 'vertex_data_normalized');
|
|
42
|
+
assert.isNumber(max_distance, 'max_distance');
|
|
40
43
|
|
|
41
44
|
let hit_found = false;
|
|
42
45
|
|
|
43
46
|
const hit_count = bvh32_query_user_data_ray(
|
|
44
47
|
scratch_array, 0,
|
|
45
48
|
bvh,
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
origin_x, origin_y, origin_z,
|
|
50
|
+
direction_x, direction_y, direction_z,
|
|
51
|
+
max_distance,
|
|
48
52
|
);
|
|
49
53
|
|
|
50
|
-
let
|
|
54
|
+
let best_distance_sqr = max_distance * max_distance;
|
|
51
55
|
|
|
52
56
|
let a, b, c;
|
|
53
57
|
|
|
@@ -90,7 +94,7 @@ export function bvh32_geometry_raycast(
|
|
|
90
94
|
let cz = vertices[c_address + 2];
|
|
91
95
|
|
|
92
96
|
// denormalize if necessary
|
|
93
|
-
if(vertex_data_normalized) {
|
|
97
|
+
if (vertex_data_normalized) {
|
|
94
98
|
ax = typed_array_value_denormalize(ax, vertices);
|
|
95
99
|
ay = typed_array_value_denormalize(ay, vertices);
|
|
96
100
|
az = typed_array_value_denormalize(az, vertices);
|
|
@@ -106,8 +110,8 @@ export function bvh32_geometry_raycast(
|
|
|
106
110
|
|
|
107
111
|
const triangle_hit_found = computeTriangleRayIntersection(
|
|
108
112
|
scratch_hit,
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
origin_x, origin_y, origin_z,
|
|
114
|
+
direction_x, direction_y, direction_z,
|
|
111
115
|
ax, ay, az,
|
|
112
116
|
bx, by, bz,
|
|
113
117
|
cx, cy, cz
|
|
@@ -119,10 +123,10 @@ export function bvh32_geometry_raycast(
|
|
|
119
123
|
|
|
120
124
|
hit_found = true;
|
|
121
125
|
|
|
122
|
-
const distance_sqr = scratch_hit.position._distanceSqrTo(
|
|
126
|
+
const distance_sqr = scratch_hit.position._distanceSqrTo(origin_x, origin_y, origin_z);
|
|
123
127
|
|
|
124
|
-
if (distance_sqr <
|
|
125
|
-
|
|
128
|
+
if (distance_sqr < best_distance_sqr) {
|
|
129
|
+
best_distance_sqr = distance_sqr;
|
|
126
130
|
result.copy(scratch_hit);
|
|
127
131
|
}
|
|
128
132
|
}
|