veloren_voxygen_anim/plugin/
mod.rs1use super::{
2 Skeleton,
3 vek::{Lerp, Mat4, Transform, Vec3, Vec4},
4};
5use common::comp;
6use vek::Quaternion;
8
9pub type Body = comp::plugin::Body;
10
11skeleton_impls!(struct PluginSkeleton ComputedPluginSkeleton {
12 + bone0
13 + bone1
14 + bone2
15 + bone3
16 + bone4
17 + bone5
18 + bone6
19 + bone7
20 + bone8
21 + bone9
22 + bone10
23 + bone11
24 + bone12
25 + bone13
26 + bone14
27 + bone15
28});
29
30impl PluginSkeleton {
31 pub fn from_module(skel: common_state::plugin::module::Skeleton) -> Self {
32 fn convert(
33 a: Option<&common_state::plugin::module::Transform>,
34 ) -> Transform<f32, f32, f32> {
35 a.map_or_else(
36 || Transform {
37 position: Vec3::zero(),
38 orientation: Quaternion::identity(),
39 scale: Vec3::one(),
40 },
41 |a| Transform {
42 position: Vec3::from(a.position),
43 orientation: Quaternion::from_vec4(Vec4::from(a.orientation)),
44 scale: Vec3::from(a.scale),
45 },
46 )
47 }
48 Self {
49 bone0: convert(skel.first()),
50 bone1: convert(skel.get(1)),
51 bone2: convert(skel.get(2)),
52 bone3: convert(skel.get(3)),
53 bone4: convert(skel.get(4)),
54 bone5: convert(skel.get(5)),
55 bone6: convert(skel.get(6)),
56 bone7: convert(skel.get(7)),
57 bone8: convert(skel.get(8)),
58 bone9: convert(skel.get(9)),
59 bone10: convert(skel.get(10)),
60 bone11: convert(skel.get(11)),
61 bone12: convert(skel.get(12)),
62 bone13: convert(skel.get(13)),
63 bone14: convert(skel.get(14)),
64 bone15: convert(skel.get(15)),
65 }
66 }
67}
68
69impl Skeleton for PluginSkeleton {
70 type Attr = SkeletonAttr;
71 type Body = Body;
72 type ComputedSkeleton = ComputedPluginSkeleton;
73
74 const BONE_COUNT: usize = ComputedPluginSkeleton::BONE_COUNT;
75 #[cfg(feature = "use-dyn-lib")]
76 const COMPUTE_FN: &'static [u8] = b"plugin_compute_mats\0";
77
78 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "plugin_compute_mats"))]
79 fn compute_matrices_inner(
80 &self,
81 base_mat: Mat4<f32>,
82 buf: &mut [crate::FigureBoneData; crate::MAX_BONE_COUNT],
83 _body: Self::Body,
84 ) -> Self::ComputedSkeleton {
85 let base_mat = base_mat * Mat4::scaling_3d(1.0 / 13.0);
86
87 let computed_skeleton = ComputedPluginSkeleton {
88 bone0: base_mat * Mat4::<f32>::from(self.bone0),
89 bone1: base_mat * Mat4::<f32>::from(self.bone1),
90 bone2: base_mat * Mat4::<f32>::from(self.bone2),
91 bone3: base_mat * Mat4::<f32>::from(self.bone3),
92 bone4: base_mat * Mat4::<f32>::from(self.bone4),
93 bone5: base_mat * Mat4::<f32>::from(self.bone5),
94 bone6: base_mat * Mat4::<f32>::from(self.bone6),
95 bone7: base_mat * Mat4::<f32>::from(self.bone7),
96 bone8: base_mat * Mat4::<f32>::from(self.bone8),
97 bone9: base_mat * Mat4::<f32>::from(self.bone9),
98 bone10: base_mat * Mat4::<f32>::from(self.bone10),
99 bone11: base_mat * Mat4::<f32>::from(self.bone11),
100 bone12: base_mat * Mat4::<f32>::from(self.bone12),
101 bone13: base_mat * Mat4::<f32>::from(self.bone13),
102 bone14: base_mat * Mat4::<f32>::from(self.bone14),
103 bone15: base_mat * Mat4::<f32>::from(self.bone15),
104 };
105
106 computed_skeleton.set_figure_bone_data(buf);
107 computed_skeleton
108 }
109}
110
111#[derive(Default)]
112pub struct SkeletonAttr {}
113
114impl<'a> TryFrom<&'a comp::Body> for SkeletonAttr {
115 type Error = ();
116
117 fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
118 match body {
119 comp::Body::Plugin(body) => Ok(SkeletonAttr::from(body)),
120 _ => Err(()),
121 }
122 }
123}
124
125impl<'a> From<&'a Body> for SkeletonAttr {
126 fn from(_body: &'a Body) -> Self { Self {} }
127}