@woosh/meep-engine 2.60.1 → 2.62.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 (87) hide show
  1. package/build/meep.cjs +20244 -20262
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +20244 -20262
  4. package/package.json +1 -1
  5. package/src/core/binary/BitSet.js +1 -1
  6. package/src/core/bvh2/BinaryNode.js +16 -13
  7. package/src/core/bvh2/LeafNode.js +6 -3
  8. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js +81 -0
  9. package/src/core/geom/3d/aabb/AABB3.js +24 -36
  10. package/src/core/geom/3d/aabb/aabb3_array_compute_from_sphere.js +22 -0
  11. package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere.js +22 -0
  12. package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere_array.js +11 -0
  13. package/src/core/geom/3d/aabb/aabb3_signed_distance_to_aabb3.js +28 -0
  14. package/src/core/geom/3d/aabb/serializeAABB3Quantized16Uint.js +19 -10
  15. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +30 -182
  16. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.spec.js +27 -1
  17. package/src/core/geom/3d/tetrahedra/delaunay/Cavity.js +3 -4
  18. package/src/core/geom/ConicRay.js +16 -21
  19. package/src/core/geom/ConicRay.spec.js +24 -0
  20. package/src/core/geom/packing/miniball/Miniball.js +68 -117
  21. package/src/core/geom/packing/miniball/Miniball.spec.js +3 -3
  22. package/src/core/geom/packing/miniball/Subspan.js +47 -34
  23. package/src/core/geom/packing/miniball/miniball_compute_quality.js +64 -0
  24. package/src/core/math/bessel_3.js +1 -0
  25. package/src/core/math/random/randomBytes.js +2 -2
  26. package/src/core/math/sqr.js +8 -0
  27. package/src/core/model/node-graph/Connection.js +21 -23
  28. package/src/core/model/node-graph/DataType.js +16 -17
  29. package/src/core/model/node-graph/NodeGraph.js +49 -50
  30. package/src/core/model/node-graph/node/NodeDescription.js +42 -44
  31. package/src/core/model/node-graph/node/NodeInstance.js +59 -60
  32. package/src/core/model/node-graph/node/NodeInstancePortReference.js +27 -29
  33. package/src/core/model/node-graph/node/NodeRegistry.js +16 -18
  34. package/src/core/model/node-graph/node/Port.js +35 -37
  35. package/src/core/model/node-graph/node/parameter/NodeParameterDescription.js +27 -13
  36. package/src/core/path/computePathDirectory.spec.js +8 -0
  37. package/src/core/process/BaseProcess.d.ts +5 -0
  38. package/src/core/process/WatchDog.js +76 -75
  39. package/src/core/process/action/AsynchronousAction.js +24 -22
  40. package/src/core/process/executor/profile/Profile.js +34 -24
  41. package/src/core/process/executor/profile/TraceEvent.js +75 -75
  42. package/src/core/process/worker/OnDemandWorkerManager.js +27 -30
  43. package/src/core/process/worker/WorkerBuilder.js +149 -149
  44. package/src/core/process/worker/WorkerProxy.js +25 -21
  45. package/src/core/process/worker/extractTransferables.js +2 -2
  46. package/src/engine/Engine.js +58 -53
  47. package/src/engine/EngineConfiguration.d.ts +4 -4
  48. package/src/engine/ecs/EntityManager.js +517 -614
  49. package/src/engine/ecs/System.js +2 -2
  50. package/src/engine/ecs/foliage/ecs/Foliage2System.js +3 -0
  51. package/src/engine/ecs/foliage/ecs/InstancedMeshComponent.js +4 -1
  52. package/src/engine/ecs/foliage/ecs/convertInstancedMeshComponents2Entities.js +64 -0
  53. package/src/engine/ecs/foliage/ecs/{InstancedMeshUtils.js → optimizeIndividualMeshesEntitiesToInstances.js} +11 -70
  54. package/src/engine/ecs/transform/Transform.d.ts +7 -5
  55. package/src/engine/ecs/transform/Transform.js +30 -16
  56. package/src/engine/ecs/validateSystem.js +89 -0
  57. package/src/engine/graphics/GraphicsEngine.js +433 -483
  58. package/src/engine/graphics/camera/testClippingPlaneComputation.js +42 -46
  59. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -2
  60. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -2
  61. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +2 -2
  62. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +49 -52
  63. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +52 -56
  64. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +20 -22
  65. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +43 -25
  66. package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +160 -180
  67. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +37 -41
  68. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +63 -67
  69. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +46 -50
  70. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +61 -65
  71. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +48 -52
  72. package/src/engine/graphics/shadows/testShadowMapRendering.js +28 -32
  73. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_lanczos.spec.js +22 -20
  74. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_linear.js +10 -13
  75. package/src/engine/graphics/texture/virtual/VirtualTexture.spec.js +1 -1
  76. package/src/engine/plugin/EnginePluginManager.d.ts +6 -1
  77. package/src/engine/sound/dB2Volume.js +8 -0
  78. package/src/engine/sound/ecs/emitter/SoundEmitter.js +125 -99
  79. package/src/engine/sound/ecs/emitter/SoundEmitterComponentContext.js +4 -42
  80. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +31 -121
  81. package/src/engine/sound/volume2dB.js +8 -0
  82. package/src/generation/theme/ThemeEngine.js +19 -53
  83. package/src/engine/ecs/components/ClingToHeightMap.js +0 -19
  84. package/src/engine/ecs/components/SynchronizePosition.js +0 -15
  85. package/src/engine/ecs/systems/ClingToHeightMapSystem.js +0 -170
  86. package/src/engine/ecs/systems/SynchronizePositionSystem.js +0 -43
  87. package/src/engine/graphics/geometry/bvh/buffered/BVHFromBufferGeometry.js +0 -133
