@woosh/meep-engine 2.33.59 → 2.33.63

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/ecs/grid/pick.js +44 -0
  16. package/editor/actions/concrete/PaintTerrainOverlayAction.js +1 -1
  17. package/editor/process/ObstacleGridDisplayProcess.js +1 -1
  18. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
  19. package/editor/tools/FoliagePaintTool.js +1 -1
  20. package/editor/tools/GridPaintTool.js +2 -2
  21. package/editor/tools/paint/TerrainPaintTool.js +2 -2
  22. package/editor/tools/paint/TerrainTexturePaintTool.js +1 -1
  23. package/editor/view/EditorView.js +1 -1
  24. package/editor/view/GridPickCoordinateView.js +2 -2
  25. package/engine/animation/removeEntityGenericEffect.js +22 -31
  26. package/engine/asset/Asset.js +0 -45
  27. package/engine/asset/AssetDescription.js +51 -0
  28. package/engine/asset/AssetManager.d.ts +7 -0
  29. package/engine/asset/AssetManager.js +98 -2
  30. package/engine/asset/AssetTransformer.d.ts +5 -0
  31. package/engine/asset/AssetTransformer.js +15 -0
  32. package/engine/asset/loaders/GLTFAssetLoader.js +27 -25
  33. package/engine/asset/loaders/material/computeImageBitmapEquality.js +2 -2
  34. package/engine/asset/loaders/material/computeTextureEquality.js +2 -2
  35. package/engine/asset/loaders/material/computeTextureHash.js +7 -13
  36. package/engine/ecs/animation/InverseKinematicsSystem.js +1 -1
  37. package/engine/ecs/attachment/AttachmentSystem.js +18 -17
  38. package/engine/ecs/evaluation/world/ReadTerrainLayerWeightPointFitness.js +1 -1
  39. package/engine/ecs/fow/FogOfWarRevealerSystem.js +2 -2
  40. package/engine/ecs/grid/HeightMap2NormalMap.js +1 -1
  41. package/engine/ecs/grid/NormalMap2AOMap.js +1 -1
  42. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +60 -45
  43. package/engine/ecs/gui/position/ViewportPositionSystem.js +5 -5
  44. package/engine/ecs/parent/EntityNode.d.ts +20 -0
  45. package/engine/ecs/parent/EntityNode.js +284 -0
  46. package/engine/ecs/parent/FaceEditor.js +137 -0
  47. package/engine/ecs/parent/testCompositionEntityNode.js +153 -0
  48. package/engine/ecs/parent/testHuDPerf.js +123 -0
  49. package/engine/ecs/storage/binary/BinaryClassUpgrader.js +1 -0
  50. package/engine/ecs/team/Team.js +82 -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/tooltip/TooltipComponentSystem.js +1 -1
  56. package/engine/ecs/util/removeComponentsExcept.js +3 -3
  57. package/engine/graphics/GraphicsEngine.js +4 -5
  58. package/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  59. package/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +1 -1
  60. package/engine/graphics/ecs/light/LightSystem.js +1 -1
  61. package/engine/graphics/ecs/mesh/Mesh.js +5 -5
  62. package/engine/graphics/ecs/mesh/MeshSystem.js +12 -20
  63. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +29 -0
  64. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +158 -1
  65. package/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
  66. package/engine/graphics/ecs/trail2d/Trail2D.js +35 -1
  67. package/engine/graphics/ecs/trail2d/Trail2DSystem.js +26 -19
  68. package/engine/graphics/ecs/trail2d/makeGradientTrail.js +68 -0
  69. package/engine/graphics/ecs/water/WaterSystem.js +1 -1
  70. package/engine/graphics/ecs/water2/shader/testWaterShader.js +1 -1
  71. package/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +55 -11
  72. package/engine/graphics/micron/convert_three_object_to_micron.js +24 -7
  73. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +107 -4
  74. package/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +176 -0
  75. package/engine/graphics/micron/render/v1/MaterialContext.js +1 -0
  76. package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +19 -3
  77. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -6
  78. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
  79. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -4
  80. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +3 -1
  81. package/engine/graphics/render/frame_graph/FrameGraphBuilder.js +36 -0
  82. package/engine/graphics/render/frame_graph/IRenderContext.js +8 -0
  83. package/engine/graphics/render/frame_graph/RenderPass.js +32 -0
  84. package/engine/graphics/render/frame_graph/RenderPassFlags.js +6 -0
  85. package/engine/graphics/render/frame_graph/RenderPassResources.js +15 -0
  86. package/engine/graphics/render/frame_graph/Resource.js +21 -0
  87. package/engine/graphics/render/frame_graph/ResourceReference.js +14 -0
  88. package/engine/graphics/render/frame_graph/TextureDescriptor.js +30 -0
  89. package/engine/graphics/render/frame_graph/UsageModeType.js +5 -0
  90. package/engine/graphics/render/frame_graph/sample/deferred/GBufferDrawPass.js +27 -0
  91. package/engine/graphics/render/frame_graph/sample/deferred/PresentPass.js +17 -0
  92. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -2
  93. package/engine/graphics/render/webgpu/sample/MeshInstance.js +99 -0
  94. package/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +71 -0
  95. package/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +39 -0
  96. package/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +21 -0
  97. package/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +41 -0
  98. package/engine/graphics/render/webgpu/sample/main.js +604 -0
  99. package/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +9 -0
  100. package/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +30 -0
  101. package/engine/graphics/shadows/ShadowMapRenderer.js +10 -4
  102. package/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  103. package/engine/graphics/texture/sampler/Sampler2D.js +24 -45
  104. package/engine/{ecs/grid → graphics/texture/sampler}/sampler2DToFloat32Texture.js +1 -1
  105. package/engine/graphics/util/modelHitTest.js +63 -0
  106. package/engine/grid/systems/GridPosition2TransformSystem.js +1 -1
  107. package/engine/grid/systems/ViewportGridProjectionSystem.js +1 -1
  108. package/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
  109. package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +3 -0
  110. package/engine/save/storage/IndexedDBStorage.js +8 -1
  111. package/engine/scene/transitionToScene.js +1 -1
  112. package/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.js +1 -1
  113. package/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
  114. package/generation/markers/debug/visualizeMarkers.js +1 -1
  115. package/generation/theme/ThemeEngine.js +1 -1
  116. package/package.json +1 -1
  117. package/samples/terrain/main.js +117 -0
  118. package/util/ScreenGridPicker.js +3 -0
  119. package/view/minimap/Minimap.js +1 -1
  120. package/engine/ecs/sockets/AttachmentSocketsSystem.js +0 -10
