@woosh/meep-engine 2.33.58 → 2.33.62

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 (120) hide show
  1. package/core/bvh2/aabb3/AABB3.js +4 -1
  2. package/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +6 -6
  3. package/core/cache/Cache.js +7 -0
  4. package/core/collection/array/fastArrayEquals.js +17 -0
  5. package/core/collection/array/typed/is_typed_array_equals.js +58 -0
  6. package/core/collection/map/AbstractAsyncMap.js +30 -0
  7. package/core/collection/map/AsyncMapWrapper.js +16 -0
  8. package/core/collection/map/AsyncRemoteHashMap.js +358 -0
  9. package/core/collection/map/CachedAsyncMap.js +34 -0
  10. package/core/geom/3d/SurfacePoint3.js +44 -5
  11. package/core/geom/Vector2.d.ts +2 -0
  12. package/core/geom/Vector4.js +5 -5
  13. package/core/geom/packing/MaxRectangles.js +13 -4
  14. package/core/math/hash/murmur3_32.js +3 -3
  15. package/editor/actions/concrete/PaintTerrainOverlayAction.js +1 -1
  16. package/editor/process/ObstacleGridDisplayProcess.js +1 -1
  17. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
  18. package/editor/tools/FoliagePaintTool.js +1 -1
  19. package/editor/tools/GridPaintTool.js +1 -1
  20. package/editor/tools/paint/TerrainPaintTool.js +1 -1
  21. package/editor/tools/paint/TerrainTexturePaintTool.js +1 -1
  22. package/editor/view/EditorView.js +1 -1
  23. package/editor/view/GridPickCoordinateView.js +1 -1
  24. package/engine/animation/removeEntityGenericEffect.js +22 -31
  25. package/engine/asset/Asset.js +0 -45
  26. package/engine/asset/AssetDescription.js +51 -0
  27. package/engine/asset/AssetManager.d.ts +7 -0
  28. package/engine/asset/AssetManager.js +98 -2
  29. package/engine/asset/AssetTransformer.d.ts +5 -0
  30. package/engine/asset/AssetTransformer.js +15 -0
  31. package/engine/asset/loaders/GLTFAssetLoader.js +27 -25
  32. package/engine/asset/loaders/material/computeImageBitmapEquality.js +2 -2
  33. package/engine/asset/loaders/material/computeTextureEquality.js +2 -2
  34. package/engine/asset/loaders/material/computeTextureHash.js +7 -13
  35. package/engine/ecs/animation/InverseKinematicsSystem.js +1 -1
  36. package/engine/ecs/attachment/AttachmentSystem.js +18 -17
  37. package/engine/ecs/evaluation/world/ReadTerrainLayerWeightPointFitness.js +1 -1
  38. package/engine/ecs/fow/FogOfWarRevealerSystem.js +1 -1
  39. package/engine/ecs/grid/HeightMap2NormalMap.js +1 -1
  40. package/engine/ecs/grid/NormalMap2AOMap.js +1 -1
  41. package/engine/ecs/gui/GUIElement.js +0 -106
  42. package/engine/ecs/gui/GUIElementSerializationAdapter.js +108 -0
  43. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +60 -45
  44. package/engine/ecs/gui/position/ViewportPositionSystem.js +5 -5
  45. package/engine/ecs/parent/EntityNode.d.ts +20 -0
  46. package/engine/ecs/parent/EntityNode.js +284 -0
  47. package/engine/ecs/parent/FaceEditor.js +137 -0
  48. package/engine/ecs/parent/testCompositionEntityNode.js +153 -0
  49. package/engine/ecs/parent/testHuDPerf.js +123 -0
  50. package/engine/ecs/storage/binary/BinaryClassUpgrader.js +1 -0
  51. package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
  52. package/engine/ecs/terrain/ecs/Terrain.js +14 -5
  53. package/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +112 -0
  54. package/engine/ecs/terrain/util/obtainTerrain.js +23 -0
  55. package/engine/ecs/util/removeComponentsExcept.js +3 -3
  56. package/engine/graphics/GraphicsEngine.js +4 -5
  57. package/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  58. package/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +0 -1
  59. package/engine/graphics/ecs/camera/topdown/TopDownCameraController.spec.js +8 -0
  60. package/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +1 -1
  61. package/engine/graphics/ecs/light/LightSystem.js +1 -1
  62. package/engine/graphics/ecs/mesh/Mesh.js +5 -5
  63. package/engine/graphics/ecs/mesh/MeshSystem.js +12 -20
  64. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +29 -0
  65. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +158 -1
  66. package/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
  67. package/engine/graphics/ecs/trail2d/Trail2D.js +35 -1
  68. package/engine/graphics/ecs/trail2d/Trail2DSystem.js +26 -19
  69. package/engine/graphics/ecs/trail2d/makeGradientTrail.js +68 -0
  70. package/engine/graphics/ecs/water/WaterSystem.js +1 -1
  71. package/engine/graphics/ecs/water2/shader/testWaterShader.js +1 -1
  72. package/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +55 -11
  73. package/engine/graphics/micron/convert_three_object_to_micron.js +24 -7
  74. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +107 -4
  75. package/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +176 -0
  76. package/engine/graphics/micron/render/v1/MaterialContext.js +1 -0
  77. package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +19 -3
  78. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.d.ts +2 -0
  79. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +2 -5
  80. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
  81. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -3
  82. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +3 -1
  83. package/engine/graphics/render/frame_graph/FrameGraphBuilder.js +36 -0
  84. package/engine/graphics/render/frame_graph/IRenderContext.js +8 -0
  85. package/engine/graphics/render/frame_graph/RenderPass.js +32 -0
  86. package/engine/graphics/render/frame_graph/RenderPassFlags.js +6 -0
  87. package/engine/graphics/render/frame_graph/RenderPassResources.js +15 -0
  88. package/engine/graphics/render/frame_graph/Resource.js +21 -0
  89. package/engine/graphics/render/frame_graph/ResourceReference.js +14 -0
  90. package/engine/graphics/render/frame_graph/TextureDescriptor.js +30 -0
  91. package/engine/graphics/render/frame_graph/UsageModeType.js +5 -0
  92. package/engine/graphics/render/frame_graph/sample/deferred/GBufferDrawPass.js +27 -0
  93. package/engine/graphics/render/frame_graph/sample/deferred/PresentPass.js +17 -0
  94. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -2
  95. package/engine/graphics/render/webgpu/sample/MeshInstance.js +87 -0
  96. package/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +71 -0
  97. package/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +39 -0
  98. package/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +21 -0
  99. package/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +41 -0
  100. package/engine/graphics/render/webgpu/sample/main.js +604 -0
  101. package/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +9 -0
  102. package/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +30 -0
  103. package/engine/graphics/shadows/ShadowMapRenderer.js +10 -4
  104. package/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  105. package/engine/graphics/texture/sampler/Sampler2D.js +24 -45
  106. package/engine/{ecs/grid → graphics/texture/sampler}/sampler2DToFloat32Texture.js +1 -1
  107. package/engine/grid/systems/GridPosition2TransformSystem.js +1 -1
  108. package/engine/grid/systems/ViewportGridProjectionSystem.js +1 -1
  109. package/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
  110. package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +3 -0
  111. package/engine/save/storage/IndexedDBStorage.js +8 -1
  112. package/engine/scene/transitionToScene.js +1 -1
  113. package/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.js +1 -1
  114. package/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
  115. package/generation/markers/debug/visualizeMarkers.js +1 -1
  116. package/generation/theme/ThemeEngine.js +1 -1
  117. package/package.json +1 -1
  118. package/samples/terrain/main.js +117 -0
  119. package/view/minimap/Minimap.js +1 -1
  120. package/engine/ecs/sockets/AttachmentSocketsSystem.js +0 -10
@@ -1,7 +1,7 @@
1
1
  import { Sampler2D } from "../../../graphics/texture/sampler/Sampler2D.js";
2
2
  import { assert } from "../../../../core/assert.js";
3
- import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
4
3
  import { bitmap2sampler_gl } from "./bitmap2sampler_gl.js";
4
+ import { fastArrayEquals } from "../../../../core/collection/array/fastArrayEquals.js";
5
5
 
6
6
  /**
7
7
  *
@@ -114,5 +114,5 @@ export function computeImageBitmapEquality(a, b) {
114
114
 
115
115
  const b_s = obtainSampler(b, ctx);
116
116
 
117
- return isArrayEqualStrict(a_s.data, b_s.data);
117
+ return fastArrayEquals(a_s.data, b_s.data);
118
118
  }
@@ -1,5 +1,5 @@
1
1
  import { computeImageBitmapEquality } from "./computeImageBitmapEquality.js";
2
- import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
2
+ import { fastArrayEquals } from "../../../../core/collection/array/fastArrayEquals.js";
3
3
 
4
4
  //
5
5
 
@@ -184,5 +184,5 @@ function textureMipmapEqual(a, b) {
184
184
  return true;
185
185
  }
186
186
 
187
- return isArrayEqualStrict(aData, bData);
187
+ return fastArrayEquals(aData, bData);
188
188
  }
@@ -1,7 +1,7 @@
1
- import { max2 } from "../../../../core/math/max2.js";
2
1
  import { computeImageBitmapHash } from "./computeImageBitmapHash.js";
3
2
  import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
4
3
  import { computeHashFloat } from "../../../../core/math/hash/computeHashFloat.js";
4
+ import { murmur3_32 } from "../../../../core/math/hash/murmur3_32.js";
5
5
 
6
6
  /**
7
7
  *
@@ -59,6 +59,7 @@ export function computeImageDataHash(image) {
59
59
  */
60
60
  function computeSpecificHash(texture) {
61
61
  let dataHash = 0;
62
+ let i;
62
63
 
63
64
  if (texture.image !== null && texture.image !== undefined) {
64
65
 
@@ -73,25 +74,18 @@ function computeSpecificHash(texture) {
73
74
  if (Array.isArray(mipmaps)) {
74
75
  const nMipmaps = mipmaps.length;
75
76
 
76
- for (let i = 0; i < nMipmaps; i++) {
77
+ for (i = 0; i < nMipmaps; i++) {
77
78
  const mipmap = mipmaps[i];
78
79
 
79
- if (mipmap.width > 16) {
80
- continue;
81
- }
82
-
83
80
  const data = mipmap.data;
84
-
85
81
  const dataSize = data.length;
86
82
 
87
- const dataStride = max2(1, Math.floor(dataSize / 31));
88
-
89
- for (let i = 0; i < dataSize; i += dataStride) {
90
- const datum = data[i];
91
-
92
- dataHash = ((dataHash << 5) - dataHash) + datum;
83
+ if (dataSize > 1024) {
84
+ continue;
93
85
  }
94
86
 
87
+ dataHash = ((dataHash << 5) - dataHash) + murmur3_32(data, 1337);
88
+
95
89
  break;
96
90
  }
97
91
 
@@ -3,9 +3,9 @@ import { InverseKinematics } from "./InverseKinematics.js";
3
3
  import Mesh, { MeshFlags } from "../../graphics/ecs/mesh/Mesh.js";
4
4
  import { TwoBoneInverseKinematicsSolver } from "./TwoBoneInverseKinematicsSolver.js";
5
5
  import { extractSkeletonFromMeshComponent } from "../../graphics/ecs/mesh/SkeletonUtils.js";
6
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
7
6
  import { OneBoneSurfaceAlignmentSolver } from "./OneBoneSurfaceAlignmentSolver.js";
8
7
  import { IKProblem } from "./IKProblem.js";
8
+ import { obtainTerrain } from "../terrain/util/obtainTerrain.js";
9
9
 
10
10
 
11
11
  export class InverseKinematicsSystem extends System {
@@ -6,7 +6,6 @@ import { assert } from "../../../core/assert.js";
6
6
  import Mesh from "../../graphics/ecs/mesh/Mesh.js";
7
7
  import { BoneAttachmentBinding } from "./BoneAttachmentBinding.js";
8
8
  import { TransformAttachmentBinding } from "./TransformAttachmentBinding.js";
9
- import { MeshSystem } from "../../graphics/ecs/mesh/MeshSystem.js";
10
9
 
11
10
  /**
12
11
  * @readonly
@@ -318,10 +317,10 @@ export class AttachmentSystem extends System {
318
317
 
319
318
  /**
320
319
  *
321
- * @param {Mesh} mesh
322
320
  * @param {number} entity
321
+ * @private
323
322
  */
324
- visitVisibleMesh(mesh, entity) {
323
+ __update_entity(entity) {
325
324
  const bindings = this.parentBindingIndex.get(entity);
326
325
 
327
326
  if (bindings !== undefined) {
@@ -335,25 +334,27 @@ export class AttachmentSystem extends System {
335
334
  }
336
335
  }
337
336
 
337
+ /**
338
+ *
339
+ * @param {Mesh} mesh
340
+ * @param {number} entity
341
+ */
342
+ visitComponent(mesh, entity) {
343
+ this.__update_entity(entity);
344
+ }
345
+
338
346
  update(timeDelta) {
339
347
  //process wait queue
340
348
  this.processWaiting();
341
349
 
342
- /**
343
- *
344
- * @type {MeshSystem}
345
- */
346
- const meshSystem = this.entityManager.getSystem(MeshSystem);
350
+ const em = this.entityManager;
347
351
 
348
- meshSystem.traverseVisible(this.visitVisibleMesh, this);
352
+ const ecd = em.dataset;
349
353
 
350
- }
351
- }
354
+ if (ecd === null) {
355
+ return;
356
+ }
352
357
 
353
- /**
354
- *
355
- * @param {AttachmentBinding} binding
356
- */
357
- function updateBinding(binding) {
358
- binding.update();
358
+ ecd.traverseComponents(Attachment, this.visitComponent, this);
359
+ }
359
360
  }
@@ -1,8 +1,8 @@
1
1
  import { PointFitnessFunction } from "../PointFitnessFunction.js";
2
- import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
3
2
  import Vector3 from "../../../../core/geom/Vector3.js";
4
3
  import Vector2 from "../../../../core/geom/Vector2.js";
5
4
  import { assert } from "../../../../core/assert.js";
5
+ import { obtainTerrain } from "../../terrain/util/obtainTerrain.js";
6
6
 
7
7
 
8
8
  const v3 = new Vector3();
@@ -4,8 +4,8 @@ import { SignalBinding } from "../../../core/events/signal/SignalBinding.js";
4
4
  import { FogOfWar } from "./FogOfWar.js";
5
5
  import Team from "../../../../model/game/ecs/component/Team.js";
6
6
  import { Transform } from "../transform/Transform.js";
7
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
8
7
  import Vector2 from "../../../core/geom/Vector2.js";
8
+ import { obtainTerrain } from "../terrain/util/obtainTerrain.js";
9
9
 
10
10
  const v2 = new Vector2();
11
11
 
@@ -5,7 +5,7 @@
5
5
  import { Sampler2D } from '../../graphics/texture/sampler/Sampler2D.js';
6
6
  import NormalMapShader from '../../graphics/shaders/NormalMapShader2.js';
7
7
  import ImageFilter from '../../graphics/filter/ImageFilter.js';
8
- import { sampler2DtoFloat32Texture } from "./sampler2DToFloat32Texture.js";
8
+ import { sampler2DtoFloat32Texture } from "../../graphics/texture/sampler/sampler2DToFloat32Texture.js";
9
9
 
10
10
 
11
11
  function convertChannel(v) {
@@ -9,7 +9,7 @@ import sampler2D2Texture from '../../graphics/texture/sampler/Sampler2D2Texture.
9
9
  import AmbientOcclusionShader from '../../graphics/shaders/AmbientOcclusionShader.js';
10
10
  import GaussianBlurShader from '../../graphics/shaders/GaussianBlurShader.js';
11
11
  import ImageFilter from '../../graphics/filter/ImageFilter.js';
12
- import { sampler2DtoFloat32Texture } from "./sampler2DToFloat32Texture.js";
12
+ import { sampler2DtoFloat32Texture } from "../../graphics/texture/sampler/sampler2DToFloat32Texture.js";
13
13
 
14
14
  function filterResult2Texture(data, width, height) {
15
15
  const result = new DataTexture();
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import Vector2 from '../../../core/geom/Vector2.js';
5
5
  import ObservedBoolean from "../../../core/model/ObservedBoolean.js";
6
- import { BinaryClassSerializationAdapter } from "../storage/binary/BinaryClassSerializationAdapter.js";
7
6
  import { COMPONENT_SERIALIZATION_TRANSIENT_FIELD } from "../storage/COMPONENT_SERIALIZATION_TRANSIENT_FIELD.js";
8
7
  import { assert } from "../../../core/assert.js";
9
8
  import { objectDeepEquals } from "../../../core/model/object/objectDeepEquals.js";
@@ -238,108 +237,3 @@ GUIElement.serializable = true;
238
237
  export default GUIElement;
239
238
 
240
239
 
241
- export class GUIElementSerializationAdapter extends BinaryClassSerializationAdapter {
242
- constructor() {
243
- super();
244
-
245
- this.klass = GUIElement;
246
- this.version = 0;
247
- }
248
-
249
- /**
250
- *
251
- * @param {BinaryBuffer} buffer
252
- * @param {GUIElement} value
253
- */
254
- serialize(buffer, value) {
255
-
256
- if (!value.getFlag(GUIElementFlag.Managed)) {
257
- throw new Error(`Expected 'Managed' flag to be set, instead it was cleared. Cannot serialize un-managed component`);
258
- }
259
-
260
- value.anchor.toBinaryBufferFloat32(buffer);
261
- buffer.writeUTF8String(value.group);
262
-
263
- buffer.writeUint8(value.visible.getValue() ? 1 : 0);
264
-
265
- buffer.writeUTF8String(value.klass);
266
- //write parameters
267
-
268
- const paramKeys = Object.keys(value.parameters);
269
-
270
- const numParamKeys = paramKeys.length;
271
- buffer.writeUintVar(numParamKeys);
272
-
273
- for (let i = 0; i < numParamKeys; i++) {
274
- const paramKey = paramKeys[i];
275
-
276
- buffer.writeUTF8String(paramKey);
277
-
278
- const parameter = value.parameters[paramKey];
279
-
280
- const paramType = typeof parameter;
281
-
282
- if (paramType === "number") {
283
- buffer.writeUint8(1);
284
-
285
- buffer.writeFloat64(parameter);
286
- } else if (paramType === "boolean") {
287
- buffer.writeUint8(2);
288
-
289
- buffer.writeUint8(parameter ? 1 : 0);
290
- } else if (paramType === "string") {
291
- buffer.writeUint8(3);
292
-
293
- buffer.writeUTF8String(parameter);
294
- } else {
295
- throw new TypeError(`Unsupported parameter type ${paramType}`);
296
- }
297
-
298
- }
299
- }
300
-
301
- /**
302
- *
303
- * @param {BinaryBuffer} buffer
304
- * @param {GUIElement} value
305
- */
306
- deserialize(buffer, value) {
307
- value.anchor.fromBinaryBufferFloat32(buffer);
308
-
309
- value.group = buffer.readUTF8String();
310
-
311
- value.visible.set(buffer.readUint8() !== 0);
312
-
313
- value.klass = buffer.readUTF8String();
314
-
315
- const numParamKeys = buffer.readUintVar();
316
-
317
- const params = {};
318
-
319
- for (let i = 0; i < numParamKeys; i++) {
320
- //read key
321
- const paramKey = buffer.readUTF8String();
322
-
323
- //read type flag
324
- const paramTypeHeader = buffer.readUint8();
325
-
326
- let paramValue;
327
- if (paramTypeHeader === 1) {
328
- //number
329
- paramValue = buffer.readFloat64();
330
- } else if (paramTypeHeader === 2) {
331
- //boolean
332
- paramValue = buffer.readUint8() !== 0;
333
- } else if (paramTypeHeader === 3) {
334
- //string
335
- paramValue = buffer.readUTF8String();
336
- } else {
337
- throw new TypeError(`Unknown type header value '${paramTypeHeader}' for parameter key '${paramKey}'`);
338
- }
339
-
340
- params[paramKey] = paramValue;
341
- }
342
-
343
- value.parameters = params;
344
- }
345
- }
@@ -0,0 +1,108 @@
1
+ import { BinaryClassSerializationAdapter } from "../storage/binary/BinaryClassSerializationAdapter.js";
2
+ import GUIElement, { GUIElementFlag } from "./GUIElement.js";
3
+
4
+ export class GUIElementSerializationAdapter extends BinaryClassSerializationAdapter {
5
+ constructor() {
6
+ super();
7
+
8
+ this.klass = GUIElement;
9
+ this.version = 0;
10
+ }
11
+
12
+ /**
13
+ *
14
+ * @param {BinaryBuffer} buffer
15
+ * @param {GUIElement} value
16
+ */
17
+ serialize(buffer, value) {
18
+
19
+ if (!value.getFlag(GUIElementFlag.Managed)) {
20
+ throw new Error(`Expected 'Managed' flag to be set, instead it was cleared. Cannot serialize un-managed component`);
21
+ }
22
+
23
+ value.anchor.toBinaryBufferFloat32(buffer);
24
+ buffer.writeUTF8String(value.group);
25
+
26
+ buffer.writeUint8(value.visible.getValue() ? 1 : 0);
27
+
28
+ buffer.writeUTF8String(value.klass);
29
+ //write parameters
30
+
31
+ const paramKeys = Object.keys(value.parameters);
32
+
33
+ const numParamKeys = paramKeys.length;
34
+ buffer.writeUintVar(numParamKeys);
35
+
36
+ for (let i = 0; i < numParamKeys; i++) {
37
+ const paramKey = paramKeys[i];
38
+
39
+ buffer.writeUTF8String(paramKey);
40
+
41
+ const parameter = value.parameters[paramKey];
42
+
43
+ const paramType = typeof parameter;
44
+
45
+ if (paramType === "number") {
46
+ buffer.writeUint8(1);
47
+
48
+ buffer.writeFloat64(parameter);
49
+ } else if (paramType === "boolean") {
50
+ buffer.writeUint8(2);
51
+
52
+ buffer.writeUint8(parameter ? 1 : 0);
53
+ } else if (paramType === "string") {
54
+ buffer.writeUint8(3);
55
+
56
+ buffer.writeUTF8String(parameter);
57
+ } else {
58
+ throw new TypeError(`Unsupported parameter type ${paramType}`);
59
+ }
60
+
61
+ }
62
+ }
63
+
64
+ /**
65
+ *
66
+ * @param {BinaryBuffer} buffer
67
+ * @param {GUIElement} value
68
+ */
69
+ deserialize(buffer, value) {
70
+ value.anchor.fromBinaryBufferFloat32(buffer);
71
+
72
+ value.group = buffer.readUTF8String();
73
+
74
+ value.visible.set(buffer.readUint8() !== 0);
75
+
76
+ value.klass = buffer.readUTF8String();
77
+
78
+ const numParamKeys = buffer.readUintVar();
79
+
80
+ const params = {};
81
+
82
+ for (let i = 0; i < numParamKeys; i++) {
83
+ //read key
84
+ const paramKey = buffer.readUTF8String();
85
+
86
+ //read type flag
87
+ const paramTypeHeader = buffer.readUint8();
88
+
89
+ let paramValue;
90
+ if (paramTypeHeader === 1) {
91
+ //number
92
+ paramValue = buffer.readFloat64();
93
+ } else if (paramTypeHeader === 2) {
94
+ //boolean
95
+ paramValue = buffer.readUint8() !== 0;
96
+ } else if (paramTypeHeader === 3) {
97
+ //string
98
+ paramValue = buffer.readUTF8String();
99
+ } else {
100
+ throw new TypeError(`Unknown type header value '${paramTypeHeader}' for parameter key '${paramKey}'`);
101
+ }
102
+
103
+ params[paramKey] = paramValue;
104
+ }
105
+
106
+ value.parameters = params;
107
+ }
108
+ }
@@ -6,23 +6,15 @@
6
6
  import { System } from '../../System.js';
7
7
  import HeadsUpDisplay from './HeadsUpDisplay.js';
8
8
  import { Transform } from '../../transform/Transform.js';
9
-
10
- import { Matrix4 } from 'three';
11
9
  import { GraphicsEngine } from "../../../graphics/GraphicsEngine.js";
12
10
  import { FogOfWarVisibilityPredicate } from "../../fow/FogOfWarVisibilityPredicate.js";
13
- import Vector4 from "../../../../core/geom/Vector4.js";
14
11
  import ViewportPosition from "../position/ViewportPosition.js";
15
12
  import GUIElement from "../GUIElement.js";
16
13
  import { HeadsUpDisplayFlag } from "./HeadsUpDisplayFlag.js";
14
+ import { mat4 } from "gl-matrix";
17
15
 
18
- /**
19
- *
20
- * @type {Vector4}
21
- */
22
- const v4 = new Vector4();
23
- const projectionMatrix = new Matrix4();
16
+ const projection = new Float32Array(16);
24
17
 
25
- const up = new Vector4();
26
18
 
27
19
  /**
28
20
  *
@@ -77,7 +69,7 @@ class HeadsUpDisplaySystem extends System {
77
69
  }
78
70
 
79
71
  /**
80
- *
72
+ * NOTE: for the sake of speed all of the matrix and vector multiplications have been inlined, readability of this method is pretty bad
81
73
  * @param {HeadsUpDisplay} hud
82
74
  * @param {Transform} transform
83
75
  * @param {ViewportPosition} vp
@@ -87,48 +79,69 @@ class HeadsUpDisplaySystem extends System {
87
79
  __apply_entity_transformation(hud, transform, vp, element) {
88
80
  const worldOffset = hud.worldOffset;
89
81
 
90
- let worldOffsetX = worldOffset.x;
91
- let worldOffsetY = worldOffset.y;
92
- let worldOffsetZ = worldOffset.z;
93
-
94
- v4.set(
95
- worldOffsetX,
96
- worldOffsetY,
97
- worldOffsetZ,
98
- 1
99
- );
82
+ let x = worldOffset.x;
83
+ let y = worldOffset.y;
84
+ let z = worldOffset.z;
100
85
 
101
86
  if (hud.getFlag(HeadsUpDisplayFlag.TransformWorldOffset)) {
102
87
  //apply scale and rotation
88
+ const transform_scale = transform.scale;
89
+
90
+ x *= transform_scale.x;
91
+ y *= transform_scale.y;
92
+ z *= transform_scale.y;
103
93
 
104
- v4.multiplyVector3(transform.scale);
94
+ const q = transform.rotation;
95
+
96
+ const qx = q.x;
97
+ const qy = q.y;
98
+ const qz = q.z;
99
+ const qw = q.w;
100
+
101
+ // calculate quat * vec
102
+ const ix = qw * x + qy * z - qz * y;
103
+ const iy = qw * y + qz * x - qx * z;
104
+ const iz = qw * z + qx * y - qy * x;
105
+ const iw = -qx * x - qy * y - qz * z;
106
+
107
+ // calculate result * inverse quat
108
+ x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
109
+ y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
110
+ z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
105
111
 
106
- v4.applyQuaternion(transform.rotation);
107
112
  }
108
113
 
114
+ // add transform position to get final world position
109
115
  const position = transform.position;
110
116
 
111
- v4.add3(position);
112
-
113
- const worldPositionX = v4.x;
114
- const worldPositionY = v4.y;
115
- const worldPositionZ = v4.z;
117
+ x += position.x;
118
+ y += position.y;
119
+ z += position.z;
116
120
 
121
+ const worldPositionX = x;
122
+ const worldPositionY = y;
123
+ const worldPositionZ = z;
117
124
 
118
125
  // Convert the [-1, 1] screen coordinate into a world coordinate on the near plane
119
- v4.threeApplyMatrix4(projectionMatrix);
120
126
 
121
- const d = 1 / Math.abs(v4.w);
122
- v4.x *= d;
123
- v4.y *= d;
124
- v4.z *= d;
127
+ // apply projection matrix
128
+ const _x = projection[0] * x + projection[4] * y + projection[8] * z + projection[12];
129
+ const _y = projection[1] * x + projection[5] * y + projection[9] * z + projection[13];
130
+ const _z = projection[2] * x + projection[6] * y + projection[10] * z + projection[14];
131
+ const _w = projection[3] * x + projection[7] * y + projection[11] * z + projection[15];
132
+
133
+ // apply perspective transform
134
+ const d = 1 / Math.abs(_w);
135
+ x = _x * d;
136
+ y = _y * d;
137
+ z = _z * d;
125
138
 
126
- const ndcX = (v4.x + 1) / 2;
127
- const ndcY = (1 - v4.y) / 2;
139
+ const ndcX = (x + 1) / 2;
140
+ const ndcY = (1 - y) / 2;
128
141
 
129
142
  vp.position.set(ndcX, ndcY);
130
143
 
131
- const trackedPositionOutOfBounds = v4.z > 1 || v4.z < -1;
144
+ const trackedPositionOutOfBounds = z > 1 || z < -1;
132
145
 
133
146
  const visible = (!trackedPositionOutOfBounds || vp.stickToScreenEdge) && this.__visibility_predicate.test(worldPositionX, worldPositionY, worldPositionZ);
134
147
 
@@ -141,18 +154,20 @@ class HeadsUpDisplaySystem extends System {
141
154
  if (hud.getFlag(HeadsUpDisplayFlag.PerspectiveRotation)) {
142
155
  //compute rotation in screen-space
143
156
 
144
- up.set(worldPositionX, worldPositionY + 1, worldPositionZ, 1);
145
- up.threeApplyMatrix4(projectionMatrix);
157
+ const w_y_1 = worldPositionY + 1;
158
+
159
+ const _up_x = projection[0] * worldPositionX + projection[4] * w_y_1 + projection[8] * worldPositionZ + projection[12];
160
+ const _up_y = projection[1] * worldPositionX + projection[5] * w_y_1 + projection[9] * worldPositionZ + projection[13];
161
+ const _up_w = projection[3] * worldPositionX + projection[7] * w_y_1 + projection[11] * worldPositionZ + projection[15];
146
162
 
147
163
  // compute perspective divide
148
- const d = 1 / Math.abs(up.w);
164
+ const d = 1 / Math.abs(_up_w);
149
165
 
150
- up.x *= d;
151
- up.y *= d;
152
- up.z *= d;
166
+ const up_x = _up_x * d;
167
+ const up_y = _up_y * d;
153
168
 
154
- const up_ndcX = (up.x + 1) / 2;
155
- const up_ndcY = (1 - up.y) / 2;
169
+ const up_ndcX = (up_x + 1) / 2;
170
+ const up_ndcY = (1 - up_y) / 2;
156
171
 
157
172
  const angle = Math.atan2(up_ndcY - ndcY, up_ndcX - ndcX);
158
173
 
@@ -176,7 +191,7 @@ class HeadsUpDisplaySystem extends System {
176
191
  */
177
192
  const camera = this.graphics.camera;
178
193
 
179
- projectionMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
194
+ mat4.multiply(projection, camera.projectionMatrix.elements, camera.matrixWorldInverse.elements);
180
195
 
181
196
  const visibilityPredicate = this.__visibility_predicate;
182
197
 
@@ -5,7 +5,6 @@ import { System } from '../../System.js';
5
5
  import ViewportPosition from './ViewportPosition.js';
6
6
  import GUIElement from "../GUIElement.js";
7
7
  import { assert } from "../../../../core/assert.js";
8
- import Vector2 from "../../../../core/geom/Vector2.js";
9
8
  import { SignalBinding } from "../../../../core/events/signal/SignalBinding.js";
10
9
  import { EPSILON } from "../../../../core/math/MathUtils.js";
11
10
  import AABB2 from "../../../../core/geom/AABB2.js";
@@ -202,8 +201,9 @@ function setElementPosition(view, bounds, viewportSize, vp) {
202
201
  if (vp.stickToScreenEdge) {
203
202
 
204
203
 
205
- const clipEdgeX = vp.screenEdgeWidth / viewportSize.x;
206
- const clipEdgeY = vp.screenEdgeWidth / viewportSize.y;
204
+ const screenEdgeWidth = vp.screenEdgeWidth;
205
+ const clipEdgeX = screenEdgeWidth / viewportSize.x;
206
+ const clipEdgeY = screenEdgeWidth / viewportSize.y;
207
207
 
208
208
 
209
209
  stickyBounds.set(clipEdgeX, clipEdgeY, 1 - clipEdgeX, 1 - clipEdgeY);
@@ -241,8 +241,8 @@ function setElementPosition(view, bounds, viewportSize, vp) {
241
241
  }
242
242
 
243
243
 
244
- const targetX = (x) * (viewportSize.x);
245
- const targetY = (y) * (viewportSize.y);
244
+ const targetX = x * (viewportSize.x);
245
+ const targetY = y * (viewportSize.y);
246
246
 
247
247
  const viewPosition = view.position;
248
248
 
@@ -0,0 +1,20 @@
1
+ import EntityBuilder from "../EntityBuilder";
2
+ import {EntityComponentDataset} from "../EntityComponentDataset";
3
+ import {Transform} from "../transform/Transform";
4
+
5
+ export class EntityNode {
6
+ constructor(entity?: EntityBuilder)
7
+
8
+ parent: EntityNode | null
9
+ entity: EntityBuilder
10
+
11
+ transform: Transform
12
+
13
+ addChild(node: EntityNode): boolean
14
+
15
+ removeChild(node: EntityNode): boolean
16
+
17
+ build(ecd: EntityComponentDataset): void
18
+
19
+ destroy(): void
20
+ }