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

Ability to create filled polygon #27

Open
frewsxcv opened this issue Aug 29, 2020 · 5 comments
Open

Ability to create filled polygon #27

frewsxcv opened this issue Aug 29, 2020 · 5 comments

Comments

@frewsxcv
Copy link

Hi! I'm interested in creating a filled in polygon from a series of lines. I noticed rgx has the ability to create lines, so I could create the outline of a polygon from a series of lines, but not sure about filling it in. Is this currently possible? If it's possible, I'm willing to add an example to the examples/ folder to demonstrate it!

@ecton
Copy link
Contributor

ecton commented Sep 4, 2020

It isn't currently possible, sadly, without implementing your own custom Pipeline. I discovered that as well recently. Luckily, it's actually a pretty straightforward add, and I'm happy to undertake it.

@cloudhead Would you be OK with a PR adding an enum option to Shape as Triangle(Vertex, Vertex, Vertex)? This would allow consumers to use any triangulation method they want, lyon for example, and can be implemented without adding any new dependencies or much code.

If you have another idea for an approach I'd be happy to do that approach instead.

@ecton
Copy link
Contributor

ecton commented Sep 4, 2020

I started trying to do this change, and the suggestion I had really isn't good at all. I would actually propose a different approach, but I haven't come up with a good design idea. One of the challenges is that Shape defines methods to alter stroke and fill on each of the types of shapes, and if you are looking to convert triangles from something like lyon into polygons, that's not exactly what you're looking for.

I'm torn between a couple of different approaches to this and am open to other ideas. One approach that could work would be to define a CustomShape trait that could be added as another enum option on Shape. I'm hesitant to propose approaches that would switch shape2d::Batch to using too much dynamic dispatch.

Lastly, I've been thinking maybe a custom lyon-"optimized" Pipeline wouldn't be a bad approach to more complicated shape drawing -- and this final approach can be done as a separate crate.

@cloudhead
Copy link
Owner

I actually had this planned a while ago, and was thinking of doing something like Shape::Polygon(Vec<Point2>), but it does get a bit complicated with fill/outline/etc. as you say, and it's not trivial to triangulate an aribitrary polygon.

I think a separate pipeline is probably the way to go here, and you can then depend on lyon without imposing the dependency on the rest of rgx.

@ecton
Copy link
Contributor

ecton commented Sep 8, 2020

I've published rgx-lyon, @frewsxcv, and in the examples folder there's an example using lyon's Path to render a triangle. I'm new to publishing, so if you have any feedback at all don't hesitate to file an issue over on that repo. Hope this helps!

I think this issue still is a good one to keep open, as it might be worth having something built-in.

@cloudhead
Copy link
Owner

Great!

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

No branches or pull requests

3 participants