-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Implement Meshable
for some 3D primitives
#11688
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts:
- I like that the default primitives are more uniformly scaled. Getting any more specific than that would be super bikeshedy.
- I like the api in general. Good use of the builder pattern.
- I would prefer if
cuboid
,plane
,cylinder
andtorus
got their own modules instead of living indim3
.
Looks pretty good all in all.
I did a review ass, the biggest thing is I don't understand why you're duplicating all this code instead of making use of existing code where it exists. Duplicated code is fragile; it would be much more preferable to build a |
The plan is to remove the render shapes in a follow up. We are temporally copying rather than replacing to make the patch smaller and more manageable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm content with this, but I'd like to remove the duplicated code ASAP.
# Objective #11431 and #11688 implemented meshing support for Bevy's new geometric primitives. The next step is to deprecate the shapes in `bevy_render::mesh::shape` and to later remove them completely for 0.14. ## Solution Deprecate the shapes and reduce code duplication by utilizing the primitive meshing API for the old shapes where possible. Note that some shapes have behavior that can't be exactly reproduced with the new primitives yet: - `Box` is more of an AABB with min/max extents - `Plane` supports a subdivision count - `Quad` has a `flipped` property These types have not been changed to utilize the new primitives yet. --- ## Changelog - Deprecated all shapes in `bevy_render::mesh::shape` - Changed all examples to use new primitives for meshing ## Migration Guide Bevy has previously used rendering-specific types like `UVSphere` and `Quad` for primitive mesh shapes. These have now been deprecated to use the geometric primitives newly introduced in version 0.13. Some examples: ```rust let before = meshes.add(shape::Box::new(5.0, 0.15, 5.0)); let after = meshes.add(Cuboid::new(5.0, 0.15, 5.0)); let before = meshes.add(shape::Quad::default()); let after = meshes.add(Rectangle::default()); let before = meshes.add(shape::Plane::from_size(5.0)); // The surface normal can now also be specified when using `new` let after = meshes.add(Plane3d::default().mesh().size(5.0, 5.0)); let before = meshes.add( Mesh::try_from(shape::Icosphere { radius: 0.5, subdivisions: 5, }) .unwrap(), ); let after = meshes.add(Sphere::new(0.5).mesh().ico(5).unwrap()); ```
Objective
Split up from #11007, fixing most of the remaining work for #10569.
Implement
Meshable
forCuboid
,Sphere
,Cylinder
,Capsule
,Torus
, andPlane3d
. This covers all shapes that Bevy has mesh structs for inbevy_render::mesh::shapes
.Cone
andConicalFrustum
are new shapes, so I can add them in a follow-up, or I could just add them here directly if that's preferrable.Solution
Implement
Meshable
forCuboid
,Sphere
,Cylinder
,Capsule
,Torus
, andPlane3d
.The logic is mostly just a copy of the the existing
bevy_render
shapes, butPlane3d
has a configurable surface normal that affects the orientation. Some property names have also been changed to be more consistent.The default values differ from the old shapes to make them a bit more logical:
Cuboid
is 1x1x1 by default unlike the dreadedBox
which is 2x1x1.Before, with "old" shapes:
Now, with primitive meshing:
I only changed the
3d_shapes
example to use primitives for now. I can change them all in this PR or a follow-up though, whichever way is preferrable.Sphere API
Spheres have had separate
Icosphere
andUVSphere
structs, but with primitives we only have oneSphere
.We need to handle this with builders:
We could add methods on
Sphere
directly to skip calling.mesh()
.I also added a
SphereKind
enum that can be used with thekind
method:The default mesh for a
Sphere
is an icosphere with 5 subdivisions (like the defaultIcosphere
).Changelog
Meshable
andDefault
forCuboid
,Sphere
,Cylinder
,Capsule
,Torus
, andPlane3d
3d_shapes
example