@zephyr3d/scene 0.9.4 → 0.9.5

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 (102) hide show
  1. package/dist/animation/animationmask.js +224 -0
  2. package/dist/animation/animationmask.js.map +1 -0
  3. package/dist/animation/animationset.js +268 -67
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js.map +1 -1
  6. package/dist/animation/eulerrotationtrack.js +3 -0
  7. package/dist/animation/eulerrotationtrack.js.map +1 -1
  8. package/dist/animation/fixed_geometry_cache_track.js +7 -0
  9. package/dist/animation/fixed_geometry_cache_track.js.map +1 -1
  10. package/dist/animation/ik_modifier.js.map +1 -1
  11. package/dist/animation/joint_dynamics/collision.js +6 -4
  12. package/dist/animation/joint_dynamics/collision.js.map +1 -1
  13. package/dist/animation/joint_dynamics/controller.js +390 -43
  14. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  15. package/dist/animation/joint_dynamics/joint_dynamics_system.js +62 -3
  16. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  17. package/dist/animation/joint_dynamics/solver.js +4 -3
  18. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  19. package/dist/animation/joint_dynamics/types.js.map +1 -1
  20. package/dist/animation/joint_dynamics_modifier.js +2 -0
  21. package/dist/animation/joint_dynamics_modifier.js.map +1 -1
  22. package/dist/animation/morphtarget.js +3 -72
  23. package/dist/animation/morphtarget.js.map +1 -1
  24. package/dist/animation/morphtrack.js +3 -0
  25. package/dist/animation/morphtrack.js.map +1 -1
  26. package/dist/animation/pca_geometry_cache_track.js +3 -0
  27. package/dist/animation/pca_geometry_cache_track.js.map +1 -1
  28. package/dist/animation/proptrack.js +3 -0
  29. package/dist/animation/proptrack.js.map +1 -1
  30. package/dist/animation/rotationtrack.js +3 -0
  31. package/dist/animation/rotationtrack.js.map +1 -1
  32. package/dist/animation/scaletrack.js +3 -0
  33. package/dist/animation/scaletrack.js.map +1 -1
  34. package/dist/animation/skeleton.js +254 -79
  35. package/dist/animation/skeleton.js.map +1 -1
  36. package/dist/animation/skeleton_modifier.js.map +1 -1
  37. package/dist/animation/spring_modifier.js.map +1 -1
  38. package/dist/animation/translationtrack.js +3 -0
  39. package/dist/animation/translationtrack.js.map +1 -1
  40. package/dist/app/engine.js +171 -107
  41. package/dist/app/engine.js.map +1 -1
  42. package/dist/app/scriptregistry.js +251 -80
  43. package/dist/app/scriptregistry.js.map +1 -1
  44. package/dist/asset/assetmanager.js +344 -365
  45. package/dist/asset/assetmanager.js.map +1 -1
  46. package/dist/asset/loaders/gltf/gltf_loader.js +17 -14
  47. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  48. package/dist/asset/loaders/loader.js +1 -6
  49. package/dist/asset/loaders/loader.js.map +1 -1
  50. package/dist/asset/loaders/zabc/zabc_loader.js.map +1 -1
  51. package/dist/asset/model.js +1000 -131
  52. package/dist/asset/model.js.map +1 -1
  53. package/dist/avatar/wardrobe.js +474 -0
  54. package/dist/avatar/wardrobe.js.map +1 -0
  55. package/dist/index.d.ts +1125 -199
  56. package/dist/index.js +3 -2
  57. package/dist/index.js.map +1 -1
  58. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +6 -3
  59. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  60. package/dist/material/mixins/pbr/common.js +72 -15
  61. package/dist/material/mixins/pbr/common.js.map +1 -1
  62. package/dist/material/msdf_text_sprite.js +4 -4
  63. package/dist/material/msdf_text_sprite.js.map +1 -1
  64. package/dist/material/pbrblueprint.js +102 -102
  65. package/dist/material/pbrblueprint.js.map +1 -1
  66. package/dist/render/envlight.js +54 -1
  67. package/dist/render/envlight.js.map +1 -1
  68. package/dist/render/sky.js +9 -0
  69. package/dist/render/sky.js.map +1 -1
  70. package/dist/scene/batchgroup.js +11 -13
  71. package/dist/scene/batchgroup.js.map +1 -1
  72. package/dist/scene/environment.js +15 -2
  73. package/dist/scene/environment.js.map +1 -1
  74. package/dist/scene/mesh.js +79 -16
  75. package/dist/scene/mesh.js.map +1 -1
  76. package/dist/scene/scene.js +1 -0
  77. package/dist/scene/scene.js.map +1 -1
  78. package/dist/scene/scene_node.js +203 -2
  79. package/dist/scene/scene_node.js.map +1 -1
  80. package/dist/text/font/font_asset.js.map +1 -1
  81. package/dist/text/msdf/generator.js.map +1 -1
  82. package/dist/text/msdf/shape.js +4 -1
  83. package/dist/text/msdf/shape.js.map +1 -1
  84. package/dist/text/runtime/msdf_text_atlas_manager.js +4 -1
  85. package/dist/text/runtime/msdf_text_atlas_manager.js.map +1 -1
  86. package/dist/utility/blueprint/material/inputs.js +1157 -1154
  87. package/dist/utility/blueprint/material/inputs.js.map +1 -1
  88. package/dist/utility/bounding_volume.js.map +1 -1
  89. package/dist/utility/pmrem.js +34 -8
  90. package/dist/utility/pmrem.js.map +1 -1
  91. package/dist/utility/serialization/manager.js +22 -9
  92. package/dist/utility/serialization/manager.js.map +1 -1
  93. package/dist/utility/serialization/scene/animation.js +700 -7
  94. package/dist/utility/serialization/scene/animation.js.map +1 -1
  95. package/dist/utility/serialization/scene/mesh.js +64 -4
  96. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  97. package/dist/utility/serialization/scene/node.js +187 -8
  98. package/dist/utility/serialization/scene/node.js.map +1 -1
  99. package/dist/utility/serialization/types.js.map +1 -1
  100. package/dist/utility/textures/sheenlut.js +138 -0
  101. package/dist/utility/textures/sheenlut.js.map +1 -0
  102. package/package.json +2 -2
@@ -1,5 +1,4 @@
1
- import { DWeakRef, ASSERT, base64ToUint8Array, Vector3, DRef, Vector4, VFSError, isPowerOf2, nextPowerOf2 } from '@zephyr3d/base';
2
- import { GLTFLoader } from './loaders/gltf/gltf_loader.js';
1
+ import { DWeakRef, DRef, ASSERT, base64ToUint8Array, Vector3, Vector4, guessMimeType, isPowerOf2, nextPowerOf2 } from '@zephyr3d/base';
3
2
  import { WebImageLoader } from './loaders/image/webimage_loader.js';
