@woosh/meep-engine 2.46.28 → 2.46.29
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/bvh3/EBBVHLeafProxy.js +6 -1
- package/src/core/geom/3d/aabb/aabb3_matrix4_project.js +1 -1
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts +9 -0
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +148 -9
- package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +21 -1
- package/src/engine/graphics/render/forward_plus/LightManager.js +0 -60
- package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +1 -3
- package/src/engine/graphics/render/forward_plus/model/Decal.js +1 -1
- package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.d.ts +0 -3
- package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +0 -11
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ export class EBBVHLeafProxy {
|
|
|
22
22
|
*/
|
|
23
23
|
bounds = new Float32Array(6);
|
|
24
24
|
|
|
25
|
-
get is_linked(){
|
|
25
|
+
get is_linked() {
|
|
26
26
|
return this.#node_id !== -1;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -55,6 +55,11 @@ export class EBBVHLeafProxy {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
write_bounds() {
|
|
58
|
+
if (this.#tree === null) {
|
|
59
|
+
// nothing to write to
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
this.#tree.node_move_aabb(this.#node_id, this.bounds);
|
|
59
64
|
}
|
|
60
65
|
}
|
|
@@ -5,7 +5,7 @@ import { assert } from "../../../assert.js";
|
|
|
5
5
|
* NOTE: {@link result} and {@link aabb} must be different objects
|
|
6
6
|
* @param {ArrayLike<number>|number[]|Float32Array} result
|
|
7
7
|
* @param {ArrayLike<number>|number[]|Float32Array} aabb
|
|
8
|
-
* @param {number[]} matrix 4x4 matrix
|
|
8
|
+
* @param {ArrayLike<number>|number[]|Float32Array} matrix 4x4 matrix
|
|
9
9
|
*/
|
|
10
10
|
export function aabb3_matrix4_project(result, aabb, matrix) {
|
|
11
11
|
assert.notEqual(result, aabb, 'input and output must not be the same for algorithm to work correctly');
|
|
@@ -2,7 +2,16 @@ import {System} from "../../../../ecs/System";
|
|
|
2
2
|
import {Decal} from "./Decal";
|
|
3
3
|
import {Transform} from "../../../../ecs/transform/Transform";
|
|
4
4
|
import Engine from "../../../../Engine";
|
|
5
|
+
import {SurfacePoint3} from "../../../../../core/geom/3d/SurfacePoint3";
|
|
5
6
|
|
|
6
7
|
export class FPDecalSystem extends System<Decal, Transform> {
|
|
7
8
|
constructor(engine: Engine)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
raycast(
|
|
12
|
+
origin_x: number, origin_y: number, origin_z: number,
|
|
13
|
+
direction_x: number, direction_y: number, direction_z: number,
|
|
14
|
+
filter_function?: (entity: number, mesh: Decal) => boolean,
|
|
15
|
+
filter_function_context?: any
|
|
16
|
+
): { entity: number, component: Decal, contact: SurfacePoint3 }[]
|
|
8
17
|
}
|
|
@@ -11,21 +11,54 @@ import { GameAssetType } from "../../../../asset/GameAssetType.js";
|
|
|
11
11
|
import { assert } from "../../../../../core/assert.js";
|
|
12
12
|
import { AsyncLoadingCache } from "../../../../../core/collection/map/AsyncLoadingCache.js";
|
|
13
13
|
import { sampler2d_to_uint8_RGBA } from "../../../texture/sampler/sampler2d_to_uint8_RGBA.js";
|
|
14
|
+
import { returnTrue } from "../../../../../core/function/Functions.js";
|
|
15
|
+
import {
|
|
16
|
+
ExplicitBinaryBoundingVolumeHierarchy
|
|
17
|
+
} from "../../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
18
|
+
import { bvh_query_leaves_ray } from "../../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
|
|
19
|
+
import { ray3_array_apply_matrix4 } from "../../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
20
|
+
import { aabb3_intersects_ray } from "../../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
|
|
21
|
+
import { ray3_array_compose } from "../../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
22
|
+
import { mat4 } from "gl-matrix";
|
|
23
|
+
import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
|
|
24
|
+
import { EBBVHLeafProxy } from "../../../../../core/bvh2/bvh3/EBBVHLeafProxy.js";
|
|
25
|
+
import { aabb3_matrix4_project } from "../../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
|
|
14
26
|
|
|
15
27
|
const placeholder_texture = Sampler2D.uint8(4, 1, 1);
|
|
16
28
|
placeholder_texture.data.fill(255);
|
|
17
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @readonly
|
|
32
|
+
* @type {Float32Array}
|
|
33
|
+
*/
|
|
34
|
+
const scratch_ray_0 = new Float32Array(6);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @type {Float32Array|mat4}
|
|
40
|
+
*/
|
|
41
|
+
const scratch_m4 = new Float32Array(16);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @type {Float32Array}
|
|
46
|
+
*/
|
|
47
|
+
const AABB_UNIT_CUBE = new Float32Array([
|
|
48
|
+
-0.5, -0.5, -0.5,
|
|
49
|
+
0.5, 0.5, 0.5
|
|
50
|
+
]);
|
|
51
|
+
|
|
18
52
|
class Context extends SystemEntityContext {
|
|
19
|
-
constructor() {
|
|
20
|
-
super();
|
|
21
53
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @type {FPDecal|null}
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
__fp_decal = null;
|
|
60
|
+
|
|
61
|
+
#bvh_leaf = new EBBVHLeafProxy();
|
|
29
62
|
|
|
30
63
|
/**
|
|
31
64
|
* @return {ForwardPlusRenderingPlugin}
|
|
@@ -51,6 +84,10 @@ class Context extends SystemEntityContext {
|
|
|
51
84
|
const transform = this.getTransform();
|
|
52
85
|
|
|
53
86
|
this.__fp_decal.setTransform(transform.matrix);
|
|
87
|
+
|
|
88
|
+
aabb3_matrix4_project(this.#bvh_leaf.bounds, AABB_UNIT_CUBE, transform.matrix);
|
|
89
|
+
|
|
90
|
+
this.#bvh_leaf.write_bounds();
|
|
54
91
|
}
|
|
55
92
|
|
|
56
93
|
async __load_texture() {
|
|
@@ -135,6 +172,7 @@ class Context extends SystemEntityContext {
|
|
|
135
172
|
}
|
|
136
173
|
});
|
|
137
174
|
|
|
175
|
+
this.#bvh_leaf.link(this.system.bvh, this.entity);
|
|
138
176
|
|
|
139
177
|
super.link();
|
|
140
178
|
}
|
|
@@ -150,6 +188,8 @@ class Context extends SystemEntityContext {
|
|
|
150
188
|
const transform = this.getTransform();
|
|
151
189
|
transform.subscribeAllChanges(this.__update_transform, this);
|
|
152
190
|
|
|
191
|
+
this.#bvh_leaf.unlink();
|
|
192
|
+
|
|
153
193
|
super.unlink();
|
|
154
194
|
}
|
|
155
195
|
}
|
|
@@ -160,6 +200,8 @@ class Context extends SystemEntityContext {
|
|
|
160
200
|
*
|
|
161
201
|
*/
|
|
162
202
|
export class FPDecalSystem extends AbstractContextSystem {
|
|
203
|
+
bvh = new ExplicitBinaryBoundingVolumeHierarchy();
|
|
204
|
+
|
|
163
205
|
/**
|
|
164
206
|
*
|
|
165
207
|
* @param {Engine} engine
|
|
@@ -223,4 +265,101 @@ export class FPDecalSystem extends AbstractContextSystem {
|
|
|
223
265
|
|
|
224
266
|
super.shutdown(em, ready_callback, error_callback);
|
|
225
267
|
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
*
|
|
271
|
+
* @param {number} origin_x
|
|
272
|
+
* @param {number} origin_y
|
|
273
|
+
* @param {number} origin_z
|
|
274
|
+
* @param {number} direction_x
|
|
275
|
+
* @param {number} direction_y
|
|
276
|
+
* @param {number} direction_z
|
|
277
|
+
* @param {function(entity:number, component:Decal):boolean} [filter_function]
|
|
278
|
+
* @param {*} [filter_function_context]
|
|
279
|
+
* @returns {{entity:number, component:Decal, contact: SurfacePoint3}[]}
|
|
280
|
+
*/
|
|
281
|
+
raycast(
|
|
282
|
+
origin_x, origin_y, origin_z,
|
|
283
|
+
direction_x, direction_y, direction_z,
|
|
284
|
+
filter_function = returnTrue, filter_function_context
|
|
285
|
+
) {
|
|
286
|
+
|
|
287
|
+
const ecd = this.entityManager.dataset;
|
|
288
|
+
|
|
289
|
+
if (ecd === null) {
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const leaves = [];
|
|
294
|
+
|
|
295
|
+
const hit_count = bvh_query_leaves_ray(this.bvh, leaves, 0,
|
|
296
|
+
origin_x, origin_y, origin_z,
|
|
297
|
+
direction_x, direction_y, direction_z
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
const result = [];
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
for (let i = 0; i < hit_count; i++) {
|
|
304
|
+
const node = leaves[i];
|
|
305
|
+
|
|
306
|
+
const entity = this.bvh.node_get_user_data(node);
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
*
|
|
311
|
+
* @type {Decal}
|
|
312
|
+
*/
|
|
313
|
+
const decal = ecd.getComponent(entity, Decal);
|
|
314
|
+
|
|
315
|
+
if (decal === undefined) {
|
|
316
|
+
// this shouldn't happen
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
const transform = ecd.getComponent(entity, Transform);
|
|
322
|
+
|
|
323
|
+
if (transform === undefined) {
|
|
324
|
+
// this shouldn't happen either
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
ray3_array_compose(
|
|
329
|
+
scratch_ray_0,
|
|
330
|
+
origin_x, origin_y, origin_z,
|
|
331
|
+
direction_x, direction_y, direction_z
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
// get transform in local space
|
|
336
|
+
mat4.invert(scratch_m4, transform.matrix);
|
|
337
|
+
|
|
338
|
+
// transform ray into decal's local space
|
|
339
|
+
ray3_array_apply_matrix4(scratch_ray_0, 0, scratch_ray_0, 0, scratch_m4);
|
|
340
|
+
|
|
341
|
+
if (aabb3_intersects_ray(
|
|
342
|
+
-0.5, -0.5, -0.5,
|
|
343
|
+
0.5, 0.5, 0.5,
|
|
344
|
+
|
|
345
|
+
scratch_ray_0[0], scratch_ray_0[1], scratch_ray_0[2],
|
|
346
|
+
scratch_ray_0[3], scratch_ray_0[4], scratch_ray_0[5],
|
|
347
|
+
)) {
|
|
348
|
+
const contact = new SurfacePoint3();
|
|
349
|
+
|
|
350
|
+
// contact will be the center of decal, and normal will follow the decal normal
|
|
351
|
+
contact.applyMatrix4(transform.matrix);
|
|
352
|
+
|
|
353
|
+
result.push({
|
|
354
|
+
entity,
|
|
355
|
+
component: decal,
|
|
356
|
+
contact
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
226
365
|
}
|
|
@@ -336,7 +336,7 @@ function makeNormalTestGridDecal(ecd, root_transform = new Transform()) {
|
|
|
336
336
|
side: DoubleSide
|
|
337
337
|
}), DrawMode.Triangles))
|
|
338
338
|
.add(arrow_transform)
|
|
339
|
-
|
|
339
|
+
.build(ecd);
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
}
|
|
@@ -476,6 +476,26 @@ async function main(engine) {
|
|
|
476
476
|
//grid(engine.entityManager.dataset, 20,30,80, 25, .4, .6, .1, decal_urls.slice(105, 105+3));
|
|
477
477
|
// await promise_time_out(10);
|
|
478
478
|
|
|
479
|
+
engine.devices.pointer.position.onChanged.add(() => {
|
|
480
|
+
const ray_origin = new Vector3();
|
|
481
|
+
const ray_direction = new Vector3();
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
const pointer = engine.devices.pointer.position;
|
|
485
|
+
|
|
486
|
+
const ndc = new Vector2();
|
|
487
|
+
|
|
488
|
+
engine.graphics.normalizeViewportPoint(pointer,ndc);
|
|
489
|
+
engine.graphics.viewportProjectionRay(ndc.x, ndc.y, ray_origin, ray_direction);
|
|
490
|
+
|
|
491
|
+
const hits = engine.entityManager.getSystem(FPDecalSystem)?.raycast(
|
|
492
|
+
ray_origin.x, ray_origin.y, ray_origin.z,
|
|
493
|
+
ray_direction.x, ray_direction.y, ray_direction.z
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
console.warn(hits);
|
|
497
|
+
|
|
498
|
+
});
|
|
479
499
|
|
|
480
500
|
}
|
|
481
501
|
|
|
@@ -50,9 +50,6 @@ import {
|
|
|
50
50
|
bvh_query_user_data_overlaps_frustum
|
|
51
51
|
} from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js";
|
|
52
52
|
import { point_light_inside_volume } from "./query/point_light_inside_volume.js";
|
|
53
|
-
import { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
|
|
54
|
-
import { ray3_array_apply_matrix4 } from "../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
55
|
-
import { aabb3_intersects_ray } from "../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
|
|
56
53
|
|
|
57
54
|
|
|
58
55
|
/**
|
|
@@ -1205,61 +1202,4 @@ export class LightManager {
|
|
|
1205
1202
|
|
|
1206
1203
|
return true;
|
|
1207
1204
|
}
|
|
1208
|
-
|
|
1209
|
-
/**
|
|
1210
|
-
*
|
|
1211
|
-
* @param {Decal[]} result
|
|
1212
|
-
* @param {number} result_offset
|
|
1213
|
-
* @param {number[]} query
|
|
1214
|
-
* @param {number} query_offset
|
|
1215
|
-
* @returns {number} number of elements added to the result
|
|
1216
|
-
*/
|
|
1217
|
-
query_decals_by_ray(result, result_offset, query, query_offset) {
|
|
1218
|
-
|
|
1219
|
-
const leaves = [];
|
|
1220
|
-
const local_ray = new Float32Array(6);
|
|
1221
|
-
|
|
1222
|
-
const hit_count = bvh_query_leaves_ray(this.#light_data_bvh, leaves, 0,
|
|
1223
|
-
query[query_offset], query[query_offset + 1], query[query_offset + 2],
|
|
1224
|
-
query[query_offset + 3], query[query_offset + 4], query[query_offset + 5]
|
|
1225
|
-
);
|
|
1226
|
-
|
|
1227
|
-
let result_count = 0;
|
|
1228
|
-
|
|
1229
|
-
for (let i = 0; i < hit_count; i++) {
|
|
1230
|
-
const node = leaves[i];
|
|
1231
|
-
const light_id = this.#light_data_bvh.node_get_user_data(node);
|
|
1232
|
-
|
|
1233
|
-
const metadata = this.#metadata_map.get(light_id);
|
|
1234
|
-
|
|
1235
|
-
/**
|
|
1236
|
-
*
|
|
1237
|
-
* @type {Decal}
|
|
1238
|
-
*/
|
|
1239
|
-
const prop = metadata.light;
|
|
1240
|
-
|
|
1241
|
-
if (prop.isDecal !== true) {
|
|
1242
|
-
// wrong prop type
|
|
1243
|
-
continue;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
// transform ray into decal's local space
|
|
1247
|
-
ray3_array_apply_matrix4(local_ray, 0, query, query_offset, prop.transform_inverse);
|
|
1248
|
-
|
|
1249
|
-
if (aabb3_intersects_ray(
|
|
1250
|
-
-0.5, -0.5, -0.5,
|
|
1251
|
-
0.5, 0.5, 0.5,
|
|
1252
|
-
|
|
1253
|
-
local_ray[0], local_ray[1], local_ray[2],
|
|
1254
|
-
local_ray[3], local_ray[4], local_ray[5],
|
|
1255
|
-
)) {
|
|
1256
|
-
result[result_offset + result_count] = prop;
|
|
1257
|
-
|
|
1258
|
-
result_count++;
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
return result_count;
|
|
1264
|
-
}
|
|
1265
1205
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import {EnginePlugin} from "../../../../plugin/EnginePlugin";
|
|
2
|
-
import {Decal} from "../../../ecs/decal/v2/Decal";
|
|
3
2
|
|
|
4
3
|
export class ForwardPlusRenderingPlugin extends EnginePlugin {
|
|
5
4
|
setClusterResolution(x: number, y: number, z: number): void
|
|
6
|
-
|
|
7
|
-
queryDecalsByRay(result: Decal[], result_offset: number, query: ArrayLike<number>, query_offset?: number): number
|
|
8
5
|
}
|
|
@@ -89,15 +89,4 @@ export class ForwardPlusRenderingPlugin extends EnginePlugin {
|
|
|
89
89
|
return this.__light_manager;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
* @param {Decal[]} result
|
|
95
|
-
* @param {number} result_offset
|
|
96
|
-
* @param {number[]} query
|
|
97
|
-
* @param {number} query_offset
|
|
98
|
-
* @returns {number} number of elements added to the result
|
|
99
|
-
*/
|
|
100
|
-
queryDecalsByRay(result, result_offset, query, query_offset=0){
|
|
101
|
-
return this.__light_manager.query_decals_by_ray(result,result_offset, query,query_offset);
|
|
102
|
-
}
|
|
103
92
|
}
|