From b7070e2486d652402ec5cb1eb68911e5004cbe75 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Mon, 28 Apr 2014 01:03:34 -0400 Subject: [PATCH] Updated builds. --- build/three.js | 265 +++++++++++++++------------------------------ build/three.min.js | 19 ++-- 2 files changed, 98 insertions(+), 186 deletions(-) diff --git a/build/three.js b/build/three.js index ade182efdf..2bed0cb239 100644 --- a/build/three.js +++ b/build/three.js @@ -31397,129 +31397,25 @@ THREE.ClosedSplineCurve3 = THREE.Curve.create( * @author mikael emtinger / http://gomo.se/ */ -THREE.AnimationHandler = ( function () { +THREE.AnimationHandler = { - var playing = []; - var library = {}; - var that = {}; + LINEAR: 0, + CATMULLROM: 1, + CATMULLROM_FORWARD: 2, - that.update = function ( deltaTimeMS ) { - - for ( var i = 0; i < playing.length; i ++ ) { - - playing[ i ].update( deltaTimeMS ); - - } - - }; - - that.addToUpdate = function ( animation ) { - - if ( playing.indexOf( animation ) === -1 ) { - - playing.push( animation ); - - } - - }; - - that.removeFromUpdate = function ( animation ) { - - var index = playing.indexOf( animation ); - - if ( index !== -1 ) { - - playing.splice( index, 1 ); - - } - - }; - - that.add = function ( data ) { - - if ( library[ data.name ] !== undefined ) { - - console.log( "THREE.AnimationHandler.add: Warning! " + data.name + " already exists in library. Overwriting." ); - - } - - library[ data.name ] = data; - initData( data ); - - }; - - that.remove = function ( name ) { - - if ( library[ name ] === undefined ) { - - console.log( "THREE.AnimationHandler.add: Warning! " + name + " doesn't exists in library. Doing nothing." ); - - } - - library[ name ] = undefined; - - }; - - that.get = function ( name ) { - - if ( typeof name === "string" ) { - - if ( library[ name ] ) { - - return library[ name ]; - - } else { - - return null; - - } - - } else { - - // todo: add simple tween library - - } - - }; - - that.parse = function ( root ) { - - // setup hierarchy - - var hierarchy = []; - - if ( root instanceof THREE.SkinnedMesh ) { - - for ( var b = 0; b < root.skeleton.bones.length; b++ ) { - - hierarchy.push( root.skeleton.bones[ b ] ); - - } - - } else { - - parseRecurseHierarchy( root, hierarchy ); - - } - - return hierarchy; - - }; - - var parseRecurseHierarchy = function ( root, hierarchy ) { - - hierarchy.push( root ); + // - for ( var c = 0; c < root.children.length; c++ ) - parseRecurseHierarchy( root.children[ c ], hierarchy ); + add: function () { console.warn( 'THREE.AnimationHandler.add() has been deprecated.' ); }, + get: function () { console.warn( 'THREE.AnimationHandler.get() has been deprecated.' ); }, + remove: function () { console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' ); }, - } + // - var initData = function ( data ) { + animations: [], - if ( data.initialized === true ) - return; + init: function ( data ) { + if ( data.initialized === true ) return; // loop through all keys @@ -31629,18 +31525,76 @@ THREE.AnimationHandler = ( function () { data.initialized = true; - }; + return data; + }, - // interpolation types + parse: function ( root ) { - that.LINEAR = 0; - that.CATMULLROM = 1; - that.CATMULLROM_FORWARD = 2; + var parseRecurseHierarchy = function ( root, hierarchy ) { - return that; + hierarchy.push( root ); -}() ); + for ( var c = 0; c < root.children.length; c++ ) + parseRecurseHierarchy( root.children[ c ], hierarchy ); + + }; + + // setup hierarchy + + var hierarchy = []; + + if ( root instanceof THREE.SkinnedMesh ) { + + for ( var b = 0; b < root.skeleton.bones.length; b++ ) { + + hierarchy.push( root.skeleton.bones[ b ] ); + + } + + } else { + + parseRecurseHierarchy( root, hierarchy ); + + } + + return hierarchy; + + }, + + play: function ( animation ) { + + if ( this.animations.indexOf( animation ) === -1 ) { + + this.animations.push( animation ); + + } + + }, + + stop: function ( animation ) { + + var index = this.animations.indexOf( animation ); + + if ( index !== -1 ) { + + this.animations.splice( index, 1 ); + + } + + }, + + update: function ( deltaTimeMS ) { + + for ( var i = 0; i < this.animations.length; i ++ ) { + + this.animations[ i ].update( deltaTimeMS ); + + } + + } + +}; /** * @author mikael emtinger / http://gomo.se/ @@ -31648,17 +31602,16 @@ THREE.AnimationHandler = ( function () { * @author alteredq / http://alteredqualia.com/ */ -THREE.Animation = function ( root, name ) { +THREE.Animation = function ( root ) { this.root = root; - this.data = THREE.AnimationHandler.get( name ); + this.data = THREE.AnimationHandler.init( root.geometry.animation ); this.hierarchy = THREE.AnimationHandler.parse( root ); this.currentTime = 0; this.timeScale = 1; this.isPlaying = false; - this.isPaused = true; this.loop = true; this.weight = 0; @@ -31676,28 +31629,10 @@ THREE.Animation.prototype.play = function ( startTime, weight ) { this.weight = weight !== undefined ? weight: 1; this.isPlaying = true; - this.isPaused = false; this.reset(); - THREE.AnimationHandler.addToUpdate( this ); - -}; - - -THREE.Animation.prototype.pause = function() { - - if ( this.isPaused === true ) { - - THREE.AnimationHandler.addToUpdate( this ); - - } else { - - THREE.AnimationHandler.removeFromUpdate( this ); - - } - - this.isPaused = !this.isPaused; + THREE.AnimationHandler.play( this ); }; @@ -31705,8 +31640,8 @@ THREE.Animation.prototype.pause = function() { THREE.Animation.prototype.stop = function() { this.isPlaying = false; - this.isPaused = false; - THREE.AnimationHandler.removeFromUpdate( this ); + + THREE.AnimationHandler.stop( this ); }; @@ -32070,11 +32005,11 @@ THREE.Animation.prototype.getPrevKeyWith = function ( type, h, key ) { * @author erik kitson */ -THREE.KeyFrameAnimation = function ( root, data ) { +THREE.KeyFrameAnimation = function ( data ) { - this.root = root; - this.data = THREE.AnimationHandler.get( data ); - this.hierarchy = THREE.AnimationHandler.parse( root ); + this.root = data.node; + this.data = THREE.AnimationHandler.init( data ); + this.hierarchy = THREE.AnimationHandler.parse( this.root ); this.currentTime = 0; this.timeScale = 0.001; this.isPlaying = false; @@ -32114,7 +32049,6 @@ THREE.KeyFrameAnimation = function ( root, data ) { }; -// Play THREE.KeyFrameAnimation.prototype.play = function ( startTime ) { @@ -32164,39 +32098,17 @@ THREE.KeyFrameAnimation.prototype.play = function ( startTime ) { this.isPaused = false; - THREE.AnimationHandler.addToUpdate( this ); + THREE.AnimationHandler.play( this ); }; - -// Pause - -THREE.KeyFrameAnimation.prototype.pause = function() { - - if( this.isPaused ) { - - THREE.AnimationHandler.addToUpdate( this ); - - } else { - - THREE.AnimationHandler.removeFromUpdate( this ); - - } - - this.isPaused = !this.isPaused; - -}; - - -// Stop - THREE.KeyFrameAnimation.prototype.stop = function() { this.isPlaying = false; this.isPaused = false; - THREE.AnimationHandler.removeFromUpdate( this ); + THREE.AnimationHandler.stop( this ); // reset JIT matrix and remove cache @@ -32366,6 +32278,7 @@ THREE.MorphAnimation.prototype = { pause: function () { this.isPlaying = false; + }, update: ( function () { diff --git a/build/three.min.js b/build/three.min.js index e9bf327e3e..fc4bcb0276 100644 --- a/build/three.min.js +++ b/build/three.min.js @@ -596,12 +596,11 @@ b)+this.b3p1(a,c)+this.b3p2(a,d)+this.b3p3(a,e)}};THREE.LineCurve=function(a,b){ THREE.QuadraticBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.y,this.v1.y,this.v2.y);b=new THREE.Vector2(b,a);b.normalize();return b};THREE.CubicBezierCurve=function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d};THREE.CubicBezierCurve.prototype=Object.create(THREE.Curve.prototype);THREE.CubicBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.Utils.b3(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);a=THREE.Shape.Utils.b3(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);return new THREE.Vector2(b,a)}; THREE.CubicBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.Utils.tangentCubicBezier(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);a=THREE.Curve.Utils.tangentCubicBezier(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);b=new THREE.Vector2(b,a);b.normalize();return b};THREE.SplineCurve=function(a){this.points=void 0==a?[]:a};THREE.SplineCurve.prototype=Object.create(THREE.Curve.prototype);THREE.SplineCurve.prototype.getPoint=function(a){var b=new THREE.Vector2,c=[],d=this.points,e;e=(d.length-1)*a;a=Math.floor(e);e-=a;c[0]=0==a?a:a-1;c[1]=a;c[2]=a>d.length-2?d.length-1:a+1;c[3]=a>d.length-3?d.length-1:a+2;b.x=THREE.Curve.Utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);b.y=THREE.Curve.Utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);return b};THREE.EllipseCurve=function(a,b,c,d,e,f,g){this.aX=a;this.aY=b;this.xRadius=c;this.yRadius=d;this.aStartAngle=e;this.aEndAngle=f;this.aClockwise=g};THREE.EllipseCurve.prototype=Object.create(THREE.Curve.prototype); THREE.EllipseCurve.prototype.getPoint=function(a){var b;b=this.aEndAngle-this.aStartAngle;0>b&&(b+=2*Math.PI);b>2*Math.PI&&(b-=2*Math.PI);b=!0===this.aClockwise?this.aEndAngle+(1-a)*(2*Math.PI-b):this.aStartAngle+a*b;a=this.aX+this.xRadius*Math.cos(b);b=this.aY+this.yRadius*Math.sin(b);return new THREE.Vector2(a,b)};THREE.ArcCurve=function(a,b,c,d,e,f){THREE.EllipseCurve.call(this,a,b,c,c,d,e,f)};THREE.ArcCurve.prototype=Object.create(THREE.EllipseCurve.prototype);THREE.LineCurve3=THREE.Curve.create(function(a,b){this.v1=a;this.v2=b},function(a){var b=new THREE.Vector3;b.subVectors(this.v2,this.v1);b.multiplyScalar(a);b.add(this.v1);return b});THREE.QuadraticBezierCurve3=THREE.Curve.create(function(a,b,c){this.v0=a;this.v1=b;this.v2=c},function(a){var b,c;b=THREE.Shape.Utils.b2(a,this.v0.x,this.v1.x,this.v2.x);c=THREE.Shape.Utils.b2(a,this.v0.y,this.v1.y,this.v2.y);a=THREE.Shape.Utils.b2(a,this.v0.z,this.v1.z,this.v2.z);return new THREE.Vector3(b,c,a)});THREE.CubicBezierCurve3=THREE.Curve.create(function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d},function(a){var b,c;b=THREE.Shape.Utils.b3(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);c=THREE.Shape.Utils.b3(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);a=THREE.Shape.Utils.b3(a,this.v0.z,this.v1.z,this.v2.z,this.v3.z);return new THREE.Vector3(b,c,a)});THREE.SplineCurve3=THREE.Curve.create(function(a){this.points=void 0==a?[]:a},function(a){var b=new THREE.Vector3,c=[],d=this.points,e;a*=d.length-1;e=Math.floor(a);a-=e;c[0]=0==e?e:e-1;c[1]=e;c[2]=e>d.length-2?d.length-1:e+1;c[3]=e>d.length-3?d.length-1:e+2;e=d[c[0]];var f=d[c[1]],g=d[c[2]],c=d[c[3]];b.x=THREE.Curve.Utils.interpolate(e.x,f.x,g.x,c.x,a);b.y=THREE.Curve.Utils.interpolate(e.y,f.y,g.y,c.y,a);b.z=THREE.Curve.Utils.interpolate(e.z,f.z,g.z,c.z,a);return b});THREE.ClosedSplineCurve3=THREE.Curve.create(function(a){this.points=void 0==a?[]:a},function(a){var b=new THREE.Vector3,c=[],d=this.points,e;e=(d.length-0)*a;a=Math.floor(e);e-=a;a+=0a.hierarchy[c].keys[d].time&& -(a.hierarchy[c].keys[d].time=0),void 0!==a.hierarchy[c].keys[d].rot&&!(a.hierarchy[c].keys[d].rot instanceof THREE.Quaternion)){var h=a.hierarchy[c].keys[d].rot;a.hierarchy[c].keys[d].rot=(new THREE.Quaternion).fromArray(h)}if(a.hierarchy[c].keys.length&&void 0!==a.hierarchy[c].keys[0].morphTargets){h={};for(d=0;da.hierarchy[b].keys[c].time&&(a.hierarchy[b].keys[c].time= +0),void 0!==a.hierarchy[b].keys[c].rot&&!(a.hierarchy[b].keys[c].rot instanceof THREE.Quaternion)){var d=a.hierarchy[b].keys[c].rot;a.hierarchy[b].keys[c].rot=(new THREE.Quaternion).fromArray(d)}if(a.hierarchy[b].keys.length&&void 0!==a.hierarchy[b].keys[0].morphTargets){d={};for(c=0;cd;d++){for(var e=this.keyTypes[d],f=this.data.hierarchy[a].keys[0],g=this.getNextKeyWith(e,a,1);g.timef.index;)f=g,g=this.getNextKeyWith(e,a,g.index+1);c.prevKey[e]=f;c.nextKey[e]=g}}}; THREE.Animation.prototype.update=function(){var a=[],b=new THREE.Vector3,c=new THREE.Vector3,d=new THREE.Quaternion,e=function(a,b){var c=[],d=[],e,q,p,s,t,r;e=(a.length-1)*b;q=Math.floor(e);e-=q;c[0]=0===q?q:q-1;c[1]=q;c[2]=q>a.length-2?q:q+1;c[3]=q>a.length-3?q:q+2;q=a[c[0]];s=a[c[1]];t=a[c[2]];r=a[c[3]];c=e*e;p=e*c;d[0]=f(q[0],s[0],t[0],r[0],e,c,p);d[1]=f(q[1],s[1],t[1],r[1],e,c,p);d[2]=f(q[2],s[2],t[2],r[2],e,c,p);return d},f=function(a,b,c,d,e,f,p){a=0.5*(c-a);d=0.5*(d-b);return(2*(b-c)+a+d)* @@ -611,11 +610,11 @@ h.lerp(c,p),l.accumulatedPosWeight+=this.weight);else{if(this.interpolationType= THREE.AnimationHandler.CATMULLROM_FORWARD&&(t=e(a,1.01*t),b.set(t[0],t[1],t[2]),b.sub(h),b.y=0,b.normalize(),h=Math.atan2(b.x,b.z),l.rotation.set(0,h,0))}else"rot"===h?(THREE.Quaternion.slerp(r,v,d,t),l instanceof THREE.Bone?0===l.accumulatedRotWeight?(l.quaternion.copy(d),l.accumulatedRotWeight=this.weight):(p=this.weight/(this.weight+l.accumulatedRotWeight),THREE.Quaternion.slerp(l.quaternion,d,l.quaternion,p),l.accumulatedRotWeight+=this.weight):l.quaternion.copy(d)):"scl"===h&&(h=l.scale,c.x= r[0]+(v[0]-r[0])*t,c.y=r[1]+(v[1]-r[1])*t,c.z=r[2]+(v[2]-r[2])*t,l instanceof THREE.Bone&&(p=this.weight/(this.weight+l.accumulatedSclWeight),h.lerp(c,p),l.accumulatedSclWeight+=this.weight))}return!0}}}(); THREE.Animation.prototype.getNextKeyWith=function(a,b,c){var d=this.data.hierarchy[b].keys;for(c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?ca&&(this.currentTime%=a);this.currentTime=Math.min(this.currentTime,a);a=0;for(var b=this.hierarchy.length;af.index;)f=g,g=e[f.index+1];d.prevKey= f;d.nextKey=g}g.time>=this.currentTime?f.interpolate(g,this.currentTime):f.interpolate(g,g.time);this.data.hierarchy[a].node.updateMatrix();c.matrixWorldNeedsUpdate=!0}}}};THREE.KeyFrameAnimation.prototype.getNextKeyWith=function(a,b,c){b=this.data.hierarchy[b].keys;for(c%=b.length;c