@@ -5,23 +5,24 @@
5
5
  */
6
6
 
7
7
 
8
- import { System } from '../../../ecs/System.js';
9
- import { SoundEmitter } from './SoundEmitter.js';
10
- import { Transform } from '../../../ecs/transform/Transform.js';
11
- import { SoundAssetLoader } from "../../../asset/loaders/SoundAssetLoader.js";
12
- import { GameAssetType } from "../../../asset/GameAssetType.js";
13
- import { BinaryNode } from "../../../../core/bvh2/BinaryNode.js";
14
- import SoundListener from "../SoundListener.js";
15
- import { IncrementalDeltaSet } from "../../../graphics/render/visibility/IncrementalDeltaSet.js";
16
8
  import {
17
- queryBinaryNode_SphereIntersections_Data
18
- } from "../../../../core/bvh2/traversal/queryBinaryNode_SphereIntersections.js";
19
- import { SoundEmitterComponentContext } from "./SoundEmitterComponentContext.js";
20
- import { SoundEmitterFlags } from "./SoundEmitterFlags.js";
21
- import { SoundEmitterChannel } from "./SoundEmitterChannel.js";
22
- import { invokeObjectCompare } from "../../../../core/model/object/invokeObjectCompare.js";
23
- import { tryRotateSingleNode } from "../../../../core/bvh2/transform/tryRotateSingleNode.js";
24
- import { SoundTrackFlags } from "./SoundTrackFlags.js";
9
+ ExplicitBinaryBoundingVolumeHierarchy
10
+ } from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
11
+ import {
12
+ bvh_query_user_data_overlaps_sphere
13
+ } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js";
14
+ import {invokeObjectCompare} from "../../../../core/model/object/invokeObjectCompare.js";
15
+ import {GameAssetType} from "../../../asset/GameAssetType.js";
16
+ import {SoundAssetLoader} from "../../../asset/loaders/SoundAssetLoader.js";
17
+ import {System} from '../../../ecs/System.js';
18
+ import {Transform} from '../../../ecs/transform/Transform.js';
19
+ import {IncrementalDeltaSet} from "../../../graphics/render/visibility/IncrementalDeltaSet.js";
20
+ import SoundListener from "../SoundListener.js";
21
+ import {SoundEmitter} from './SoundEmitter.js';
22
+ import {SoundEmitterChannel} from "./SoundEmitterChannel.js";
23
+ import {SoundEmitterComponentContext} from "./SoundEmitterComponentContext.js";
24
+ import {SoundEmitterFlags} from "./SoundEmitterFlags.js";
25
+ import {SoundTrackFlags} from "./SoundTrackFlags.js";
25
26
 
