-
Notifications
You must be signed in to change notification settings - Fork 44
Access to shape data #65
Comments
So looking at debug
This logic is required for What do we expect for Heightfield (#62), Cylinder (#63) and Cone (#64)? It looks like those can be entirely defined upon creation, though I'm not entirely clear about what So we could treat On the other hand, both
which defines |
Yeah, what I did for the ConvexHull (#60) was more a "work-around" than the actual solution to the present issue.
Yes, I think we'll have all information we needs in the definition of the
Yes. Alghough I'm never fan of having exceptions, I don't think there is much way around it. If we create a generalized approach for polygons, then the sphere, capsule, cylinder and cone would become the exceptions.
Although technially possible, and maybe even "nice" for the debug renderer, I'm not eager to add public component for this. The thing is the debug render is only a debug tool. Ideally, I would like to extend the API (public components/resources, etc.) only to support the physics manipulation. Otherwise, it may make stuff confusing. For instance what should happen if the user mutate that Anyway, it would be possible to have a general approach in the debug render without such component: fn base_builder(body: &Body, shape: &dyn Shape) -> GeometryBuilder {
let mut builder = GeometryBuilder::new();
// Try to display a polygon if possible (ignoring the content of Body)
if let Some(polygon) = shape.as_convex_polygon() {
builder.add(&shapes::Polygon {
points: polygon.points().into_bevy(),
closed: true,
});
return builder;
}
// It wasn't possible to draw a polygon. Inspect the `Body` component:
match body {
Body::Sphere { radius } => ...
Body::Capsule { half_segment, radius } => ...
_ -> eprintln!("Some collision shapes couldn't be rendered")
};
builder
} |
To be clear: I'm not concerned with the debug renderer. I have a non-debug renderer that also uses this information, so I'd like there to be a public API for this. I thought Heron is all about exposing the Rapier APIs in a more friendly way, integrated with Bevy? In your example Note that your example is not generic in the way I describe with If there is no way to get this information, I wonder whether we should support Concerning mutating a points component - I guess read-only components aren't a thing then in Bevy? It strikes me those would be useful if you're integrating Bevy with external systems like physics engines in general. Another way would be to expose a resource to get the points data for a body or entity. Is there is a way to get from a heron Body to a Rapier/Parry Shape? Or would you have to go through entity? |
Ah, ok. I misunderstood then. Sorry. That of course invalidate my previous comment. I think I would call the component And if we are to expose the shape data, I would try to do it for every shape, not only for the polygons. Maybe we need some SVG-like API: struct ShapeData {
path: Vec<ShapeSegment>
}
enum ShapeSegment {
LineTo(Vec3),
ArcTo(...)
} To answer myself about mutability of the component we have to:
|
If we provided a way to create a Body from a |
If there were a way to create a body from a bevy_prototype_lyon polygon (which then would be a convex_polygon instead of a convex hull?) then I think that would fulfill my use case and in fact reduce some duplication (as I stole the regular polygon code from bevy_prototype_lyon in the first place to create a regular Rapier polygon). The SVG-like API to draw any shape sounds attractive in general but wouldn't be required for my use case. |
Maybe we could introduce a And it would create a collider that is the convex-hull of the polygon/mesh component found on the same entity. I'm not yet sure if that is a good or a bad idea. I will think more about it. |
We have a use case where we want to access shape data in the renderer code. For instance, ConvexHull creates a set of points that defines the convex hull depending on the points you give it. It should be possible to access this data through a Heron API. This issue is to remind us to think about this.
In Rapier, once you have the shape, you can call this:
Where
as_convex_polygon
is a typecast and then points is the method that returns the points to draw.Do we want to expose some kind of typecast API that can fail like this or is there another pattern that would work better? I know absolutely nothing about the reflection system of Bevy, is that relevant?
We need a Heron version of a convex polygon, that exposes Bevy vectors instead of Rapier points.
See also #43 as a fallback on how to get to the Rapier world. This could be a quick way to implement it without any new Heron APIs for the debug renderer, but in the longer term it would be better to expose this information in some nice Heron API.
The text was updated successfully, but these errors were encountered: