Merge branch 'imbris/hot-anim' into 'master'

Hotreloadable animations for improved iterative development

See merge request veloren/veloren!1094
This commit is contained in:
Songtronix 2020-06-19 06:46:45 +00:00
commit 362338876a
82 changed files with 1072 additions and 219 deletions

13
Cargo.lock generated
View File

@ -4594,11 +4594,24 @@ dependencies = [
"veloren-client",
"veloren-common",
"veloren-server",
"veloren-voxygen-anim",
"veloren-world",
"winit",
"winres",
]
[[package]]
name = "veloren-voxygen-anim"
version = "0.6.0"
dependencies = [
"lazy_static",
"libloading 0.6.2",
"log",
"notify",
"vek",
"veloren-common",
]
[[package]]
name = "veloren-world"
version = "0.6.0"

View File

@ -10,6 +10,7 @@ members = [
"voxygen",
"world",
"network",
"voxygen/src/anim"
]
# default profile for devs, fast to compile, okay enough to run, no debug information

View File

@ -12,6 +12,7 @@ default-run = "veloren-voxygen"
gl = ["gfx_device_gl"]
singleplayer = ["server"]
tweak = ["const-tweaker"]
hot-anim = ["anim/use-dyn-lib"]
default = ["gl", "singleplayer", "msgbox"]
@ -19,6 +20,8 @@ default = ["gl", "singleplayer", "msgbox"]
common = { package = "veloren-common", path = "../common" }
client = { package = "veloren-client", path = "../client" }
anim = { package = "veloren-voxygen-anim", path = "src/anim", default-features = false }
# Graphics
gfx = "0.18.2"
gfx_device_gl = { version = "0.16.2", optional = true }

View File

@ -0,0 +1,25 @@
[package]
name = "veloren-voxygen-anim"
version = "0.6.0"
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>", "Imbris <imbrisf@gmail.com>"]
edition = "2018"
[lib]
name = "voxygen_anim"
# Uncomment to use animation hot reloading
# Note: this breaks `cargo test`
#crate-type = ["lib", "cdylib"]
[features]
use-dyn-lib = ["libloading", "notify", "lazy_static", "log"]
be-dyn-lib = []
default = ["be-dyn-lib"]
[dependencies]
vek = { version = "0.11.2", features = ["serde"] }
common = { package = "veloren-common", path = "../../../common" }
libloading = { version = "0.6.2", optional = true }
notify = { version = "5.0.0-pre.2", optional = true }
lazy_static = { version = "1.4.0", optional = true }
log = { version = "0.4.8", optional = true }

View File

@ -1,75 +0,0 @@
pub mod biped_large;
pub mod bird_medium;
pub mod bird_small;
pub mod character;
pub mod critter;
pub mod dragon;
pub mod fish_medium;
pub mod fish_small;
pub mod fixture;
pub mod golem;
pub mod object;
pub mod quadruped_medium;
pub mod quadruped_small;
use crate::render::FigureBoneData;
use vek::*;
#[derive(Copy, Clone, Debug)]
pub struct Bone {
pub offset: Vec3<f32>,
pub ori: Quaternion<f32>,
pub scale: Vec3<f32>,
}
impl Default for Bone {
fn default() -> Self {
Self {
offset: Vec3::zero(),
ori: Quaternion::identity(),
scale: Vec3::broadcast(1.0 / 11.0),
}
}
}
impl Bone {
pub fn compute_base_matrix(&self) -> Mat4<f32> {
Mat4::<f32>::translation_3d(self.offset)
* Mat4::scaling_3d(self.scale)
* Mat4::from(self.ori)
}
/// Change the current bone to be more like `target`.
fn interpolate(&mut self, target: &Bone, dt: f32) {
// TODO: Make configurable.
let factor = (15.0 * dt).min(1.0);
self.offset += (target.offset - self.offset) * factor;
self.ori = vek::Slerp::slerp(self.ori, target.ori, factor);
self.scale += (target.scale - self.scale) * factor;
}
}
pub trait Skeleton: Send + Sync + 'static {
type Attr;
fn bone_count(&self) -> usize { 16 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>);
/// Change the current skeleton to be more like `target`.
fn interpolate(&mut self, target: &Self, dt: f32);
}
pub trait Animation {
type Skeleton: Skeleton;
type Dependency;
/// Returns a new skeleton that is generated by the animation.
fn update_skeleton(
skeleton: &Self::Skeleton,
dependency: Self::Dependency,
anim_time: f64,
rate: &mut f32,
skeleton_attr: &<<Self as Animation>::Skeleton as Skeleton>::Attr,
) -> Self::Skeleton;
}

View File

