bevy_mesh/
skinning.rs

1use bevy_asset::{AsAssetId, Asset, AssetId, Handle};
2use bevy_ecs::{component::Component, entity::Entity, prelude::ReflectComponent};
3use bevy_math::Mat4;
4use bevy_reflect::prelude::*;
5use core::ops::Deref;
6
7#[derive(Component, Debug, Default, Clone, Reflect)]
8#[reflect(Component, Default, Debug, Clone)]
9pub struct SkinnedMesh {
10    pub inverse_bindposes: Handle<SkinnedMeshInverseBindposes>,
11    #[entities]
12    pub joints: Vec<Entity>,
13}
14
15impl AsAssetId for SkinnedMesh {
16    type Asset = SkinnedMeshInverseBindposes;
17
18    // We implement this so that `AssetChanged` will work to pick up any changes
19    // to `SkinnedMeshInverseBindposes`.
20    fn as_asset_id(&self) -> AssetId<Self::Asset> {
21        self.inverse_bindposes.id()
22    }
23}
24
25#[derive(Asset, TypePath, Debug)]
26pub struct SkinnedMeshInverseBindposes(Box<[Mat4]>);
27
28impl From<Vec<Mat4>> for SkinnedMeshInverseBindposes {
29    fn from(value: Vec<Mat4>) -> Self {
30        Self(value.into_boxed_slice())
31    }
32}
33
34impl Deref for SkinnedMeshInverseBindposes {
35    type Target = [Mat4];
36    fn deref(&self) -> &Self::Target {
37        &self.0
38    }
39}