@woosh/meep-engine 2.126.43 → 2.126.44

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.126.43",
8
+ "version": "2.126.44",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -2,9 +2,9 @@
2
2
  *
3
3
  * @param {number[]} result
4
4
  * @param {number} result_offset
5
- * @param {number} constrained_planes_mask if bit is set to 1, that plane is not allowed to move
5
+ * @param {number} plane_mask if bit is set to 0, that plane is not allowed to move
6
6
  * @param {BVH} bvh
7
7
  * @param {number[]|ArrayLike<number>|Float32Array} frustum
8
8
  */
9
- export function compute_tight_near_far_clipping_planes(result: number[], result_offset: number, constrained_planes_mask: number, bvh: BVH, frustum: number[] | ArrayLike<number> | Float32Array): boolean;
9
+ export function compute_tight_near_far_clipping_planes(result: number[], result_offset: number, plane_mask: number, bvh: BVH, frustum: number[] | ArrayLike<number> | Float32Array): boolean;
10
10
  //# sourceMappingURL=compute_tight_near_far_clipping_planes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compute_tight_near_far_clipping_planes.d.ts","sourceRoot":"","sources":["../../../../../../src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js"],"names":[],"mappings":"AAcA;;;;;;;GAOG;AACH,+DANW,MAAM,EAAE,iBACR,MAAM,2BACN,MAAM,OACN,GAAG,WACH,MAAM,EAAE,GAAC,SAAS,CAAC,MAAM,CAAC,GAAC,YAAY,WAuIjD"}
