@woosh/meep-engine 3.4.0 → 3.6.0

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.
Files changed (66) hide show
  1. package/package.json +1 -1
  2. package/src/core/geom/3d/gjk/gjk_epa_penetration.d.ts +30 -3
  3. package/src/core/geom/3d/gjk/gjk_epa_penetration.d.ts.map +1 -1
  4. package/src/core/geom/3d/gjk/gjk_epa_penetration.js +83 -10
  5. package/src/core/geom/3d/gjk/mpr.d.ts +7 -1
  6. package/src/core/geom/3d/gjk/mpr.d.ts.map +1 -1
  7. package/src/core/geom/3d/gjk/mpr.js +76 -13
  8. package/src/engine/Engine.js +2 -2
  9. package/src/engine/graphics/CONTEXT_LOSS_RECOVERY_PLAN.md +1 -1
  10. package/src/engine/graphics3/GraphicsEngine3.d.ts +7 -0
  11. package/src/engine/graphics3/GraphicsEngine3.d.ts.map +1 -1
  12. package/src/engine/graphics3/GraphicsEngine3.js +9 -0
  13. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  14. package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -1
  15. package/src/engine/physics/narrowphase/narrowphase_step.js +20 -2
  16. package/src/shade/playground/skinned_blas_refit/README.md +56 -33
  17. package/src/shade/playground/skinned_blas_refit/place_character.d.ts +2 -1
  18. package/src/shade/playground/skinned_blas_refit/place_character.d.ts.map +1 -1
  19. package/src/shade/playground/skinned_blas_refit/place_character.js +2 -1
  20. package/src/shade/renderer/scene/bvh/StaticSceneBVH.js +4 -4
  21. package/src/view/graphics/{WebGLContextFailureView.d.ts → GraphicsContextFailureView.d.ts} +2 -2
  22. package/src/view/graphics/GraphicsContextFailureView.d.ts.map +1 -0
  23. package/src/view/graphics/{WebGLContextFailureView.js → GraphicsContextFailureView.js} +1 -1
  24. package/src/core/geom/3d/aabb/aabb3_from_three_geometry.d.ts +0 -7
  25. package/src/core/geom/3d/aabb/aabb3_from_three_geometry.d.ts.map +0 -1
  26. package/src/core/geom/3d/aabb/aabb3_from_three_geometry.js +0 -18
  27. package/src/core/geom/3d/aabb/aabb3_from_threejs_geometry.d.ts +0 -7
  28. package/src/core/geom/3d/aabb/aabb3_from_threejs_geometry.d.ts.map +0 -1
  29. package/src/core/geom/3d/aabb/aabb3_from_threejs_geometry.js +0 -7
  30. package/src/engine/ecs/transform/copy_three_transform.d.ts +0 -7
  31. package/src/engine/ecs/transform/copy_three_transform.d.ts.map +0 -1
  32. package/src/engine/ecs/transform/copy_three_transform.js +0 -15
  33. package/src/engine/graphics/ecs/mesh-v2/DeferredBoundsQueue.d.ts +0 -48
  34. package/src/engine/graphics/ecs/mesh-v2/DeferredBoundsQueue.d.ts.map +0 -1
  35. package/src/engine/graphics/ecs/mesh-v2/DeferredBoundsQueue.js +0 -88
  36. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.d.ts +0 -63
  37. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.d.ts.map +0 -1
  38. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +0 -314
  39. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.d.ts +0 -67
  40. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.d.ts.map +0 -1
  41. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +0 -130
  42. package/src/engine/graphics/ecs/mesh-v2/render/adapters/SGCacheKey.d.ts +0 -42
  43. package/src/engine/graphics/ecs/mesh-v2/render/adapters/SGCacheKey.d.ts.map +0 -1
  44. package/src/engine/graphics/ecs/mesh-v2/render/adapters/SGCacheKey.js +0 -71
  45. package/src/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.d.ts +0 -20
  46. package/src/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.d.ts.map +0 -1
  47. package/src/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.js +0 -123
  48. package/src/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.d.ts +0 -8
  49. package/src/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.d.ts.map +0 -1
  50. package/src/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +0 -55
  51. package/src/engine/graphics/impostors/octahedral/util/load_mesh_for_bake.d.ts +0 -12
  52. package/src/engine/graphics/impostors/octahedral/util/load_mesh_for_bake.d.ts.map +0 -1
  53. package/src/engine/graphics/impostors/octahedral/util/load_mesh_for_bake.js +0 -31
  54. package/src/engine/graphics/sh3/build_injected_shader.d.ts +0 -51
  55. package/src/engine/graphics/sh3/build_injected_shader.d.ts.map +0 -1
  56. package/src/engine/graphics/sh3/build_injected_shader.js +0 -56
  57. package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts +0 -9
  58. package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts.map +0 -1
  59. package/src/engine/graphics/sh3/fromCubeRenderTarget.js +0 -142
  60. package/src/engine/graphics/sh3/shader/visualize.frag.d.ts +0 -3
  61. package/src/engine/graphics/sh3/shader/visualize.frag.d.ts.map +0 -1
  62. package/src/engine/graphics/sh3/shader/visualize.frag.js +0 -51
  63. package/src/engine/graphics/sh3/shader/visualize.vert.d.ts +0 -3
  64. package/src/engine/graphics/sh3/shader/visualize.vert.d.ts.map +0 -1
  65. package/src/engine/graphics/sh3/shader/visualize.vert.js +0 -12
  66. package/src/view/graphics/WebGLContextFailureView.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"place_character.d.ts","sourceRoot":"","sources":["../../../../../src/shade/playground/skinned_blas_refit/place_character.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,sEAJW,MAAM,KACN,MAAM,GACJ,MAAM,CA+BlB;AAED;;;;;;;;;;;;GAYG;AACH,qCALW,MAAM,SACN,MAAM,WACN,MAAM,GACJ;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAUlC;uBAnHsB,gCAAgC"}
1
+ {"version":3,"file":"place_character.d.ts","sourceRoot":"","sources":["../../../../../src/shade/playground/skinned_blas_refit/place_character.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,sEAJW,MAAM,KACN,MAAM,GACJ,MAAM,CA+BlB;AAED;;;;;;;;;;;;GAYG;AACH,qCALW,MAAM,SACN,MAAM,WACN,MAAM,GACJ;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAUlC;uBApHsB,gCAAgC"}
@@ -21,7 +21,8 @@ import { Node3D } from "../../renderer/scene/Node3D.js";
21
21
  * actually sit under.
22
22
  *
23
23
  * Michelle is the shape that makes this concrete. Her file is one root carrying the centimetre
24
- * scale and the Z-up rotation, with the mesh node and the joint root as *siblings* beneath it:
24
+ * scale and the up-axis rotation (+90° about x, the file's Z-up into the renderer's Y-up), with the
25
+ * mesh node and the joint root as *siblings* beneath it:
25
26
  *
26
27
  * ```
27
28
  * "Character" R=(0.70711, 0, 0, 0.70711) S=(0.01, 0.01, 0.01)
@@ -390,10 +390,10 @@ export class StaticSceneBVH {
390
390
  let nearest_distance = ray.tMax;
391
391
 
392
392
  const hit_count = bvh_query_user_data_ray(
393
- bvh,
394
- bvh.root,
395
393
  scratch_instance_hits,
396
394
  0,
395
+ bvh,
396
+ bvh.root,
397
397
  ray.origin_x, ray.origin_y, ray.origin_z,
398
398
  ray.direction_x, ray.direction_y, ray.direction_z
399
399
  );
@@ -501,10 +501,10 @@ export class StaticSceneBVH {
501
501
  const bvh = this.instance_bvh;
502
502
 
503
503
  const hit_count = bvh_query_user_data_ray(
504
- bvh,
505
- bvh.root,
506
504
  scratch_instance_hits,
507
505
  0,
506
+ bvh,
507
+ bvh.root,
508
508
  ray.origin_x, ray.origin_y, ray.origin_z,
509
509
  ray.direction_x, ray.direction_y, ray.direction_z
510
510
  );
@@ -6,7 +6,7 @@
6
6
  * case where the renderer is dead, which is not a good moment to depend on the localization pipeline
7
7
  * having the keys; an application that has them should pass localized strings in.
8
8
  */
9
- export class WebGLContextFailureView extends EmptyView {
9
+ export class GraphicsContextFailureView extends EmptyView {
10
10
  /**
11
11
  * @param {string} [title]
12
12
  * @param {string} [text]
@@ -16,4 +16,4 @@ export class WebGLContextFailureView extends EmptyView {
16
16
  constructor({ title, text, action_label, action }?: string);
17
17
  }
18
18
  import EmptyView from "../elements/EmptyView.js";
19
- //# sourceMappingURL=WebGLContextFailureView.d.ts.map
19
+ //# sourceMappingURL=GraphicsContextFailureView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphicsContextFailureView.d.ts","sourceRoot":"","sources":["../../../../src/view/graphics/GraphicsContextFailureView.js"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH;IACI;;;;;OAKG;IACH,oDALW,MAAM,EA4DhB;CACJ;sBA1EqB,0BAA0B"}
@@ -10,7 +10,7 @@ import LabelView from "../common/LabelView.js";
10
10
  * case where the renderer is dead, which is not a good moment to depend on the localization pipeline
11
11
  * having the keys; an application that has them should pass localized strings in.
12
12
  */
13
- export class WebGLContextFailureView extends EmptyView {
13
+ export class GraphicsContextFailureView extends EmptyView {
14
14
  /**
15
15
  * @param {string} [title]
16
16
  * @param {string} [text]
@@ -1,7 +0,0 @@
1
- /**
2
- *
3
- * @param {number[]|ArrayLike<number>|Float32Array} result
4
- * @param {BufferGeometry} geometry
5
- */
6
- export function aabb3_from_three_geometry(result: number[] | ArrayLike<number> | Float32Array, geometry: BufferGeometry): void;
7
- //# sourceMappingURL=aabb3_from_three_geometry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aabb3_from_three_geometry.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/aabb/aabb3_from_three_geometry.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,kDAHW,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,kCAYjD"}
@@ -1,18 +0,0 @@
1
- import { assert } from "../../../assert.js";
2
- import { aabb3_from_min_max } from "./aabb3_from_min_max.js";
3
-
4
- /**
5
- *
6
- * @param {number[]|ArrayLike<number>|Float32Array} result
7
- * @param {BufferGeometry} geometry
8
- */
9
- export function aabb3_from_three_geometry(result, geometry) {
10
- const gbb = geometry.boundingBox;
11
-
12
- assert.notNull(gbb, 'boundingBox');
13
-
14
- const min = gbb.min;
15
- const max = gbb.max;
16
-
17
- aabb3_from_min_max(result, min, max);
18
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * @deprecated Renamed to {@link aabb3_from_three_geometry}. This re-export is kept for backward
3
- * compatibility (meep is a library; old names are public surface).
4
- */
5
- export const aabb3_from_threejs_geometry: typeof aabb3_from_three_geometry;
6
- import { aabb3_from_three_geometry } from "./aabb3_from_three_geometry.js";
7
- //# sourceMappingURL=aabb3_from_threejs_geometry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aabb3_from_threejs_geometry.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/aabb/aabb3_from_threejs_geometry.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH,2EAAqE;0CAN3B,gCAAgC"}
@@ -1,7 +0,0 @@
1
- import { aabb3_from_three_geometry } from "./aabb3_from_three_geometry.js";
2
-
3
- /**
4
- * @deprecated Renamed to {@link aabb3_from_three_geometry}. This re-export is kept for backward
5
- * compatibility (meep is a library; old names are public surface).
6
- */
7
- export const aabb3_from_threejs_geometry = aabb3_from_three_geometry;
@@ -1,7 +0,0 @@
1
- /**
2
- *
3
- * @param {Transform} transform
4
- * @param {THREE.Object3D} three_object
5
- */
6
- export function copy_three_transform(transform: Transform, three_object: THREE.Object3D): void;
7
- //# sourceMappingURL=copy_three_transform.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"copy_three_transform.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/transform/copy_three_transform.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,+FASC"}
@@ -1,15 +0,0 @@
1
- /**
2
- *
3
- * @param {Transform} transform
4
- * @param {THREE.Object3D} three_object
5
- */
6
- export function copy_three_transform(transform, three_object) {
7
-
8
- // copy object transform
9
- transform.position.copy(three_object.position);
10
- transform.scale.copy(three_object.scale);
11
- transform.rotation.copy(three_object.quaternion);
12
-
13
- //
14
- transform.matrix.set(three_object.matrix.elements);
15
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Collects {@link ShadedGeometry} components whose bounding box has gone stale under
3
- * {@link ShadedGeometryFlags.DeferredBoundsUpdate}, until the owner of the BVH is ready
4
- * to take the updates.
5
- *
6
- * WHY THIS EXISTS
7
- *
8
- * A {@link Transform} signals `position`, `rotation` and `scale` separately, so one
9
- * logical move produces several change notifications: two when a caller sets position
10
- * and rotation, three when the transform is written as a matrix (which is what
11
- * {@link TransformAttachmentSystem} does for every entity in a hierarchy, and what
12
- * `Transform.copy` does). Updating bounds on each of those recomputes the same box and
13
- * walks the same path to the BVH root several times over. Parking the component here
14
- * instead collapses the batch into one update per component per flush.
15
- *
16
- * Entries are appended without a membership test; {@link ShadedGeometry} carries the
17
- * "already queued" bit so enqueueing stays O(1) and a component appears at most once.
18
- */
19
- export class DeferredBoundsQueue {
20
- /**
21
- * Number of components waiting for their bounds to be applied.
22
- * @returns {number}
23
- */
24
- get size(): number;
25
- /**
26
- * Park a component whose bounds have gone stale.
27
- *
28
- * The caller must not add a component that is already queued — see
29
- * {@link ShadedGeometry.updateTransform}, which owns that bit.
30
- * @param {ShadedGeometry} sg
31
- * @returns {void}
32
- */
33
- add(sg: ShadedGeometry): void;
34
- /**
35
- * Apply every parked update, leaving the BVH consistent with the current transforms.
36
- *
37
- * Components that were unlinked while queued, or whose bounds were already settled by
38
- * a read, are skipped.
39
- *
40
- * Must not be re-entered: nothing reached from here writes to a {@link Transform},
41
- * so no component can go dirty while the batch is being applied.
42
- * @returns {number} how many components actually had an update applied, which is a
43
- * useful profiling signal — it is the number of BVH refits the batch cost
44
- */
45
- flush(): number;
46
- #private;
47
- }
48
- //# sourceMappingURL=DeferredBoundsQueue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeferredBoundsQueue.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/ecs/mesh-v2/DeferredBoundsQueue.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH;IAaI;;;OAGG;IACH,mBAEC;IAED;;;;;;;OAOG;IACH,yBAFa,IAAI,CAIhB;IAED;;;;;;;;;;OAUG;IACH,SAHa,MAAM,CA2BlB;;CACJ"}
@@ -1,88 +0,0 @@
1
- /**
2
- * Collects {@link ShadedGeometry} components whose bounding box has gone stale under
3
- * {@link ShadedGeometryFlags.DeferredBoundsUpdate}, until the owner of the BVH is ready
4
- * to take the updates.
5
- *
6
- * WHY THIS EXISTS
7
- *
8
- * A {@link Transform} signals `position`, `rotation` and `scale` separately, so one
9
- * logical move produces several change notifications: two when a caller sets position
10
- * and rotation, three when the transform is written as a matrix (which is what
11
- * {@link TransformAttachmentSystem} does for every entity in a hierarchy, and what
12
- * `Transform.copy` does). Updating bounds on each of those recomputes the same box and
13
- * walks the same path to the BVH root several times over. Parking the component here
14
- * instead collapses the batch into one update per component per flush.
15
- *
16
- * Entries are appended without a membership test; {@link ShadedGeometry} carries the
17
- * "already queued" bit so enqueueing stays O(1) and a component appears at most once.
18
- */
19
- export class DeferredBoundsQueue {
20
- /**
21
- * Retained between flushes and overwritten in place rather than re-allocated.
22
- * Only the first {@link #size} entries are live.
23
- * @type {ShadedGeometry[]}
24
- */
25
- #items = [];
26
-
27
- /**
28
- * @type {number}
29
- */
30
- #size = 0;
31
-
32
- /**
33
- * Number of components waiting for their bounds to be applied.
34
- * @returns {number}
35
- */
36
- get size() {
37
- return this.#size;
38
- }
39
-
40
- /**
41
- * Park a component whose bounds have gone stale.
42
- *
43
- * The caller must not add a component that is already queued — see
44
- * {@link ShadedGeometry.updateTransform}, which owns that bit.
45
- * @param {ShadedGeometry} sg
46
- * @returns {void}
47
- */
48
- add(sg) {
49
- this.#items[this.#size++] = sg;
50
- }
51
-
52
- /**
53
- * Apply every parked update, leaving the BVH consistent with the current transforms.
54
- *
55
- * Components that were unlinked while queued, or whose bounds were already settled by
56
- * a read, are skipped.
57
- *
58
- * Must not be re-entered: nothing reached from here writes to a {@link Transform},
59
- * so no component can go dirty while the batch is being applied.
60
- * @returns {number} how many components actually had an update applied, which is a
61
- * useful profiling signal — it is the number of BVH refits the batch cost
62
- */
63
- flush() {
64
- const items = this.#items;
65
- const size = this.#size;
66
-
67
- let applied = 0;
68
-
69
- for (let i = 0; i < size; i++) {
70
- if (items[i].applyDeferredBoundsUpdate()) {
71
- applied++;
72
- }
73
- }
74
-
75
- // Drop the references so components unlinked while queued are not held alive
76
- // until their slot happens to be overwritten — after a teardown the slots may
77
- // never be reused, and each entry retains a geometry and a material.
78
- //
79
- // Done in one sweep rather than per entry inside the loop above: clearing each
80
- // slot as it was consumed measured ~25% slower per tick on a 2000-mover scene,
81
- // the store into the object array carrying a GC write barrier each time.
82
- items.fill(null, 0, size);
83
-
84
- this.#size = 0;
85
-
86
- return applied;
87
- }
88
- }
@@ -1,63 +0,0 @@
1
- export class SGMeshSystem extends System<any> {
2
- /**
3
- *
4
- * @param {Engine} engine
5
- */
6
- constructor(engine: Engine);
7
- dependencies: (typeof Transform | typeof SGMesh)[];
8
- components_used: (ResourceAccessSpecification<typeof Transform> | ResourceAccessSpecification<typeof TransformAttachment> | ResourceAccessSpecification<typeof SGMesh> | ResourceAccessSpecification<typeof ShadedGeometry>)[];
9
- /**
10
- *
11
- * @type {number[]}
12
- * @private
13
- */
14
- private __wait_queue;
15
- /**
16
- *
17
- * @type {number}
18
- * @private
19
- */
20
- private __wait_queue_process_index;
21
- /**
22
- *
23
- * @type {Engine}
24
- * @private
25
- */
26
- private __engine;
27
- /**
28
- *
29
- * @type {AssetManager}
30
- * @private
31
- */
32
- private __assetManager;
33
- startup(em: any): Promise<void>;
34
- /**
35
- *
36
- * @param {number} entity
37
- * @param {SGMesh} mesh
38
- * @param {Transform} transform
39
- */
40
- process(entity: number, mesh: SGMesh, transform: Transform): Promise<void>;
41
- /**
42
- *
43
- * @param {SGMesh} mesh
44
- * @param {Transform} transform
45
- * @param {number} entity
46
- */
47
- link(mesh: SGMesh, transform: Transform, entity: number): void;
48
- /**
49
- *
50
- * @param {SGMesh} mesh
51
- * @param {Transform} transform
52
- * @param {number} entity
53
- */
54
- unlink(mesh: SGMesh, transform: Transform, entity: number): void;
55
- update(time_delta: any): void;
56
- }
57
- import { System } from "../../../../ecs/System.js";
58
- import { Transform } from "../../../../ecs/transform/Transform.js";
59
- import { SGMesh } from "./SGMesh.js";
60
- import { ResourceAccessSpecification } from "../../../../../core/model/ResourceAccessSpecification.js";
61
- import { TransformAttachment } from "../../../../ecs/transform-attachment/TransformAttachment.js";
62
- import { ShadedGeometry } from "../ShadedGeometry.js";
63
- //# sourceMappingURL=SGMeshSystem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SGMeshSystem.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js"],"names":[],"mappings":"AA8CA;IAuBI;;;OAGG;IACH,4BAgBC;IA1CD,mDAAmC;IACnC,+NAKE;IAEF;;;;OAIG;IACH,qBAAkB;IAElB;;;;OAIG;IACH,mCAA+B;IAS3B;;;;OAIG;IACH,iBAAsB;IAEtB;;;;OAIG;IACH,uBAAyC;IAG7C,gCAMC;IAED;;;;;OAKG;IACH,gBAJW,MAAM,QACN,MAAM,aACN,SAAS,iBA8GnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,aACN,SAAS,UACT,MAAM,QAiBhB;IAED;;;;;OAKG;IACH,aAJW,MAAM,aACN,SAAS,UACT,MAAM,QAehB;IAED,8BAqDC;CACJ;uBAnTsB,2BAA2B;0BAGxB,wCAAwC;uBAK3C,aAAa;4CAZQ,0DAA0D;oCAKlE,6DAA6D;+BAIlE,sBAAsB"}
@@ -1,314 +0,0 @@
1
- import { min2 } from "../../../../../core/math/min2.js";
2
- import { ResourceAccessKind } from "../../../../../core/model/ResourceAccessKind.js";
3
- import { ResourceAccessSpecification } from "../../../../../core/model/ResourceAccessSpecification.js";
4
- import { STATIC_ASSET_CACHE } from "../../../../asset/STATIC_ASSET_CACHE.js";
5
- import { EntityNode } from "../../../../ecs/parent/EntityNode.js";
6
- import { ParentEntity } from "../../../../ecs/parent/ParentEntity.js";
7
- import { System } from "../../../../ecs/System.js";
8
- import { TransformAttachment } from "../../../../ecs/transform-attachment/TransformAttachment.js";
9
- import { TransformAttachmentSystem } from "../../../../ecs/transform-attachment/TransformAttachmentSystem.js";
10
- import { Transform } from "../../../../ecs/transform/Transform.js";
11
- import { assetTypeByPath } from "../../mesh/assetTypeByPath.js";
12
- import { ShadedGeometry } from "../ShadedGeometry.js";
13
- import { ShadedGeometryFlags } from "../ShadedGeometryFlags.js";
14
- import { three_object_to_entity_composition } from "../three_object_to_entity_composition.js";
15
- import { SGMesh } from "./SGMesh.js";
16
- import { SGMeshEvents } from "./SGMeshEvents.js";
17
-
18
-
19
- /**
20
- * @readonly
21
- * @type {number}
22
- */
23
- const MAX_CYCLE_COUNT = 128;
24
-
25
- /**
26
- * In milliseconds
27
- * @readonly
28
- * @type {number}
29
- */
30
- const MAX_CYCLE_TIME = 40;
31
-
32
-
33
- /**
34
- *
35
- * @param {string} url
36
- * @param {AssetManager} assetManager
37
- * @returns {Promise<THREE.Object3D>}
38
- */
39
- async function getAsset(url, assetManager) {
40
-
41
- const assetType = assetTypeByPath(url);
42
-
43
- const asset = await assetManager.promise(url, assetType);
44
- }
45
-
46
-
47
- export class SGMeshSystem extends System {
48
- dependencies = [SGMesh, Transform];
49
- components_used = [
50
- ResourceAccessSpecification.from(SGMesh, ResourceAccessKind.Read | ResourceAccessKind.Write),
51
- ResourceAccessSpecification.from(Transform, ResourceAccessKind.Read),
52
- ResourceAccessSpecification.from(ShadedGeometry, ResourceAccessKind.Create),
53
- ResourceAccessSpecification.from(TransformAttachment, ResourceAccessKind.Create),
54
- ];
55
-
56
- /**
57
- *
58
- * @type {number[]}
59
- * @private
60
- */
61
- __wait_queue = [];
62
-
63
- /**
64
- *
65
- * @type {number}
66
- * @private
67
- */
68
- __wait_queue_process_index = 0;
69
-
70
- /**
71
- *
72
- * @param {Engine} engine
73
- */
74
- constructor(engine) {
75
- super();
76
-
77
- /**
78
- *
79
- * @type {Engine}
80
- * @private
81
- */
82
- this.__engine = engine;
83
-
84
- /**
85
- *
86
- * @type {AssetManager}
87
- * @private
88
- */
89
- this.__assetManager = engine.assetManager;
90
- }
91
-
92
- async startup(em) {
93
-
94
- if (!em.hasSystem(TransformAttachmentSystem)) {
95
- await em.addSystem(new TransformAttachmentSystem());
96
- }
97
-
98
- }
99
-
100
- /**
101
- *
102
- * @param {number} entity
103
- * @param {SGMesh} mesh
104
- * @param {Transform} transform
105
- */
106
- async process(entity, mesh, transform) {
107
- const am = this.__assetManager;
108
- const ecd = this.entityManager.dataset;
109
-
110
- const assetType = assetTypeByPath(mesh.url);
111
-
112
- let asset;
113
-
114
- try {
115
- asset = await am.promise(mesh.url, assetType);
116
- } catch (e) {
117
- ecd.sendEvent(entity, SGMeshEvents.AssetLoadFailed);
118
- return;
119
- }
120
-
121
- if (!ecd.entityExists(entity)) {
122
- // entity no longer exists
123
- return;
124
- }
125
-
126
- if (ecd.getComponent(entity, SGMesh) !== mesh) {
127
- // mesh has changed
128
- return;
129
- }
130
-
131
- if (asset.boundingBox !== undefined) {
132
- mesh.__initial_bounds.copy(asset.boundingBox);
133
-
134
- if (asset.has_root_transform) {
135
- // TODO potentially move this to the GLTF Asset Loader to skip matrix operations here
136
- mesh.__initial_bounds.applyMatrix4(asset.root_transform.matrix);
137
- }
138
-
139
- } else {
140
- console.error(`No bounds for asset: ${asset.description}`);
141
- }
142
-
143
- let object;
144
- const cached_object = STATIC_ASSET_CACHE.get(asset);
145
-
146
- if (cached_object !== null) {
147
- object = cached_object;
148
- } else {
149
- object = asset.create();
150
-
151
- STATIC_ASSET_CACHE.set(asset, object);
152
- }
153
-
154
- let entity_node = three_object_to_entity_composition(object);
155
-
156
- if (asset.has_root_transform) {
157
- // apply root transform
158
-
159
- const new_root = new EntityNode();
160
-
161
- new_root.entity.add(new Transform());
162
-
163
- entity_node.transform.copy(asset.root_transform);
164
-
165
- new_root.addChild(entity_node);
166
-
167
- entity_node = new_root;
168
- }
169
-
170
- // attach parent entity to link hierarchy to this entity
171
- entity_node.entity.add(ParentEntity.from(entity));
172
-
173
- mesh.__node = entity_node;
174
-
175
- function copy_transform() {
176
- entity_node.transform.copy(transform);
177
- }
178
-
179
- copy_transform();
180
-
181
- entity_node.build(ecd);
182
-
183
- transform.subscribe(copy_transform);
184
-
185
- entity_node.on.destroyed.addOne(() => {
186
-
187
- transform.unsubscribe(copy_transform);
188
-
189
- });
190
-
191
- const material_override = mesh.materialOverride;
192
-
193
- // apply flags to the hierarchy
194
- entity_node.traverse(node => {
195
- /**
196
- *
197
- * @type {ShadedGeometry|null}
198
- */
199
- const sg = node.entity.getComponent(ShadedGeometry);
200
- if (sg === null) {
201
- return;
202
- }
203
-
204
- sg.writeFlag(ShadedGeometryFlags.CastShadow, mesh.castShadow);
205
- sg.writeFlag(ShadedGeometryFlags.ReceiveShadow, mesh.receiveShadow);
206
-
207
- if (material_override !== null) {
208
- sg.material = material_override;
209
- }
210
- });
211
-
212
-
213
- ecd.sendEvent(entity, SGMeshEvents.AssetLoaded);
214
- }
215
-
216
- /**
217
- *
218
- * @param {SGMesh} mesh
219
- * @param {Transform} transform
220
- * @param {number} entity
221
- */
222
- link(mesh, transform, entity) {
223
- const p = transform.position;
224
-
225
- // set initial bounds to single point
226
- mesh.__initial_bounds.setBounds(
227
- p.x, p.y, p.z,
228
- p.x, p.y, p.z,
229
- );
230
-
231
- if (mesh.url === null) {
232
- this.__wait_queue.push(entity);
233
- return;
234
- }
235
-
236
- this.process(entity, mesh, transform);
237
- }
238
-
239
- /**
240
- *
241
- * @param {SGMesh} mesh
242
- * @param {Transform} transform
243
- * @param {number} entity
244
- */
245
- unlink(mesh, transform, entity) {
246
- if (mesh.__node !== null) {
247
- mesh.__node.destroy();
248
-
249
- mesh.__node = null;
250
- }
251
-
252
- // check the queue
253
- const i = this.__wait_queue.indexOf(entity);
254
-
255
- if (i !== -1) {
256
- this.__wait_queue.splice(i, 1);
257
- }
258
- }
259
-
260
- update(time_delta) {
261
-
262
- const entityManager = this.entityManager;
263
- const dataset = entityManager.dataset;
264
-
265
- if (dataset === null) {
266
- return;
267
- }
268
-
269
- const waiting = this.__wait_queue;
270
-
271
- let l = waiting.length;
272
-
273
- if (l > 0) {
274
-
275
- const time_0 = performance.now();
276
-
277
- let pointer = this.__wait_queue_process_index;
278
-
279
- const pointer_limit = pointer + min2(l, MAX_CYCLE_COUNT);
280
-
281
- while (pointer < pointer_limit) {
282
-
283
- const index = pointer % l;
284
- pointer++;
285
-
286
- const entity = waiting[index];
287
-
288
- const mesh = dataset.getComponent(entity, SGMesh);
289
-
290
- if (mesh.url === null) {
291
- // no URL yet
292
- continue;
293
- }
294
-
295
- waiting.splice(index, 1);
296
-
297
- const transform = dataset.getComponent(entity, Transform);
298
-
299
- this.process(entity, mesh, transform);
300
-
301
- const time_1 = performance.now();
302
-
303
- if ((time_1 - time_0) > MAX_CYCLE_TIME) {
304
- // too much time has passed
305
- break;
306
- }
307
-
308
- }
309
-
310
- this.__wait_queue_process_index = pointer;
311
-
312
- }
313
- }
314
- }