@@ -38,36 +38,42 @@ THREE.SVGLoader.prototype = {
3838 break ;
3939
4040 case 'g' :
41- parseStyle ( node , style ) ;
41+ style = parseStyle ( node , style ) ;
4242 break ;
4343
4444 case 'path' :
45- parseStyle ( node , style ) ;
46- paths . push ( parsePathNode ( node , style ) ) ;
45+ style = parseStyle ( node , style ) ;
46+ if ( style . fill !== 'none' ) paths . push ( parsePathNode ( node , style ) ) ;
4747 break ;
4848
4949 case 'rect' :
50- paths . push ( parseRectNode ( node , style ) ) ;
50+ style = parseStyle ( node , style ) ;
51+ if ( style . fill !== 'none' ) paths . push ( parseRectNode ( node , style ) ) ;
5152 break ;
5253
5354 case 'polygon' :
54- paths . push ( parsePolygonNode ( node , style ) ) ;
55+ style = parseStyle ( node , style ) ;
56+ if ( style . fill !== 'none' ) paths . push ( parsePolygonNode ( node , style ) ) ;
5557 break ;
5658
5759 case 'polyline' :
58- paths . push ( parsePolylineNode ( node , style ) ) ;
60+ style = parseStyle ( node , style ) ;
61+ if ( style . fill !== 'none' ) paths . push ( parsePolylineNode ( node , style ) ) ;
5962 break ;
6063
6164 case 'circle' :
62- paths . push ( parseCircleNode ( node , style ) ) ;
65+ style = parseStyle ( node , style ) ;
66+ if ( style . fill !== 'none' ) paths . push ( parseCircleNode ( node , style ) ) ;
6367 break ;
6468
6569 case 'ellipse' :
66- paths . push ( parseEllipseNode ( node , style ) ) ;
70+ style = parseStyle ( node , style ) ;
71+ if ( style . fill !== 'none' ) paths . push ( parseEllipseNode ( node , style ) ) ;
6772 break ;
6873
6974 case 'line' :
70- paths . push ( parseLineNode ( node , style ) ) ;
75+ style = parseStyle ( node , style ) ;
76+ if ( style . fill !== 'none' ) paths . push ( parseLineNode ( node , style ) ) ;
7177 break ;
7278
7379 default :
@@ -88,7 +94,7 @@ THREE.SVGLoader.prototype = {
8894 function parsePathNode ( node , style ) {
8995
9096 var path = new THREE . ShapePath ( ) ;
91- path . color . setStyle ( parseFill ( node , style ) ) ;
97+ path . color . setStyle ( style . fill ) ;
9298
9399 var point = new THREE . Vector2 ( ) ;
94100 var control = new THREE . Vector2 ( ) ;
@@ -331,11 +337,12 @@ THREE.SVGLoader.prototype = {
331337 var h = parseFloat ( node . getAttribute ( 'height' ) ) ;
332338
333339 var path = new THREE . ShapePath ( ) ;
334- path . color . setStyle ( parseFill ( node , style ) ) ;
340+ path . color . setStyle ( style . fill ) ;
335341 path . moveTo ( x , y ) ;
336342 path . lineTo ( x + w , y ) ;
337343 path . lineTo ( x + w , y + h ) ;
338344 path . lineTo ( x , y + h ) ;
345+
339346 return path ;
340347
341348 }
@@ -392,7 +399,7 @@ THREE.SVGLoader.prototype = {
392399 var regex = / ( - ? [ \d \. ? ] + ) [ , | \s ] ( - ? [ \d \. ? ] + ) / g;
393400
394401 var path = new THREE . ShapePath ( ) ;
395- path . color . setStyle ( parseFill ( node , style ) ) ;
402+ path . color . setStyle ( style . fill ) ;
396403
397404 var index = 0 ;
398405
@@ -414,7 +421,7 @@ THREE.SVGLoader.prototype = {
414421 subpath . absarc ( x , y , r , 0 , Math . PI * 2 ) ;
415422
416423 var path = new THREE . ShapePath ( ) ;
417- path . color . setStyle ( parseFill ( node , style ) ) ;
424+ path . color . setStyle ( style . fill ) ;
418425 path . subPaths . push ( subpath ) ;
419426
420427 return path ;
@@ -432,7 +439,7 @@ THREE.SVGLoader.prototype = {
432439 subpath . absellipse ( x , y , rx , ry , 0 , Math . PI * 2 ) ;
433440
434441 var path = new THREE . ShapePath ( ) ;
435- path . color . setStyle ( parseFill ( node , style ) ) ;
442+ path . color . setStyle ( style . fill ) ;
436443 path . subPaths . push ( subpath ) ;
437444
438445 return path ;
@@ -459,25 +466,12 @@ THREE.SVGLoader.prototype = {
459466
460467 function parseStyle ( node , style ) {
461468
462- if ( node . style . fill !== '' ) style . fill = node . style . fill ;
463-
464- }
465-
466- function parseFill ( node , style ) {
467-
468- if ( node . hasAttribute ( 'fill' ) ) {
469-
470- return node . getAttribute ( 'fill' ) ;
471-
472- }
469+ style = Object . assign ( { } , style ) ; // clone style
473470
474- if ( style . fill !== '' && style . fill !== 'none' ) {
475-
476- return style . fill ;
477-
478- }
471+ if ( node . hasAttribute ( 'fill' ) ) style . fill = node . getAttribute ( 'fill' ) ;
472+ if ( node . style . fill !== '' ) style . fill = node . style . fill ;
479473
480- return '#ffffff' ;
474+ return style ;
481475
482476 }
483477
@@ -511,7 +505,7 @@ THREE.SVGLoader.prototype = {
511505
512506 var paths = [ ] ;
513507
514- parseNode ( svg , { } ) ;
508+ parseNode ( svg , { fill : '#000' } ) ;
515509
516510 return paths ;
517511
0 commit comments