diff --git a/core3d/modules/octree/loader.ts b/core3d/modules/octree/loader.ts index bc5066a..871e5ff 100644 --- a/core3d/modules/octree/loader.ts +++ b/core3d/modules/octree/loader.ts @@ -1,6 +1,7 @@ import type { AbortAllMessage, AbortMessage, InitMessage, CloseMessage, LoadMessage, MessageRequest, MessageResponse, NodePayload, ParseMessage, ParseConfig } from "./worker"; import { OctreeNode } from "./node.js"; import type { DeviceProfile } from "core3d/device.js"; +import type { RenderContext } from "core3d/context"; interface PayloadPromiseMethods { readonly resolve: (value: NodePayload | undefined) => void, readonly reject: (reason: string) => void }; @@ -13,7 +14,7 @@ export class NodeLoader { private resolveBuffer: (() => void) | undefined; aborted = false; - constructor(readonly worker: Worker) { + constructor(readonly worker: Worker, readonly renderContext: RenderContext) { worker.onmessage = e => { this.receive(e.data as MessageResponse); } @@ -47,6 +48,7 @@ export class NodeLoader { const { resolveAbortAll } = this; this.resolveAbortAll = undefined; resolveAbortAll?.(); + this.renderContext.setSceneResolved(true); return; } const { id } = msg; @@ -60,9 +62,11 @@ export class NodeLoader { resolve(msg); break; case "aborted": + this.renderContext.setSceneResolved(this.payloadPromises.size == 0); resolve(undefined); break; case "error": + this.renderContext.setSceneResolved(this.payloadPromises.size == 0); reject(msg.error); break; } @@ -110,10 +114,7 @@ export class NodeLoader { const loadMsg: LoadMessage = { kind: "load", id, config, url: url.toString(), byteSize, enableOutlines, applyFilter }; console.assert(byteSize != 0); const abortMsg: AbortMessage = { kind: "abort", id }; - const abort = () => { - node.context.renderContext.setSceneResolved(this.payloadPromises.size == 1); - this.send(abortMsg); - } + const abort = () => { this.send(abortMsg); } node.download = { abort }; this.send(loadMsg); return new Promise((resolve, reject) => { diff --git a/core3d/modules/octree/module.ts b/core3d/modules/octree/module.ts index 10d6db7..37a22ab 100644 --- a/core3d/modules/octree/module.ts +++ b/core3d/modules/octree/module.ts @@ -68,7 +68,7 @@ export class OctreeModule implements RenderModule { const uniforms = this.createUniforms(); const resources = await this.createResources(context, uniforms); - const loader = new NodeLoader(context.imports.loaderWorker); + const loader = new NodeLoader(context.imports.loaderWorker, context); const maxObjects = 25_000_000;// TODO: Get from device profile? const maxByteLength = maxObjects + 4; // add four bytes for mutex const buffer = new SharedArrayBuffer(maxByteLength);