-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Tracking Issue: Primitive Shapes #10572
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
Comments
# Add and implement constructors for Primitives - Adds more Primitive types and adds a constructor for almost all of them - Works towards finishing #10572 ## Solution - Created new primitives - Torus - Conical Frustum - Cone - Ellipse - Implemented constructors (`Primitive::new`) for almost every single other primitive. --------- Co-authored-by: Joona Aalto <[email protected]> Co-authored-by: Alice Cecile <[email protected]>
…10856) # Objective A better alternative version of #10843. Currently, Bevy has a single `Ray` struct for 3D. To allow better interoperability with Bevy's primitive shapes (#10572) and some third party crates (that handle e.g. spatial queries), it would be very useful to have separate versions for 2D and 3D respectively. ## Solution Separate `Ray` into `Ray2d` and `Ray3d`. These new structs also take advantage of the new primitives by using `Direction2d`/`Direction3d` for the direction: ```rust pub struct Ray2d { pub origin: Vec2, pub direction: Direction2d, } pub struct Ray3d { pub origin: Vec3, pub direction: Direction3d, } ``` and by using `Plane2d`/`Plane3d` in `intersect_plane`: ```rust impl Ray2d { // ... pub fn intersect_plane(&self, plane_origin: Vec2, plane: Plane2d) -> Option<f32> { // ... } } ``` --- ## Changelog ### Added - `Ray2d` and `Ray3d` - `Ray2d::new` and `Ray3d::new` constructors - `Plane2d::new` and `Plane3d::new` constructors ### Removed - Removed `Ray` in favor of `Ray3d` ### Changed - `direction` is now a `Direction2d`/`Direction3d` instead of a vector, which provides guaranteed normalization - `intersect_plane` now takes a `Plane2d`/`Plane3d` instead of just a vector for the plane normal - `Direction2d` and `Direction3d` now derive `Serialize` and `Deserialize` to preserve ray (de)serialization ## Migration Guide `Ray` has been renamed to `Ray3d`. ### Ray creation Before: ```rust Ray { origin: Vec3::ZERO, direction: Vec3::new(0.5, 0.6, 0.2).normalize(), } ``` After: ```rust // Option 1: Ray3d { origin: Vec3::ZERO, direction: Direction3d::new(Vec3::new(0.5, 0.6, 0.2)).unwrap(), } // Option 2: Ray3d::new(Vec3::ZERO, Vec3::new(0.5, 0.6, 0.2)) ``` ### Plane intersections Before: ```rust let result = ray.intersect_plane(Vec2::X, Vec2::Y); ``` After: ```rust let result = ray.intersect_plane(Vec2::X, Plane2d::new(Vec2::Y)); ```
# Add and implement constructors for Primitives - Adds more Primitive types and adds a constructor for almost all of them - Works towards finishing bevyengine#10572 ## Solution - Created new primitives - Torus - Conical Frustum - Cone - Ellipse - Implemented constructors (`Primitive::new`) for almost every single other primitive. --------- Co-authored-by: Joona Aalto <[email protected]> Co-authored-by: Alice Cecile <[email protected]>
# Objective Working towards finishing a part of #10572, this PR adds a ton of math helpers and useful constructors for primitive shapes. I also tried fixing some naming inconsistencies. ## Solution - Add mathematical helpers like `area`, `volume`, `perimeter`, `RegularPolygon::inradius` and so on, trying to cover all core mathematical properties of each shape - Add some constructors like `Rectangle::from_corners`, `Cuboid::from_corners` and `Plane3d::from_points` I also derived `PartialEq` for the shapes where it's trivial. Primitives like `Line2d` and `Segment2d` are not trivial because you could argue that they would be equal if they had an opposite direction. All mathematical methods have tests with reference values computed by hand or with external tools. ## Todo - [x] Add tests to verify that the values from mathematical helpers are correct --------- Co-authored-by: IQuick 143 <[email protected]>
…ne#10632) # Objective Working towards finishing a part of bevyengine#10572, this PR adds a ton of math helpers and useful constructors for primitive shapes. I also tried fixing some naming inconsistencies. ## Solution - Add mathematical helpers like `area`, `volume`, `perimeter`, `RegularPolygon::inradius` and so on, trying to cover all core mathematical properties of each shape - Add some constructors like `Rectangle::from_corners`, `Cuboid::from_corners` and `Plane3d::from_points` I also derived `PartialEq` for the shapes where it's trivial. Primitives like `Line2d` and `Segment2d` are not trivial because you could argue that they would be equal if they had an opposite direction. All mathematical methods have tests with reference values computed by hand or with external tools. ## Todo - [x] Add tests to verify that the values from mathematical helpers are correct --------- Co-authored-by: IQuick 143 <[email protected]>
Is this tracking issue still being utilized? Can we add any of
From #11773 to the list, if still applicable? Plane subdivision, specifically was a hot topic in Discord recently. |
I added the plane subdivision count to the list. The other two aren't as applicable in my opinion; we have AABB types and don't need a |
# Objective - #10572 There is no 2D primitive available for the common shape of an annulus (ring). ## Solution This PR introduces a new type to the existing math primitives: - `Annulus`: the region between two concentric circles --- ## Changelog ### Added - `Annulus` primitive to the `bevy_math` crate - `Annulus` tests (`diameter`, `thickness`, `area`, `perimeter` and `closest_point` methods) --------- Co-authored-by: Joona Aalto <[email protected]>
I think |
# Objective - #10572 There is no 3D primitive available for the common shape of a tetrahedron (3-simplex). ## Solution This PR introduces a new type to the existing math primitives: - `Tetrahedron`: a polyhedron composed of four triangular faces, six straight edges, and four vertices --- ## Changelog ### Added - `Tetrahedron` primitive to the `bevy_math` crate - `Tetrahedron` tests (`area`, `volume` methods) - `impl_reflect!` declaration for `Tetrahedron` in the `bevy_reflect` crate
# Objective Related to #10572 Allow the `Annulus` primitive to be meshed. ## Solution We introduce a `Meshable` structure, `AnnulusMeshBuilder`, which allows the `Annulus` primitive to be meshed, leaving optional configuration of the number of angular sudivisions to the user. Here is a picture of the annulus's UV-mapping: <img width="1440" alt="Screenshot 2024-03-26 at 10 39 48 AM" src="https://github.com/bevyengine/bevy/assets/2975848/b170291d-cba7-441b-90ee-2ad6841eaedb"> Other features are essentially identical to the implementations for `Circle`/`Ellipse`. --- ## Changelog - Introduced `AnnulusMeshBuilder` - Implemented `Meshable` for `Annulus` with `Output = AnnulusMeshBuilder` - Implemented `From<Annulus>` and `From<AnnulusMeshBuilder>` for `Mesh` - Added `impl_reflect!` declaration for `Annulus` and `Triangle3d` in `bevy_reflect` --- ## Discussion ### Design considerations The only interesting wrinkle here is that the existing UV-mapping of `Ellipse` (and hence of `Circle` and `RegularPolygon`) is non-radial (it's skew-free, created by situating the mesh in a bounding rectangle), so the UV-mapping of `Annulus` doesn't limit to that of `Circle` as its inner radius tends to zero, for instance. I don't see this as a real issue for `Annulus`, which should almost certainly have this kind of UV-mapping, but I think we ought to at least consider allowing mesh configuration for `Circle`/`Ellipse` that performs radial UV-mapping instead. (In these cases in particular, it would be especially easy, since we wouldn't need a different parameter set in the builder.) --------- Co-authored-by: Alice Cecile <[email protected]>
) # Objective - bevyengine#10572 There is no 3D primitive available for the common shape of a tetrahedron (3-simplex). ## Solution This PR introduces a new type to the existing math primitives: - `Tetrahedron`: a polyhedron composed of four triangular faces, six straight edges, and four vertices --- ## Changelog ### Added - `Tetrahedron` primitive to the `bevy_math` crate - `Tetrahedron` tests (`area`, `volume` methods) - `impl_reflect!` declaration for `Tetrahedron` in the `bevy_reflect` crate
# Objective Related to bevyengine#10572 Allow the `Annulus` primitive to be meshed. ## Solution We introduce a `Meshable` structure, `AnnulusMeshBuilder`, which allows the `Annulus` primitive to be meshed, leaving optional configuration of the number of angular sudivisions to the user. Here is a picture of the annulus's UV-mapping: <img width="1440" alt="Screenshot 2024-03-26 at 10 39 48 AM" src="https://github.com/bevyengine/bevy/assets/2975848/b170291d-cba7-441b-90ee-2ad6841eaedb"> Other features are essentially identical to the implementations for `Circle`/`Ellipse`. --- ## Changelog - Introduced `AnnulusMeshBuilder` - Implemented `Meshable` for `Annulus` with `Output = AnnulusMeshBuilder` - Implemented `From<Annulus>` and `From<AnnulusMeshBuilder>` for `Mesh` - Added `impl_reflect!` declaration for `Annulus` and `Triangle3d` in `bevy_reflect` --- ## Discussion ### Design considerations The only interesting wrinkle here is that the existing UV-mapping of `Ellipse` (and hence of `Circle` and `RegularPolygon`) is non-radial (it's skew-free, created by situating the mesh in a bounding rectangle), so the UV-mapping of `Annulus` doesn't limit to that of `Circle` as its inner radius tends to zero, for instance. I don't see this as a real issue for `Annulus`, which should almost certainly have this kind of UV-mapping, but I think we ought to at least consider allowing mesh configuration for `Circle`/`Ellipse` that performs radial UV-mapping instead. (In these cases in particular, it would be especially easy, since we wouldn't need a different parameter set in the builder.) --------- Co-authored-by: Alice Cecile <[email protected]>
# Objective - Ongoing work for #10572 - Implement the `Meshable` trait for `Triangle3d`, allowing 3d triangle primitives to produce meshes. ## Solution The `Meshable` trait for `Triangle3d` directly produces a `Mesh`, much like that of `Triangle2d`. The mesh consists only of a single triangle (the triangle itself), and its vertex data consists of: - Vertex positions, which are the triangle's vertices themselves (i.e. the triangle provides its own coordinates in mesh space directly) - Normals, which are all the normal of the triangle itself - Indices, which are directly inferred from the vertex order (note that this is slightly different than `Triangle2d` which, because of its lower dimension, has an orientation which can be corrected for so that it always faces "the right way") - UV coordinates, which are produced as follows: 1. The first coordinate is coincident with the `ab` direction of the triangle. 2. The second coordinate maps to be perpendicular to the first in mesh space, so that the UV-mapping is skew-free. 3. The UV-coordinates map to the smallest rectangle possible containing the triangle, given the preceding constraints. Here is a visual demonstration; here, the `ab` direction of the triangle is horizontal, left to right — the point `c` moves, expanding the bounding rectangle of the triangle when it pushes past `a` or `b`: <img width="1440" alt="Screenshot 2024-03-23 at 5 36 01 PM" src="https://github.com/bevyengine/bevy/assets/2975848/bef4d786-7b82-4207-abd4-ac4557d0f8b8"> <img width="1440" alt="Screenshot 2024-03-23 at 5 38 12 PM" src="https://github.com/bevyengine/bevy/assets/2975848/c0f72b8f-8e70-46fa-a750-2041ba6dfb78"> <img width="1440" alt="Screenshot 2024-03-23 at 5 37 15 PM" src="https://github.com/bevyengine/bevy/assets/2975848/db287e4f-2b0b-4fd4-8d71-88f4e7a03b7c"> The UV-mapping of `Triangle2d` has also been changed to use the same logic. --- ## Changelog - Implemented `Meshable` for `Triangle3d`. - Changed UV-mapping of `Triangle2d` to match that of `Triangle3d`. ## Migration Guide The UV-mapping of `Triangle2d` has changed with this PR; the main difference is that the UVs are no longer dependent on the triangle's absolute coordinates, but instead follow translations of the triangle itself in its definition. If you depended on the old UV-coordinates for `Triangle2d`, then you will have to update affected areas to use the new ones which, briefly, can be described as follows: - The first coordinate is parallel to the line between the first two vertices of the triangle. - The second coordinate is orthogonal to this, pointing in the direction of the third point. Generally speaking, this means that the first two points will have coordinates `[_, 0.]`, while the third coordinate will be `[_, 1.]`, with the exact values depending on the position of the third point relative to the first two. For acute triangles, the first two vertices always have UV-coordinates `[0., 0.]` and `[1., 0.]` respectively. For obtuse triangles, the third point will have coordinate `[0., 1.]` or `[1., 1.]`, with the coordinate of one of the two other points shifting to maintain proportionality. For example: - The default `Triangle2d` has UV-coordinates `[0., 0.]`, `[0., 1.]`, [`0.5, 1.]`. - The triangle with vertices `vec2(0., 0.)`, `vec2(1., 0.)`, `vec2(2., 1.)` has UV-coordinates `[0., 0.]`, `[0.5, 0.]`, `[1., 1.]`. - The triangle with vertices `vec2(0., 0.)`, `vec2(1., 0.)`, `vec2(-2., 1.)` has UV-coordinates `[2./3., 0.]`, `[1., 0.]`, `[0., 1.]`. ## Discussion ### Design considerations 1. There are a number of ways to UV-map a triangle (at least two of which are fairly natural); for instance, we could instead declare the second axis to be essentially `bc` so that the vertices are always `[0., 0.]`, `[0., 1.]`, and `[1., 0.]`. I chose this method instead because it is skew-free, so that the sampling from textures has only bilinear scaling. I think this is better for cases where a relatively "uniform" texture is mapped to the triangle, but it's possible that we might want to support the other thing in the future. Thankfully, we already have the capability of easily expanding to do that with Builders if the need arises. This could also allow us to provide things like barycentric subdivision. 2. Presently, the mesh-creation code for `Triangle3d` is set up to never fail, even in the case that the triangle is degenerate. I have mixed feelings about this, but none of our other primitive meshes fail, so I decided to take the same approach. Maybe this is something that could be worth revisiting in the future across the board. --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Jakub Marcowski <[email protected]>
I don't understand what is meant by
Considering there already is
which would basically produce a bunch of prisms. In addition, |
# Objective - Adds a basic `Extrusion<T: Primitive2d>` shape, suggestion of #10572 ## Solution - Adds `Measured2d` and `Measured3d` traits for getting the perimeter/area or area/volume of shapes. This allows implementing `.volume()` and `.area()` for all extrusions `Extrusion<T: Primitive2d + Measured2d>` within `bevy_math` - All existing perimeter, area and volume implementations for primitves have been moved into implementations of `Measured2d` and `Measured3d` - Shapes should be extruded along the Z-axis since an extrusion of depth `0.` should be equivalent in everything but name to the base shape ## Caviats - I am not sure about the naming. `Extrusion<T>` could also be `Prism<T>` and the `MeasuredNd` could also be something like `MeasuredPrimitiveNd`. If you have any other suggestions, please fell free to share them :) ## Future work This PR adds a basic `Extrusion` shape and does not implement a lot of things you might want it to. Some of the future possibilities include: - [ ] bounding for extrusions - [ ] making extrusions work with gizmos - [ ] meshing --------- Co-authored-by: Alice Cecile <[email protected]>
I've got a naive ellipsoid implementation working but it produces meshes identical to a scaled UV sphere, as it uses the sphere UV code with sectors and stacks, substituting variables for 2024-06-29_164446.mp4
Also the area calculation uses the approximate formula which could be a problem, the maths for integrating everything and getting a closer answer is too much for my brain 🤯 |
Any plans for an "annular segment" / should that be added to the list? |
Sounds good to me. Shouldn't be too diffivult either. I'll glady help with PRs regarding that! Maybe open a separate issue and link to that one here if you have a need for it! |
This issue tracks progress on primitive shapes, which were first added in #10466 based on the
primitive-shapes
RFC.Meshing #10569
Primitives should support
Mesh
construction.Meshable
trait and implement meshing for 2D primitives #11431Meshable
for some 3D primitives #11688bevy_render::mesh::shape
Deprecate shapes inbevy_render::mesh::shape
#11773Gizmos #10571
Gizmos should support drawing primitives.
Bounding volumes #10570
Bevy should have first-party bounding volumes and support computing them for primitives.
List of primitives
Annulus
primitive tobevy_math::primitives
#12706Arc2d
,CircularSector
,CircularSegment
#13482Arc2d
,CircularSector
,CircularSegment
#13482Arc2d
,CircularSector
,CircularSegment
#13482Remove bounding volumes from
bevy_render
See #13945
Misc
Ray
intoRay2d
andRay3d
and simplify plane construction #10856bevy_sprite
UseIntersectsVolume
for breakout example collisions #11500project_point
,contains_point
, etc.)Long-term possibilities
The text was updated successfully, but these errors were encountered: