@@ -756,140 +756,139 @@ THREE.SVGLoader.prototype = {
756756
757757 function parseTransformNode ( node ) {
758758
759- var transformAttr = node . getAttribute ( 'transform' ) ;
760- var transform = null ;
761- var openParPos = transformAttr . indexOf ( "(" ) ;
762- var closeParPos = transformAttr . indexOf ( ")" ) ;
759+ var transform = new THREE . Matrix3 ( ) ;
760+ var currentTransform = tempTransform0 ;
761+ var transformsTexts = node . getAttribute ( 'transform' ) . split ( ' ' ) ;
762+
763+ for ( var tIndex = transformsTexts . length - 1 ; tIndex >= 0 ; tIndex -- ) {
763764
764- if ( openParPos > 0 && openParPos < closeParPos ) {
765+ var transformText = transformsTexts [ tIndex ] ;
766+ var openParPos = transformText . indexOf ( "(" ) ;
767+ var closeParPos = transformText . indexOf ( ")" ) ;
765768
766- var transformType = transformAttr . substr ( 0 , openParPos ) ;
769+ if ( openParPos > 0 && openParPos < closeParPos ) {
767770
768- var array = parseFloats ( transformAttr . substr ( openParPos + 1 , closeParPos - openParPos - 1 ) ) ;
771+ var transformType = transformText . substr ( 0 , openParPos ) ;
769772
770- switch ( transformType ) {
773+ var array = parseFloats ( transformText . substr ( openParPos + 1 , closeParPos - openParPos - 1 ) ) ;
774+
775+ currentTransform . identity ( ) ;
771776
772- case "translate" :
777+ switch ( transformType ) {
773778
774- if ( array . length >= 1 ) {
779+ case "translate" :
775780
776- transform = new THREE . Matrix3 ( ) ;
781+ if ( array . length >= 1 ) {
777782
778- var tx = array [ 0 ] ;
779- var ty = tx ;
783+ var tx = array [ 0 ] ;
784+ var ty = tx ;
780785
781- if ( array . length >= 2 ) {
786+ if ( array . length >= 2 ) {
782787
783- ty = array [ 1 ] ;
788+ ty = array [ 1 ] ;
784789
785- }
790+ }
786791
787- transform . translate ( tx , ty ) ;
792+ currentTransform . translate ( tx , ty ) ;
788793
789- }
794+ }
790795
791- break ;
796+ break ;
792797
793- case "rotate" :
798+ case "rotate" :
794799
795- if ( array . length >= 1 ) {
800+ if ( array . length >= 1 ) {
796801
797- var angle = 0 ;
798- var cx = 0 ;
799- var cy = 0 ;
802+ var angle = 0 ;
803+ var cx = 0 ;
804+ var cy = 0 ;
800805
801- transform = new THREE . Matrix3 ( ) ;
806+ // Angle
807+ angle = - array [ 0 ] * Math . PI / 180 ;
802808
803- // Angle
804- angle = - array [ 0 ] * Math . PI / 180 ;
809+ if ( array . length >= 3 ) {
805810
806- if ( array . length >= 3 ) {
811+ // Center x, y
812+ cx = array [ 1 ] ;
813+ cy = array [ 2 ] ;
807814
808- // Center x, y
809- cx = array [ 1 ] ;
810- cy = array [ 2 ] ;
815+ }
811816
812- }
817+ // Rotate around center (cx, cy)
818+ tempTransform1 . identity ( ) . translate ( - cx , - cy ) ;
819+ tempTransform2 . identity ( ) . rotate ( angle ) ;
820+ tempTransform3 . multiplyMatrices ( tempTransform2 , tempTransform1 ) ;
821+ tempTransform1 . identity ( ) . translate ( cx , cy ) ;
822+ currentTransform . multiplyMatrices ( tempTransform1 , tempTransform3 ) ;
813823
814- // Rotate around center (cx, cy)
815- tempTransform1 . identity ( ) . translate ( - cx , - cy ) ;
816- tempTransform2 . identity ( ) . rotate ( angle ) ;
817- tempTransform3 . multiplyMatrices ( tempTransform2 , tempTransform1 ) ;
818- tempTransform1 . identity ( ) . translate ( cx , cy ) ;
819- transform . multiplyMatrices ( tempTransform1 , tempTransform3 ) ;
824+ }
820825
821- }
826+ break ;
822827
823- break ;
828+ case "scale" :
824829
825- case "scale" :
830+ if ( array . length >= 1 ) {
826831
827- if ( array . length >= 1 ) {
832+ var scaleX = array [ 0 ] ;
833+ var scaleY = scaleX ;
828834
829- transform = new THREE . Matrix3 ( ) ;
835+ if ( array . length >= 2 ) {
836+ scaleY = array [ 1 ] ;
837+ }
830838
831- var scaleX = array [ 0 ] ;
832- var scaleY = scaleX ;
839+ currentTransform . scale ( scaleX , scaleY ) ;
833840
834- if ( array . length >= 2 ) {
835- scaleY = array [ 1 ] ;
836841 }
837842
838- transform . scale ( scaleX , scaleY ) ;
839-
840- }
841-
842- break ;
843-
844- case "skewX" :
845-
846- if ( array . length === 1 ) {
843+ break ;
847844
848- transform = new THREE . Matrix3 ( ) ;
845+ case "skewX" :
849846
850- transform . set (
851- 1 , Math . tan ( array [ 0 ] * Math . PI / 180 ) , 0 ,
852- 0 , 1 , 0 ,
853- 0 , 0 , 1
854- ) ;
847+ if ( array . length === 1 ) {
855848
856- }
849+ currentTransform . set (
850+ 1 , Math . tan ( array [ 0 ] * Math . PI / 180 ) , 0 ,
851+ 0 , 1 , 0 ,
852+ 0 , 0 , 1
853+ ) ;
857854
858- break ;
855+ }
859856
860- case "skewY" :
857+ break ;
861858
862- if ( array . length === 1 ) {
859+ case "skewY" :
863860
864- transform = new THREE . Matrix3 ( ) ;
861+ if ( array . length === 1 ) {
865862
866- transform . set (
867- 1 , 0 , 0 ,
868- Math . tan ( array [ 0 ] * Math . PI / 180 ) , 1 , 0 ,
869- 0 , 0 , 1
870- ) ;
863+ currentTransform . set (
864+ 1 , 0 , 0 ,
865+ Math . tan ( array [ 0 ] * Math . PI / 180 ) , 1 , 0 ,
866+ 0 , 0 , 1
867+ ) ;
871868
872- }
869+ }
873870
874- break ;
871+ break ;
875872
876- case "matrix" :
873+ case "matrix" :
877874
878- if ( array . length === 6 ) {
875+ if ( array . length === 6 ) {
879876
880- transform = new THREE . Matrix3 ( ) ;
877+ currentTransform . set (
878+ array [ 0 ] , array [ 2 ] , array [ 4 ] ,
879+ array [ 1 ] , array [ 3 ] , array [ 5 ] ,
880+ 0 , 0 , 1
881+ ) ;
881882
882- transform . set (
883- array [ 0 ] , array [ 2 ] , array [ 4 ] ,
884- array [ 1 ] , array [ 3 ] , array [ 5 ] ,
885- 0 , 0 , 1
886- ) ;
883+ }
887884
888- }
885+ break ;
886+ }
889887
890- break ;
891888 }
892889
890+ transform . premultiply ( currentTransform ) ;
891+
893892 }
894893
895894 return transform ;
@@ -984,6 +983,7 @@ THREE.SVGLoader.prototype = {
984983
985984 var transformStack = [ ] ;
986985
986+ var tempTransform0 = new THREE . Matrix3 ( ) ;
987987 var tempTransform1 = new THREE . Matrix3 ( ) ;
988988 var tempTransform2 = new THREE . Matrix3 ( ) ;
989989 var tempTransform3 = new THREE . Matrix3 ( ) ;
0 commit comments