Replies: 6 comments 7 replies
-
A 3D OSM renderer in Rust sounds awesome, I'll be following your project with lots of excitement! Let me see how I can help... Widgetry has code to transform an SVG file into a list of colored triangles. The pipeline is:
As you've found, https://github.com/a-b-street/abstreet/blob/master/widgetry/src/svg.rs does all of this. It's pure Rust all the way down, so it works fine in wasm. This includes text rendering, with some glue to load in fonts at abstreet/widgetry/src/assets.rs Line 58 in 2598f2a There are two possible problems with adapting this approach. First, you need a PNG to upload to the GPU? Is it possible to send in triangles and colors and have a simple shader to draw in the GPU? If you need to rasterize the triangles into an image, I'm not familiar with the Rust library that would best help you -- maybe tiny-skia or raquote? Second, depending on the complexity of your SVGs, some things won't work -- mainly transform matrices and some linear/radial gradient coloring. I remember to get some more complex SVGs working properly, I had to use another tool to "flatten" things: 139f442 |
Beta Was this translation helpful? Give feedback.
-
Since you're asking about wasm, am I correct in assuming you're building some kind of web app? Would it be reasonable to instead do whatever application logic you need to build the SVG in rust, but then export the SVG via a wasm API to be rendered using the browsers native SVG rendering? |
Beta Was this translation helpful? Give feedback.
-
Intermediate summary:
Rust is great but some times ... |
Beta Was this translation helpful? Give feedback.
-
If you are in the wasm version of resvg, try: https://github.com/yisibl/resvg-js#webassembly |
Beta Was this translation helpful? Give feedback.
-
Yes, that's a way to do it inside WASM. |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm wondering if there's any updated solution to this? I'm currently trying to render SVG using wgpu+lyon on WASM, but I haven't been able to figure out how to do it. Thank you! |
Beta Was this translation helpful? Give feedback.
-
When I needed a SVG renderer, I found the crate 'resvg'. It worked fine for binary but not for WASM.
'widgetry' was recommended, but as a new-by to Rust I was just puzzled by the complexity.
Now I hope, I got this right:
'resvg' does triangulate but not render the SVG. This is done "only" by 'tiny-skia'.
While 'widgetry' uses 'lyon' and quite some "glue code".
My project (an OSM 3D renderer) already calls let svg_tree = Tree::from_data
and needs the PNG only as a byte array (to send it as a texture to the GPU by 'three-d')
Could I use widgetry as it is (and how)? An compact example would be nice.
May be I will try to extract the parts of widgetry, I need.
(add_svg_inner from abstreet/widgetry/src/svg.rs, GeomBatch and all things requested by the build %-)
'widgetry' raised to build 'abstreed' but is usefull for other to.
May the function, to render SVG with WASM could be put in an extra sub crate?
(Or added/moved to 'resvg-wasm'?)
Beta Was this translation helpful? Give feedback.
All reactions