use crate::{
Evolution, Tf, Cl, Transformation, Colorization, Vertex,
D_TRANSFORMATION_SPEED_EVOLUTION, D_TRANSFORMATION_START_TIME, D_TRANSFORMATION_END_TIME,
D_COLORIZATION_SPEED_EVOLUTION, D_COLORIZATION_START_TIME, D_COLORIZATION_END_TIME,
};
pub struct Model {
pub vertices: Vec<Vertex>,
pub t: Vec<Tf>,
}
impl Model {
pub fn from_merge(models: Vec<Model>) -> Self {
Self {
vertices: models
.into_iter()
.flat_map(move |model| model.vertices.into_iter())
.collect(),
t: vec![],
}
}
pub fn from_vertices(vertices: Vec<Vertex>) -> Self {
Self {
vertices,
t: vec![],
}
}
pub fn rgb(mut self, red: f32, green: f32, blue: f32) -> Self {
self.vertices
.iter_mut()
.for_each(|v| v.set_rgb(red, green, blue));
self
}
pub fn alpha(mut self, alpha: f32) -> Self {
self.vertices.iter_mut().for_each(|v| v.set_alpha(alpha));
self
}
pub fn transform(mut self, transformation: Transformation) -> Self {
self.t.push(Tf {
t: transformation,
e: unsafe { D_TRANSFORMATION_SPEED_EVOLUTION },
start: unsafe { D_TRANSFORMATION_START_TIME },
end: unsafe { D_TRANSFORMATION_END_TIME },
});
self
}
pub fn recolor(mut self, colorization: Colorization) -> Self {
self.vertices.iter_mut().for_each(|v| { v.c.push(Cl {
c: colorization,
e: unsafe { D_COLORIZATION_SPEED_EVOLUTION },
start: unsafe { D_COLORIZATION_START_TIME },
end: unsafe { D_COLORIZATION_END_TIME },
})});
self
}
pub fn evolution_c(mut self, e: Evolution) -> Self {
self.vertices.iter_mut().for_each(|v| { v.c.last_mut().unwrap().e = e; });
self
}
pub fn start_c(mut self, start: f32) -> Self {
self.vertices.iter_mut().for_each(|v| { v.c.last_mut().unwrap().start = start; });
self
}
pub fn end_c(mut self, end: f32) -> Self {
self.vertices.iter_mut().for_each(|v| { v.c.last_mut().unwrap().end = end; });
self
}
pub fn evolution_t(mut self, e: Evolution) -> Self {
self.t.last_mut().unwrap().e = e;
self
}
pub fn start_t(mut self, start: f32) -> Self {
self.t.last_mut().unwrap().start = start;
self
}
pub fn end_t(mut self, end: f32) -> Self {
self.t.last_mut().unwrap().end = end;
self
}
}
pub struct Triangle;
impl Triangle {
pub fn new(v1: Vertex, v2: Vertex, v3: Vertex) -> Model {
Model::from_vertices(vec![v1, v2, v3])
}
}