4
3
  import { DDSLoader } from './loaders/dds/dds_loader.js';
5
4
  import { HDRLoader } from './loaders/hdr/hdr.js';
@@ -35,20 +34,20 @@ import '../render/clipmap.js';
35
34
  import '../shaders/atmosphere.js';
36
35
  import { FontAsset } from '../text/font/font_asset.js';
37
36
 
38
- /**
39
- * Centralized asset manager for loading and caching resources.
40
- *
41
- * Responsibilities:
42
- * - Abstracts resource loading via VFS (text/json/binary).
43
- * - Dispatches texture/model loading to registered loaders by MIME type.
44
- * - Caches results and uses weak references to allow GPU resources to be GC'd when unused.
45
- * - Harmonizes cross-backend constraints (e.g., WebGL non-power-of-two rules and sRGB handling).
46
- * - Provides access to built-in textures with device-restore handlers.
47
- *
48
- * Threading/async model:
49
- * - All I/O is async; repeated calls are coalesced via internal promise caches keyed by URL or hash.
50
- *
51
- * @public
37
+ /**
38
+ * Centralized asset manager for loading and caching resources.
39
+ *
40
+ * Responsibilities:
41
+ * - Abstracts resource loading via VFS (text/json/binary).
42
+ * - Dispatches texture/model loading to registered loaders by MIME type.
43
+ * - Caches results and uses weak references to allow GPU resources to be GC'd when unused.
44
+ * - Harmonizes cross-backend constraints (e.g., WebGL non-power-of-two rules and sRGB handling).
45
+ * - Provides access to built-in textures with device-restore handlers.
46
+ *
47
+ * Threading/async model:
48
+ * - All I/O is async; repeated calls are coalesced via internal promise caches keyed by URL or hash.
49
+ *
50
+ * @public
52
51
  */ class AssetManager {
53
52
  /** @internal */ static _builtinTextures = {};
54
53
  /** @internal */ static _builtinTextureLoaders = {
@@ -60,9 +59,7 @@ import { FontAsset } from '../text/font/font_asset.js';
60
59
  new HDRLoader(),
61
60
  new TGALoader()
62
61
  ];
63
- /** @internal */ static _modelLoaders = [
64
- new GLTFLoader()
65
- ];
62
+ /** @internal */ _modelLoaders = {};
66
63
  /** @internal */ _textures;
67
64
  /** @internal */ _models;
68
65
  /** @internal */ _binaryDatas;
@@ -74,8 +71,8 @@ import { FontAsset } from '../text/font/font_asset.js';
74
71
  /** @internal */ _skeletons;
75
72
  /** @internal */ _jsonDatas;
76
73
  /** @internal */ _resourceManager;
77
- /**
78
- * Creates an instance of AssetManager
74
+ /**
75
+ * Creates an instance of AssetManager
79
76
  */ constructor(resourceManager){
80
77
  this._resourceManager = resourceManager ?? getEngine().resourceManager;
81
78
  this._textures = {};
@@ -89,18 +86,18 @@ import { FontAsset } from '../text/font/font_asset.js';
89
86
  this._textDatas = {};
90
87
  this._jsonDatas = {};
91
88
  }
92
- /**
93
- * VFS used to read resources (files, URLs, virtual mounts).
89
+ /**
90
+ * VFS used to read resources (files, URLs, virtual mounts).
94
91
  */ get vfs() {
95
92
  return this._resourceManager.VFS;
96
93
  }
97
- /**
98
- * Clear cached references and promises.
99
- *
100
- * - Disposes any DWeakRef holders maintained by this manager.
101
- * - Empties internal maps for textures, models, and raw data (text/json/binary).
102
- * - Does not forcibly dispose GPU resources; it only clears references so they can be GC'd
103
- * if no other owners are holding them.
94
+ /**
95
+ * Clear cached references and promises.
96
+ *
97
+ * - Disposes any DWeakRef holders maintained by this manager.
98
+ * - Empties internal maps for textures, models, and raw data (text/json/binary).
99
+ * - Does not forcibly dispose GPU resources; it only clears references so they can be GC'd
100
+ * if no other owners are holding them.
104
101
  */ clearCache() {
105
102
  for(const k in Object.keys(this._textures)){
106
103
  const v = this._textures[k];
@@ -142,13 +139,13 @@ import { FontAsset } from '../text/font/font_asset.js';
142
139
  this._textDatas = {};
143
140
  this._jsonDatas = {};
144
141
  }
145
- /**
146
- * Removes a cached font asset entry by URL.
147
- *
148
- * This only evicts the cache entry. It does not dispose any external references to the FontAsset.
149
- *
150
- * @param url - Resource URL or VFS path.
151
- * @returns `true` if a cache entry existed and was removed.
142
+ /**
143
+ * Removes a cached font asset entry by URL.
144
+ *
145
+ * This only evicts the cache entry. It does not dispose any external references to the FontAsset.
146
+ *
147
+ * @param url - Resource URL or VFS path.
148
+ * @returns `true` if a cache entry existed and was removed.
152
149
  */ releaseFontAsset(url) {
153
150
  if (url in this._fontAssets) {
154
151
  delete this._fontAssets[url];
@@ -156,101 +153,97 @@ import { FontAsset } from '../text/font/font_asset.js';
156
153
  }
157
154
  return false;
158
155
  }
159
- /**
160
- * Register a texture loader (highest priority first).
161
- *
162
- * Note: This is a static registry shared by all AssetManager instances.
163
- *
164
- * @param loader - A concrete texture loader implementation.
156
+ /**
157
+ * Register a texture loader (highest priority first).
158
+ *
159
+ * Note: This is a static registry shared by all AssetManager instances.
160
+ *
161
+ * @param loader - A concrete texture loader implementation.
165
162
  */ static addTextureLoader(loader) {
166
163
  if (loader) {
167
164
  this._textureLoaders.unshift(loader);
168
165
  }
169
166
  }
170
- /**
171
- * Register a model loader (highest priority first).
172
- *
173
- * Note: This is a static registry shared by all AssetManager instances.
174
- *
175
- * @param loader - A concrete model loader implementation.
176
- */ static addModelLoader(loader) {
167
+ /**
168
+ * Register a model loader (highest priority first).
169
+ */ setModelLoader(mimeType, loader) {
177
170
  if (loader) {
178
- this._modelLoaders.unshift(loader);
179
- }
180
- }
181
- /**
182
- * Fetch a UTF-8 text resource via VFS.
183
- *
184
- * - Results are cached per resolved URL (via HttpRequest.urlResolver if provided; otherwise the raw URL).
185
- * - If cached, any provided postProcess is ignored for subsequent calls; create a separate AssetManager
186
- * if you need different post-processing of the same URL.
187
- *
188
- * @param url - Resource URL or VFS path.
189
- * @param postProcess - Optional transformation applied to the loaded text.
190
- * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
191
- * @returns A promise that resolves to the loaded (and optionally processed) text.
192
- */ async fetchTextData(url, postProcess, httpRequest, VFSs) {
171
+ this._modelLoaders[mimeType] = loader;
172
+ }
173
+ }
174
+ /**
175
+ * Fetch a UTF-8 text resource via VFS.
176
+ *
177
+ * - Results are cached per resolved URL (via HttpRequest.urlResolver if provided; otherwise the raw URL).
178
+ * - If cached, any provided postProcess is ignored for subsequent calls; create a separate AssetManager
179
+ * if you need different post-processing of the same URL.
180
+ *
181
+ * @param url - Resource URL or VFS path.
182
+ * @param postProcess - Optional transformation applied to the loaded text.
183
+ * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
184
+ * @returns A promise that resolves to the loaded (and optionally processed) text.
185
+ */ async fetchTextData(url, postProcess, httpRequest, options) {
193
186
  const hash = httpRequest?.urlResolver?.(url) ?? url;
194
187
  let P = this._textDatas[hash];
195
188
  if (!P) {
196
- P = this.loadTextData(url, postProcess, VFSs);
189
+ P = this.loadTextData(url, postProcess, options?.overrideVFS);
197
190
  this._textDatas[hash] = P;
198
191
  }
199
192
  return P;
200
193
  }
201
- /**
202
- * Fetch a JSON resource via VFS.
203
- *
204
- * - Parses as JSON after text load.
205
- * - Cached per resolved URL. Post-process is applied only on the first load for a given cache key.
206
- *
207
- * @param url - Resource URL or VFS path.
208
- * @param postProcess - Optional transformation applied to the parsed JSON object.
209
- * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
210
- * @returns A promise that resolves to the loaded (and optionally processed) JSON value.
211
- */ async fetchJsonData(url, postProcess, httpRequest, VFSs) {
194
+ /**
195
+ * Fetch a JSON resource via VFS.
196
+ *
197
+ * - Parses as JSON after text load.
198
+ * - Cached per resolved URL. Post-process is applied only on the first load for a given cache key.
199
+ *
200
+ * @param url - Resource URL or VFS path.
201
+ * @param postProcess - Optional transformation applied to the parsed JSON object.
202
+ * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
203
+ * @returns A promise that resolves to the loaded (and optionally processed) JSON value.
204
+ */ async fetchJsonData(url, postProcess, httpRequest, options) {
212
205
  const hash = httpRequest?.urlResolver?.(url) ?? url;
213
206
  let P = this._jsonDatas[hash];
214
207
  if (!P) {
215
- P = this.loadJsonData(url, postProcess, VFSs);
208
+ P = this.loadJsonData(url, postProcess, options?.overrideVFS);
216
209
  this._jsonDatas[hash] = P;
217
210
  }
218
211
  return P;
219
212
  }
220
- /**
221
- * Fetch a binary resource via VFS.
222
- *
223
- * - Cached per resolved URL. Post-process is applied only on first load for a given key.
224
- *
225
- * @param url - Resource URL or VFS path.
226
- * @param postProcess - Optional transformation applied to the loaded ArrayBuffer.
227
- * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
228
- * @returns A promise that resolves to the loaded (and optionally processed) ArrayBuffer.
229
- */ async fetchBinaryData(url, postProcess, httpRequest, VFSs) {
213
+ /**
214
+ * Fetch a binary resource via VFS.
215
+ *
216
+ * - Cached per resolved URL. Post-process is applied only on first load for a given key.
217
+ *
218
+ * @param url - Resource URL or VFS path.
219
+ * @param postProcess - Optional transformation applied to the loaded ArrayBuffer.
220
+ * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
221
+ * @returns A promise that resolves to the loaded (and optionally processed) ArrayBuffer.
222
+ */ async fetchBinaryData(url, postProcess, httpRequest, options) {
230
223
  const hash = httpRequest?.urlResolver?.(url) ?? url;
231
224
  let P = this._binaryDatas[hash];
232
225
  if (!P) {
233
- P = this.loadBinaryData(url, postProcess, VFSs);
226
+ P = this.loadBinaryData(url, postProcess, options?.overrideVFS);
234
227
  this._binaryDatas[hash] = P;
235
228
  }
236
229
  return P;
237
230
  }
238
- /**
239
- * Fetch a font asset via VFS.
240
- *
241
- * - Cached per URL only.
242
- * - `options` are applied only when the font is first loaded for that URL.
243
- * - If the URL is already cached, later calls ignore `options` and reuse the cached FontAsset.
244
- *
245
- * @param url - Resource URL or VFS path.
246
- * @param options - Optional MSDF atlas settings bound to the loaded FontAsset.
247
- * @returns A promise that resolves to the loaded (and optionally processed) font asset.
248
- */ async fetchFontAsset(url, options, VFSs) {
231
+ /**
232
+ * Fetch a font asset via VFS.
233
+ *
234
+ * - Cached per URL only.
235
+ * - `options` are applied only when the font is first loaded for that URL.
236
+ * - If the URL is already cached, later calls ignore `options` and reuse the cached FontAsset.
237
+ *
238
+ * @param url - Resource URL or VFS path.
239
+ * @param options - Optional MSDF atlas settings bound to the loaded FontAsset.
240
+ * @returns A promise that resolves to the loaded (and optionally processed) font asset.
241
+ */ async fetchFontAsset(url, options) {
249
242
  const hash = url;
250
243
  let P = this._fontAssets[hash];
251
244
  if (!P) {
252
245
  P = new Promise((resolve, reject)=>{
253
- this.loadBinaryData(url, null, VFSs).then((data)=>{
246
+ this.loadBinaryData(url, null, options?.overrideVFS).then((data)=>{
254
247
  resolve(data ? FontAsset.fromBuffer(data, options) : null);
255
248
  }).catch((err)=>{
256
249
  reject(new Error(`Failed to load font asset from ${url}: ${err instanceof Error ? err.message : err}`));
@@ -260,36 +253,36 @@ import { FontAsset } from '../text/font/font_asset.js';
260
253
  }
261
254
  return P;
262
255
  }
263
- /**
264
- * Fetch a font asset via VFS if already cached.
265
- * @param url - Resource URL or VFS path.
266
- * @returns The cached FontAsset if it exists and is loaded, or null if not cached or still loading.
256
+ /**
257
+ * Fetch a font asset via VFS if already cached.
258
+ * @param url - Resource URL or VFS path.
259
+ * @returns The cached FontAsset if it exists and is loaded, or null if not cached or still loading.
267
260
  */ getFontAsset(url) {
268
261
  const hash = url;
269
262
  return this._fontAssets[hash] instanceof Promise ? null : this._fontAssets[hash] ?? null;
270
263
  }
271
- async fetchBluePrint(url, VFSs) {
264
+ async fetchBluePrint(url, options) {
272
265
  const hash = url;
273
266
  let P = this._bluePrints[hash];
274
267
  if (!P) {
275
- P = this.loadBluePrint(url, VFSs);
268
+ P = this.loadBluePrint(url, options?.overrideVFS);
276
269
  this._bluePrints[hash] = P;
277
270
  }
278
271
  return P;
279
272
  }
280
- /**
281
- * Fetch a material resource.
282
- *
283
- * @typeParam T - Expected concrete material type.
284
- * @param url - Resource URL or VFS path.
285
- * @returns A promise that resolves to the loaded material.
286
- */ async fetchMaterial(url, VFSs) {
273
+ /**
274
+ * Fetch a material resource.
275
+ *
276
+ * @typeParam T - Expected concrete material type.
277
+ * @param url - Resource URL or VFS path.
278
+ * @returns A promise that resolves to the loaded material.
279
+ */ async fetchMaterial(url, options) {
287
280
  const hash = url;
288
281
  let P = this._materials[hash];
289
282
  if (P instanceof DWeakRef && P.get() && !P.get().disposed) {
290
283
  return P.get();
291
284
  } else if (!P || P instanceof DWeakRef) {
292
- P = this.loadMaterial(url, false, VFSs);
285
+ P = this.loadMaterial(url, false, options?.overrideVFS);
293
286
  this._materials[hash] = P;
294
287
  }
295
288
  const material = await P;
@@ -298,19 +291,19 @@ import { FontAsset } from '../text/font/font_asset.js';
298
291
  }
299
292
  return material;
300
293
  }
301
- /**
302
- * Fetch a primitive resource.
303
- *
304
- * @typeParam T - Expected concrete primitive type.
305
- * @param url - Resource URL or VFS path.
306
- * @returns A promise that resolves to the loaded primitive.
307
- */ async fetchPrimitive(url, VFSs) {
294
+ /**
295
+ * Fetch a primitive resource.
296
+ *
297
+ * @typeParam T - Expected concrete primitive type.
298
+ * @param url - Resource URL or VFS path.
299
+ * @returns A promise that resolves to the loaded primitive.
300
+ */ async fetchPrimitive(url, options) {
308
301
  const hash = url;
309
302
  let P = this._primitives[hash];
310
303
  if (P instanceof DWeakRef && P.get() && !P.get().disposed) {
311
304
  return P.get();
312
305
  } else if (!P || P instanceof DWeakRef) {
313
- P = this.loadPrimitive(url, VFSs);
306
+ P = this.loadPrimitive(url, options?.overrideVFS);
314
307
  this._primitives[hash] = P;
315
308
  }
316
309
  const primitive = await P;
@@ -319,29 +312,29 @@ import { FontAsset } from '../text/font/font_asset.js';
319
312
  }
320
313
  return primitive;
321
314
  }
322
- /**
323
- * Fetch a texture resource via registered loaders.
324
- *
325
- * - Chooses loader by explicit MIME type or by VFS file extension inference.
326
- * - Deduplicates in-flight requests and caches ready textures.
327
- * - If `options.texture` is provided, the asset will be uploaded/blitted into that texture.
328
- * - On WebGL backends, enforces constraints by repacking non-power-of-two or sRGB textures.
329
- *
330
- * @typeParam T - Expected concrete texture type.
331
- * @param url - Resource URL or VFS path.
332
- * @param options - Texture fetching options (color space, sampler, target texture).
333
- * @param httpRequest - Optional HttpRequest (not used for binary read but may supply URL resolver for hashing).
334
- * @returns A promise that resolves to the loaded texture.
335
- */ async fetchTexture(url, options, VFSs) {
315
+ /**
316
+ * Fetch a texture resource via registered loaders.
317
+ *
318
+ * - Chooses loader by explicit MIME type or by VFS file extension inference.
319
+ * - Deduplicates in-flight requests and caches ready textures.
320
+ * - If `options.texture` is provided, the asset will be uploaded/blitted into that texture.
321
+ * - On WebGL backends, enforces constraints by repacking non-power-of-two or sRGB textures.
322
+ *
323
+ * @typeParam T - Expected concrete texture type.
324
+ * @param url - Resource URL or VFS path.
325
+ * @param options - Texture fetching options (color space, sampler, target texture).
326
+ * @param httpRequest - Optional HttpRequest (not used for binary read but may supply URL resolver for hashing).
327
+ * @returns A promise that resolves to the loaded texture.
328
+ */ async fetchTexture(url, options) {
336
329
  if (options?.texture) {
337
- return this.loadTexture(url, options.mimeType ?? null, !options.linearColorSpace, options.samplerOptions, options.texture, VFSs);
330
+ return this.loadTexture(url, options.mimeType ?? null, !options.linearColorSpace, options.samplerOptions, options.texture, options.overrideVFS);
338
331
  } else {
339
332
  const hash = this.getHash('2d', url, options);
340
333
  let P = this._textures[hash];
341
334
  if (P instanceof DWeakRef && P.get() && !P.get().disposed) {
342
335
  return P.get();
343
336
  } else if (!P || P instanceof DWeakRef) {
344
- P = this.loadTexture(url, options?.mimeType ?? null, !options?.linearColorSpace, options?.samplerOptions, null, VFSs);
337
+ P = this.loadTexture(url, options?.mimeType ?? null, !options?.linearColorSpace, options?.samplerOptions, null, options?.overrideVFS);
345
338
  this._textures[hash] = P;
346
339
  }
347
340
  const tex = await P;
@@ -351,23 +344,23 @@ import { FontAsset } from '../text/font/font_asset.js';
351
344
  return tex;
352
345
  }
353
346
  }
354
- /**
355
- * Fetch a model resource via registered model loaders (data only).
356
- *
357
- * - Returns a SharedModel which can create scene nodes in any Scene.
358
- * - Uses DWeakRef to cache and allow model data to be reclaimed if unused.
359
- *
360
- * @param url - Model URL or VFS path.
361
- * @param options - Model loader options (MIME override, Draco, instancing hint, post-process).
362
- * @returns A promise that resolves to the SharedModel.
363
- * @internal
364
- */ async fetchModelData(url, options, VFSs) {
347
+ /**
348
+ * Fetch a model resource via registered model loaders (data only).
349
+ *
350
+ * - Returns a SharedModel which can create scene nodes in any Scene.
351
+ * - Uses DWeakRef to cache and allow model data to be reclaimed if unused.
352
+ *
353
+ * @param url - Model URL or VFS path.
354
+ * @param options - Model loader options (MIME override, Draco, instancing hint, post-process).
355
+ * @returns A promise that resolves to the SharedModel.
356
+ * @internal
357
+ */ async fetchModelData(url, options) {
365
358
  const hash = url;
366
359
  let P = this._models[hash];
367
360
  if (P instanceof DWeakRef && P.get() && !P.get().disposed) {
368
361
  return P.get();
369
362
  } else if (!P || P instanceof DWeakRef) {
370
- P = this.loadModel(url, options, VFSs);
363
+ P = this.loadModel(url, options, options?.overrideVFS);
371
364
  this._models[hash] = P;
372
365
  }
373
366
  const sharedModel = await P;
@@ -376,38 +369,46 @@ import { FontAsset } from '../text/font/font_asset.js';
376
369
  }
377
370
  return sharedModel;
378
371
  }
379
- /**
380
- * Fetch a model resource and instantiate it under a scene.
381
- *
382
- * - Loads or retrieves a cached SharedModel, then creates a SceneNode hierarchy.
383
- * - Returns both the created group node and any associated AnimationSet.
384
- *
385
- * @param scene - Scene into which the model node will be created.
386
- * @param url - Model URL or VFS path.
387
- * @param options - Model loader options and instancing hint.
388
- * @param httpRequest - Optional HttpRequest (unused for binary read; present for API symmetry).
389
- * @returns A promise with the created node group and animation set info.
390
- */ async fetchModel(scene, url, options, VFSs) {
391
- const sharedModel = await this.fetchModelData(url, options, VFSs);
392
- const node = sharedModel.createSceneNode(scene, !!options?.enableInstancing);
393
- return {
394
- group: node,
395
- animationSet: node.animationSet
396
- };
397
- }
398
- /**
399
- * Load a text resource via VFS and optionally post-process it.
400
- *
401
- * - Does not use or modify the internal cache; use fetchTextData for cached loads.
402
- *
403
- * @param url - Resource URL or VFS path.
404
- * @param postProcess - Optional transformation applied to the text.
405
- * @returns A promise that resolves to the loaded (and optionally processed) text.
406
- * @internal
407
- */ async loadTextData(url, postProcess, VFSs) {
408
- let text = await this.readFileFromVFSs(url, {
372
+ /**
373
+ * Fetch a model resource and instantiate it under a scene.
374
+ *
375
+ * - Loads or retrieves a cached SharedModel, then creates a SceneNode hierarchy.
376
+ * - Returns both the created group node and any associated AnimationSet.
377
+ *
378
+ * @param scene - Scene into which the model node will be created.
379
+ * @param url - Model URL or VFS path.
380
+ * @param options - Model loader options and instancing hint.
381
+ * @param httpRequest - Optional HttpRequest (unused for binary read; present for API symmetry).
382
+ * @returns A promise with the created node group and animation set info.
383
+ *
384
+ * @internal
385
+ */ async fetchModel(scene, url, options) {
386
+ const sharedModel = new DRef();
387
+ try {
388
+ sharedModel.set(await this.fetchModelData(url, options));
389
+ const node = await sharedModel.get().createSceneNode(getEngine().resourceManager, scene, options?.enableInstancing ?? false, options?.loadMeshes ?? true, options?.loadSkeletons ?? true, options?.loadAnimations ?? true, options?.loadJointDynamics ?? true, options?.overrideVFS ?? getEngine().resourceManager.VFS);
390
+ node.sharedModel = sharedModel.get();
391
+ node.animationSet.resetSkeletonModifiers();
392
+ return node;
393
+ } catch (err) {
394
+ console.error(`Load model failed: ${url}: ${err}`);
395
+ } finally{
396
+ sharedModel.dispose();
397
+ }
398
+ }
399
+ /**
400
+ * Load a text resource via VFS and optionally post-process it.
401
+ *
402
+ * - Does not use or modify the internal cache; use fetchTextData for cached loads.
403
+ *
404
+ * @param url - Resource URL or VFS path.
405
+ * @param postProcess - Optional transformation applied to the text.
406
+ * @returns A promise that resolves to the loaded (and optionally processed) text.
407
+ * @internal
408
+ */ async loadTextData(url, postProcess, vfs) {
409
+ let text = await this.readFileFromVFS(url, {
409
410
  encoding: 'utf8'
410
- }, VFSs);
411
+ }, vfs);
411
412
  if (postProcess) {
412
413
  try {
413
414
  text = postProcess(text);
@@ -417,19 +418,19 @@ import { FontAsset } from '../text/font/font_asset.js';
417
418
  }
418
419
  return text;
419
420
  }
420
- /**
421
- * Load a JSON resource via VFS and optionally post-process it.
422
- *
423
- * - Does not use or modify the internal cache; use fetchJsonData for cached loads.
424
- *
425
- * @param url - Resource URL or VFS path.
426
- * @param postProcess - Optional transformation applied to the parsed JSON.
427
- * @returns A promise that resolves to the loaded (and optionally processed) JSON.
428
- * @internal
429
- */ async loadJsonData(url, postProcess, VFSs) {
430
- let json = JSON.parse(await this.readFileFromVFSs(url, {
421
+ /**
422
+ * Load a JSON resource via VFS and optionally post-process it.
423
+ *
424
+ * - Does not use or modify the internal cache; use fetchJsonData for cached loads.
425
+ *
426
+ * @param url - Resource URL or VFS path.
427
+ * @param postProcess - Optional transformation applied to the parsed JSON.
428
+ * @returns A promise that resolves to the loaded (and optionally processed) JSON.
429
+ * @internal
430
+ */ async loadJsonData(url, postProcess, vfs) {
431
+ let json = JSON.parse(await this.readFileFromVFS(url, {
431
432
  encoding: 'utf8'
432
- }, VFSs));
433
+ }, vfs));
433
434
  if (postProcess) {
434
435
  try {
435
436
  json = postProcess(json);
@@ -439,20 +440,20 @@ import { FontAsset } from '../text/font/font_asset.js';
439
440
  }
440
441
  return json;
441
442
  }
442
- /**
443
- * Load a binary resource via VFS and optionally post-process it.
444
- *
445
- * - Does not use or modify the internal cache; use fetchBinaryData for cached loads.
446
- *
447
- * @param url - Resource URL or VFS path.
448
- * @param postProcess - Optional transformation applied to the ArrayBuffer.
449
- * @returns A promise that resolves to the loaded (and optionally processed) ArrayBuffer.
450
- * @internal
451
- */ async loadBinaryData(url, postProcess, VFSs) {
443
+ /**
444
+ * Load a binary resource via VFS and optionally post-process it.
445
+ *
446
+ * - Does not use or modify the internal cache; use fetchBinaryData for cached loads.
447
+ *
448
+ * @param url - Resource URL or VFS path.
449
+ * @param postProcess - Optional transformation applied to the ArrayBuffer.
450
+ * @returns A promise that resolves to the loaded (and optionally processed) ArrayBuffer.
451
+ * @internal
452
+ */ async loadBinaryData(url, postProcess, vfs) {
452
453
  try {
453
- let data = await this.readFileFromVFSs(url, {
454
+ let data = await this.readFileFromVFS(url, {
454
455
  encoding: 'binary'
455
- }, VFSs);
456
+ }, vfs);
456
457
  if (postProcess) {
457
458
  data = postProcess(data);
458
459
  }
@@ -462,11 +463,11 @@ import { FontAsset } from '../text/font/font_asset.js';
462
463
  return null;
463
464
  }
464
465
  }
465
- async loadPrimitive(url, VFSs) {
466
+ async loadPrimitive(url, vfs) {
466
467
  try {
467
- const data = await this.readFileFromVFSs(url, {
468
+ const data = await this.readFileFromVFS(url, {
468
469
  encoding: 'utf8'
469
- }, VFSs);
470
+ }, vfs);
470
471
  const content = JSON.parse(data);
471
472
  ASSERT(content.type === 'Primitive' || content.type === 'Default', `Unsupported primitive type: ${content.type}`);
472
473
  if (content.type === 'Primitive') {
@@ -532,20 +533,22 @@ import { FontAsset } from '../text/font/font_asset.js';
532
533
  }
533
534
  }
534
535
  }
535
- async loadBluePrintMaterialData(url, reload, VFSs) {
536
+ async loadBluePrintMaterialData(url, reload, vfs) {
536
537
  try {
537
538
  let irData;
538
539
  if (typeof url === 'string') {
539
- const data = await this.readFileFromVFSs(url, {
540
+ const data = await this.readFileFromVFS(url, {
540
541
  encoding: 'utf8'
541
- }, VFSs);
542
+ }, vfs);
542
543
  const content = JSON.parse(data);
543
544
  ASSERT(content.type === 'PBRBluePrintMaterial' || content.type === 'SpriteBluePrintMaterial', `Unsupported material type: ${content.type}`);
544
545
  irData = content.data;
545
546
  } else {
546
547
  irData = url;
547
548
  }
548
- const ir = reload ? await this.loadBluePrint(irData.IR, VFSs) : await this.fetchBluePrint(irData.IR, VFSs);
549
+ const ir = reload ? await this.loadBluePrint(irData.IR, vfs) : await this.fetchBluePrint(irData.IR, vfs ? {
550
+ overrideVFS: vfs
551
+ } : undefined);
549
552
  const uniformValues = irData.uniformValues.map((v)=>({
550
553
  ...v,
551
554
  finalValue: v.value.length === 1 ? v.value[0] : new Float32Array(v.value)
@@ -554,8 +557,9 @@ import { FontAsset } from '../text/font/font_asset.js';
554
557
  const textures = irData.uniformTextures;
555
558
  for (const v of textures){
556
559
  const tex = await this.fetchTexture(v.texture, {
557
- linearColorSpace: !v.sRGB
558
- }, VFSs);
560
+ linearColorSpace: !v.sRGB,
561
+ overrideVFS: vfs
562
+ });
559
563
  uniformTextures.push({
560
564
  ...v,
561
565
  finalTexture: new DRef(tex),
@@ -580,27 +584,27 @@ import { FontAsset } from '../text/font/font_asset.js';
580
584
  return null;
581
585
  }
582
586
  }
583
- /**
584
- * Load a material.
585
- *
586
- * - Does not use or modify the internal cache; use fetchMaterial for cached loads.
587
- *
588
- * @param url - Resource URL or VFS path.
589
- * @returns A promise that resolves to the loaded material.
590
- * @internal
591
- */ async loadMaterial(url, reload, VFSs) {
587
+ /**
588
+ * Load a material.
589
+ *
590
+ * - Does not use or modify the internal cache; use fetchMaterial for cached loads.
591
+ *
592
+ * @param url - Resource URL or VFS path.
593
+ * @returns A promise that resolves to the loaded material.
594
+ * @internal
595
+ */ async loadMaterial(url, reload, vfs) {
592
596
  try {
593
- const data = await this.readFileFromVFSs(url, {
597
+ const data = await this.readFileFromVFS(url, {
594
598
  encoding: 'utf8'
595
- }, VFSs);
599
+ }, vfs);
596
600
  const content = JSON.parse(data);
597
601
  ASSERT(content.type === 'PBRBluePrintMaterial' || content.type === 'SpriteBluePrintMaterial' || content.type === 'Default', `Unsupported material type: ${content.type}`);
598
602
  let mat;
599
603
  if (content.type === 'PBRBluePrintMaterial') {
600
- const data = await this.loadBluePrintMaterialData(content.data, reload, VFSs);
604
+ const data = await this.loadBluePrintMaterialData(content.data, reload, vfs);
601
605
  mat = new PBRBluePrintMaterial(data.irFragment, data.irVertex, data.uniformValues, data.uniformTextures);
602
606
  } else if (content.type === 'SpriteBluePrintMaterial') {
603
- const data = await this.loadBluePrintMaterialData(content.data, reload, VFSs);
607
+ const data = await this.loadBluePrintMaterialData(content.data, reload, vfs);
604
608
  mat = new SpriteBlueprintMaterial(data.irFragment, data.uniformValues, data.uniformTextures);
605
609
  } else {
606
610
  const obj = await this._resourceManager.deserializeObject(null, content.data);
@@ -743,11 +747,11 @@ import { FontAsset } from '../text/font/font_asset.js';
743
747
  invalidateBluePrint(path) {
744
748
  delete this._bluePrints[path];
745
749
  }
746
- async loadBluePrint(path, VFSs) {
750
+ async loadBluePrint(path, vfs) {
747
751
  try {
748
- const content = await this.readFileFromVFSs(path, {
752
+ const content = await this.readFileFromVFS(path, {
749
753
  encoding: 'utf8'
750
- }, VFSs);
754
+ }, vfs);
751
755
  const bp = JSON.parse(content);
752
756
  ASSERT(bp.type === 'PBRMaterial' || bp.type === 'SpriteMaterial' || bp.type === 'MaterialFunction', `Unsupported blueprint type: ${bp.type}`);
753
757
  const states = bp.state;
@@ -773,19 +777,19 @@ import { FontAsset } from '../text/font/font_asset.js';
773
777
  return null;
774
778
  }
775
779
  }
776
- /**
777
- * Load a texture directly from an ArrayBuffer or typed array.
778
- *
779
- * - Chooses an appropriate loader based on the provided MIME type.
780
- * - Can upload into an existing texture if `texture` is specified.
781
- *
782
- * @typeParam T - Expected concrete texture type.
783
- * @param arrayBuffer - Raw texture data buffer.
784
- * @param mimeType - MIME type of the texture (must be supported by a registered loader).
785
- * @param srgb - If true, treat image as sRGB; otherwise linear.
786
- * @param samplerOptions - Optional sampler options passed to the loader path.
787
- * @param texture - Optional destination texture to populate.
788
- * @returns A promise that resolves to the created or populated texture.
780
+ /**
781
+ * Load a texture directly from an ArrayBuffer or typed array.
782
+ *
783
+ * - Chooses an appropriate loader based on the provided MIME type.
784
+ * - Can upload into an existing texture if `texture` is specified.
785
+ *
786
+ * @typeParam T - Expected concrete texture type.
787
+ * @param arrayBuffer - Raw texture data buffer.
788
+ * @param mimeType - MIME type of the texture (must be supported by a registered loader).
789
+ * @param srgb - If true, treat image as sRGB; otherwise linear.
790
+ * @param samplerOptions - Optional sampler options passed to the loader path.
791
+ * @param texture - Optional destination texture to populate.
792
+ * @returns A promise that resolves to the created or populated texture.
789
793
  */ async loadTextureFromBuffer(arrayBuffer, mimeType, srgb, samplerOptions, texture) {
790
794
  for (const loader of AssetManager._textureLoaders){
791
795
  if (!loader.supportMIMEType(mimeType)) {
@@ -796,24 +800,24 @@ import { FontAsset } from '../text/font/font_asset.js';
796
800
  }
797
801
  throw new Error(`Can not find loader for MIME type '${mimeType}'`);
798
802
  }
799
- /**
800
- * Load a texture via VFS by URL and MIME type.
801
- *
802
- * - Uses the first loader that supports the inferred or provided MIME type.
803
- * - On WebGL, may repack textures (resample to power-of-two, convert formats) to meet backend constraints.
804
- * - If `texture` is provided, the source is blitted into it, possibly resizing or changing sampling accordingly.
805
- *
806
- * @param url - Texture URL or VFS path.
807
- * @param mimeType - Optional explicit MIME type; otherwise inferred by VFS.
808
- * @param srgb - If true, treat image as sRGB; otherwise linear.
809
- * @param samplerOptions - Optional sampler options for loader or blit path.
810
- * @param texture - Optional destination texture to populate.
811
- * @returns A promise that resolves to the created or populated texture.
812
- * @internal
813
- */ async loadTexture(url, mimeType, srgb, samplerOptions, texture, VFSs) {
814
- const data = await this.readFileFromVFSs(url, {
803
+ /**
804
+ * Load a texture via VFS by URL and MIME type.
805
+ *
806
+ * - Uses the first loader that supports the inferred or provided MIME type.
807
+ * - On WebGL, may repack textures (resample to power-of-two, convert formats) to meet backend constraints.
808
+ * - If `texture` is provided, the source is blitted into it, possibly resizing or changing sampling accordingly.
809
+ *
810
+ * @param url - Texture URL or VFS path.
811
+ * @param mimeType - Optional explicit MIME type; otherwise inferred by VFS.
812
+ * @param srgb - If true, treat image as sRGB; otherwise linear.
813
+ * @param samplerOptions - Optional sampler options for loader or blit path.
814
+ * @param texture - Optional destination texture to populate.
815
+ * @returns A promise that resolves to the created or populated texture.
816
+ * @internal
817
+ */ async loadTexture(url, mimeType, srgb, samplerOptions, texture, vfs) {
818
+ const data = await this.readFileFromVFS(url, {
815
819
  encoding: 'binary'
816
- }, VFSs);
820
+ }, vfs);
817
821
  mimeType = mimeType ?? this.vfs.guessMIMEType(url);
818
822
  for (const loader of AssetManager._textureLoaders){
819
823
  if (!loader.supportMIMEType(mimeType)) {
@@ -827,18 +831,18 @@ import { FontAsset } from '../text/font/font_asset.js';
827
831
  }
828
832
  throw new Error(`Can not find loader for asset ${url}`);
829
833
  }
830
- /**
831
- * Internal routine that executes the texture load using a specific loader and applies
832
- * backend-specific compatibility steps (e.g., WebGL NPOT/sRGB rules).
833
- *
834
- * @param loader - Concrete loader to use for decoding/creation.
835
- * @param mimeType - Texture MIME type.
836
- * @param data - Raw binary data.
837
- * @param srgb - If true, treat image as sRGB; otherwise linear.
838
- * @param samplerOptions - Optional sampler options.
839
- * @param texture - Optional destination texture to populate.
840
- * @returns A promise that resolves to the created or populated texture.
841
- * @internal
834
+ /**
835
+ * Internal routine that executes the texture load using a specific loader and applies
836
+ * backend-specific compatibility steps (e.g., WebGL NPOT/sRGB rules).
837
+ *
838
+ * @param loader - Concrete loader to use for decoding/creation.
839
+ * @param mimeType - Texture MIME type.
840
+ * @param data - Raw binary data.
841
+ * @param srgb - If true, treat image as sRGB; otherwise linear.
842
+ * @param samplerOptions - Optional sampler options.
843
+ * @param texture - Optional destination texture to populate.
844
+ * @returns A promise that resolves to the created or populated texture.
845
+ * @internal
842
846
  */ async doLoadTexture(loader, mimeType, data, srgb, samplerOptions, texture) {
843
847
  const device = getDevice();
844
848
  if (device.type !== 'webgl') {
@@ -889,33 +893,22 @@ import { FontAsset } from '../text/font/font_asset.js';
889
893
  return tex;
890
894
  }
891
895
  }
892
- /**
893
- * Load a model via registered model loaders.
894
- *
895
- * - Selects loader by MIME type (explicit or inferred).
896
- * - Optionally applies a post-process transform to the SharedModel.
897
- * - Sets the model's name from the source filename for convenience.
898
- *
899
- * @param url - Model URL or VFS path.
900
- * @param options - Model load options (MIME override, Draco module, post-process hook).
901
- * @returns A promise that resolves to the loaded SharedModel.
902
- * @internal
903
- */ async loadModel(url, options, VFSs) {
904
- const arrayBuffer = await this.readFileFromVFSs(url, {
905
- encoding: 'binary'
906
- }, VFSs);
907
- const mimeType = options?.mimeType || this.vfs.guessMIMEType(url);
908
- const data = new Blob([
909
- arrayBuffer
910
- ], {
911
- type: mimeType
912
- });
913
- const filename = this.vfs.basename(url);
914
- for (const loader of AssetManager._modelLoaders){
915
- if (!loader.supportMIMEType(mimeType)) {
916
- continue;
917
- }
918
- let model = await loader.load(this, url, options?.mimeType || data.type, data, options?.dracoDecoderModule, VFSs);
896
+ /**
897
+ * Load a model via registered model loaders.
898
+ *
899
+ * - Selects loader by MIME type (explicit or inferred).
900
+ * - Optionally applies a post-process transform to the SharedModel.
901
+ * - Sets the model's name from the source filename for convenience.
902
+ *
903
+ * @param url - Model URL or VFS path.
904
+ * @param options - Model load options (MIME override, Draco module, post-process hook).
905
+ * @returns A promise that resolves to the loaded SharedModel.
906
+ * @internal
907
+ */ async loadModel(url, options, vfs) {
908
+ const mimeType = options?.mimeType || guessMimeType(url);
909
+ const importer = this._modelLoaders[mimeType];
910
+ if (importer) {
911
+ let model = await importer.loadModel(url, vfs);
919
912
  if (!model) {
920
913
  throw new Error(`Load asset failed: ${url}`);
921
914
  }
@@ -926,22 +919,21 @@ import { FontAsset } from '../text/font/font_asset.js';
926
919
  throw new Error(`Model loader post process failed: ${err}`);
927
920
  }
928
921
  }
929
- model.name = filename;
930
922
  return model;
931
923
  }
932
924
  throw new Error(`Can not find loader for asset ${url}`);
933
925
  }
934
- /**
935
- * Fetch a built-in texture synchronously by name.
936
- *
937
- * - If this built-in was not created yet, the registered loader is invoked.
938
- * - Registers a device restore handler so the texture can be re-initialized after device loss.
939
- * - If an existing texture is provided, the loader uploads into it.
940
- *
941
- * @typeParam T - Expected concrete texture type.
942
- * @param name - Built-in texture identifier.
943
- * @param texture - Optional destination texture to populate.
944
- * @returns The built-in texture (created or populated).
926
+ /**
927
+ * Fetch a built-in texture synchronously by name.
928
+ *
929
+ * - If this built-in was not created yet, the registered loader is invoked.
930
+ * - Registers a device restore handler so the texture can be re-initialized after device loss.
931
+ * - If an existing texture is provided, the loader uploads into it.
932
+ *
933
+ * @typeParam T - Expected concrete texture type.
934
+ * @param name - Built-in texture identifier.
935
+ * @param texture - Optional destination texture to populate.
936
+ * @returns The built-in texture (created or populated).
945
937
  */ fetchBuiltinTexture(name, texture) {
946
938
  const loader = AssetManager._builtinTextureLoaders[name];
947
939
  if (!loader) {
@@ -961,14 +953,14 @@ import { FontAsset } from '../text/font/font_asset.js';
961
953
  return texture;
962
954
  }
963
955
  }
964
- /**
965
- * Override or unregister the loader for a named built-in texture.
966
- *
967
- * - Passing a valid loader function sets/overrides the creation path.
968
- * - Passing `undefined` removes the loader mapping for the given name.
969
- *
970
- * @param name - Built-in texture identifier.
971
- * @param loader - Factory that creates the built-in texture using the provided AssetManager.
956
+ /**
957
+ * Override or unregister the loader for a named built-in texture.
958
+ *
959
+ * - Passing a valid loader function sets/overrides the creation path.
960
+ * - Passing `undefined` removes the loader mapping for the given name.
961
+ *
962
+ * @param name - Built-in texture identifier.
963
+ * @param loader - Factory that creates the built-in texture using the provided AssetManager.
972
964
  */ static setBuiltinTextureLoader(name, loader) {
973
965
  if (loader) {
974
966
  this._builtinTextureLoaders[name] = loader;
@@ -976,54 +968,41 @@ import { FontAsset } from '../text/font/font_asset.js';
976
968
  delete this._builtinTextureLoaders[name];
977
969
  }
978
970
  }
979
- /**
980
- * Compute a cache key for texture requests.
981
- *
982
- * Includes texture type tag, URL, and color space choice to avoid cross-color-space cache collisions.
983
- *
984
- * @typeParam T - Texture type parameter (not used for runtime behavior; helps preserve generic intent).
985
- * @param type - Logical texture type tag (e.g., '2d', 'cube').
986
- * @param url - Resource URL or VFS path.
987
- * @param options - Texture fetch options to incorporate into the key.
988
- * @returns A string cache key combining type, URL, and color space choice.
989
- * @internal
971
+ /**
972
+ * Compute a cache key for texture requests.
973
+ *
974
+ * Includes texture type tag, URL, and color space choice to avoid cross-color-space cache collisions.
975
+ *
976
+ * @typeParam T - Texture type parameter (not used for runtime behavior; helps preserve generic intent).
977
+ * @param type - Logical texture type tag (e.g., '2d', 'cube').
978
+ * @param url - Resource URL or VFS path.
979
+ * @param options - Texture fetch options to incorporate into the key.
980
+ * @returns A string cache key combining type, URL, and color space choice.
981
+ * @internal
990
982
  */ getHash(type, url, options) {
991
983
  return `${type}:${url}:${!options?.linearColorSpace}`;
992
984
  }
993
- /**
994
- * Try reading from file from a list of VFSs
995
- *
996
- * @param path - File path
997
- * @param options - Read options
998
- * @param vfsList - VFS list
999
- * @returns File content
1000
- *
1001
- * @internal
1002
- */ async readFileFromVFSs(path, options, vfsList) {
1003
- vfsList = vfsList ?? [
1004
- this.vfs
1005
- ];
1006
- for (const vfs of vfsList){
1007
- try {
1008
- return await vfs.readFile(path, options);
1009
- } catch {}
1010
- }
1011
- throw new VFSError(`File does not exist: ${path}`, 'ENOENT', path);
1012
- }
1013
- /**
1014
- * Write file to a list of VFSs
1015
- *
1016
- * @param path - File path
1017
- * @param data - Data to write
1018
- * @param options - Write options
1019
- * @param vfsList - Which VFSs will be written to
1020
- */ async writeFileToVFSs(path, data, options, vfsList) {
1021
- vfsList = vfsList ?? [
1022
- this.vfs
1023
- ];
1024
- for (const vfs of vfsList){
1025
- await vfs.writeFile(path, data, options);
1026
- }
985
+ /**
986
+ * Try reading from file from a VFS
987
+ *
988
+ * @param path - File path
989
+ * @param options - Read options
990
+ * @param vfs - VFS to read from
991
+ * @returns File content
992
+ *
993
+ * @internal
994
+ */ async readFileFromVFS(path, options, vfs) {
995
+ return await (vfs ?? this.vfs).readFile(path, options);
996
+ }
997
+ /**
998
+ * Write file to a VFS
999
+ *
1000
+ * @param path - File path
1001
+ * @param data - Data to write
1002
+ * @param options - Write options
1003
+ * @param vfs - VFS to write to
1004
+ */ async writeFileToVFSs(path, data, options, vfs) {
1005
+ await (vfs ?? this.vfs).writeFile(path, data, options);
1027
1006
  }
1028
1007
  }
1029
1008