I am learning to work with BonsaiJS and would like to import an external SVG image on the stage.
At http://docs.bonsaijs.org/overview/Path.html I learnt that there are three ways to create a new Path()
sending SVG paths, path commands or path points as arguments, but for more complex SVG files this is too much of a hassle to make this work.
At How Can I Animate my SVG files with a JS Library - Is Bonsai Ideal for this? I read one can use the new Bitmap()
method, but SVG's are turned into... bitmaps.
Am I missing something? Thanks in advance!
At the time it seems impossible for BonsaiJS to load external SVG's like it is possible to load external bitmap images. The BonsaiJS docs (http://docs.bonsaijs.org/overview/Path.html) do provide three methods to manually handle paths from an SVG file separately.
Path nodes
If your SVG contains
<path>
nodes (tags), get the value of thed
attribute and apply the fill manually:SVG
BonsaiJS
Polygon nodes
If your SVG ie. contains
<polygon>
nodes, get the string value of thepoints
attribute, split this string into an array and turn all string elements into floats. Again also apply the fill manually:SVG
BonsaiJS
Then...
After defining all parts, one can create a group and add all parts to 'reconstruct' the original SVG image, ie.: