veloren_voxygen/scene/figure/
volume.rs1use super::{
2 EcsEntity,
3 cache::{FigureKey, TerrainModelEntryFuture},
4 load::{BodySpec, ShipBoneMeshes},
5};
6use common::{assets, comp::ship::figuredata::VoxelCollider};
7use std::{convert::TryFrom, sync::Arc};
8
9#[derive(Copy, Clone, PartialEq, Eq, Hash)]
10pub struct VolumeKey {
11 pub entity: EcsEntity,
12 pub mut_count: usize,
13}
14
15impl From<&Self> for VolumeKey {
16 fn from(this: &Self) -> Self { *this }
17}
18
19impl anim::Skeleton for VolumeKey {
20 type Attr = Self;
21 type Body = Self;
22
23 const BONE_COUNT: usize = 4;
24 #[cfg(feature = "hot-anim")]
25 const COMPUTE_FN: &'static [u8] = b"I AM NOT USED\0";
26
27 fn compute_matrices(
30 &self,
31 base_mat: anim::vek::Mat4<f32>,
32 buf: &mut [anim::FigureBoneData; anim::MAX_BONE_COUNT],
33 body: Self::Body,
34 ) -> anim::Offsets {
35 self.compute_matrices_inner(base_mat, buf, body)
36 }
37
38 fn compute_matrices_inner(
39 &self,
40 base_mat: anim::vek::Mat4<f32>,
41 buf: &mut [anim::FigureBoneData; anim::MAX_BONE_COUNT],
42 _: Self::Body,
43 ) -> anim::Offsets {
44 let bone = base_mat;
45
46 *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
47 anim::make_bone(bone),
48 anim::make_bone(bone),
49 anim::make_bone(bone),
50 anim::make_bone(bone),
51 ];
52
53 anim::Offsets::default()
54 }
55}
56
57impl BodySpec for VolumeKey {
58 type BoneMesh = ShipBoneMeshes;
59 type Extra = Arc<VoxelCollider>;
60 type Manifests = ();
61 type ModelEntryFuture<const N: usize> = TerrainModelEntryFuture<N>;
62 type Spec = ();
63
64 fn load_spec() -> Result<Self::Manifests, assets::Error> { Ok(()) }
65
66 fn reload_watcher(_: &Self::Manifests) -> assets::ReloadWatcher {
67 assets::ReloadWatcher::default()
68 }
69
70 fn bone_meshes(
71 _: &FigureKey<Self>,
72 _: &Self::Manifests,
73 collider: Self::Extra,
74 ) -> [Option<Self::BoneMesh>; anim::MAX_BONE_COUNT] {
75 [
76 Some((
77 collider.volume().clone(),
78 -collider.volume().sz.map(|e| e as f32) / 2.0,
79 )),
80 None,
81 None,
82 None,
83 None,
84 None,
85 None,
86 None,
87 None,
88 None,
89 None,
90 None,
91 None,
92 None,
93 None,
94 None,
95 ]
96 }
97}