Skip to content

Commit dbcee85

Browse files
committed
minor rename
1 parent a30adb3 commit dbcee85

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/extension.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,10 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
660660
}
661661

662662
// Dispose previously loaded LOD entries
663-
for (const [key, entry] of this.previouslyLoaded) {
663+
for (const [key, entry] of this.cache) {
664664
if (key.includes(guid)) {
665665
this._disposeCacheEntry(entry);
666-
this.previouslyLoaded.delete(key);
666+
this.cache.delete(key);
667667
}
668668
}
669669
} else {
@@ -681,10 +681,10 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
681681
}
682682
this.lowresCache.clear();
683683

684-
for (const [, entry] of this.previouslyLoaded) {
684+
for (const [, entry] of this.cache) {
685685
this._disposeCacheEntry(entry);
686686
}
687-
this.previouslyLoaded.clear();
687+
this.cache.clear();
688688
}
689689
}
690690

@@ -713,7 +713,7 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
713713
/** A map of key = asset uuid and value = LOD information */
714714
private static readonly lodInfos = new Map<string, NEEDLE_progressive_ext>();
715715
/** cache of already loaded mesh lods. Uses WeakRef for single resources to allow garbage collection when unused. */
716-
private static readonly previouslyLoaded: Map<string, LODCacheEntry> = new Map();
716+
private static readonly cache: Map<string, LODCacheEntry> = new Map();
717717
/** this contains the geometry/textures that were originally loaded. Uses WeakRef to allow garbage collection when unused. */
718718
private static readonly lowresCache: Map<string, WeakRef<Texture> | WeakRef<BufferGeometry[]>> = new Map();
719719

@@ -723,13 +723,13 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
723723
* The held value is the cache key string used in `previouslyLoaded`.
724724
*/
725725
private static readonly _resourceRegistry = new FinalizationRegistry<string>((cacheKey: string) => {
726-
const entry = NEEDLE_progressive.previouslyLoaded.get(cacheKey);
727-
console.debug(`[gltf-progressive] FinalizationRegistry cleanup: Resource GC'd for ${cacheKey}.`);
726+
const entry = NEEDLE_progressive.cache.get(cacheKey);
727+
if(debug) console.debug(`[gltf-progressive] Resource GC'd\n${cacheKey}`);
728728
// Only delete if the entry is still a WeakRef and the resource is gone
729729
if (entry instanceof WeakRef) {
730730
const derefed = entry.deref();
731731
if (!derefed) {
732-
NEEDLE_progressive.previouslyLoaded.delete(cacheKey);
732+
NEEDLE_progressive.cache.delete(cacheKey);
733733
if (debug) console.log(`[gltf-progressive] Cache entry auto-cleaned (GC'd): ${cacheKey}`);
734734
}
735735

@@ -823,7 +823,7 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
823823
const slot = await this.queue.slot(lod_url);
824824

825825
// check if the requested file is currently being loaded or was previously loaded
826-
const existing = this.previouslyLoaded.get(KEY);
826+
const existing = this.cache.get(KEY);
827827
if (existing !== undefined) {
828828
if (debugverbose) console.log(`LOD ${level} was already loading/loaded: ${KEY}`);
829829

@@ -850,7 +850,7 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
850850
}
851851
}
852852
// Resource was garbage collected or disposed — remove stale entry and re-load
853-
this.previouslyLoaded.delete(KEY);
853+
this.cache.delete(KEY);
854854
if (debug) console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${KEY}`);
855855
}
856856
else {
@@ -872,7 +872,7 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
872872
// if it has been disposed we need to load it again
873873
else {
874874
resouceIsDisposed = true;
875-
this.previouslyLoaded.delete(KEY);
875+
this.cache.delete(KEY);
876876
}
877877
}
878878
else if (res instanceof BufferGeometry && current instanceof BufferGeometry) {
@@ -881,7 +881,7 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
881881
}
882882
else {
883883
resouceIsDisposed = true;
884-
this.previouslyLoaded.delete(KEY);
884+
this.cache.delete(KEY);
885885
}
886886
}
887887
if (!resouceIsDisposed) {
@@ -1046,29 +1046,30 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
10461046
// we could not find a texture or mesh with the given guid
10471047
return resolve(null);
10481048
});
1049-
this.previouslyLoaded.set(KEY, request);
1049+
this.cache.set(KEY, request);
10501050
slot.use(request);
10511051
const res = await request;
10521052

10531053
// Optimize cache entry: replace loading promise with lightweight reference.
10541054
// This releases closure variables captured during the loading function.
10551055
if (res != null) {
1056-
if (Array.isArray(res)) {
1057-
// For BufferGeometry[] (multi-primitive meshes), use a resolved promise.
1058-
// WeakRef can't be used here because callers only extract individual elements
1059-
// from the array, so the array object itself would be GC'd immediately.
1060-
this.previouslyLoaded.set(KEY, Promise.resolve(res));
1061-
} else {
1062-
// For single resources (Texture or BufferGeometry), use WeakRef to allow
1063-
// garbage collection when the resource is no longer referenced by the scene.
1056+
if (res instanceof Texture) {
1057+
// For Texture resources, use WeakRef to allow garbage collection.
10641058
// The FinalizationRegistry will auto-clean this entry when the resource is GC'd.
1065-
this.previouslyLoaded.set(KEY, new WeakRef(res));
1059+
this.cache.set(KEY, new WeakRef(res));
10661060
NEEDLE_progressive._resourceRegistry.register(res, KEY);
1061+
} else if (Array.isArray(res)) {
1062+
// For BufferGeometry[] (multi-primitive meshes), use a resolved promise.
1063+
// This keeps geometries in memory as they should not be GC'd (mesh LODs stay cached).
1064+
this.cache.set(KEY, Promise.resolve(res));
1065+
} else {
1066+
// For single BufferGeometry, keep in memory (don't use WeakRef)
1067+
this.cache.set(KEY, Promise.resolve(res));
10671068
}
10681069
} else {
10691070
// Failed load — replace with clean resolved promise to release loading closure.
10701071
// Keeping the entry prevents retrying (existing behavior).
1071-
this.previouslyLoaded.set(KEY, Promise.resolve(null));
1072+
this.cache.set(KEY, Promise.resolve(null));
10721073
}
10731074

10741075
return res as T;

0 commit comments

Comments
 (0)