Skip to content

Instantly share code, notes, and snippets.

@zellski
Created November 10, 2017 03:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zellski/be4e9207ab8e70c4e89062d48ce345ba to your computer and use it in GitHub Desktop.
Save zellski/be4e9207ab8e70c4e89062d48ce345ba to your computer and use it in GitHub Desktop.
RebindingScene & RebindingSkinnedMesh
/**
* 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;
}
}
@enricocantori
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment