Created
August 2, 2022 02:13
-
-
Save valentincognito/82e1f258f9b9b7b927e678c37cc39f2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cloneSkinnedMesh(){ | |
const skinnedMeshes = {} | |
this.original.traverse( child => { | |
if(child.isSkinnedMesh){ | |
skinnedMeshes[child.name] = child | |
} | |
}) | |
const cloneBones = {} | |
const cloneSkinnedMeshes = {} | |
this.clone.traverse( node => { | |
if ( node.isBone) { | |
cloneBones[node.name] = node | |
} | |
if ( node.isSkinnedMesh) { | |
cloneSkinnedMeshes[node.name] = node | |
} | |
}) | |
for (let name in skinnedMeshes) { | |
const skinnedMesh = skinnedMeshes[name] | |
const skeleton = skinnedMesh.skeleton | |
const cloneSkinnedMesh = cloneSkinnedMeshes[name] | |
cloneSkinnedMesh.name = "skinnedMesh."+this.name | |
const orderedCloneBones = [] | |
for (let i = 0; i < skeleton.bones.length; i++) { | |
const cloneBone = cloneBones[skeleton.bones[i].name] | |
orderedCloneBones.push(cloneBone) | |
} | |
cloneSkinnedMesh.bind( | |
new THREE.Skeleton(orderedCloneBones, skeleton.boneInverses), | |
cloneSkinnedMesh.matrixWorld | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment