Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to SVG file #379

Open
sethboyles opened this issue Aug 7, 2019 · 7 comments · May be fixed by #778
Open

Export to SVG file #379

sethboyles opened this issue Aug 7, 2019 · 7 comments · May be fixed by #778

Comments

@sethboyles
Copy link
Contributor

sethboyles commented Aug 7, 2019

An "Export to SVG file" would be something handy for users who would like to take images from their nannou sketches and work with them externally (e.g. printing, laser cutting, axidraw, etc).

Since lyon is in the process of being added to nannou (see #375), it'd probably be best to look at how to convert the results from lyon to SVG.

As noted in the lyon README:

How do I render an SVG file with lyon?
Lyon is not an SVG renderer. For now lyon mainly provides primitives to tessellate
complex path fills and strokes in a way that is convenient to use with GPU APIs such
as gfx-rs, glium, OpenGL, D3D, etc. How the tessellated geometry is rendered is 
completely up to the user of this crate.
@sethboyles
Copy link
Contributor Author

sethboyles commented Aug 7, 2019

For reference, Processing and OpenFrameworks have solutions for this (I'm unsure how complete or fully-featured they are):

@mitchmindtree
Copy link
Member

Thanks for opening this @sethboyles!

If you're mostly interested in drawing the contents of a Draw instance (the type often yielded by app.draw in nannou examples), one quick approach that might be worth looking into is the Draw::triangles method.

Produce an iterator yielding all triangles from the inner mesh transformed via the inner geometry graph.

Triangles are yielded in depth-first-order of the geometry graph nodes from which they are produced.

Note: If there are any Drawings in progress, these will first be drained and completed before any vertices are yielded.

Each triangle contains the color and position data for each vertex. Perhaps these triangles can be used alongside the svg crate somehow to produce the SVG? It wouldn't produce the most optimal SVG (e.g. tessellation of all the primitives would already be performed) but it might be a good-enough work around in the meantime depending on the use case?

I agree it would be nicer to have a proper solution in the future. One thought that crosses my mind is, rather than tessellating each shape as they're drawn, we could store them as a list of commands in the Draw itself. Then this list of commands could either be rendered to a more efficient SVG path representation, or tessellated for submission to a shader, etc.

@duncangeere
Copy link

Would love to see this too.

@jeffreyrosenbluth
Copy link

@mitchmindtree I'm thinking of taking this on, that is the "proper solution." I'm a bit confused by your comment though after a cursory glance at the source code. Aren't the list of commands already stored in the Stateof the Draw struct?

@ajdorexyz
Copy link

have recently just begun looking into using nannou/rust, would also love to see this. Willing to help if possible.

@dzil123 dzil123 linked a pull request Jul 28, 2021 that will close this issue
22 tasks
@wildfunctions
Copy link

The would be nice. Anyone working on this currently?

@dcturner
Copy link

dcturner commented Feb 1, 2023

Hello all 👋

I'm very interested in SVG import / export for Nannnou.
I'm wondering if the primitive drawing actions could implement something like a "ToSVG" trait which could be chained together to produce the final output? I'm going to look into this briefly - happy to assist + test if anyone else is working on a better solution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants