GLTF edits without loading external images #450
-
Is there any way to open a GLTF (+ bin, if buffer-related editing occurs) without requiring the images to be present at that moment? I have some very large files being processed, and to speed things up I'd like to copy only the resources I need from s3 to the local node environment. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
There isn't currently an I/O function for that, or an internal representation of a remote texture. What you could do instead would be to manually create a JSONDocument with placeholders for the textures, then parse it with import fs from 'fs/promises';
import { NodeIO } from '@gltf-transform/core';
const io = new NodeIO();
const json = await fs.readFile('path/to/file.gltf');
const resources = {};
// Load buffers (.bin).
for (const buffer of json.buffers) {
resources[buffer.uri] = await fs.readFile(buffer.uri);
}
// Add placeholder images.
let i = 0;
for (const image of json.images) {
resources[image.uri] = new Uint8Array([ i++ ]).buffer;
}
const document = io.readJSON({json, resources}); Loading the .bin probably isn't avoidable, though. |
Beta Was this translation helpful? Give feedback.
There isn't currently an I/O function for that, or an internal representation of a remote texture. What you could do instead would be to manually create a JSONDocument with placeholders for the textures, then parse it with
io.readJSON
: