Improves fish_small, new npc

This commit is contained in:
Snowram 2020-11-29 17:22:13 +01:00
parent 80fbf6e225
commit 6f200ffe93
26 changed files with 132 additions and 107 deletions

View File

@ -686,7 +686,7 @@
"species": {
"reddragon": {
"keyword": "reddragon",
"generic": "Reddragon"
"generic": "Red Dragon"
}
}
},
@ -705,9 +705,9 @@
]
},
"species": {
"sardine": {
"keyword": "sardine",
"generic": "Sardine"
"clownfish": {
"keyword": "clownfish",
"generic": "Clownfish"
}
}
},

View File

@ -1,30 +1,22 @@
({
(Sardine, Male): (
head: (
offset: (-4.0, 0.0, -3.0),
central: ("npc.sardine.male.head"),
),
(Clownfish, Male): (
chest: (
offset: (-5.0, -7.5, -3.0),
central: ("npc.sardine.male.chest"),
offset: (-1.5, -7.5, -5.0),
central: ("npc.clownfish.male.chest"),
),
tail: (
offset: (-1.0, -9.0, -1.5),
central: ("npc.sardine.male.tail"),
offset: (-0.5, -5.0, -2.5),
central: ("npc.clownfish.male.tail"),
),
),
(Sardine, Female): (
head: (
offset: (-4.0, 0.0, -3.0),
central: ("npc.sardine.male.head"),
),
(Clownfish, Female): (
chest: (
offset: (-5.0, -7.5, -3.0),
central: ("npc.sardine.male.chest"),
offset: (-1.5, -7.5, -5.0),
central: ("npc.clownfish.male.chest"),
),
tail: (
offset: (-1.0, -9.0, -1.5),
central: ("npc.sardine.male.tail"),
offset: (-0.5, -5.0, -2.5),
central: ("npc.clownfish.male.tail"),
),
),
})

View File

@ -1,22 +1,22 @@
({
(Sardine, Male): (
(Clownfish, Male): (
fin_l: (
offset: (-1.5, -5.0, -3.0),
lateral: ("npc.sardine.male.fin_l"),
offset: (-0.5, -3.0, -4.0),
lateral: ("npc.clownfish.male.fin_l"),
),
fin_r: (
offset: (-1.5, -5.0, -3.0),
lateral: ("npc.sardine.male.fin_r"),
offset: (-0.5, -3.0, -4.0),
lateral: ("npc.clownfish.male.fin_r"),
),
),
(Sardine, Female): (
(Clownfish, Female): (
fin_l: (
offset: (-1.5, -5.0, -3.0),
lateral: ("npc.sardine.male.fin_l"),
offset: (-0.5, -3.0, -4.0),
lateral: ("npc.clownfish.male.fin_l"),
),
fin_r: (
offset: (-1.5, -5.0, -3.0),
lateral: ("npc.sardine.male.fin_r"),
offset: (-0.5, -3.0, -4.0),
lateral: ("npc.clownfish.male.fin_r"),
),
),
})

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -87,7 +87,7 @@ impl<BodyMeta, SpeciesMeta> core::ops::Index<NpcKind> for AllBodies<BodyMeta, Sp
NpcKind::Pig => &self.quadruped_small.body,
NpcKind::Wolf => &self.quadruped_medium.body,
NpcKind::Duck => &self.bird_medium.body,
NpcKind::Sardine => &self.fish_medium.body,
NpcKind::Clownfish => &self.fish_medium.body,
NpcKind::Marlin => &self.fish_small.body,
NpcKind::Ogre => &self.biped_large.body,
NpcKind::StoneGolem => &self.golem.body,

View File

@ -34,7 +34,7 @@ make_case_elim!(
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum Species {
Sardine = 0,
Clownfish = 0,
}
);
@ -43,7 +43,7 @@ make_case_elim!(
/// NOTE: Deliberately don't (yet?) implement serialize.
#[derive(Clone, Debug, Deserialize)]
pub struct AllSpecies<SpeciesMeta> {
pub sardine: SpeciesMeta,
pub clownfish: SpeciesMeta,
}
impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies<SpeciesMeta> {
@ -52,12 +52,12 @@ impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies<SpeciesMeta>
#[inline]
fn index(&self, &index: &'a Species) -> &Self::Output {
match index {
Species::Sardine => &self.sardine,
Species::Clownfish => &self.clownfish,
}
}
}
pub const ALL_SPECIES: [Species; 1] = [Species::Sardine];
pub const ALL_SPECIES: [Species; 1] = [Species::Clownfish];
impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies<SpeciesMeta> {
type IntoIter = std::iter::Copied<std::slice::Iter<'static, Self::Item>>;

View File

@ -13,7 +13,7 @@ pub enum NpcKind {
Wolf,
Pig,
Duck,
Sardine,
Clownfish,
Marlin,
Ogre,
Archaeos,
@ -27,7 +27,7 @@ pub const ALL_NPCS: [NpcKind; 11] = [
NpcKind::Wolf,
NpcKind::Pig,
NpcKind::Duck,
NpcKind::Sardine,
NpcKind::Clownfish,
NpcKind::Marlin,
NpcKind::Ogre,
NpcKind::Archaeos,
@ -97,7 +97,7 @@ pub fn kind_to_body(kind: NpcKind) -> Body {
NpcKind::Pig => comp::quadruped_small::Body::random().into(),
NpcKind::Wolf => comp::quadruped_medium::Body::random().into(),
NpcKind::Duck => comp::bird_medium::Body::random().into(),
NpcKind::Sardine => comp::fish_small::Body::random().into(),
NpcKind::Clownfish => comp::fish_small::Body::random().into(),
NpcKind::Marlin => comp::fish_medium::Body::random().into(),
NpcKind::Ogre => comp::biped_large::Body::random().into(),
NpcKind::Archaeos => comp::theropod::Body::random().into(),
@ -204,7 +204,7 @@ impl NpcBody {
.or_else(|| {
parse(
s,
NpcKind::Sardine,
NpcKind::Clownfish,
&npc_names.fish_small,
comp::fish_small::Body::random_with,
)

View File

@ -22,7 +22,6 @@ impl Animation for IdleAnimation {
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let slower = (anim_time as f32 * 1.0 + PI).sin();
let slow = (anim_time as f32 * 3.5 + PI).sin();
let slowalt = (anim_time as f32 * 3.5 + PI + 0.2).sin();

View File

@ -21,10 +21,7 @@ impl Animation for IdleAnimation {
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
next.head.scale = Vec3::one() / 11.0;
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
next.head.orientation = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
next.chest.scale = Vec3::one() / 11.0;
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
next.chest.orientation = Quaternion::rotation_x(0.0);

View File

@ -21,10 +21,7 @@ impl Animation for JumpAnimation {
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
next.head.scale = Vec3::one() / 11.0;
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
next.head.orientation = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
next.chest.scale = Vec3::one() / 11.0;
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
next.chest.orientation = Quaternion::rotation_x(0.0);

View File

@ -2,9 +2,13 @@ pub mod idle;
pub mod jump;
pub mod run;
pub mod swim;
pub mod swimidle;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation, swim::SwimAnimation};
pub use self::{
idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation, swim::SwimAnimation,
swimidle::SwimIdleAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use common::comp::{self};
@ -13,7 +17,6 @@ use core::convert::TryFrom;
pub type Body = comp::fish_small::Body;
skeleton_impls!(struct FishSmallSkeleton {
+ head,
+ chest,
+ tail,
+ fin_l,
@ -24,7 +27,7 @@ impl Skeleton for FishSmallSkeleton {
type Attr = SkeletonAttr;
type Body = Body;
const BONE_COUNT: usize = 5;
const BONE_COUNT: usize = 4;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"fish_small_compute_mats\0";
@ -37,7 +40,6 @@ impl Skeleton for FishSmallSkeleton {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
make_bone(chest_mat * Mat4::<f32>::from(self.head)),
make_bone(chest_mat),
make_bone(chest_mat * Mat4::<f32>::from(self.tail)),
make_bone(chest_mat * Mat4::<f32>::from(self.fin_l)),
@ -48,7 +50,6 @@ impl Skeleton for FishSmallSkeleton {
}
pub struct SkeletonAttr {
head: (f32, f32),
chest: (f32, f32),
tail: (f32, f32),
fin: (f32, f32, f32),
@ -68,7 +69,6 @@ impl<'a> std::convert::TryFrom<&'a comp::Body> for SkeletonAttr {
impl Default for SkeletonAttr {
fn default() -> Self {
Self {
head: (0.0, 0.0),
chest: (0.0, 0.0),
tail: (0.0, 0.0),
fin: (0.0, 0.0, 0.0),
@ -80,17 +80,14 @@ impl<'a> From<&'a Body> for SkeletonAttr {
fn from(body: &'a Body) -> Self {
use comp::fish_small::Species::*;
Self {
head: match (body.species, body.body_type) {
(Sardine, _) => (1.5, 2.0),
},
chest: match (body.species, body.body_type) {
(Sardine, _) => (0.0, 5.0),
(Clownfish, _) => (0.0, 5.0),
},
tail: match (body.species, body.body_type) {
(Sardine, _) => (-6.0, 0.0),
(Clownfish, _) => (-7.5, -0.5),
},
fin: match (body.species, body.body_type) {
(Sardine, _) => (3.5, 6.0, -1.0),
(Clownfish, _) => (2.0, 0.5, 1.0),
},
}
}

View File

@ -21,10 +21,7 @@ impl Animation for RunAnimation {
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
next.head.scale = Vec3::one() / 11.0;
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
next.head.orientation = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
next.chest.scale = Vec3::one() / 11.0;
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
next.chest.orientation = Quaternion::rotation_x(0.0);

View File

@ -19,15 +19,13 @@ impl Animation for SwimAnimation {
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(velocity, orientation, last_ori, global_time, avg_vel): Self::Dependency,
(velocity, orientation, last_ori, _global_time, avg_vel): Self::Dependency,
anim_time: f64,
rate: &mut f32,
_rate: &mut f32,
s_a: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let slower = (anim_time as f32 * 1.0 + PI).sin();
let slow = (anim_time as f32 * 3.5 + PI).sin();
let slowalt = (anim_time as f32 * 3.5 + PI + 0.2).sin();
let fast = (anim_time as f32 * 5.5 + PI).sin();
let fastalt = (anim_time as f32 * 5.5 + PI + 0.2).sin();
@ -48,8 +46,6 @@ impl Animation for SwimAnimation {
let abstilt = tilt.abs();
let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude());
let squash = if abstilt > 0.2 { 0.35 } else { 1.0 }; //condenses the body at strong turns
next.chest_front.scale = Vec3::one() / 11.0;
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);

View File

@ -2,7 +2,7 @@ use super::{
super::{vek::*, Animation},
FishMediumSkeleton, SkeletonAttr,
};
use std::{f32::consts::PI, ops::Mul};
use std::f32::consts::PI;
pub struct SwimIdleAnimation;
@ -19,14 +19,13 @@ impl Animation for SwimIdleAnimation {
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(velocity, orientation, last_ori, global_time, avg_vel): Self::Dependency,
(_velocity, _orientation, _last_ori, _global_time, _avg_vel): Self::Dependency,
anim_time: f64,
rate: &mut f32,
_rate: &mut f32,
s_a: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let slower = (anim_time as f32 * 1.0 + PI).sin();
let slow = (anim_time as f32 * 3.5 + PI).sin();
let slowalt = (anim_time as f32 * 3.5 + PI + 0.2).sin();

View File

@ -2,6 +2,7 @@ use super::{
super::{vek::*, Animation},
FishSmallSkeleton, SkeletonAttr,
};
use std::f32::consts::PI;
pub struct SwimAnimation;
@ -18,29 +19,45 @@ impl Animation for SwimAnimation {
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(velocity, orientation, last_ori, global_time, avg_vel): Self::Dependency,
_anim_time: f64,
(velocity, orientation, last_ori, _global_time, avg_vel): Self::Dependency,
anim_time: f64,
_rate: &mut f32,
s_a: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
next.head.scale = Vec3::one() / 11.0;
let fast = (anim_time as f32 * 7.0 + PI).sin();
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
next.head.orientation = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori);
let tilt = if ::vek::Vec2::new(ori, last_ori)
.map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite())
.reduce_and()
&& ori.angle_between(last_ori).is_finite()
{
ori.angle_between(last_ori).min(0.8)
* last_ori.determine_side(Vec2::zero(), ori).signum()
} else {
0.0
} * 1.3;
let abstilt = tilt.abs();
let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude());
next.chest.scale = Vec3::one() / 11.0;
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
next.chest.orientation = Quaternion::rotation_x(0.0);
next.chest.orientation = Quaternion::rotation_z(fast * -0.1)
+ Quaternion::rotation_x(velocity.z.abs() * -0.005 + abstilt * 1.0 + x_tilt);
next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
next.tail.orientation = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
next.tail.orientation = Quaternion::rotation_z(fast * 0.3 + tilt * 2.0);
next.fin_l.position = Vec3::new(-s_a.fin.0, s_a.fin.1, s_a.fin.2);
next.fin_l.orientation = Quaternion::rotation_y(0.0);
next.fin_l.orientation = Quaternion::rotation_z(fast * 0.3 - 0.3 + tilt * -0.5);
next.fin_r.position = Vec3::new(s_a.fin.0, s_a.fin.1, s_a.fin.2);
next.fin_r.orientation = Quaternion::rotation_y(0.0);
next.fin_r.orientation = Quaternion::rotation_z(-fast * 0.3 + 0.3 + tilt * -0.5);
next
}
}

View File

@ -0,0 +1,46 @@
use super::{
super::{vek::*, Animation},
FishSmallSkeleton, SkeletonAttr,
};
use std::f32::consts::PI;
pub struct SwimIdleAnimation;
type SwimIdleAnimationDependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64, Vec3<f32>);
impl Animation for SwimIdleAnimation {
type Dependency = SwimIdleAnimationDependency;
type Skeleton = FishSmallSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"fish_small_swimidle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_swimidle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _orientation, _last_ori, _global_time, _avg_vel): Self::Dependency,
anim_time: f64,
_rate: &mut f32,
s_a: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let slow = (anim_time as f32 * 3.5 + PI).sin();
next.chest.scale = Vec3::one() / 11.0;
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
next.chest.orientation = Quaternion::rotation_x(0.0);
next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
next.tail.orientation = Quaternion::rotation_z(slow * 0.1);
next.fin_l.position = Vec3::new(-s_a.fin.0, s_a.fin.1, s_a.fin.2);
next.fin_l.orientation = Quaternion::rotation_z(slow * 0.1 - 0.1);
next.fin_r.position = Vec3::new(s_a.fin.0, s_a.fin.1, s_a.fin.2);
next.fin_r.orientation = Quaternion::rotation_z(-slow * 0.1 + 0.1);
next
}
}

View File

@ -2287,7 +2287,6 @@ struct FishSmallCentralSpec(HashMap<(FSSpecies, FSBodyType), SidedFSCentralVoxSp
#[derive(Deserialize)]
struct SidedFSCentralVoxSpec {
head: FishSmallCentralSubSpec,
chest: FishSmallCentralSubSpec,
tail: FishSmallCentralSubSpec,
}
@ -2317,10 +2316,6 @@ make_vox_spec!(
},
|FigureKey { body, .. }, spec| {
[
Some(spec.central.asset.mesh_head(
body.species,
body.body_type,
)),
Some(spec.central.asset.mesh_chest(
body.species,
body.body_type,
@ -2348,27 +2343,12 @@ make_vox_spec!(
None,
None,
None,
None,
]
},
);
impl FishSmallCentralSpec {
fn mesh_head(&self, species: FSSpecies, body_type: FSBodyType) -> BoneMeshes {
let spec = match self.0.get(&(species, body_type)) {
Some(spec) => spec,
None => {
error!(
"No head specification exists for the combination of {:?} and {:?}",
species, body_type
);
return load_mesh("not_found", Vec3::new(-5.0, -5.0, -2.5));
},
};
let central = graceful_load_segment(&spec.head.central.0);
(central, Vec3::from(spec.head.offset))
}
fn mesh_chest(&self, species: FSSpecies, body_type: FSBodyType) -> BoneMeshes {
let spec = match self.0.get(&(species, body_type)) {
Some(spec) => spec,

View File

@ -2605,8 +2605,16 @@ impl FigureMgr {
&mut state_animation_rate,
skeleton_attr,
),
// Idle Water
(_, false, true) => anim::fish_small::SwimIdleAnimation::update_skeleton(
&FishSmallSkeleton::default(),
(vel.0, ori, state.last_ori, time, state.avg_vel),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
),
// Swim
(_, _, true) => anim::fish_small::SwimAnimation::update_skeleton(
(_, true, true) => anim::fish_small::SwimAnimation::update_skeleton(
&FishSmallSkeleton::default(),
(vel.0, ori, state.last_ori, time, state.avg_vel),
state.state_time,