use rinecs::{Component, NToOneComponent, OneToNComponent, HierarchicalComponent, Entity};
use rin_math::{Mat4, Mat3, Pnt3, Vec3, UnitQuat, Vec4, DualQuat};
use hashbrown::HashMap;
use std::fmt::{self, Display, Debug};
use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy)]
pub struct SkinWeights {
pub weights: Vec4<f32>,
pub bone_indices: Vec4<u32>,
}
#[derive(Clone, Component)]
#[debug_as_string]
pub struct GeometryWeights{
pub dvert: Vec<Option<rinblender::mesh::MDeformVert>>,
pub dweight: Vec<rinblender::mesh::MDeformWeight>,
pub final_dverts: Vec<Option<rinblender::mesh::MDeformVert>>,
pub final_weights: Vec<rinblender::mesh::MDeformWeight>,
pub gpu_weights: Vec<SkinWeights>,
pub deformflags: rinblender::ArmatureDeformFlag,
}
impl Debug for GeometryWeights{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result{
fmt.write_str("GeometryWeights")
}
}
#[derive(NToOneComponent,Clone,Copy,Debug,Eq,PartialEq, Serialize, Deserialize)]
pub struct SkeletonRef(pub rinecs::Entity);
#[derive(Clone,Debug,Component,Eq,PartialEq, Serialize, Deserialize)]
pub struct SkeletonName(pub rinblender::ObjectId);
impl Display for SkeletonName{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result{
Display::fmt(&self.0, fmt)
}
}
#[derive(Component, Debug, Serialize, Deserialize)]
pub struct Skeleton {
pub changed: bool,
}
impl Skeleton {
pub fn new() -> Skeleton {
Skeleton {
changed: true,
}
}
}
#[derive(Clone, Debug, OneToNComponent, Serialize, Deserialize)]
pub struct BoneBase(pub rinecs::Entity);
#[derive(HierarchicalComponent,Clone,Eq,PartialEq,Debug, Serialize, Deserialize)]
pub struct BoneName(pub String);
impl Display for BoneName{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result{
Display::fmt(&self.0, fmt)
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BoneRef{
pub entity: rinecs::Entity,
pub name: String,
pub position: Pnt3,
pub delta: Vec3,
pub orientation: UnitQuat,
pub orientation_delta: UnitQuat,
pub prev_blend_pos: HashMap<String, Option<(f32, Pnt3)>>,
pub prev_blend_orientation: HashMap<String, Option<(f32, UnitQuat)>>,
pub changed: bool,
}
#[derive(Clone, Component, Debug, Serialize, Deserialize)]
pub struct RootMotionBone(pub BoneRef);
#[derive(Clone, Component, Debug, Serialize, Deserialize)]
#[storage(DenseVec)]
pub struct FootBones{
pub left: Vec<BoneRef>,
pub right: Vec<BoneRef>,
}
pub trait DefaultWeight{
fn default_weight(&self) -> f32;
fn set_default_weight(&mut self, dw: f32);
}
#[derive(Clone,Debug,Component, Serialize, Deserialize)]
pub struct ArmatureCache{
pub index: HashMap<String, usize>,
pub skinning_bones_index: Vec<Entity>,
pub changed: bool,
pub postmat: Option<Mat4>,
pub postmat3: Option<Mat3>,
pub premat: Option<Mat4>,
pub premat3: Option<Mat3>,
}
#[derive(Clone,Copy,Debug,OneToNComponent, Serialize, Deserialize)]
pub struct ArmatureMatrices{
pub bone_mat: Mat4,
}
#[derive(Clone,Copy,Debug,OneToNComponent, Serialize, Deserialize)]
pub struct ArmatureDualQuats{
pub dual_quat: DualQuat,
pub scale: Mat4,
}
#[derive(Clone,Debug,Component)]
#[debug_as_string]
pub struct BoneWeightsAndIndicesBuffer(pub glin::SharedBuffer<SkinWeights>);
#[derive(Clone,Debug,Component)]
#[debug_as_string]
pub struct ArmatureMatricesBuffer(pub glin::SharedBuffer<ArmatureMatrices>);
#[derive(Clone,Debug,Component)]
#[debug_as_string]
pub struct ArmatureDualQuatsBuffer(pub glin::SharedBuffer<ArmatureDualQuats>);