#[derive(Debug, Serialize, Deserialize, PartialEq, Default)]
pub struct VertexAttribute {
data: Vec<f32>,
size: AttributeSize,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum AttributeSize {
Two = 2,
Three = 3,
}
impl Default for AttributeSize {
fn default() -> Self {
AttributeSize::Three
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Default)]
pub struct BoneAttributes {
bone_indices: VertexAttribute,
bone_weights: VertexAttribute,
}
impl VertexAttribute {
pub fn new(data: Vec<f32>, size: AttributeSize) -> VertexAttribute {
VertexAttribute { data, size }
}
pub fn data(&self) -> &Vec<f32> {
&self.data
}
pub(crate) fn data_mut(&mut self) -> &mut Vec<f32> {
&mut self.data
}
}
impl VertexAttribute {
pub(crate) fn set_three_components(&mut self, idx: usize, comp1: f32, comp2: f32, comp3: f32) {
match self.size {
AttributeSize::Three => {
self.data[idx * 3] = comp1;
self.data[idx * 3 + 1] = comp2;
self.data[idx * 3 + 2] = comp3;
}
_ => panic!("Does not have exactly three components"),
};
}
pub(crate) fn increment_three_components(
&mut self,
idx: usize,
comp1: f32,
comp2: f32,
comp3: f32,
) {
match self.size {
AttributeSize::Three => {
self.data[idx * 3] += comp1;
self.data[idx * 3 + 1] += comp2;
self.data[idx * 3 + 2] += comp3;
}
_ => panic!("Does not have exactly three components"),
};
}
pub(crate) fn set_two_components(&mut self, idx: usize, comp1: f32, comp2: f32) {
match self.size {
AttributeSize::Two => {
self.data[idx * 2] = comp1;
self.data[idx * 2 + 1] = comp2;
}
_ => panic!("Does not have exactly two components"),
};
}
pub(crate) fn push(&mut self, val: f32) {
self.data.push(val)
}
}