Amp-Thread-ID: https://ampcode.com/threads/T-01a01380-b478-77d0-84a0-102880a5c5ae Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
1.8 KiB
1.8 KiB
glTF import worker
@yawn/gltf-import keeps parsing and bulk upload off the renderer command channel. It fetches a .gltf or .glb URL in a dedicated worker and writes a format-neutral packet directly into shared memory.
Load a scene
import { GltfImporter } from "@yawn/gltf-import";
const importer = new GltfImporter(core);
try {
const result = await importer.load("/models/level.glb");
console.log(result.meshes, result.materials, result.bounds);
} finally {
importer.dispose();
}
The import handshake is:
- The import worker fetches and measures the asset packet.
- Core allocates a fixed
upload.renderDatashared array. - The import worker writes packet bytes into that SAB.
- Core receives only the array ID and byte count, then installs render data.
No GLB payload is copied through the renderer's message queue.
Camera framing
Import frames the canonical camera.state row from scene bounds by default. Select an exterior or interior framing policy, or preserve the current camera.
await importer.load(url, { framing: "exterior" });
await importer.load(url, { framing: "interior" });
await importer.load(url, { framing: false });
Framing is an addon behavior implemented as a shared camera-row write. It is not a camera subsystem in core.
Wrap the result when useful
Import returns protocol descriptors. Less technical consumers can turn those descriptors into generation-safe objects.
import { MeshHandles, MaterialHandles } from "@yawn/mesh-handles";
const meshes = new MeshHandles(core).fromImportedScene(result);
const materials = new MaterialHandles(core).fromImportedScene(result);