@needle-tools/gltf-progressive 3.6.0 → 3.6.1
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/CHANGELOG.md +4 -0
- package/gltf-progressive.js +520 -507
- package/gltf-progressive.min.js +9 -9
- package/gltf-progressive.umd.cjs +9 -9
- package/lib/extension.d.ts +2 -0
- package/lib/extension.js +29 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/lib/extension.js
CHANGED
|
@@ -796,6 +796,8 @@ export class NEEDLE_progressive {
|
|
|
796
796
|
}
|
|
797
797
|
}
|
|
798
798
|
else {
|
|
799
|
+
// Requests already waiting for a queue slot must not populate a new cache lifetime.
|
|
800
|
+
this.cacheGeneration++;
|
|
799
801
|
this.lodInfos.clear();
|
|
800
802
|
for (const [, entryRef] of this.lowresCache) {
|
|
801
803
|
const entry = entryRef.deref();
|
|
@@ -840,6 +842,7 @@ export class NEEDLE_progressive {
|
|
|
840
842
|
else {
|
|
841
843
|
// Promise — may be in-flight or already resolved.
|
|
842
844
|
// Attach disposal to run after resolution.
|
|
845
|
+
this.disposedRequests.add(entry);
|
|
843
846
|
entry.then(resource => {
|
|
844
847
|
if (resource) {
|
|
845
848
|
if (Array.isArray(resource)) {
|
|
@@ -938,8 +941,11 @@ export class NEEDLE_progressive {
|
|
|
938
941
|
}
|
|
939
942
|
}
|
|
940
943
|
static workers = [];
|
|
944
|
+
static cacheGeneration = 0;
|
|
945
|
+
static disposedRequests = new WeakSet();
|
|
941
946
|
static _workersIndex = 0;
|
|
942
947
|
static async getOrLoadLOD(current, level, options) {
|
|
948
|
+
const generation = this.cacheGeneration;
|
|
943
949
|
const debugverbose = debug == "verbose";
|
|
944
950
|
/** this key is used to lookup the LOD information */
|
|
945
951
|
const LOD = this.getAssignedLODInformation(current);
|
|
@@ -1010,6 +1016,8 @@ export class NEEDLE_progressive {
|
|
|
1010
1016
|
const KEY = lod_url + "_" + lodInfo.guid;
|
|
1011
1017
|
// check if the requested file is currently being loaded or was previously loaded
|
|
1012
1018
|
const cached = await this.tryResolveLODCacheEntry(this.cache.get(KEY), KEY, lod_url, current, level, debugverbose);
|
|
1019
|
+
if (generation !== this.cacheGeneration)
|
|
1020
|
+
return null;
|
|
1013
1021
|
if (cached.found)
|
|
1014
1022
|
return cached.value;
|
|
1015
1023
|
if (options?.isCurrent?.() === false) {
|
|
@@ -1018,6 +1026,8 @@ export class NEEDLE_progressive {
|
|
|
1018
1026
|
return null;
|
|
1019
1027
|
}
|
|
1020
1028
|
const slot = await this.queue.slot(lod_url);
|
|
1029
|
+
if (generation !== this.cacheGeneration)
|
|
1030
|
+
return null;
|
|
1021
1031
|
if (options?.isCurrent?.() === false) {
|
|
1022
1032
|
if (debugverbose)
|
|
1023
1033
|
console.log(`Skipping stale LOD ${level} request after queue: ${lod_url}`);
|
|
@@ -1026,8 +1036,20 @@ export class NEEDLE_progressive {
|
|
|
1026
1036
|
// Another request can fill the cache while this one waits for a queue slot.
|
|
1027
1037
|
// Re-checking here avoids duplicate loads for heavily instanced assets.
|
|
1028
1038
|
const cachedAfterQueue = await this.tryResolveLODCacheEntry(this.cache.get(KEY), KEY, lod_url, current, level, debugverbose);
|
|
1039
|
+
if (generation !== this.cacheGeneration)
|
|
1040
|
+
return null;
|
|
1029
1041
|
if (cachedAfterQueue.found)
|
|
1030
1042
|
return cachedAfterQueue.value;
|
|
1043
|
+
// Even a cache miss above yields a microtask. Another slot holder can
|
|
1044
|
+
// start this same request before that continuation resumes.
|
|
1045
|
+
const startedMeanwhile = this.cache.get(KEY);
|
|
1046
|
+
if (startedMeanwhile !== undefined) {
|
|
1047
|
+
const cached = await this.tryResolveLODCacheEntry(startedMeanwhile, KEY, lod_url, current, level, debugverbose);
|
|
1048
|
+
if (generation !== this.cacheGeneration)
|
|
1049
|
+
return null;
|
|
1050
|
+
if (cached.found)
|
|
1051
|
+
return cached.value;
|
|
1052
|
+
}
|
|
1031
1053
|
// #region loading
|
|
1032
1054
|
if (!slot.use) {
|
|
1033
1055
|
if (debug)
|
|
@@ -1175,6 +1197,10 @@ export class NEEDLE_progressive {
|
|
|
1175
1197
|
this.cache.set(KEY, request);
|
|
1176
1198
|
slot.use(request);
|
|
1177
1199
|
const res = await request;
|
|
1200
|
+
// dispose() owns cleanup of removed pending entries. Do not return their
|
|
1201
|
+
// disposed resources to callers or overwrite a newer request for this key.
|
|
1202
|
+
if (generation !== this.cacheGeneration || this.cache.get(KEY) !== request)
|
|
1203
|
+
return null;
|
|
1178
1204
|
// Optimize cache entry: replace loading promise with lightweight reference.
|
|
1179
1205
|
// This releases closure variables captured during the loading function.
|
|
1180
1206
|
if (res != null) {
|
|
@@ -1212,7 +1238,7 @@ export class NEEDLE_progressive {
|
|
|
1212
1238
|
console.log("Load texture from uri: " + lod_url);
|
|
1213
1239
|
const loader = new TextureLoader();
|
|
1214
1240
|
const tex = await loader.loadAsync(lod_url);
|
|
1215
|
-
if (options?.isCurrent?.() === false) {
|
|
1241
|
+
if (generation !== this.cacheGeneration || options?.isCurrent?.() === false) {
|
|
1216
1242
|
tex?.dispose();
|
|
1217
1243
|
return null;
|
|
1218
1244
|
}
|
|
@@ -1269,6 +1295,8 @@ export class NEEDLE_progressive {
|
|
|
1269
1295
|
console.error(`Error loading LOD ${level} from ${lodUrl}\n`, err);
|
|
1270
1296
|
return null;
|
|
1271
1297
|
});
|
|
1298
|
+
if (this.disposedRequests.has(existing))
|
|
1299
|
+
return { found: true, value: null };
|
|
1272
1300
|
let resourceIsDisposed = false;
|
|
1273
1301
|
if (res == null) {
|
|
1274
1302
|
// Failed loads stay cached as null so we don't retry the same missing resource forever.
|
package/lib/version.js
CHANGED
package/package.json
CHANGED