saschagehlich / pixi-svg-graphics

Draws SVG documents on PIXI.Graphics objects
MIT License
55 stars 20 forks source link

[feature] Make a Graphics tree from all SVG elements. #8

Closed trusktr closed 5 years ago

trusktr commented 7 years ago

Instead of drawing everything in one Graphics object, make a new child Graphics object for each SVG element.

This would result in a Pixi scene graph tree, which would make it possible to traverse the tree and apply translations, rotations, etc, to individual Graphics objects, just like working with any existing Pixi tree.

Currently, if one wants to animate something, they have to re-render the whole SVG each tick, which is much more expensive than (for example) finding a sub-node and modifying only that sub-node.

You've got the drawing commands mapped, you just need create the child Graphics objects, then apply the same drawing commands in the child Graphics.

Basically, instead of rendering all commands into the Graphics object passed into SVGGraphics.drawSVG, you would add children to that Graphics object, and apply commands to each child corresponding to each SVG elements, and etcetera for children of those children.

The result would be a tree that is similar in structure to the SVG DOM tree.

saschagehlich commented 5 years ago

This is now the case with 1.0.0