40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
use bevy_asset::{AsAssetId, Asset, AssetId, Handle};
|
|
use bevy_ecs::{component::Component, entity::Entity, prelude::ReflectComponent};
|
|
use bevy_math::Mat4;
|
|
use bevy_reflect::prelude::*;
|
|
use core::ops::Deref;
|
|
|
|
#[derive(Component, Debug, Default, Clone, Reflect)]
|
|
#[reflect(Component, Default, Debug, Clone)]
|
|
pub struct SkinnedMesh {
|
|
pub inverse_bindposes: Handle<SkinnedMeshInverseBindposes>,
|
|
#[entities]
|
|
pub joints: Vec<Entity>,
|
|
}
|
|
|
|
impl AsAssetId for SkinnedMesh {
|
|
type Asset = SkinnedMeshInverseBindposes;
|
|
|
|
// We implement this so that `AssetChanged` will work to pick up any changes
|
|
// to `SkinnedMeshInverseBindposes`.
|
|
fn as_asset_id(&self) -> AssetId<Self::Asset> {
|
|
self.inverse_bindposes.id()
|
|
}
|
|
}
|
|
|
|
#[derive(Asset, TypePath, Debug)]
|
|
pub struct SkinnedMeshInverseBindposes(Box<[Mat4]>);
|
|
|
|
impl From<Vec<Mat4>> for SkinnedMeshInverseBindposes {
|
|
fn from(value: Vec<Mat4>) -> Self {
|
|
Self(value.into_boxed_slice())
|
|
}
|
|
}
|
|
|
|
impl Deref for SkinnedMeshInverseBindposes {
|
|
type Target = [Mat4];
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|