Created
November 10, 2017 03:21
-
-
Save zellski/be4e9207ab8e70c4e89062d48ce345ba to your computer and use it in GitHub Desktop.
RebindingScene & RebindingSkinnedMesh
This file contains 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
/** | |
* An object that rebinds its skinned meshes when cloned. | |
*/ | |
export class RebindingScene extends THREE.Scene { | |
constructor() { | |
super(); | |
} | |
copy(source :THREE.Scene, recursive :?boolean) :THREE.Object3D { | |
super.copy(source, recursive); | |
var nodes = {}; | |
var skinnedMeshes = []; | |
this.traverse(node => { | |
nodes[node.name] = node; | |
if (node instanceof THREE.SkinnedMesh) { | |
skinnedMeshes.push(node); | |
} | |
}); | |
for (let skinnedMesh of skinnedMeshes) { | |
var skeleton = skinnedMesh.skeleton.clone(); | |
for (var ii = 0; ii < skeleton.bones.length; ii++) { | |
skeleton.bones[ii] = nodes[skeleton.bones[ii].name]; | |
} | |
skinnedMesh.bind(skeleton, skinnedMesh.bindMatrix); | |
} | |
return this; | |
} | |
} | |
/** | |
* A skinned mesh that rebinds on clone. | |
*/ | |
export class RebindingSkinnedMesh extends THREE.SkinnedMesh { | |
constructor( | |
geometry :THREE.Geometry, | |
material :THREE.Material, | |
useVertexTexture :?boolean) { | |
super(geometry, material, useVertexTexture); | |
} | |
copy(source :THREE.SkinnedMesh, recursive :?boolean) :THREE.Object3D { | |
super.copy(source, recursive); | |
this.skeleton = source.skeleton; | |
this.bindMatrix = source.bindMatrix; | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Three.is is frequently used in the world of character animations. I can’t find no functions, no working examples related to the replace of parts of characters. Almost all characters are composed by skinnedMesh children and a lot of time is necessary change a part of the character like clothes, hair, face within characters that have same skeleton without broke animation (ex. Readyplayes characters) Can I use one of this functions to solve this problem? How?