26
27
  /**
27
28
  * @readonly
@@ -35,21 +36,9 @@ export const SoundEmitterChannels = {
35
36
 
36
37
  /**
37
38
  *
38
- * @type {Map<NodeDescription, number>}
39
- */
40
- const leafCount = new Map();
41
-
42
- /**
43
- *
44
- * @type {SoundEmitterComponentContext[]}
39
+ * @type {number[]}
45
40
  */
46
- const positionalNodes = [];
47
-
48
- /**
49
- *
50
- * @type {number}
51
- */
52
- const OPTIMIZATION_LOOP_LIMIT = 10000;
41
+ const scratch_array = [];
53
42
 
54
43
  export class SoundEmitterSystem extends System {
55
44
  /**
@@ -103,17 +92,10 @@ export class SoundEmitterSystem extends System {
103
92
 
104
93
  /**
105
94
  * Spatial index
106
- * @type {BinaryNode}
107
- * @private
108
- */
109
- this.__bvh = new BinaryNode();
110
-
111
- /**
112
- *
113
- * @type {number}
95
+ * @type {ExplicitBinaryBoundingVolumeHierarchy}
114
96
  * @private
115
97
  */
116
- this.__optimizationPointer = 0;
98
+ this.__bvh = new ExplicitBinaryBoundingVolumeHierarchy();
117
99
 
118
100
  /**
119
101
  * Number of currently linked entities
@@ -226,6 +208,8 @@ export class SoundEmitterSystem extends System {
226
208
  emitter.buildNodes(context);
227
209
  }
228
210
 
211
+ emitter.bvh.link(this.__bvh, entity);
212
+
229
213
  const ctx = new SoundEmitterComponentContext();
230
214
 
231
215
  ctx.system = this;
@@ -240,11 +224,6 @@ export class SoundEmitterSystem extends System {
240
224
 
241
225
  this.data[entity] = ctx;
242
226
 
243
- //attach bvh
244
- this.__bvh.insertNode(ctx.leaf);
245
-
246
- leafCount.clear();
247
-
248
227
  this.__linkedCount++;
249
228
  }
250
229
 
@@ -266,12 +245,9 @@ export class SoundEmitterSystem extends System {
266
245
 
267
246
  ctx.unlink();
268
247
 
269
- ctx.leaf.disconnect();
270
-
271
248
  }
272
249
 
273
-
274
- leafCount.clear();
250
+ emitter.bvh.unlink();
275
251
 
276
252
  this.__linkedCount--;
277
253
  }
@@ -296,13 +272,18 @@ export class SoundEmitterSystem extends System {
296
272
 
297
273
  const listenerPosition = listenerTransform.position;
298
274
 
299
- const matchCount = queryBinaryNode_SphereIntersections_Data(positionalNodes, 0, this.__bvh, listenerPosition.x, listenerPosition.y, listenerPosition.z, 0);
275
+ const matchCount = bvh_query_user_data_overlaps_sphere(
276
+ scratch_array, 0,
277
+ this.__bvh, [listenerPosition.x, listenerPosition.y, listenerPosition.z, 0]
278
+ );
300
279
 
301
280
  for (let i = 0; i < matchCount; i++) {
281
+ const entity = scratch_array[i];
282
+
302
283
  /**
303
284
  * @type {SoundEmitterComponentContext}
304
285
  */
305
- const ctx = positionalNodes[i];
286
+ const ctx = this.data[entity];
306
287
 
307
288
  const emitter = ctx.emitter;
308
289
 
@@ -378,79 +359,8 @@ export class SoundEmitterSystem extends System {
378
359
  }
379
360
 
380
361
  activeSet.finalizeUpdate();
381
-
382
- this.optimize(1, 50);
383
362
  }
384
363
 
385
- /**
386
- *
387
- * @param {number} timeout In milliseconds
388
- * @param {number} iterations Maximum number of steps the optimizer can take
389
- */
390
- optimize(timeout, iterations) {
391
- let ctx;
392
-
393
- let i = 0;
394
- let j = 0;
395
-
396
- if (this.__linkedCount <= 0) {
397
- //nothing to optimize
398
- return;
399
- }
400
-
401
- const data = this.data;
402
- const length = data.length;
403
-
404
- const t0 = performance.now();
405
-
406
-
407
- LOOP_MAIN: while (j < OPTIMIZATION_LOOP_LIMIT) {
408
-
409
- j++;
410
-
411
- //find next entity
412
- while (((ctx = data[this.__optimizationPointer]) === undefined)) {
413
-
414
- this.__optimizationPointer++;
415
-
416
- j++;
417
-
418
- if (this.__optimizationPointer >= length) {
419
- this.__optimizationPointer = 0;
420
-
421
- continue LOOP_MAIN;
422
- }
423
-
424
- }
425
-
426
- let n = ctx.leaf.parentNode;
427
-
428
- while (n !== null) {
429
-
430
- tryRotateSingleNode(n, leafCount);
431
-
432
- i++
433
-
434
- if (Math.random() < 0.5) {
435
- //random exit
436
- break;
437
- }
438
-
439
- n = n.parentNode;
440
- }
441
-
442
- this.__optimizationPointer++;
443
-
444
- const t1 = performance.now();
445
-
446
- const time = t1 - t0;
447
-
448
- if (time > timeout || i > iterations) {
449
-
450
- break;
451
- }
452
- }
453
- }
454
364
 
455
365
 
456
366
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Convert percentage volume to decibel
3
+ * @param {number} volume
4
+ * @returns {number}
5
+ */
6
+ function volume2dB(volume) {
7
+ return 20 * Math.log10(volume);
8
+ }
@@ -1,25 +1,23 @@
1
- import { QuadTreeNode } from "../../core/geom/2d/quad-tree/QuadTreeNode.js";
2
- import { assert } from "../../core/assert.js";
3
- import { seededRandom } from "../../core/math/random/seededRandom.js";
4
- import { TerrainLayerRuleAggregator } from "./TerrainLayerRuleAggregator.js";
5
- import { Sampler2D } from "../../engine/graphics/texture/sampler/Sampler2D.js";
1
+ import {assert} from "../../core/assert.js";
2
+ import {binarySearchLowIndex} from "../../core/collection/array/binarySearchLowIndex.js";
3
+ import {HashMap} from "../../core/collection/map/HashMap.js";
4
+ import {QuadTreeNode} from "../../core/geom/2d/quad-tree/QuadTreeNode.js";
5
+ import {randomFloatBetween} from "../../core/math/random/randomFloatBetween.js";
6
+ import {seededRandom} from "../../core/math/random/seededRandom.js";
7
+ import {number_compare_ascending} from "../../core/primitives/numbers/number_compare_ascending.js";
8
+ import Future from "../../core/process/Future.js";
6
9
  import Task from "../../core/process/task/Task.js";
7
- import { TaskSignal } from "../../core/process/task/TaskSignal.js";
8
10
  import TaskGroup from "../../core/process/task/TaskGroup.js";
