@woosh/meep-engine 2.31.1 → 2.31.5

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 (55) hide show
  1. package/core/binary/BitSet.js +5 -1
  2. package/core/collection/RingBuffer.js +16 -1
  3. package/core/geom/Vector1.js +228 -219
  4. package/core/geom/Vector2.js +547 -502
  5. package/core/geom/Vector3.js +8 -0
  6. package/core/geom/Vector4.js +322 -311
  7. package/core/graph/v2/Graph.js +6 -6
  8. package/core/model/ObservedBoolean.js +12 -4
  9. package/core/process/worker/WorkerBuilder.js +27 -9
  10. package/core/process/worker/WorkerProxy.js +6 -0
  11. package/editor/Editor.js +10 -1
  12. package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +3 -1
  13. package/engine/EngineHarness.js +1 -1
  14. package/engine/ecs/parent/ParentEntitySystem.js +1 -1
  15. package/engine/ecs/terrain/ecs/Terrain.js +11 -2
  16. package/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +10 -10
  17. package/engine/graphics/camera/makeOrbitalCameraController.js +7 -1
  18. package/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js +4 -31
  19. package/engine/graphics/ecs/mesh/Mesh.js +9 -3
  20. package/engine/graphics/ecs/path/entity/EntityPath.js +7 -7
  21. package/engine/graphics/ecs/trail2d/Trail2DSystem.js +31 -16
  22. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +17 -8
  23. package/engine/graphics/micron/build/graph/metis/metis.js +23 -33
  24. package/engine/graphics/micron/render/v1/MaterialContext.js +21 -2
  25. package/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +1 -1
  26. package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +1 -1
  27. package/engine/graphics/render/buffer/buffers/NormalFrameBuffer.js +25 -16
  28. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +6 -5
  29. package/engine/graphics/trail/x/RibbonMaterialX.js +7 -2
  30. package/engine/grid/components/GridPosition.js +22 -122
  31. package/engine/grid/components/GridPositionSerializationAdapter.js +58 -0
  32. package/engine/grid/components/GridPositionSerializationUpdater_0_1.js +37 -0
  33. package/engine/intelligence/mcts/MonteCarlo.js +12 -15
  34. package/engine/intelligence/mcts/StateNode.js +3 -3
  35. package/generation/GridTags.js +3 -2
  36. package/generation/example/SampleGenerator0.js +1 -1
  37. package/generation/example/generators/{mir_generator_place_buff_objects.js → interactive/mir_generator_place_buff_objects.js} +97 -26
  38. package/generation/example/generators/mir_generator_place_starting_point.js +12 -5
  39. package/generation/example/grid/configureMirGrid.js +1 -1
  40. package/generation/filtering/CellFilter.js +14 -0
  41. package/generation/filtering/numeric/util/CellFilterLogToConsole.js +2 -1
  42. package/generation/grid/GridData.js +18 -14
  43. package/generation/grid/MarkerMatchCounter.js +23 -0
  44. package/generation/grid/generation/GridTaskApplyActionToCells.js +86 -0
  45. package/generation/grid/generation/grid/select/CellSupplier.js +28 -0
  46. package/generation/grid/generation/grid/select/CellSupplierBestN.js +188 -0
  47. package/generation/grid/generation/grid/select/CellSupplierPathUpHill.js +187 -0
  48. package/generation/markers/GridActionRuleSet.js +1 -1
  49. package/generation/markers/MarkerNode.js +18 -0
  50. package/generation/markers/debug/visualizeMarkers.js +8 -1
  51. package/generation/markers/transform/MarkerNodeTransformerSequence.js +47 -0
  52. package/generation/placement/GridCellActionTransformNearbyMarkers.js +9 -17
  53. package/generation/rules/CellMatcherFromFilter.js +38 -0
  54. package/generation/rules/cell/CellMatcherContainsMarkerWithinRadius.js +1 -1
  55. package/package.json +3 -3
@@ -122,11 +122,16 @@ export class Graph {
122
122
  * @returns {N|undefined}
123
123
  */
124
124
  findNode(filter, thisArg) {
125
- for (const [node, container] of this.__nodes) {
125
+ const nodes = this.__nodes;
126
+
127
+ for (const [node, container] of nodes) {
128
+
126
129
  const pass = filter.call(thisArg, node);
130
+
127
131
  if (pass) {
128
132
  return node;
129
133
  }
134
+
130
135
  }
131
136
 
132
137
  return undefined;
@@ -297,11 +302,6 @@ export class Graph {
297
302
  return false;
298
303
  }
299
304
 
300
- if (!this.hasNode(b)) {
301
- // check if B is part of the graph
302
- return false;
303
- }
304
-
305
305
  return context_a.edgeWithNodeExists(b);
306
306
  }
307
307
 
@@ -1,7 +1,7 @@
1
1
  import { assert } from "../assert.js";
2
2
  import Signal from "../events/signal/Signal.js";
3
3
 
4
- class ObservedBoolean extends Boolean{
4
+ class ObservedBoolean extends Boolean {
5
5
  /**
6
6
  *
7
7
  * @param {boolean} value
@@ -44,7 +44,7 @@ class ObservedBoolean extends Boolean{
44
44
  * @returns {ObservedBoolean}
45
45
  */
46
46
  set(value) {
47
- assert.equal(typeof value, "boolean", `Value must be of type "boolean", instead was "${typeof value}"`);
47
+ assert.isBoolean(value, 'value');
48
48
 
49
49
  const oldValue = this.__value;
50
50
  if (oldValue !== value) {
@@ -56,6 +56,14 @@ class ObservedBoolean extends Boolean{
56
56
  return this;
57
57
  }
58
58
 
59
+ setTrue() {
60
+ this.set(true);
61
+ }
62
+
63
+ setFalse() {
64
+ this.set(false);
65
+ }
66
+
59
67
  /**
60
68
  *
61
69
  * @param {ObservedBoolean} other
@@ -77,8 +85,8 @@ class ObservedBoolean extends Boolean{
77
85
  *
78
86
  * @return {number}
79
87
  */
80
- hashCode(){
81
- return this.__value?1:0;
88
+ hashCode() {
89
+ return this.__value ? 1 : 0;
82
90
  }
83
91
 
84
92
  /**
@@ -5,19 +5,19 @@
5
5
 
6
6
  import { convertPathToURL } from "../../../engine/network/convertPathToURL.js";
7
7
  import WorkerProxy from "./WorkerProxy.js";
8
- import { extractTransferables } from "./extractTransferables.js";
8
+ import LineBuilder from "../../codegen/LineBuilder.js";
9
9
 
10
10
  const RxMatchFunctionName = /(function\s*)([a-zA-Z0-9_]+)?(\s*\([^\]]*\)\s*\{.*)/g;
11
11
 
12
- const builtin_functions = [{
13
- f: extractTransferables,
14
- name: 'extractTransferables'
15
- }];
16
-
17
12
  const WorkerBuilder = function () {
18
13
  this.imports = [];
19
14
  this.methods = {};
20
15
  this.functions = [];
16
+ this.preable = new LineBuilder();
17
+ };
18
+
19
+ WorkerBuilder.prototype.addCode = function (code) {
20
+ this.preable.add(code);
21
21
  };
22
22
 
23
23
  /**
@@ -30,7 +30,7 @@ WorkerBuilder.prototype.addMethod = function (name, method) {
30
30
  };
31
31
 
32
32
  /**
33
- *
33
+ * NOTE: take care when using minifiers as they may mangle function names
34
34
  * @param name
35
35
  * @param {function} f
36
36
  */
@@ -78,8 +78,10 @@ WorkerBuilder.prototype.build = function () {
78
78
  codeLines.push("globalScope.importScripts('" + url + "');");
79
79
  });
80
80
 
81
+ codeLines.push(this.preable.build());
82
+
81
83
  //handle functions
82
- builtin_functions.concat(this.functions).forEach(function (spec) {
84
+ this.functions.forEach(function (spec) {
83
85
  const f = spec.f;
84
86
 
85
87
  const function_string = f.toString();
@@ -102,7 +104,23 @@ WorkerBuilder.prototype.build = function () {
102
104
 
103
105
  //api handler
104
106
  Array.prototype.push.apply(codeLines, [
105
-
107
+ `function extractTransferables(obj, result) {
108
+ if (typeof obj !== "object") {
109
+ return; //not an object, skip
110
+ } else if (obj instanceof ArrayBuffer) {
111
+ result.push(obj);
112
+ } else if (obj.buffer instanceof ArrayBuffer) {
113
+ result.push(obj.buffer);
114
+ } else if (obj instanceof ImageBitmap) {
115
+ result.push(obj);
116
+ } else {
117
+ for (var i in obj) {
118
+ if (obj.hasOwnProperty(i)) {
119
+ extractTransferables(obj[i], result);
120
+ }
121
+ }
122
+ }
123
+ }`,
106
124
  'globalScope.onmessage = function(event){',
107
125
  ' var eventData = event.data;',
108
126
  ' var requestId = eventData.id',
@@ -263,6 +263,12 @@ class WorkerProxy {
263
263
 
264
264
  this.__worker = new Worker(this.url);
265
265
  this.__worker.onmessage = this.__handleMessageBound;
266
+
267
+ // TODO attach proper error handler
268
+ this.__worker.onerror = (errorEvent) => {
269
+ console.error('Worker error:', errorEvent);
270
+ };
271
+
266
272
  this.__isRunning = true;
267
273
 
268
274
  this.sendPendingRequests();
package/editor/Editor.js CHANGED
@@ -286,7 +286,16 @@ function activateEditorCamera(cameraEntity, dataset, editor) {
286
286
  */
287
287
  const cameraController = cameraEntity.getComponent(TopDownCameraController);
288
288
 
289
- setCameraControllerFromTransform(cameraTransform, cameraController);
289
+ const active_camera_controller = dataset.getComponent(activeCameraEntity, TopDownCameraController);
290
+ if (active_camera_controller !== undefined) {
291
+ cameraController.target.copy(active_camera_controller.target);
292
+ cameraController.distance = active_camera_controller.distance;
293
+ cameraController.pitch = active_camera_controller.pitch;
294
+ cameraController.yaw = active_camera_controller.yaw;
295
+ cameraController.roll = active_camera_controller.roll;
296
+ } else {
297
+ setCameraControllerFromTransform(cameraTransform, cameraController);
298
+ }
290
299
  }
291
300
 
292
301
  camera.active.set(true);
@@ -6,6 +6,8 @@ import Renderable from "../../../engine/ecs/components/Renderable.js";
6
6
  import { Transform } from "../../../engine/ecs/transform/Transform.js";
7
7
  import { synchronizeTransform } from "./synchronizeTransform.js";
8
8
 
9
+ const SPRITE_SIZE = 0.3;
10
+
9
11
  /**
10
12
  * @template C,T
11
13
  * @param {Engine} engine
@@ -57,7 +59,7 @@ export function makePositionedIconDisplaySymbol(engine, iconURL, ComponentClass)
57
59
 
58
60
 
59
61
  //sprite size
60
- cT.scale.set(1, 1, 1);
62
+ cT.scale.set(SPRITE_SIZE, SPRITE_SIZE, SPRITE_SIZE);
61
63
  cR.boundingBox.setBounds(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5);
62
64
 
63
65
  synchronizeTransform(transform, cT, api.bindings, true, false, false);
@@ -150,7 +150,7 @@ export class EngineHarness {
150
150
  ecd = engine.entityManager.dataset,
151
151
  target = new Vector3(),
152
152
  distance = 10,
153
- pitch = -1.4,
153
+ pitch = 1.4,
154
154
  yaw = 0,
155
155
  autoClip = true,
156
156
  distanceMin = 0,
@@ -75,7 +75,7 @@ class Context extends SystemEntityContext {
75
75
  */
76
76
  const cParent = this.components[0];
77
77
 
78
- ecd.removeEntityEventListener(cParent.entity, EventType.EntityRemoved, this.die, this);
78
+ ecd.removeEntityEventListener(cParent.entity, EventType.EntityRemoved, this.handleParentEntityRemoval, this);
79
79
  }
80
80
  }
81
81
 
@@ -40,6 +40,7 @@ import { makeTerrainWorkerProxy } from "./makeTerrainWorkerProxy.js";
40
40
  import { MeepSettings } from "../../../MeepSettings.js";
41
41
  import { loadLegacyTerrainLayers } from "./layers/loadLegacyTerrainLayers.js";
42
42
  import { TerrainFlags } from "./TerrainFlags.js";
43
+ import { IllegalStateException } from "../../../../core/fsm/exceptions/IllegalStateException.js";
43
44
 
44
45
  /**
45
46
  *
@@ -464,6 +465,12 @@ class Terrain {
464
465
  this.clearFlag(TerrainFlags.Linked);
465
466
  }
466
467
 
468
+ dispose() {
469
+ if (this.getFlag(TerrainFlags.Linked)) {
470
+ throw new IllegalStateException('component is linked, must be unlinked first');
471
+ }
472
+ }
473
+
467
474
  initialize() {
468
475
  const overlay = this.overlay;
469
476
 
@@ -894,9 +901,11 @@ class Terrain {
894
901
 
895
902
  updateWorkerHeights() {
896
903
  const s = this.samplerHeight;
897
- this.buildWorker.setHeightSampler(s.data, s.itemSize, s.width, s.height);
904
+ const worker = this.buildWorker;
905
+
906
+ worker.setHeightSampler(s.data, s.itemSize, s.width, s.height);
898
907
 
899
- this.buildWorker.computeHeightRange()
908
+ worker.computeHeightRange()
900
909
  .then(({ min, max }) => {
901
910
  this.tiles.setHeightRange(min, max);
902
911
  });
@@ -8,19 +8,19 @@ export function makeTerrainWorkerProxy() {
8
8
  const workerBuilder = new WorkerBuilder();
9
9
  workerBuilder.importScript('bundle-worker-terrain.js');
10
10
 
11
- function useSampler(callback) {
12
- if (globalScope.samplerHeight !== undefined) {
13
- callback(globalScope.samplerHeight);
14
- } else {
15
- if (globalScope.useSampleCallbacks === undefined) {
16
- globalScope.useSampleCallbacks = [callback];
11
+ workerBuilder.addCode(`
12
+ function useSampler(callback) {
13
+ if (globalScope.samplerHeight !== undefined) {
14
+ callback(globalScope.samplerHeight);
17
15
  } else {
18
- globalScope.useSampleCallbacks.push(callback);
16
+ if (globalScope.useSampleCallbacks === undefined) {
17
+ globalScope.useSampleCallbacks = [callback];
18
+ } else {
19
+ globalScope.useSampleCallbacks.push(callback);
20
+ }
19
21
  }
20
22
  }
21
- }
22
-
23
- workerBuilder.importFunction('useSampler', useSampler);
23
+ `);
24
24
 
25
25
  workerBuilder.addMethod('computeHeightRange', function () {
26
26
  return new Promise(function (resolve, reject) {
@@ -3,6 +3,7 @@ import InputController from "../../input/ecs/components/InputController.js";
3
3
  import { decodeMouseEventButtons } from "../../input/devices/PointerDevice.js";
4
4
  import EntityBuilder from "../../ecs/EntityBuilder.js";
5
5
  import { Camera } from "../ecs/camera/Camera.js";
6
+ import { clamp } from "../../../core/math/clamp.js";
6
7
 
7
8
  /**
8
9
  *
@@ -18,6 +19,10 @@ export function makeOrbitalCameraController({
18
19
  dom_element,
19
20
  sensitivity = 0.01
20
21
  }) {
22
+ /**
23
+ *
24
+ * @returns {TopDownCameraController}
25
+ */
21
26
  function getCameraController() {
22
27
  return ecd.getComponent(camera_entity, TopDownCameraController)
23
28
  }
@@ -55,7 +60,8 @@ export function makeOrbitalCameraController({
55
60
  function zoom(delta) {
56
61
  const cameraController = getCameraController();
57
62
 
58
- cameraController.distance += delta;
63
+ const new_distance = cameraController.distance + delta;
64
+ cameraController.distance = clamp(new_distance, cameraController.distanceMin, cameraController.distanceMax);
59
65
  }
60
66
 
61
67
  const inputController = new InputController([
@@ -12,8 +12,6 @@ import { System } from '../../../../ecs/System.js';
12
12
 
13
13
  import TopDownCameraController from './TopDownCameraController.js';
14
14
 
15
- import { Euler as ThreeEuler } from 'three';
16
-
17
15
 
18
16
  const v3_scratch = new Vector3();
19
17
 
@@ -80,36 +78,11 @@ export function computeTopDownTransform(control, result) {
80
78
  * @param {number} distance
81
79
  */
82
80
  export function setCameraControllerFromTransform(transform, controller, distance = 20) {
83
- //set camera controller
84
- const euler = new ThreeEuler();
85
-
86
- transform.rotation.__setThreeEuler(euler);
87
-
88
- controller.yaw = euler.y;
89
-
90
- const pitch = euler.x;
91
-
92
- controller.pitch = pitch;
93
-
94
- controller.roll = 0;
95
-
96
- //compute direction
97
- const direction = new Vector3();
98
-
99
- direction.copy(Vector3.forward);
100
- direction.applyQuaternion(transform.rotation);
101
-
102
- direction.normalize();
103
-
104
- controller.distance = distance;
105
-
106
- const targetOffset = direction.clone();
107
- targetOffset.multiplyScalar(controller.distance);
108
-
109
- const target = transform.position.clone();
110
- target.sub(targetOffset);
81
+ const v_f = Vector3.forward.clone();
82
+ v_f.multiplyScalar(distance);
83
+ v_f.applyQuaternion(transform.rotation);
111
84
 
112
- controller.target.copy(target)
85
+ controller.setFromEyeAndTarget(transform.position,v_f);
113
86
  }
114
87
 
115
88
  export default TopDownCameraControllerSystem;
@@ -41,6 +41,12 @@ class Mesh {
41
41
  */
42
42
  this.mesh = null;
43
43
 
44
+ /**
45
+ * Mesh with micron data, if available
46
+ * @type {Object3D|null}
47
+ */
48
+ this.micron_mesh = null;
49
+
44
50
  /**
45
51
  * @transient
46
52
  * @type {Asset|null}
@@ -214,9 +220,9 @@ class Mesh {
214
220
  */
215
221
  equals(other) {
216
222
  return this.url === other.url
217
- && this.opacity === other.opacity
218
- && this.castShadow === other.castShadow
219
- && this.receiveShadow === other.receiveShadow
223
+ && this.opacity === other.opacity
224
+ && this.castShadow === other.castShadow
225
+ && this.receiveShadow === other.receiveShadow
220
226
  ;
221
227
  }
222
228
 
@@ -6,7 +6,7 @@ import { EPSILON } from "../../../../../core/math/MathUtils.js";
6
6
  import { binarySearchHighIndex } from "../../../../../core/collection/ArrayUtils.js";
7
7
  import { assert } from "../../../../../core/assert.js";
8
8
 
9
- const v3 = new Vector3();
9
+ const scratch_v3 = new Vector3();
10
10
 
11
11
 
12
12
  /**
@@ -117,19 +117,19 @@ export class EntityPath {
117
117
 
118
118
  if (def.align) {
119
119
  // get next point position to figure out orientation
120
- if (path.sample(v3, offset + EPSILON)) {
121
- v3.sub(transform.position);
120
+ if (path.sample(scratch_v3, offset + EPSILON)) {
121
+ scratch_v3.sub(transform.position);
122
122
 
123
123
  } else {
124
124
  // sample behind
125
- path.sample(v3, offset - EPSILON);
125
+ path.sample(scratch_v3, offset - EPSILON);
126
126
 
127
- v3.subVectors(transform.position, v3);
127
+ scratch_v3.subVectors(transform.position, scratch_v3);
128
128
  }
129
129
 
130
- v3.normalize();
130
+ scratch_v3.normalize();
131
131
 
132
- transform.rotation.lookRotation(v3);
132
+ transform.rotation.lookRotation(scratch_v3);
133
133
  }
134
134
 
135
135
  transform.multiplyTransforms(transform, def.transform);
@@ -8,7 +8,7 @@ import { max2 } from "../../../../core/math/max2.js";
8
8
  import { System } from '../../../ecs/System.js';
9
9
  import { Transform } from '../../../ecs/transform/Transform.js';
10
10
  import Vector3 from '../../../../core/geom/Vector3.js';
11
- import { computeHashFloat, computeHashIntegerArray} from '../../../../core/math/MathUtils.js';
11
+ import { computeHashFloat, computeHashIntegerArray } from '../../../../core/math/MathUtils.js';
12
12
 
13
13
  import Trail2D, { Trail2DFlags } from './Trail2D.js';
14
14
  import { ClampToEdgeWrapping, DoubleSide, LinearFilter, TextureLoader } from 'three';
@@ -27,7 +27,9 @@ import {
27
27
  } from "../../trail/x/ribbon_attributes_spec.js";
28
28
  import { RibbonMaterialX } from "../../trail/x/RibbonMaterialX.js";
29
29
  import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
30
+ import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
30
31
 
32
+ const scratch_aabb3 = new AABB3();
31
33
  const v3Temp1 = new Vector3();
32
34
 
33
35
  const v3_array = [];
@@ -153,6 +155,7 @@ class Trail2DSystem extends System {
153
155
  this.entityManager = entityManager;
154
156
 
155
157
  this.renderLayer = this.graphics.layers.create('trail-2d-system');
158
+ // this.renderLayer.renderPass = RenderPassType.Transparent;
156
159
 
157
160
  this.renderLayer.extractRenderable = function (trail) {
158
161
  return trail.mesh;
@@ -220,12 +223,12 @@ class Trail2DSystem extends System {
220
223
  //instantiation
221
224
 
222
225
  //make a mesh
223
- const numSegments = Math.ceil(clamp(trail.maxAge * segmentsPerSecond, 2, maxSegments));
226
+ const segment_count = Math.ceil(clamp(trail.maxAge * segmentsPerSecond, 2, maxSegments));
224
227
 
225
228
  const ribbon = new RibbonX();
226
229
 
227
230
  ribbon.buildGeometry();
228
- ribbon.setCount(numSegments);
231
+ ribbon.setCount(segment_count);
229
232
 
230
233
 
231
234
  const geometry = ribbon.getGeometry();
@@ -242,24 +245,22 @@ class Trail2DSystem extends System {
242
245
  trail.mesh = mesh;
243
246
  trail.timeSinceLastUpdate = 0;
244
247
 
245
- const leafNode = new LeafNode();
246
248
 
247
- trail.bvhLeaf = leafNode;
248
- trail.material = material;
249
-
250
- leafNode.object = trail;
251
- leafNode.setInfiniteBounds();
249
+ const trail_offset = trail.offset;
250
+ const transform_position = transform.position;
252
251
 
253
- const position = trail.offset.clone().add(transform.position);
252
+ const position_x = trail_offset.x + transform_position.x;
253
+ const position_y = trail_offset.y + transform_position.y;
254
+ const position_z = trail_offset.z + transform_position.z;
254
255
 
255
256
  const color = trail.color;
256
257
 
257
258
  //initialize segments
258
- for (let i = 0; i < numSegments; i++) {
259
- const f = i / (numSegments - 1);
259
+ for (let i = 0; i < segment_count; i++) {
260
+ const f = i / (segment_count - 1);
260
261
 
261
262
  ribbon.setPointColor(i, color.x * 255, color.y * 255, color.z * 255);
262
- ribbon.setPointPosition(i, position.x, position.y, position.z);
263
+ ribbon.setPointPosition(i, position_x, position_y, position_z);
263
264
  ribbon.setPointThickness(i, trail.width);
264
265
  ribbon.setPointAttribute_Scalar(i, RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET, f);
265
266
  ribbon.setPointAlpha(i, color.w);
@@ -267,9 +268,17 @@ class Trail2DSystem extends System {
267
268
 
268
269
  }
269
270
 
270
- leafNode.setBounds(position.x, position.y, position.z);
271
+ const leafNode = new LeafNode(
272
+ trail,
273
+
274
+ position_x, position_y, position_z,
275
+ position_x, position_y, position_z
276
+ );
277
+
278
+ trail.bvhLeaf = leafNode;
279
+ trail.material = material;
271
280
 
272
- this.bvh.insertNode(trail.bvhLeaf);
281
+ this.bvh.insertNode(leafNode);
273
282
  }
274
283
 
275
284
  unlink(component, transform, entity) {
@@ -328,8 +337,14 @@ class Trail2DSystem extends System {
328
337
  ribbon.setPointAttribute_Scalar(head_index, RIBBON_ATTRIBUTE_ADDRESS_AGE, ageOffset);
329
338
 
330
339
  }
340
+ const bvh = trail.bvhLeaf;
341
+
342
+ ribbon.computeBoundingBox(bvh);
343
+
344
+ if (bvh.parentNode !== null) {
345
+ bvh.parentNode.bubbleRefit();
346
+ }
331
347
 
332
- ribbon.computeBoundingBox(trail.bvhLeaf);
333
348
 
334
349
  this.simulator.update(ribbon, trail.maxAge, timeDelta);
335
350
  }
@@ -174,6 +174,8 @@ export function compute_buffer_geometry_byte_size(g) {
174
174
  return result;
175
175
  }
176
176
 
177
+ const PRINT_VERBOSE_STATS = false;
178
+
177
179
  /**
178
180
  *
179
181
  * @param {THREE.BufferGeometry} input
@@ -217,10 +219,12 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
217
219
  vertex_to_patch_map
218
220
  );
219
221
 
220
- console.log(`build leaf patches: ${(performance.now() - t_build_leaf_patches_start)}ms`);
222
+ if (PRINT_VERBOSE_STATS) {
223
+ console.log(`build leaf patches: ${(performance.now() - t_build_leaf_patches_start)}ms`);
221
224
 
222
225
 
223
- console.log(build_clustering_info(patches));
226
+ console.log(build_clustering_info(patches));
227
+ }
224
228
 
225
229
  // verify total poly count
226
230
 
@@ -233,8 +237,10 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
233
237
 
234
238
  const t_build_hierarchy_start = performance.now();
235
239
  const root = await buildAbstractPatchHierarchy(patches);
236
- console.log(`build hierarchy: ${(performance.now() - t_build_hierarchy_start)}ms`);
237
240
 
241
+ if (PRINT_VERBOSE_STATS) {
242
+ console.log(`build hierarchy: ${(performance.now() - t_build_hierarchy_start)}ms`);
243
+ }
238
244
 
239
245
  // console.profile('simplification');
240
246
  // console.time('simplification');
@@ -248,14 +254,16 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
248
254
  // assign IDs to the patches
249
255
  assign_ids_to_hierarchy(root);
250
256
 
251
- console.log(build_graph_info(root));
257
+ if (PRINT_VERBOSE_STATS) {
258
+ console.log(build_graph_info(root));
259
+ }
252
260
 
253
261
  const r = new MicronGeometry();
254
262
  r.source_triangle_count = index_attribute.count / 3;
255
263
  r.source_vertex_count = input.getAttribute('position').count;
256
264
  r.source_byte_size = compute_buffer_geometry_byte_size(input);
257
265
 
258
- console.time('build geometry');
266
+ // console.time('build geometry');
259
267
 
260
268
  const vertex_attributes = attributes_from_buffer_geometry(input);
261
269
  const data_types = buildVertexDataTypeMap(vertex_attributes);
@@ -267,10 +275,11 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
267
275
 
268
276
  r.initialize();
269
277
 
270
- console.timeEnd('build geometry');
271
-
278
+ // console.timeEnd('build geometry');
272
279
 
273
- console.log(build_geometry_info(r));
280
+ if (PRINT_VERBOSE_STATS) {
281
+ console.log(build_geometry_info(r));
282
+ }
274
283
 
275
284
  // assign dependencies
276
285
 
@@ -1,44 +1,11 @@
1
1
  import WorkerBuilder from "../../../../../../core/process/worker/WorkerBuilder.js";
2
2
  import { OnDemandWorkerManager } from "../../../../../../core/process/worker/OnDemandWorkerManager.js";
3
3
 
4
- /**
5
- *
6
- * @param {ArrayBuffer} data
7
- * @return {number}
8
- */
9
- function write_to_heap(data) {
10
- const pointer = _create_buffer(data.byteLength);
11
-
12
- Module.HEAP8.set(new Uint8Array(data), pointer); // write to heap
13
-
14
- return pointer;
15
- }
16
-
17
- /**
18
- *
19
- * @param {Uint32Array} data
20
- * @return {number}
21
- */
22
- function write_to_heap_uint32(data) {
23
- return write_to_heap(data.buffer);
24
- }
25
-
26
- /**
27
- *
28
- * @param {Float32Array} data
29
- * @return {number}
30
- */
31
- function write_to_heap_float32(data) {
32
- return write_to_heap(data.buffer);
33
- }
34
4
 
35
5
  export class Metis {
36
6
  constructor() {
37
7
  const wb = new WorkerBuilder();
38
8
  wb.importScript('libs/metis/metis.js');
39
- wb.importFunction("write_to_heap", write_to_heap);
40
- wb.importFunction("write_to_heap_uint32", write_to_heap_uint32);
41
- wb.importFunction("write_to_heap_float32", write_to_heap_float32);
42
9
  wb.addMethod('partition',
43
10
  /**
44
11
  *
@@ -74,6 +41,29 @@ export class Metis {
74
41
  throw new Error(`Edge weight table size must be equal to and adjacency table size * n_constraints, instead #edge_weights=${edge_weights.length}, #adjacency=${adjacency.length}, n_constraints=${ncon}`);
75
42
  }
76
43
 
44
+
45
+ /**
46
+ *
47
+ * @param {ArrayBuffer} data
48
+ * @return {number}
49
+ */
50
+ function write_to_heap(data) {
51
+ const pointer = _create_buffer(data.byteLength);
52
+
53
+ Module.HEAP8.set(new Uint8Array(data), pointer); // write to heap
54
+
55
+ return pointer;
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @param {Uint32Array} data
61
+ * @return {number}
62
+ */
63
+ function write_to_heap_uint32(data) {
64
+ return write_to_heap(data.buffer);
65
+ }
66
+
77
67
  /**
78
68
  * Bind function to be called. Comes from the imported emscripten-compiled js file
79
69
  * @type {function}