Rebuild core around render graph AST and shared memory
Amp-Thread-ID: https://ampcode.com/threads/T-01a01380-b478-77d0-84a0-102880a5c5ae Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { writeSharedUpload } from "./shared-upload.js";
|
||||
|
||||
const downloads = new Map();
|
||||
|
||||
addEventListener("message", async ({ data: message }) => {
|
||||
const request = message?.request;
|
||||
try {
|
||||
if (message?.type === "load") {
|
||||
const response = await fetch(message.url);
|
||||
if (!response.ok) throw new Error(`HTTP_${response.status}`);
|
||||
const bytes = new Uint8Array(await response.arrayBuffer());
|
||||
if (!bytes.byteLength) throw new Error("GLTF_EMPTY");
|
||||
downloads.set(request, bytes);
|
||||
postMessage({ type: "allocate", request, byteLength: bytes.byteLength });
|
||||
return;
|
||||
}
|
||||
if (message?.type === "storage") {
|
||||
const bytes = downloads.get(request);
|
||||
if (!bytes) throw new Error("GLTF_REQUEST_UNKNOWN");
|
||||
writeSharedUpload(message.buffer, message.descriptor, bytes);
|
||||
downloads.delete(request);
|
||||
postMessage({ type: "ready", request, byteLength: bytes.byteLength });
|
||||
}
|
||||
} catch (error) {
|
||||
downloads.delete(request);
|
||||
postMessage({ type: "error", request, code: error?.message || "GLTF_IMPORT_FAILED" });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user