Skip to content

Instantly share code, notes, and snippets.

@satori99
Last active September 1, 2016 23:38
Show Gist options
  • Save satori99/8dceb70686c3fa947591d693688b456f to your computer and use it in GitHub Desktop.
Save satori99/8dceb70686c3fa947591d693688b456f to your computer and use it in GitHub Desktop.
if ( group.userData.bones !== undefined ) {
armature = group
var bones = createBones( armature, group.userData.bones )
armature.updateMatrixWorld()
armature.userData.skeleton = new THREE.Skeleton( bones, undefined, true )
console.debug( 'skeleton', armature.userData.skeleton )
skeletonHelper = new THREE.SkeletonHelper( armature )
skeletonHelper.material.fog = false
// skeletonHelper.layers.set( LAYER.HELPERS )
scene.add( skeletonHelper )
if ( scene.animations && scene.animations.length !== 0 ) {
mixer = armature.userData.mixer = new THREE.AnimationMixer( armature )
console.log( 'mixer', mixer )
const animation = scene.animations ? scene.animations[ 0 ] : null
console.log( 'animation', animation )
action = mixer.clipAction( animation ).play()
console.log( 'action', action )
}
}
======================================
// Copied fropm SkinnedMesh constructor
function createBones ( object, jsonBones ) {
const bones = [];
var bone, gbone;
// create bones from json bone data
for ( var b = 0, bl = jsonBones.length; b < bl; ++ b ) {
gbone = jsonBones[ b ];
bone = new THREE.Bone();
bone.name = gbone.name
bone.position.fromArray( gbone.pos )
bone.quaternion.fromArray( gbone.rotq )
if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
bones.push( bone )
}
// set parent relations
for ( var b = 0, bl = jsonBones.length; b < bl; ++ b ) {
gbone = jsonBones[ b ]
if ( gbone.parent !== -1 && gbone.parent !== null && bones[ gbone.parent ] !== undefined ) {
bones[ gbone.parent ].add( bones[ b ] )
} else {
object.add( bones[ b ] )
}
}
return bones
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment