Skip to content

GLTF edits without loading external images #450

Answered by donmccurdy
benferns asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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({

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@benferns
Comment options

@benferns
Comment options

@donmccurdy
Comment options

@benferns
Comment options

Answer selected by benferns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants