mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-26 21:37:01 +00:00
Compare commits
1 Commits
250bae4c96
...
c9229c6884
Author | SHA1 | Date | |
---|---|---|---|
|
c9229c6884 |
@ -91,16 +91,13 @@ impl GltfRefMap {
|
|||||||
|
|
||||||
#[derive(Component, Reflect)]
|
#[derive(Component, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
struct GltfRef<T: Component> {
|
struct GltfRef<T: Component + FromGltfRef> {
|
||||||
target: String,
|
target: String,
|
||||||
#[reflect(ignore)]
|
#[reflect(ignore)]
|
||||||
_marker: PhantomData<T>,
|
_marker: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Component> GltfRef<T>
|
impl<T: Component + FromGltfRef> GltfRef<T> {
|
||||||
where
|
|
||||||
Entity: Into<T>,
|
|
||||||
{
|
|
||||||
fn system(
|
fn system(
|
||||||
refs: Query<(Entity, &Self)>,
|
refs: Query<(Entity, &Self)>,
|
||||||
gltf_for_entity: GltfForEntity,
|
gltf_for_entity: GltfForEntity,
|
||||||
@ -116,7 +113,7 @@ where
|
|||||||
|
|
||||||
match ref_map.get_ref(gltf_root, &gltf_ref.target) {
|
match ref_map.get_ref(gltf_root, &gltf_ref.target) {
|
||||||
Some(target) => {
|
Some(target) => {
|
||||||
commands.entity(entity).insert(Into::<T>::into(target));
|
commands.entity(entity).insert(T::from_ref(target));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
warn!(
|
warn!(
|
||||||
@ -129,14 +126,17 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trait for creating a component for a Gltf reference.
|
||||||
|
pub trait FromGltfRef {
|
||||||
|
/// Creates `Self` given the `entity` for this reference.
|
||||||
|
fn from_ref(entity: Entity) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
/// Plugin for automatically converting [`GltfRef`]s into their corresponding
|
/// Plugin for automatically converting [`GltfRef`]s into their corresponding
|
||||||
/// `T`.
|
/// `T`.
|
||||||
pub struct GltfRefPlugin<T: Component + TypePath>(PhantomData<T>);
|
pub struct GltfRefPlugin<T: Component + FromGltfRef>(PhantomData<T>);
|
||||||
|
|
||||||
impl<T: Component + TypePath> Plugin for GltfRefPlugin<T>
|
impl<T: Component + FromGltfRef + Reflect + TypePath> Plugin for GltfRefPlugin<T> {
|
||||||
where
|
|
||||||
Entity: Into<T>,
|
|
||||||
{
|
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.register_type::<GltfRef<T>>().add_systems(
|
app.register_type::<GltfRef<T>>().add_systems(
|
||||||
Update,
|
Update,
|
||||||
@ -147,10 +147,7 @@ where
|
|||||||
|
|
||||||
// Manual implementation of Default for GltfRefPlugin to avoid `Default` trait
|
// Manual implementation of Default for GltfRefPlugin to avoid `Default` trait
|
||||||
// bounds on `T`.
|
// bounds on `T`.
|
||||||
impl<T: Component + TypePath> Default for GltfRefPlugin<T>
|
impl<T: Component + FromGltfRef> Default for GltfRefPlugin<T> {
|
||||||
where
|
|
||||||
Entity: Into<T>,
|
|
||||||
{
|
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self(Default::default())
|
Self(Default::default())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user