Hi there,
in Three.js I need to traverse a complete GLTF model to clone it correctly and the Three.js group has kindly provided a method to do that which paste down there. Is that required in ThreeJS dart as well and - assuming the answer is yes - could someone help me convert that code to Dart.
function parallelTraverse( a, b, callback )
{
callback( a, b );
for ( var i = 0; i < a.children.length; i ++ ) {
parallelTraverse( a.children[ i ], b.children[ i ], callback );
}
}
function cloneGTLF( source )
{
var sourceLookup = new Map();
var cloneLookup = new Map();
var clone = source.clone();
parallelTraverse( source, clone, function ( sourceNode, clonedNode ) {
sourceLookup.set( clonedNode, sourceNode );
cloneLookup.set( sourceNode, clonedNode );
} );
clone.traverse( function ( node ) {
if ( ! node.isSkinnedMesh ) return;
var clonedMesh = node;
var sourceMesh = sourceLookup.get( node );
var sourceBones = sourceMesh.skeleton.bones;
clonedMesh.skeleton = sourceMesh.skeleton.clone();
clonedMesh.bindMatrix.copy( sourceMesh.bindMatrix );
clonedMesh.skeleton.bones = sourceBones.map( function ( bone ) {
return cloneLookup.get( bone );
} );
clonedMesh.bind( clonedMesh.skeleton, clonedMesh.bindMatrix );
} );
return clone;
}
Hi there,
in Three.js I need to traverse a complete GLTF model to clone it correctly and the Three.js group has kindly provided a method to do that which paste down there. Is that required in ThreeJS dart as well and - assuming the answer is yes - could someone help me convert that code to Dart.
function parallelTraverse( a, b, callback )
{
callback( a, b );
for ( var i = 0; i < a.children.length; i ++ ) {
parallelTraverse( a.children[ i ], b.children[ i ], callback );
}
}
function cloneGTLF( source )
{
var sourceLookup = new Map();
var cloneLookup = new Map();
var clone = source.clone();
parallelTraverse( source, clone, function ( sourceNode, clonedNode ) {
sourceLookup.set( clonedNode, sourceNode );
cloneLookup.set( sourceNode, clonedNode );
} );
clone.traverse( function ( node ) {
if ( ! node.isSkinnedMesh ) return;
var clonedMesh = node;
var sourceMesh = sourceLookup.get( node );
var sourceBones = sourceMesh.skeleton.bones;
clonedMesh.skeleton = sourceMesh.skeleton.clone();
clonedMesh.bindMatrix.copy( sourceMesh.bindMatrix );
clonedMesh.skeleton.bones = sourceBones.map( function ( bone ) {
return cloneLookup.get( bone );
} );
clonedMesh.bind( clonedMesh.skeleton, clonedMesh.bindMatrix );
} );
return clone;
}