Nilirad / bevy_prototype_lyon

Draw 2D shapes in Bevy
Apache License 2.0
702 stars 87 forks source link

RegularPolygon into Polygon to access Vertices #239

Closed andrewexton373 closed 1 month ago

andrewexton373 commented 9 months ago

Hello,

I'd like to be able to convert a RegularPolygon into a Polygon, so that I'm able to access the Vector of vertices that make up the shape. In order to create a Collider for the xpbd physics library, I need to provide a Vector of vertices that make up the shape, and as far as I'm currently aware, there's no way to access this given a RegularPolygon.

Here's an example of what I'd like to be able to do:

let base_shape: Polygon = lyon::shapes::RegularPolygon {
            sides: 6,
            feature: lyon::shapes::RegularPolygonFeature::Radius(
                crate::PIXELS_PER_METER * BASE_STATION_SIZE,
            ),
            ..lyon::shapes::RegularPolygon::default()
        }.into();

let collider = Collider::convex_hull(base_shape.points.clone()).unwrap();

Here's and example that works, but only works on Polygons:

let player_poly = shapes::Polygon {
            points: vec![
                Vec2 {x: 0.0, y: 2.0 * crate::PIXELS_PER_METER},
                Vec2 {x: 1.0 * crate::PIXELS_PER_METER, y: -1.0 * crate::PIXELS_PER_METER},
                Vec2 {x: -1.0 * crate::PIXELS_PER_METER, y: -1.0 * crate::PIXELS_PER_METER}
            ],
            closed: true
        };        

let collider = Collider::convex_hull(player_poly.points.clone()).unwrap();

I have a feeling that this should be possible, but I'm scratching my head as to how to make it happen. Let me know if you have any thoughts, I appreciate the time taken to hear me out and ponder my questions.