Repository navigation
Add Tetrahedron primitive to bevy_math::primitives - #12688
Conversation
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
|
FYI, I have also already done a substantial amount of work on this; I would recommend joining us in the math-dev channel on Discord to talk about some of the things that have come up! |
|
Aw shucks, my bad 😅 I threw this PR draft out there after checking that there isn't anything that implements it in https://github.com/bevyengine/bevy/pulls, so that there is no doubling of efforts, but I guess I was too late anyway. Should I close this PR? |
mweatherley
left a comment
There was a problem hiding this comment.
This is fairly barebones, but I'd be happy to have this as a baseline!
mweatherley
left a comment
There was a problem hiding this comment.
Pretty happy with this! Thanks!
Jondolf
left a comment
There was a problem hiding this comment.
I think this looks good for an initial implementation :) We can build on this in follow-ups
| Vec3::new(0.0, 0.5, 0.0), | ||
| Vec3::new(-0.5, -0.5, 0.0), | ||
| Vec3::new(0.5, -0.5, 0.0), | ||
| Vec3::new(0.0, 0.0, 0.5), |
There was a problem hiding this comment.
I'm really confused as to why this is the default tetrahedron. I would expect a regular tetrahedron, centered at the origin. Or at least one that contains the origin. This one satisfies none of those properties. Can we have it be this instead?
| Vec3::new(0.0, 0.5, 0.0), | |
| Vec3::new(-0.5, -0.5, 0.0), | |
| Vec3::new(0.5, -0.5, 0.0), | |
| Vec3::new(0.0, 0.0, 0.5), | |
| Vec3::new(0.5, 0.5, 0.5), | |
| Vec3::new(-0.5, -0.5, 0.5), | |
| Vec3::new(0.5, -0.5, -0.5), | |
| Vec3::new(-0.5, 0.5, -0.5), |
There was a problem hiding this comment.
I think this was chosen so that, in particular, its base is the Default Triangle3d. I guess it does contain the origin, but only on its boundary :)
There was a problem hiding this comment.
What @mweatherley said, in practice it's just Triangle3d base + an extra vertex on the Z-axis.
I was thinking, if we go with your suggestion would it be possible to keep the tetrahedron upright? I think that's how people typically imagine this shape to look like.
|
|
||
| impl Default for Tetrahedron { | ||
| /// Returns the default [`Tetrahedron`] with the vertices | ||
| /// `[0.0, 0.5, 0.0]`, `[-0.5, -0.5, 0.0]`, `[0.5, -0.5, 0.0]` and `[0.0, 0.0, 0.5]`. |
There was a problem hiding this comment.
| /// `[0.0, 0.5, 0.0]`, `[-0.5, -0.5, 0.0]`, `[0.5, -0.5, 0.0]` and `[0.0, 0.0, 0.5]`. | |
| /// `[0.5, 0.5, 0.5]`, `[-0.5, -0.5, 0.5]`, `[0.5, -0.5, -0.5]` and `[-0.5, 0.5, -0.5]`. |
| impl Primitive3d for Tetrahedron {} | ||
|
|
||
| impl Default for Tetrahedron { | ||
| /// Returns the default [`Tetrahedron`] with the vertices |
There was a problem hiding this comment.
| /// Returns the default [`Tetrahedron`] with the vertices | |
| /// Returns a regular [`Tetrahedron`] centered at the origin with the vertices |
I agree with this; there's obviously some tension in terms of making things match up, but that's less important than the ergonomics of actually using the shape. (Then again, I kind of think a lot of the default shapes are a little silly) |
I guess that decision is being lifted off my shoulders, thanks for all the reviews! For the record, I agree, though I still feel like having this primitive remain upright (three vertices on a plane that's parallel to the |
) # 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
|
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1295 if you'd like to help out. |
Objective
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 verticesChangelog
Added
Tetrahedronprimitive to thebevy_mathcrateTetrahedrontests (area,volumemethods)impl_reflect!declaration forTetrahedronin thebevy_reflectcrate