@@ -83,7 +83,14 @@ Transform.prototype.setMatrix=function(value){
8383}
8484Transform . prototype . isIdentity = function ( ) {
8585 if ( this . _matrixDirty ) {
86- this . getMatrix ( ) ;
86+ if ( this . complexMatrix ) {
87+ this . getMatrix ( ) ;
88+ } else {
89+ return this . position [ 0 ] == 0 && this . position [ 1 ] == 0 &&
90+ this . position [ 2 ] == 0 && this . scale [ 0 ] == 1 &&
91+ this . scale [ 1 ] == 1 && this . scale [ 2 ] == 1 &&
92+ GLMath . quatIsIdentity ( this . rotation ) ;
93+ }
8794 }
8895 return this . _isIdentity ;
8996}
@@ -303,26 +310,35 @@ Transform.prototype.multOrientation=function(angle, v,vy,vz){
303310Transform . prototype . getMatrix = function ( ) {
304311 if ( this . _matrixDirty ) {
305312 this . _matrixDirty = false ;
306- // for best results, multiply in this order:
307- // 1. translation
313+ if ( GLMath . quatIsIdentity ( this . rotation ) ) {
314+ this . matrix = [ this . scale [ 0 ] , 0 , 0 , 0 , 0 ,
315+ this . scale [ 1 ] , 0 , 0 , 0 , 0 ,
316+ this . scale [ 2 ] , 0 ,
317+ this . position [ 0 ] ,
318+ this . position [ 1 ] ,
319+ this . position [ 2 ] , 1 ] ;
320+ this . _isIdentity = ( this . position [ 0 ] == 0 && this . position [ 1 ] == 0 &&
321+ this . position [ 2 ] == 0 && this . scale [ 0 ] == 1 &&
322+ this . scale [ 1 ] == 1 && this . scale [ 2 ] == 1 ) ;
323+ } else {
324+ // for best results, multiply in this order:
325+ // 1. translation
308326 this . matrix = [ 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 ,
309327 this . position [ 0 ] ,
310328 this . position [ 1 ] ,
311329 this . position [ 2 ] , 1 ] ;
312- // 2. rotation
313- if ( ! GLMath . quatIsIdentity ( this . rotation ) ) {
330+ // 2. rotation
314331 this . matrix = GLMath . mat4multiply ( this . matrix ,
315332 GLMath . quatToMat4 ( this . rotation ) ) ;
333+ // 3. scaling
334+ GLMath . mat4scaleInPlace ( this . matrix , this . scale ) ;
335+ this . _isIdentity = (
336+ m [ 0 ] == 1 && m [ 1 ] == 0 && m [ 2 ] == 0 && m [ 3 ] == 0 &&
337+ m [ 4 ] == 0 && m [ 5 ] == 1 && m [ 6 ] == 0 && m [ 7 ] == 0 &&
338+ m [ 8 ] == 0 && m [ 9 ] == 0 && m [ 10 ] == 1 && m [ 11 ] == 0 &&
339+ m [ 12 ] == 0 && m [ 13 ] == 0 && m [ 14 ] == 0 && m [ 15 ] == 1
340+ ) ;
316341 }
317- // 3. scaling
318- GLMath . mat4scaleInPlace ( this . matrix , this . scale ) ;
319- var m = this . matrix
320- this . _isIdentity = (
321- m [ 0 ] == 1 && m [ 1 ] == 0 && m [ 2 ] == 0 && m [ 3 ] == 0 &&
322- m [ 4 ] == 0 && m [ 5 ] == 1 && m [ 6 ] == 0 && m [ 7 ] == 0 &&
323- m [ 8 ] == 0 && m [ 9 ] == 0 && m [ 10 ] == 1 && m [ 11 ] == 0 &&
324- m [ 12 ] == 0 && m [ 13 ] == 0 && m [ 14 ] == 0 && m [ 15 ] == 1
325- ) ;
326342 } else if ( this . _isIdentity ) {
327343 return GLMath . mat4identity ( ) ;
328344 }
0 commit comments