@woosh/meep-engine 2.53.0 → 2.55.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 (149) hide show
  1. package/package.json +1 -1
  2. package/src/core/__module.js +1 -1
  3. package/src/core/cache/Cache.js +1 -1
  4. package/src/core/collection/Stack.js +11 -14
  5. package/src/core/collection/array/array_contains_duplicates.js +5 -2
  6. package/src/core/collection/array/array_contains_duplicates.spec.js +14 -0
  7. package/src/core/collection/array/array_copy_entire.js +6 -11
  8. package/src/core/collection/array/array_get_index_in_range.js +5 -0
  9. package/src/core/collection/array/array_get_index_in_range.spec.js +16 -0
  10. package/src/core/collection/array/groupArrayBy.js +1 -1
  11. package/src/core/collection/array/isArrayEqual.js +4 -1
  12. package/src/core/collection/array/randomizeArrayElementOrder.js +1 -0
  13. package/src/core/collection/array/randomizeArrayElementOrder.spec.js +27 -0
  14. package/src/core/collection/heap/Uin32Heap.spec.js +64 -0
  15. package/src/core/collection/heap/Uint32Heap.js +6 -2
  16. package/src/core/collection/list/List.js +1 -0
  17. package/src/core/collection/{HashMap.js → map/HashMap.js} +10 -10
  18. package/src/core/collection/{HashMap.spec.js → map/HashMap.spec.js} +1 -1
  19. package/src/core/collection/{ObservedMap.js → map/ObservedMap.js} +1 -1
  20. package/src/core/collection/{HashSet.js → set/HashSet.js} +4 -3
  21. package/src/core/collection/{Set.d.ts → set/Set.d.ts} +1 -1
  22. package/src/core/collection/{Set.js → set/Set.js} +17 -14
  23. package/src/core/geom/2d/aabb/AABB2.js +1 -1
  24. package/src/core/geom/3d/aabb/AABB3.js +3 -1
  25. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_calc_edges.js +1 -1
  26. package/src/core/model/ObservedInteger.js +12 -7
  27. package/src/core/model/ObservedString.js +10 -8
  28. package/src/core/model/node-graph/visual/NodeGraphVisualData.js +1 -1
  29. package/src/core/model/object/ImmutableObjectPool.js +1 -1
  30. package/src/core/model/reactive/evaluation/MultiPredicateEvaluator.js +1 -1
  31. package/src/engine/EngineConfiguration.js +24 -25
  32. package/src/engine/asset/AssetManager.js +3 -3
  33. package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
  34. package/src/engine/ecs/EntityBlueprint.js +10 -14
  35. package/src/engine/ecs/EntityComponentDataset.spec.js +77 -0
  36. package/src/engine/ecs/animation/AnimationSerializationAdapter.js +2 -5
  37. package/src/engine/ecs/components/Motion.js +0 -27
  38. package/src/engine/ecs/components/MotionSerializationAdapter.js +26 -0
  39. package/src/engine/ecs/components/PropertySet.js +0 -29
  40. package/src/engine/ecs/components/PropertySetSerializationAdapter.js +29 -0
  41. package/src/engine/ecs/components/SerializationMetadata.js +0 -28
  42. package/src/engine/ecs/components/SerializationMetadataSerializationAdapter.js +26 -0
  43. package/src/engine/ecs/components/Steering.js +0 -35
  44. package/src/engine/ecs/components/SteeringSerializationAdapter.js +34 -0
  45. package/src/engine/ecs/components/Tag.js +6 -102
  46. package/src/engine/ecs/components/TagSerializationAdapter.js +44 -0
  47. package/src/engine/ecs/components/TagSerializationUpgrader_0_1.js +18 -0
  48. package/src/engine/ecs/components/Timer.js +1 -1
  49. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.js +1 -1
  50. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleCooldownDescription.js +10 -14
  51. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescription.js +31 -39
  52. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescriptionTable.js +1 -1
  53. package/src/engine/ecs/dynamic_actions/{DynamicRuleDescriptionTable.spec.js → rules/DynamicRuleDescriptionTable.spec.js} +12 -12
  54. package/src/engine/ecs/foliage/ecs/InstancedMeshSerializationAdapter.js +2 -5
  55. package/src/engine/ecs/fow/serialization/FogOfWarRevealerSerializationAdapter.js +2 -5
  56. package/src/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +5 -8
  57. package/src/engine/ecs/gui/GUIElementSerializationAdapter.js +2 -5
  58. package/src/engine/ecs/gui/hud/HeadsUpDisplaySerializationAdapter.js +3 -6
  59. package/src/engine/ecs/gui/position/ViewportPosition.js +2 -5
  60. package/src/engine/ecs/ik/IKConstraint.js +95 -0
  61. package/src/engine/ecs/ik/InverseKinematics.js +10 -169
  62. package/src/engine/ecs/ik/InverseKinematicsSerializationAdapter.js +72 -0
  63. package/src/engine/ecs/speaker/Voice.js +5 -8
  64. package/src/engine/ecs/speaker/VoiceSystem.js +15 -19
  65. package/src/engine/ecs/speaker/lines/LineDescription.js +20 -25
  66. package/src/engine/ecs/speaker/lines/sets/LineSetDescription.js +15 -19
  67. package/src/engine/ecs/storage/binary/BinaryClassSerializationAdapter.js +7 -0
  68. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +1 -1
  69. package/src/engine/ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js +6 -9
  70. package/src/engine/ecs/team/TeamSerializationAdapter.js +2 -5
  71. package/src/engine/ecs/terrain/ecs/Terrain.spec.js +5 -0
  72. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrain.js +23 -21
  73. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSerializationAdapter.js +2 -5
  74. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +2 -40
  75. package/src/engine/ecs/terrain/overlay/TerrainOverlay.spec.js +6 -0
  76. package/src/engine/ecs/terrain/serialization/TerrainSerializationAdapter.js +7 -10
  77. package/src/engine/ecs/terrain/tiles/TerrainTile.js +79 -76
  78. package/src/engine/ecs/terrain/tiles/TerrainTile.spec.js +25 -0
  79. package/src/engine/ecs/tooltip/TooltipComponent.spec.js +47 -0
  80. package/src/engine/ecs/tooltip/TooltipComponentSerializationAdapter.js +2 -5
  81. package/src/engine/ecs/transform/Transform.spec.js +52 -0
  82. package/src/engine/ecs/transform/TransformSerializationAdapter.js +2 -5
  83. package/src/engine/ecs/transform-attachment/TransformAttachment.js +18 -19
  84. package/src/engine/graphics/ecs/animation/AnimationController.js +20 -129
  85. package/src/engine/graphics/ecs/animation/AnimationControllerSerializationAdapter.js +27 -0
  86. package/src/engine/graphics/ecs/animation/AnimationRule.js +79 -0
  87. package/src/engine/graphics/ecs/animation/animator/graph/AnimationGraphSerializationAdapter.js +9 -11
  88. package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/AnimationGraphDefinitionSerializationAdapter.js +3 -5
  89. package/src/engine/graphics/ecs/camera/serialization/CameraSerializationAdapter.js +2 -5
  90. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationAdapter.js +2 -6
  91. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLander.js +3 -15
  92. package/src/engine/graphics/ecs/decal/v2/DecalSerializationAdapter.js +2 -4
  93. package/src/engine/graphics/ecs/highlight/HighlightSerializationAdapter.js +2 -5
  94. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +1 -1
  95. package/src/engine/graphics/ecs/light/LightSerializationAdapter.js +2 -5
  96. package/src/engine/graphics/ecs/mesh/serialization/MeshSerializationAdapter.js +2 -5
  97. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +3 -0
  98. package/src/engine/graphics/ecs/mesh-v2/render/adapters/InstancedRendererAdapter.js +1 -1
  99. package/src/engine/graphics/ecs/water/WaterSerializationAdapter.js +2 -5
  100. package/src/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.js +1 -1
  101. package/src/engine/graphics/impostors/octahedral/ImpostorBaker.js +1 -1
  102. package/src/engine/graphics/material/manager/MaterialManager.js +1 -1
  103. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -1
  104. package/src/engine/graphics/particles/node-based/codegen/CodeContext.js +1 -1
  105. package/src/engine/graphics/particles/particular/engine/emitter/serde/ParameterLookupTableSerializationAdapter.js +2 -5
  106. package/src/engine/graphics/particles/particular/engine/emitter/serde/ParticleEmitterSerializationAdapter.js +2 -5
  107. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.js +1 -1
  108. package/src/engine/graphics/texture/atlas/ManagedTextureAtlas.js +1 -1
  109. package/src/engine/graphics/texture/sampler/serialization/Sampler2DSerializationAdapter.js +2 -5
  110. package/src/engine/grid/grid2transform/GridPosition2Transform.js +11 -13
  111. package/src/engine/grid/grid2transform/GridPosition2TransformSerializationAdapter.js +3 -5
  112. package/src/engine/grid/obstacle/GridObstacleSerializationAdapter.js +2 -5
  113. package/src/engine/grid/position/GridPositionSerializationAdapter.js +2 -5
  114. package/src/engine/grid/transform2grid/Transform2GridPosition.js +10 -13
  115. package/src/engine/input/devices/KeyboardDevice.js +5 -2
  116. package/src/engine/input/devices/KeyboardDevice.spec.js +12 -0
  117. package/src/engine/input/devices/PointerDevice.js +5 -1
  118. package/src/engine/input/ecs/components/Input.js +37 -11
  119. package/src/engine/input/ecs/ism/InputBinding.js +30 -12
  120. package/src/engine/intelligence/behavior/ecs/BehaviorComponentSerializationAdapter.js +7 -10
  121. package/src/engine/intelligence/behavior/ecs/WaitForEventBehaviorSerializationAdapter.js +2 -5
  122. package/src/engine/intelligence/behavior/primitive/FailingBehaviorSerializationAdapter.js +2 -6
  123. package/src/engine/intelligence/behavior/primitive/SucceedingBehaviorSerializationAdapter.js +2 -5
  124. package/src/engine/intelligence/blackboard/BlackboardSerializationAdapter.js +2 -5
  125. package/src/engine/knowledge/database/StaticKnowledgeDatabase.js +12 -13
  126. package/src/engine/knowledge/database/StaticKnowledgeDatabase.spec.js +23 -0
  127. package/src/engine/navigation/ecs/components/PathSerializationAdapter.js +2 -5
  128. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationAdapter.js +2 -5
  129. package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +25 -0
  130. package/src/engine/options/OptionAbstract.js +6 -5
  131. package/src/engine/options/OptionGroup.js +13 -25
  132. package/src/engine/options/OptionGroup.spec.js +61 -0
  133. package/src/engine/platform/EnginePlatform.js +0 -4
  134. package/src/engine/save/storage/InMemoryStorage.js +3 -2
  135. package/src/engine/sound/ecs/SoundController.js +2 -6
  136. package/src/engine/sound/ecs/SoundListener.js +3 -21
  137. package/src/engine/sound/ecs/emitter/SoundEmitterSerializationAdapter.js +2 -6
  138. package/src/generation/theme/ThemeEngine.js +1 -1
  139. package/src/core/collection/LazyStream.js +0 -23
  140. package/src/core/collection/LazyStream.spec.js +0 -13
  141. package/src/core/collection/heap/BinaryHeap.js +0 -153
  142. package/src/engine/InputEngine.js +0 -94
  143. package/src/engine/PointerLock.js +0 -60
  144. package/src/engine/ecs/components/GeometryBVH.js +0 -44
  145. package/src/engine/ecs/systems/GeometryBVHSystem.js +0 -36
  146. package/src/engine/ecs/terrain/ecs/layers/loadLegacyTerrainLayers.js +0 -99
  147. package/src/engine/ecs/terrain/ecs/splat/loadLegacyTerrainSplats.js +0 -73
  148. /package/src/core/collection/{HashMap.d.ts → map/HashMap.d.ts} +0 -0
  149. /package/src/core/collection/{HashSet.d.ts → set/HashSet.d.ts} +0 -0
@@ -0,0 +1,61 @@
1
+ import { OptionGroup } from "./OptionGroup.js";
2
+ import { noop } from "../../core/function/Functions.js";
3
+ import { InMemoryStorage } from "../save/storage/InMemoryStorage.js";
4
+
5
+ test("constructor", () => {
6
+ const group = new OptionGroup("x");
7
+
8
+ expect(group.id).toEqual("x");
9
+ });
10
+
11
+ test("resolve non-existent", () => {
12
+
13
+ const group = new OptionGroup("x");
14
+
15
+ expect(() => group.resolve(['a'])).toThrow();
16
+
17
+ });
18
+
19
+ test("add/get", () => {
20
+ const group = new OptionGroup("x");
21
+
22
+ group.add("a", noop, noop, {});
23
+
24
+ expect(group.getChildById('a')).toBeDefined();
25
+ });
26
+
27
+ test("to/from JSON", () => {
28
+ const group = new OptionGroup("x");
29
+
30
+ const writer = jest.fn();
31
+
32
+ group.add("a", () => 7, writer, {});
33
+
34
+ const json = group.toJSON();
35
+
36
+ expect(json).toEqual({ a: 7 });
37
+
38
+ group.fromJSON({ a: 13 });
39
+
40
+ expect(writer).toHaveBeenCalledTimes(1);
41
+ expect(writer).toHaveBeenCalledWith(13);
42
+ });
43
+
44
+
45
+ test("attach to storage", async () => {
46
+ const group = new OptionGroup("x");
47
+
48
+ const op_a = {
49
+ value: 3
50
+ };
51
+
52
+ group.add('a', () => op_a.value, v => op_a.value = v, {});
53
+
54
+ const storage = new InMemoryStorage();
55
+
56
+ storage.store('options', JSON.stringify({ a: 13 }));
57
+
58
+ await group.attachToStorage('options', storage);
59
+
60
+ expect(op_a.value).toEqual(13);
61
+ });
@@ -1,8 +1,4 @@
1
1
  export class EnginePlatform {
2
- constructor() {
3
- }
4
-
5
-
6
2
  /**
7
3
  * @returns {Storage}
8
4
  */
@@ -1,10 +1,11 @@
1
1
  import Storage from "../Storage.js";
2
2
  import { collectIteratorValueToArray } from "../../../core/collection/collectIteratorValueToArray.js";
3
+ import { noop } from "../../../core/function/Functions.js";
3
4
 
4
5
  export class InMemoryStorage extends Storage {
5
6
  #data = new Map();
6
7
 
7
- store(key, value, resolve, reject, progress) {
8
+ store(key, value, resolve=noop, reject, progress) {
8
9
  this.#data.set(key, value);
9
10
 
10
11
  resolve();
@@ -14,7 +15,7 @@ export class InMemoryStorage extends Storage {
14
15
  resolve(this.#data.get(key));
15
16
  }
16
17
 
17
- remove(key, resolve, reject) {
18
+ remove(key, resolve=noop, reject) {
18
19
  this.#data.delete(key);
19
20
 
20
21
  resolve();
@@ -146,12 +146,8 @@ export default SoundController;
146
146
 
147
147
 
148
148
  export class SoundControllerSerializationAdapter extends BinaryClassSerializationAdapter {
149
- constructor() {
150
- super();
151
-
152
- this.klass = SoundController;
153
- this.version = 0;
154
- }
149
+ klass = SoundController;
150
+ version = 0;
155
151
 
156
152
  /**
157
153
  *
@@ -42,26 +42,8 @@ export default SoundListener;
42
42
 
43
43
 
44
44
  export class SoundListenerSerializationAdapter extends BinaryClassSerializationAdapter {
45
- constructor() {
46
- super();
45
+ klass = SoundListener;
46
+ version = 0;
47
47
 
48
- this.klass = SoundListener;
49
- this.version = 0;
50
- }
51
-
52
- /**
53
- *
54
- * @param {BinaryBuffer} buffer
55
- * @param {SoundListener} value
56
- */
57
- serialize(buffer, value) {
58
- }
59
-
60
- /**
61
- *
62
- * @param {BinaryBuffer} buffer
63
- * @param {SoundListener} value
64
- */
65
- deserialize(buffer, value) {
66
- }
48
+ // NO-OP
67
49
  }
@@ -3,13 +3,9 @@ import { SoundEmitter } from "./SoundEmitter.js";
3
3
  import { SoundTrack } from "./SoundTrack.js";
4
4
 
5
5
  export class SoundEmitterSerializationAdapter extends BinaryClassSerializationAdapter {
6
- constructor() {
7
- super();
8
-
9
- this.klass = SoundEmitter;
10
- this.version = 2;
11
- }
12
6
 
7
+ klass = SoundEmitter;
8
+ version = 2;
13
9
 
14
10
  /**
15
11
  *
@@ -10,7 +10,7 @@ import TaskGroup from "../../core/process/task/TaskGroup.js";
10
10
  import Future from "../../core/process/Future.js";
11
11
  import { optimizeIndividualMeshesEntitiesToInstances } from "../../engine/ecs/foliage/ecs/InstancedMeshUtils.js";
12
12
  import TaskState from "../../core/process/task/TaskState.js";
13
- import { HashMap } from "../../core/collection/HashMap.js";
13
+ import { HashMap } from "../../core/collection/map/HashMap.js";
14
14
  import { TerrainLayer } from "../../engine/ecs/terrain/ecs/layers/TerrainLayer.js";
15
15
  import { TerrainFlags } from "../../engine/ecs/terrain/ecs/TerrainFlags.js";
16
16
  import { binarySearchLowIndex } from "../../core/collection/array/binarySearchLowIndex.js";
@@ -1,23 +0,0 @@
1
- /**
2
- * @template A,B
3
- * @param {A[]} source
4
- * @param {function(A,index:number):B} transformer
5
- * @returns {B[]}
6
- */
7
- export function lazyArrayMap(source, transformer) {
8
- return new Proxy(source, {
9
- get(target, p, receiver) {
10
- if (/^([0-9]+)$/.test(p)) {
11
-
12
- const targetElement = target[p];
13
-
14
- const resultElement = transformer(targetElement, p);
15
-
16
- return resultElement;
17
- } else {
18
-
19
- return target[p];
20
- }
21
- }
22
- });
23
- }
@@ -1,13 +0,0 @@
1
- import { lazyArrayMap } from "./LazyStream.js";
2
-
3
- test('lazyArrayMap', () => {
4
- const source = [1, 2, 3];
5
-
6
- const map = lazyArrayMap(source, a => a * 2);
7
-
8
- expect(map.length).toBe(source.length);
9
-
10
- for (let i = 0; i < source.length; i++) {
11
- expect(map[i]).toBe(source[i] * 2);
12
- }
13
- });
@@ -1,153 +0,0 @@
1
- /**
2
- * @deprecated use {@link FastBinaryHeap} instead
3
- * @param scoreFunction
4
- * @constructor
5
- */
6
- function BinaryHeap(scoreFunction) {
7
- this.content = [];
8
- this.hash = [];
9
- this.scoreFunction = scoreFunction;
10
- }
11
-
12
- BinaryHeap.prototype = {
13
- push: function (element) {
14
- const content = this.content;
15
- const length = content.length;
16
- // Add the new element to the end of the array.
17
- content.push(element);
18
- //update hash
19
- this.hash[element] = length;
20
-
21
- // Allow it to sink down.
22
- this.sinkDown(length);
23
- },
24
- pop: function () {
25
- // Store the first element so we can return it later.
26
- const content = this.content;
27
- const hash = this.hash;
28
- const result = content[0];
29
- //update hash
30
- delete hash[result];
31
- // Get the element at the end of the array.
32
- const end = content.pop();
33
- // If there are any elements left, put the end element at the
34
- // start, and let it bubble up.
35
- const length = content.length;
36
- if (length > 0) {
37
- content[0] = end;
38
- hash[end] = 0;
39
- this.bubbleUp(0);
40
- }
41
- return result;
42
- },
43
- contains: function (node) {
44
- return this.hash[node] !== void 0;
45
- },
46
- remove: function (node) {
47
-
48
- const length = this.content.length;
49
- const i = this.hash[node];
50
-
51
- // When it is found, the process seen in 'pop' is repeated
52
- // to fill up the hole.
53
- const end = this.content.pop();
54
- if (i !== length) {
55
- this.content[i] = end;
56
-
57
- if (this.scoreFunction(end) < this.scoreFunction(node)) {
58
- this.sinkDown(i);
59
- } else {
60
- this.bubbleUp(i);
61
- }
62
- }
63
- },
64
- size: function () {
65
- return this.content.length;
66
- },
67
- rescoreElement: function (node) {
68
- this.sinkDown(this.hash[node]);
69
- },
70
- sinkDown: function (n) {
71
- // Fetch the element that has to be sunk.
72
- const content = this.content;
73
- const hash = this.hash;
74
- const element = content[n];
75
-
76
- // When at 0, an element can not sink any further.
77
- while (n > 0) {
78
-
79
- // Compute the parent element's index, and fetch it.
80
- const parentN = ((n + 1) >> 1) - 1,
81
- parent = content[parentN];
82
- // Swap the elements if the parent is greater.
83
- if (this.scoreFunction(element) < this.scoreFunction(parent)) {
84
- content[parentN] = element;
85
- content[n] = parent;
86
- //update hash
87
- hash[element] = parentN;
88
- hash[parent] = n;
89
- // Update 'n' to continue at the new position.
90
- n = parentN;
91
- }
92
- // Found a parent that is less, no need to sink any further.
93
- else {
94
- break;
95
- }
96
- }
97
- },
98
- bubbleUp: function (n) {
99
- // Look up the target element and its score.
100
- const content = this.content;
101
- const hash = this.hash;
102
- const scoreFunction = this.scoreFunction;
103
- const length = content.length,
104
- element = content[n],
105
- elemScore = scoreFunction(element);
106
-
107
- for (; ;) {
108
- // Compute the indices of the child elements.
109
- const child2N = (n + 1) << 1,
110
- child1N = child2N - 1;
111
- // This is used to store the new position of the element, if any.
112
- let swap = null,
113
- child1Score;
114
- // If the first child exists (is inside the array)...
115
- if (child1N < length) {
116
- // Look it up and compute its score.
117
- const child1 = content[child1N];
118
- child1Score = scoreFunction(child1);
119
-
120
- // If the score is less than our element's, we need to swap.
121
- if (child1Score < elemScore) {
122
- swap = child1N;
123
- }
124
-
125
- }
126
-
127
- // Do the same checks for the other child.
128
- if (child2N < length) {
129
- const child2 = content[child2N],
130
- child2Score = scoreFunction(child2);
131
- if (child2Score < (swap === null ? elemScore : child1Score)) {
132
- swap = child2N;
133
- }
134
- }
135
-
136
- // If the element needs to be moved, swap it, and continue.
137
- if (swap !== null) {
138
- const swapContent = content[swap];
139
- content[n] = swapContent;
140
- content[swap] = element;
141
- //update hash
142
- hash[element] = swap;
143
- hash[swapContent] = n;
144
- n = swap;
145
- }
146
- // Otherwise, we are done.
147
- else {
148
- break;
149
- }
150
- }
151
- }
152
- };
153
- export default BinaryHeap;
@@ -1,94 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 22/6/2014
4
- * Time: 20:15
5
- */
6
- import { KeyCodes } from './input/devices/KeyCodes.js';
7
- import { assert } from "../core/assert.js";
8
-
9
- /**
10
- * @deprecated use PointerDevice and KeyboardDevice respectively
11
- * @param pointerContext
12
- * @param keyContext
13
- * @constructor
14
- */
15
- const InputEngine = function (pointerContext, keyContext) {
16
- assert.defined(pointerContext, 'pointerContext');
17
- assert.defined(keyContext, 'keyContext');
18
-
19
- console.warn('deprecated, use PointerDevice and KeyboardDevice instead');
20
-
21
- const keyMap = [];
22
- const mouseMap = {};
23
-
24
- function obtainBindingByCode(code) {
25
- let binding;
26
- if (typeof (code) === "number") {
27
- if (keyMap[code] === void 0) {
28
- keyMap[code] = {};
29
- }
30
- binding = keyMap[code];
31
- } else {
32
- if (mouseMap[code] === void 0) {
33
- mouseMap[code] = {};
34
- }
35
- binding = mouseMap[code];
36
- }
37
- return binding;
38
- }
39
-
40
- this.mapKey = function (keyCode, config) {
41
- const binding = obtainBindingByCode(keyCode);
42
- if (config.on) {
43
- binding.on = config.on;
44
- }
45
- if (config.off) {
46
- binding.off = config.off;
47
- }
48
- };
49
- this.mapKeyBoolean = function (keyName, context, property) {
50
- const keyCode = KeyCodes[keyName];
51
- const binding = obtainBindingByCode(keyCode);
52
- binding.on = function () {
53
- context[property] = true;
54
- };
55
- binding.off = function () {
56
- context[property] = false;
57
- };
58
- return this;
59
- };
60
- const keyDownHandler = function (event) {
61
- const keyCode = event.keyCode;
62
- //console.log("down", keyCode);
63
- const binding = keyMap[keyCode];
64
- if (binding && binding.on) {
65
- binding.on(event);
66
- }
67
- };
68
- const keyUpHandler = function (event) {
69
- const keyCode = event.keyCode;
70
- const binding = keyMap[keyCode];
71
- if (binding && binding.off) {
72
- binding.off(event);
73
- }
74
- };
75
- const mouseUpHandler = function (event) {
76
- const mouse1 = mouseMap.mouse1;
77
- if (mouse1) {
78
- mouse1.off(event);
79
- }
80
- };
81
- const mouseDownHandler = function (event) {
82
- const mouse1 = mouseMap.mouse1;
83
- if (mouse1) {
84
- mouse1.on(event);
85
- }
86
- };
87
- keyContext.addEventListener("keydown", keyDownHandler);
88
- keyContext.addEventListener("keyup", keyUpHandler);
89
- pointerContext.addEventListener("mousedown", mouseDownHandler);
90
- pointerContext.addEventListener("mouseup", mouseUpHandler);
91
- //
92
-
93
- };
94
- export default InputEngine;
@@ -1,60 +0,0 @@
1
- /**
2
- * Created by Alex on 27/02/14.
3
- */
4
-
5
-
6
-
7
- function getPointerLockElement() {
8
- const pointerLockElement = document.pointerLockElement ||
9
- document.mozPointerLockElement ||
10
- document.webkitPointerLockElement;
11
- return pointerLockElement;
12
- }
13
-
14
- function PointerLock(element) {
15
- this.element = element;
16
- element.requestPointerLock = element.requestPointerLock ||
17
- element.mozRequestPointerLock ||
18
- element.webkitRequestPointerLock;
19
- element.exitPointerLock = element.exitPointerLock ||
20
- element.mozExitPointerLock ||
21
- element.webkitExitPointerLock;
22
- this.pointerLockError = (function (evt) {
23
- console.error("failed to lock pointer", evt);
24
- }).bind(this);
25
- this.pointerLockChange = (function (evt) {
26
- if (this.isBound()) {
27
- this.emit("locked");
28
- } else {
29
- this.unlock();
30
- }
31
- }).bind(this);
32
- }
33
-
34
- PointerLock.prototype = new EventEmitter();
35
- PointerLock.prototype.isBound = function () {
36
- return this.element === getPointerLockElement();
37
- };
38
- PointerLock.prototype.lock = function () {
39
- if (this.isBound()) {
40
- return;
41
- }
42
- document.addEventListener('pointerlockerror', this.pointerLockError, false);
43
- document.addEventListener('mozpointerlockerror', this.pointerLockError, false);
44
- document.addEventListener('webkitpointerlockerror', this.pointerLockError, false);
45
-
46
- document.addEventListener('pointerlockchange', this.pointerLockChange, false);
47
- document.addEventListener('mozpointerlockchange', this.pointerLockChange, false);
48
- document.addEventListener('webkitpointerlockchange', this.pointerLockChange, false);
49
- this.element.requestPointerLock();
50
- };
51
- PointerLock.prototype.unlock = function () {
52
- document.removeEventListener('pointerlockchange', this.pointerLockChange, false);
53
- document.removeEventListener('mozpointerlockchange', this.pointerLockChange, false);
54
- document.removeEventListener('webkitpointerlockchange', this.pointerLockChange, false);
55
- if (this.isBound()) {
56
- this.element.exitPointerLock();
57
- }
58
- this.emit("unlocked");
59
- };
60
- export default PointerLock;
@@ -1,44 +0,0 @@
1
- /**
2
- * Created by Alex on 02/02/2015.
3
- */
4
- import { Ray as ThreeRay, Vector3 as ThreeVector3 } from 'three';
5
-
6
- function GeometryBVH(geometry) {
7
- this.geometry = geometry;
8
- this.bvh = null;
9
- }
10
-
11
- GeometryBVH.prototype.raycast = (function () {
12
- const hit = new ThreeVector3();
13
- const ray = new ThreeRay();
14
-
15
- function raycast(origin, direction, callback) {
16
- const geometry = this.geometry;
17
- const vertices = geometry.vertices;
18
- let hitCount = 0;
19
- this.bvh.traverseRayLeafIntersections(origin.x, origin.y, origin.z, direction.x, direction.y, direction.z, function (leaf) {
20
- const face = leaf.object;
21
- hitCount++;
22
- ray.set(origin, direction);
23
- const vA = vertices[face.a];
24
- const vB = vertices[face.b];
25
- const vC = vertices[face.c];
26
- let hitFound = ray.intersectTriangle(vA, vB, vC, false, hit);
27
- if (hitFound) {
28
- callback(hit, face, geometry);
29
- } else {
30
- //try opposite way
31
- hitFound = ray.intersectTriangle(vC, vB, vA, false, hit);
32
- if (hitFound) {
33
- callback(hit, face, geometry);
34
- }
35
- }
36
- });
37
- }
38
-
39
- return raycast;
40
- })();
41
-
42
- GeometryBVH.typeName = "GeometryBVH";
43
-
44
- export default GeometryBVH;
@@ -1,36 +0,0 @@
1
- /**
2
- * Created by Alex on 02/02/2015.
3
- */
4
- import { System } from '../System.js';
5
- import GeometryBVH from '../components/GeometryBVH.js';
6
- import BVHFromGeometry from '../../graphics/geometry/bvh/BVHFromGeometry.js';
7
-
8
-
9
- class GeometryBVHSystem extends System {
10
- constructor(grid) {
11
- super();
12
-
13
- this.dependencies = [GeometryBVH];
14
- //
15
- this.entityManager = null;
16
- this.grid = grid;
17
- }
18
-
19
- unlink(component, entity) {
20
- }
21
-
22
- link(component, entity) {
23
- //build bvh
24
- const g = component.geometry;
25
- //check if bvh exists
26
- if (component.bvh === null) {
27
- component.bvh = BVHFromGeometry(g);
28
- }
29
- }
30
-
31
- update(timeDelta) {
32
- }
33
- }
34
-
35
-
36
- export default GeometryBVHSystem;
@@ -1,99 +0,0 @@
1
- import { max2 } from "../../../../../core/math/max2.js";
2
- import { TerrainLayer } from "./TerrainLayer.js";
3
- import { Sampler2D } from "../../../../graphics/texture/sampler/Sampler2D.js";
4
-
5
- /**
6
- *
7
- * @param {{repeat:Vector2,textures:{diffuse:string[]}}} description
8
- * @param {TerrainLayers} layers
9
- * @param {AssetManager} am
10
- * @param {Vector2} size
11
- * @param {number} gridScale
12
- * @returns {Promise}
13
- */
14
- export function loadLegacyTerrainLayers(description, layers, am, size, gridScale) {
15
-
16
- /**
17
- *
18
- * @type {string[]}
19
- */
20
- const textures = description.textures.diffuse;
21
-
22
- /**
23
- *
24
- * @param {string} url
25
- * @param {number} layerIndex
26
- * @return {Promise<Asset>}
27
- */
28
- function loadLayer(url, layerIndex) {
29
-
30
- /**
31
- *
32
- * @type {TerrainLayer}
33
- */
34
- const layer = layers.layers.get(layerIndex);
35
-
36
- layer.textureDiffuseURL = url;
37
-
38
- return layer.loadTextureData(am);
39
- }
40
-
41
- const layerCount = textures.length;
42
-
43
- for (let i = 0; i < layerCount; i++) {
44
-
45
- const layer = new TerrainLayer();
46
-
47
-
48
- const nX = gridScale * (size.x / size.y);
49
- const nY = gridScale;
50
-
51
- layer.size.set(nX / description.repeat.x, nY / description.repeat.y);
52
-
53
- layer.diffuse = Sampler2D.uint8(3, layers.resolution.x, layers.resolution.y);
54
-
55
- layers.addLayer(layer);
56
- }
57
-
58
- layers.buildTexture();
59
-
60
- const promises = [];
61
-
62
- for (let i = 0; i < layerCount; i++) {
63
- const url = textures[i];
64
-
65
- const promise = loadLayer(url, i);
66
-
67
- promises.push(promise);
68
- }
69
-
70
- function updateResolution() {
71
-
72
- let size_x = 0;
73
- let size_y = 0;
74
-
75
- for (let i = 0; i < layerCount; i++) {
76
- const layer = layers.get(i);
77
-
78
- size_x = max2(layer.diffuse.width, size_x);
79
- size_y = max2(layer.diffuse.height, size_y);
80
- }
81
-
82
- layers.resolution.set(size_x, size_y);
83
-
84
- layers.buildTexture();
85
- }
86
-
87
- function writeLayers() {
88
-
89
- layers.writeAllLayersDataIntoTexture();
90
- }
91
-
92
-
93
- return Promise.all(promises)
94
- .then(() => {
95
- updateResolution();
96
-
97
- writeLayers();
98
- });
99
- }