added skeleton, needs animation fix

Former-commit-id: f2c741426c073f3bfab3cdcd5b7f401a4fc6400e
This commit is contained in:
jshipsey 2019-05-13 22:24:34 -04:00
parent cf487589e2
commit 2a2b873f56
4 changed files with 146 additions and 65 deletions

View File

@ -69,6 +69,26 @@ pub enum Shoulder {
pub enum Draw { pub enum Draw {
Default, Default,
} }
////
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Pighead {
Default,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Pigchest {
Default,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Pigleg_l {
Default,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Pigleg_r {
Default,
}
////
const ALL_RACES: [Race; 6] = [ const ALL_RACES: [Race; 6] = [
Race::Danari, Race::Danari,
@ -137,19 +157,19 @@ const ALL_QRACES: [Race; 6] = [
Race::Orc, Race::Orc,
Race::Undead,]; Race::Undead,];
const ALL_QBODY_TYPES: [BodyType; 3] = [BodyType::Female, BodyType::Male, BodyType::Unspecified]; const ALL_QBODY_TYPES: [BodyType; 3] = [BodyType::Female, BodyType::Male, BodyType::Unspecified];
const ALL_QHEADS: [Head; 1] = [Head::Default]; const ALL_QHEADS: [Pighead; 1] = [Pighead::Default];
const ALL_QCHESTS: [Chest; 1] = [Chest::Default]; const ALL_QCHESTS: [Pigchest; 1] = [Pigchest::Default];
const ALL_QHANDS: [Hand; 1] = [Hand::Default]; const ALL_QPIGLEG_LS: [Pigleg_l; 1] = [Pigleg_l::Default];
const ALL_QFEET: [Foot; 1] = [Foot::Default]; const ALL_QPIGLEG_RS: [Pigleg_r; 1] = [Pigleg_r::Default];
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct QuadrupedBody { pub struct QuadrupedBody {
pub race: Race, pub race: Race,
pub body_type: BodyType, pub body_type: BodyType,
pub head: Head, pub pighead: Pighead,
pub chest: Chest, pub pigchest: Pigchest,
pub hand: Hand, pub pigleg_l: Pigleg_l,
pub foot: Foot, pub pigleg_r: Pigleg_r,
} }
@ -158,10 +178,10 @@ impl QuadrupedBody {
Self { Self {
race: *thread_rng().choose(&ALL_QRACES).unwrap(), race: *thread_rng().choose(&ALL_QRACES).unwrap(),
body_type: *thread_rng().choose(&ALL_QBODY_TYPES).unwrap(), body_type: *thread_rng().choose(&ALL_QBODY_TYPES).unwrap(),
head: *thread_rng().choose(&ALL_QHEADS).unwrap(), pighead: *thread_rng().choose(&ALL_QHEADS).unwrap(),
chest: *thread_rng().choose(&ALL_QCHESTS).unwrap(), pigchest: *thread_rng().choose(&ALL_QCHESTS).unwrap(),
hand: *thread_rng().choose(&ALL_QHANDS).unwrap(), pigleg_l: *thread_rng().choose(&ALL_QPIGLEG_LS).unwrap(),
foot: *thread_rng().choose(&ALL_QFEET).unwrap(), pigleg_r: *thread_rng().choose(&ALL_QPIGLEG_RS).unwrap(),
} }
} }
} }

View File

@ -13,24 +13,24 @@ const SCALE: f32 = 11.0;
#[derive(Clone)] #[derive(Clone)]
pub struct QuadrupedSkeleton { pub struct QuadrupedSkeleton {
head: Bone, pighead: Bone,
chest: Bone, pigchest: Bone,
lf_leg: Bone, piglf_leg: Bone,
rf_leg: Bone, pigrf_leg: Bone,
lb_leg: Bone, piglb_leg: Bone,
rb_leg: Bone, pigrb_leg: Bone,
} }
impl QuadrupedSkeleton { impl QuadrupedSkeleton {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
head: Bone::default(), pighead: Bone::default(),
chest: Bone::default(), pigchest: Bone::default(),
lf_leg: Bone::default(), piglf_leg: Bone::default(),
rf_leg: Bone::default(), pigrf_leg: Bone::default(),
lb_leg: Bone::default(), piglb_leg: Bone::default(),
rb_leg: Bone::default(), pigrb_leg: Bone::default(),
} }
} }
} }
@ -38,12 +38,12 @@ impl QuadrupedSkeleton {
impl Skeleton for QuadrupedSkeleton { impl Skeleton for QuadrupedSkeleton {
fn compute_matrices(&self) -> [FigureBoneData; 16] { fn compute_matrices(&self) -> [FigureBoneData; 16] {
[ [
FigureBoneData::new(self.head.compute_base_matrix()), FigureBoneData::new(self.pighead.compute_base_matrix()),
FigureBoneData::new(self.chest.compute_base_matrix()), FigureBoneData::new(self.pigchest.compute_base_matrix()),
FigureBoneData::new(self.lf_leg.compute_base_matrix()), FigureBoneData::new(self.piglf_leg.compute_base_matrix()),
FigureBoneData::new(self.rf_leg.compute_base_matrix()), FigureBoneData::new(self.pigrf_leg.compute_base_matrix()),
FigureBoneData::new(self.lb_leg.compute_base_matrix()), FigureBoneData::new(self.piglb_leg.compute_base_matrix()),
FigureBoneData::new(self.rb_leg.compute_base_matrix()), FigureBoneData::new(self.pigrb_leg.compute_base_matrix()),
FigureBoneData::default(), FigureBoneData::default(),
FigureBoneData::default(), FigureBoneData::default(),
FigureBoneData::default(), FigureBoneData::default(),
@ -58,11 +58,11 @@ impl Skeleton for QuadrupedSkeleton {
} }
fn interpolate(&mut self, target: &Self) { fn interpolate(&mut self, target: &Self) {
self.head.interpolate(&target.head); self.pighead.interpolate(&target.pighead);
self.chest.interpolate(&target.chest); self.pigchest.interpolate(&target.pigchest);
self.lf_leg.interpolate(&target.lf_leg); self.piglf_leg.interpolate(&target.piglf_leg);
self.rf_leg.interpolate(&target.rf_leg); self.pigrf_leg.interpolate(&target.pigrf_leg);
self.lb_leg.interpolate(&target.lb_leg); self.piglb_leg.interpolate(&target.piglb_leg);
self.rb_leg.interpolate(&target.rb_leg); self.pigrb_leg.interpolate(&target.pigrb_leg);
} }
} }

View File

@ -28,29 +28,29 @@ impl Animation for RunAnimation {
let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos(); let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos();
let wave_dip = (wave_slow.abs() - 0.5).abs(); let wave_dip = (wave_slow.abs() - 0.5).abs();
next.head.offset = Vec3::new(5.5, 2.0, 11.0 + wavecos * 1.3); next.pighead.offset = Vec3::new(5.5, 2.0, 11.0 + wavecos * 1.3);
next.head.ori = Quaternion::rotation_x(0.15); next.pighead.ori = Quaternion::rotation_x(0.15);
next.head.scale = Vec3::one(); next.pighead.scale = Vec3::one();
next.chest.offset = Vec3::new(5.5, 0.0, 7.0 + wavecos * 1.1); next.pigchest.offset = Vec3::new(5.5, 0.0, 7.0 + wavecos * 1.1);
next.chest.ori = Quaternion::rotation_z(wave * 0.1); next.pigchest.ori = Quaternion::rotation_z(wave * 0.1);
next.chest.scale = Vec3::one(); next.pigchest.scale = Vec3::one();
next.lf_leg.offset = Vec3::new(5.5, 0.0, 5.0 + wavecos * 1.1); next.piglf_leg.offset = Vec3::new(5.5, 0.0, 5.0 + wavecos * 1.1);
next.lf_leg.ori = Quaternion::rotation_z(wave * 0.25); next.piglf_leg.ori = Quaternion::rotation_z(wave * 0.25);
next.lf_leg.scale = Vec3::one(); next.piglf_leg.scale = Vec3::one();
next.rf_leg.offset = Vec3::new(5.5, 0.0, 2.0 + wavecos * 1.1); next.pigrf_leg.offset = Vec3::new(5.5, 0.0, 2.0 + wavecos * 1.1);
next.rf_leg.ori = Quaternion::rotation_z(wave * 0.6); next.pigrf_leg.ori = Quaternion::rotation_z(wave * 0.6);
next.rf_leg.scale = Vec3::one(); next.pigrf_leg.scale = Vec3::one();
next.lb_leg.offset = Vec3::new(-6.0, 0.0 + wavecos * 2.5, 11.0 - wave * 1.5); next.piglb_leg.offset = Vec3::new(-6.0, 0.0 + wavecos * 2.5, 11.0 - wave * 1.5);
next.lb_leg.ori = Quaternion::rotation_x(wavecos * 0.9); next.piglb_leg.ori = Quaternion::rotation_x(wavecos * 0.9);
next.lb_leg.scale = Vec3::one(); next.piglb_leg.scale = Vec3::one();
next.rb_leg.offset = Vec3::new(9.0, 0.0 - wavecos * 2.5, 11.0 + wave * 1.5); next.pigrb_leg.offset = Vec3::new(9.0, 0.0 - wavecos * 2.5, 11.0 + wave * 1.5);
next.rb_leg.ori = Quaternion::rotation_x(wavecos * -0.9); next.pigrb_leg.ori = Quaternion::rotation_x(wavecos * -0.9);
next.rb_leg.scale = Vec3::one(); next.pigrb_leg.scale = Vec3::one();
next next
} }

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
anim::{ anim::{
character::{CharacterSkeleton, IdleAnimation, JumpAnimation, RunAnimation}, character::{CharacterSkeleton, IdleAnimation, JumpAnimation, RunAnimation},
quadruped::{QuadrupedSkeleton}, quadruped::{QuadrupedSkeleton,},
Animation, Skeleton, Animation, Skeleton,
}, },
mesh::Meshable, mesh::Meshable,
@ -15,8 +15,8 @@ use common::{
assets, assets,
comp::{ comp::{
self, self,
actor::{Belt, Chest, Foot, Hand, Head, Pants, Shoulder, Weapon}, actor::{Belt, Chest, Foot, Hand, Head, Pants, Shoulder, Weapon, Pighead, Pigchest, Pigleg_l, Pigleg_r},
Body, HumanoidBody, Body, HumanoidBody, QuadrupedBody
}, },
figure::Segment, figure::Segment,
msg, msg,
@ -71,13 +71,13 @@ impl FigureModelCache {
None, None,
None, None,
], ],
Body::Quadruped(body) => [ // TODO Body::Quadruped(body) => [
None, Some(Self::load_pighead(body.pighead)),
None, Some(Self::load_pigchest(body.pigchest)),
None, Some(Self::load_piglf_leg(body.pigleg_l)),
None, Some(Self::load_pigrf_leg(body.pigleg_r)),
None, Some(Self::load_piglb_leg(body.pigleg_l)),
None, Some(Self::load_pigrb_leg(body.pigleg_r)),
None, None,
None, None,
None, None,
@ -237,8 +237,63 @@ impl FigureModelCache {
// //
// ) // )
// } // }
fn load_pighead(pighead: Pighead) -> Mesh<FigurePipeline> {
Self::load_mesh(
match pighead {
Pighead::Default => "pighead.vox",
},
Vec3::new(0.0, 5.0, 0.0),
)
}
fn load_pigchest(pigchest: Pigchest) -> Mesh<FigurePipeline> {
Self::load_mesh(
match pigchest {
Pigchest::Default => "pigchest.vox",
},
Vec3::new(0.0, 0.0, 0.0),
)
}
fn load_piglf_leg(pigleg_l: Pigleg_l) -> Mesh<FigurePipeline> {
Self::load_mesh(
match pigleg_l {
Pigleg_l::Default => "pigleg_l.vox",
},
Vec3::new(0.0, 0.0, 0.0),
)
}
fn load_pigrf_leg(pigleg_r: Pigleg_r) -> Mesh<FigurePipeline> {
Self::load_mesh(
match pigleg_r {
Pigleg_r::Default => "pigleg_r.vox",
},
Vec3::new(0.0, 0.0, 0.0),
)
}
fn load_piglb_leg(pigleg_l: Pigleg_l) -> Mesh<FigurePipeline> {
Self::load_mesh(
match pigleg_l {
Pigleg_l::Default => "pigleg_l.vox",
},
Vec3::new(0.0, 0.0, 0.0),
)
}
fn load_pigrb_leg(pigleg_r: Pigleg_r) -> Mesh<FigurePipeline> {
Self::load_mesh(
match pigleg_r {
Pigleg_r::Default => "pigleg_r.vox",
},
Vec3::new(0.0, 0.0, 0.0),
)
}
} }
pub struct FigureMgr { pub struct FigureMgr {
model_cache: FigureModelCache, model_cache: FigureModelCache,
character_states: HashMap<EcsEntity, FigureState<CharacterSkeleton>>, character_states: HashMap<EcsEntity, FigureState<CharacterSkeleton>>,
@ -305,7 +360,13 @@ impl FigureMgr {
FigureState::new(renderer, QuadrupedSkeleton::new()) FigureState::new(renderer, QuadrupedSkeleton::new())
}); });
// TODO! Animations here, like above! let target_skeleton = match animation_history.current {
comp::Animation::Run => RunAnimation::update_skeleton(
state.skeleton_mut(),
(vel.0.magnitude(), time),
animation_history.time,
),
};
state.update(renderer, pos.0, dir.0); state.update(renderer, pos.0, dir.0);
}, },