@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = BipedLargeSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"biped_large_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
global_time: Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for JumpAnimation {
type Dependency = (f32, f64);
type Skeleton = BipedLargeSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"biped_large_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_jump")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -33,9 +32,13 @@ impl BipedLargeSkeleton {
impl Skeleton for BipedLargeSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"biped_large_compute_mats\0";
fn bone_count(&self) -> usize { 11 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_compute_mats")]
fn compute_matrices_inner(&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();

View File

@ -8,7 +8,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = BipedLargeSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"biped_large_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for FlyAnimation {
type Dependency = (f32, f64);
type Skeleton = BirdMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"bird_medium_fly\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_fly")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,12 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = BirdMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"bird_medium_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
global_time: Self::Dependency,
anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -28,9 +27,14 @@ impl BirdMediumSkeleton {
impl Skeleton for BirdMediumSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"bird_medium_compute_mats\0";
fn bone_count(&self) -> usize { 7 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let torso_mat = self.torso.compute_base_matrix();
(

View File

@ -8,7 +8,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = BirdMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"bird_medium_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = BirdSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"bird_small_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "bird_small_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for JumpAnimation {
type Dependency = (f32, f64);
type Skeleton = BirdSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"bird_small_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "bird_small_jump")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -33,9 +32,14 @@ impl BirdSmallSkeleton {
impl Skeleton for BirdSmallSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"bird_small_compute_mats\0";
fn bone_count(&self) -> usize { 4 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "bird_small_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let torso_mat = self.torso.compute_base_matrix();
(

View File

@ -8,7 +8,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = BirdSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"bird_small_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "bird_small_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency,
_anim_time: f64,

View File

@ -9,8 +9,12 @@ impl Animation for AlphaAnimation {
type Dependency = (Option<ToolKind>, f32, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_alpha\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_alpha")]
#[allow(clippy::approx_constant)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, velocity, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for BetaAnimation {
type Dependency = (Option<ToolKind>, f32, f64);
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_beta\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_beta")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, _velocity, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -12,7 +12,11 @@ impl Animation for BlockAnimation {
type Dependency = (Option<ToolKind>, f64);
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_block\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_block")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, global_time): Self::Dependency,
anim_time: f64,

View File

@ -12,7 +12,11 @@ impl Animation for BlockIdleAnimation {
type Dependency = (Option<ToolKind>, f64);
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_blockidle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_blockidle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,9 +9,13 @@ impl Animation for ChargeAnimation {
type Dependency = (Option<ToolKind>, f32, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_charge\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_charge")]
#[allow(clippy::approx_constant)] // TODO: Pending review in #587
#[allow(clippy::identity_conversion)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, velocity, orientation, last_ori, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,7 +9,11 @@ impl Animation for ClimbAnimation {
type Dependency = (Option<ToolKind>, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_climb\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_climb")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, velocity, _orientation, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,7 +9,11 @@ impl Animation for DanceAnimation {
type Dependency = (Option<ToolKind>, f64);
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_dance\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_dance")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, global_time): Self::Dependency,
anim_time: f64,

View File

@ -11,8 +11,12 @@ impl Animation for DashAnimation {
type Dependency = (Option<ToolKind>, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_dash\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_dash")]
#[allow(clippy::single_match)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -10,8 +10,12 @@ impl Animation for EquipAnimation {
type Dependency = (Option<ToolKind>, f32, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_equip\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_equip")]
#[allow(clippy::approx_constant)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, velocity, global_time): Self::Dependency,
anim_time: f64,

View File

@ -0,0 +1,308 @@
use super::{super::Animation, CharacterSkeleton, SkeletonAttr};
use common::comp::item::ToolKind;
use std::{f32::consts::PI, ops::Mul};
use vek::*;
pub struct GlideWieldAnimation;
impl Animation for GlideWieldAnimation {
type Dependency = (Option<ToolKind>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_glidewield\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_glidewield")]
#[allow(clippy::identity_conversion)] // TODO: Pending review in #587
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
anim_time: f64,
rate: &mut f32,
skeleton_attr: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let speed = Vec2::<f32>::from(velocity).magnitude();
*rate = 1.0;
let slow = (anim_time as f32 * 1.0).sin();
let breathe = ((anim_time as f32 * 0.5).sin()).abs();
let walkintensity = if speed > 5.0 { 1.0 } else { 0.45 };
let walk = if speed > 5.0 { 1.0 } else { 0.5 };
let lower = if speed > 5.0 { 0.0 } else { 1.0 };
let _snapfoot = if speed > 5.0 { 1.1 } else { 2.0 };
let lab = 1.0;
let foothoril = (anim_time as f32 * 16.0 * walk * lab as f32 + PI * 1.45).sin();
let foothorir = (anim_time as f32 * 16.0 * walk * lab as f32 + PI * (0.45)).sin();
let footvertl = (anim_time as f32 * 16.0 * walk * lab as f32).sin();
let footvertr = (anim_time as f32 * 16.0 * walk * lab as f32 + PI).sin();
let footrotl = (((5.0)
/ (2.5
+ (2.5)
* ((anim_time as f32 * 16.0 * walk * lab as f32 + PI * 1.4).sin())
.powf(2.0 as f32)))
.sqrt())
* ((anim_time as f32 * 16.0 * walk * lab as f32 + PI * 1.4).sin());
let footrotr = (((5.0)
/ (1.0
+ (4.0)
* ((anim_time as f32 * 16.0 * walk * lab as f32 + PI * 0.4).sin())
.powf(2.0 as f32)))
.sqrt())
* ((anim_time as f32 * 16.0 * walk * lab as f32 + PI * 0.4).sin());
let short = (((5.0)
/ (1.5
+ 3.5 * ((anim_time as f32 * lab as f32 * 16.0 * walk).sin()).powf(2.0 as f32)))
.sqrt())
* ((anim_time as f32 * lab as f32 * 16.0 * walk).sin());
let noisea = (anim_time as f32 * 11.0 + PI / 6.0).sin();
let noiseb = (anim_time as f32 * 19.0 + PI / 4.0).sin();
let shorte = (((5.0)
/ (4.0
+ 1.0 * ((anim_time as f32 * lab as f32 * 16.0 * walk).sin()).powf(2.0 as f32)))
.sqrt())
* ((anim_time as f32 * lab as f32 * 16.0 * walk).sin());
let shortalt = (anim_time as f32 * lab as f32 * 16.0 * walk + PI / 2.0).sin();
let shortalter = (anim_time as f32 * lab as f32 * 16.0 * walk + PI / -2.0).sin();
let wave_stop = (anim_time as f32 * 26.0).min(PI / 2.0 / 2.0).sin();
let head_look = Vec2::new(
((global_time + anim_time) as f32 / 18.0)
.floor()
.mul(7331.0)
.sin()
* 0.2,
((global_time + anim_time) as f32 / 18.0)
.floor()
.mul(1337.0)
.sin()
* 0.1,
);
let ori = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(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.2)
* last_ori.determine_side(Vec2::zero(), ori).signum()
} else {
0.0
} * 1.3;
next.l_hand.offset = Vec3::new(
-2.0 - skeleton_attr.hand.0,
skeleton_attr.hand.1,
skeleton_attr.hand.2 + 15.0,
);
next.l_hand.ori = Quaternion::rotation_x(3.35);
next.l_hand.scale = Vec3::one();
next.r_hand.offset = Vec3::new(
2.0 + skeleton_attr.hand.0,
skeleton_attr.hand.1,
skeleton_attr.hand.2 + 15.0,
);
next.r_hand.ori = Quaternion::rotation_x(3.35);
next.r_hand.scale = Vec3::one();
if speed > 0.5 {
next.head.offset = Vec3::new(
0.0,
-3.0 + skeleton_attr.head.0,
skeleton_attr.head.1 + short * 0.1,
);
next.head.ori = Quaternion::rotation_z(tilt * -2.5 + head_look.x * 0.2 - short * 0.1)
* Quaternion::rotation_x(head_look.y + 0.45 - lower * 0.35);
next.head.scale = Vec3::one() * skeleton_attr.head_scale;
next.chest.offset = Vec3::new(
0.0,
skeleton_attr.chest.0,
skeleton_attr.chest.1 + 2.0 + shortalt * -1.5 - lower,
);
next.chest.ori = Quaternion::rotation_z(short * 0.10 * walkintensity + tilt * -1.0)
* Quaternion::rotation_y(tilt * 2.2)
* Quaternion::rotation_x(
shortalter * 0.035 + wave_stop * speed * -0.1 + (tilt.abs()),
);
next.chest.scale = Vec3::one();
next.belt.offset = Vec3::new(0.0, skeleton_attr.belt.0, skeleton_attr.belt.1);
next.belt.ori = Quaternion::rotation_z(short * 0.1 + tilt * -1.1)
* Quaternion::rotation_y(tilt * 0.5);
next.belt.scale = Vec3::one();
next.glider.ori = Quaternion::rotation_x(0.8);
next.glider.offset = Vec3::new(0.0, -10.0, 15.0);
next.glider.scale = Vec3::one() * 1.0;
next.back.offset = Vec3::new(0.0, skeleton_attr.back.0, skeleton_attr.back.1);
next.back.ori =
Quaternion::rotation_x(-0.25 + short * 0.1 + noisea * 0.1 + noiseb * 0.1);
next.back.scale = Vec3::one() * 1.02;
next.shorts.offset = Vec3::new(0.0, skeleton_attr.shorts.0, skeleton_attr.shorts.1);
next.shorts.ori = Quaternion::rotation_z(short * 0.25 + tilt * -1.5)
* Quaternion::rotation_y(tilt * 0.7);
next.shorts.scale = Vec3::one();
next.l_foot.offset = Vec3::new(
-skeleton_attr.foot.0,
-1.5 + skeleton_attr.foot.1 + foothoril * -8.5 * walkintensity - lower * 1.0,
2.0 + skeleton_attr.foot.2 + ((footvertl * -2.7).max(-1.0)) * walkintensity,
);
next.l_foot.ori = Quaternion::rotation_x(-0.2 + footrotl * -1.2 * walkintensity)
* Quaternion::rotation_y(tilt * 1.8);
next.l_foot.scale = Vec3::one();
next.r_foot.offset = Vec3::new(
skeleton_attr.foot.0,
-1.5 + skeleton_attr.foot.1 + foothorir * -8.5 * walkintensity - lower * 1.0,
2.0 + skeleton_attr.foot.2 + ((footvertr * -2.7).max(-1.0)) * walkintensity,
);
next.r_foot.ori = Quaternion::rotation_x(-0.2 + footrotr * -1.2 * walkintensity)
* Quaternion::rotation_y(tilt * 1.8);
next.r_foot.scale = Vec3::one();
next.l_shoulder.offset = Vec3::new(
-skeleton_attr.shoulder.0,
skeleton_attr.shoulder.1,
skeleton_attr.shoulder.2,
);
next.l_shoulder.ori = Quaternion::rotation_x(short * 0.15 * walkintensity);
next.l_shoulder.scale = Vec3::one() * 1.1;
next.r_shoulder.offset = Vec3::new(
skeleton_attr.shoulder.0,
skeleton_attr.shoulder.1,
skeleton_attr.shoulder.2,
);
next.r_shoulder.ori = Quaternion::rotation_x(short * -0.15 * walkintensity);
next.r_shoulder.scale = Vec3::one() * 1.1;
next.main.offset = Vec3::new(-7.0, -6.5, 15.0);
next.main.ori =
Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57 + short * 0.25);
next.main.scale = Vec3::one();
next.second.scale = Vec3::one() * 0.0;
next.lantern.offset = Vec3::new(
skeleton_attr.lantern.0,
skeleton_attr.lantern.1,
skeleton_attr.lantern.2,
);
next.lantern.ori =
Quaternion::rotation_x(shorte * 0.7 + 0.4) * Quaternion::rotation_y(shorte * 0.4);
next.lantern.scale = Vec3::one() * 0.65;
next.torso.offset = Vec3::new(0.0, 0.0, 0.0) * skeleton_attr.scaler;
next.torso.ori = Quaternion::rotation_y(0.0);
next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler;
next.control.offset = Vec3::new(0.0, 0.0, 0.0);
next.control.ori = Quaternion::rotation_x(0.0);
next.control.scale = Vec3::one();
next.l_control.scale = Vec3::one();
next.r_control.scale = Vec3::one();
} else {
next.head.offset = Vec3::new(
0.0,
-3.0 + skeleton_attr.head.0,
skeleton_attr.head.1 + slow * 0.3 + breathe * -0.05,
);
next.head.ori =
Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y.abs());
next.head.scale = Vec3::one() * skeleton_attr.head_scale + breathe * -0.05;
next.chest.offset = Vec3::new(
0.0,
skeleton_attr.chest.0,
skeleton_attr.chest.1 + slow * 0.3,
);
next.chest.ori = Quaternion::rotation_z(head_look.x * 0.6);
next.chest.scale = Vec3::one() * 1.01 + breathe * 0.03;
next.belt.offset = Vec3::new(0.0, skeleton_attr.belt.0, skeleton_attr.belt.1);
next.belt.ori = Quaternion::rotation_z(head_look.x * -0.1);
next.belt.scale = Vec3::one() + breathe * -0.03;
next.glider.ori = Quaternion::rotation_x(0.35);
next.glider.offset = Vec3::new(0.0, -9.0, 17.0);
next.glider.scale = Vec3::one() * 1.0;
next.back.offset = Vec3::new(0.0, skeleton_attr.back.0, skeleton_attr.back.1);
next.back.scale = Vec3::one() * 1.02;
next.shorts.offset = Vec3::new(0.0, skeleton_attr.shorts.0, skeleton_attr.shorts.1);
next.shorts.ori = Quaternion::rotation_z(head_look.x * -0.2);
next.shorts.scale = Vec3::one() + breathe * -0.03;
next.l_foot.offset = Vec3::new(
-skeleton_attr.foot.0,
skeleton_attr.foot.1,
skeleton_attr.foot.2,
);
next.l_foot.scale = Vec3::one();
next.r_foot.offset = Vec3::new(
skeleton_attr.foot.0,
skeleton_attr.foot.1,
skeleton_attr.foot.2,
);
next.r_foot.scale = Vec3::one();
next.l_shoulder.offset = Vec3::new(
-skeleton_attr.shoulder.0,
skeleton_attr.shoulder.1,
skeleton_attr.shoulder.2,
);
next.l_shoulder.scale = (Vec3::one() + breathe * -0.05) * 1.15;
next.r_shoulder.offset = Vec3::new(
skeleton_attr.shoulder.0,
skeleton_attr.shoulder.1,
skeleton_attr.shoulder.2,
);
next.r_shoulder.scale = (Vec3::one() + breathe * -0.05) * 1.15;
next.main.offset = Vec3::new(-7.0, -5.0, 15.0);
next.main.ori = Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57);
next.main.scale = Vec3::one();
next.second.offset = Vec3::new(0.0, 0.0, 0.0);
next.second.scale = Vec3::one() * 0.0;
next.lantern.offset = Vec3::new(
skeleton_attr.lantern.0,
skeleton_attr.lantern.1,
skeleton_attr.lantern.2,
);
next.lantern.ori = Quaternion::rotation_x(0.1) * Quaternion::rotation_y(0.1);
next.lantern.scale = Vec3::one() * 0.65;
next.torso.offset = Vec3::new(0.0, 0.0, 0.0) * skeleton_attr.scaler;
next.torso.ori = Quaternion::rotation_x(0.0);
next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler;
next.control.scale = Vec3::one();
next.l_control.scale = Vec3::one();
next.r_control.scale = Vec3::one();
}
next
}
}

View File

@ -9,8 +9,12 @@ impl Animation for GlidingAnimation {
type Dependency = (Option<ToolKind>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_gliding\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_gliding")]
#[allow(clippy::identity_conversion)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: f64,
anim_time: f64,

View File

@ -7,8 +7,12 @@ impl Animation for JumpAnimation {
type Dependency = (Option<ToolKind>, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_jump")]
#[allow(clippy::identity_conversion)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, orientation, last_ori, global_time): Self::Dependency,
anim_time: f64,

View File

@ -31,8 +31,7 @@ pub use self::{
wield::WieldAnimation,
};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp;
use vek::{Vec3, Vec4};
@ -67,9 +66,14 @@ impl CharacterSkeleton {
impl Skeleton for CharacterSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"character_compute_mats\0";
fn bone_count(&self) -> usize { 16 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let chest_mat = self.chest.compute_base_matrix();
let torso_mat = self.torso.compute_base_matrix();
let l_hand_mat = self.l_hand.compute_base_matrix();

View File

@ -8,8 +8,12 @@ impl Animation for RollAnimation {
type Dependency = (Option<ToolKind>, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_roll\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_roll")]
#[allow(clippy::identity_conversion)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, orientation, last_ori, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,8 +9,12 @@ impl Animation for RunAnimation {
type Dependency = (Option<ToolKind>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_run")]
#[allow(clippy::identity_conversion)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
anim_time: f64,

View File

@ -8,8 +8,12 @@ impl Animation for ShootAnimation {
type Dependency = (Option<ToolKind>, f32, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_shoot\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_shoot")]
#[allow(clippy::approx_constant)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, velocity, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,7 +9,11 @@ impl Animation for SitAnimation {
type Dependency = (Option<ToolKind>, f64);
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_sit\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_sit")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, global_time): Self::Dependency,
anim_time: f64,

View File

@ -12,7 +12,11 @@ impl Animation for SpinAnimation {
type Dependency = (Option<ToolKind>, f64);
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_spin\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_spin")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,7 +9,11 @@ impl Animation for StandAnimation {
type Dependency = (Option<ToolKind>, f64);
type Skeleton = CharacterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_stand\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_stand")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,8 +9,12 @@ impl Animation for SwimAnimation {
type Dependency = (Option<ToolKind>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_swim\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_swim")]
#[allow(clippy::identity_conversion)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,8 +9,12 @@ impl Animation for WieldAnimation {
type Dependency = (Option<ToolKind>, f32, f64);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_wield\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_wield")]
#[allow(clippy::approx_constant)] // TODO: Pending review in #587
fn update_skeleton(
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, velocity, global_time): Self::Dependency,
anim_time: f64,

View File

@ -9,7 +9,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = CritterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"critter_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "critter_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
global_time: Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for JumpAnimation {
type Dependency = (f32, f64);
type Skeleton = CritterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"critter_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "critter_jump")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -33,9 +32,14 @@ impl CritterSkeleton {
impl Skeleton for CritterSkeleton {
type Attr = CritterAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"critter_compute_mats\0";
fn bone_count(&self) -> usize { 5 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "critter_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
(
[
FigureBoneData::new(self.head.compute_base_matrix()),

View File

@ -9,7 +9,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = CritterSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"critter_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "critter_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for FlyAnimation {
type Dependency = (f32, f64);
type Skeleton = DragonSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"dragon_fly\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_fly")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = DragonSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"dragon_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
global_time: Self::Dependency,
anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -36,9 +35,14 @@ impl DragonSkeleton {
impl Skeleton for DragonSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"dragon_compute_mats\0";
fn bone_count(&self) -> usize { 15 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
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();

View File

@ -8,7 +8,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = DragonSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"dragon_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, global_time): Self::Dependency,
anim_time: f64,

View File

@ -0,0 +1,155 @@
use lazy_static::lazy_static;
use libloading::Library;
use notify::{immediate_watcher, EventKind, RecursiveMode, Watcher};
use std::{
process::{Command, Stdio},
sync::{mpsc, Mutex},
thread,
time::Duration,
};
lazy_static! {
pub static ref LIB: Mutex<Option<LoadedLib>> = Mutex::new(Some(LoadedLib::compile_load()));
}
pub struct LoadedLib {
pub lib: Library,
}
impl LoadedLib {
fn compile_load() -> Self {
// Compile
compile();
#[cfg(target_os = "windows")]
copy();
Self::load()
}
fn load() -> Self {
#[cfg(target_os = "windows")]
let lib = Library::new("../target/debug/voxygen_anim_active.dll").unwrap();
#[cfg(not(target_os = "windows"))]
let lib = Library::new("../target/debug/libvoxygen_anim.so").unwrap();
Self { lib }
}
}
// Starts up watcher
pub fn init() {
// Make sure first compile is done
drop(LIB.lock());
// TODO: use crossbeam
let (reload_send, reload_recv) = mpsc::channel();
// Start watcher
let mut watcher = immediate_watcher(move |res| event_fn(res, &reload_send)).unwrap();
watcher.watch("src/anim", RecursiveMode::Recursive).unwrap();
// Start reloader that watcher signals
// "Debounces" events since I can't find the option to do this in the latest
// `notify`
thread::spawn(move || {
let mut modified_paths = std::collections::HashSet::new();
while let Ok(path) = reload_recv.recv() {
modified_paths.insert(path);
// Wait for any additional modify events before reloading
while let Ok(path) = reload_recv.recv_timeout(Duration::from_millis(300)) {
modified_paths.insert(path);
}
let mut info = "Hot reloading animations because these files were modified:".to_owned();
for path in std::mem::take(&mut modified_paths) {
info.push('\n');
info.push('\"');
info.push_str(&path);
info.push('\"');
}
log::warn!("{}", info);
// Reload
reload();
}
});
// Let the watcher live forever
std::mem::forget(watcher);
}
// Recompiles and hotreloads the lib if the source has been changed
// Note: designed with voxygen dir as working dir, could be made more flexible
fn event_fn(res: notify::Result<notify::Event>, sender: &mpsc::Sender<String>) {
match res {
Ok(event) => match event.kind {
EventKind::Modify(_) => {
event
.paths
.iter()
.filter(|p| p.extension().map(|e| e == "rs").unwrap_or(false))
.map(|p| p.to_string_lossy().into_owned())
// Signal reloader
.for_each(|p| { let _ = sender.send(p); });
},
_ => {},
},
Err(e) => log::error!("Animation hotreload watcher error: {:?}", e),
}
}
fn reload() {
// Stop if recompile failed
if !compile() {
return;
}
let mut lock = LIB.lock().unwrap();
// Close lib
lock.take().unwrap().lib.close().unwrap();
// Rename lib file on windows
// Called after closing lib so file will be unlocked
#[cfg(target_os = "windows")]
copy();
// Open new lib
*lock = Some(LoadedLib::load());
log::warn!("Updated animations");
}
// Returns false if compile failed
fn compile() -> bool {
let output = Command::new("cargo")
.stderr(Stdio::inherit())
.stdout(Stdio::inherit())
.arg("build")
.arg("--package")
.arg("veloren-voxygen-anim")
.output()
.unwrap();
// If compile failed
if !output.status.success() {
log::error!("Failed to compile anim crate");
false
} else {
log::warn!("Animation recompile success!!");
true
}
}
// Copy lib file if on windows since loading the lib locks the file blocking
// future compilation
#[cfg(target_os = "windows")]
fn copy() {
std::fs::copy(
"../target/debug/voxygen_anim.dll",
"../target/debug/voxygen_anim_active.dll",
)
.expect("Failed to rename animations dll");
}

View File

@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = FishMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"fish_medium_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_medium_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for JumpAnimation {
type Dependency = (f32, f64);
type Skeleton = FishMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"fish_medium_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_medium_jump")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -37,9 +36,13 @@ impl FishMediumSkeleton {
impl Skeleton for FishMediumSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"fish_medium_compute_mats\0";
fn bone_count(&self) -> usize { 6 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_medium_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let torso_mat = self.torso.compute_base_matrix();
let rear_mat = self.rear.compute_base_matrix();

View File

@ -8,7 +8,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = FishMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"fish_medium_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_medium_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = FishSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"fish_small_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for JumpAnimation {
type Dependency = (f32, f64);
type Skeleton = FishSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"fish_small_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_jump")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -29,9 +28,14 @@ impl FishSmallSkeleton {
impl Skeleton for FishSmallSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"fish_small_compute_mats\0";
fn bone_count(&self) -> usize { 2 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let torso_mat = self.torso.compute_base_matrix();
(

View File

@ -8,7 +8,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = FishSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"fish_small_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency,
_anim_time: f64,

View File

@ -1,5 +1,4 @@
use super::Skeleton;
use crate::render::FigureBoneData;
use super::{FigureBoneData, Skeleton};
use vek::Vec3;
#[derive(Clone)]
@ -15,9 +14,14 @@ impl FixtureSkeleton {
impl Skeleton for FixtureSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"fixture_compute_mats\0";
fn bone_count(&self) -> usize { 1 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "fixture_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
(
[
FigureBoneData::new(vek::Mat4::identity()), // <-- This is actually a bone!

View File

@ -8,7 +8,12 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = GolemSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"golem_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "golem_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
global_time: Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,12 @@ impl Animation for JumpAnimation {
type Dependency = (f32, f64);
type Skeleton = GolemSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"golem_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "golem_jump")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -5,12 +5,11 @@ pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct GolemSkeleton {
head: Bone,
upper_torso: Bone,
@ -26,28 +25,19 @@ pub struct GolemSkeleton {
}
impl GolemSkeleton {
#[allow(clippy::new_without_default)] // TODO: Pending review in #587
pub fn new() -> Self {
Self {
head: Bone::default(),
upper_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(),
}
}
pub fn new() -> Self { Self::default() }
}
impl Skeleton for GolemSkeleton {
type Attr = SkeletonAttr;
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"golem_compute_mats\0";
fn bone_count(&self) -> usize { 15 }
#[cfg_attr(feature = "be-dyn-lib", export_name = "golem_compute_mats")]
fn compute_matrices_inner(&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();

View File

@ -8,7 +8,12 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = GolemSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"golem_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "golem_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency,
anim_time: f64,

171
voxygen/src/anim/src/lib.rs Normal file
View File

@ -0,0 +1,171 @@
#[cfg(all(feature = "be-dyn-lib", feature = "use-dyn-lib"))]
compile_error!("Can't use both \"be-dyn-lib\" and \"use-dyn-lib\" features at once");
pub mod biped_large;
pub mod bird_medium;
pub mod bird_small;
pub mod character;
pub mod critter;
pub mod dragon;
#[cfg(feature = "use-dyn-lib")] pub mod dyn_lib;
pub mod fish_medium;
pub mod fish_small;
pub mod fixture;
pub mod golem;
pub mod object;
pub mod quadruped_medium;
pub mod quadruped_small;
#[cfg(feature = "use-dyn-lib")]
pub use dyn_lib::init;
#[cfg(feature = "use-dyn-lib")]
use std::ffi::CStr;
use vek::*;
// TODO: replace with inner type everywhere
pub struct FigureBoneData(pub Mat4<f32>);
impl FigureBoneData {
pub fn new(mat: Mat4<f32>) -> Self { Self(mat) }
pub fn default() -> Self { Self(Mat4::identity()) }
}
#[derive(Copy, Clone, Debug)]
pub struct Bone {
pub offset: Vec3<f32>,
pub ori: Quaternion<f32>,
pub scale: Vec3<f32>,
}
impl Default for Bone {
fn default() -> Self {
Self {
offset: Vec3::zero(),
ori: Quaternion::identity(),
scale: Vec3::broadcast(1.0 / 11.0),
}
}
}
impl Bone {
pub fn compute_base_matrix(&self) -> Mat4<f32> {
Mat4::<f32>::translation_3d(self.offset)
* Mat4::scaling_3d(self.scale)
* Mat4::from(self.ori)
}
/// Change the current bone to be more like `target`.
fn interpolate(&mut self, target: &Bone, dt: f32) {
// TODO: Make configurable.
let factor = (15.0 * dt).min(1.0);
self.offset += (target.offset - self.offset) * factor;
self.ori = vek::Slerp::slerp(self.ori, target.ori, factor);
self.scale += (target.scale - self.scale) * factor;
}
}
pub trait Skeleton: Send + Sync + 'static {
type Attr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8];
fn bone_count(&self) -> usize { 16 }
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>);
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg(not(feature = "use-dyn-lib"))]
{
Self::compute_matrices_inner(self)
}
#[cfg(feature = "use-dyn-lib")]
{
let lock = dyn_lib::LIB.lock().unwrap();
let lib = &lock.as_ref().unwrap().lib;
let compute_fn: libloading::Symbol<fn(&Self) -> ([FigureBoneData; 16], Vec3<f32>)> =
unsafe { lib.get(Self::COMPUTE_FN) }.unwrap_or_else(|err| {
panic!(
"Trying to use: {} but had error: {:?}",
CStr::from_bytes_with_nul(Self::COMPUTE_FN)
.map(CStr::to_str)
.unwrap()
.unwrap(),
err
)
});
compute_fn(self)
}
}
/// Change the current skeleton to be more like `target`.
fn interpolate(&mut self, target: &Self, dt: f32);
}
pub trait Animation {
type Skeleton: Skeleton;
type Dependency;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8];
/// Returns a new skeleton that is generated by the animation.
fn update_skeleton_inner(
_skeleton: &Self::Skeleton,
_dependency: Self::Dependency,
_anim_time: f64,
_rate: &mut f32,
_skeleton_attr: &<<Self as Animation>::Skeleton as Skeleton>::Attr,
) -> Self::Skeleton;
/// Calls `update_skeleton_inner` either directly or via `libloading` to
/// generate the new skeleton.
fn update_skeleton(
skeleton: &Self::Skeleton,
dependency: Self::Dependency,
anim_time: f64,
rate: &mut f32,
skeleton_attr: &<<Self as Animation>::Skeleton as Skeleton>::Attr,
) -> Self::Skeleton {
#[cfg(not(feature = "use-dyn-lib"))]
{
Self::update_skeleton_inner(skeleton, dependency, anim_time, rate, skeleton_attr)
}
#[cfg(feature = "use-dyn-lib")]
{
let lock = dyn_lib::LIB.lock().unwrap();
let lib = &lock.as_ref().unwrap().lib;
let update_fn: libloading::Symbol<
fn(
&Self::Skeleton,
Self::Dependency,
f64,
&mut f32,
&<Self::Skeleton as Skeleton>::Attr,
) -> Self::Skeleton,
> = unsafe {
//let start = std::time::Instant::now();
// Overhead of 0.5-5 us (could use hashmap to mitigate if this is an issue)
let f = lib.get(Self::UPDATE_FN);
//println!("{}", start.elapsed().as_nanos());
f
}
.unwrap_or_else(|err| {
panic!(
"Trying to use: {} but had error: {:?}",
CStr::from_bytes_with_nul(Self::UPDATE_FN)
.map(CStr::to_str)
.unwrap()
.unwrap(),
err
)
});
update_fn(skeleton, dependency, anim_time, rate, skeleton_attr)
}
}
}

View File

@ -1,5 +1,4 @@
use super::Skeleton;
use crate::render::FigureBoneData;
use super::{FigureBoneData, Skeleton};
use vek::*;
#[derive(Clone)]
@ -16,9 +15,13 @@ const SCALE: f32 = 1.0 / 11.0;
impl Skeleton for ObjectSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 1 }
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"object_compute_mats\0";
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
fn bone_count(&self) -> usize { 15 }
#[cfg_attr(feature = "be-dyn-lib", export_name = "object_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
(
[
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),

View File

@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = QuadrupedMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_medium_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
global_time: Self::Dependency,
anim_time: f64,

View File

@ -7,7 +7,11 @@ impl Animation for JumpAnimation {
type Dependency = (f32, f64);
type Skeleton = QuadrupedMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_medium_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_jump")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -32,9 +31,13 @@ impl QuadrupedMediumSkeleton {
impl Skeleton for QuadrupedMediumSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"quadruped_medium_compute_mats\0";
fn bone_count(&self) -> usize { 11 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let ears_mat = self.ears.compute_base_matrix();
let head_upper_mat = self.head_upper.compute_base_matrix();
let head_lower_mat = self.head_lower.compute_base_matrix();

View File

@ -8,7 +8,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = QuadrupedMediumSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_medium_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, global_time): Self::Dependency,
anim_time: f64,

View File

@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
type Dependency = f64;
type Skeleton = QuadrupedSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_small_idle\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
global_time: Self::Dependency,
anim_time: f64,

View File

@ -7,7 +7,11 @@ impl Animation for JumpAnimation {
type Dependency = (f32, f64);
type Skeleton = QuadrupedSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_small_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_jump")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency,
_anim_time: f64,

View File

@ -5,8 +5,7 @@ pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
use super::{Bone, FigureBoneData, Skeleton};
use common::comp::{self};
use vek::Vec3;
@ -28,9 +27,13 @@ impl QuadrupedSmallSkeleton {
impl Skeleton for QuadrupedSmallSkeleton {
type Attr = SkeletonAttr;
#[cfg(feature = "use-dyn-lib")]
const COMPUTE_FN: &'static [u8] = b"quadruped_small_compute_mats\0";
fn bone_count(&self) -> usize { 7 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_compute_mats")]
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
let chest_mat = self.chest.compute_base_matrix();
(
[

View File

@ -8,7 +8,11 @@ impl Animation for RunAnimation {
type Dependency = (f32, f64);
type Skeleton = QuadrupedSmallSkeleton;
fn update_skeleton(
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_small_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_run")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency,
anim_time: f64,

View File

@ -5,7 +5,6 @@
#[macro_use]
pub mod ui;
pub mod anim;
pub mod audio;
pub mod controller;
mod ecs;

View File

@ -162,6 +162,10 @@ fn main() {
default_hook(panic_info);
}));
// Initialise watcher for animation hotreloading
#[cfg(feature = "hot-anim")]
anim::init();
// Set up the initial play state.
let mut states: Vec<Box<dyn PlayState>> = vec![Box::new(MainMenuState::new(&mut global_state))];
states

View File

@ -7,7 +7,6 @@ pub mod model;
pub mod pipelines;
pub mod renderer;
pub mod texture;
mod util;
// Reexports
pub use self::{

View File

@ -1,5 +1,5 @@
use super::{
super::{util::arr_to_mat, Pipeline, TgtColorFmt, TgtDepthStencilFmt},
super::{Pipeline, TgtColorFmt, TgtDepthStencilFmt},
Globals, Light, Shadow,
};
use gfx::{
@ -81,7 +81,7 @@ impl Locals {
flags |= is_player as u32;
Self {
model_mat: arr_to_mat(model_mat.into_col_array()),
model_mat: model_mat.into_col_arrays(),
model_col: col.into_array(),
flags,
}
@ -95,7 +95,7 @@ impl Default for Locals {
impl BoneData {
pub fn new(bone_mat: Mat4<f32>) -> Self {
Self {
bone_mat: arr_to_mat(bone_mat.into_col_array()),
bone_mat: bone_mat.into_col_arrays(),
}
}

View File

@ -6,7 +6,6 @@ pub mod sprite;
pub mod terrain;
pub mod ui;
use super::util::arr_to_mat;
use crate::scene::camera::CameraMode;
use common::terrain::BlockKind;
use gfx::{self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta};
@ -64,9 +63,9 @@ impl Globals {
sprite_render_distance: f32,
) -> Self {
Self {
view_mat: arr_to_mat(view_mat.into_col_array()),
proj_mat: arr_to_mat(proj_mat.into_col_array()),
all_mat: arr_to_mat((proj_mat * view_mat).into_col_array()),
view_mat: view_mat.into_col_arrays(),
proj_mat: proj_mat.into_col_arrays(),
all_mat: (proj_mat * view_mat).into_col_arrays(),
cam_pos: Vec4::from(cam_pos).into_array(),
focus_pos: Vec4::from(focus_pos).into_array(),
view_distance: [view_distance; 4],

View File

@ -1,5 +1,5 @@
use super::{
super::{util::arr_to_mat, Pipeline, TgtColorFmt, TgtDepthStencilFmt},
super::{Pipeline, TgtColorFmt, TgtDepthStencilFmt},
Globals, Light, Shadow,
};
use gfx::{
@ -67,7 +67,7 @@ impl Vertex {
impl Instance {
pub fn new(mat: Mat4<f32>, col: Rgb<f32>, wind_sway: f32) -> Self {
let mat_arr = arr_to_mat(mat.into_col_array());
let mat_arr = mat.into_col_arrays();
Self {
inst_mat0: mat_arr[0],
inst_mat1: mat_arr[1],

View File

@ -1,10 +0,0 @@
// TODO: Get rid of this ugliness.
#[rustfmt::skip]
pub fn arr_to_mat(arr: [f32; 16]) -> [[f32; 4]; 4] {
[
[arr[ 0], arr[ 1], arr[ 2], arr[ 3]],
[arr[ 4], arr[ 5], arr[ 6], arr[ 7]],
[arr[ 8], arr[ 9], arr[10], arr[11]],
[arr[12], arr[13], arr[14], arr[15]],
]
}

View File

@ -1,10 +1,10 @@
use super::load::*;
use crate::{
anim::{self, Skeleton},
mesh::Meshable,
render::{FigurePipeline, Mesh, Model, Renderer},
scene::camera::CameraMode,
};
use anim::Skeleton;
use common::{
assets::watch::ReloadIndicator,
comp::{

View File

@ -5,13 +5,6 @@ pub use cache::FigureModelCache;
pub use load::load_mesh; // TODO: Don't make this public.
use crate::{
anim::{
self, biped_large::BipedLargeSkeleton, bird_medium::BirdMediumSkeleton,
bird_small::BirdSmallSkeleton, character::CharacterSkeleton, critter::CritterSkeleton,
dragon::DragonSkeleton, fish_medium::FishMediumSkeleton, fish_small::FishSmallSkeleton,
golem::GolemSkeleton, object::ObjectSkeleton, quadruped_medium::QuadrupedMediumSkeleton,
quadruped_small::QuadrupedSmallSkeleton, Animation, Skeleton,
},
ecs::comp::Interpolated,
render::{Consts, FigureBoneData, FigureLocals, Globals, Light, Renderer, Shadow},
scene::{
@ -19,6 +12,13 @@ use crate::{
SceneData,
},
};
use anim::{
biped_large::BipedLargeSkeleton, bird_medium::BirdMediumSkeleton,
bird_small::BirdSmallSkeleton, character::CharacterSkeleton, critter::CritterSkeleton,
dragon::DragonSkeleton, fish_medium::FishMediumSkeleton, fish_small::FishSmallSkeleton,
golem::GolemSkeleton, object::ObjectSkeleton, quadruped_medium::QuadrupedMediumSkeleton,
quadruped_small::QuadrupedSmallSkeleton, Animation, Skeleton,
};
use common::{
comp::{
item::ItemKind, Body, CharacterState, Last, LightAnimation, LightEmitter, Loadout, Ori,
@ -2037,7 +2037,8 @@ pub struct FigureState<S: Skeleton> {
impl<S: Skeleton> FigureState<S> {
pub fn new(renderer: &mut Renderer, skeleton: S) -> Self {
let (bone_consts, lantern_offset) = skeleton.compute_matrices();
let (bone_mats, lantern_offset) = skeleton.compute_matrices();
let bone_consts = figure_bone_data_from_anim(bone_mats);
Self {
bone_consts: renderer.create_consts(&bone_consts).unwrap(),
locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(),
@ -2081,7 +2082,9 @@ impl<S: Skeleton> FigureState<S> {
let locals = FigureLocals::new(mat, col, is_player);
renderer.update_consts(&mut self.locals, &[locals]).unwrap();
let (new_bone_consts, lantern_offset) = self.skeleton.compute_matrices();
let (new_bone_mats, lantern_offset) = self.skeleton.compute_matrices();
let new_bone_consts = figure_bone_data_from_anim(new_bone_mats);
renderer
.update_consts(
&mut self.bone_consts,
@ -2097,3 +2100,24 @@ impl<S: Skeleton> FigureState<S> {
pub fn skeleton_mut(&mut self) -> &mut S { &mut self.skeleton }
}
fn figure_bone_data_from_anim(mats: [anim::FigureBoneData; 16]) -> [FigureBoneData; 16] {
[
FigureBoneData::new(mats[0].0),
FigureBoneData::new(mats[1].0),
FigureBoneData::new(mats[2].0),
FigureBoneData::new(mats[3].0),
FigureBoneData::new(mats[4].0),
FigureBoneData::new(mats[5].0),
FigureBoneData::new(mats[6].0),
FigureBoneData::new(mats[7].0),
FigureBoneData::new(mats[8].0),
FigureBoneData::new(mats[9].0),
FigureBoneData::new(mats[10].0),
FigureBoneData::new(mats[11].0),
FigureBoneData::new(mats[12].0),
FigureBoneData::new(mats[13].0),
FigureBoneData::new(mats[14].0),
FigureBoneData::new(mats[15].0),
]
}

View File

@ -9,7 +9,6 @@ use self::{
terrain::Terrain,
};
use crate::{
anim::character::SkeletonAttr,
audio::{music::MusicMgr, sfx::SfxMgr, AudioFrontend},
render::{
create_pp_mesh, create_skybox_mesh, Consts, Globals, Light, Model, PostProcessLocals,
@ -17,6 +16,7 @@ use crate::{
},
window::{AnalogGameInput, Event},
};
use anim::character::SkeletonAttr;
use common::{
comp,
state::State,

View File

@ -1,9 +1,4 @@
use crate::{
anim::{
character::{CharacterSkeleton, IdleAnimation, SkeletonAttr},
fixture::FixtureSkeleton,
Animation, Skeleton,
},
mesh::Meshable,
render::{
create_pp_mesh, create_skybox_mesh, Consts, FigurePipeline, Globals, Light, Mesh, Model,
@ -15,6 +10,11 @@ use crate::{
},
window::{Event, PressState},
};
use anim::{
character::{CharacterSkeleton, IdleAnimation, SkeletonAttr},
fixture::FixtureSkeleton,
Animation, Skeleton,
};
use common::{
comp::{humanoid, Body, Loadout},
figure::Segment,