@needle-tools/gltf-progressive 3.4.0-next.a9f46ea → 3.4.0-next.dbcee85
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/gltf-progressive.js +338 -337
- package/gltf-progressive.min.js +8 -7
- package/gltf-progressive.umd.cjs +8 -7
- package/lib/extension.d.ts +1 -1
- package/lib/extension.js +26 -23
- package/package.json +1 -1
package/lib/extension.js
CHANGED
|
@@ -552,10 +552,10 @@ export class NEEDLE_progressive {
|
|
|
552
552
|
this.lowresCache.delete(guid);
|
|
553
553
|
}
|
|
554
554
|
// Dispose previously loaded LOD entries
|
|
555
|
-
for (const [key, entry] of this.
|
|
555
|
+
for (const [key, entry] of this.cache) {
|
|
556
556
|
if (key.includes(guid)) {
|
|
557
557
|
this._disposeCacheEntry(entry);
|
|
558
|
-
this.
|
|
558
|
+
this.cache.delete(key);
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
561
|
}
|
|
@@ -574,10 +574,10 @@ export class NEEDLE_progressive {
|
|
|
574
574
|
}
|
|
575
575
|
}
|
|
576
576
|
this.lowresCache.clear();
|
|
577
|
-
for (const [, entry] of this.
|
|
577
|
+
for (const [, entry] of this.cache) {
|
|
578
578
|
this._disposeCacheEntry(entry);
|
|
579
579
|
}
|
|
580
|
-
this.
|
|
580
|
+
this.cache.clear();
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
583
|
/** Dispose a single cache entry's three.js resource(s) to free GPU memory. */
|
|
@@ -606,7 +606,7 @@ export class NEEDLE_progressive {
|
|
|
606
606
|
/** A map of key = asset uuid and value = LOD information */
|
|
607
607
|
static lodInfos = new Map();
|
|
608
608
|
/** cache of already loaded mesh lods. Uses WeakRef for single resources to allow garbage collection when unused. */
|
|
609
|
-
static
|
|
609
|
+
static cache = new Map();
|
|
610
610
|
/** this contains the geometry/textures that were originally loaded. Uses WeakRef to allow garbage collection when unused. */
|
|
611
611
|
static lowresCache = new Map();
|
|
612
612
|
/**
|
|
@@ -615,13 +615,14 @@ export class NEEDLE_progressive {
|
|
|
615
615
|
* The held value is the cache key string used in `previouslyLoaded`.
|
|
616
616
|
*/
|
|
617
617
|
static _resourceRegistry = new FinalizationRegistry((cacheKey) => {
|
|
618
|
-
const entry = NEEDLE_progressive.
|
|
619
|
-
|
|
618
|
+
const entry = NEEDLE_progressive.cache.get(cacheKey);
|
|
619
|
+
if (debug)
|
|
620
|
+
console.debug(`[gltf-progressive] Resource GC'd\n${cacheKey}`);
|
|
620
621
|
// Only delete if the entry is still a WeakRef and the resource is gone
|
|
621
622
|
if (entry instanceof WeakRef) {
|
|
622
623
|
const derefed = entry.deref();
|
|
623
624
|
if (!derefed) {
|
|
624
|
-
NEEDLE_progressive.
|
|
625
|
+
NEEDLE_progressive.cache.delete(cacheKey);
|
|
625
626
|
if (debug)
|
|
626
627
|
console.log(`[gltf-progressive] Cache entry auto-cleaned (GC'd): ${cacheKey}`);
|
|
627
628
|
}
|
|
@@ -700,7 +701,7 @@ export class NEEDLE_progressive {
|
|
|
700
701
|
const KEY = lod_url + "_" + lodInfo.guid;
|
|
701
702
|
const slot = await this.queue.slot(lod_url);
|
|
702
703
|
// check if the requested file is currently being loaded or was previously loaded
|
|
703
|
-
const existing = this.
|
|
704
|
+
const existing = this.cache.get(KEY);
|
|
704
705
|
if (existing !== undefined) {
|
|
705
706
|
if (debugverbose)
|
|
706
707
|
console.log(`LOD ${level} was already loading/loaded: ${KEY}`);
|
|
@@ -728,7 +729,7 @@ export class NEEDLE_progressive {
|
|
|
728
729
|
}
|
|
729
730
|
}
|
|
730
731
|
// Resource was garbage collected or disposed — remove stale entry and re-load
|
|
731
|
-
this.
|
|
732
|
+
this.cache.delete(KEY);
|
|
732
733
|
if (debug)
|
|
733
734
|
console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${KEY}`);
|
|
734
735
|
}
|
|
@@ -751,7 +752,7 @@ export class NEEDLE_progressive {
|
|
|
751
752
|
// if it has been disposed we need to load it again
|
|
752
753
|
else {
|
|
753
754
|
resouceIsDisposed = true;
|
|
754
|
-
this.
|
|
755
|
+
this.cache.delete(KEY);
|
|
755
756
|
}
|
|
756
757
|
}
|
|
757
758
|
else if (res instanceof BufferGeometry && current instanceof BufferGeometry) {
|
|
@@ -760,7 +761,7 @@ export class NEEDLE_progressive {
|
|
|
760
761
|
}
|
|
761
762
|
else {
|
|
762
763
|
resouceIsDisposed = true;
|
|
763
|
-
this.
|
|
764
|
+
this.cache.delete(KEY);
|
|
764
765
|
}
|
|
765
766
|
}
|
|
766
767
|
if (!resouceIsDisposed) {
|
|
@@ -912,30 +913,32 @@ export class NEEDLE_progressive {
|
|
|
912
913
|
// we could not find a texture or mesh with the given guid
|
|
913
914
|
return resolve(null);
|
|
914
915
|
});
|
|
915
|
-
this.
|
|
916
|
+
this.cache.set(KEY, request);
|
|
916
917
|
slot.use(request);
|
|
917
918
|
const res = await request;
|
|
918
919
|
// Optimize cache entry: replace loading promise with lightweight reference.
|
|
919
920
|
// This releases closure variables captured during the loading function.
|
|
920
921
|
if (res != null) {
|
|
921
|
-
if (
|
|
922
|
+
if (res instanceof Texture) {
|
|
923
|
+
// For Texture resources, use WeakRef to allow garbage collection.
|
|
924
|
+
// The FinalizationRegistry will auto-clean this entry when the resource is GC'd.
|
|
925
|
+
this.cache.set(KEY, new WeakRef(res));
|
|
926
|
+
NEEDLE_progressive._resourceRegistry.register(res, KEY);
|
|
927
|
+
}
|
|
928
|
+
else if (Array.isArray(res)) {
|
|
922
929
|
// For BufferGeometry[] (multi-primitive meshes), use a resolved promise.
|
|
923
|
-
//
|
|
924
|
-
|
|
925
|
-
this.previouslyLoaded.set(KEY, Promise.resolve(res));
|
|
930
|
+
// This keeps geometries in memory as they should not be GC'd (mesh LODs stay cached).
|
|
931
|
+
this.cache.set(KEY, Promise.resolve(res));
|
|
926
932
|
}
|
|
927
933
|
else {
|
|
928
|
-
// For single
|
|
929
|
-
|
|
930
|
-
// The FinalizationRegistry will auto-clean this entry when the resource is GC'd.
|
|
931
|
-
this.previouslyLoaded.set(KEY, new WeakRef(res));
|
|
932
|
-
NEEDLE_progressive._resourceRegistry.register(res, KEY);
|
|
934
|
+
// For single BufferGeometry, keep in memory (don't use WeakRef)
|
|
935
|
+
this.cache.set(KEY, Promise.resolve(res));
|
|
933
936
|
}
|
|
934
937
|
}
|
|
935
938
|
else {
|
|
936
939
|
// Failed load — replace with clean resolved promise to release loading closure.
|
|
937
940
|
// Keeping the entry prevents retrying (existing behavior).
|
|
938
|
-
this.
|
|
941
|
+
this.cache.set(KEY, Promise.resolve(null));
|
|
939
942
|
}
|
|
940
943
|
return res;
|
|
941
944
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-progressive",
|
|
3
|
-
"version": "3.4.0-next.
|
|
3
|
+
"version": "3.4.0-next.dbcee85",
|
|
4
4
|
"description": "three.js support for loading glTF or GLB files that contain progressive loading data",
|
|
5
5
|
"homepage": "https://needle.tools",
|
|
6
6
|
"author": {
|