@woosh/meep-engine 2.131.33 → 2.131.35

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 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.33",
8
+ "version": "2.131.35",
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":"AAKA;;;;;;;;;;;;GAYG;AACH,kDAXW,MAAM,EAAE,iBACR,MAAM,kCAEN,MAAM,YACN,MAAM,YACN,MAAM,eACN,MAAM,eACN,MAAM,eACN,MAAM,GACJ,MAAM,CAgFlB"}
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 { aabb3_array_intersects_ray } from "../../../geom/3d/aabb/aabb3_array_intersects_ray.js";
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
- if (!aabb3_array_intersects_ray(
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
- direction_x, direction_y, direction_z
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":"ebvh_optimize_treelet.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/ebvh_optimize_treelet.js"],"names":[],"mappings":"AAuNA;;;;;;;GAOG;AACH,uDAHW,MAAM,iBACN,MAAM,QA+IhB"}
1
+ {"version":3,"file":"ebvh_optimize_treelet.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/ebvh_optimize_treelet.js"],"names":[],"mappings":"AAgRA;;;;;;;GAOG;AACH,uDAHW,MAAM,iBACN,MAAM,QA+IhB"}
@@ -1,15 +1,16 @@
1
1
  import { assert } from "../../assert.js";
2
2
  import { lsb_32 } from "../../binary/lsb_32.js";
3
3
  import { bitCount } from "../../binary/operations/bitCount.js";
4
- import { NULL_NODE } from "./BVH.js";
4
+ import { ELEMENT_WORD_COUNT, NULL_NODE } from "./BVH.js";
5
5
 
6
6
  // Common continuous memory region for better cache performance
7
- const scratch_memory = new ArrayBuffer((256 * 3 + 16) * 4);
7
+ const scratch_memory = new ArrayBuffer((256 * 3 + 16) * 4 + 256 * 6 * 4);
8
8
 
9
- const scratch_areas = new Float32Array(scratch_memory, 0, 256);
10
- const scratch_cost = new Float32Array(scratch_memory, 1024, 256);
11
- const scratch_partitions = new Uint32Array(scratch_memory, 2048, 256);
12
- const scratch_treelet = new Uint32Array(scratch_memory, 3072, 16);
9
+ const scratch_bounds = new Float32Array(scratch_memory, 0, 256 * 6);
10
+ const scratch_areas = new Float32Array(scratch_memory, 6144, 256);
11
+ const scratch_cost = new Float32Array(scratch_memory, 7168, 256);
12
+ const scratch_partitions = new Uint32Array(scratch_memory, 8192, 256);
13
+ const scratch_treelet = new Uint32Array(scratch_memory, 9216, 16);
13
14
 
14
15
  /**
15
16
  *
@@ -74,28 +75,84 @@ function optimize_treelet(bvh, root, leaves, leaf_count) {
74
75
 
75
76
  // see "Fast Parallel Construction of High-Quality Bounding Volume Hierarchies", Algorithm 2
76
77
 
78
+ const bvh_float32 = bvh.data_float32;
79
+
77
80
  // Calculate surface area for each subset
78
- for (let i = 0; i < leaf_count; i++) {
79
- const leaf_0 = leaves[i];
80
- for (let j = i + 1; j < leaf_count; j++) {
81
- const leaf_1 = leaves[j];
81
+ const mask_limit = (1 << leaf_count) - 1;
82
+
83
+ for (let s = 1; s <= mask_limit; s++) {
84
+ let min_x, min_y, min_z, max_x, max_y, max_z;
85
+
86
+ // Check if 's' is a power of 2 (i.e., a single leaf)
87
+ // (s & (s-1)) === 0 is the standard trick for this
88
+ const is_a_leaf = (s & (s - 1)) === 0;
89
+
90
+ if (is_a_leaf) {
91
+ // --- CASE A: LEAF ---
92
+ // Map the mask bit back to a linear index (0..7)
93
+ const leaf_index = lsb_32(s);
94
+
95
+ // Read from your compact linear array
96
+ const node = leaves[leaf_index];
97
+
98
+ const source_offset = node * ELEMENT_WORD_COUNT;
99
+
100
+ min_x = bvh_float32[source_offset];
101
+ min_y = bvh_float32[source_offset + 1];
102
+ min_z = bvh_float32[source_offset + 2];
103
+ max_x = bvh_float32[source_offset + 3];
104
+ max_y = bvh_float32[source_offset + 4];
105
+ max_z = bvh_float32[source_offset + 5];
106
+
107
+ // Initialize base cost for leaf (SAH_COST_TRIANGLE * Area)
108
+ // (Calculated below)
109
+ } else {
110
+ // --- CASE B: SUBSET ---
111
+ // Split s into: LSB (Leaf) + Rest (Subset)
112
+ // Both of these are < s, so they are guaranteed to be initialized.
113
+ const mask_lsb = s & -s; // Extract lowest set bit
114
+ const mask_rest = s ^ mask_lsb; // The rest of the bits
115
+
116
+ const i_lsb = mask_lsb * 6;
117
+ const i_rest = mask_rest * 6;
118
+
119
+ // Merge bounds
120
+ min_x = Math.min(scratch_bounds[i_lsb], scratch_bounds[i_rest]);
121
+ min_y = Math.min(scratch_bounds[i_lsb + 1], scratch_bounds[i_rest + 1]);
122
+ min_z = Math.min(scratch_bounds[i_lsb + 2], scratch_bounds[i_rest + 2]);
123
+ max_x = Math.max(scratch_bounds[i_lsb + 3], scratch_bounds[i_rest + 3]);
124
+ max_y = Math.max(scratch_bounds[i_lsb + 4], scratch_bounds[i_rest + 4]);
125
+ max_z = Math.max(scratch_bounds[i_lsb + 5], scratch_bounds[i_rest + 5]);
126
+ }
82
127
 
83
- const s = (1 << i) | (1 << j);
128
+ // --- STORE ---
129
+ const dest_offset = s * 6;
84
130
 
85
- scratch_areas[s] = bvh.node_get_combined_surface_area(leaf_0, leaf_1)
86
- }
87
- }
131
+ scratch_bounds[dest_offset] = min_x;
132
+ scratch_bounds[dest_offset + 1] = min_y;
133
+ scratch_bounds[dest_offset + 2] = min_z;
134
+ scratch_bounds[dest_offset + 3] = max_x;
135
+ scratch_bounds[dest_offset + 4] = max_y;
136
+ scratch_bounds[dest_offset + 5] = max_z;
88
137
 
89
- // Initialize costs of individual leaves
90
- for (let i = 0; i < leaf_count; i++) {
91
- const leaf = leaves[i];
138
+ // Calculate Surface Area
139
+ const dx = max_x - min_x;
140
+ const dy = max_y - min_y;
141
+ const dz = max_z - min_z;
92
142
 
93
- scratch_cost[1 << i] = SAH_COST_TRIANGLE * bvh.node_get_surface_area(leaf);
143
+ const area = 2.0 * (dx * dy + dy * dz + dz * dx);
144
+
145
+ scratch_areas[s] = area;
146
+
147
+ if(is_a_leaf){
148
+ // Initialize costs of individual leaves
149
+ scratch_cost[s] = SAH_COST_TRIANGLE * area;
150
+ }
94
151
  }
95
152
 
96
153
  // Optimize every subset of leaves
97
154
  for (let k = 2; k <= leaf_count; k++) {
98
- for (let s = 1; s <= (1 << leaf_count) - 1; s++) {
155
+ for (let s = 1; s <= mask_limit; s++) {
99
156
  if (bitCount(s) !== k) {
100
157
  continue;
101
158
  }
@@ -322,7 +379,7 @@ export function ebvh_optimize_treelet(
322
379
 
323
380
  } else if (came_from_type === CAME_FROM_TYPE_PARENT) {
324
381
  const child1 = bvh.node_get_child1(node);
325
- const child2 = bvh.node_get_child1(node);
382
+ const child2 = bvh.node_get_child2(node);
326
383
 
327
384
  if (child1 !== NULL_NODE) {
328
385
  came_from_type = CAME_FROM_TYPE_PARENT;
@@ -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,CA+ClB"}
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"}
@@ -60,6 +60,7 @@ export function aabb3_near_distance_to_intersection_ray_segment(
60
60
  const t_box_max = Math.min(t_max_x, t_max_y, t_max_z, max_distance);
61
61
 
62
62
  if (t_box_min > t_box_max) {
63
+ // signal a miss
63
64
  return Infinity;
64
65
  }
65
66
 
@@ -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,CAkDlB;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;oBAzlBmB,kCAAkC;4BAG1B,2CAA2C;sDAZhE,OAAO;0BAEY,yCAAyC;gCADnC,mDAAmD;mBAGhE,0CAA0C;8BAI/B,2CAA2C"}
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"}
@@ -199,7 +199,8 @@ class TerrainTile {
199
199
  attribute_position.normalized,
200
200
  geometryIndices,
201
201
  _originX, _originY, _originZ,
202
- _directionX, _directionY, _directionZ
202
+ _directionX, _directionY, _directionZ,
203
+ Infinity,
203
204
  );
204
205
 
205
206
  if (hit_found) {
@@ -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,CA8ClB;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;;gCAjRT,sDAAsD"}
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(destination, bvh, position_data, position_data_offset, stride, position_attribute.normalized, geometryIndices, ray_origin_x, ray_origin_y, ray_origin_z, ray_direction_x, ray_direction_y, ray_direction_z);
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
 
@@ -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} originX
11
- * @param {number} originY
12
- * @param {number} originZ
13
- * @param {number} directionX
14
- * @param {number} directionY
15
- * @param {number} directionZ
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, originX: number, originY: number, originZ: number, directionX: number, directionY: number, directionZ: number): boolean;
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;;;;;;;;;;;;;;;;GAgBG;AACH,+CAfW,aAAa,kCAEb,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,iBAC1B,MAAM,iBACN,MAAM,0BACN,OAAO,WACP,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,SAAS,WACpC,MAAM,WACN,MAAM,WACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,GACJ,OAAO,CAwGnB;8BA7H6B,8CAA8C"}
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} originX
22
- * @param {number} originY
23
- * @param {number} originZ
24
- * @param {number} directionX
25
- * @param {number} directionY
26
- * @param {number} directionZ
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
- originX, originY, originZ,
36
- directionX, directionY, directionZ
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
- originX, originY, originZ,
47
- directionX, directionY, directionZ
49
+ origin_x, origin_y, origin_z,
50
+ direction_x, direction_y, direction_z,
51
+ max_distance,
48
52
  );
49
53
 
50
- let best_distance = Infinity;
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
- originX, originY, originZ,
110
- directionX, directionY, directionZ,
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(originX, originY, originZ);
126
+ const distance_sqr = scratch_hit.position._distanceSqrTo(origin_x, origin_y, origin_z);
123
127
 
124
- if (distance_sqr < best_distance) {
125
- best_distance = distance_sqr;
128
+ if (distance_sqr < best_distance_sqr) {
129
+ best_distance_sqr = distance_sqr;
126
130
  result.copy(scratch_hit);
127
131
  }
128
132
  }