@woosh/meep-engine 2.37.17 → 2.37.20

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 (206) hide show
  1. package/core/assert.js +1 -1
  2. package/core/binary/float2uint8.js +8 -0
  3. package/core/binary/uint82float.js +8 -0
  4. package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +6 -4
  5. package/core/collection/array/typed/isTypedArray.js +20 -0
  6. package/core/collection/array/typedArrayToDataType.js +1 -0
  7. package/core/collection/list/List.d.ts +1 -1
  8. package/core/collection/table/RowFirstTable.js +34 -0
  9. package/core/collection/table/RowFirstTable.spec.js +59 -1
  10. package/core/color/Color.js +83 -1
  11. package/core/color/YCbCr_to_rgb_uint24.js +3 -4
  12. package/core/color/hsv2rgb.js +4 -3
  13. package/core/color/linear_to_sRGB.js +4 -5
  14. package/core/color/rgb2hex.js +1 -1
  15. package/core/color/rgb2uint24.js +6 -4
  16. package/core/color/rgb_to_YCbCr_uint24.js +11 -13
  17. package/core/events/signal/Signal.d.ts +11 -9
  18. package/core/events/signal/Signal.js +8 -8
  19. package/core/events/signal/Signal.spec.js +16 -0
  20. package/core/geom/2d/quad-tree/qt_collect_by_circle.js +67 -0
  21. package/core/geom/Quaternion.d.ts +21 -1
  22. package/core/geom/Quaternion.js +279 -200
  23. package/core/geom/Quaternion.spec.js +71 -2
  24. package/core/geom/Vector2.js +3 -3
  25. package/core/geom/Vector3.d.ts +2 -0
  26. package/core/geom/Vector3.js +31 -7
  27. package/core/geom/Vector3.schema.json +16 -0
  28. package/core/geom/Vector4.js +16 -0
  29. package/core/json/JsonUtils.js +2 -20
  30. package/core/math/bell_membership_function.js +19 -0
  31. package/core/math/exp2.js +8 -0
  32. package/core/math/interval/NumericInterval.js +17 -0
  33. package/core/math/physics/brdf/brdf_burley.js +25 -0
  34. package/core/math/physics/bsdf/bsdf_schlick.js +22 -0
  35. package/core/math/physics/irradiance/interpolate_irradiance_linear.js +18 -0
  36. package/{engine/sound/ecs/emitter/attenuate/attenuateSoundLogarithmic.js → core/math/physics/irradiance/interpolate_irradiance_lograrithmic.js} +2 -2
  37. package/{engine/sound/ecs/emitter/attenuate/attenuateSoundSmith.js → core/math/physics/irradiance/interpolate_irradiance_smith.js} +1 -1
  38. package/core/model/ObservedEnum.js +8 -0
  39. package/editor/Editor.js +97 -1
  40. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
  41. package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
  42. package/editor/actions/concrete/PatchTerrainHeightAction.js +13 -105
  43. package/editor/ecs/component/FieldDescriptor.js +34 -0
  44. package/editor/ecs/component/FieldValueAdapter.js +20 -0
  45. package/editor/ecs/component/TypeEditor.js +33 -0
  46. package/editor/ecs/component/TypeSchema.d.ts +38 -0
  47. package/editor/ecs/component/createFieldEditor.js +90 -0
  48. package/editor/ecs/component/createObjectEditor.js +266 -60
  49. package/editor/ecs/component/editors/ColorEditor.js +39 -0
  50. package/editor/ecs/component/editors/HTMLElementEditor.js +17 -0
  51. package/editor/ecs/component/editors/ImagePathEditor.js +50 -0
  52. package/editor/ecs/component/editors/NumericIntervalEditor.js +86 -0
  53. package/editor/ecs/component/editors/ObservedBooleanEditor.js +13 -0
  54. package/editor/ecs/component/editors/ObservedEnumEditor.js +32 -0
  55. package/editor/ecs/component/editors/ObservedIntegerEditor.js +43 -0
  56. package/editor/ecs/component/editors/ObservedStringEditor.js +51 -0
  57. package/editor/ecs/component/editors/Sampler2DEditor.js +107 -0
  58. package/editor/ecs/component/editors/collection/ListEditor.js +83 -0
  59. package/editor/ecs/component/editors/common/BitFlagsEditor.js +80 -0
  60. package/editor/ecs/component/editors/common/EnumEditor.js +41 -0
  61. package/editor/ecs/component/editors/common/makeV3_editor.js +85 -0
  62. package/editor/ecs/component/editors/common/noEditor.js +9 -0
  63. package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +17 -0
  64. package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.js +16 -0
  65. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +44 -0
  66. package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
  67. package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
  68. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +54 -0
  69. package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.js +21 -0
  70. package/editor/ecs/component/editors/ecs/Trail2DEditor.js +33 -0
  71. package/editor/ecs/component/editors/ecs/TransformEditor.js +23 -0
  72. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +21 -0
  73. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +89 -0
  74. package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.js +18 -0
  75. package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.js +22 -0
  76. package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.js +20 -0
  77. package/editor/ecs/component/editors/geom/QuaternionEditor.js +56 -0
  78. package/editor/ecs/component/editors/geom/Vector1Editor.js +57 -0
  79. package/editor/ecs/component/editors/geom/Vector2Editor.js +11 -0
  80. package/editor/ecs/component/editors/geom/Vector3Editor.js +13 -0
  81. package/editor/ecs/component/editors/geom/Vector4Editor.js +12 -0
  82. package/editor/ecs/component/editors/primitive/ArrayEditor.js +46 -0
  83. package/editor/ecs/component/editors/primitive/BooleanEditor.js +27 -0
  84. package/editor/ecs/component/editors/primitive/FunctionEditor.js +29 -0
  85. package/editor/ecs/component/editors/primitive/NumberEditor.js +60 -0
  86. package/editor/ecs/component/editors/primitive/ObjectEditor.js +12 -0
  87. package/editor/ecs/component/editors/primitive/StringEditor.js +31 -0
  88. package/editor/ecs/component/editors/three/BufferGeometryEditor.js +28 -0
  89. package/editor/ecs/component/editors/three/MaterialEditor.js +27 -0
  90. package/editor/ecs/component/editors/three/MeshEditor.js +35 -0
  91. package/editor/ecs/component/editors/three/TextureEditor.js +32 -0
  92. package/editor/ecs/component/findNearestRegisteredType.js +59 -0
  93. package/editor/ecs/component/prototypeObjectEditor.js +379 -0
  94. package/editor/tools/SelectionTool.js +1 -1
  95. package/editor/tools/paint/TerrainHeightPaintTool.js +88 -68
  96. package/editor/tools/paint/TerrainPaintTool.js +2 -1
  97. package/editor/tools/paint/TerrainTexturePaintTool.js +8 -73
  98. package/editor/view/EditorView.js +1 -1
  99. package/editor/view/ecs/ComponentControlView.js +2 -30
  100. package/editor/view/ecs/EntityEditor.js +61 -139
  101. package/editor/view/ecs/components/GridObstacleController.js +4 -4
  102. package/editor/view/ecs/components/TerrainController.js +1 -1
  103. package/editor/view/ecs/components/common/NumberController.js +19 -7
  104. package/engine/animation/keyed2/AnimationTrack.js +1 -1
  105. package/engine/asset/AssetManager.d.ts +1 -1
  106. package/engine/asset/AssetManager.js +390 -388
  107. package/engine/asset/loaders/gltf/extensions/MSFT_texture_dds.js +14 -2
  108. package/engine/ecs/components/TagEditor.js +15 -0
  109. package/engine/ecs/fow/FogOfWarEditor.js +13 -0
  110. package/engine/ecs/terrain/ecs/OffsetScaleTransform2D.d.ts +6 -0
  111. package/engine/ecs/terrain/ecs/Terrain.js +44 -43
  112. package/engine/ecs/terrain/ecs/TerrainSystem.js +2 -2
  113. package/engine/ecs/terrain/ecs/layers/TerrainLayer.js +1 -1
  114. package/engine/ecs/terrain/ecs/splat/SplatMapping.js +26 -28
  115. package/engine/ecs/terrain/overlay/TerrainOverlay.js +71 -66
  116. package/engine/ecs/terrain/tiles/TerrainTileManager.js +23 -0
  117. package/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +1 -1
  118. package/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +13 -7
  119. package/engine/ecs/transform/Transform.d.ts +2 -0
  120. package/engine/ecs/transform/Transform.editor.schema.json +16 -0
  121. package/engine/ecs/transform/Transform.js +3 -0
  122. package/engine/graphics/ecs/highlight/HighlightEditor.js +17 -0
  123. package/engine/graphics/ecs/light/Light.js +0 -47
  124. package/engine/graphics/ecs/light/LightSerializationAdapter.js +50 -0
  125. package/engine/graphics/ecs/mesh/MeshEditor.js +28 -0
  126. package/engine/graphics/ecs/mesh-v2/DrawMode.js +2 -1
  127. package/engine/graphics/ecs/mesh-v2/aggregate/prototypeSGMesh.js +3 -3
  128. package/engine/graphics/ecs/mesh-v2/build_three_object.js +3 -1
  129. package/engine/graphics/ecs/sprite/Sprite.js +11 -0
  130. package/engine/graphics/ecs/sprite/SpriteSystemPE.js +133 -0
  131. package/engine/graphics/ecs/sprite/prototypeSpriteSystem.js +1566 -0
  132. package/engine/graphics/micron/prototypeVirtualGeometry.js +2 -2
  133. package/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +15 -15
  134. package/engine/graphics/particles/particular/engine/ParticularEngine.js +5 -0
  135. package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +17 -9
  136. package/engine/graphics/particles/particular/engine/renderers/ParticleRenderer.js +12 -10
  137. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +7 -2
  138. package/engine/graphics/particles/particular/engine/renderers/billboard/SoftBillboardParticlePool.js +27 -0
  139. package/engine/graphics/particles/particular/engine/renderers/billboard/SoftBillboardParticleRenderer.js +80 -0
  140. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +16 -4
  141. package/engine/graphics/shaders/TerrainShader.js +8 -8
  142. package/engine/graphics/texture/atlas/TextureAtlasDebugger.js +2 -1
  143. package/engine/graphics/texture/sampler/Sampler2D.js +206 -201
  144. package/engine/graphics/texture/sampler/Sampler2D.spec.js +34 -35
  145. package/engine/graphics/texture/sampler/bicubic.js +59 -0
  146. package/engine/graphics/texture/sampler/downsampleSample2D.spec.js +2 -2
  147. package/engine/graphics/texture/sampler/genericResampleSampler2D.js +0 -2
  148. package/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +146 -0
  149. package/engine/graphics/texture/sampler/{downsampleSampler2D.js → sampler2D_scale_down_linear.js} +8 -4
  150. package/engine/graphics/texture/sampler/sampler2_d_scale_down_lanczos.js +140 -0
  151. package/engine/graphics/texture/sampler/scaleSampler2D.js +3 -3
  152. package/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.js +1 -1
  153. package/engine/graphics/util/ScaleObject3ToBox.js +14 -1
  154. package/engine/graphics/util/makeMeshPreviewScene.js +2 -1
  155. package/engine/grid/components/GridObstacle.js +0 -44
  156. package/engine/grid/components/GridObstacleSerializationAdapter.js +46 -0
  157. package/engine/input/ecs/util/TerrainCameraTargetSampler.js +2 -2
  158. package/engine/navigation/ecs/components/Path.d.ts +2 -0
  159. package/engine/navigation/ecs/components/Path.js +6 -1
  160. package/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +117 -0
  161. package/engine/platform/GetURLHash.js +27 -0
  162. package/engine/platform/WebEnginePlatform.js +1 -22
  163. package/engine/sound/ecs/emitter/SoundEmitter.js +10 -6
  164. package/generation/GridGenerator.js +7 -6
  165. package/generation/example/SampleGenerator0.js +39 -35
  166. package/generation/example/filters/SampleGroundMoistureFilter.js +58 -17
  167. package/generation/example/generators/interactive/mir_generator_place_buff_objects.js +7 -6
  168. package/generation/example/generators/mir_generator_place_bases.js +7 -3
  169. package/generation/example/generators/mir_generator_place_road_decorators.js +3 -3
  170. package/generation/example/generators/mir_generator_place_starting_point.js +3 -2
  171. package/generation/example/themes/SampleTheme0.js +11 -7
  172. package/generation/filtering/numeric/CellFilterLiteralFloat.js +5 -0
  173. package/generation/filtering/numeric/complex/CellFilterDilate.js +36 -0
  174. package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +15 -5
  175. package/generation/filtering/numeric/complex/CellFilterSimplexNoise.js +53 -1
  176. package/generation/filtering/numeric/math/CellFilterMax2.js +3 -0
  177. package/generation/filtering/numeric/math/CellFilterMembershipGeneralizedBell.js +55 -0
  178. package/generation/filtering/numeric/sampling/AbstractCellFilterSampleGridLayer.js +42 -0
  179. package/generation/filtering/numeric/sampling/CellFilterSampleLayerCubic.js +36 -0
  180. package/generation/filtering/numeric/sampling/CellFilterSampleLayerLinear.js +41 -0
  181. package/generation/grid/GridData.d.ts +5 -1
  182. package/generation/grid/GridData.js +35 -36
  183. package/generation/grid/MarkerMatchCounter.js +5 -3
  184. package/generation/markers/GridActionRuleSet.js +15 -32
  185. package/generation/markers/GridCellActionPlaceMarker.js +12 -8
  186. package/generation/markers/debug/visualizeMarkers.js +56 -36
  187. package/generation/markers/emitter/MarkerNodeEmitterFromAction.js +8 -8
  188. package/generation/markers/prototypeGridCellActionPlaceMarker.js +209 -0
  189. package/generation/markers/transform/MarkerNodeTransformerOffsetPosition.js +1 -5
  190. package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.spec.js +2 -2
  191. package/generation/placement/GridCellPlacementRule.js +31 -25
  192. package/generation/theme/ThemeEngine.js +1 -1
  193. package/package.json +1 -1
  194. package/samples/terrain/from_image.js +7 -3
  195. package/samples/terrain/main.js +1 -1
  196. package/view/View.js +23 -1
  197. package/view/common/LabelView.js +1 -1
  198. package/view/compose3x3transform.js +32 -8
  199. package/view/controller/dat/DatGuiUtils.js +1 -1
  200. package/view/elements/DropDownSelectionView.js +11 -3
  201. package/view/elements/image/ImageView.js +3 -1
  202. package/core/model/ObservedReal.js +0 -55
  203. package/editor/ecs/component/ObjectEditor.js +0 -0
  204. package/engine/graphics/particles/particular/engine/renderers/SoftBillboardParticleRenderer.js +0 -7
  205. package/engine/sound/ecs/emitter/attenuate/attenuateSoundLinear.js +0 -11
  206. package/generation/filtering/numeric/CellFilterReadGridLayer.js +0 -73
@@ -40,503 +40,505 @@ function PendingAsset(description) {
40
40
 
41
41
 
42
42
  /**
43
- *
44
- * @param {Engine} engine
45
- * @constructor
43
+ * @class
46
44
  */
47
- function AssetManager(engine) {
45
+ export class AssetManager {
48
46
  /**
49
47
  *
50
- * @type {HashMap<AssetDescription, Asset>}
48
+ * @param {Engine} engine
49
+ * @constructor
51
50
  */
52
- this.assets = new HashMap();
51
+ constructor(engine) {
52
+ /**
53
+ *
54
+ * @type {HashMap<AssetDescription, Asset>}
55
+ */
56
+ this.assets = new HashMap();
57
+
58
+ /**
59
+ *
60
+ * @type {ObservedMap<AssetDescription, PendingAsset>}
61
+ */
62
+ this.requestMap = new ObservedMap(new HashMap());
63
+
64
+ /**
65
+ * Registered loaders
66
+ * @type {Object<AssetLoader>}
67
+ */
68
+ this.loaders = {};
69
+
70
+ /**
71
+ * After asset is loaded, a chain of transforms can be applied to it, these are registered here
72
+ * Transformers are executed in the order in which they are added
73
+ * @type {Object<AssetTransformer[]>}
74
+ */
75
+ this.transformers = {};
76
+
77
+ /**
78
+ * Named links to specific assets. Useful to later re-mapping assets and having meaningful names for them
79
+ * @type {Map<string, AssetDescription>}
80
+ */
81
+ this.aliases = new Map();
82
+
83
+ /**
84
+ * This will be added to asset path for actual network resolution
85
+ * @type {string}
86
+ */
87
+ this.rootPath = '';
88
+
89
+ /**
90
+ *
91
+ * @type {Engine}
92
+ * @private
93
+ */
94
+ this.__engine = engine;
95
+
96
+ /**
97
+ *
98
+ * @type {CrossOriginConfig}
99
+ */
100
+ this.crossOriginConfig = new CrossOriginConfig();
101
+
102
+ /**
103
+ *
104
+ * @type {HashSet<AssetDescription>}
105
+ */
106
+ this.failures = new HashSet();
107
+ /**
108
+ * @readonly
109
+ * @type {boolean}
110
+ */
111
+ this.isAssetManager = true;
112
+ }
53
113
 
54
114
  /**
55
- *
56
- * @type {ObservedMap<AssetDescription, PendingAsset>}
115
+ * Remove asset if it is loaded, does nothing otherwise
116
+ * @param {String} path
117
+ * @param {String} type
118
+ * @returns {boolean} true if asset was removed, else otherwise
57
119
  */
58
- this.requestMap = new ObservedMap(new HashMap());
120
+ remove(path, type) {
59
121
 
60
- /**
61
- * Registered loaders
62
- * @type {Object<AssetLoader>}
63
- */
64
- this.loaders = {};
122
+ const assetDescription = new AssetDescription(path, type);
65
123
 
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 = {};
124
+ return this.assets.delete(assetDescription);
125
+ }
72
126
 
73
127
  /**
74
- * Named links to specific assets. Useful to later re-mapping assets and having meaningful names for them
75
- * @type {Map<string, AssetDescription>}
128
+ * Clear out all loaded assets
76
129
  */
77
- this.aliases = new Map();
130
+ clear() {
131
+ this.assets.clear();
132
+ }
133
+
134
+ dumpLoadedAssetList() {
135
+ return JSON.stringify(extractAssetListFromManager(this), 3, 3);
136
+ }
78
137
 
79
138
  /**
80
- * This will be added to asset path for actual network resolution
81
- * @type {string}
139
+ * @param {String} path
140
+ * @param {String} type
141
+ * @returns {Promise<Asset>}
82
142
  */
83
- this.rootPath = '';
143
+ promise(path, type) {
144
+ return new Promise((resolve, reject) => {
145
+ this.get(path, type, resolve, reject);
146
+ });
147
+ }
84
148
 
85
149
  /**
86
150
  *
87
- * @type {Engine}
88
- * @private
151
+ * @param {String} path
152
+ * @param {String} type
153
+ * @param {function(asset:Asset)} callback
154
+ * @param {function(*)} failure
155
+ * @param {function(loaded:number, total:number)} [progress]
89
156
  */
90
- this.__engine = engine;
157
+ get(path, type, callback, failure, progress) {
158
+ if (typeof path !== "string") {
159
+ throw new Error("Path must be string. Path = " + JSON.stringify(path));
160
+ }
161
+
162
+ const assetDescription = new AssetDescription(path, type);
163
+
164
+ const asset = this.assets.get(assetDescription);
165
+
166
+ if (asset !== undefined) {
167
+ callback(asset);
168
+ } else {
169
+ //create request object
170
+ const assetRequest = new AssetRequest(callback, failure, progress);
171
+ //submit request
172
+ this.submitRequest(path, type, assetRequest);
173
+ }
174
+ }
91
175
 
92
176
  /**
93
177
  *
94
- * @type {CrossOriginConfig}
178
+ * @param {string} path
179
+ * @param {string} type
180
+ * @param {Asset} asset
95
181
  */
96
- this.crossOriginConfig = new CrossOriginConfig();
182
+ insert(path, type, asset) {
183
+ const assetDescription = new AssetDescription(path, type);
184
+
185
+ this.assets.set(assetDescription, asset);
186
+ }
97
187
 
98
188
  /**
99
189
  *
100
- * @type {HashSet<AssetDescription>}
190
+ * @param {string} path
191
+ * @param {string} type
192
+ * @param {AssetRequest} request
193
+ * @private
101
194
  */
102
- this.failures = new HashSet();
103
- }
195
+ submitRequest(path, type, request) {
196
+ const requestMap = this.requestMap;
104
197
 
105
- /**
106
- * Remove asset if it is loaded, does nothing otherwise
107
- * @param {String} path
108
- * @param {String} type
109
- * @returns {boolean} true if asset was removed, else otherwise
110
- */
111
- AssetManager.prototype.remove = function (path, type) {
198
+ const assetDescription = new AssetDescription(path, type);
112
199
 
113
- const assetDescription = new AssetDescription(path, type);
200
+ let pendingAsset = requestMap.get(assetDescription);
201
+ if (pendingAsset !== undefined) {
202
+ //already loading
203
+ pendingAsset.requests.push(request);
204
+ return;
205
+ }
114
206
 
115
- return this.assets.delete(assetDescription);
116
- };
207
+ pendingAsset = new PendingAsset(assetDescription);
117
208
 
118
- /**
119
- * Clear out all loaded assets
120
- */
121
- AssetManager.prototype.clear = function () {
122
- this.assets.clear();
123
- };
209
+ requestMap.set(assetDescription, pendingAsset);
124
210
 
125
- AssetManager.prototype.dumpLoadedAssetList = function () {
126
- return JSON.stringify(extractAssetListFromManager(this), 3, 3);
127
- };
211
+ const requests = pendingAsset.requests;
212
+ requests.push(request);
128
213
 
129
- /**
130
- * @param {String} path
131
- * @param {String} type
132
- * @returns {Promise<Asset>}
133
- */
134
- AssetManager.prototype.promise = function (path, type) {
135
- return new Promise((resolve, reject) => {
136
- this.get(path, type, resolve, reject);
137
- });
138
- };
214
+ const loader = this.loaders[type];
139
215
 
140
- /**
141
- *
142
- * @param {String} path
143
- * @param {String} type
144
- * @param {function(asset:Asset)} callback
145
- * @param {function(*)} failure
146
- * @param {function(loaded:number, total:number)} [progress]
147
- */
148
- AssetManager.prototype.get = function (path, type, callback, failure, progress) {
149
- if (typeof path !== "string") {
150
- throw new Error("Path must be string. Path = " + JSON.stringify(path));
151
- }
216
+ if (loader === void 0) {
217
+ if (typeof request.failureCallback === "function") {
218
+ request.failureCallback(`no loader exists for asset type '${type}', valid types are: ${Object.keys(this.loaders).join(', ')}`);
219
+ } else {
220
+ //uncaught
221
+ console.error("Uncaught asset load failure: No loader for asset type", type);
222
+ }
223
+ return;
224
+ }
152
225
 
153
- const assetDescription = new AssetDescription(path, type);
226
+ const assets = this.assets;
227
+ const failures = this.failures;
228
+
229
+ /**
230
+ *
231
+ * @param {Asset} loaded_asset
232
+ */
233
+ const success = async (loaded_asset) => {
234
+ let asset = loaded_asset;
235
+
236
+ // apply transform chain
237
+ const transformers = this.transformers[type];
238
+ if (transformers !== undefined) {
239
+ const transformer_count = transformers.length;
240
+ for (let i = 0; i < transformer_count; i++) {
241
+ const transformer = transformers[i];
242
+
243
+ const transformed_asset = await transformer.transform(asset, assetDescription);
244
+
245
+ if (typeof transformed_asset !== "object") {
246
+ console.error('Transformer produced invalid result. Ignoring result.', transformer, assetDescription);
247
+ } else {
248
+ asset = transformed_asset;
249
+ }
250
+ }
251
+ }
154
252
 
155
- const asset = this.assets.get(assetDescription);
253
+ //link asset description
254
+ asset.description = assetDescription;
156
255
 
157
- if (asset !== undefined) {
158
- callback(asset);
159
- } else {
160
- //create request object
161
- const assetRequest = new AssetRequest(callback, failure, progress);
162
- //submit request
163
- this.submitRequest(path, type, assetRequest);
164
- }
165
- };
256
+ //register asset
257
+ assets.set(assetDescription, asset);
258
+ requests.forEach(function (request) {
259
+ try {
260
+ request.successCallback(asset);
261
+ } catch (e) {
262
+ console.error("Failed to execute asset success callback", e);
263
+ }
264
+ });
265
+ //clear callbacks
266
+ requestMap.delete(assetDescription);
267
+ }
166
268
 
167
- /**
168
- *
169
- * @param {string} path
170
- * @param {string} type
171
- * @param {Asset} asset
172
- */
173
- AssetManager.prototype.insert = function (path, type, asset) {
174
- const assetDescription = new AssetDescription(path, type);
269
+ function failure(error) {
270
+ requests.forEach(function (request) {
271
+ try {
272
+ request.failureCallback(error);
273
+ } catch (e) {
274
+ console.error("Failed to execute asset failure callback", e);
275
+ }
276
+ });
277
+ //clear callbacks
278
+ requestMap.delete(assetDescription);
175
279
 
176
- this.assets.set(assetDescription, asset);
177
- };
280
+ // record failure
281
+ failures.add(assetDescription);
282
+ }
178
283
 
179
- /**
180
- *
181
- * @param {string} path
182
- * @param {string} type
183
- * @param {AssetRequest} request
184
- * @private
185
- */
186
- AssetManager.prototype.submitRequest = function (path, type, request) {
187
- const requestMap = this.requestMap;
284
+ function progress(current, total) {
285
+ requests.forEach(function (request) {
286
+ if (typeof request.pogressCallback !== "function") {
287
+ //progress callback is not a function, ignore
288
+ return;
289
+ }
188
290
 
189
- const assetDescription = new AssetDescription(path, type);
291
+ try {
292
+ request.pogressCallback(current, total);
293
+ } catch (e) {
294
+ console.error("Failed to execute asset progress callback", e);
295
+ }
296
+ });
190
297
 
191
- let pendingAsset = requestMap.get(assetDescription);
192
- if (pendingAsset !== undefined) {
193
- //already loading
194
- pendingAsset.requests.push(request);
195
- return;
196
- }
298
+ pendingAsset.progress.setValue(current);
299
+ pendingAsset.progress.setUpperLimit(total);
300
+ }
197
301
 
198
- pendingAsset = new PendingAsset(assetDescription);
302
+ try {
303
+ const fullPath = this.rootPath + path;
199
304
 
200
- requestMap.set(assetDescription, pendingAsset);
305
+ if (typeof loader === "function") {
201
306
 
202
- const requests = pendingAsset.requests;
203
- requests.push(request);
307
+ loader(fullPath, success, failure, progress);
204
308
 
205
- const loader = this.loaders[type];
309
+ } else {
206
310
 
207
- if (loader === void 0) {
208
- if (typeof request.failureCallback === "function") {
209
- request.failureCallback(`no loader exists for asset type '${type}', valid types are: ${Object.keys(this.loaders).join(', ')}`);
210
- } else {
211
- //uncaught
212
- console.error("Uncaught asset load failure: No loader for asset type", type);
311
+ loader.load(fullPath, success, failure, progress);
312
+
313
+ }
314
+
315
+ } catch (e) {
316
+ console.error(`Loader failed on invocation. path=${path}, type=${type}`, request, 'Loader exception: ', e);
317
+ failure(e);
213
318
  }
214
- return;
215
319
  }
216
320
 
217
- const assets = this.assets;
218
- const failures = this.failures;
219
-
220
321
  /**
221
322
  *
222
- * @param {Asset} loaded_asset
323
+ * @param {string} type
324
+ * @return {boolean}
223
325
  */
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, assetDescription);
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
-
244
- //link asset description
245
- asset.description = assetDescription;
246
-
247
- //register asset
248
- assets.set(assetDescription, asset);
249
- requests.forEach(function (request) {
250
- try {
251
- request.successCallback(asset);
252
- } catch (e) {
253
- console.error("Failed to execute asset success callback", e);
254
- }
255
- });
256
- //clear callbacks
257
- requestMap.delete(assetDescription);
326
+ hasLoaderForType(type) {
327
+ return this.getLoaderByType(type) !== undefined;
258
328
  }
259
329
 
260
- function failure(error) {
261
- requests.forEach(function (request) {
262
- try {
263
- request.failureCallback(error);
264
- } catch (e) {
265
- console.error("Failed to execute asset failure callback", e);
266
- }
267
- });
268
- //clear callbacks
269
- requestMap.delete(assetDescription);
330
+ /**
331
+ *
332
+ * @param {string} type
333
+ * @returns {AssetLoader|undefined}
334
+ */
335
+ getLoaderByType(type) {
336
+ assert.isString(type, 'type');
270
337
 
271
- // record failure
272
- failures.add(assetDescription);
338
+ return this.loaders[type];
273
339
  }
274
340
 
275
- function progress(current, total) {
276
- requests.forEach(function (request) {
277
- if (typeof request.pogressCallback !== "function") {
278
- //progress callback is not a function, ignore
279
- return;
280
- }
281
-
282
- try {
283
- request.pogressCallback(current, total);
284
- } catch (e) {
285
- console.error("Failed to execute asset progress callback", e);
286
- }
287
- });
288
-
289
- pendingAsset.progress.setValue(current);
290
- pendingAsset.progress.setUpperLimit(total);
341
+ /**
342
+ *
343
+ * @param {string} type
344
+ * @return {AssetDescription[]}
345
+ * @private
346
+ */
347
+ __getLoadedAssetDescriptorsByType(type) {
348
+ const loaded_assets = Array.from(this.assets.keys());
349
+ return loaded_assets.filter(t => t.type === type);
291
350
  }
292
351
 
293
- try {
294
- const fullPath = this.rootPath + path;
352
+ /**
353
+ * @template T
354
+ * @param {string} type
355
+ * @param {AssetTransformer<T>} transformer
356
+ */
357
+ registerTransformer(type, transformer) {
358
+ let transformers = this.transformers[type];
295
359
 
296
- if (typeof loader === "function") {
360
+ if (transformers === undefined) {
361
+ transformers = [];
297
362
 
298
- loader(fullPath, success, failure, progress);
363
+ this.transformers[type] = transformers;
364
+ }
299
365
 
300
- } else {
366
+ transformers.push(transformer);
301
367
 
302
- loader.load(fullPath, success, failure, progress);
368
+ // check for loaded assets
369
+ const matching_assets = this.__getLoadedAssetDescriptorsByType(type);
303
370
 
371
+ if (matching_assets.length > 0) {
372
+ 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')}`);
304
373
  }
305
374
 
306
- } catch (e) {
307
- console.error(`Loader failed on invocation. path=${path}, type=${type}`, request, 'Loader exception: ', e);
308
- failure(e);
309
375
  }
310
- };
311
376
 
312
- /**
313
- *
314
- * @param {string} type
315
- * @return {boolean}
316
- */
317
- AssetManager.prototype.hasLoaderForType = function (type) {
318
- return this.getLoaderByType(type) !== undefined;
319
- }
320
-
321
- /**
322
- *
323
- * @param {string} type
324
- * @returns {AssetLoader|undefined}
325
- */
326
- AssetManager.prototype.getLoaderByType = function (type) {
327
- assert.isString(type, 'type');
328
-
329
- return this.loaders[type];
330
- };
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
- }
377
+ /**
378
+ * @template T
379
+ * @param {string} type
380
+ * @param {AssetTransformer<T>} transformer
381
+ */
382
+ unregisterTransformer(type, transformer) {
342
383
 
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];
384
+ const transformers = this.transformers[type];
350
385
 
351
- if (transformers === undefined) {
352
- transformers = [];
386
+ if (transformers === undefined) {
387
+ // not found
388
+ return false;
389
+ }
353
390
 
354
- this.transformers[type] = transformers;
355
- }
391
+ if (!array_remove_element(transformers, 0, transformers.length, transformer)) {
392
+ // not found
393
+ return false;
394
+ }
356
395
 
357
- transformers.push(transformer);
396
+ // check for loaded assets
397
+ const matching_assets = this.__getLoadedAssetDescriptorsByType(type);
358
398
 
359
- // check for loaded assets
360
- const matching_assets = this.__getLoadedAssetDescriptorsByType(type);
399
+ if (matching_assets.length > 0) {
400
+ 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')}`);
401
+ }
361
402
 
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')}`);
403
+ return true;
364
404
  }
365
405
 
366
- };
406
+ /**
407
+ * @template T
408
+ * @param {string} type
409
+ * @param {AssetLoader<T>} loader
410
+ * @throws if a loader is already registered for the given type
411
+ */
412
+ async registerLoader(type, loader) {
413
+ assert.isString(type, 'type');
414
+
415
+ const existing_loader = this.getLoaderByType(type);
416
+
417
+ if (existing_loader !== undefined) {
418
+ if (existing_loader === loader) {
419
+ // all is well, already registered
420
+ return existing_loader;
421
+ } else if (Object.getPrototypeOf(existing_loader) === Object.getPrototypeOf(loader)) {
422
+ console.warn(`Another instance of this loader is already registered for type '${type}'. Ignoring.`);
423
+ return existing_loader;
424
+ } else {
425
+ throw new Error(`Loader for type '${type}' is already registered`);
426
+ }
427
+ }
367
428
 
368
- /**
369
- * @template T
370
- * @param {string} type
371
- * @param {AssetTransformer<T>} transformer
372
- */
373
- AssetManager.prototype.unregisterTransformer = function (type, transformer) {
429
+ if (typeof loader === "function") {
374
430
 
375
- const transformers = this.transformers[type];
376
431
 
377
- if (transformers === undefined) {
378
- // not found
379
- return false;
380
- }
432
+ console.warn(`function-based loaders are deprecated (${type})`);
381
433
 
382
- if (!array_remove_element(transformers, 0, transformers.length, transformer)) {
383
- // not found
384
- return false;
385
- }
434
+ } else {
386
435
 
387
- // check for loaded assets
388
- const matching_assets = this.__getLoadedAssetDescriptorsByType(type);
436
+ await loader.link(this, this.__engine);
389
437
 
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
- }
438
+ }
393
439
 
394
- return true;
395
- }
440
+ this.loaders[type] = loader;
396
441
 
397
- /**
398
- * @template T
399
- * @param {string} type
400
- * @param {AssetLoader<T>} loader
401
- * @throws if a loader is already registered for the given type
402
- */
403
- AssetManager.prototype.registerLoader = async function (type, loader) {
404
- assert.isString(type, 'type');
405
-
406
- const existing_loader = this.getLoaderByType(type);
407
-
408
- if (existing_loader !== undefined) {
409
- if (existing_loader === loader) {
410
- // all is well, already registered
411
- return existing_loader;
412
- } else if (Object.getPrototypeOf(existing_loader) === Object.getPrototypeOf(loader)) {
413
- console.warn(`Another instance of this loader is already registered for type '${type}'. Ignoring.`);
414
- return existing_loader;
415
- } else {
416
- throw new Error(`Loader for type '${type}' is already registered`);
417
- }
442
+ return loader;
418
443
  }
419
444
 
420
- if (typeof loader === "function") {
445
+ /**
446
+ *
447
+ * @param {string} type
448
+ */
449
+ async unregisterLoader(type) {
450
+ const loader = this.getLoaderByType(type);
421
451
 
452
+ if (loader === undefined) {
453
+ // asset loader is not registered, nothing to do
454
+ return;
422
455
 
423
- console.warn(`function-based loaders are deprecated (${type})`);
456
+ }
424
457
 
425
- } else {
458
+ // first remove the loader from registry so no further asset requests can be made
459
+ delete this.loaders[type];
426
460
 
427
- await loader.link(this, this.__engine);
461
+ // TODO address all pending requests, possibly waiting for all of them to finalize
428
462
 
463
+ // finally unlink the loader
464
+ await loader.unlink();
429
465
  }
430
466
 
431
- this.loaders[type] = loader;
432
- };
433
-
434
- /**
435
- *
436
- * @param {string} type
437
- */
438
- AssetManager.prototype.unregisterLoader = async function (type) {
439
- const loader = this.getLoaderByType(type);
467
+ /**
468
+ * @template T
469
+ * Retrieve an asset if it is loaded, returns null if asset is not loaded.
470
+ * @param {String} path
471
+ * @param {String} type
472
+ * @returns {Asset<T>|null}
473
+ */
474
+ tryGet(path, type) {
475
+ const assetDescription = new AssetDescription(path, type);
440
476
 
441
- if (loader === undefined) {
442
- // asset loader is not registered, nothing to do
443
- return;
477
+ const asset = this.assets.get(assetDescription);
444
478
 
479
+ if (asset !== undefined) {
480
+ return asset;
481
+ } else {
482
+ return null;
483
+ }
445
484
  }
446
485
 
447
- // first remove the loader from registry so no further asset requests can be made
448
- delete this.loaders[type];
449
-
450
- // TODO address all pending requests, possibly waiting for all of them to finalize
451
-
452
- // finally unlink the loader
453
- await loader.unlink();
454
- };
455
-
456
- /**
457
- * @template T
458
- * Retrieve an asset if it is loaded, returns null if asset is not loaded.
459
- * @param {String} path
460
- * @param {String} type
461
- * @returns {Asset<T>|null}
462
- */
463
- AssetManager.prototype.tryGet = function (path, type) {
464
- const assetDescription = new AssetDescription(path, type);
465
-
466
- const asset = this.assets.get(assetDescription);
486
+ /**
487
+ *
488
+ * @param {string} path
489
+ * @param {string} type
490
+ * @returns {boolean}
491
+ */
492
+ isFailed(path, type) {
493
+ const ad = new AssetDescription(path, type);
467
494
 
468
- if (asset !== undefined) {
469
- return asset;
470
- } else {
471
- return null;
495
+ return this.failures.has(ad);
472
496
  }
473
- };
474
497
 
475
- /**
476
- *
477
- * @param {string} path
478
- * @param {string} type
479
- * @returns {boolean}
480
- */
481
- AssetManager.prototype.isFailed = function (path, type) {
482
- const ad = new AssetDescription(path, type);
498
+ /**
499
+ * @template T
500
+ * @param {string} alias
501
+ * @return {Promise<Asset<T>>}
502
+ */
503
+ promiseByAlias(alias) {
504
+ assert.typeOf(alias, 'string', 'alias');
483
505
 
484
- return this.failures.has(ad);
485
- };
506
+ // resolve alias
507
+ const assetDescription = this.aliases.get(alias);
486
508
 
487
- /**
488
- * @template T
489
- * @param {string} alias
490
- * @return {Promise<Asset<T>>}
491
- */
492
- AssetManager.prototype.promiseByAlias = function (alias) {
493
- assert.typeOf(alias, 'string', 'alias');
494
-
495
- // resolve alias
496
- const assetDescription = this.aliases.get(alias);
509
+ if (assetDescription === undefined) {
510
+ return new Promise.reject(`Alias '${alias}' not found`);
511
+ }
497
512
 
498
- if (assetDescription === undefined) {
499
- return new Promise.reject(`Alias '${alias}' not found`);
513
+ return this.promise(assetDescription.path, assetDescription.path);
500
514
  }
501
515
 
502
- return this.promise(assetDescription.path, assetDescription.path);
503
- };
504
-
505
- /**
506
- *
507
- * @param {string} alias
508
- * @return {AssetDescription}
509
- */
510
- AssetManager.prototype.resolveAlias = function (alias) {
511
-
512
- // todo consider cloning result to protect against mutation
513
-
514
- return this.aliases.get(alias);
516
+ /**
517
+ *
518
+ * @param {string} alias
519
+ * @return {AssetDescription}
520
+ */
521
+ resolveAlias(alias) {
515
522
 
516
- };
523
+ // todo consider cloning result to protect against mutation
517
524
 
518
- /**
519
- *
520
- * @param {string} alias
521
- * @param {string} path
522
- * @param {string} type
523
- */
524
- AssetManager.prototype.assignAlias = function (alias, path, type) {
525
- assert.isString(alias, 'alias');
526
- assert.isString(path, 'path');
527
- assert.isString(type, 'type');
525
+ return this.aliases.get(alias);
528
526
 
529
- const assetDescription = new AssetDescription(path, type);
527
+ }
530
528
 
531
- this.aliases.set(alias, assetDescription);
532
- };
529
+ /**
530
+ *
531
+ * @param {string} alias
532
+ * @param {string} path
533
+ * @param {string} type
534
+ */
535
+ assignAlias(alias, path, type) {
536
+ assert.isString(alias, 'alias');
537
+ assert.isString(path, 'path');
538
+ assert.isString(type, 'type');
533
539
 
534
- /**
535
- * @readonly
536
- * @type {boolean}
537
- */
538
- AssetManager.prototype.isAssetManager = true;
540
+ const assetDescription = new AssetDescription(path, type);
539
541
 
540
- export {
541
- AssetManager
542
- };
542
+ this.aliases.set(alias, assetDescription);
543
+ }
544
+ }