Files
three.js/src/objects/Bone.js
T
alteredq cf37a8cc43 First integration step: something appeared on the screen ;)
Otherwise things are very much work in progress, expect everything to be broken.
2011-02-16 17:58:19 +01:00

91 lines
1.9 KiB
JavaScript

/**
* @author mikael emtinger / http://gomo.se/
*/
THREE.Bone = function( belongsToSkin ) {
THREE.Object3D.call( this );
this.skin = belongsToSkin;
this.skinMatrix = new THREE.Matrix4();
this.hasNoneBoneChildren = false;
};
THREE.Bone.prototype = new THREE.Object3D();
THREE.Bone.prototype.constructor = THREE.Bone;
THREE.Bone.prototype.supr = THREE.Object3D.prototype;
/*
* Update
*/
THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate, camera, renderer ) {
// update local
if( this.autoUpdateMatrix )
forceUpdate |= this.updateMatrix();
// update skin matrix
if( forceUpdate || this.matrixNeedsToUpdate ) {
if( parentSkinMatrix )
this.skinMatrix.multiply( parentSkinMatrix, this.localMatrix );
else
this.skinMatrix.copy( this.localMatrix );
this.matrixNeedsToUpdate = false;
forceUpdate = true;
}
// update children
if( this.hasNoneBoneChildren ) {
this.globalMatrix.multiply( this.skin.globalMatrix, this.skinMatrix );
for( var i = 0; i < this.children.length; i++ )
if( !( this.children[ i ] instanceof THREE.Bone ))
this.children[ i ].update( this.globalMatrix, true, camera, renderer );
else
this.children[ i ].update( this.skinMatrix, forceUpdate, camera, renderer );
} else {
for( var i = 0; i < this.children.length; i++ )
this.children[ i ].update( this.skinMatrix, forceUpdate, camera, renderer );
}
};
/*
* Add child
*/
THREE.Bone.prototype.addChild = function( child ) {
if( this.children.indexOf( child ) === -1 ) {
if( child.parent !== undefined )
child.parent.removeChild( child );
child.parent = this;
this.children.push( child );
if( !( child instanceof THREE.Bone ))
this.hasNoneBoneChildren = true;
}
};
/*
* Todo: Remove Children: see if any remaining are none-Bone
*/