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

View File

@ -13,24 +13,24 @@ const SCALE: f32 = 11.0;
#[derive(Clone)]
pub struct QuadrupedSkeleton {
head: Bone,
chest: Bone,
lf_leg: Bone,
rf_leg: Bone,
lb_leg: Bone,
rb_leg: Bone,
pighead: Bone,
pigchest: Bone,
piglf_leg: Bone,
pigrf_leg: Bone,
piglb_leg: Bone,
pigrb_leg: Bone,
}
impl QuadrupedSkeleton {
pub fn new() -> Self {
Self {
head: Bone::default(),
chest: Bone::default(),
lf_leg: Bone::default(),
rf_leg: Bone::default(),
lb_leg: Bone::default(),
rb_leg: Bone::default(),
pighead: Bone::default(),
pigchest: Bone::default(),
piglf_leg: Bone::default(),
pigrf_leg: Bone::default(),
piglb_leg: Bone::default(),
pigrb_leg: Bone::default(),
}
}
}
@ -38,12 +38,12 @@ impl QuadrupedSkeleton {
impl Skeleton for QuadrupedSkeleton {
fn compute_matrices(&self) -> [FigureBoneData; 16] {
[
FigureBoneData::new(self.head.compute_base_matrix()),
FigureBoneData::new(self.chest.compute_base_matrix()),
FigureBoneData::new(self.lf_leg.compute_base_matrix()),
FigureBoneData::new(self.rf_leg.compute_base_matrix()),
FigureBoneData::new(self.lb_leg.compute_base_matrix()),
FigureBoneData::new(self.rb_leg.compute_base_matrix()),
FigureBoneData::new(self.pighead.compute_base_matrix()),
FigureBoneData::new(self.pigchest.compute_base_matrix()),
FigureBoneData::new(self.piglf_leg.compute_base_matrix()),
FigureBoneData::new(self.pigrf_leg.compute_base_matrix()),
FigureBoneData::new(self.piglb_leg.compute_base_matrix()),
FigureBoneData::new(self.pigrb_leg.compute_base_matrix()),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
@ -58,11 +58,11 @@ impl Skeleton for QuadrupedSkeleton {
}
fn interpolate(&mut self, target: &Self) {
self.head.interpolate(&target.head);
self.chest.interpolate(&target.chest);
self.lf_leg.interpolate(&target.lf_leg);
self.rf_leg.interpolate(&target.rf_leg);
self.lb_leg.interpolate(&target.lb_leg);
self.rb_leg.interpolate(&target.rb_leg);
self.pighead.interpolate(&target.pighead);
self.pigchest.interpolate(&target.pigchest);
self.piglf_leg.interpolate(&target.piglf_leg);
self.pigrf_leg.interpolate(&target.pigrf_leg);
self.piglb_leg.interpolate(&target.piglb_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 wave_dip = (wave_slow.abs() - 0.5).abs();
next.head.offset = Vec3::new(5.5, 2.0, 11.0 + wavecos * 1.3);
next.head.ori = Quaternion::rotation_x(0.15);
next.head.scale = Vec3::one();
next.pighead.offset = Vec3::new(5.5, 2.0, 11.0 + wavecos * 1.3);
next.pighead.ori = Quaternion::rotation_x(0.15);
next.pighead.scale = Vec3::one();
next.chest.offset = Vec3::new(5.5, 0.0, 7.0 + wavecos * 1.1);
next.chest.ori = Quaternion::rotation_z(wave * 0.1);
next.chest.scale = Vec3::one();
next.pigchest.offset = Vec3::new(5.5, 0.0, 7.0 + wavecos * 1.1);
next.pigchest.ori = Quaternion::rotation_z(wave * 0.1);
next.pigchest.scale = Vec3::one();
next.lf_leg.offset = Vec3::new(5.5, 0.0, 5.0 + wavecos * 1.1);
next.lf_leg.ori = Quaternion::rotation_z(wave * 0.25);
next.lf_leg.scale = Vec3::one();
next.piglf_leg.offset = Vec3::new(5.5, 0.0, 5.0 + wavecos * 1.1);
next.piglf_leg.ori = Quaternion::rotation_z(wave * 0.25);
next.piglf_leg.scale = Vec3::one();
next.rf_leg.offset = Vec3::new(5.5, 0.0, 2.0 + wavecos * 1.1);
next.rf_leg.ori = Quaternion::rotation_z(wave * 0.6);
next.rf_leg.scale = Vec3::one();
next.pigrf_leg.offset = Vec3::new(5.5, 0.0, 2.0 + wavecos * 1.1);
next.pigrf_leg.ori = Quaternion::rotation_z(wave * 0.6);
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.lb_leg.ori = Quaternion::rotation_x(wavecos * 0.9);
next.lb_leg.scale = Vec3::one();
next.piglb_leg.offset = Vec3::new(-6.0, 0.0 + wavecos * 2.5, 11.0 - wave * 1.5);
next.piglb_leg.ori = Quaternion::rotation_x(wavecos * 0.9);
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.rb_leg.ori = Quaternion::rotation_x(wavecos * -0.9);
next.rb_leg.scale = Vec3::one();
next.pigrb_leg.offset = Vec3::new(9.0, 0.0 - wavecos * 2.5, 11.0 + wave * 1.5);
next.pigrb_leg.ori = Quaternion::rotation_x(wavecos * -0.9);
next.pigrb_leg.scale = Vec3::one();
next
}

View File

@ -1,7 +1,7 @@
use crate::{
anim::{
character::{CharacterSkeleton, IdleAnimation, JumpAnimation, RunAnimation},
quadruped::{QuadrupedSkeleton},
quadruped::{QuadrupedSkeleton,},
Animation, Skeleton,
},
mesh::Meshable,
@ -15,8 +15,8 @@ use common::{
assets,
comp::{
self,
actor::{Belt, Chest, Foot, Hand, Head, Pants, Shoulder, Weapon},
Body, HumanoidBody,
actor::{Belt, Chest, Foot, Hand, Head, Pants, Shoulder, Weapon, Pighead, Pigchest, Pigleg_l, Pigleg_r},
Body, HumanoidBody, QuadrupedBody
},
figure::Segment,
msg,
@ -71,13 +71,13 @@ impl FigureModelCache {
None,
None,
],
Body::Quadruped(body) => [ // TODO
None,
None,
None,
None,
None,
None,
Body::Quadruped(body) => [
Some(Self::load_pighead(body.pighead)),
Some(Self::load_pigchest(body.pigchest)),
Some(Self::load_piglf_leg(body.pigleg_l)),
Some(Self::load_pigrf_leg(body.pigleg_r)),
Some(Self::load_piglb_leg(body.pigleg_l)),
Some(Self::load_pigrb_leg(body.pigleg_r)),
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 {
model_cache: FigureModelCache,
character_states: HashMap<EcsEntity, FigureState<CharacterSkeleton>>,
@ -305,7 +360,13 @@ impl FigureMgr {
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);
},