Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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