question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GLTFLoader: record association between glTF elements and Three.js objects

See original GitHub issue

Note: I don’t want to bury the lede for this request, so I moved a brief summary to the top of the issue. Please refer to the second and third headings for a more detailed background and rationale!

Proposal

When loading models with GLTFLoader, it would be nice if we could retain associations between glTF scene graph elements and the Three.js objects that correspond to them. I briefly discussed this problem with @donmccurdy and he suggested that one of the following approaches might be acceptable:

  1. Decorate Three.js objects via userData e.g., material.userData.gltfMeta.index = 3
  2. Expose a lookup table somewhere e.g., parser.getDefinition( material: THREE.Material ): GLTF.Material

What do others think about this problem? Would you be willing to consider a change that makes either of the suggested enhancements?

Background

Three.js’ GLTFLoader currently produces an artifact that contains a Three.js scene graph as well as a GLTFParser instance that holds the original, deserialized glTF.

The GLTFParser holds associations between the elements in the original glTF and the Three.js scene graph. These associations are expressed both by GLTFParser.prototype.getDependencies and the cache object on the GLTFParser instance.

In some cases, the relationship between the original glTF element and the associated Three.js objects is obscured and cannot be trivially re-established. For example, materials associated with a skinned mesh are cloned, and the resulting clones are cached against a key that cannot be reconstructed easily:

https://github.com/mrdoob/three.js/blob/648c4bbd7d8dd354680d720578da64a77548eecf/examples/jsm/loaders/GLTFLoader.js#L2118-L2127

Description of the problem

Consider a model editor that allows a user to:

  1. Load a glTF with any shape
  2. Interactively change the value of any field of any element of the glTF
  3. See the result of the change rendered in real time
  4. Export a new glTF

In an ideal world, the editor should faithfully re-export the model with its original hierarchy and shape. The only meaningful change in the exported file should be the one made interactively by the user.

In the pursuit of this goal, it is very useful (and probably required) that an association between the source glTF scene graph and the Three.js scene graph be made, so that for any change we make to a glTF element, we can reflect that change in the rendered Three.js scene in real-time without completely re-loading the glTF.

Some of the information required to correctly correlate the glTF scene graph with the Three.js scene graph is lost or obscured, and this makes the above described editor scenario very difficult (perhaps impossible) to achieve.

Three.js version
  • Dev
  • r115
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:27 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
donmccurdycommented, May 7, 2020

@pushmatrix this is still in progress, but for use cases like optimizing a model you may find https://github.com/donmccurdy/glTF-Transform helpful.

2reactions
donmccurdycommented, May 2, 2020

@drcmda and @FMS-Cat: I think you’ve both asked about variations of this in the past. Would either of these approaches be helpful for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

GLTFLoader – three.js docs
GLTFLoader. A loader for glTF 2.0 resources. glTF (GL Transmission Format) is an open format specification for efficient delivery and loading of 3D...
Read more >
Three.js Accessing an object after it was loaded with GLTF ...
I expect that the gltf model hasn't loaded by the time you are trying to set the position of it. The LoadingManager is...
Read more >
How to Import a 3D Blender Object into a Three.js Project as a ...
A tutorial that walks through each step from creating a Three.js-compatible UV-wrapped 3D object in Blender to loading the object into a Three.js...
Read more >
Import glTF 3D Models | Sample Code - ArcGIS Developers
The glTF (GL Transmission Format) is a file format for 3D models (e.g. ... as an ObjectSymbol3DLayer by specifying a link to the...
Read more >
Three.js Loading a .GLTF File
It provides no scene graph so everything loaded is one large mesh. It was designed mostly as a simple way to pass data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found