76168b6927
gltf-transform dedup/prune/weld/quantize/sparse,几何未简化(simplify 会伤玻璃折射精度)。KHR_mesh_quantization 为 GLTFLoader 原生支持,无需 Draco/Meshopt 解码器;base64 内嵌 buffer 转 glb 二进制直接省 33% 开销。同步更新 GlassModels URL 与 loadingBus REQUIRED key。
69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
/**
|
|
* Heavy-asset loading progress — mirrors the original's heavy-load tracking
|
|
* (models + texture layers + sticker atlas gate the entrance). Components
|
|
* report completion via mark(); the overlay reads progress/ready.
|
|
*/
|
|
|
|
const REQUIRED = [
|
|
"model:hello.glb",
|
|
"model:cursor.glb",
|
|
"stickers",
|
|
"img:about",
|
|
] as const;
|
|
|
|
const done = new Set<string>();
|
|
const listeners = new Set<() => void>();
|
|
let notifyQueued = false;
|
|
|
|
function notify() {
|
|
if (notifyQueued) return;
|
|
notifyQueued = true;
|
|
queueMicrotask(() => {
|
|
notifyQueued = false;
|
|
listeners.forEach((l) => l());
|
|
});
|
|
}
|
|
|
|
function computeSnapshot() {
|
|
const marked = REQUIRED.filter((k) => done.has(k)).length;
|
|
return {
|
|
progress: Math.round((marked / REQUIRED.length) * 100),
|
|
ready: marked === REQUIRED.length,
|
|
};
|
|
}
|
|
|
|
let currentSnapshot = computeSnapshot();
|
|
|
|
export const loadingBus = {
|
|
mark(key: string) {
|
|
if (!done.has(key)) {
|
|
done.add(key);
|
|
currentSnapshot = computeSnapshot();
|
|
notify();
|
|
}
|
|
},
|
|
/** Safety valve: complete everything (a stalled asset must not soft-lock). */
|
|
forceReady() {
|
|
let changed = false;
|
|
for (const k of REQUIRED) {
|
|
if (!done.has(k)) {
|
|
done.add(k);
|
|
changed = true;
|
|
}
|
|
}
|
|
if (changed) {
|
|
currentSnapshot = computeSnapshot();
|
|
notify();
|
|
}
|
|
},
|
|
getSnapshot() {
|
|
return currentSnapshot;
|
|
},
|
|
subscribe(listener: () => void) {
|
|
listeners.add(listener);
|
|
return () => {
|
|
listeners.delete(listener);
|
|
};
|
|
},
|
|
};
|