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

Add SVG render and export #778

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft

Conversation

dzil123
Copy link
Contributor

@dzil123 dzil123 commented Jul 28, 2021

Fixes: #379

Creates a PrimitiveRenderer trait to allow separation of the lyon tesselation and wgpu rendering from the general preparation and finalization of the different primitives, which allows alternative renderers to avoid duplicating existing code that normalizes the nannou primitives into simpler rendering primitives.

Implements an SVG renderer using above renderer abstractions.

Checklist:

  • PrimitiveRenderer
  • Migrate existing wgpu+lyon renderer
  • Verify all examples still work
  • SVG export
  • Draw context
    • Background
    • Blend
    • Scissor
    • Topology (point_mode, line_mode)
    • Sampler
  • Single color paths
    • Shapes
    • Polygons
    • Polylines
  • Text
  • Meshes
  • Textures
    • points_textured
  • points_colored
  • if stroke start_cap != end_cap
  • Finalized user-facing API
  • Documentation

@dzil123
Copy link
Contributor Author

dzil123 commented Jul 31, 2021

This PR is at the point where it can render the draw.rs example. Here is a sketch that renders the window to svg on mouse click: https://gist.github.com/dzil123/f52f4d554c570188ddcf73483a2dc292.

@mitchmindtree, would you mind taking a look?

@fenjalien
Copy link

fenjalien commented Aug 6, 2021

Hi I've tried making my own program to generate a Sierpinski triangle SVG file and it works really well! One thing I didn't realise is it only renders whats been drawn by the Draw struct in the view method.

See here: https://gist.github.com/fenjalien/bc9fa8ca765470308ea311ea68fb499a

Unfortunately I'm very new to nannou so I can't really suggest any changes 😅

@dzil123
Copy link
Contributor Author

dzil123 commented Aug 7, 2021

Thanks for checking it out!

I see what you mean about it rendering only whats drawn by the Draw that single view call. Nannou doesn't remember all the draw commands from previous frames, so fixing this isn't trivial. It just loads last frame's rendered texture and draws on top of it if draw.background() wasn't set.

I don't know if it would be practical to store previous draw commands indefinitely because it can grow without bounds if not cleared with a background. Maybe it could be opt-in? It could also be useful to redraw everything when the render texture is lost due to a window resize.

@dzil123 dzil123 changed the title Refactor draw::renderer::RenderPrimitive to enable alternative renderers Add SVG render and export Aug 10, 2021
@danwilhelm
Copy link
Contributor

It probably does make sense to constrain the SVG render to the commands within a single Draw instance -- without incorporating texture contents.

There are many situations that would have to be handled otherwise, e.g.:

  • frame.clear() (bypassing app.draw()),
  • Multiple Draw instances,
  • Use of wgpu (i.e. shaders, blending, etc.), and
  • Drawing on top of an existing texture as mentioned.

@mmansion
Copy link

mmansion commented Feb 6, 2022

Great work on this so far! SVG rendering will be an excellent enhancement. Looking to seeing it integrated soon.

@akonneker
Copy link

I wanted to leave a nudge here. I'm currently setting up to use nannou to generate some input files for a laser marking system. I would like to export svgs... and so this PR would be immensely helpful. I'm currently working off my own fork of this PR in the meantime.

If the underlying abstractions are still sound and this has potential to be merged with a reduced scope (e.g. ignoring meshes and stroke end cap stuff), I may be able to sponsor someone to work on it. I've not been involved in the nannou project, so I'm not sure how many active contributors there are, or if that is a possible or desirable arrangement.

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

Successfully merging this pull request may close these issues.

Export to SVG file
5 participants