mod vertex_attribute;
pub use self::vertex_attribute::{BoneAttributes, VertexAttribute};
use crate::bone::BoneInfluencesPerVertex;
mod single_indexed;
pub use self::single_indexed::*;
pub type VertexIndices = Vec<u16>;
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum VertexAttributes {
Multi(MultiIndexedVertexAttributes),
Single(SingleIndexedVertexAttributes),
}
impl Default for VertexAttributes {
fn default() -> Self {
VertexAttributes::Multi(MultiIndexedVertexAttributes::default())
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct MultiIndexedVertexAttributes {
pub(crate) vertices_in_each_face: Vec<u8>,
pub(crate) positions: IndexedAttribute,
pub(crate) normals: Option<IndexedAttribute>,
pub(crate) uvs: Option<IndexedAttribute>,
pub(crate) bone_influences: Option<VertexBoneInfluences>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct IndexedAttribute {
pub(crate) indices: VertexIndices,
pub(crate) attribute: VertexAttribute<f32>,
}
#[allow(missing_docs)]
impl IndexedAttribute {
pub fn new(indices: VertexIndices, attribute: VertexAttribute<f32>) -> Self {
IndexedAttribute { indices, attribute }
}
}
impl From<(VertexIndices, VertexAttribute<f32>)> for IndexedAttribute {
fn from(v: (VertexIndices, VertexAttribute<f32>)) -> Self {
Self {
indices: v.0,
attribute: v.1,
}
}
}
impl From<MultiIndexedVertexAttributes> for VertexAttributes {
fn from(m: MultiIndexedVertexAttributes) -> Self {
VertexAttributes::Multi(m)
}
}
impl From<SingleIndexedVertexAttributes> for VertexAttributes {
fn from(s: SingleIndexedVertexAttributes) -> Self {
VertexAttributes::Single(s)
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct VertexBoneInfluences {
pub(crate) bones_per_vertex: BoneInfluencesPerVertex,
pub(crate) bone_indices: Vec<u8>,
pub(crate) bone_weights: Vec<f32>,
}