pub struct Triangle {
pub v: [[f64; 3]; 3],
pub n: [[f64; 3]; 3],
pub uv: [[f64; 2]; 3],
pub material_id: u32,
}Expand description
A triangle primitive for ray tracing.
Fields§
§v: [[f64; 3]; 3]Vertex positions.
n: [[f64; 3]; 3]Per-vertex normals.
uv: [[f64; 2]; 3]Per-vertex UV coordinates.
material_id: u32Material index.
Implementations§
Source§impl Triangle
impl Triangle
Sourcepub fn new(
v0: [f64; 3],
v1: [f64; 3],
v2: [f64; 3],
n0: [f64; 3],
n1: [f64; 3],
n2: [f64; 3],
uv0: [f64; 2],
uv1: [f64; 2],
uv2: [f64; 2],
material_id: u32,
) -> Self
pub fn new( v0: [f64; 3], v1: [f64; 3], v2: [f64; 3], n0: [f64; 3], n1: [f64; 3], n2: [f64; 3], uv0: [f64; 2], uv1: [f64; 2], uv2: [f64; 2], material_id: u32, ) -> Self
Create a new triangle.
Sourcepub fn geometric_normal(&self) -> [f64; 3]
pub fn geometric_normal(&self) -> [f64; 3]
Compute the geometric normal from vertex positions.
Sourcepub fn intersect(&self, ray: &Ray) -> Option<f64>
pub fn intersect(&self, ray: &Ray) -> Option<f64>
Möller–Trumbore ray-triangle intersection.
Returns Some(t) if the ray intersects the triangle, within [t_min, t_max].
Sourcepub fn intersect_full(&self, ray: &Ray) -> Option<(f64, f64, f64)>
pub fn intersect_full(&self, ray: &Ray) -> Option<(f64, f64, f64)>
Full intersection returning barycentric coordinates.
Sourcepub fn interpolate_normal(&self, u: f64, v: f64) -> [f64; 3]
pub fn interpolate_normal(&self, u: f64, v: f64) -> [f64; 3]
Interpolate the shading normal at barycentric (u,v).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Triangle
impl RefUnwindSafe for Triangle
impl Send for Triangle
impl Sync for Triangle
impl Unpin for Triangle
impl UnsafeUnpin for Triangle
impl UnwindSafe for Triangle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more