Open momer opened 3 days ago
hey @momer , there is an issue with how the paths are triangulated. We use a much faster, but less accurate triangulation method for pixi shapes including svgs.
Perhaps we could add a plugin that uses something like this to triangulate it more thoroughly (albeit slower!)
@GoodBoyDigital If performance of parsing the initial path is a concern, it might make sense to cache the instructions
associated with the SVG, and de-couple them from the GraphicsContext
. It would also be cool to have SVGParser
become an interface, and allow users to select from FastSVGParse
and AccurateSVGParse
implementations.
On the caching side, copy-on-write seems like a good approach, as the common use-case is probably creating one or many instances of the same SVG, and perhaps changing any instructions (e.g. path fill), warrants a copy; although, even the styles could be decoupled from the instruction
paths - depending on what the common usage path is.
Somewhat related: a decoupling in any case would also be great for supporting things like SVG Groups - I dropped some ideas about that use case specifically today in discord.
I'm also pretty new to Pixi and animating stuff, so may be completely off-base with those thoughts, as I'm only really familiar with my usage!
Ninja edit: I'm also happy to help work on this!
I like the idea of SVG groups - I think that we could suppor them within the context it as a collection of paths / instructions - unless the goal is to reuse them reuse them in other contexts or save us from building groups more than once?
I think focusing on having a new method to triangulate the shapes, would be an great thing to add to Pixi! Moves us closer to being a ble to support even more svgs! Would love a hand here - we are always looking for smart cookies to help make pixi more awesome!
Supporting SVG groups would be rad - my use case depends on referencing individual group's paths for creating other Sprites/Graphics. It is a bit of a bummer that an SVG is reloaded and parsed for each Graphics
object, though!
Current Behavior
Attached are three SVG files. I extracted the shapes from a larger SVG asset, containing many paths, after narrowing down the issue to the triangle shape. Looking at the path itself, it looks like the issue may be related to its sub-pixel polygon points.
1 and 2 render the SVG shapes as expected, as the browser does. 3 results in a shape which is neither. And, when these two shapes are combined as part of a larger SVG, with other paths, the artifact stretches and takes a bit of a different shape, but along the same path (seemingly).
SVG images
Rendered results of Rock and Triangle (pixi.js @
^8.5.2
)Expected Behavior
The triangle should render as a triangle. That said, the triangle looks fine in Illustrator, and the only way I narrowed down the bug to this particular element was by deleting other elements on the stage until it was clear that this element was causing the issue.
Steps to Reproduce
Here's a
pixi-react
page with components to render the issueEnvironment
pixi.js
version:8.5.2
@pixi/react
version:8.0.0-beta.14
Possible Solution
No response
Additional Information
This issue is most painful when importing pre-existing assets, and trying to identify the source of artifacts rendering around the
Graphic
. The artifact occurred ~800px away from the little triangle buddy.