提交 3e784651 编写于 作者: Y yomboprime

SVG Loader: Accept multiple transforms in a single node

上级 8b5da8c4
...@@ -756,138 +756,158 @@ THREE.SVGLoader.prototype = { ...@@ -756,138 +756,158 @@ THREE.SVGLoader.prototype = {
function parseTransformNode( node ) { function parseTransformNode( node ) {
var transformAttr = node.getAttribute( 'transform' );
var transform = null; var transform = null;
var openParPos = transformAttr.indexOf( "(" ); var transformsTexts = node.getAttribute( 'transform' ).split( ' ' );
var closeParPos = transformAttr.indexOf( ")" );
for ( var tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex-- ) {
if ( openParPos > 0 && openParPos < closeParPos ) { var newTransform = null;
var transformType = transformAttr.substr( 0, openParPos ); var transformText = transformsTexts[ tIndex ];
var openParPos = transformText.indexOf( "(" );
var closeParPos = transformText.indexOf( ")" );
var array = parseFloats( transformAttr.substr( openParPos + 1, closeParPos - openParPos - 1 ) ); if ( openParPos > 0 && openParPos < closeParPos ) {
switch ( transformType ) { var transformType = transformText.substr( 0, openParPos );
case "translate": var array = parseFloats( transformText.substr( openParPos + 1, closeParPos - openParPos - 1 ) );
if ( array.length >= 1 ) { switch ( transformType ) {
transform = new THREE.Matrix3(); case "translate":
var tx = array[ 0 ]; if ( array.length >= 1 ) {
var ty = tx;
if ( array.length >= 2 ) { newTransform = new THREE.Matrix3();
ty = array[ 1 ]; var tx = array[ 0 ];
var ty = tx;
if ( array.length >= 2 ) {
ty = array[ 1 ];
}
newTransform.translate( tx, ty );
} }
transform.translate( tx, ty ); break;
} case "rotate":
break; if ( array.length >= 1 ) {
case "rotate": var angle = 0;
var cx = 0;
var cy = 0;
if ( array.length >= 1 ) { newTransform = new THREE.Matrix3();
var angle = 0; // Angle
var cx = 0; angle = - array[ 0 ] * Math.PI / 180;
var cy = 0;
transform = new THREE.Matrix3(); if ( array.length >= 3 ) {
// Angle // Center x, y
angle = - array[ 0 ] * Math.PI / 180; cx = array[ 1 ];
cy = array[ 2 ];
if ( array.length >= 3 ) { }
// Center x, y // Rotate around center (cx, cy)
cx = array[ 1 ]; tempTransform1.identity().translate( -cx, -cy );
cy = array[ 2 ]; tempTransform2.identity().rotate( angle );
tempTransform3.multiplyMatrices( tempTransform2, tempTransform1 );
tempTransform1.identity().translate( cx, cy );
newTransform.multiplyMatrices( tempTransform1, tempTransform3 );
} }
// Rotate around center (cx, cy) break;
tempTransform1.identity().translate( -cx, -cy );
tempTransform2.identity().rotate( angle );
tempTransform3.multiplyMatrices( tempTransform2, tempTransform1 );
tempTransform1.identity().translate( cx, cy );
transform.multiplyMatrices( tempTransform1, tempTransform3 );
} case "scale":
break; if ( array.length >= 1 ) {
case "scale": newTransform = new THREE.Matrix3();
if ( array.length >= 1 ) { var scaleX = array[ 0 ];
var scaleY = scaleX;
transform = new THREE.Matrix3(); if ( array.length >= 2 ) {
scaleY = array[ 1 ];
}
var scaleX = array[ 0 ]; newTransform.scale( scaleX, scaleY );
var scaleY = scaleX;
if ( array.length >= 2 ) {
scaleY = array[ 1 ];
} }
transform.scale( scaleX, scaleY ); break;
} case "skewX":
break; if ( array.length === 1 ) {
case "skewX": newTransform = new THREE.Matrix3();
if ( array.length === 1 ) { newTransform.set(
1, Math.tan( array[ 0 ] * Math.PI / 180 ), 0,
0, 1, 0,
0, 0, 1
);
transform = new THREE.Matrix3(); }
transform.set( break;
1, Math.tan( array[ 0 ] * Math.PI / 180 ), 0,
0, 1, 0,
0, 0, 1
);
} case "skewY":
break; if ( array.length === 1 ) {
case "skewY": newTransform = new THREE.Matrix3();
if ( array.length === 1 ) { newTransform.set(
1, 0, 0,
Math.tan( array[ 0 ] * Math.PI / 180 ), 1, 0,
0, 0, 1
);
transform = new THREE.Matrix3(); }
transform.set( break;
1, 0, 0,
Math.tan( array[ 0 ] * Math.PI / 180 ), 1, 0,
0, 0, 1
);
} case "matrix":
break; if ( array.length === 6 ) {
case "matrix": newTransform = new THREE.Matrix3();
if ( array.length === 6 ) { newTransform.set(
array[ 0 ], array[ 2 ], array[ 4 ],
array[ 1 ], array[ 3 ], array[ 5 ],
0, 0, 1
);
transform = new THREE.Matrix3(); }
transform.set( break;
array[ 0 ], array[ 2 ], array[ 4 ], }
array[ 1 ], array[ 3 ], array[ 5 ],
0, 0, 1
);
} }
if ( newTransform ) {
if ( transform ) {
newTransform.multiply( transform );
}
transform = newTransform;
break;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册