Skip to content

writeJson after updating it result in loose data. #392

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

You must be logged in to vote

Working with the raw JSON data is unforgiving, I wouldn't recommend that for anything more than cosmetic changes, or to load something in memory that the NodeIO and WebIO classes wouldn't otherwise be able to access. But if you do go that route, note that when changing a URI, you must also change the corresponding key in the jsonDocument.resources object. Those resources are held in memory, so io.readJSON(...) does not read anything from disk.


The preferred solution here would be to work with a Document instead of the raw JSON:

const document = io.read('input.gltf');

fs.ensureDirSync('path/to/assets');

for (const texture of document.getRoot().listTextures()) {
  texture.setURI('path/to…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by donmccurdy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #391 on October 22, 2021 16:18.