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

Tools for subdividing curves into line meshes #509

Open
mnesarco opened this issue May 28, 2021 · 3 comments
Open

Tools for subdividing curves into line meshes #509

mnesarco opened this issue May 28, 2021 · 3 comments

Comments

@mnesarco
Copy link

Hi Vladimir,

I am using Magnum to render some 3D primitives, I want to draw a path (like an svg path), it is just a sequence of rect segments, arcs of circle, arcs of ellipse and bezier segments, there is nothing already made in the Primitives workspace for beziers or arcs, but can you helpme with some info on how to create the MeshData required to this kind of drawing?

Thank you.

@mosra mosra added this to TODO in Math and algorithms via automation Jun 5, 2021
@mosra
Copy link
Owner

mosra commented Jun 5, 2021

Hi,

this is an advanced topic and you're right, currently there's nothing builtin that would do this for you. There's a few different ways of achieving this:

  • Subdividing the path to line segments, triangulating the resulting polygon and then rendering it as a classic mesh, possibly with MSAA enabled for smooth edges. Magnum's Bezier class has some subdivision APIs, but it's all very rudimentary and you'll probably have it easier if you use some 3rd party library. For the polygon triangulation, earcut is probably the most widely used library.
  • Because the above may require quite a lot of triangles for smooth curves and will not give you antialiasing for free, an alternative way is to triangulate only roughly and then have a customized shader do the hard work. This "research area" overlaps quite a lot with text rendering and there's many different approaches. One of the more advanced (but patented) algorithms is Slug, many more are listed in the "Shaders and rendering" section of this issue: Text rendering improvements #143
  • If you can afford being limited to just NVidia hardware, they have an extension exactly for this kind of thing: https://developer.nvidia.com/nv-path-rendering I think it can even digest SVGs directly.
  • And yet another library (although currently abandoned/unmaintained) is https://github.com/memononen/nanosvg

This area (path triangulation and rendering) is something I eventually want to have directly in Magnum, but I can't give any estimate when that could be.

@mnesarco
Copy link
Author

mnesarco commented Jun 5, 2021

Ok, thank you for the detailed answer. I will take a look at nanovg, apparently it is very popular, i suppose people don't care that it is unmaintained because there are not many options and it is in source anyway so quick fixes can be done if required.

@mosra mosra changed the title Primitive Path drawing Tools for subdividing curves into line meshes Mar 7, 2023
@mosra
Copy link
Owner

mosra commented Mar 7, 2023

A line drawing shader is now implemented with #601 (docs), however it only provides rendering of already-created line meshes, and provides no tools to convert arbitrary curves, circles or arcs to line meshes.

Such tools will get added eventually as well, keeping this issue open to track that.

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

No branches or pull requests

2 participants