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: primitive type .extras

See original GitHub issue
Description of the problem

From #14315

Currently GLTFLoader just sets .extras property to Three.js object’s .userData.

if ( nodeDef.extras ) node.userData = nodeDef.extras;

But .extras type in glTF is any while .userData type in Three.js is object. If .extras have primitive type value, like integer or strings, .userData will have invalid type value in Three.js.

I’m thinking of .userData.glTF (or .userData.extras) instead of .userData to set .extras to.

if ( nodeDef.extras ) node.userData.glTF = nodeDef.extras;

Another option is to set like { value: *.extras } to .userData if .extras is non-object.

if ( nodeDef.extras ) {

    node.userData = ( typeof nodeDef.extras === 'object' )
        ? nodeDef.extras
        : { value: nodeDef.extras };

}

Any thoughts?

/cc @donmccurdy @wlinna

(BTW, we should replace if ( *.extras ) with if ( *.extras !== undefined ) because .extras can be 0, false, or empty strings ‘’.)

Three.js version
  • Dev
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 5 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
donmccurdycommented, Jul 9, 2018

Thus, I’d prefer extras to be simply assigned to userData field, and primitive types would be handled as a special case.

+1. While technically allowed, no tools are doing this. Better to establish clear best practice that it be an object, and perhaps even disallow primitive extras types in a future version of glTF. If extras is a primitive type, we could log a warning and ignore it, but until/unless it causes a real issue I’d vote to avoid adding specific code for the case at all.

2reactions
takahiroxcommented, Jun 25, 2018

Yeah, I prefer .userData.glTF too but one concern. How we should export .userData.

If we import .extras as .userData.glTF and export .userData as .extras, we’ll get .userData.glTF.glTF.glTF... if we repeatedly import and export.

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 Loading a .GLTF File
The gLTF format is actually a format designed from the ground up for be used for displaying graphics. 3D formats can be divided...
Read more >
Load 3D Models in glTF Format - Discover three.js!
You can use three.js to build any kind of 3D application, however, ... To load glTF files, first, you need to add the...
Read more >
three.js 加载gltf模型的简化demo - CSDN博客
GLTFLoader : Ignoring primitive type .extras, ' + gltfDef.extras ); } } } /** * ...
Read more >
GLTF Format — x-visual 0.4 documentation
Three.js GLTFLoader will create then use a cache for meshes' material: GLTFParser.prototype.assignFinalMaterial = function ( mesh ) { if ( ! cachedMaterial )...
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