9
- import Future from "../../core/process/Future.js";
10
- import { optimizeIndividualMeshesEntitiesToInstances } from "../../engine/ecs/foliage/ecs/InstancedMeshUtils.js";
11
- import TaskState from "../../core/process/task/TaskState.js";
12
- import { HashMap } from "../../core/collection/map/HashMap.js";
13
- import { TerrainLayer } from "../../engine/ecs/terrain/ecs/layers/TerrainLayer.js";
14
- import { TerrainFlags } from "../../engine/ecs/terrain/ecs/TerrainFlags.js";
15
- import { binarySearchLowIndex } from "../../core/collection/array/binarySearchLowIndex.js";
16
- import { randomFloatBetween } from "../../core/math/random/randomFloatBetween.js";
17
- import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
18
- import { actionTask } from "../../core/process/task/util/actionTask.js";
19
- import { countTask } from "../../core/process/task/util/countTask.js";
20
- import { emptyTask } from "../../core/process/task/util/emptyTask.js";
21
- import { futureTask } from "../../core/process/task/util/futureTask.js";
22
- import { number_compare_ascending } from "../../core/primitives/numbers/number_compare_ascending.js";
11
+ import {TaskSignal} from "../../core/process/task/TaskSignal.js";
12
+ import {actionTask} from "../../core/process/task/util/actionTask.js";
13
+ import {countTask} from "../../core/process/task/util/countTask.js";
14
+ import {emptyTask} from "../../core/process/task/util/emptyTask.js";
15
+ import {futureTask} from "../../core/process/task/util/futureTask.js";
16
+ import {TerrainLayer} from "../../engine/ecs/terrain/ecs/layers/TerrainLayer.js";
17
+ import {TerrainFlags} from "../../engine/ecs/terrain/ecs/TerrainFlags.js";
18
+ import {obtainTerrain} from "../../engine/ecs/terrain/util/obtainTerrain.js";
19
+ import {Sampler2D} from "../../engine/graphics/texture/sampler/Sampler2D.js";
20
+ import {TerrainLayerRuleAggregator} from "./TerrainLayerRuleAggregator.js";
23
21
 
