提交 67e34fe5 编写于 作者: M Mr.doob

Clean up and updated builds.

上级 f85d5043
......@@ -13553,119 +13553,140 @@ THREE.SkinnedMesh.prototype.addBone = function( bone ) {
};
THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) {
THREE.SkinnedMesh.prototype.updateMatrixWorld = function () {
this.matrixAutoUpdate && this.updateMatrix();
var offsetMatrix = new THREE.Matrix4();
// update matrixWorld
return function ( force ) {
if ( this.matrixWorldNeedsUpdate || force ) {
this.matrixAutoUpdate && this.updateMatrix();
if ( this.parent ) {
// update matrixWorld
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
if ( this.matrixWorldNeedsUpdate || force ) {
} else {
if ( this.parent ) {
this.matrixWorld.copy( this.matrix );
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
}
} else {
this.matrixWorldNeedsUpdate = false;
this.matrixWorld.copy( this.matrix );
force = true;
}
}
this.matrixWorldNeedsUpdate = false;
// update children
force = true;
for ( var i = 0, l = this.children.length; i < l; i ++ ) {
}
var child = this.children[ i ];
// update children
if ( child instanceof THREE.Bone ) {
for ( var i = 0, l = this.children.length; i < l; i ++ ) {
child.update( this.identityMatrix, false );
var child = this.children[ i ];
} else {
if ( child instanceof THREE.Bone ) {
child.update( this.identityMatrix, false );
} else {
child.updateMatrixWorld( true );
child.updateMatrixWorld( true );
}
}
}
// make a snapshot of the bones' rest position
// make a snapshot of the bones' rest position
if ( this.boneInverses == undefined ) {
if ( this.boneInverses == undefined ) {
this.boneInverses = [];
this.boneInverses = [];
for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
var inverse = new THREE.Matrix4();
var inverse = new THREE.Matrix4();
inverse.getInverse( this.bones[ b ].skinMatrix );
inverse.getInverse( this.bones[ b ].skinMatrix );
this.boneInverses.push( inverse );
this.boneInverses.push( inverse );
}
}
}
// flatten bone matrices to array
// flatten bone matrices to array
for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
// compute the offset between the current and the original transform;
// compute the offset between the current and the original transform;
//TODO: we could get rid of this multiplication step if the skinMatrix
// was already representing the offset; however, this requires some
// major changes to the animation system
// TODO: we could get rid of this multiplication step if the skinMatrix
// was already representing the offset; however, this requires some
// major changes to the animation system
THREE.SkinnedMesh.offsetMatrix.multiplyMatrices( this.bones[ b ].skinMatrix, this.boneInverses[ b ] );
offsetMatrix.multiplyMatrices( this.bones[ b ].skinMatrix, this.boneInverses[ b ] );
offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
THREE.SkinnedMesh.offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
}
}
if ( this.useVertexTexture ) {
if ( this.useVertexTexture ) {
this.boneTexture.needsUpdate = true;
this.boneTexture.needsUpdate = true;
}
}
};
};
}();
THREE.SkinnedMesh.prototype.pose = function () {
this.updateMatrixWorld( true );
for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
this.normalizeSkinWeights();
// normalize weights
};
var sw = this.geometry.skinWeights[ i ];
THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
var scale = 1.0 / sw.lengthManhattan();
if ( this.geometry instanceof THREE.Geometry ) {
if ( scale !== Infinity ) {
for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
sw.multiplyScalar( scale );
var sw = this.geometry.skinWeights[ i ];
} else {
var scale = 1.0 / sw.lengthManhattan();
if ( scale !== Infinity ) {
sw.set( 1 ); // this will be normalized by the shader anyway
sw.multiplyScalar( scale );
} else {
sw.set( 1 ); // this will be normalized by the shader anyway
}
}
} else {
// skinning weights assumed to be normalized for THREE.BufferGeometry
}
};
THREE.SkinnedMesh.prototype.clone = function ( object ) {
if ( object === undefined ) object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
if ( object === undefined ) {
object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
}
THREE.Mesh.prototype.clone.call( this, object );
......@@ -13673,8 +13694,6 @@ THREE.SkinnedMesh.prototype.clone = function ( object ) {
};
THREE.SkinnedMesh.offsetMatrix = new THREE.Matrix4();
/**
* @author alteredq / http://alteredqualia.com/
*/
......
......@@ -274,9 +274,9 @@ THREE.Mesh.prototype.updateMorphTargets=function(){if(0<this.geometry.morphTarge
THREE.Mesh.prototype.getMorphTargetIndexByName=function(a){if(void 0!==this.morphTargetDictionary[a])return this.morphTargetDictionary[a];console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+a+" does not exist. Returning 0.");return 0};THREE.Mesh.prototype.clone=function(a){void 0===a&&(a=new THREE.Mesh(this.geometry,this.material));THREE.Object3D.prototype.clone.call(this,a);return a};THREE.Bone=function(a){THREE.Object3D.call(this);this.skin=a;this.skinMatrix=new THREE.Matrix4};THREE.Bone.prototype=Object.create(THREE.Object3D.prototype);THREE.Bone.prototype.update=function(a,b){this.matrixAutoUpdate&&(b|=this.updateMatrix());if(b||this.matrixWorldNeedsUpdate)a?this.skinMatrix.multiplyMatrices(a,this.matrix):this.skinMatrix.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,b=!0;var c,d=this.children.length;for(c=0;c<d;c++)this.children[c].update(this.skinMatrix,b)};THREE.SkinnedMesh=function(a,b,c){THREE.Mesh.call(this,a,b);this.useVertexTexture=void 0!==c?c:!0;this.identityMatrix=new THREE.Matrix4;this.bones=[];this.boneMatrices=[];var d,e,f;if(this.geometry&&void 0!==this.geometry.bones){for(a=0;a<this.geometry.bones.length;a++)c=this.geometry.bones[a],d=c.pos,e=c.rotq,f=c.scl,b=this.addBone(),b.name=c.name,b.position.set(d[0],d[1],d[2]),b.quaternion.set(e[0],e[1],e[2],e[3]),b.useQuaternion=!0,void 0!==f?b.scale.set(f[0],f[1],f[2]):b.scale.set(1,1,1);for(a=
0;a<this.bones.length;a++)c=this.geometry.bones[a],b=this.bones[a],-1===c.parent?this.add(b):this.bones[c.parent].add(b);a=this.bones.length;this.useVertexTexture?(this.boneTextureHeight=this.boneTextureWidth=a=256<a?64:64<a?32:16<a?16:8,this.boneMatrices=new Float32Array(4*this.boneTextureWidth*this.boneTextureHeight),this.boneTexture=new THREE.DataTexture(this.boneMatrices,this.boneTextureWidth,this.boneTextureHeight,THREE.RGBAFormat,THREE.FloatType),this.boneTexture.minFilter=THREE.NearestFilter,
this.boneTexture.magFilter=THREE.NearestFilter,this.boneTexture.generateMipmaps=!1,this.boneTexture.flipY=!1):this.boneMatrices=new Float32Array(16*a);this.pose()}};THREE.SkinnedMesh.prototype=Object.create(THREE.Mesh.prototype);THREE.SkinnedMesh.prototype.addBone=function(a){void 0===a&&(a=new THREE.Bone(this));this.bones.push(a);return a};
THREE.SkinnedMesh.prototype.updateMatrixWorld=function(a){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||a)this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1;for(var a=0,b=this.children.length;a<b;a++){var c=this.children[a];c instanceof THREE.Bone?c.update(this.identityMatrix,!1):c.updateMatrixWorld(!0)}if(void 0==this.boneInverses){this.boneInverses=[];a=0;for(b=this.bones.length;a<
b;a++)c=new THREE.Matrix4,c.getInverse(this.bones[a].skinMatrix),this.boneInverses.push(c)}a=0;for(b=this.bones.length;a<b;a++)THREE.SkinnedMesh.offsetMatrix.multiplyMatrices(this.bones[a].skinMatrix,this.boneInverses[a]),THREE.SkinnedMesh.offsetMatrix.flattenToArrayOffset(this.boneMatrices,16*a);this.useVertexTexture&&(this.boneTexture.needsUpdate=!0)};
THREE.SkinnedMesh.prototype.pose=function(){this.updateMatrixWorld(!0);for(var a=0;a<this.geometry.skinIndices.length;a++){var b=this.geometry.skinWeights[a],c=1/b.lengthManhattan();Infinity!==c?b.multiplyScalar(c):b.set(1)}};THREE.SkinnedMesh.prototype.clone=function(a){void 0===a&&(a=new THREE.SkinnedMesh(this.geometry,this.material,this.useVertexTexture));THREE.Mesh.prototype.clone.call(this,a);return a};THREE.SkinnedMesh.offsetMatrix=new THREE.Matrix4;THREE.MorphAnimMesh=function(a,b){THREE.Mesh.call(this,a,b);this.duration=1E3;this.mirroredLoop=!1;this.currentKeyframe=this.lastKeyframe=this.time=0;this.direction=1;this.directionBackwards=!1;this.setFrameRange(0,this.geometry.morphTargets.length-1)};THREE.MorphAnimMesh.prototype=Object.create(THREE.Mesh.prototype);THREE.MorphAnimMesh.prototype.setFrameRange=function(a,b){this.startKeyframe=a;this.endKeyframe=b;this.length=this.endKeyframe-this.startKeyframe+1};
THREE.SkinnedMesh.prototype.updateMatrixWorld=function(){var a=new THREE.Matrix4;return function(b){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1;for(var b=0,c=this.children.length;b<c;b++){var d=this.children[b];d instanceof THREE.Bone?d.update(this.identityMatrix,!1):d.updateMatrixWorld(!0)}if(void 0==this.boneInverses){this.boneInverses=
[];b=0;for(c=this.bones.length;b<c;b++)d=new THREE.Matrix4,d.getInverse(this.bones[b].skinMatrix),this.boneInverses.push(d)}b=0;for(c=this.bones.length;b<c;b++)a.multiplyMatrices(this.bones[b].skinMatrix,this.boneInverses[b]),a.flattenToArrayOffset(this.boneMatrices,16*b);this.useVertexTexture&&(this.boneTexture.needsUpdate=!0)}}();THREE.SkinnedMesh.prototype.pose=function(){this.updateMatrixWorld(!0);this.normalizeSkinWeights()};
THREE.SkinnedMesh.prototype.normalizeSkinWeights=function(){if(this.geometry instanceof THREE.Geometry)for(var a=0;a<this.geometry.skinIndices.length;a++){var b=this.geometry.skinWeights[a],c=1/b.lengthManhattan();Infinity!==c?b.multiplyScalar(c):b.set(1)}};THREE.SkinnedMesh.prototype.clone=function(a){void 0===a&&(a=new THREE.SkinnedMesh(this.geometry,this.material,this.useVertexTexture));THREE.Mesh.prototype.clone.call(this,a);return a};THREE.MorphAnimMesh=function(a,b){THREE.Mesh.call(this,a,b);this.duration=1E3;this.mirroredLoop=!1;this.currentKeyframe=this.lastKeyframe=this.time=0;this.direction=1;this.directionBackwards=!1;this.setFrameRange(0,this.geometry.morphTargets.length-1)};THREE.MorphAnimMesh.prototype=Object.create(THREE.Mesh.prototype);THREE.MorphAnimMesh.prototype.setFrameRange=function(a,b){this.startKeyframe=a;this.endKeyframe=b;this.length=this.endKeyframe-this.startKeyframe+1};
THREE.MorphAnimMesh.prototype.setDirectionForward=function(){this.direction=1;this.directionBackwards=!1};THREE.MorphAnimMesh.prototype.setDirectionBackward=function(){this.direction=-1;this.directionBackwards=!0};
THREE.MorphAnimMesh.prototype.parseAnimations=function(){var a=this.geometry;a.animations||(a.animations={});for(var b,c=a.animations,d=/([a-z]+)(\d+)/,e=0,f=a.morphTargets.length;e<f;e++){var h=a.morphTargets[e].name.match(d);if(h&&1<h.length){h=h[1];c[h]||(c[h]={start:Infinity,end:-Infinity});var g=c[h];e<g.start&&(g.start=e);e>g.end&&(g.end=e);b||(b=h)}}a.firstAnimation=b};
THREE.MorphAnimMesh.prototype.setAnimationLabel=function(a,b,c){this.geometry.animations||(this.geometry.animations={});this.geometry.animations[a]={start:b,end:c}};THREE.MorphAnimMesh.prototype.playAnimation=function(a,b){var c=this.geometry.animations[a];c?(this.setFrameRange(c.start,c.end),this.duration=1E3*((c.end-c.start)/b),this.time=0):console.warn("animation["+a+"] undefined")};
......
......@@ -128,89 +128,94 @@ THREE.SkinnedMesh.prototype.addBone = function( bone ) {
};
THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) {
THREE.SkinnedMesh.prototype.updateMatrixWorld = function () {
this.matrixAutoUpdate && this.updateMatrix();
var offsetMatrix = new THREE.Matrix4();
// update matrixWorld
return function ( force ) {
if ( this.matrixWorldNeedsUpdate || force ) {
this.matrixAutoUpdate && this.updateMatrix();
if ( this.parent ) {
// update matrixWorld
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
if ( this.matrixWorldNeedsUpdate || force ) {
} else {
if ( this.parent ) {
this.matrixWorld.copy( this.matrix );
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
}
} else {
this.matrixWorldNeedsUpdate = false;
this.matrixWorld.copy( this.matrix );
force = true;
}
}
this.matrixWorldNeedsUpdate = false;
// update children
force = true;
for ( var i = 0, l = this.children.length; i < l; i ++ ) {
}
var child = this.children[ i ];
// update children
if ( child instanceof THREE.Bone ) {
for ( var i = 0, l = this.children.length; i < l; i ++ ) {
child.update( this.identityMatrix, false );
var child = this.children[ i ];
} else {
if ( child instanceof THREE.Bone ) {
child.updateMatrixWorld( true );
child.update( this.identityMatrix, false );
} else {
child.updateMatrixWorld( true );
}
}
}
// make a snapshot of the bones' rest position
// make a snapshot of the bones' rest position
if ( this.boneInverses == undefined ) {
if ( this.boneInverses == undefined ) {
this.boneInverses = [];
this.boneInverses = [];
for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
var inverse = new THREE.Matrix4();
var inverse = new THREE.Matrix4();
inverse.getInverse( this.bones[ b ].skinMatrix );
inverse.getInverse( this.bones[ b ].skinMatrix );
this.boneInverses.push( inverse );
this.boneInverses.push( inverse );
}
}
}
// flatten bone matrices to array
// flatten bone matrices to array
for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
// compute the offset between the current and the original transform;
// compute the offset between the current and the original transform;
//TODO: we could get rid of this multiplication step if the skinMatrix
// was already representing the offset; however, this requires some
// major changes to the animation system
// TODO: we could get rid of this multiplication step if the skinMatrix
// was already representing the offset; however, this requires some
// major changes to the animation system
THREE.SkinnedMesh.offsetMatrix.multiplyMatrices( this.bones[ b ].skinMatrix, this.boneInverses[ b ] );
offsetMatrix.multiplyMatrices( this.bones[ b ].skinMatrix, this.boneInverses[ b ] );
offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
THREE.SkinnedMesh.offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
}
}
if ( this.useVertexTexture ) {
if ( this.useVertexTexture ) {
this.boneTexture.needsUpdate = true;
this.boneTexture.needsUpdate = true;
}
}
};
};
}();
THREE.SkinnedMesh.prototype.pose = function () {
......@@ -222,7 +227,7 @@ THREE.SkinnedMesh.prototype.pose = function () {
THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
if (this.geometry instanceof THREE.Geometry) {
if ( this.geometry instanceof THREE.Geometry ) {
for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
......@@ -252,12 +257,14 @@ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
THREE.SkinnedMesh.prototype.clone = function ( object ) {
if ( object === undefined ) object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
if ( object === undefined ) {
object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
}
THREE.Mesh.prototype.clone.call( this, object );
return object;
};
THREE.SkinnedMesh.offsetMatrix = new THREE.Matrix4();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册