1
+ {"version":3,"file":"compute_tight_near_far_clipping_planes.d.ts","sourceRoot":"","sources":["../../../../../../src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,+DANW,MAAM,EAAE,iBACR,MAAM,cACN,MAAM,OACN,GAAG,WACH,MAAM,EAAE,GAAC,SAAS,CAAC,MAAM,CAAC,GAAC,YAAY,WA+LjD"}
@@ -1,28 +1,39 @@
1
- //
2
-
3
-
4
1
  import { array_copy } from "../../../collection/array/array_copy.js";
5
2
  import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
6
- import { aabb3_array_intersects_frustum_degree } from "../../../geom/3d/aabb/aabb3_array_intersects_frustum_degree.js";
7
3
  import { v3_distance_above_plane } from "../../../geom/vec3/v3_distance_above_plane.js";
8
4
  import { NULL_NODE } from "../BVH.js";
9
- import { bvh_collect_user_data } from "./bvh_collect_user_data.js";
10
5
 
11
6
  const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
12
7
 
13
8
  const scratch_aabb = [];
14
9
 
10
+ const scratch_frustum = new Float32Array(24);
11
+
15
12
  /**
16
13
  *
17
14
  * @param {number[]} result
18
15
  * @param {number} result_offset
19
- * @param {number} constrained_planes_mask if bit is set to 1, that plane is not allowed to move
16
+ * @param {number} plane_mask if bit is set to 0, that plane is not allowed to move
20
17
  * @param {BVH} bvh
21
18
  * @param {number[]|ArrayLike<number>|Float32Array} frustum
22
19
  */
23
- export function compute_tight_near_far_clipping_planes(result, result_offset, constrained_planes_mask, bvh, frustum) {
20
+ export function compute_tight_near_far_clipping_planes(
21
+ result,
22
+ result_offset,
23
+ plane_mask,
24
+ bvh,
25
+ frustum
26
+ ) {
27
+
24
28
  // initialize result
25
- array_copy(frustum, 0, result, result_offset, 24);
29
+ array_copy(frustum, 0, scratch_frustum, 0, 24);
30
+
31
+ // set output planes to infinity so we can slowly bring them in
32
+ for (let i = 0; i < 6; i++) {
33
+ if (((plane_mask >> i) & 1) === 1) {
34
+ scratch_frustum[i * 4 + 3] = Infinity;
35
+ }
36
+ }
26
37
 
27
38
  const root = bvh.root;
28
39
 
@@ -68,13 +79,19 @@ export function compute_tight_near_far_clipping_planes(result, result_offset, co
68
79
  const _z1 = scratch_aabb[5];
69
80
 
70
81
  for (let plane_index = 0; plane_index < 6; plane_index++) {
82
+
83
+ if (((plane_mask >> plane_index) & 1) === 1) {
84
+ // plane is not fixed, we're done here
85
+ continue;
86
+ }
87
+
71
88
  const plane_address = plane_index * 4;
72
89
 
73
90
  //read out plane
74
- const plane_normal_x = frustum[plane_address];
75
- const plane_normal_y = frustum[plane_address + 1];
76
- const plane_normal_z = frustum[plane_address + 2];
77
- const plane_offset = frustum[plane_address + 3];
91
+ const plane_normal_x = scratch_frustum[plane_address];
92
+ const plane_normal_y = scratch_frustum[plane_address + 1];
93
+ const plane_normal_z = scratch_frustum[plane_address + 2];
94
+ const plane_offset = scratch_frustum[plane_address + 3];
78
95
 
79
96
 
80
97
  // construct nearest and farthest corners along the plane normal
@@ -112,45 +129,81 @@ export function compute_tight_near_far_clipping_planes(result, result_offset, co
112
129
  continue node_loop;
113
130
  }
114
131
 
115
- if ((constrained_planes_mask & (1 << plane_index)) !== 0) {
116
- // plane is constrained, we're done here
117
- continue;
118
- }
119
-
120
- //
121
-
122
132
  }
123
133
 
124
- const intersection = aabb3_array_intersects_frustum_degree(scratch_aabb, 0, frustum);
125
-
126
- if (intersection === 0) {
127
- // fully outside
128
- continue;
129
- }
130
134
 
131
135
  const node_is_leaf = bvh.node_is_leaf(node);
132
136
 
133
137
  if (!node_is_leaf) {
134
138
 
135
- if (intersection === 2) {
136
- // fully inside, fast collection path
137
- result_cursor += bvh_collect_user_data(result, result_cursor, bvh, node);
138
- } else {
139
- // partially inside
140
- // read in-order
141
- const child1 = bvh.node_get_child1(node);
142
- const child2 = bvh.node_get_child2(node);
143
-
144
- // write to stack in reverse order, so that fist child ends up being visited first
145
- stack[stack.pointer++] = child1;
146
- stack[stack.pointer++] = child2;
147
- }
139
+ // inside
140
+ // read in-order
141
+ const child1 = bvh.node_get_child1(node);
142
+ const child2 = bvh.node_get_child2(node);
143
+
144
+ // write to stack in reverse order, so that fist child ends up being visited first
145
+ stack[stack.pointer++] = child1;
146
+ stack[stack.pointer++] = child2;
148
147
 
149
148
  } else {
149
+
150
150
  // leaf node
151
151
 
152
+ // update planes
153
+ for (let i = 0; i < 6; i++) {
154
+ if (((plane_mask >> i) & 1) === 1) {
155
+
156
+ const plane_address = i * 4;
157
+
158
+ //read out plane
159
+ const plane_normal_x = scratch_frustum[plane_address];
160
+ const plane_normal_y = scratch_frustum[plane_address + 1];
161
+ const plane_normal_z = scratch_frustum[plane_address + 2];
162
+ const plane_offset = scratch_frustum[plane_address + 3];
163
+
164
+
165
+ // construct nearest and farthest corners along the plane normal
166
+ if (plane_normal_x > 0) {
167
+ x0 = _x0;
168
+ x1 = _x1;
169
+ } else {
170
+ x0 = _x1;
171
+ x1 = _x0;
172
+ }
173
+
174
+ if (plane_normal_y > 0) {
175
+ y0 = _y0;
176
+ y1 = _y1;
177
+ } else {
178
+ y0 = _y1;
179
+ y1 = _y0;
180
+ }
181
+
182
+ if (plane_normal_z > 0) {
183
+ z0 = _z0;
184
+ z1 = _z1;
185
+ } else {
186
+ z0 = _z1;
187
+ z1 = _z0;
188
+ }
189
+
190
+ const distance_above_plane = v3_distance_above_plane(
191
+ x1, y1, z1,
192
+ plane_normal_x, plane_normal_y, plane_normal_z, 0
193
+ );
194
+
195
+ if (distance_above_plane < plane_offset) {
196
+ // move plane
197
+ scratch_frustum[plane_address + 3] = distance_above_plane;
198
+ }
199
+ }
200
+ }
201
+
152
202
  }
153
203
  }
154
204
 
155
- return true;
205
+ // TODO check if results are still at infinity
206
+
207
+ array_copy(scratch_frustum, 0, result, result_offset, 24);
208
+
156
209
  }