24
22
  /**
25
23
  *
@@ -530,39 +528,7 @@ export class ThemeEngine {
530
528
  terrain.buildLightMap().then(resolve, reject);
531
529
  }), 'Building Lightmap');
532
530
 
533
- const optimization_task = new TaskGroup([]);
534
-
535
- const tOptimizeMeshes = new Task({
536
- name: 'Mesh optimization',
537
- initializer(task, executor) {
538
-
539
- const o = optimizeIndividualMeshesEntitiesToInstances(ecd, 10);
540
-
541
- optimization_task.addChildren(o.tasks);
542
-
543
- executor.runGroup(optimization_task);
544
- },
545
- cycleFunction() {
546
- const state = optimization_task.state.getValue();
547
-
548
- if (state === TaskState.RUNNING) {
549
- return TaskSignal.Yield;
550
- } else if (state === TaskState.FAILED) {
551
- return TaskSignal.EndFailure;
552
- } else if (state === TaskState.SUCCEEDED) {
553
- return TaskSignal.EndSuccess;
554
- } else {
555
- return TaskSignal.Continue;
556
- }
557
- },
558
- computeProgress() {
559
- return optimization_task.computeProgress();
560
- }
561
- });
562
-
563
- tOptimizeMeshes.estimatedDuration = 5;
564
-
565
- return new TaskGroup([tLightMap, tOptimizeMeshes]);
531
+ return new TaskGroup([tLightMap]);
566
532
  }
567
533
 
568
534
  /**
@@ -1,19 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 1/10/2014
4
- * Time: 21:29
5
- */
6
- import Vector3 from "../../../core/geom/Vector3.js";
7
-
8
- function ClingToHeightMap(options) {
9
- if (options === void 0) {
10
- options = {};
11
- }
12
- this.normalAlign = options.normalAlign !== void 0 ? options.normalAlign : false;
13
- this.sampleCount = options.sampleCount !== void 0 ? options.sampleCount : 1;
14
- this.samplingRadius = options.samplingRadius !== void 0 ? options.samplingRadius : 0;
15
- const inf = Number.POSITIVE_INFINITY;
16
- this.__prevPosition = new Vector3(inf, inf, inf);
17
- }
18
-
19
- export default ClingToHeightMap;
@@ -1,15 +0,0 @@
1
- /**
2
- * Created by Alex on 05/02/2015.
3
- */
4
- function SynchronizePosition(options) {
5
- this.targetEntity = options.targetEntity;
6
- this.x = options.x !== void 0 ? options.x : true;
7
- this.y = options.y !== void 0 ? options.y : true;
8
- this.z = options.z !== void 0 ? options.z : true;
9
- }
10
-
11
- SynchronizePosition.typeName = "SynchronizePosition";
12
-
13
- SynchronizePosition.serializable = false;
14
-
15
- export default SynchronizePosition;
@@ -1,170 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 1/10/2014
4
- * Time: 21:32
5
- */
6
- import { System } from '../System.js';
7
- import ClingToHeightMap from '../components/ClingToHeightMap.js';
8
- import { Transform } from '../transform/Transform.js';
9
- import { Euler as ThreeEuler, Matrix4 as ThreeMatrix4, Vector2 as ThreeVector2, Vector3 as ThreeVector3 } from 'three';
10
-
11
- class ClingToHeightMapSystem extends System {
12
- constructor(grid) {
13
- super();
14
-
15
- this.dependencies = [ClingToHeightMap];
16
- //
17
- this.entityManager = null;
18
- this.grid = grid;
19
- this.update = function () {
20
- const uv = new ThreeVector2();
21
- let u, v;
22
- const euler = new ThreeEuler();
23
- const normal = new ThreeVector3();
24
- const m = new ThreeMatrix4();
25
- const vUp = new ThreeVector3(0, 1, 0);
26
- const vOrigin = new ThreeVector3();
27
-
28
- function update(timeDelta) {
29
- const entityManager = this.entityManager;
30
- const terrain = this.terrain;
31
- if (terrain === void 0) {
32
- return 0;
33
- }
34
- const grid = this.grid;
35
- const heightSampler = terrain.samplerHeight;
36
- const samplerNormal = terrain.samplerNormal;
37
- entityManager.traverseEntities([ClingToHeightMap, Transform], function (clingon, transform) {
38
- const position = transform.global.position;
39
- if (position.equals(clingon.__prevPosition)) {
40
- return; //already correct placement
41
- } else {
42
- clingon.__prevPosition.copy(position);
43
- }
44
- grid.pointWorld2Grid(position, uv);
45
- uv.divide(grid.size);
46
- u = uv.x;
47
- v = uv.y;
48
- position.y = heightSampler.sample(u, v);
49
- transform.setGlobalPosition(position.x, position.y, position.z);
50
- //
51
- if (clingon.normalAlign) {
52
- if (clingon.samplingRadius !== 0 && clingon.sampleCount > 1) {
53
- //more than one sample is to be used to compute normal by averaging
54
- sampleNormalOnDisk(clingon.sampleCount, clingon.samplingRadius, samplerNormal, uv, normal);
55
- } else {
56
- samplerNormal.sample(u, v, normal);
57
- }
58
- vOrigin.set(0, 0, 0);
59
- vUp.set(0, 1, 0);
60
- //normal.set(-normal.x, normal.z, -normal.y);
61
- //
62
- m.identity();
63
- m.lookAt(normal, vOrigin, vUp);
64
- euler.setFromRotationMatrix(m, "XZY");
65
- if (Math.abs(euler.y) + 0.0001 >= Math.PI) {
66
- euler.z = -euler.z;
67
- }
68
- euler.y = 0; //drop rotation orthogonal to terrain
69
- transform.rotation.setFromEuler(euler);
70
- }
71
- });
72
- }
73
-
74
- return update;
75
- }();
76
- }
77
-
78
- remove(component) {
79
- }
80
-
81
- add(component) {
82
- }
83
-
84
- clearCache() {
85
- const em = this.entityManager;
86
- em.traverseEntities([ClingToHeightMap], function (clingon) {
87
- clingon.__prevPosition.set(Number.NaN, Number.NaN, Number.NaN);
88
- });
89
- }
90
- }
91
-
92
-
93
- const sampleNormalOnDisk = (function () {
94
- const tempNormal = new ThreeVector3();
95
- const offset = new ThreeVector2();
96
- const PI2 = Math.PI * 2;
97
-
98
- //TODO consider plane-fitting algorithm from: http://www.ilikebigbits.com/blog/2015/3/2/plane-from-points
99
- /*
100
- // source: http://www.ilikebigbits.com/blog/2015/3/2/plane-from-points
101
- // @author Emil Ernerfeldt
102
- // Constructs a plane from a collection of points
103
- // so that the summed squared distance to all points is minimzized
104
- fn plane_from_points(points: &[Vec3]) -> Plane {
105
- let n = points.len();
106
- assert!(n >= 3, "At least three points required");
107
-
108
- let mut sum = Vec3{x:0.0, y:0.0, z:0.0};
109
- for p in points {
110
- sum = &sum + &p;
111
- }
112
- let centroid = &sum * (1.0 / (n as f64));
113
-
114
- // Calc full 3x3 covariance matrix, excluding symmetries:
115
- let mut xx = 0.0; let mut xy = 0.0; let mut xz = 0.0;
116
- let mut yy = 0.0; let mut yz = 0.0; let mut zz = 0.0;
117
-
118
- for p in points {
119
- let r = p - &centroid;
120
- xx += r.x * r.x;
121
- xy += r.x * r.y;
122
- xz += r.x * r.z;
123
- yy += r.y * r.y;
124
- yz += r.y * r.z;
125
- zz += r.z * r.z;
126
- }
127
-
128
- let det_x = yy*zz - yz*yz;
129
- let det_y = xx*zz - xz*xz;
130
- let det_z = xx*yy - xy*xy;
131
-
132
- let det_max = max3(det_x, det_y, det_z);
133
- assert!(det_max > 0.0, 'The points don't span a plane");
134
-
135
- // Pick path with best conditioning:
136
- let dir =
137
- if det_max == det_x {
138
- let a = (xz*yz - xy*zz) / det_x;
139
- let b = (xy*yz - xz*yy) / det_x;
140
- Vec3{x: 1.0, y: a, z: b}
141
- } else if det_max == det_y {
142
- let a = (yz*xz - xy*zz) / det_y;
143
- let b = (xy*xz - yz*xx) / det_y;
144
- Vec3{x: a, y: 1.0, z: b}
145
- } else {
146
- let a = (yz*xy - xz*yy) / det_z;
147
- let b = (xz*xy - yz*xx) / det_z;
148
- Vec3{x: a, y: b, z: 1.0}
149
- };
150
-
151
- plane_from_point_and_normal(&centroid, &normalize(dir))
152
- }
153
- */
154
- function sampleNormalOnDisk(sampleCount, radius, sampler, origin, result) {
155
- const radiusU = radius / sampler.width;
156
- const radiusV = radius / sampler.height;
157
- result.set(0, 0, 0);
158
- for (let i = 0; i < sampleCount; i++) {
159
- const angle = PI2 * (i / sampleCount);
160
- offset.set(radiusU * Math.cos(angle), radiusV * Math.sin(angle));
161
- sampler.sample(origin.x + offset.x, origin.y + offset.y, tempNormal);
162
- result.add(tempNormal);
163
- }
164
- result.normalize();
165
- }
166
-
167
- return sampleNormalOnDisk;
168
- })();
169
-
170
- export default ClingToHeightMapSystem;
@@ -1,43 +0,0 @@
1
- /**
2
- * Created by Alex on 05/02/2015.
3
- */
4
- import { System } from '../System.js';
5
- import SynchronizePosition from '../components/SynchronizePosition.js';
6
- import { Transform } from '../transform/Transform.js';
7
-
8
-
9
- class SynchronizePositionSystem extends System {
10
- constructor() {
11
- super();
12
-
13
- this.dependencies = [SynchronizePosition];
14
-
15
- this.entityManager = null;
16
- }
17
-
18
- update(timeDelta) {
19
- const em = this.entityManager;
20
- const ecd = em.dataset;
21
-
22
- if (ecd === null) {
23
- return;
24
- }
25
-
26
- ecd.traverseEntities([SynchronizePosition, Transform], function (sync, transform) {
27
- const targetEntity = sync.targetEntity;
28
- const targetTransform = ecd.getComponent(targetEntity, Transform);
29
- if (sync.x) {
30
- transform.position.x = targetTransform.position.x;
31
- }
32
- if (sync.y) {
33
- transform.position.y = targetTransform.position.y;
34
- }
35
- if (sync.z) {
36
- transform.position.z = targetTransform.position.z;
37
- }
38
- });
39
- }
40
- }
41
-
42
-
43
- export default SynchronizePositionSystem;