提交 bac513dd 编写于 作者: A alteredq

Merge remote-tracking branch 'remotes/mrdoob/dev' into dev

此差异已折叠。
......@@ -23,7 +23,7 @@ b.copy(this.direction),H=i.matrixWorld,n=H.multiplyVector3(n.copy(h.centroid)).s
e,f,g)&&(h={distance:a.distanceTo(l),point:l.clone(),face:h,object:i},o.push(h));else if(h instanceof THREE.Face4&&(d(l,e,f,j)||d(l,f,g,j)))h={distance:a.distanceTo(l),point:l.clone(),face:h,object:i},o.push(h)}return o};var h=new THREE.Vector3,m=new THREE.Vector3,o=new THREE.Vector3,p,i,q,F,x,I,G,r,C,y,D};
THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,j=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,l,h){j=!1;b=f;c=g;d=l;e=h;a()};this.addPoint=function(f,g){j?(j=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
function(f,g,l,h,m,o){j?(j=!1,b=f<l?f<m?f:m:l<m?l:m,c=g<h?g<o?g:o:h<o?h:o,d=f>l?f>m?f:m:l>m?l:m,e=g>h?g>o?g:o:h>o?h:o):(b=f<l?f<m?f<b?f:b:m<b?m:b:l<m?l<b?l:b:m<b?m:b,c=g<h?g<o?g<c?g:c:o<c?o:c:h<o?h<c?h:c:o<c?o:c,d=f>l?f>m?f>d?f:d:m>d?m:d:l>m?l>d?l:d:m>d?m:d,e=g>h?g>o?g>e?g:e:o>e?o:e:h>o?h>e?h:e:o>e?o:e);a()};this.addRectangle=function(f){j?(j=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){j=!0;e=d=c=b=0;a()};this.isEmpty=function(){return j}};
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){if(d<a.getLeft())return!1;if(b>a.getRight())return!1;if(e<a.getTop())return!1;if(c>a.getBottom())return!1;return!0};this.empty=function(){j=!0;e=d=c=b=0;a()};this.isEmpty=function(){return j}};
THREE.Math={clamp:function(a,b,c){return a<b?b:a>c?c:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())}};THREE.Matrix3=function(){this.m=[]};
THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
THREE.Matrix4=function(a,b,c,d,e,f,g,j,n,k,l,h,m,o,p,i){this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,j||0,n||0,k||0,l!==void 0?l:1,h||0,m||0,o||0,p||0,i!==void 0?i:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
......
......@@ -23,7 +23,7 @@ b.copy(this.direction),q=k.matrixWorld,l=q.multiplyVector3(l.copy(m.centroid)).s
e,f,g)&&(m={distance:a.distanceTo(j),point:j.clone(),face:m,object:k},n.push(m));else if(m instanceof THREE.Face4&&(d(j,e,f,h)||d(j,f,g,h)))m={distance:a.distanceTo(j),point:j.clone(),face:m,object:k},n.push(m)}return n};var k=new THREE.Vector3,m=new THREE.Vector3,n=new THREE.Vector3,p,o,r,C,t,B,D,q,y,u,w};
THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,j,k){h=!1;b=f;c=g;d=j;e=k;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
function(f,g,j,k,m,n){h?(h=!1,b=f<j?f<m?f:m:j<m?j:m,c=g<k?g<n?g:n:k<n?k:n,d=f>j?f>m?f:m:j>m?j:m,e=g>k?g>n?g:n:k>n?k:n):(b=f<j?f<m?f<b?f:b:m<b?m:b:j<m?j<b?j:b:m<b?m:b,c=g<k?g<n?g<c?g:c:n<c?n:c:k<n?k<c?k:c:n<c?n:c,d=f>j?f>m?f>d?f:d:m>d?m:d:j>m?j>d?j:d:m>d?m:d,e=g>k?g>n?g>e?g:e:n>e?n:e:k>n?k>e?k:e:n>e?n:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){if(d<a.getLeft())return!1;if(b>a.getRight())return!1;if(e<a.getTop())return!1;if(c>a.getBottom())return!1;return!0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
THREE.Math={clamp:function(a,b,c){return a<b?b:a>c?c:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())}};THREE.Matrix3=function(){this.m=[]};
THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
THREE.Matrix4=function(a,b,c,d,e,f,g,h,l,i,j,k,m,n,p,o){this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,h||0,l||0,i||0,j!==void 0?j:1,k||0,m||0,n||0,p||0,o!==void 0?o:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -23,7 +23,7 @@ b.copy(this.direction),t=j.matrixWorld,l=t.multiplyVector3(l.copy(m.centroid)).s
e,f,g)&&(m={distance:a.distanceTo(k),point:k.clone(),face:m,object:j},n.push(m));else if(m instanceof THREE.Face4&&(d(k,e,f,h)||d(k,f,g,h)))m={distance:a.distanceTo(k),point:k.clone(),face:m,object:j},n.push(m)}return n};var j=new THREE.Vector3,n=new THREE.Vector3,m=new THREE.Vector3,o,p,u,F,v,D,s,t,B,x,y};
THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,k,j){h=!1;b=f;c=g;d=k;e=j;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
function(f,g,k,j,n,m){h?(h=!1,b=f<k?f<n?f:n:k<n?k:n,c=g<j?g<m?g:m:j<m?j:m,d=f>k?f>n?f:n:k>n?k:n,e=g>j?g>m?g:m:j>m?j:m):(b=f<k?f<n?f<b?f:b:n<b?n:b:k<n?k<b?k:b:n<b?n:b,c=g<j?g<m?g<c?g:c:m<c?m:c:j<m?j<c?j:c:m<c?m:c,d=f>k?f>n?f>d?f:d:n>d?n:d:k>n?k>d?k:d:n>d?n:d,e=g>j?g>m?g>e?g:e:m>e?m:e:j>m?j>e?j:e:m>e?m:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){if(d<a.getLeft())return!1;if(b>a.getRight())return!1;if(e<a.getTop())return!1;if(c>a.getBottom())return!1;return!0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
THREE.Math={clamp:function(a,b,c){return a<b?b:a>c?c:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())}};THREE.Matrix3=function(){this.m=[]};
THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
THREE.Matrix4=function(a,b,c,d,e,f,g,h,l,i,k,j,n,m,o,p){this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,h||0,l||0,i||0,k!==void 0?k:1,j||0,n||0,m||0,o||0,p!==void 0?p:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
......
......@@ -23,7 +23,7 @@ b.copy(this.direction),I=n.matrixWorld,l=I.multiplyVector3(l.copy(w.centroid)).s
f,g,h)&&(w={distance:a.distanceTo(j),point:j.clone(),face:w,object:n},p.push(w));else if(w instanceof THREE.Face4&&(c(j,f,g,i)||c(j,g,h,i)))w={distance:a.distanceTo(j),point:j.clone(),face:w,object:n},p.push(w)}return p};var p=new THREE.Vector3,s=new THREE.Vector3,w=new THREE.Vector3,n,E,y,J,P,Q,V,C,D,N,O};
THREE.Rectangle=function(){function a(){g=c-b;h=f-d}var b,d,c,f,g,h,i=!0;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return g};this.getHeight=function(){return h};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return c};this.getBottom=function(){return f};this.set=function(g,h,j,p){i=!1;b=g;d=h;c=j;f=p;a()};this.addPoint=function(g,h){i?(i=!1,b=g,d=h,c=g,f=h):(b=b<g?b:g,d=d<h?d:h,c=c>g?c:g,f=f>h?f:h);a()};this.add3Points=
function(g,h,j,p,s,w){i?(i=!1,b=g<j?g<s?g:s:j<s?j:s,d=h<p?h<w?h:w:p<w?p:w,c=g>j?g>s?g:s:j>s?j:s,f=h>p?h>w?h:w:p>w?p:w):(b=g<j?g<s?g<b?g:b:s<b?s:b:j<s?j<b?j:b:s<b?s:b,d=h<p?h<w?h<d?h:d:w<d?w:d:p<w?p<d?p:d:w<d?w:d,c=g>j?g>s?g>c?g:c:s>c?s:c:j>s?j>c?j:c:s>c?s:c,f=h>p?h>w?h>f?h:f:w>f?w:f:p>w?p>f?p:f:w>f?w:f);a()};this.addRectangle=function(g){i?(i=!1,b=g.getLeft(),d=g.getTop(),c=g.getRight(),f=g.getBottom()):(b=b<g.getLeft()?b:g.getLeft(),d=d<g.getTop()?d:g.getTop(),c=c>g.getRight()?c:g.getRight(),f=f>
g.getBottom()?f:g.getBottom());a()};this.inflate=function(g){b-=g;d-=g;c+=g;f+=g;a()};this.minSelf=function(g){b=b>g.getLeft()?b:g.getLeft();d=d>g.getTop()?d:g.getTop();c=c<g.getRight()?c:g.getRight();f=f<g.getBottom()?f:g.getBottom();a()};this.intersects=function(a){return Math.min(c,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(f,a.getBottom())-Math.max(d,a.getTop())>=0};this.empty=function(){i=!0;f=c=d=b=0;a()};this.isEmpty=function(){return i}};
g.getBottom()?f:g.getBottom());a()};this.inflate=function(g){b-=g;d-=g;c+=g;f+=g;a()};this.minSelf=function(g){b=b>g.getLeft()?b:g.getLeft();d=d>g.getTop()?d:g.getTop();c=c<g.getRight()?c:g.getRight();f=f<g.getBottom()?f:g.getBottom();a()};this.intersects=function(a){if(c<a.getLeft())return!1;if(b>a.getRight())return!1;if(f<a.getTop())return!1;if(d>a.getBottom())return!1;return!0};this.empty=function(){i=!0;f=c=d=b=0;a()};this.isEmpty=function(){return i}};
THREE.Math={clamp:function(a,b,d){return a<b?b:a>d?d:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,d,c,f){return c+(a-b)*(f-c)/(d-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())}};THREE.Matrix3=function(){this.m=[]};
THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
THREE.Matrix4=function(a,b,d,c,f,g,h,i,l,k,j,p,s,w,n,E){this.set(a!==void 0?a:1,b||0,d||0,c||0,f||0,g!==void 0?g:1,h||0,i||0,l||0,k||0,j!==void 0?j:1,p||0,s||0,w||0,n||0,E!==void 0?E:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
......
......@@ -165,8 +165,14 @@ THREE.Rectangle = function () {
this.intersects = function ( r ) {
return Math.min( _right, r.getRight() ) - Math.max( _left, r.getLeft() ) >= 0 &&
Math.min( _bottom, r.getBottom() ) - Math.max( _top, r.getTop() ) >= 0;
// http://gamemath.com/2011/09/detecting-whether-two-boxes-overlap/
if ( _right < r.getLeft() ) return false;
if ( _left > r.getRight() ) return false;
if ( _bottom < r.getTop() ) return false;
if ( _top > r.getBottom() ) return false;
return true;
};
......
......@@ -5,12 +5,14 @@
THREE.ImageUtils = {
crossOrigin: '',
loadTexture: function ( path, mapping, callback ) {
var image = new Image(), texture = new THREE.Texture( image, mapping );
image.onload = function () { texture.needsUpdate = true; if ( callback ) callback( this ); };
image.crossOrigin = '';
image.crossOrigin = this.crossOrigin;
image.src = path;
return texture;
......
......@@ -10,7 +10,7 @@ THREE.Animation = function( root, data, interpolationType, JITCompile ) {
this.data = THREE.AnimationHandler.get( data );
this.hierarchy = THREE.AnimationHandler.parse( root );
this.currentTime = 0;
this.timeScale = 0.001;
this.timeScale = 1;
this.isPlaying = false;
this.isPaused = true;
this.loop = true;
......@@ -20,37 +20,6 @@ THREE.Animation = function( root, data, interpolationType, JITCompile ) {
this.points = [];
this.target = new THREE.Vector3();
// initialize to first keyframes
for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
var keys = this.data.hierarchy[h].keys,
sids = this.data.hierarchy[h].sids,
obj = this.hierarchy[h];
if ( keys.length ) {
for ( var s = 0; s < sids.length; s++ ) {
var sid = sids[ s ],
next = this.getNextKeyWith( sid, h, 0 );
if ( next ) {
next.apply( sid );
}
}
obj.matrixAutoUpdate = false;
this.data.hierarchy[h].node.updateMatrix();
obj.matrixWorldNeedsUpdate = true;
}
}
};
// Play
......@@ -62,21 +31,16 @@ THREE.Animation.prototype.play = function( loop, startTimeMS ) {
this.isPlaying = true;
this.loop = loop !== undefined ? loop : true;
this.currentTime = startTimeMS !== undefined ? startTimeMS : 0;
this.startTimeMs = startTimeMS;
this.startTime = 10000000;
this.endTime = -this.startTime;
// reset key cache
var h, hl = this.hierarchy.length,
object,
node;
object;
for ( h = 0; h < hl; h++ ) {
object = this.hierarchy[ h ];
node = this.data.hierarchy[ h ];
if ( this.interpolationType !== THREE.AnimationHandler.CATMULLROM_FORWARD ) {
......@@ -84,26 +48,27 @@ THREE.Animation.prototype.play = function( loop, startTimeMS ) {
}
if ( node.animationCache === undefined ) {
node.animationCache = {};
node.animationCache.prevKey = null;
node.animationCache.nextKey = null;
node.animationCache.originalMatrix = object instanceof THREE.Bone ? object.skinMatrix : object.matrix;
object.matrixAutoUpdate = true;
}
if ( object.animationCache === undefined ) {
var keys = this.data.hierarchy[h].keys;
object.animationCache = {};
object.animationCache.prevKey = { pos: 0, rot: 0, scl: 0 };
object.animationCache.nextKey = { pos: 0, rot: 0, scl: 0 };
object.animationCache.originalMatrix = object instanceof THREE.Bone ? object.skinMatrix : object.matrix;
if (keys.length) {
}
node.animationCache.prevKey = keys[ 0 ];
node.animationCache.nextKey = keys[ 1 ];
var prevKey = object.animationCache.prevKey;
var nextKey = object.animationCache.nextKey;
this.startTime = Math.min( keys[0].time, this.startTime );
this.endTime = Math.max( keys[keys.length - 1].time, this.endTime );
prevKey.pos = this.data.hierarchy[ h ].keys[ 0 ];
prevKey.rot = this.data.hierarchy[ h ].keys[ 0 ];
prevKey.scl = this.data.hierarchy[ h ].keys[ 0 ];
}
nextKey.pos = this.getNextKeyWith( "pos", h, 1 );
nextKey.rot = this.getNextKeyWith( "rot", h, 1 );
nextKey.scl = this.getNextKeyWith( "scl", h, 1 );
}
......@@ -151,25 +116,20 @@ THREE.Animation.prototype.stop = function() {
for ( var h = 0; h < this.hierarchy.length; h++ ) {
var obj = this.hierarchy[ h ];
if ( obj.animationCache !== undefined ) {
if ( this.hierarchy[ h ].animationCache !== undefined ) {
var original = obj.animationCache.originalMatrix;
if( this.hierarchy[ h ] instanceof THREE.Bone ) {
if( obj instanceof THREE.Bone ) {
original.copy( obj.skinMatrix );
obj.skinMatrix = original;
this.hierarchy[ h ].skinMatrix = this.hierarchy[ h ].animationCache.originalMatrix;
} else {
original.copy( obj.matrix );
obj.matrix = original;
this.hierarchy[ h ].matrix = this.hierarchy[ h ].animationCache.originalMatrix;
}
delete obj.animationCache;
delete this.hierarchy[ h ].animationCache;
}
......@@ -189,13 +149,18 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
// vars
var types = [ "pos", "rot", "scl" ];
var type;
var scale;
var vector;
var prevXYZ, nextXYZ;
var prevKey, nextKey;
var object;
var node;
var animationCache;
var frame;
var JIThierarchy = this.data.JIT.hierarchy;
var currentTime, unloopedCurrentTime;
var looped;
var currentPoint, forwardPoint, angle;
// update
......@@ -204,70 +169,15 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
unloopedCurrentTime = this.currentTime;
currentTime = this.currentTime = this.currentTime % this.data.length;
// if looped around, the current time should be based on the startTime
if ( currentTime < this.startTimeMs ) {
currentTime = this.currentTime = this.startTimeMs + currentTime;
}
frame = parseInt( Math.min( currentTime * this.data.fps, this.data.length * this.data.fps ), 10 );
looped = currentTime < unloopedCurrentTime;
if ( looped && !this.loop ) {
// Set the animation to the last keyframes and stop
for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
var keys = this.data.hierarchy[h].keys,
sids = this.data.hierarchy[h].sids,
end = keys.length-1,
obj = this.hierarchy[h];
if ( keys.length ) {
for ( var s = 0; s < sids.length; s++ ) {
var sid = sids[ s ],
prev = this.getPrevKeyWith( sid, h, end );
if ( prev ) {
prev.apply( sid );
}
}
this.data.hierarchy[h].node.updateMatrix();
obj.matrixWorldNeedsUpdate = true;
}
}
this.stop();
return;
}
// check pre-infinity
if ( currentTime < this.startTime ) {
return;
}
// update
for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
object = this.hierarchy[ h ];
node = this.data.hierarchy[ h ];
var keys = node.keys,
animationCache = node.animationCache;
animationCache = object.animationCache;
// use JIT?
......@@ -276,39 +186,49 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
if( object instanceof THREE.Bone ) {
object.skinMatrix = JIThierarchy[ h ][ frame ];
object.matrixAutoUpdate = false;
object.matrixWorldNeedsUpdate = false;
} else {
object.matrix = JIThierarchy[ h ][ frame ];
object.matrixAutoUpdate = false;
object.matrixWorldNeedsUpdate = true;
}
// use interpolation
} else if ( keys.length ) {
} else {
// make sure so original matrix and not JIT matrix is set
if ( this.JITCompile && animationCache ) {
if ( this.JITCompile ) {
if( object instanceof THREE.Bone ) {
object.skinMatrix = animationCache.originalMatrix;
object.skinMatrix = object.animationCache.originalMatrix;
} else {
object.matrix = animationCache.originalMatrix;
object.matrix = object.animationCache.originalMatrix;
}
}
prevKey = animationCache.prevKey;
nextKey = animationCache.nextKey;
if ( prevKey && nextKey ) {
// loop through pos/rot/scl
for ( var t = 0; t < 3; t++ ) {
// get keys
type = types[ t ];
prevKey = animationCache.prevKey[ type ];
nextKey = animationCache.nextKey[ type ];
// switch keys?
......@@ -316,42 +236,120 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
// did we loop?
if ( looped && this.loop ) {
if ( currentTime < unloopedCurrentTime ) {
prevKey = keys[ 0 ];
nextKey = keys[ 1 ];
if ( this.loop ) {
while ( nextKey.time < currentTime ) {
prevKey = this.data.hierarchy[ h ].keys[ 0 ];
nextKey = this.getNextKeyWith( type, h, 1 );
prevKey = nextKey;
nextKey = keys[ prevKey.index + 1 ];
while( nextKey.time < currentTime ) {
}
prevKey = nextKey;
nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
}
} else {
this.stop();
return;
} else if ( !looped ) {
}
var lastIndex = keys.length - 1;
} else {
while ( nextKey.time < currentTime && nextKey.index !== lastIndex ) {
do {
prevKey = nextKey;
nextKey = keys[ prevKey.index + 1 ];
nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
}
} while( nextKey.time < currentTime )
}
animationCache.prevKey = prevKey;
animationCache.nextKey = nextKey;
animationCache.prevKey[ type ] = prevKey;
animationCache.nextKey[ type ] = nextKey;
}
prevKey.interpolate( nextKey, currentTime );
}
object.matrixAutoUpdate = true;
object.matrixWorldNeedsUpdate = true;
scale = ( currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
prevXYZ = prevKey[ type ];
nextXYZ = nextKey[ type ];
// check scale error
if ( scale < 0 || scale > 1 ) {
console.log( "THREE.Animation.update: Warning! Scale out of bounds:" + scale + " on bone " + h );
scale = scale < 0 ? 0 : 1;
}
// interpolate
if ( type === "pos" ) {
this.data.hierarchy[h].node.updateMatrix();
object.matrixWorldNeedsUpdate = true;
vector = object.position;
if( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
vector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
vector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
vector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
} else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
this.points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
this.points[ 1 ] = prevXYZ;
this.points[ 2 ] = nextXYZ;
this.points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
scale = scale * 0.33 + 0.33;
currentPoint = this.interpolateCatmullRom( this.points, scale );
vector.x = currentPoint[ 0 ];
vector.y = currentPoint[ 1 ];
vector.z = currentPoint[ 2 ];
if( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
forwardPoint = this.interpolateCatmullRom( this.points, scale * 1.01 );
this.target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
this.target.subSelf( vector );
this.target.y = 0;
this.target.normalize();
angle = Math.atan2( this.target.x, this.target.z );
object.rotation.set( 0, angle, 0 );
}
}
} else if ( type === "rot" ) {
THREE.Quaternion.slerp( prevXYZ, nextXYZ, object.quaternion, scale );
} else if( type === "scl" ) {
vector = object.scale;
vector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
vector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
vector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
}
}
}
......@@ -431,7 +429,7 @@ THREE.Animation.prototype.interpolate = function( p0, p1, p2, p3, t, t2, t3 ) {
// Get next key with
THREE.Animation.prototype.getNextKeyWith = function( sid, h, key ) {
THREE.Animation.prototype.getNextKeyWith = function( type, h, key ) {
var keys = this.data.hierarchy[ h ].keys;
......@@ -448,7 +446,7 @@ THREE.Animation.prototype.getNextKeyWith = function( sid, h, key ) {
for ( ; key < keys.length; key++ ) {
if ( keys[ key ].hasTarget( sid ) ) {
if ( keys[ key ][ type ] !== undefined ) {
return keys[ key ];
......@@ -456,13 +454,13 @@ THREE.Animation.prototype.getNextKeyWith = function( sid, h, key ) {
}
return keys[ 0 ];
return this.data.hierarchy[ h ].keys[ 0 ];
};
// Get previous key with
THREE.Animation.prototype.getPrevKeyWith = function( sid, h, key ) {
THREE.Animation.prototype.getPrevKeyWith = function( type, h, key ) {
var keys = this.data.hierarchy[ h ].keys;
......@@ -480,7 +478,7 @@ THREE.Animation.prototype.getPrevKeyWith = function( sid, h, key ) {
for ( ; key >= 0; key-- ) {
if ( keys[ key ].hasTarget( sid ) ) {
if ( keys[ key ][ type ] !== undefined ) {
return keys[ key ];
......@@ -488,6 +486,6 @@ THREE.Animation.prototype.getPrevKeyWith = function( sid, h, key ) {
}
return keys[ keys.length - 1 ];
return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
};
};
\ No newline at end of file
/**
* @author mikael emtinger / http://gomo.se/
* @author mrdoob / http://mrdoob.com/
* @author alteredq / http://alteredqualia.com/
* @author khang duong
* @author erik kitson
*/
THREE.KeyFrameAnimation = function( root, data, JITCompile ) {
this.root = root;
this.data = THREE.AnimationHandler.get( data );
this.hierarchy = THREE.AnimationHandler.parse( root );
this.currentTime = 0;
this.timeScale = 0.001;
this.isPlaying = false;
this.isPaused = true;
this.loop = true;
this.JITCompile = JITCompile !== undefined ? JITCompile : true;
// initialize to first keyframes
for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
var keys = this.data.hierarchy[h].keys,
sids = this.data.hierarchy[h].sids,
obj = this.hierarchy[h];
if ( keys.length && sids ) {
for ( var s = 0; s < sids.length; s++ ) {
var sid = sids[ s ],
next = this.getNextKeyWith( sid, h, 0 );
if ( next ) {
next.apply( sid );
}
}
obj.matrixAutoUpdate = false;
this.data.hierarchy[h].node.updateMatrix();
obj.matrixWorldNeedsUpdate = true;
}
}
};
// Play
THREE.KeyFrameAnimation.prototype.play = function( loop, startTimeMS ) {
if( !this.isPlaying ) {
this.isPlaying = true;
this.loop = loop !== undefined ? loop : true;
this.currentTime = startTimeMS !== undefined ? startTimeMS : 0;
this.startTimeMs = startTimeMS;
this.startTime = 10000000;
this.endTime = -this.startTime;
// reset key cache
var h, hl = this.hierarchy.length,
object,
node;
for ( h = 0; h < hl; h++ ) {
object = this.hierarchy[ h ];
node = this.data.hierarchy[ h ];
object.useQuaternion = true;
if ( node.animationCache === undefined ) {
node.animationCache = {};
node.animationCache.prevKey = null;
node.animationCache.nextKey = null;
node.animationCache.originalMatrix = object instanceof THREE.Bone ? object.skinMatrix : object.matrix;
}
var keys = this.data.hierarchy[h].keys;
if (keys.length) {
node.animationCache.prevKey = keys[ 0 ];
node.animationCache.nextKey = keys[ 1 ];
this.startTime = Math.min( keys[0].time, this.startTime );
this.endTime = Math.max( keys[keys.length - 1].time, this.endTime );
}
}
this.update( 0 );
}
this.isPaused = false;
THREE.AnimationHandler.addToUpdate( 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 );
// reset JIT matrix and remove cache
for ( var h = 0; h < this.hierarchy.length; h++ ) {
var obj = this.hierarchy[ h ];
if ( obj.animationCache !== undefined ) {
var original = obj.animationCache.originalMatrix;
if( obj instanceof THREE.Bone ) {
original.copy( obj.skinMatrix );
obj.skinMatrix = original;
} else {
original.copy( obj.matrix );
obj.matrix = original;
}
delete obj.animationCache;
}
}
};
// Update
THREE.KeyFrameAnimation.prototype.update = function( deltaTimeMS ) {
// early out
if( !this.isPlaying ) return;
// vars
var prevKey, nextKey;
var object;
var node;
var frame;
var JIThierarchy = this.data.JIT.hierarchy;
var currentTime, unloopedCurrentTime;
var looped;
// update
this.currentTime += deltaTimeMS * this.timeScale;
unloopedCurrentTime = this.currentTime;
currentTime = this.currentTime = this.currentTime % this.data.length;
// if looped around, the current time should be based on the startTime
if ( currentTime < this.startTimeMs ) {
currentTime = this.currentTime = this.startTimeMs + currentTime;
}
frame = parseInt( Math.min( currentTime * this.data.fps, this.data.length * this.data.fps ), 10 );
looped = currentTime < unloopedCurrentTime;
if ( looped && !this.loop ) {
// Set the animation to the last keyframes and stop
for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
var keys = this.data.hierarchy[h].keys,
sids = this.data.hierarchy[h].sids,
end = keys.length-1,
obj = this.hierarchy[h];
if ( keys.length ) {
for ( var s = 0; s < sids.length; s++ ) {
var sid = sids[ s ],
prev = this.getPrevKeyWith( sid, h, end );
if ( prev ) {
prev.apply( sid );
}
}
this.data.hierarchy[h].node.updateMatrix();
obj.matrixWorldNeedsUpdate = true;
}
}
this.stop();
return;
}
// check pre-infinity
if ( currentTime < this.startTime ) {
return;
}
// update
for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
object = this.hierarchy[ h ];
node = this.data.hierarchy[ h ];
var keys = node.keys,
animationCache = node.animationCache;
// use JIT?
if ( this.JITCompile && JIThierarchy[ h ][ frame ] !== undefined ) {
if( object instanceof THREE.Bone ) {
object.skinMatrix = JIThierarchy[ h ][ frame ];
object.matrixWorldNeedsUpdate = false;
} else {
object.matrix = JIThierarchy[ h ][ frame ];
object.matrixWorldNeedsUpdate = true;
}
// use interpolation
} else if ( keys.length ) {
// make sure so original matrix and not JIT matrix is set
if ( this.JITCompile && animationCache ) {
if( object instanceof THREE.Bone ) {
object.skinMatrix = animationCache.originalMatrix;
} else {
object.matrix = animationCache.originalMatrix;
}
}
prevKey = animationCache.prevKey;
nextKey = animationCache.nextKey;
if ( prevKey && nextKey ) {
// switch keys?
if ( nextKey.time <= unloopedCurrentTime ) {
// did we loop?
if ( looped && this.loop ) {
prevKey = keys[ 0 ];
nextKey = keys[ 1 ];
while ( nextKey.time < currentTime ) {
prevKey = nextKey;
nextKey = keys[ prevKey.index + 1 ];
}
} else if ( !looped ) {
var lastIndex = keys.length - 1;
while ( nextKey.time < currentTime && nextKey.index !== lastIndex ) {
prevKey = nextKey;
nextKey = keys[ prevKey.index + 1 ];
}
}
animationCache.prevKey = prevKey;
animationCache.nextKey = nextKey;
}
prevKey.interpolate( nextKey, currentTime );
}
this.data.hierarchy[h].node.updateMatrix();
object.matrixWorldNeedsUpdate = true;
}
}
// update JIT?
if ( this.JITCompile ) {
if ( JIThierarchy[ 0 ][ frame ] === undefined ) {
this.hierarchy[ 0 ].updateMatrixWorld( true );
for ( var h = 0; h < this.hierarchy.length; h++ ) {
if( this.hierarchy[ h ] instanceof THREE.Bone ) {
JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].skinMatrix.clone();
} else {
JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].matrix.clone();
}
}
}
}
};
// Get next key with
THREE.KeyFrameAnimation.prototype.getNextKeyWith = function( sid, h, key ) {
var keys = this.data.hierarchy[ h ].keys;
key = key % keys.length;
for ( ; key < keys.length; key++ ) {
if ( keys[ key ].hasTarget( sid ) ) {
return keys[ key ];
}
}
return keys[ 0 ];
};
// Get previous key with
THREE.KeyFrameAnimation.prototype.getPrevKeyWith = function( sid, h, key ) {
var keys = this.data.hierarchy[ h ].keys;
key = key >= 0 ? key : key + keys.length;
for ( ; key >= 0; key-- ) {
if ( keys[ key ].hasTarget( sid ) ) {
return keys[ key ];
}
}
return keys[ keys.length - 1 ];
};
......@@ -17,6 +17,8 @@ THREE.Loader.prototype = {
constructor: THREE.Loader,
crossOrigin: '',
addStatusElement: function () {
var e = document.createElement( "div" );
......@@ -95,6 +97,8 @@ THREE.Loader.prototype = {
createMaterial: function ( m, texture_path ) {
var _this = this;
function is_pow2( n ) {
var l = Math.log( n ) / Math.LN2;
......@@ -132,7 +136,7 @@ THREE.Loader.prototype = {
where.needsUpdate = true;
};
image.crossOrigin = '';
image.crossOrigin = _this.crossOrigin;
image.src = url;
}
......@@ -153,17 +157,17 @@ THREE.Loader.prototype = {
}
if( offset ) {
if ( offset ) {
where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
}
if( wrap ) {
if ( wrap ) {
var wrapMap = {
"repeat" : THREE.RepeatWrapping,
"mirror" : THREE.MirroredRepeatWrapping
"repeat" : THREE.RepeatWrapping,
"mirror" : THREE.MirroredRepeatWrapping
}
if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
......@@ -369,4 +373,4 @@ THREE.Loader.prototype = {
}
};
};
\ No newline at end of file
......@@ -98,6 +98,7 @@ EXTRAS_FILES = [
'extras/core/TextPath.js',
'extras/animation/AnimationHandler.js',
'extras/animation/Animation.js',
'extras/animation/KeyFrameAnimation.js',
'extras/cameras/CubeCamera.js',
'extras/cameras/FirstPersonCamera.js',
'extras/cameras/PathCamera.js',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册