@preference-sl/pref-viewer 2.13.0-beta.8 → 2.13.0-beta.9
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.
- package/package.json +1 -1
- package/src/babylonjs-controller.js +15 -1
- package/src/file-storage.js +17 -0
- package/src/gltf-resolver.js +11 -0
package/package.json
CHANGED
|
@@ -39,6 +39,7 @@ import { translate } from "./localization/i18n.js";
|
|
|
39
39
|
* 5. Use `setContainerVisibility`, `setMaterialOptions`, `setCameraOptions`, or `setIBLOptions` for targeted updates; these
|
|
40
40
|
* helpers stop/restart the render loop while they rebuild camera-dependent resources.
|
|
41
41
|
* 6. Invoke `disable()` when the element disconnects to tear down scenes, XR sessions, observers, and handlers.
|
|
42
|
+
* The controller also disposes the shared GLTF resolver, which closes its internal IndexedDB handle.
|
|
42
43
|
*
|
|
43
44
|
* Public API Highlights
|
|
44
45
|
* - constructor(canvas, containers, options)
|
|
@@ -1230,6 +1231,18 @@ export default class BabylonJSController {
|
|
|
1230
1231
|
}
|
|
1231
1232
|
}
|
|
1232
1233
|
|
|
1234
|
+
/**
|
|
1235
|
+
* Disposes the shared GLTFResolver instance and closes its underlying storage handle.
|
|
1236
|
+
* @private
|
|
1237
|
+
* @returns {void}
|
|
1238
|
+
*/
|
|
1239
|
+
#disposeGLTFResolver() {
|
|
1240
|
+
if (this.#gltfResolver) {
|
|
1241
|
+
this.#gltfResolver.dispose();
|
|
1242
|
+
this.#gltfResolver = null;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1233
1246
|
/**
|
|
1234
1247
|
* Disposes the Babylon.js WebXR experience if it exists.
|
|
1235
1248
|
* @private
|
|
@@ -2258,13 +2271,14 @@ export default class BabylonJSController {
|
|
|
2258
2271
|
|
|
2259
2272
|
/**
|
|
2260
2273
|
* Disposes the Babylon.js engine and disconnects the canvas resize observer.
|
|
2261
|
-
* Cleans up all scene, camera, light, and
|
|
2274
|
+
* Cleans up all scene, camera, light, XR, and GLTF resolver resources.
|
|
2262
2275
|
* @public
|
|
2263
2276
|
* @returns {void}
|
|
2264
2277
|
*/
|
|
2265
2278
|
disable() {
|
|
2266
2279
|
this.#disableInteraction();
|
|
2267
2280
|
this.#disposeAnimationController();
|
|
2281
|
+
this.#disposeGLTFResolver();
|
|
2268
2282
|
this.#disposeXRExperience();
|
|
2269
2283
|
this.#unloadCameraDependentEffects();
|
|
2270
2284
|
this.#stopEngineRenderLoop();
|
package/src/file-storage.js
CHANGED
|
@@ -36,6 +36,7 @@ import { openDB } from "idb";
|
|
|
36
36
|
* - getBlob(uri): Retrieves file blob from cache or server.
|
|
37
37
|
* - get(uri): Gets file from cache with automatic server sync and cache versioning.
|
|
38
38
|
* - put(uri): Stores file from server in IndexedDB cache.
|
|
39
|
+
* - dispose(): Closes the active IndexedDB handle held by the instance.
|
|
39
40
|
*
|
|
40
41
|
* Features:
|
|
41
42
|
* - Automatic Cache Versioning: Compares server and cached timestamps to update cache.
|
|
@@ -105,6 +106,7 @@ import { openDB } from "idb";
|
|
|
105
106
|
* - Supports both HTTPS and HTTP (HTTP not recommended for production)
|
|
106
107
|
* - Object URLs should be revoked after use to free memory
|
|
107
108
|
* - IndexedDB cache is auto-maintained (TTL, max entries, quota cleanup)
|
|
109
|
+
* - Call dispose() when the owner is torn down to release the DB connection proactively.
|
|
108
110
|
*
|
|
109
111
|
* Error Handling:
|
|
110
112
|
* - Network failures: Returns undefined (get) or false (other methods)
|
|
@@ -782,4 +784,19 @@ export default class FileStorage {
|
|
|
782
784
|
const fileToStore = await this.#getServerFile(uri);
|
|
783
785
|
return fileToStore ? !!(await this.#putFile(fileToStore, uri)) : false;
|
|
784
786
|
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Closes the IndexedDB handle held by this storage instance.
|
|
790
|
+
* Safe to call multiple times; next storage operation will lazily reopen the DB.
|
|
791
|
+
* @public
|
|
792
|
+
* @returns {void}
|
|
793
|
+
*/
|
|
794
|
+
dispose() {
|
|
795
|
+
if (this.#db) {
|
|
796
|
+
try {
|
|
797
|
+
this.#db.close();
|
|
798
|
+
} catch {}
|
|
799
|
+
}
|
|
800
|
+
this.#db = undefined;
|
|
801
|
+
}
|
|
785
802
|
}
|
package/src/gltf-resolver.js
CHANGED
|
@@ -19,6 +19,7 @@ import { initDb, loadModel } from "./gltf-storage.js";
|
|
|
19
19
|
* Public Methods:
|
|
20
20
|
* - getSource(storage, currentSize, currentTimeStamp): Resolves and prepares a glTF/GLB source for loading.
|
|
21
21
|
* - revokeObjectURLs(objectURLs): Releases temporary blob URLs generated during source resolution.
|
|
22
|
+
* - dispose(): Releases resolver resources and closes the internal FileStorage DB handle.
|
|
22
23
|
*
|
|
23
24
|
* Private Methods:
|
|
24
25
|
* - #initializeStorage(db, table): Ensures IndexedDB store is initialized.
|
|
@@ -231,6 +232,16 @@ export default class GLTFResolver {
|
|
|
231
232
|
objectURLs.length = 0;
|
|
232
233
|
}
|
|
233
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Disposes resolver-owned resources.
|
|
237
|
+
* @public
|
|
238
|
+
* @returns {void}
|
|
239
|
+
*/
|
|
240
|
+
dispose() {
|
|
241
|
+
this.#fileStorage?.dispose?.();
|
|
242
|
+
this.#fileStorage = null;
|
|
243
|
+
}
|
|
244
|
+
|
|
234
245
|
/**
|
|
235
246
|
* Resolves and prepares a glTF/GLB source from various storage backends.
|
|
236
247
|
* Supports IndexedDB, direct URLs, and base64-encoded data.
|