-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add and impl Primitives #10580
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
Add and impl Primitives #10580
Changes from all commits
3c439a1
4c79096
5e12cc9
e976114
5200e06
926c2df
235b473
2efd563
9d5cbc3
ca5f977
5bf8491
5e93e79
9422276
c543697
05d488f
da80164
5340e96
cf2b44e
0550f30
5b7e525
fce6f02
2bc9c0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,24 @@ pub struct Polyline3d<const N: usize> { | |
} | ||
impl<const N: usize> Primitive3d for Polyline3d<N> {} | ||
|
||
impl<const N: usize> FromIterator<Vec3> for Polyline3d<N> { | ||
fn from_iter<I: IntoIterator<Item = Vec3>>(iter: I) -> Self { | ||
let mut vertices: [Vec3; N] = [Vec3::ZERO; N]; | ||
|
||
for (index, i) in iter.into_iter().take(N).enumerate() { | ||
vertices[index] = i; | ||
} | ||
Self { vertices } | ||
} | ||
} | ||
|
||
impl<const N: usize> Polyline3d<N> { | ||
/// Create a new `Polyline3d` from its vertices | ||
pub fn new(vertices: impl IntoIterator<Item = Vec3>) -> Self { | ||
Self::from_iter(vertices) | ||
} | ||
} | ||
|
||
/// A series of connected line segments in 3D space, allocated on the heap | ||
/// in a `Box<[Vec3]>`. | ||
/// | ||
|
@@ -118,6 +136,22 @@ pub struct BoxedPolyline3d { | |
} | ||
impl Primitive3d for BoxedPolyline3d {} | ||
|
||
impl FromIterator<Vec3> for BoxedPolyline3d { | ||
fn from_iter<I: IntoIterator<Item = Vec3>>(iter: I) -> Self { | ||
let vertices: Vec<Vec3> = iter.into_iter().collect(); | ||
Self { | ||
vertices: vertices.into_boxed_slice(), | ||
} | ||
} | ||
} | ||
|
||
impl BoxedPolyline3d { | ||
/// Create a new `BoxedPolyline3d` from its vertices | ||
pub fn new(vertices: impl IntoIterator<Item = Vec3>) -> Self { | ||
Self::from_iter(vertices) | ||
} | ||
} | ||
|
||
/// A cuboid primitive, more commonly known as a box. | ||
#[derive(Clone, Copy, Debug)] | ||
pub struct Cuboid { | ||
|
@@ -171,3 +205,47 @@ pub struct Capsule { | |
} | ||
impl super::Primitive2d for Capsule {} | ||
impl Primitive3d for Capsule {} | ||
|
||
impl Capsule { | ||
/// Create a new `Capsule` from a radius and length | ||
pub fn new(radius: f32, length: f32) -> Self { | ||
Self { | ||
radius, | ||
half_length: length / 2.0, | ||
} | ||
} | ||
} | ||
|
||
/// A cone primitive. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @NiseVoid suggested (#10580 (comment)), maybe we should mention where the origin of the cone should be so that different integrations have consistent representations? If the options are the base and apex (tip), the base is more intuitive for me personally. I view cones like Wikipedia's description:
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct Cone { | ||
/// The radius of the base | ||
pub radius: f32, | ||
/// The height of the cone | ||
pub height: f32, | ||
} | ||
impl Primitive3d for Cone {} | ||
|
||
/// A conical frustum primitive. | ||
/// A conical frustum can be created | ||
/// by slicing off a section of a cone. | ||
#[derive(Clone, Copy, Debug)] | ||
pub struct ConicalFrustum { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also nice to have, but if we also want primitives to be used for rendering, a viewing frustum would be more useful. For rendering, it would be defined by an aspect-ratio, fov and the near and far planes, but maybe that's a bit too rendering-specific for primitives? More opinions on this would be useful. If we add a viewing frustum though, it should probably be done in a separate PR since it'd touch on rendering code too and be a bit more controversial. If we want to support different types of frusta, then perhaps a polygonal frustum with a regular polygon as a base could also be useful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @superdump also briefly touched on this here: #10466 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, we should split rendering frustra into a different PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rendering frustum most likely belongs in the bounding PR. Might be good to create some helper later to create a primitive shape you can render from the 6 plane representation (which is not exactly most convinient way to render them) |
||
/// The radius of the top of the frustum | ||
pub radius_top: f32, | ||
/// The radius of the base of the frustum | ||
pub radius_bottom: f32, | ||
/// The height of the frustum | ||
pub height: f32, | ||
Aztro-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
impl Primitive3d for ConicalFrustum {} | ||
|
||
/// A torus (AKA donut) primitive. | ||
#[derive(Clone, Copy, Debug)] | ||
pub struct Torus { | ||
/// The radius of the overall shape | ||
pub radius: f32, | ||
/// The radius of the internal ring | ||
pub ring_radius: f32, | ||
} | ||
impl Primitive3d for Torus {} |
Uh oh!
There was an error while loading. Please reload this page.