Skip to content

Commit

Permalink
SVGLoader: Fix parsing of flags in compressed definitions. (#21485)
Browse files Browse the repository at this point in the history
* SVGLoader: Fix parsing of flags in compressed definitions.

* SVGLoader: Add missing state assignment.
  • Loading branch information
Mugen87 committed Mar 21, 2021
1 parent bfc15ba commit 53d08e6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
21 changes: 16 additions & 5 deletions examples/js/loaders/SVGLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
break;

case 'A':
var numbers = parseFloats( data );
var numbers = parseFloats( data, [ 3, 4 ], 7 );

for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {

Expand Down Expand Up @@ -575,7 +575,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
break;

case 'a':
var numbers = parseFloats( data );
var numbers = parseFloats( data, [ 3, 4 ], 7 );

for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {

Expand Down Expand Up @@ -975,7 +975,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype

// from https://github.com/ppvg/svg-numbers (MIT License)

function parseFloats( input ) {
function parseFloats( input, flags, stride ) {

if ( typeof input !== 'string' ) {

Expand All @@ -991,7 +991,8 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
SIGN: /[-+]/,
POINT: /\./,
COMMA: /,/,
EXP: /e/i
EXP: /e/i,
FLAGS: /[01]/
};

// States
Expand Down Expand Up @@ -1031,6 +1032,16 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype

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
if ( state === SEP ) {

Expand Down Expand Up @@ -1136,7 +1147,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
}

// parse exponent part
if ( state == EXP ) {
if ( state === EXP ) {

if ( RE.DIGIT.test( current ) ) {

Expand Down
21 changes: 16 additions & 5 deletions examples/jsm/loaders/SVGLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
break;

case 'A':
var numbers = parseFloats( data );
var numbers = parseFloats( data, [ 3, 4 ], 7 );

for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {

Expand Down Expand Up @@ -590,7 +590,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
break;

case 'a':
var numbers = parseFloats( data );
var numbers = parseFloats( data, [ 3, 4 ], 7 );

for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {

Expand Down Expand Up @@ -990,7 +990,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

// from https://github.com/ppvg/svg-numbers (MIT License)

function parseFloats( input ) {
function parseFloats( input, flags, stride ) {

if ( typeof input !== 'string' ) {

Expand All @@ -1006,7 +1006,8 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
SIGN: /[-+]/,
POINT: /\./,
COMMA: /,/,
EXP: /e/i
EXP: /e/i,
FLAGS: /[01]/
};

// States
Expand Down Expand Up @@ -1046,6 +1047,16 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

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
if ( state === SEP ) {

Expand Down Expand Up @@ -1151,7 +1162,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}

// parse exponent part
if ( state == EXP ) {
if ( state === EXP ) {

if ( RE.DIGIT.test( current ) ) {

Expand Down
4 changes: 4 additions & 0 deletions examples/models/svg/tests/9.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/webgl_loader_svg.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"Test 6": 'models/svg/tests/6.svg',
"Test 7": 'models/svg/tests/7.svg',
"Test 8": 'models/svg/tests/8.svg',
"Test 9": 'models/svg/tests/9.svg',
"Units": 'models/svg/tests/units.svg',
"Defs": 'models/svg/tests/testDefs/Svg-defs.svg',
"Defs2": 'models/svg/tests/testDefs/Svg-defs2.svg',
Expand Down

0 comments on commit 53d08e6

Please sign in to comment.