Untitled diff

Creado El diff nunca expira
12 eliminaciones
1013 líneas
83 adiciones
1021 líneas
/**
/**
* @author mrdoob / http://mrdoob.com/
* @author mrdoob / http://mrdoob.com/
* @author zz85 / http://joshuakoo.com/
* @author zz85 / http://joshuakoo.com/
* @author yomboprime / https://yombo.org
* @author yomboprime / https://yombo.org
*/
*/


THREE.SVGLoader = function ( manager ) {
THREE.SVGLoader = function ( manager ) {


this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;


};
};


THREE.SVGLoader.prototype = {
THREE.SVGLoader.prototype = {


constructor: THREE.SVGLoader,
constructor: THREE.SVGLoader,


load: function ( url, onLoad, onProgress, onError ) {
load: function ( url, onLoad, onProgress, onError ) {


var scope = this;
var scope = this;


var loader = new THREE.FileLoader( scope.manager );
var loader = new THREE.FileLoader( scope.manager );
loader.setPath( scope.path );
loader.setPath( scope.path );
loader.load( url, function ( text ) {
loader.load( url, function ( text ) {


onLoad( scope.parse( text ) );
onLoad( scope.parse( text ) );


}, onProgress, onError );
}, onProgress, onError );


},
},


setPath: function ( value ) {
setPath: function ( value ) {


this.path = value;
this.path = value;
return this;
return this;


},
},


parse: function ( text ) {
parse: function ( text ) {


function parseNode( node, style ) {
function parseNode( node, style ) {


if ( node.nodeType !== 1 ) return;
if ( node.nodeType !== 1 ) return;


var transform = getNodeTransform( node );
var transforms = getNodeTransform( node );

var i = 0;
do {
var path = null;
var path = null;


switch ( node.nodeName ) {
switch ( node.nodeName ) {


case 'svg':
case 'svg':
break;
break;


case 'g':
case 'g':
style = parseStyle( node, style );
style = parseStyle( node, style );
break;
break;


case 'path':
case 'path':
style = parseStyle( node, style );
style = parseStyle( node, style );
if ( node.hasAttribute( 'd' ) && isVisible( style ) ) path = parsePathNode( node, style );
if ( node.hasAttribute( 'd' ) && isVisible( style ) ) path = parsePathNode( node, style );
break;
break;


case 'rect':
case 'rect':
style = parseStyle( node, style );
style = parseStyle( node, style );
if ( isVisible( style ) ) path = parseRectNode( node, style );
if ( isVisible( style ) ) path = parseRectNode( node, style );
break;
break;


case 'polygon':
case 'polygon':
style = parseStyle( node, style );
style = parseStyle( node, style );
if ( isVisible( style ) ) path = parsePolygonNode( node, style );
if ( isVisible( style ) ) path = parsePolygonNode( node, style );
break;
break;


case 'polyline':
case 'polyline':
style = parseStyle( node, style );
style = parseStyle( node, style );
if ( isVisible( style ) ) path = parsePolylineNode( node, style );
if ( isVisible( style ) ) path = parsePolylineNode( node, style );
break;
break;


case 'circle':
case 'circle':
style = parseStyle( node, style );
style = parseStyle( node, style );
if ( isVisible( style ) ) path = parseCircleNode( node, style );
if ( isVisible( style ) ) path = parseCircleNode( node, style );
break;
break;


case 'ellipse':
case 'ellipse':
style = parseStyle( node, style );
style = parseStyle( node, style );
if ( isVisible( style ) ) path = parseEllipseNode( node, style );
if ( isVisible( style ) ) path = parseEllipseNode( node, style );
break;
break;


case 'line':
case 'line':
style = parseStyle( node, style );
style = parseStyle( node, style );
if ( isVisible( style ) ) path = parseLineNode( node, style );
if ( isVisible( style ) ) path = parseLineNode( node, style );
break;
break;


default:
default:
console.log( node );
console.log( node );


}
}


if ( path ) {
if ( path ) {


transformPath( path, currentTransform );
transformPath( path, currentTransform );


paths.push( path );
paths.push( path );


}
}


var nodes = node.childNodes;
var nodes = node.childNodes;


for ( var i = 0; i < nodes.length; i ++ ) {
for ( var i = 0; i < nodes.length; i ++ ) {


parseNode( nodes[ i ], style );
parseNode( nodes[ i ], style );


}
}


if ( transform ) {
if ( transforms ) {

transform = transforms[i];
currentTransform.copy( transformStack.pop() );
currentTransform.copy( transformStack.pop() );

}
i++;
}
}

while (transforms && i < transforms.length)
}
}


function parsePathNode( node, style ) {
function parsePathNode( node, style ) {


var path = new THREE.ShapePath();
var path = new THREE.ShapePath();
path.color.setStyle( style.fill );
path.color.setStyle( style.fill );


var point = new THREE.Vector2();
var point = new THREE.Vector2();
var control = new THREE.Vector2();
var control = new THREE.Vector2();


var firstPoint = new THREE.Vector2();
var firstPoint = new THREE.Vector2();
var isFirstPoint = true;
var isFirstPoint = true;