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