SVGLoader: Fix parsing of flags in compressed definitions. #21485
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue: Fixed #20608.
Description
SVGLoader
assumes sequences of floats like7.51,7.51,0,0,1,1.311,3.879
are separated by specific values (signs, points, comma or whitespaces). The problem is that a mangled version like7.51 7.51 0 011.311 3.879
is impossible to parse without knowing the semantics of the respective command.For example
011.311
is actually0,1,1.311
. However, without knowing that the first and second numbers in that string are SVG flags, you will end up with0,11.311
(because you can't detect whether the1
is part of the subsequent number or not).With this PR
parseFloats()
is enhanced with two parameters that allow the caller to specify optional semantics about the given definition. An additional array defines the indices of flags (meaning where flags occur in a definition) and the total length of a single definition. This should fix the tooth SVG (which is now a test asset ofwebgl_loader_svg
) and the SVG from https://discourse.threejs.org/t/svgloader-parse-errors/24537.@karimbeyrouti Do you mind testing this PR?