veloren_voxygen/scene/figure/
volume.rs

1use 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    type ComputedSkeleton = ();
23
24    const BONE_COUNT: usize = 4;
25    #[cfg(feature = "hot-anim")]
26    const COMPUTE_FN: &'static [u8] = b"I AM NOT USED\0";
27
28    // Override compute_matrices so that hotloading is not done for this (since it
29    // will fail as this isn't part of the hotloaded anim crate)
30    fn compute_matrices(
31        &self,
32        base_mat: anim::vek::Mat4<f32>,
33        buf: &mut [anim::FigureBoneData; anim::MAX_BONE_COUNT],
34        body: Self::Body,
35    ) -> Self::ComputedSkeleton {
36        self.compute_matrices_inner(base_mat, buf, body)
37    }
38
39    fn compute_matrices_inner(
40        &self,
41        base_mat: anim::vek::Mat4<f32>,
42        buf: &mut [anim::FigureBoneData; anim::MAX_BONE_COUNT],
43        _: Self::Body,
44    ) -> Self::ComputedSkeleton {
45        let bone = base_mat;
46
47        *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
48            anim::make_bone(bone),
49            anim::make_bone(bone),
50            anim::make_bone(bone),
51            anim::make_bone(bone),
52        ];
53    }
54}
55
56impl BodySpec for VolumeKey {
57    type BoneMesh = ShipBoneMeshes;
58    type Extra = Arc<VoxelCollider>;
59    type Manifests = ();
60    type ModelEntryFuture<const N: usize> = TerrainModelEntryFuture<N>;
61    type Spec = ();
62
63    fn load_spec() -> Result<Self::Manifests, assets::Error> { Ok(()) }
64
65    fn reload_watcher(_: &Self::Manifests) -> assets::ReloadWatcher {
66        assets::ReloadWatcher::default()
67    }
68
69    fn bone_meshes(
70        _: &FigureKey<Self>,
71        _: &Self::Manifests,
72        collider: Self::Extra,
73    ) -> [Option<Self::BoneMesh>; anim::MAX_BONE_COUNT] {
74        [
75            Some((
76                collider.volume().clone(),
77                -collider.volume().sz.map(|e| e as f32) / 2.0,
78            )),
79            None,
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        ]
95    }
96}