Symmetry of dragon skeleton

This commit is contained in:
Snowram 2020-05-03 00:55:14 +02:00 committed by jshipsey
parent edcde84505
commit 33f8a47cfa
30 changed files with 236 additions and 191 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,116 +1,114 @@
pub mod fly;
pub mod idle;
pub mod jump;
pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
pub use self::{fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use common::comp::{self};
use vek::Vec3;
#[derive(Clone)]
pub struct BipedLargeSkeleton {
head: Bone,
upper_torso: Bone,
lower_torso: Bone,
shoulder_l: Bone,
shoulder_r: Bone,
hand_l: Bone,
hand_r: Bone,
leg_l: Bone,
leg_r: Bone,
foot_l: Bone,
foot_r: Bone,
torso: Bone,
#[derive(Clone, Default)]
pub struct DragonSkeleton {
head_upper: Bone,
head_lower: Bone,
jaw: Bone,
chest_front: Bone,
chest_rear: Bone,
tail_front: Bone,
tail_rear: Bone,
wing_in_l: Bone,
wing_in_r: Bone,
wing_out_l: Bone,
wing_out_r: Bone,
foot_fl: Bone,
foot_fr: Bone,
foot_bl: Bone,
foot_br: Bone,
}
impl BipedLargeSkeleton {
pub fn new() -> Self {
Self {
head: Bone::default(),
upper_torso: Bone::default(),
lower_torso: Bone::default(),
shoulder_l: Bone::default(),
shoulder_r: Bone::default(),
hand_l: Bone::default(),
hand_r: Bone::default(),
leg_l: Bone::default(),
leg_r: Bone::default(),
foot_l: Bone::default(),
foot_r: Bone::default(),
torso: Bone::default(),
}
}
impl DragonSkeleton {
pub fn new() -> Self { Self::default() }
}
impl Skeleton for BipedLargeSkeleton {
impl Skeleton for DragonSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 11 }
fn bone_count(&self) -> usize { 15 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let upper_torso_mat = self.upper_torso.compute_base_matrix();
let shoulder_l_mat = self.shoulder_l.compute_base_matrix();
let shoulder_r_mat = self.shoulder_r.compute_base_matrix();
let leg_l_mat = self.leg_l.compute_base_matrix();
let leg_r_mat = self.leg_r.compute_base_matrix();
let torso_mat = self.torso.compute_base_matrix();
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let head_upper_mat = self.head_upper.compute_base_matrix();
let head_lower_mat = self.head_lower.compute_base_matrix();
let chest_front_mat = self.chest_front.compute_base_matrix();
let chest_rear_mat = self.chest_rear.compute_base_matrix();
let wing_in_l_mat = self.wing_in_l.compute_base_matrix();
let wing_in_r_mat = self.wing_in_r.compute_base_matrix();
let tail_front_mat = self.tail_front.compute_base_matrix();
(
[
FigureBoneData::new(torso_mat * upper_torso_mat * self.head.compute_base_matrix()),
FigureBoneData::new(torso_mat * upper_torso_mat),
FigureBoneData::new(
torso_mat * upper_torso_mat * self.lower_torso.compute_base_matrix(),
),
FigureBoneData::new(torso_mat * upper_torso_mat * shoulder_l_mat),
FigureBoneData::new(torso_mat * upper_torso_mat * shoulder_r_mat),
FigureBoneData::new(
torso_mat * upper_torso_mat * self.hand_l.compute_base_matrix(),
),
FigureBoneData::new(
torso_mat * upper_torso_mat * self.hand_r.compute_base_matrix(),
),
FigureBoneData::new(torso_mat * upper_torso_mat * leg_l_mat),
FigureBoneData::new(torso_mat * upper_torso_mat * leg_r_mat),
FigureBoneData::new(self.foot_l.compute_base_matrix()),
FigureBoneData::new(self.foot_r.compute_base_matrix()),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
],
Vec3::default(),
)
[
FigureBoneData::new(chest_front_mat * head_lower_mat * head_upper_mat),
FigureBoneData::new(chest_front_mat * head_lower_mat),
FigureBoneData::new(
chest_front_mat * head_lower_mat * head_upper_mat * self.jaw.compute_base_matrix(),
),
FigureBoneData::new(chest_front_mat),
FigureBoneData::new(chest_front_mat * self.chest_rear.compute_base_matrix()),
FigureBoneData::new(chest_front_mat * chest_rear_mat * tail_front_mat),
FigureBoneData::new(
chest_front_mat
* chest_rear_mat
* tail_front_mat
* self.tail_rear.compute_base_matrix(),
),
FigureBoneData::new(chest_front_mat * self.wing_in_l.compute_base_matrix()),
FigureBoneData::new(chest_front_mat * self.wing_in_r.compute_base_matrix()),
FigureBoneData::new(
chest_front_mat * wing_in_l_mat * self.wing_out_l.compute_base_matrix(),
),
FigureBoneData::new(
chest_front_mat * wing_in_r_mat * self.wing_out_r.compute_base_matrix(),
),
FigureBoneData::new(self.foot_fl.compute_base_matrix()),
FigureBoneData::new(self.foot_fr.compute_base_matrix()),
FigureBoneData::new(self.foot_bl.compute_base_matrix()),
FigureBoneData::new(self.foot_br.compute_base_matrix()),
FigureBoneData::default(),
]
}
fn interpolate(&mut self, target: &Self, dt: f32) {
self.head.interpolate(&target.head, dt);
self.upper_torso.interpolate(&target.upper_torso, dt);
self.lower_torso.interpolate(&target.lower_torso, dt);
self.shoulder_l.interpolate(&target.shoulder_l, dt);
self.shoulder_r.interpolate(&target.shoulder_r, dt);
self.hand_l.interpolate(&target.hand_l, dt);
self.hand_r.interpolate(&target.hand_r, dt);
self.leg_l.interpolate(&target.leg_l, dt);
self.leg_r.interpolate(&target.leg_r, dt);
self.foot_l.interpolate(&target.foot_l, dt);
self.foot_r.interpolate(&target.foot_r, dt);
self.torso.interpolate(&target.torso, dt);
self.head_upper.interpolate(&target.head_upper, dt);
self.head_lower.interpolate(&target.head_lower, dt);
self.jaw.interpolate(&target.jaw, dt);
self.chest_front.interpolate(&target.chest_front, dt);
self.chest_rear.interpolate(&target.chest_rear, dt);
self.tail_front.interpolate(&target.tail_front, dt);
self.tail_rear.interpolate(&target.tail_rear, dt);
self.wing_in_l.interpolate(&target.wing_in_l, dt);
self.wing_in_r.interpolate(&target.wing_in_r, dt);
self.wing_out_l.interpolate(&target.wing_out_l, dt);
self.wing_out_r.interpolate(&target.wing_out_r, dt);
self.foot_fl.interpolate(&target.foot_fl, dt);
self.foot_fr.interpolate(&target.foot_fr, dt);
self.foot_bl.interpolate(&target.foot_bl, dt);
self.foot_br.interpolate(&target.foot_br, dt);
}
}
pub struct SkeletonAttr {
head: (f32, f32),
upper_torso: (f32, f32),
lower_torso: (f32, f32),
shoulder: (f32, f32, f32),
hand: (f32, f32, f32),
leg: (f32, f32, f32),
foot: (f32, f32, f32),
head_upper: (f32, f32),
head_lower: (f32, f32),
jaw: (f32, f32),
chest_front: (f32, f32),
chest_rear: (f32, f32),
tail_front: (f32, f32),
tail_rear: (f32, f32),
wing_in: (f32, f32, f32),
wing_out: (f32, f32, f32),
feet_f: (f32, f32, f32),
feet_b: (f32, f32, f32),
height: f32,
}
impl<'a> std::convert::TryFrom<&'a comp::Body> for SkeletonAttr {
@ -118,7 +116,7 @@ impl<'a> std::convert::TryFrom<&'a comp::Body> for SkeletonAttr {
fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
match body {
comp::Body::BipedLarge(body) => Ok(SkeletonAttr::from(body)),
comp::Body::Dragon(body) => Ok(SkeletonAttr::from(body)),
_ => Err(()),
}
}
@ -127,41 +125,61 @@ impl<'a> std::convert::TryFrom<&'a comp::Body> for SkeletonAttr {
impl Default for SkeletonAttr {
fn default() -> Self {
Self {
head: (0.0, 0.0),
upper_torso: (0.0, 0.0),
lower_torso: (0.0, 0.0),
shoulder: (0.0, 0.0, 0.0),
hand: (0.0, 0.0, 0.0),
leg: (0.0, 0.0, 0.0),
foot: (0.0, 0.0, 0.0),
head_upper: (0.0, 0.0),
head_lower: (0.0, 0.0),
jaw: (0.0, 0.0),
chest_front: (0.0, 0.0),
chest_rear: (0.0, 0.0),
tail_front: (0.0, 0.0),
tail_rear: (0.0, 0.0),
wing_in: (0.0, 0.0, 0.0),
wing_out: (0.0, 0.0, 0.0),
feet_f: (0.0, 0.0, 0.0),
feet_b: (0.0, 0.0, 0.0),
height: (0.0),
}
}
}
impl<'a> From<&'a comp::biped_large::Body> for SkeletonAttr {
fn from(body: &'a comp::biped_large::Body) -> Self {
use comp::biped_large::Species::*;
impl<'a> From<&'a comp::dragon::Body> for SkeletonAttr {
fn from(body: &'a comp::dragon::Body) -> Self {
use comp::dragon::Species::*;
Self {
head: match (body.species, body.body_type) {
(Ogre, _) => (3.0, 6.0),
head_upper: match (body.species, body.body_type) {
(Reddragon, _) => (2.5, 4.5),
},
upper_torso: match (body.species, body.body_type) {
(Ogre, _) => (0.0, 20.0),
head_lower: match (body.species, body.body_type) {
(Reddragon, _) => (7.5, 3.5),
},
lower_torso: match (body.species, body.body_type) {
(Ogre, _) => (1.0, -9.5),
jaw: match (body.species, body.body_type) {
(Reddragon, _) => (7.0, -5.0),
},
shoulder: match (body.species, body.body_type) {
(Ogre, _) => (6.1, 0.5, 2.5),
chest_front: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 14.0),
},
hand: match (body.species, body.body_type) {
(Ogre, _) => (10.5, -1.0, 0.5),
chest_rear: match (body.species, body.body_type) {
(Reddragon, _) => (-12.5, 0.0),
},
leg: match (body.species, body.body_type) {
(Ogre, _) => (0.0, 0.0, -6.0),
tail_front: match (body.species, body.body_type) {
(Reddragon, _) => (-6.5, 1.5),
},
foot: match (body.species, body.body_type) {
(Ogre, _) => (4.0, 0.5, 2.5),
tail_rear: match (body.species, body.body_type) {
(Reddragon, _) => (-11.5, -1.0),
},
wing_in: match (body.species, body.body_type) {
(Reddragon, _) => (2.5, -16.5, 0.0),
},
wing_out: match (body.species, body.body_type) {
(Reddragon, _) => (23.0, 0.5, 4.0),
},
feet_f: match (body.species, body.body_type) {
(Reddragon, _) => (6.0, 0.0, 1.5),
},
feet_b: match (body.species, body.body_type) {
(Reddragon, _) => (6.0, -15.0, 3.0),
},
height: match (body.species, body.body_type) {
(Reddragon, _) => (1.0),
},
}
}

View File

@ -1,6 +1,7 @@
use super::{super::Animation, DragonSkeleton, SkeletonAttr};
//use std::{f32::consts::PI, ops::Mul};
use vek::*;
pub struct IdleAnimation;
impl Animation for IdleAnimation {
@ -16,45 +17,49 @@ impl Animation for IdleAnimation {
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const HEAD_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const HEAD_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_F_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_F_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_R_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_R_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_F_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_F_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_R_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_R_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_X: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -100.0, max = 20.0, step = 0.5)]
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_Z: f32 = 0.0;
next.head.offset = Vec3::new(0.0, *HEAD_X, *HEAD_Z);
@ -77,19 +82,19 @@ impl Animation for IdleAnimation {
next.tail_rear.ori = Quaternion::rotation_x(0.0);
next.tail_rear.scale = Vec3::one() * 1.01;
next.wing_in_l.offset = Vec3::new(0.0, *WING_IN_X, *WING_IN_Z);
next.wing_in_l.offset = Vec3::new(*WING_IN_X, *WING_IN_Y, *WING_IN_Z);
next.wing_in_l.ori = Quaternion::rotation_x(0.0);
next.wing_in_l.scale = Vec3::one() * 1.01;
next.wing_in_r.offset = Vec3::new(0.0, *WING_IN_X, *WING_IN_Z);
next.wing_in_r.offset = Vec3::new(-*WING_IN_X, *WING_IN_Y, *WING_IN_Z);
next.wing_in_r.ori = Quaternion::rotation_x(0.0);
next.wing_in_r.scale = Vec3::one() * 1.01;
next.wing_out_l.offset = Vec3::new(0.0, *WING_OUT_X, *WING_OUT_Z);
next.wing_out_l.offset = Vec3::new(*WING_OUT_X, *WING_OUT_Y, *WING_OUT_Z);
next.wing_out_l.ori = Quaternion::rotation_x(0.0);
next.wing_out_l.scale = Vec3::one() * 1.01;
next.wing_out_r.offset = Vec3::new(0.0, *WING_OUT_X, *WING_OUT_Z);
next.wing_out_r.offset = Vec3::new(-*WING_OUT_X, *WING_OUT_Y, *WING_OUT_Z);
next.wing_out_r.ori = Quaternion::rotation_x(0.0);
next.wing_out_r.scale = Vec3::one() * 1.01;
@ -97,7 +102,7 @@ impl Animation for IdleAnimation {
next.foot_fl.ori = Quaternion::rotation_x(0.0);
next.foot_fl.scale = Vec3::one() * 1.01;
next.foot_fr.offset = Vec3::new(*FEET_F_X, *FEET_F_Y, *FEET_F_Z);
next.foot_fr.offset = Vec3::new(-*FEET_F_X, *FEET_F_Y, *FEET_F_Z);
next.foot_fr.ori = Quaternion::rotation_x(0.0);
next.foot_fr.scale = Vec3::one() * 1.01;
@ -105,7 +110,7 @@ impl Animation for IdleAnimation {
next.foot_bl.ori = Quaternion::rotation_x(0.0);
next.foot_bl.scale = Vec3::one() * 1.01;
next.foot_br.offset = Vec3::new(*FEET_F_X, *FEET_B_Y, *FEET_B_Z);
next.foot_br.offset = Vec3::new(-*FEET_F_X, *FEET_B_Y, *FEET_B_Z);
next.foot_br.ori = Quaternion::rotation_x(0.0);
next.foot_br.scale = Vec3::one() * 1.01;
next

View File

@ -38,10 +38,12 @@ impl Skeleton for DragonSkeleton {
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let chest_front_mat = self.chest_front.compute_base_matrix();
let chest_rear_mat = self.chest_rear.compute_base_matrix();
let wing_in_l_mat = self.wing_in_l.compute_base_matrix();
let wing_in_r_mat = self.wing_in_r.compute_base_matrix();
let tail_front_mat = self.tail_front.compute_base_matrix();
<<<<<<< HEAD
(
[
FigureBoneData::new(self.head.compute_base_matrix() * chest_front_mat),
@ -63,6 +65,26 @@ impl Skeleton for DragonSkeleton {
],
Vec3::default(),
)
=======
[
FigureBoneData::new(self.head.compute_base_matrix() * chest_front_mat),
FigureBoneData::new(chest_front_mat),
FigureBoneData::new(self.chest_rear.compute_base_matrix() * chest_front_mat),
FigureBoneData::new(chest_rear_mat * self.tail_front.compute_base_matrix()),
FigureBoneData::new(self.tail_rear.compute_base_matrix() * tail_front_mat),
FigureBoneData::new(chest_front_mat * self.wing_in_l.compute_base_matrix()),
FigureBoneData::new(chest_front_mat * self.wing_in_r.compute_base_matrix()),
FigureBoneData::new(self.wing_out_l.compute_base_matrix() * wing_in_l_mat),
FigureBoneData::new(self.wing_out_r.compute_base_matrix() * wing_in_r_mat),
FigureBoneData::new(self.foot_fl.compute_base_matrix()),
FigureBoneData::new(self.foot_fr.compute_base_matrix()),
FigureBoneData::new(self.foot_bl.compute_base_matrix()),
FigureBoneData::new(self.foot_br.compute_base_matrix()),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
]
>>>>>>> Symmetry of dragon skeleton
}
fn interpolate(&mut self, target: &Self, dt: f32) {
@ -88,8 +110,8 @@ pub struct SkeletonAttr {
chest_rear: (f32, f32),
tail_front: (f32, f32),
tail_rear: (f32, f32),
wing_in: (f32, f32),
wing_out: (f32, f32),
wing_in: (f32, f32, f32),
wing_out: (f32, f32, f32),
feet_f: (f32, f32, f32),
feet_b: (f32, f32, f32),
}
@ -113,8 +135,8 @@ impl Default for SkeletonAttr {
chest_rear: (0.0, 0.0),
tail_front: (0.0, 0.0),
tail_rear: (0.0, 0.0),
wing_in: (0.0, 0.0),
wing_out: (0.0, 0.0),
wing_in: (0.0, 0.0, 0.0),
wing_out: (0.0, 0.0, 0.0),
feet_f: (0.0, 0.0, 0.0),
feet_b: (0.0, 0.0, 0.0),
}
@ -141,10 +163,10 @@ impl<'a> From<&'a comp::dragon::Body> for SkeletonAttr {
(Reddragon, _) => (0.0, 0.0),
},
wing_in: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0),
(Reddragon, _) => (0.0, 0.0, 0.0),
},
wing_out: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0),
(Reddragon, _) => (0.0, 0.0, 0.0),
},
feet_f: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0, 0.0),

View File

@ -21,7 +21,7 @@ use crate::{
util::{Grid, Sampler},
};
use common::{
comp::{self, bird_medium, critter, quadruped_medium, quadruped_small, dragon},
comp::{self, bird_medium, critter, quadruped_medium, quadruped_small},
generation::{ChunkSupplement, EntityInfo},
terrain::{Block, BlockKind, TerrainChunk, TerrainChunkMeta, TerrainChunkSize},
vol::{ReadVol, RectVolSize, Vox, WriteVol},