use crate::data::BoneId;
use crate::math::Color;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum Inherit {
#[default]
Normal,
OnlyTranslation,
NoRotationOrReflection,
NoScale,
NoScaleOrReflection,
}
impl Inherit {
#[must_use]
pub fn from_index(v: u32) -> Option<Self> {
Some(match v {
0 => Self::Normal,
1 => Self::OnlyTranslation,
2 => Self::NoRotationOrReflection,
3 => Self::NoScale,
4 => Self::NoScaleOrReflection,
_ => return None,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct BoneLocal {
pub x: f32,
pub y: f32,
pub rotation: f32,
pub scale_x: f32,
pub scale_y: f32,
pub shear_x: f32,
pub shear_y: f32,
pub inherit: Inherit,
}
impl Default for BoneLocal {
fn default() -> Self {
Self {
x: 0.0,
y: 0.0,
rotation: 0.0,
scale_x: 1.0,
scale_y: 1.0,
shear_x: 0.0,
shear_y: 0.0,
inherit: Inherit::Normal,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct BoneData {
pub index: BoneId,
pub name: String,
pub parent: Option<BoneId>,
pub length: f32,
pub setup: BoneLocal,
pub skin_required: bool,
pub color: Color,
pub icon: String,
pub icon_size: f32,
pub icon_rotation: f32,
pub visible: bool,
}
impl BoneData {
#[must_use]
pub fn new(index: BoneId, name: impl Into<String>, parent: Option<BoneId>) -> Self {
Self {
index,
name: name.into(),
parent,
length: 0.0,
setup: BoneLocal::default(),
skin_required: false,
color: Color::new(0.61, 0.61, 0.61, 1.0),
icon: String::new(),
icon_size: 1.0,
icon_rotation: 0.0,
visible: true,
}
}
}