@woosh/meep-engine 2.65.0 → 2.66.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 (56) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +52474 -53800
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +52474 -53800
  5. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +4 -10
  6. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +7 -7
  7. package/editor/tools/SelectionTool.js +6 -95
  8. package/package.json +1 -1
  9. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +118 -113
  10. package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
  11. package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +98 -0
  12. package/src/core/bvh2/bvh3/BVH.d.ts +1 -1
  13. package/src/core/bvh2/bvh3/BvhClient.d.ts +11 -0
  14. package/src/core/bvh2/bvh3/BvhClient.js +19 -0
  15. package/src/core/collection/array/array_copy.js +6 -0
  16. package/src/core/geom/3d/aabb/aabb3_array_combine.js +17 -8
  17. package/src/core/geom/3d/aabb/aabb3_array_intersects_ray.js +5 -2
  18. package/src/core/geom/3d/aabb/aabb3_array_set.js +25 -0
  19. package/src/core/geom/3d/aabb/aabb3_compute_half_surface_area.js +3 -0
  20. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +8 -1
  21. package/src/engine/EngineHarness.js +23 -25
  22. package/src/engine/ecs/renderable/RenderSystem.js +44 -32
  23. package/src/engine/ecs/renderable/Renderable.d.ts +2 -2
  24. package/src/engine/ecs/renderable/Renderable.js +12 -11
  25. package/src/engine/ecs/terrain/ecs/Terrain.js +83 -87
  26. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +106 -57
  27. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +5 -2
  28. package/src/engine/ecs/terrain/tiles/TerrainTile.js +122 -67
  29. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +162 -146
  30. package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +16 -5
  31. package/src/engine/graphics/camera/testClippingPlaneComputation.js +3 -6
  32. package/src/engine/graphics/debug/VisualSymbolLine.js +1 -0
  33. package/src/engine/graphics/ecs/camera/CameraSystem.js +9 -9
  34. package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +3 -23
  35. package/src/engine/graphics/ecs/light/LightSystem.js +12 -48
  36. package/src/engine/graphics/ecs/mesh/MeshSystem.js +9 -31
  37. package/src/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +3 -43
  38. package/src/engine/graphics/ecs/trail2d/Trail2D.js +105 -106
  39. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +60 -61
  40. package/src/engine/graphics/ecs/trail2d/makeGradientTrail.js +3 -3
  41. package/src/engine/graphics/ecs/water/WATER_SIZE.js +1 -0
  42. package/src/engine/graphics/ecs/water/Water.js +84 -42
  43. package/src/engine/graphics/ecs/water/WaterSystem.js +53 -105
  44. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +13 -7
  45. package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +58 -0
  46. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +32 -62
  47. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1 -1
  48. package/src/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +8 -11
  49. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +21 -19
  50. package/src/engine/graphics/render/layers/RenderLayer.d.ts +8 -2
  51. package/src/engine/graphics/render/layers/RenderLayer.js +7 -65
  52. package/src/engine/graphics/render/make_bvh_visibility_builder.js +64 -0
  53. package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +4 -4
  54. package/src/engine/graphics/trail/x/RibbonX.js +26 -5
  55. package/src/core/bvh2/binary/tiny/TinyBVH.js +0 -221
  56. package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +0 -138
@@ -3,23 +3,22 @@
3
3
  */
4
4
 
5
5
 
6
+ import { assert } from "../../../../core/assert.js";
7
+ import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
8
+ import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
9
+ import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
10
+ import { AbstractContextSystem } from "../../../ecs/system/AbstractContextSystem.js";
6
11
  import { Transform } from '../../../ecs/transform/Transform.js';
7
- import { Light } from './Light.js';
12
+ import { ForwardPlusRenderingPlugin } from "../../render/forward_plus/plugin/ForwardPlusRenderingPlugin.js";
8
13
  import { Camera } from '../camera/Camera.js';
9
14
 
10
15
  import FrustumProjector from '../camera/FrustumProjector.js';
