clone static method
dynamic
clone(
- dynamic source
Implementation
static clone(source) {
var sourceLookup = new Map();
var cloneLookup = new Map();
var clone = source.clone();
parallelTraverse(source, clone, (sourceNode, clonedNode) {
// sourceLookup.set( clonedNode, sourceNode );
// cloneLookup.set( sourceNode, clonedNode );
sourceLookup[clonedNode] = sourceNode;
cloneLookup[sourceNode] = clonedNode;
});
clone.traverse((node) {
if (!node.runtimeType.toString().contains("SkinnedMesh")) return;
var clonedMesh = node;
var sourceMesh = sourceLookup[node];
var sourceBones = sourceMesh.skeleton.bones;
clonedMesh.skeleton = sourceMesh.skeleton.clone();
clonedMesh.bindMatrix.copy(sourceMesh.bindMatrix);
clonedMesh.skeleton.bones = List<Bone>.from(sourceBones.map((bone) {
return cloneLookup[bone];
}).toList());
clonedMesh.bind(clonedMesh.skeleton, clonedMesh.bindMatrix);
});
return clone;
}