Browse Source

SVGLoader: Fix parsing of flags in compressed definitions. (#21485)

* SVGLoader: Fix parsing of flags in compressed definitions.

* SVGLoader: Add missing state assignment.
Michael Herzog 4 years ago
parent
commit
53d08e665e

+ 16 - 5
examples/js/loaders/SVGLoader.js

@@ -383,7 +383,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
 						break;
 						break;
 
 
 					case 'A':
 					case 'A':
-						var numbers = parseFloats( data );
+						var numbers = parseFloats( data, [ 3, 4 ], 7 );
 
 
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
 
 
@@ -575,7 +575,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
 						break;
 						break;
 
 
 					case 'a':
 					case 'a':
-						var numbers = parseFloats( data );
+						var numbers = parseFloats( data, [ 3, 4 ], 7 );
 
 
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
 
 
@@ -975,7 +975,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
 
 
 		// from https://github.com/ppvg/svg-numbers (MIT License)
 		// from https://github.com/ppvg/svg-numbers (MIT License)
 
 
-		function parseFloats( input ) {
+		function parseFloats( input, flags, stride ) {
 
 
 			if ( typeof input !== 'string' ) {
 			if ( typeof input !== 'string' ) {
 
 
@@ -991,7 +991,8 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
 				SIGN: /[-+]/,
 				SIGN: /[-+]/,
 				POINT: /\./,
 				POINT: /\./,
 				COMMA: /,/,
 				COMMA: /,/,
-				EXP: /e/i
+				EXP: /e/i,
+				FLAGS: /[01]/
 			};
 			};
 
 
 			// States
 			// States
@@ -1031,6 +1032,16 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
 
 
 				current = input[ i ];
 				current = input[ i ];
 
 
+				// check for flags
+				if ( Array.isArray( flags ) && flags.includes( result.length % stride ) && RE.FLAGS.test( current ) ) {
+
+					state = INT;
+					number = current;
+					newNumber();
+					continue;
+
+				}
+
 				// parse until next number
 				// parse until next number
 				if ( state === SEP ) {
 				if ( state === SEP ) {
 
 
@@ -1136,7 +1147,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
 				}
 				}
 
 
 				// parse exponent part
 				// parse exponent part
-				if ( state == EXP ) {
+				if ( state === EXP ) {
 
 
 					if ( RE.DIGIT.test( current ) ) {
 					if ( RE.DIGIT.test( current ) ) {
 
 

+ 16 - 5
examples/jsm/loaders/SVGLoader.js

@@ -398,7 +398,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 						break;
 						break;
 
 
 					case 'A':
 					case 'A':
-						var numbers = parseFloats( data );
+						var numbers = parseFloats( data, [ 3, 4 ], 7 );
 
 
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
 
 
@@ -590,7 +590,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 						break;
 						break;
 
 
 					case 'a':
 					case 'a':
-						var numbers = parseFloats( data );
+						var numbers = parseFloats( data, [ 3, 4 ], 7 );
 
 
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
 
 
@@ -990,7 +990,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 
 		// from https://github.com/ppvg/svg-numbers (MIT License)
 		// from https://github.com/ppvg/svg-numbers (MIT License)
 
 
-		function parseFloats( input ) {
+		function parseFloats( input, flags, stride ) {
 
 
 			if ( typeof input !== 'string' ) {
 			if ( typeof input !== 'string' ) {
 
 
@@ -1006,7 +1006,8 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 				SIGN: /[-+]/,
 				SIGN: /[-+]/,
 				POINT: /\./,
 				POINT: /\./,
 				COMMA: /,/,
 				COMMA: /,/,
-				EXP: /e/i
+				EXP: /e/i,
+				FLAGS: /[01]/
 			};
 			};
 
 
 			// States
 			// States
@@ -1046,6 +1047,16 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 
 				current = input[ i ];
 				current = input[ i ];
 
 
+				// check for flags
+				if ( Array.isArray( flags ) && flags.includes( result.length % stride ) && RE.FLAGS.test( current ) ) {
+
+					state = INT;
+					number = current;
+					newNumber();
+					continue;
+
+				}
+
 				// parse until next number
 				// parse until next number
 				if ( state === SEP ) {
 				if ( state === SEP ) {
 
 
@@ -1151,7 +1162,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 				}
 				}
 
 
 				// parse exponent part
 				// parse exponent part
-				if ( state == EXP ) {
+				if ( state === EXP ) {
 
 
 					if ( RE.DIGIT.test( current ) ) {
 					if ( RE.DIGIT.test( current ) ) {
 
 

+ 4 - 0
examples/models/svg/tests/9.svg

@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16.187" height="18.499" viewBox="0 0 16.187 18.499">
+	<path id="tooth-solid-export" d="M16.035 3.479A4.679 4.679 0 0012.711.092 3.836 3.836 0 009.49.971a2.413 2.413 0 01-.379.2l1.023.658a.578.578 0 01-.625.972L5.877.465A3.324 3.324 0 003.463.092 4.679 4.679 0 00.139 3.479a4.739 4.739 0 00.777 3.99 7.51 7.51 0 011.311 3.879 38.586 38.586 0 00.757 5.07l.282 1.227a1.1 1.1 0 002.139.02l1.245-5a1.479 1.479 0 012.873 0l1.245 5a1.1 1.1 0 002.139-.02l.282-1.227a38.638 38.638 0 00.757-5.07 7.509 7.509 0 011.311-3.879 4.735 4.735 0 00.778-3.99z"  fill="#fff">
+	</path>
+</svg>

+ 1 - 0
examples/webgl_loader_svg.html

@@ -100,6 +100,7 @@
 					"Test 6": 'models/svg/tests/6.svg',
 					"Test 6": 'models/svg/tests/6.svg',
 					"Test 7": 'models/svg/tests/7.svg',
 					"Test 7": 'models/svg/tests/7.svg',
 					"Test 8": 'models/svg/tests/8.svg',
 					"Test 8": 'models/svg/tests/8.svg',
+					"Test 9": 'models/svg/tests/9.svg',
 					"Units": 'models/svg/tests/units.svg',
 					"Units": 'models/svg/tests/units.svg',
 					"Defs": 'models/svg/tests/testDefs/Svg-defs.svg',
 					"Defs": 'models/svg/tests/testDefs/Svg-defs.svg',
 					"Defs2": 'models/svg/tests/testDefs/Svg-defs2.svg',
 					"Defs2": 'models/svg/tests/testDefs/Svg-defs2.svg',