rgx.legacy
rgx.legacy copied to clipboard
Ability to create filled polygon
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!
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.
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.
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.
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.
Great!