@@ -12,9 +12,10 @@ import Vector2 from "../Vector2.js";
12
12
  * @param {AABB2[]} boxes
13
13
  */
14
14
  function removeRedundantBoxesArray(boxes) {
15
+ let i, j;
15
16
  let numBoxes = boxes.length;
16
17
 
17
- loop_a: for (let i = 0; i < numBoxes; i++) {
18
+ loop_a: for (i = 0; i < numBoxes; i++) {
18
19
  const a = boxes[i];
19
20
 
20
21
  const ax0 = a.x0;
@@ -22,7 +23,7 @@ function removeRedundantBoxesArray(boxes) {
22
23
  const ax1 = a.x1;
23
24
  const ay1 = a.y1;
24
25
 
25
- for (let j = i + 1; j < numBoxes; j++) {
26
+ for (j = i + 1; j < numBoxes; j++) {
26
27
  const b = boxes[j];
27
28
 
28
29
  const bx0 = b.x0;
@@ -157,7 +158,7 @@ function findBestContainer(width, height, boxes, costFunction) {
157
158
  let best = null;
158
159
  let bestScore = Number.POSITIVE_INFINITY;
159
160
 
160
- boxes.traversePreOrder(node => {
161
+ const visitor = (node) => {
161
162
 
162
163
  if (node.getWidth() < width) {
163
164
  //too small, don't traverse deeper
@@ -195,7 +196,11 @@ function findBestContainer(width, height, boxes, costFunction) {
195
196
  best = box;
196
197
  }
197
198
  }
198
- });
199
+
200
+ return true;
201
+ };
202
+
203
+ boxes.traversePreOrder(visitor);
199
204
 
200
205
  return best;
201
206
  }
@@ -337,6 +342,10 @@ export class MaxRectanglesPacker {
337
342
  this.free = new QuadTreeNode(0, 0, width, height);
338
343
  this.free.add(null, 0, 0, width, height);
339
344
 
345
+ /**
346
+ *
347
+ * @type {AABB2[]}
348
+ */
340
349
  this.boxes = [];
341
350
  }
342
351
 
@@ -9,9 +9,9 @@ export function murmur3_32(key, seed) {
9
9
  let k1;
10
10
  let i = 0;
11
11
 
12
- const bytes = key.length;
12
+ const key_length = key.length;
13
13
 
14
- while (i < bytes) {
14
+ while (i < key_length) {
15
15
  k1 = key[i];
16
16
  ++i;
17
17
 
@@ -26,7 +26,7 @@ export function murmur3_32(key, seed) {
26
26
  }
27
27
 
28
28
  // mix in array length
29
- h1 ^= bytes;
29
+ h1 ^= key_length;
30
30
 
31
31
  h1 ^= h1 >>> 16;
32
32
  h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16));
@@ -0,0 +1,44 @@
1
+ import { assert } from "../../core/assert.js";
2
+ import Vector3 from "../../core/geom/Vector3.js";
3
+ import { SurfacePoint3 } from "../../core/geom/3d/SurfacePoint3.js";
4
+ import Vector2 from "../../core/geom/Vector2.js";
5
+
6
+ /**
7
+ *
8
+ * @param {number} x
9
+ * @param {number} y
10
+ * @param {GraphicsEngine} graphicsEngine
11
+ * @param {Terrain} terrain
12
+ * @param {function(gridPosition:Vector2,worldPosition:Vector3,normal:Vector3)} callback
13
+ */
14
+ export function pick(x, y, graphicsEngine, terrain, callback) {
15
+
16
+ assert.isNumber(x, 'x');
17
+ assert.isNumber(y, 'y');
18
+
19
+ assert.defined(terrain, 'terrain');
20
+ assert.notNull(terrain, 'terrain');
21
+
22
+ assert.isFunction(callback, 'callback');
23
+
24
+ const vSource = new Vector3(x, y, 0);
25
+ const vTarget = new Vector3();
26
+
27
+ graphicsEngine.normalizeViewportPoint(vSource, vSource);
28
+ graphicsEngine.viewportProjectionRay(vSource.x, vSource.y, vSource, vTarget);
29
+
30
+ const surfacePoint3 = new SurfacePoint3();
31
+
32
+ const hitFound = terrain.raycastFirstSync(surfacePoint3, vSource.x, vSource.y, vSource.z, vTarget.x, vTarget.y, vTarget.z);
33
+
34
+ if (!hitFound) {
35
+ // nothing found
36
+ } else {
37
+
38
+ const gridPosition = new Vector2();
39
+ terrain.mapPointWorld2Grid(surfacePoint3.position, gridPosition);
40
+ gridPosition._add(0.5, 0.5);
41
+ callback(gridPosition, surfacePoint3.position, surfacePoint3.normal);
42
+ }
43
+
44
+ }
@@ -1,6 +1,6 @@
1
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
2
1
  import Vector4 from "../../../core/geom/Vector4.js";
3
2
  import { Action } from "../../../core/process/undo/Action.js";
3
+ import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
4
4
 
5
5
  class PaintTerrainOverlayAction extends Action {
6
6
  /**
@@ -1,8 +1,8 @@
1
1
  import { EditorProcess } from "./EditorProcess.js";
2
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
3
2
  import GridObstacle from "../../engine/grid/components/GridObstacle.js";
4
3
  import GridPosition from "../../engine/grid/components/GridPosition.js";
5
4
  import { Sampler2D } from "../../engine/graphics/texture/sampler/Sampler2D.js";
5
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
6
6
 
7
7
  class ObstacleGridDisplayProcess extends EditorProcess {
8
8
 
@@ -4,7 +4,6 @@ import Task from "../../../core/process/task/Task.js";
4
4
  import TaskSignal from "../../../core/process/task/TaskSignal.js";
5
5
  import EntityBuilder from "../../../engine/ecs/EntityBuilder.js";
6
6
  import { BufferGeometry, Float32BufferAttribute, Line, LineBasicMaterial } from "three";
7
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
8
7
  import Renderable from "../../../engine/ecs/components/Renderable.js";
9
8
  import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
10
9
  import Vector3 from "../../../core/geom/Vector3.js";
@@ -14,6 +13,7 @@ import { EventType } from "../../../engine/ecs/EntityManager.js";
14
13
  import { make3DSymbolicDisplay } from "./make3DSymbolicDisplay.js";
15
14
  import GridPosition from "../../../engine/grid/components/GridPosition.js";
16
15
  import { ProcessState } from "../../../core/process/ProcessState.js";
16
+ import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
17
17
 
18
18
  /**
19
19
  *
@@ -1,12 +1,12 @@
1
1
  import Tool from "./engine/Tool.js";
2
2
  import Vector1 from "../../core/geom/Vector1.js";
3
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
4
3
  import ObservedValue from "../../core/model/ObservedValue.js";
5
4
  import Vector4 from "../../core/geom/Vector4.js";
6
5
  import loadSampler2D from "../../engine/graphics/texture/sampler/loadSampler2D.js";
7
6
  import convertSampler2D2Canvas from "../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
8
7
  import { InstancedMeshComponent } from "../../engine/ecs/foliage/ecs/InstancedMeshComponent.js";
9
8
  import { parseHex } from "../../core/color/parseHex.js";
9
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
10
10
 
11
11
  class FoliagePaintTool extends Tool {
12
12
  constructor() {
@@ -1,17 +1,17 @@
1
1
  import Tool from "./engine/Tool.js";
2
2
  import GridPosition from "../../engine/grid/components/GridPosition.js";
3
3
  import GridObstacle from "../../engine/grid/components/GridObstacle.js";
4
- import { pick } from "../../../model/game/util/ScreenGridPicker.js";
5
4
  import Vector4 from "../../core/geom/Vector4.js";
6
5
  import ObservedValue from "../../core/model/ObservedValue.js";
7
6
  import Vector1 from "../../core/geom/Vector1.js";
8
7
  import WriteGridValueAction from "../actions/concrete/WriteGridValueAction.js";
9
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
10
8
  import PaintTerrainOverlayAction from "../actions/concrete/PaintTerrainOverlayAction.js";
11
9
  import { decodeMouseEventButtons, PointerDevice } from "../../engine/input/devices/PointerDevice.js";
12
10
  import Vector2 from "../../core/geom/Vector2.js";
13
11
  import TopDownCameraControllerSystem from "../../engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
14
12
  import { parseHex } from "../../core/color/parseHex.js";
13
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
14
+ import { pick } from "../../ecs/grid/pick.js";
15
15
 
16
16
  class GridPaintTool extends Tool {
17
17
  constructor() {
@@ -1,14 +1,14 @@
1
1
  import { max2 } from "../../../core/math/max2.js";
2
2
  import Tool from "../engine/Tool.js";
3
3
  import { Color } from "../../../core/color/Color.js";
4
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
5
4
  import { Sampler2D } from "../../../engine/graphics/texture/sampler/Sampler2D.js";
6
5
  import Vector2 from "../../../core/geom/Vector2.js";
7
- import { pick } from "../../../../model/game/util/ScreenGridPicker.js";
8
6
  import convertSampler2D2Canvas from "../../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
9
7
  import ObservedString from "../../../core/model/ObservedString.js";
10
8
  import { GameAssetType } from "../../../engine/asset/GameAssetType.js";
11
9
  import Vector1 from "../../../core/geom/Vector1.js";
10
+ import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
11
+ import { pick } from "../../../ecs/grid/pick.js";
12
12
 
13
13
  export class TerrainPaintTool extends Tool {
14
14
  constructor() {
@@ -4,7 +4,7 @@ import { TerrainPaintTool } from "./TerrainPaintTool.js";
4
4
  import { Sampler2D } from "../../../engine/graphics/texture/sampler/Sampler2D.js";
5
5
  import { PatchTerrainTextureAction } from "../../actions/concrete/PatchTerrainTextureAction.js";
6
6
  import { convertSampler2D2DataURL } from "../../../engine/graphics/texture/sampler/convertSampler2D2DataURL.js";
7
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
7
+ import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
8
8
 
9
9
  export class TerrainTexturePaintTool extends TerrainPaintTool {
10
10
  constructor() {
@@ -22,7 +22,6 @@ import MeshLibraryView from "./library/MeshLibraryView.js";
22
22
  import BottomLeftResizeHandleView from "../../view/elements/BottomLeftResizeHandleView.js";
23
23
  import Vector2 from "../../core/geom/Vector2.js";
24
24
  import Vector3 from "../../core/geom/Vector3.js";
25
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
26
25
  import Mesh from "../../engine/graphics/ecs/mesh/Mesh.js";
27
26
  import { Transform } from "../../engine/ecs/transform/Transform.js";
28
27
  import SelectionClearAction from "../actions/concrete/SelectionClearAction.js";
@@ -32,6 +31,7 @@ import SelectionAddAction from "../actions/concrete/SelectionAddAction.js";
32
31
  import { noop, passThrough } from "../../core/function/Functions.js";
33
32
  import { ProcessState } from "../../core/process/ProcessState.js";
34
33
  import { MeshEvents } from "../../engine/graphics/ecs/mesh/MeshEvents.js";
34
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
35
35
 
36
36
  class ViewManager extends View {
37
37
  constructor() {
@@ -1,8 +1,8 @@
1
1
  import View from "../../view/View.js";
2
- import { pick } from "../../../model/game/util/ScreenGridPicker.js";
3
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
4
2
  import domify from "../../view/DOM.js";
5
3
  import { PointerDevice } from "../../engine/input/devices/PointerDevice.js";
4
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
5
+ import { pick } from "../../ecs/grid/pick.js";
6
6
 
7
7
  class GridPickCoordinateView extends View {
8
8
  /**
@@ -3,22 +3,7 @@ import { ParticleEmitter } from "../graphics/particles/particular/engine/emitter
3
3
 
4
4
  const lib = {
5
5
  'cloud-puff': {
6
- "position": {
7
- "x": 56.41791044776119,
8
- "y": -8.887834661270745,
9
- "z": 223.65671641791042
10
- },
11
- "scale": {
12
- "x": 1,
13
- "y": 1,
14
- "z": 1
15
- },
16
- "rotation": {
17
- "x": 0,
18
- "y": 0,
19
- "z": 0,
20
- "w": 1
21
- },
6
+ "receiveLight": true,
22
7
  "parameters": [
23
8
  {
24
9
  "name": "scale",
@@ -80,24 +65,24 @@ const lib = {
80
65
  "track": {
81
66
  "itemSize": 4,
82
67
  "data": [
83
- 0.9803921568627451,
84
- 0.9803921568627451,
85
- 0.9803921568627451,
86
- 0.3,
68
+ 0.6,
69
+ 0.6,
70
+ 0.6,
71
+ 0,
87
72
 
88
- 0.9882352941176471,
89
- 0.9882352941176471,
90
- 0.9882352941176471,
91
- 0.9880952380952381,
73
+ 0.6,
74
+ 0.6,
75
+ 0.6,
76
+ 1,
92
77
 
93
- 0.9882352941176471,
94
- 0.9882352941176471,
95
- 0.9882352941176471,
78
+ 0.6,
79
+ 0.6,
80
+ 0.6,
96
81
  0.5,
97
82
 
98
- 0.9882352941176471,
99
- 0.9882352941176471,
100
- 0.9882352941176471,
83
+ 0.6,
84
+ 0.6,
85
+ 0.6,
101
86
  0
102
87
  ],
103
88
  "positions": [
@@ -155,7 +140,13 @@ export function removeEntityGenericEffect(
155
140
  }
156
141
  ) {
157
142
 
158
- const emitter = ParticleEmitter.fromJSON(lib[particles]);
143
+ const particle_json = lib[particles];
144
+
145
+ if (particle_json === undefined) {
146
+ throw new Error(`Unsupported particle ID '${particles}'`);
147
+ }
148
+
149
+ const emitter = ParticleEmitter.fromJSON(particle_json);
159
150
 
160
151
  const result = removeEntityWithEffect({
161
152
  entity,
@@ -4,51 +4,6 @@
4
4
  * @param {string} type
5
5
  * @constructor
6
6
  */
7
- import { assert } from "../../core/assert.js";
8
- import { computeStringHash } from "../../core/primitives/strings/computeStringHash.js";
9
- import { computeHashIntegerArray } from "../../core/collection/array/computeHashIntegerArray.js";
10
-
11
- export class AssetDescription {
12
- /**
13
- *
14
- * @param {string} path
15
- * @param {string} type
16
- * @constructor
17
- */
18
- constructor(path, type) {
19
- assert.typeOf(path, 'string', 'path');
20
- assert.typeOf(type, 'string', 'type');
21
-
22
- /**
23
- * @type {string}
24
- */
25
- this.path = path;
26
- /**
27
- * @type {string}
28
- */
29
- this.type = type;
30
- }
31
-
32
- /**
33
- *
34
- * @param {AssetDescription} other
35
- * @returns {boolean}
36
- */
37
- equals(other) {
38
- return this.path === other.path && this.type === other.type;
39
- }
40
-
41
- /**
42
- *
43
- * @returns {number}
44
- */
45
- hash() {
46
- return computeHashIntegerArray(
47
- computeStringHash(this.path),
48
- computeStringHash(this.type)
49
- );
50
- }
51
- }
52
7
 
53
8
 
54
9
  export class Asset {
@@ -0,0 +1,51 @@
1
+ import { assert } from "../../core/assert.js";
2
+ import { computeHashIntegerArray } from "../../core/collection/array/computeHashIntegerArray.js";
3
+ import { computeStringHash } from "../../core/primitives/strings/computeStringHash.js";
4
+
5
+ export class AssetDescription {
6
+ /**
7
+ *
8
+ * @param {string} path
9
+ * @param {string} type
10
+ * @constructor
11
+ */
12
+ constructor(path, type) {
13
+ assert.isString(path, 'path');
14
+ assert.isString(type, 'type');
15
+
16
+ /**
17
+ * @type {string}
18
+ */
19
+ this.path = path;
20
+ /**
21
+ * @type {string}
22
+ */
23
+ this.type = type;
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @param {AssetDescription} other
29
+ * @returns {boolean}
30
+ */
31
+ equals(other) {
32
+ return this.path === other.path
33
+ && this.type === other.type
34
+ ;
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @returns {number}
40
+ */
41
+ hash() {
42
+ return computeHashIntegerArray(
43
+ computeStringHash(this.path),
44
+ computeStringHash(this.type)
45
+ );
46
+ }
47
+
48
+ toString() {
49
+ return `{ type: '${this.type}', path: '${this.path}' }`;
50
+ }
51
+ }
@@ -1,6 +1,7 @@
1
1
  import {AssetLoader} from "./loaders/AssetLoader";
2
2
  import {Asset} from "./Asset";
3
3
  import {CrossOriginConfig} from "./CORS/CrossOriginConfig";
4
+ import {AssetTransformer} from "./AssetTransformer";
4
5
 
5
6
  export class AssetManager {
6
7
  public readonly crossOriginConfig: CrossOriginConfig
@@ -12,4 +13,10 @@ export class AssetManager {
12
13
  public clear(): void
13
14
 
14
15
  public registerLoader<T>(type: string, loader: AssetLoader<T>): Promise<void>
16
+
17
+ public unregisterLoader(type: string): Promise<void>
18
+
19
+ public registerTransformer<T extends Asset<X>, X = any>(type: string, transformer: AssetTransformer<T>): void
20
+
21
+ public unregisterTransformer<T extends Asset<X>, X = any>(type: string, transformer: AssetTransformer<T>): boolean
15
22
  }
@@ -5,12 +5,13 @@
5
5
 
6
6
  import BoundedValue from "../../core/model/BoundedValue.js";
7
7
  import { ObservedMap } from "../../core/collection/ObservedMap.js";
8
- import { AssetDescription } from "./Asset.js";
9
8
  import { HashMap } from "../../core/collection/HashMap.js";
10
9
  import { extractAssetListFromManager } from "./preloader/extractAssetListFromManager.js";
11
10
  import { assert } from "../../core/assert.js";
12
11
  import { HashSet } from "../../core/collection/HashSet.js";
13
12
  import { CrossOriginConfig } from "./CORS/CrossOriginConfig.js";
13
+ import { array_remove_element } from "../../core/collection/array/array_remove_element.js";
14
+ import { AssetDescription } from "./AssetDescription.js";
14
15
 
15
16
  /**
16
17
  *
@@ -62,6 +63,13 @@ function AssetManager(engine) {
62
63
  */
63
64
  this.loaders = {};
64
65
 
66
+ /**
67
+ * After asset is loaded, a chain of transforms can be applied to it, these are registered here
68
+ * Transformers are executed in the order in which they are added
69
+ * @type {Object<AssetTransformer[]>}
70
+ */
71
+ this.transformers = {};
72
+
65
73
  /**
66
74
  * Named links to specific assets. Useful to later re-mapping assets and having meaningful names for them
67
75
  * @type {Map<string, AssetDescription>}
@@ -209,7 +217,30 @@ AssetManager.prototype.submitRequest = function (path, type, request) {
209
217
  const assets = this.assets;
210
218
  const failures = this.failures;
211
219
 
212
- function success(asset) {
220
+ /**
221
+ *
222
+ * @param {Asset} loaded_asset
223
+ */
224
+ const success = async (loaded_asset) => {
225
+ let asset = loaded_asset;
226
+
227
+ // apply transform chain
228
+ const transformers = this.transformers[type];
229
+ if (transformers !== undefined) {
230
+ const transformer_count = transformers.length;
231
+ for (let i = 0; i < transformer_count; i++) {
232
+ const transformer = transformers[i];
233
+
234
+ const transformed_asset = await transformer.transform(asset);
235
+
236
+ if (typeof transformed_asset !== "object") {
237
+ console.error('Transformer produced invalid result. Ignoring result.', transformer, assetDescription);
238
+ } else {
239
+ asset = transformed_asset;
240
+ }
241
+ }
242
+ }
243
+
213
244
  //link asset description
214
245
  asset.description = assetDescription;
215
246
 
@@ -298,6 +329,71 @@ AssetManager.prototype.getLoaderByType = function (type) {
298
329
  return this.loaders[type];
299
330
  };
300
331
 
332
+ /**
333
+ *
334
+ * @param {string} type
335
+ * @return {AssetDescription[]}
336
+ * @private
337
+ */
338
+ AssetManager.prototype.__getLoadedAssetDescriptorsByType = function (type) {
339
+ const loaded_assets = Array.from(this.assets.keys());
340
+ return loaded_assets.filter(t => t.type === type);
341
+ }
342
+
343
+ /**
344
+ * @template T
345
+ * @param {string} type
346
+ * @param {AssetTransformer<T>} transformer
347
+ */
348
+ AssetManager.prototype.registerTransformer = function (type, transformer) {
349
+ let transformers = this.transformers[type];
350
+
351
+ if (transformers === undefined) {
352
+ transformers = [];
353
+
354
+ this.transformers[type] = transformers;
355
+ }
356
+
357
+ transformers.push(transformer);
358
+
359
+ // check for loaded assets
360
+ const matching_assets = this.__getLoadedAssetDescriptorsByType(type);
361
+
362
+ if (matching_assets.length > 0) {
363
+ console.warn(`Following assets of matching type '${type}' are already loaded and transform is not applied to them:\n\t${matching_assets.join('\n\t')}`);
364
+ }
365
+
366
+ };
367
+
368
+ /**
369
+ * @template T
370
+ * @param {string} type
371
+ * @param {AssetTransformer<T>} transformer
372
+ */
373
+ AssetManager.prototype.unregisterTransformer = function (type, transformer) {
374
+
375
+ const transformers = this.transformers[type];
376
+
377
+ if (transformers === undefined) {
378
+ // not found
379
+ return false;
380
+ }
381
+
382
+ if (!array_remove_element(transformers, 0, transformers.length, transformer)) {
383
+ // not found
384
+ return false;
385
+ }
386
+
387
+ // check for loaded assets
388
+ const matching_assets = this.__getLoadedAssetDescriptorsByType(type);
389
+
390
+ if (matching_assets.length > 0) {
391
+ console.warn(`Following assets of matching type '${type}' are already loaded and transform was probably already applied to them:\n\t${matching_assets.join('\n\t')}`);
392
+ }
393
+
394
+ return true;
395
+ }
396
+
301
397
  /**
302
398
  * @template T
303
399
  * @param {string} type
@@ -0,0 +1,5 @@
1
+ import {Asset} from "./Asset";
2
+
3
+ export class AssetTransformer<A extends Asset<T>, T = any> {
4
+ transform(source: A): Promise<A>
5
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Applies a transformation to an asset. Such as performing mesh simplification for example.
3
+ * Transformation is executed by the {@link AssetManager}
4
+ * @template {Asset<T>} A
5
+ * @template T
6
+ */
7
+ export class AssetTransformer {
8
+ /**
9
+ * @param {A} source
10
+ * @returns {A}
11
+ */
12
+ async transform(source) {
13
+ throw new Error('Not Implemented');
14
+ }
15
+ }