Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gltf] Fix parsing of Bone nodes. #11524

Merged
merged 2 commits into from
Jun 18, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions examples/js/loaders/GLTF2Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2531,28 +2531,34 @@ THREE.GLTF2Loader = ( function () {
var extensions = this.extensions;
var scope = this;

return _each( json.nodes, function ( node ) {

var matrix = new THREE.Matrix4();
var nodes = json.nodes || [];

var _node;
// Nothing in the node definition indicates whether it is a Bone or an
// Object3D. So, traverse the hierarchy once in advance, using node.skins
// references to mark bones.
nodes.forEach( function ( node ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donmccurdy
Why do you traverse all nodes and check each for skin? It would be faster to traverse skins directly:

skins.forEach( function ( skin ) {

    if ( skin.joints !== undefined ) {

        skin.joints.forEach( function ( id ) {

            nodes[ id ].isBone = true;

        } );

    }
    
} );

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks! 😆


if ( node.jointName ) {
if ( node.skin !== undefined ) {

_node = new THREE.Bone();
_node.name = node.name !== undefined ? node.name : node.jointName;
_node.jointName = node.jointName;
json.skins[ node.skin ].joints.forEach( function ( id ) {

} else {
nodes[ id ].isBone = true;

_node = new THREE.Object3D();
if ( node.name !== undefined ) _node.name = node.name;
} );

}

if ( _node.name !== undefined ) {
} );

return _each( json.nodes, function ( node ) {

var matrix = new THREE.Matrix4();

var _node = node.isBone === true ? new THREE.Bone() : new THREE.Object3D();

if ( node.name !== undefined ) {

_node.name = THREE.PropertyBinding.sanitizeNodeName( _node.name );
_node.name = THREE.PropertyBinding.sanitizeNodeName( node.name );

}

Expand Down