11
- import { LightType } from "./LightType.js";
12
- import { CameraClippingPlaneComputer } from "../camera/CameraClippingPlaneComputer.js";
13
- import { assert } from "../../../../core/assert.js";
14
- import { ForwardPlusRenderingPlugin } from "../../render/forward_plus/plugin/ForwardPlusRenderingPlugin.js";
15
- import { ThreeLightCache } from "./three/ThreeLightCache.js";
16
- import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
17
- import { ShadowManager } from "./shadow/ShadowManager.js";
18
- import { AbstractContextSystem } from "../../../ecs/system/AbstractContextSystem.js";
16
+ import { Light } from './Light.js';
19
17
  import { LightContext } from "./LightContext.js";
18
+ import { LightType } from "./LightType.js";
20
19
  import { setShadowCameraDimensionsDiscrete } from "./shadow/setShadowCameraDimensionsDiscrete.js";
21
- import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
22
- import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
20
+ import { ShadowManager } from "./shadow/ShadowManager.js";
21
+ import { ThreeLightCache } from "./three/ThreeLightCache.js";
23
22
 
24
23
  class LightSystem extends AbstractContextSystem {
25
24
  /**
@@ -265,8 +264,6 @@ class LightSystem extends AbstractContextSystem {
265
264
  }
266
265
  }
267
266
 
268
- const cameraClippingPlaneComputer = new CameraClippingPlaneComputer();
269
-
270
267
  const scratch_aabb3 = new AABB3();
271
268
 
272
269
  /**
@@ -278,10 +275,6 @@ const scratch_aabb3 = new AABB3();
278
275
  */
279
276
  function updateShadowMap(camera, light, graphics) {
280
277
 
281
- /**
282
- * @type {RenderLayerManager}
283
- */
284
- const layers = graphics.layers;
285
278
 
286
279
  // Fit shadow camera's ortho frustum to camera frustum
287
280
  const shadow = light.shadow;
@@ -310,43 +303,14 @@ function updateShadowMap(camera, light, graphics) {
310
303
 
311
304
  // collect all visible objects
312
305
 
313
- cameraClippingPlaneComputer.hysteresis = 0.33;
314
-
315
- cameraClippingPlaneComputer.camera = shadowCamera;
316
- cameraClippingPlaneComputer.layers = layers;
317
-
318
- cameraClippingPlaneComputer.compute();
319
-
320
- shadowCamera.near = cameraClippingPlaneComputer.near;
321
- shadowCamera.far = cameraClippingPlaneComputer.far;
306
+ shadowCamera.near = 0.1;
307
+ shadowCamera.far = 100;
322
308
 
323
309
  shadowCamera.updateProjectionMatrix();
324
310
 
325
311
  // small bias to prevent shadow acne
326
312
  shadow.bias = -0.0001;
327
313
 
328
- //
329
- // const frustum = new Frustum();
330
- // frustumFromCamera(shadowCamera, frustum);
331
- // visitor.setFrustums([frustum]);
332
- // visitor.collector = collector;
333
- //
334
- // shadow_scene.children = [];
335
- //
336
- // const layers_list = layers.layers;
337
- // const layer_count = layers_list.length;
338
- //
339
- // for (let i = 0; i < layer_count; i++) {
340
- // const renderLayer = layers_list.get(i);
341
- //
342
- // collector.callbackContext = shadow_scene.children;
343
- // collector.callback = Array.prototype.push;
344
- // collector.reader = renderLayer.extractRenderable;
345
- //
346
- // traverseBinaryNodeUsingVisitor(renderLayer.bvh, visitor);
347
- // }
348
- //
349
- // graphics.shadowmap_renderer.update(graphics.renderer, light.shadow, shadow_scene, camera, light);
350
314
  }
351
315
 
352
316
  export default LightSystem;
@@ -6,9 +6,6 @@
6
6
  import { BoxBufferGeometry, MeshLambertMaterial } from "three";
7
7
  import { assert } from "../../../../core/assert.js";
8
8
  import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
9
- import {
10
- bvh_query_user_data_overlaps_frustum
11
- } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js";
12
9
  import { SignalBinding } from "../../../../core/events/signal/SignalBinding.js";
13
10
 
14
11
  import Vector3 from "../../../../core/geom/Vector3.js";
@@ -17,6 +14,7 @@ import { ResourceAccessSpecification } from "../../../../core/model/ResourceAcce
17
14
  import { GLTFAssetLoader } from "../../../asset/loaders/GLTFAssetLoader.js";
18
15
  import { System } from "../../../ecs/System.js";
19
16
  import { Transform } from "../../../ecs/transform/Transform.js";
17
+ import { make_bvh_visibility_builder } from "../../render/make_bvh_visibility_builder.js";
20
18
 
21
19
  import checkerTexture from "../../texture/CheckersTexture.js";
22
20
 
@@ -34,8 +32,6 @@ const PLACEHOLDER_TEXTURE = checkerTexture.create();
34
32
 
35
33
  const PLACEHOLDER_MATERIAL = new MeshLambertMaterial({ map: PLACEHOLDER_TEXTURE });
36
34
 
37
- const scratch_array = [];
38
-
39
35
  export class MeshSystem extends System {
40
36
  /**
41
37
  *
@@ -152,37 +148,19 @@ export class MeshSystem extends System {
152
148
  const graphics = this.graphics;
153
149
  this.renderLayer = graphics.layers.create("mesh-system");
154
150
 
155
- this.renderLayer.buildVisibleSet = (destination, destination_offset, view) => {
156
-
157
- const ecd = entityManager.dataset;
158
-
159
- if (ecd === null) {
160
- return 0;
161
- }
162
-
163
- const view_frustum = view.frustum;
164
-
165
- const hit_count = bvh_query_user_data_overlaps_frustum(scratch_array, 0, this.__bvh_binary, view_frustum);
166
-
167
- let added = 0;
168
-
169
- for (let i = 0; i < hit_count; i++) {
170
- const entity = scratch_array[i];
171
-
151
+ this.renderLayer.buildVisibleSet = make_bvh_visibility_builder(
152
+ this.entityManager, this.__bvh_binary,
153
+ (destination, offset, entity, ecd) => {
172
154
  const component = ecd.getComponent(entity, Mesh);
173
155
 
174
- const object3D = component.mesh;
175
-
176
- if (object3D === null) {
177
- continue;
156
+ if (component.mesh === null) {
157
+ return 0;
178
158
  }
179
159
 
180
- destination[destination_offset + added] = object3D;
181
- added++;
160
+ destination[offset] = component.mesh;
161
+ return 1;
182
162
  }
183
-
184
- return added;
185
- };
163
+ )
186
164
 
187
165
  const visibleSet = this.renderLayer.visibleSet;
188
166
 
@@ -1,54 +1,14 @@
1
1
  import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
2
2
 
3
- /**
4
- * Common buffer for scratch objects for better cache locality
5
- * @type {ArrayBuffer}
6
- */
7
- const scratch_buffer = new ArrayBuffer(28 * 4);
8
-
9
- /**
10
- *
11
- * @type {Float32Array}
12
- */
13
- const scratch_matrix4 = new Float32Array(scratch_buffer, 0, 16);
14
-
15
- /**
16
- *
17
- * @type {Float32Array}
18
- */
19
- const scratch_aabb_0 = new Float32Array(scratch_buffer, 64, 6);
20
-
21
- /**
22
- *
23
- * @type {Float32Array}
24
- */
25
- const scratch_aabb_1 = new Float32Array(scratch_buffer, 88, 6);
26
-
27
3
  /**
28
4
  *
29
- * @param {LeafNode} bvh
5
+ * @param {BvhClient} bvh
30
6
  * @param {AABB3} boundingBox
31
7
  * @param {Transform} transform
32
8
  */
33
9
  export function updateNodeByTransformAndBBB(bvh, boundingBox, transform) {
34
- transform.toMatrix4(scratch_matrix4);
35
-
36
- updateNodeByMatrix4AndBBB(bvh, boundingBox, scratch_matrix4);
37
- }
38
-
39
- /**
40
- *
41
- * @param {LeafNode} bvh
42
- * @param {AABB3} boundingBox
43
- * @param {ArrayLike<number>|number[]|Float32Array} matrix4
44
- */
45
- export function updateNodeByMatrix4AndBBB(bvh, boundingBox, matrix4) {
46
- boundingBox.writeToArray(scratch_aabb_1, 0);
47
-
48
- aabb3_matrix4_project(scratch_aabb_0, scratch_aabb_1, matrix4);
49
-
50
- bvh.readFromArray(scratch_aabb_0, 0);
10
+ aabb3_matrix4_project(bvh.bounds, boundingBox, transform.matrix);
51
11
 
52
- bvh.bubbleRefit();
12
+ bvh.write_bounds();
53
13
  }
54
14
 
@@ -3,13 +3,13 @@
3
3
  */
4
4
 
5
5
 
6
+ import { BvhClient } from "../../../../core/bvh2/bvh3/BvhClient.js";
6
7
  import Vector3 from "../../../../core/geom/Vector3.js";
7
8
  import Vector4 from "../../../../core/geom/Vector4.js";
9
+ import ThreeFactory from "../../three/ThreeFactory.js";
10
+ import { RibbonX } from "../../trail/x/RibbonX.js";
8
11
  import { RibbonXMaterialSpec } from "../../trail/x/RibbonXMaterialSpec.js";
9
- import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
10
12
  import { makeGradientTrail } from "./makeGradientTrail.js";
11
- import { RibbonX } from "../../trail/x/RibbonX.js";
12
- import ThreeFactory from "../../three/ThreeFactory.js";
13
13
 
14
14
  /**
15
15
  * @readonly
@@ -21,80 +21,80 @@ export const Trail2DFlags = {
21
21
  Built: 4,
22
22
  };
23
23
 
24
+ const DEFAULT_FLAGS = Trail2DFlags.Spawning | Trail2DFlags.Aging;
25
+
26
+ const DEFAULT_MAX_AGE = 5;
27
+
28
+ const DEFAULT_WIDTH = 1;
29
+
24
30
  class Trail2D {
25
- constructor() {
26
-
27
- /**
28
- * Age at which trail segment disappears, in seconds
29
- * @type {number}
30
- */
31
- this.maxAge = 5;
32
-
33
- /**
34
- * Trail width
35
- * @type {number}
36
- */
37
- this.width = 1;
38
-
39
- /**
40
- * Current simulated time since trail birth
41
- * @type {number}
42
- */
43
- this.time = 0;
44
-
45
- /**
46
- *
47
- * @type {number}
48
- */
49
- this.trailingIndex = 0;
50
-
51
- /**
52
- * Time elapsed since last update
53
- * @type {number}
54
- */
55
- this.timeSinceLastUpdate = 0;
56
-
57
- /**
58
- * @readonly
59
- * @type {Vector4}
60
- */
61
- this.color = new Vector4(1, 1, 1, 1);
62
-
63
- /**
64
- * World offset
65
- * @readonly
66
- * @type {Vector3}
67
- */
68
- this.offset = new Vector3();
69
-
70
- /**
71
- * transient
72
- * @type {RibbonX|null}
73
- */
74
- this.ribbon = null;
75
-
76
- /**
77
- * transient
78
- * @type {RibbonXMaterialSpec}
79
- */
80
- this.material = new RibbonXMaterialSpec();
81
-
82
- /**
83
- * transient
84
- * @type {LeafNode|null}
85
- */
86
- this.bvhLeaf = new LeafNode(
87
- this,
88
- 0, 0, 0,
89
- 0, 0, 0
90
- );
91
-
92
- /**
93
- * @private
94
- * @type {Trail2DFlags|number}
95
- */
96
- this.flags = Trail2DFlags.Spawning | Trail2DFlags.Aging;
97
- }
31
+
32
+ /**
33
+ * Age at which trail segment disappears, in seconds
34
+ * @type {number}
35
+ */
36
+ maxAge = DEFAULT_MAX_AGE;
37
+
38
+ /**
39
+ * Trail width
40
+ * @type {number}
41
+ */
42
+ width = DEFAULT_WIDTH;
43
+
44
+ /**
45
+ * Current simulated time since trail birth
46
+ * @type {number}
47
+ */
48
+ time = 0;
49
+
50
+ /**
51
+ *
52
+ * @type {number}
53
+ */
54
+ trailingIndex = 0;
55
+
56
+ /**
57
+ * Time elapsed since last update
58
+ * @type {number}
59
+ */
60
+ timeSinceLastUpdate = 0;
61
+
62
+ /**
63
+ * @readonly
64
+ * @type {Vector4}
65
+ */
66
+ color = new Vector4(1, 1, 1, 1);
67
+
68
+ /**
69
+ * World offset
70
+ * @readonly
71
+ * @type {Vector3}
72
+ */
73
+ offset = new Vector3();
74
+
75
+ /**
76
+ * transient
77
+ * @type {RibbonX|null}
78
+ */
79
+ ribbon = null;
80
+
81
+ /**
82
+ * transient
83
+ * @type {RibbonXMaterialSpec}
84
+ */
85
+ material = new RibbonXMaterialSpec();
86
+
87
+ /**
88
+ * @readonly
89
+ * @type {BvhClient}
90
+ */
91
+ bvh = new BvhClient();
92
+
93
+ /**
94
+ * @private
95
+ * @type {Trail2DFlags|number}
96
+ */
97
+ flags = DEFAULT_FLAGS;
98
98
 
99
99
  dispose() {
100
100
  if (this.ribbon !== null) {
@@ -150,36 +150,10 @@ class Trail2D {
150
150
  return (this.flags & flag) === flag;
151
151
  }
152
152
 
153
- static fromJSON(json) {
154
- const r = new Trail2D();
155
-
156
- r.fromJSON(json);
157
-
158
- return r;
159
- }
160
-
161
- fromJSON(json) {
162
- if (typeof json.maxAge === "number") {
163
- this.maxAge = json.maxAge;
164
- }
165
-
166
- if (typeof json.width === "number") {
167
- this.width = json.width;
168
- }
169
-
170
- if (typeof json.textureURL === "string") {
171
- this.textureURL = json.textureURL;
172
- }
173
-
174
- if (json.offset !== undefined) {
175
- this.offset.fromJSON(json.offset);
176
- }
177
-
178
- if (json.color !== undefined) {
179
- this.color.fromJSON(json.color);
180
- }
181
- }
182
-
153
+ /**
154
+ *
155
+ * @param {number} segment_count
156
+ */
183
157
  build(segment_count) {
184
158
 
185
159
  const ribbon = new RibbonX();
@@ -195,6 +169,31 @@ class Trail2D {
195
169
  this.mesh = mesh;
196
170
  }
197
171
 
172
+ static fromJSON(json) {
173
+ const r = new Trail2D();
174
+
175
+ r.fromJSON(json);
176
+
177
+ return r;
178
+ }
179
+
180
+ fromJSON({
181
+ maxAge = DEFAULT_MAX_AGE,
182
+ width = DEFAULT_WIDTH,
183
+ textureURL,
184
+ offset = Vector3.zero,
185
+ color = { x: 1, y: 1, z: 1, w: 1 }
186
+ }) {
187
+
188
+ this.maxAge = maxAge;
189
+ this.width = width;
190
+ this.textureURL = textureURL;
191
+
192
+ this.offset.fromJSON(offset);
193
+ this.color.fromJSON(color);
194
+ }
195
+
196
+
198
197
  toJSON() {
199
198
  return {
200
199
  maxAge: this.maxAge,
@@ -3,31 +3,66 @@
3
3
  */
4
4
 
5
5
 
6
+ import { assert } from "../../../../core/assert.js";
7
+ import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
8
+ import Vector3 from '../../../../core/geom/Vector3.js';
6
9
  import { clamp } from "../../../../core/math/clamp.js";
7
10
  import { max2 } from "../../../../core/math/max2.js";
11
+ import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
12
+ import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
8
13
  import { System } from '../../../ecs/System.js';
9
14
  import { Transform } from '../../../ecs/transform/Transform.js';
10
- import Vector3 from '../../../../core/geom/Vector3.js';
11
-
12
- import Trail2D, { Trail2DFlags } from './Trail2D.js';
15
+ import { Reference } from "../../../reference/v2/Reference.js";
13
16
  import { GraphicsEngine } from "../../GraphicsEngine.js";
14
- import { RibbonXFixedPhysicsSimulator } from "../../trail/x/simulator/RibbonXFixedPhysicsSimulator.js";
15
- import { RibbonX } from "../../trail/x/RibbonX.js";
17
+ import { make_bvh_visibility_builder } from "../../render/make_bvh_visibility_builder.js";
16
18
  import {
17
19
  RIBBON_ATTRIBUTE_ADDRESS_AGE,
18
20
  RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET
19
21
  } from "../../trail/x/ribbon_attributes_spec.js";
20
- import { Reference } from "../../../reference/v2/Reference.js";
22
+ import { RibbonX } from "../../trail/x/RibbonX.js";
21
23
  import { RibbonXPlugin } from "../../trail/x/RibbonXPlugin.js";
22
- import { assert } from "../../../../core/assert.js";
23
- import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
24
- import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
24
+ import { RibbonXFixedPhysicsSimulator } from "../../trail/x/simulator/RibbonXFixedPhysicsSimulator.js";
25
+
26
+ import Trail2D, { Trail2DFlags } from './Trail2D.js';
25
27
 
26
28
  const v3Temp1 = new Vector3();
27
29
 
28
30
  const v3_array = [];
29
31
 
30
32
  class Trail2DSystem extends System {
33
+ dependencies = [Trail2D, Transform];
34
+
35
+ components_used = [
36
+ ResourceAccessSpecification.from(Trail2D, ResourceAccessKind.Write)
37
+ ];
38
+
39
+ /**
40
+ *
41
+ * @type {RibbonXFixedPhysicsSimulator}
42
+ */
43
+ simulator = new RibbonXFixedPhysicsSimulator();
44
+
45
+ /**
46
+ *
47
+ * @type {Reference<RibbonXPlugin>}
48
+ * @private
49
+ */
50
+ __ribbon_plugin = Reference.NULL;
51
+
52
+
53
+ /**
54
+ *
55
+ * @type {number}
56
+ * @private
57
+ */
58
+ __timeDelta = 0;
59
+
60
+ /**
61
+ * @private
62
+ * @type {BVH}
63
+ */
64
+ bvh = new BVH();
65
+
31
66
  /**
32
67
  * @param {Engine} engine
33
68
  * @constructor
@@ -39,12 +74,6 @@ class Trail2DSystem extends System {
39
74
  assert.notNull(engine, 'engine');
40
75
  assert.equal(engine.isEngine, true, 'engine.isEngine !== true');
41
76
 
42
- this.dependencies = [Trail2D, Transform];
43
-
44
- this.components_used = [
45
- ResourceAccessSpecification.from(Trail2D, ResourceAccessKind.Write)
46
- ];
47
-
48
77
 
49
78
  /**
50
79
  *
@@ -53,13 +82,11 @@ class Trail2DSystem extends System {
53
82
  */
54
83
  this.__engine = engine;
55
84
 
56
- const graphics = engine.graphics;
57
-
58
85
  /**
59
86
  *
60
87
  * @type {GraphicsEngine}
61
88
  */
62
- this.graphics = graphics;
89
+ this.graphics = engine.graphics;
63
90
 
64
91
  /**
65
92
  *
@@ -67,45 +94,21 @@ class Trail2DSystem extends System {
67
94
  */
68
95
  this.renderLayer = null;
69
96
 
70
- /**
71
- *
72
- * @type {BinaryNode}
73
- */
74
- this.bvh = null;
75
-
76
- /**
77
- *
78
- * @type {RibbonXFixedPhysicsSimulator}
79
- */
80
- this.simulator = new RibbonXFixedPhysicsSimulator();
81
97
 
82
- /**
83
- *
84
- * @type {Reference<RibbonXPlugin>}
85
- * @private
86
- */
87
- this.__ribbon_plugin = Reference.NULL;
88
-
89
-
90
- /**
91
- *
92
- * @type {number}
93
- * @private
94
- */
95
- this.__timeDelta = 0;
96
98
  }
97
99
 
98
100
  async startup(entityManager, readyCallback, errorCallback) {
99
101
  this.entityManager = entityManager;
100
102
 
101
103
  this.renderLayer = this.graphics.layers.create('trail-2d-system');
102
- // this.renderLayer.renderPass = RenderPassType.Transparent;
103
-
104
- this.renderLayer.extractRenderable = function (trail) {
105
- return trail.mesh;
106
- };
107
104
 
108
- this.bvh = this.renderLayer.bvh;
105
+ this.renderLayer.buildVisibleSet = make_bvh_visibility_builder(
106
+ this.entityManager, this.bvh,
107
+ (destination, offset, entity, ecd) => {
108
+ destination[offset] = ecd.getComponent(entity, Trail2D).mesh
109
+ return 1;
110
+ }
111
+ );
109
112
 
110
113
  this.__ribbon_plugin = await this.__engine.plugins.acquire(RibbonXPlugin);
111
114
 
@@ -172,9 +175,9 @@ class Trail2DSystem extends System {
172
175
 
173
176
  }
174
177
 
175
- trail.bvhLeaf.resize(
176
- position_x, position_y, position_z,
177
- position_x, position_y, position_z
178
+ trail.bvh.resize(
179
+ position_x,position_y,position_z,
180
+ position_x,position_y,position_z
178
181
  );
179
182
 
180
183
  trail.setFlag(Trail2DFlags.Built);
@@ -196,7 +199,7 @@ class Trail2DSystem extends System {
196
199
  }
197
200
 
198
201
 
199
- this.bvh.insertNode(trail.bvhLeaf);
202
+ trail.bvh.link(this.bvh, entityId);
200
203
  }
201
204
 
202
205
  /**
@@ -207,10 +210,11 @@ class Trail2DSystem extends System {
207
210
  */
208
211
  unlink(component, transform, entity) {
209
212
 
213
+ component.bvh.unlink();
214
+
210
215
  // release resources
211
216
  component.dispose();
212
217
 
213
- component.bvhLeaf.disconnect();
214
218
  }
215
219
 
216
220
  /**
@@ -265,14 +269,9 @@ class Trail2DSystem extends System {
265
269
  ribbon.setPointAttribute_Scalar(head_index, RIBBON_ATTRIBUTE_ADDRESS_AGE, ageOffset);
266
270
 
267
271
  }
268
- const bvh = trail.bvhLeaf;
269
-
270
- ribbon.computeBoundingBox(bvh);
271
-
272
- if (bvh.parentNode !== null) {
273
- bvh.parentNode.bubbleRefit();
274
- }
275
272
 
273
+ ribbon.computeBoundingBox(trail.bvh.bounds);
274
+ trail.bvh.write_bounds();
276
275
 
277
276
  this.simulator.update(ribbon, trail.maxAge, timeDelta);
278
277
  }