Add Capsule2d primitive#11585
Conversation
|
It looks like your PR is a breaking change, but you didn't provide a migration guide. Could you add some context on what users should update when this change get released in a new version of Bevy? |
| /// Half of the width and height of the rectangle | ||
| pub half_size: Vec2, | ||
| } | ||
| impl Primitive2d for Rectangle {} |
There was a problem hiding this comment.
I randomly spotted this missing, lol
|
Much prefer Edit: oh you're way ahead of me. Figures :p You have a great eye for details like this. |
|
@Jondolf a couple of issues following the merge; let me know when you have it fixed up. |
|
Should be fixed @alice-i-cecile |
# Objective The `Capsule2d` primitive was added in #11585. It should support meshing like the other 2D primitives. ## Solution Implement meshing for `Capsule2d`. It doesn't currently support "rings" like Bevy's `Capsule` shape (not `Capsule3d`), but it does support resolution to control the number of vertices used for one hemicircle. The total vertex count is two times the resolution; if we allowed setting the full vertex count, odd numbers would lead to uneven vertex counts for the top and bottom hemicircles and produce potentially unwanted results. The capsule looks like this (with UV visualization and wireframe) using resolutions of 16, 8, and 3:    The `2d_shapes` example now includes the capsule, so we also get one more color of the rainbow 🌈 
# Objective Currently, the `Capsule` primitive is technically dimension-agnostic in that it implements both `Primitive2d` and `Primitive3d`. This seems good on paper, but it can often be useful to have separate 2D and 3D versions of primitives. For example, one might want a two-dimensional capsule mesh. We can't really implement both 2D and 3D meshing for the same type using the upcoming `Meshable` trait (see bevyengine#11431). We also currently don't implement `Bounded2d` for `Capsule`, see bevyengine#11336 (comment). Having 2D and 3D separate at a type level is more explicit, and also more consistent with the existing primitives, as there are no other types that implement both `Primitive2d` and `Primitive3d` at the same time. ## Solution Rename `Capsule` to `Capsule3d` and add `Capsule2d`. `Capsule2d` implements `Bounded2d`. For now, I went for `Capsule2d` for the sake of consistency and clarity. Mathematically the more accurate term would be `Stadium` or `Pill` (see [Wikipedia](https://en.wikipedia.org/wiki/Stadium_(geometry))), but those might be less obvious to game devs. For reference, Godot has [`CapsuleShape2D`](https://docs.godotengine.org/en/stable/classes/class_capsuleshape2d.html). I can rename it if others think the geometrically correct name is better though. --- ## Changelog - Renamed `Capsule` to `Capsule3d` - Added `Capsule2d` with `Bounded2d` implemented --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
# Objective The `Capsule2d` primitive was added in bevyengine#11585. It should support meshing like the other 2D primitives. ## Solution Implement meshing for `Capsule2d`. It doesn't currently support "rings" like Bevy's `Capsule` shape (not `Capsule3d`), but it does support resolution to control the number of vertices used for one hemicircle. The total vertex count is two times the resolution; if we allowed setting the full vertex count, odd numbers would lead to uneven vertex counts for the top and bottom hemicircles and produce potentially unwanted results. The capsule looks like this (with UV visualization and wireframe) using resolutions of 16, 8, and 3:    The `2d_shapes` example now includes the capsule, so we also get one more color of the rainbow 🌈 
Objective
Currently, the
Capsuleprimitive is technically dimension-agnostic in that it implements bothPrimitive2dandPrimitive3d. This seems good on paper, but it can often be useful to have separate 2D and 3D versions of primitives.For example, one might want a two-dimensional capsule mesh. We can't really implement both 2D and 3D meshing for the same type using the upcoming
Meshabletrait (see #11431). We also currently don't implementBounded2dforCapsule, see #11336 (comment).Having 2D and 3D separate at a type level is more explicit, and also more consistent with the existing primitives, as there are no other types that implement both
Primitive2dandPrimitive3dat the same time.Solution
Rename
CapsuletoCapsule3dand addCapsule2d.Capsule2dimplementsBounded2d.For now, I went for
Capsule2dfor the sake of consistency and clarity. Mathematically the more accurate term would beStadiumorPill(see Wikipedia), but those might be less obvious to game devs. For reference, Godot hasCapsuleShape2D. I can rename it if others think the geometrically correct name is better though.Changelog
CapsuletoCapsule3dCapsule2dwithBounded2dimplemented