mod intersect;
mod modifiers;
use std::ops::{Index, IndexMut};
use glam::{Vec2, Vec3};
#[derive(Clone, Copy, Debug)]
pub struct Triangle {
pub points: [Vec3; 3],
pub uvs: [Vec2; 3],
pub normal: Vec3,
}
impl Triangle {
pub fn new(points: [Vec3; 3], uvs: [Vec2; 3], normal: Vec3) -> Self {
Self {
points,
uvs,
normal,
}
}
pub fn from_points_uvs(points: [Vec3; 3], uvs: [Vec2; 3]) -> Self {
let normal = (points[1] - points[0]).cross(points[2] - points[0]);
Self::new(points, uvs, normal)
}
pub fn from_points(points: [Vec3; 3]) -> Self {
Self::from_points_uvs(points, [Vec2::ZERO; 3])
}
pub fn max(&self) -> Vec3 {
self[0].max(self[1]).max(self[2])
}
pub fn min(&self) -> Vec3 {
self[0].min(self[1]).min(self[2])
}
pub fn area(&self) -> f32 {
let ab = self[1] - self[0];
let ac = self[2] - self[0];
ab.dot(ac) * 0.5
}
}
impl Index<usize> for Triangle {
type Output = Vec3;
fn index(&self, index: usize) -> &Self::Output {
&self.points[index]
}
}
impl IndexMut<usize> for Triangle {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.points[index]
}
}