@woosh/meep-engine 2.47.35 → 2.47.36

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": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.47.35",
8
+ "version": "2.47.36",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,65 @@
1
+ import { aabb3_build_corners } from "./aabb3_build_corners.js";
2
+ import { aabb3_matrix4_project_by_corners } from "./aabb3_matrix4_project_by_corners.js";
3
+ import { v3_distance_above_plane } from "../../v3_distance_above_plane.js";
4
+
5
+ const scratch_corners = new Float32Array(24);
6
+
7
+ /**
8
+ *
9
+ * 2,0,or -2; 2: above, -2 : below, 0 : intersects plane
10
+ * @param {number} x0
11
+ * @param {number} y0
12
+ * @param {number} z0
13
+ * @param {number} x1
14
+ * @param {number} y1
15
+ * @param {number} z1
16
+ * @param {number} plane_normal_x
17
+ * @param {number} plane_normal_y
18
+ * @param {number} plane_normal_z
19
+ * @param {number} plane_offset
20
+ * @param {number[]|Float32Array} transform_matrix
21
+ * @returns {number}
22
+ */
23
+ export function aabb3_transformed_compute_plane_side(
24
+ x0, y0, z0, x1, y1, z1,
25
+ plane_normal_x, plane_normal_y, plane_normal_z, plane_offset,
26
+ transform_matrix
27
+ ) {
28
+
29
+ aabb3_build_corners(
30
+ scratch_corners, 0,
31
+ x0, y0, z0, x1, y1, z1
32
+ );
33
+
34
+ aabb3_matrix4_project_by_corners(
35
+ scratch_corners,
36
+ scratch_corners,
37
+ transform_matrix
38
+ );
39
+
40
+ let has_above = false, has_below = false;
41
+
42
+ for (let i = 0; i < 8; i++) {
43
+ const i3 = i * 3;
44
+ const x = scratch_corners[i3];
45
+ const y = scratch_corners[i3 + 1];
46
+ const z = scratch_corners[i3 + 2];
47
+
48
+ if (v3_distance_above_plane(x, y, z, plane_normal_x, plane_normal_y, plane_normal_z, plane_offset)) {
49
+ has_above = true;
50
+ } else {
51
+ has_below = true;
52
+ }
53
+ }
54
+
55
+ let result = 0;
56
+
57
+ if (has_above) {
58
+ result += 2;
59
+ }
60
+ if (has_below) {
61
+ result -= 2;
62
+ }
63
+
64
+ return result;
65
+ }
@@ -14,4 +14,7 @@ export class FPDecalSystem extends System<Decal, Transform> {
14
14
  filter_function?: (entity: number, mesh: Decal) => boolean,
15
15
  filter_function_context?: any
16
16
  ): { entity: number, component: Decal, contact: SurfacePoint3 }[]
17
+
18
+
19
+ queryOverlapFrustum(result: number[], result_offset: number, planes: number[]): number
17
20
  }
@@ -23,6 +23,12 @@ import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
23
23
  import { EBBVHLeafProxy } from "../../../../../core/bvh2/bvh3/EBBVHLeafProxy.js";
24
24
  import { aabb3_matrix4_project } from "../../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
25
25
  import { aabb3_raycast } from "../../../../../core/geom/3d/aabb/aabb3_raycast.js";
26
+ import {
27
+ bvh_query_user_data_overlaps_frustum
28
+ } from "../../../../../core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js";
29
+ import {
30
+ aabb3_transformed_compute_plane_side
31
+ } from "../../../../../core/geom/3d/aabb/aabb3_transformed_compute_plane_side.js";
26
32
 
27
33
  const placeholder_texture = Sampler2D.uint8(4, 1, 1);
28
34
  placeholder_texture.data.fill(255);
@@ -289,6 +295,72 @@ export class FPDecalSystem extends AbstractContextSystem {
289
295
  super.shutdown(em, ready_callback, error_callback);
290
296
  }
291
297
 
298
+ /**
299
+ *
300
+ * @param {number[]} result entity IDs
301
+ * @param {number} result_offset
302
+ * @param {number[]} planes
303
+ * @returns {number} number of results
304
+ */
305
+ queryOverlapFrustum(result, result_offset, planes) {
306
+ const ecd = this.entityManager.dataset;
307
+
308
+ if (ecd === null) {
309
+ return 0;
310
+ }
311
+
312
+ const entities = [];
313
+ const rough_count = bvh_query_user_data_overlaps_frustum(
314
+ entities, 0,
315
+ this.bvh,
316
+ planes
317
+ );
318
+
319
+ let result_cursor = result_offset;
320
+
321
+ loop_0: for (let i = 0; i < rough_count; i++) {
322
+
323
+ const entity = entities[i];
324
+
325
+ /**
326
+ *
327
+ * @type {Transform}
328
+ */
329
+ const transform = ecd.getComponent(entity, Transform);
330
+
331
+ if (transform === undefined) {
332
+ // this shouldn't happen either
333
+ continue;
334
+ }
335
+
336
+ for (let j = 0; j < 6; j++) {
337
+ // test true box against each plane
338
+ const plane_address = j * 4;
339
+
340
+ const plane_x = planes[plane_address]
341
+ const plane_y = planes[plane_address + 1]
342
+ const plane_z = planes[plane_address + 2]
343
+ const plane_offset = planes[plane_address + 3]
344
+
345
+ const side = aabb3_transformed_compute_plane_side(
346
+ -0.5, -0.5, -0.5,
347
+ 0.5, 0.5, 0.5,
348
+ plane_x, plane_y, plane_z, plane_offset,
349
+ transform.matrix
350
+ );
351
+
352
+ if (side < 0) {
353
+ // completely outside
354
+ continue loop_0;
355
+ }
356
+ }
357
+
358
+ result[result_cursor++] = entity;
359
+ }
360
+
361
+ return result_cursor - result_offset;
362
+ }
363
+
292
364
  /**
293
365
  *
294
366
  * @param {number} origin_x
@@ -345,6 +417,10 @@ export class FPDecalSystem extends AbstractContextSystem {
345
417
  continue;
346
418
  }
347
419
 
420
+ /**
421
+ *
422
+ * @type {Transform}
423
+ */
348
424
  const transform = ecd.getComponent(entity, Transform);
349
425
 
350
426
  if (transform === undefined) {