From 70931ee1630142d1f3e4af4cdb1aac065824b21b Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Mon, 8 Jul 2024 13:30:46 +0200 Subject: [PATCH] chore(Blenvy:Bevy): more cleanups --- crates/bevy_gltf_blueprints/src/assets.rs | 6 +- crates/bevy_gltf_blueprints/src/lib.rs | 4 +- crates/blenvy/src/blueprints/assets.rs | 14 ++--- crates/blenvy/src/blueprints/hot_reload.rs | 6 +- crates/blenvy/src/blueprints/materials.rs | 2 +- crates/blenvy/src/blueprints/mod.rs | 13 ++-- .../src/blueprints/spawn_from_blueprints.rs | 13 ++-- crates/blenvy/src/components/mod.rs | 2 +- .../ronstring_to_reflect_component.rs | 2 +- testing/bevy_example/assets/registry.json | 60 +++++++++---------- 10 files changed, 56 insertions(+), 66 deletions(-) diff --git a/crates/bevy_gltf_blueprints/src/assets.rs b/crates/bevy_gltf_blueprints/src/assets.rs index 543ad26..73d4bf5 100644 --- a/crates/bevy_gltf_blueprints/src/assets.rs +++ b/crates/bevy_gltf_blueprints/src/assets.rs @@ -7,7 +7,7 @@ use crate::{BluePrintsConfig, BlueprintAnimations}; /// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] -pub struct MyAsset { +pub struct BlueprintAsset { pub name: String, pub path: String, } @@ -15,12 +15,12 @@ pub struct MyAsset { /// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] -pub struct LocalAssets(pub Vec); +pub struct LocalAssets(pub Vec); /// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] -pub struct BlueprintAssets(pub Vec); +pub struct BlueprintAssets(pub Vec); //////////////////////// /// diff --git a/crates/bevy_gltf_blueprints/src/lib.rs b/crates/bevy_gltf_blueprints/src/lib.rs index 0e1e3c3..3effb39 100644 --- a/crates/bevy_gltf_blueprints/src/lib.rs +++ b/crates/bevy_gltf_blueprints/src/lib.rs @@ -119,8 +119,8 @@ impl Plugin for BlueprintsPlugin { .register_type::>>() .register_type::>>>() .add_event::() - .register_type::() - .register_type::>() + .register_type::() + .register_type::>() .register_type::>() .register_type::() .register_type::() diff --git a/crates/blenvy/src/blueprints/assets.rs b/crates/blenvy/src/blueprints/assets.rs index bd31ae6..aa84f40 100644 --- a/crates/blenvy/src/blueprints/assets.rs +++ b/crates/blenvy/src/blueprints/assets.rs @@ -1,14 +1,10 @@ -use std::path::{Path, PathBuf}; - -use bevy::{asset::LoadedUntypedAsset, gltf::Gltf, prelude::*, utils::HashMap}; +use bevy::{asset::LoadedUntypedAsset, prelude::*}; use serde::Deserialize; -use crate::{BlenvyConfig, BlueprintAnimations}; - /// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints #[derive(Component, Reflect, Default, Debug, Deserialize)] #[reflect(Component)] -pub struct MyAsset { +pub struct BlueprintAsset { pub name: String, pub path: String, } @@ -18,7 +14,7 @@ pub struct MyAsset { #[reflect(Component)] pub struct BlueprintAssets { /// only this field should get filled in from the Blender side - pub assets: Vec, + pub assets: Vec, /// set to default when deserializing #[serde(default)] #[reflect(default)] @@ -31,7 +27,7 @@ pub struct BlueprintAssets { #[serde(skip)] pub asset_infos: Vec, } -//(pub Vec); +//(pub Vec); //////////////////////// /// @@ -44,7 +40,7 @@ pub(crate) struct BlueprintAssetsNotLoaded; /// helper component, for tracking loaded assets's loading state, id , handle etc #[derive(Debug, Reflect)] -pub(crate) struct AssetLoadTracker { +pub struct AssetLoadTracker { #[allow(dead_code)] pub name: String, pub path: String, diff --git a/crates/blenvy/src/blueprints/hot_reload.rs b/crates/blenvy/src/blueprints/hot_reload.rs index 19e54fb..2268433 100644 --- a/crates/blenvy/src/blueprints/hot_reload.rs +++ b/crates/blenvy/src/blueprints/hot_reload.rs @@ -1,11 +1,11 @@ use crate::{BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintInfo, SpawnBlueprint}; -use bevy::asset::{AssetEvent, LoadedUntypedAsset}; +use bevy::asset::AssetEvent; use bevy::prelude::*; use bevy::scene::SceneInstance; pub(crate) fn react_to_asset_changes( mut gltf_events: EventReader>, - mut untyped_events: EventReader>, + // mut untyped_events: EventReader>, mut blueprint_assets: Query<( Entity, Option<&Name>, @@ -22,7 +22,7 @@ pub(crate) fn react_to_asset_changes( AssetEvent::Modified { id } => { // React to the image being modified // println!("Modified gltf {:?}", asset_server.get_path(*id)); - for (entity, entity_name, blueprint_info, mut assets_to_load, children) in + for (entity, entity_name, _blueprint_info, mut assets_to_load, children) in blueprint_assets.iter_mut() { for tracker in assets_to_load.asset_infos.iter_mut() { diff --git a/crates/blenvy/src/blueprints/materials.rs b/crates/blenvy/src/blueprints/materials.rs index a464ddb..62ec6bd 100644 --- a/crates/blenvy/src/blueprints/materials.rs +++ b/crates/blenvy/src/blueprints/materials.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; -use crate::{BlenvyConfig, BlueprintReadyForPostProcess}; +use crate::BlenvyConfig; #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] diff --git a/crates/blenvy/src/blueprints/mod.rs b/crates/blenvy/src/blueprints/mod.rs index 7194bf0..c089d72 100644 --- a/crates/blenvy/src/blueprints/mod.rs +++ b/crates/blenvy/src/blueprints/mod.rs @@ -16,13 +16,10 @@ pub use materials::*; pub mod copy_components; pub use copy_components::*; -pub mod hot_reload; -pub use hot_reload::*; +pub(crate) mod hot_reload; +pub(crate) use hot_reload::*; -use core::fmt; -use std::path::PathBuf; - -use bevy::{prelude::*, render::primitives::Aabb, utils::HashMap}; +use bevy::{prelude::*, utils::HashMap}; use crate::{BlenvyConfig, GltfComponentsSet}; @@ -112,8 +109,8 @@ impl Plugin for BlueprintsPlugin { .register_type::>>() .register_type::>>>() .add_event::() - .register_type::() - .register_type::>() + .register_type::() + .register_type::>() .register_type::>() .register_type::() .register_type::>>() diff --git a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs index 81868ce..a643f6e 100644 --- a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs +++ b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs @@ -1,4 +1,4 @@ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use bevy::{gltf::Gltf, prelude::*, scene::SceneInstance, utils::hashbrown::HashMap}; use serde_json::Value; @@ -113,7 +113,7 @@ Overview of the Blueprint Spawning process */ pub(crate) fn blueprints_prepare_spawn( - blueprint_instances_to_spawn: Query<(Entity, &BlueprintInfo), (Added)>, + blueprint_instances_to_spawn: Query<(Entity, &BlueprintInfo), Added>, mut commands: Commands, asset_server: Res, ) { @@ -401,8 +401,7 @@ pub(crate) fn blueprints_scenes_spawned( all_children: Query<&Children>, all_parents: Query<&Parent>, - mut sub_blueprint_trackers: Query<(Entity, &mut SubBlueprintsSpawnTracker, &BlueprintInfo)>, - + // mut sub_blueprint_trackers: Query<(Entity, &mut SubBlueprintsSpawnTracker, &BlueprintInfo)>, mut commands: Commands, all_names: Query<&Name>, @@ -511,7 +510,7 @@ pub(crate) fn blueprints_cleanup_spawned_scene( >, added_animation_players: Query<(Entity, &Parent), Added>, - mut sub_blueprint_trackers: Query<(Entity, &mut SubBlueprintsSpawnTracker, &BlueprintInfo)>, + mut sub_blueprint_trackers: Query<&mut SubBlueprintsSpawnTracker, With>, all_children: Query<&Children>, mut commands: Commands, @@ -593,9 +592,7 @@ pub(crate) fn blueprints_cleanup_spawned_scene( if let Some(track_root) = track_root { let root_name = all_names.get(track_root.0); println!("got some root {:?}", root_name); - if let Ok((s_entity, mut tracker, bp_info)) = - sub_blueprint_trackers.get_mut(track_root.0) - { + if let Ok(mut tracker) = sub_blueprint_trackers.get_mut(track_root.0) { tracker .sub_blueprint_instances .entry(original) diff --git a/crates/blenvy/src/components/mod.rs b/crates/blenvy/src/components/mod.rs index e300b46..d79a79f 100644 --- a/crates/blenvy/src/components/mod.rs +++ b/crates/blenvy/src/components/mod.rs @@ -10,7 +10,7 @@ pub use process_gltfs::*; pub mod blender_settings; use bevy::{ - ecs::{component::Component, reflect::ReflectComponent, system::Resource}, + ecs::{component::Component, reflect::ReflectComponent}, prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update}, reflect::Reflect, }; diff --git a/crates/blenvy/src/components/ronstring_to_reflect_component.rs b/crates/blenvy/src/components/ronstring_to_reflect_component.rs index 56dfc5a..faf2cf7 100644 --- a/crates/blenvy/src/components/ronstring_to_reflect_component.rs +++ b/crates/blenvy/src/components/ronstring_to_reflect_component.rs @@ -1,5 +1,5 @@ use bevy::log::{debug, warn}; -use bevy::reflect::serde::{ReflectDeserializer, ReflectSerializer}; +use bevy::reflect::serde::ReflectDeserializer; use bevy::reflect::{Reflect, TypeRegistration, TypeRegistry}; use bevy::utils::HashMap; use ron::Value; diff --git a/testing/bevy_example/assets/registry.json b/testing/bevy_example/assets/registry.json index 54a49df..4bb1026 100644 --- a/testing/bevy_example/assets/registry.json +++ b/testing/bevy_example/assets/registry.json @@ -250,16 +250,16 @@ "type": "array", "typeInfo": "List" }, - "alloc::vec::Vec": { + "alloc::vec::Vec": { "isComponent": false, "isResource": false, "items": { "type": { - "$ref": "#/$defs/blenvy::blueprints::assets::MyAsset" + "$ref": "#/$defs/blenvy::blueprints::assets::BlueprintAsset" } }, - "long_name": "alloc::vec::Vec", - "short_name": "Vec", + "long_name": "alloc::vec::Vec", + "short_name": "Vec", "type": "array", "typeInfo": "List" }, @@ -13354,6 +13354,31 @@ "type": "object", "typeInfo": "Struct" }, + "blenvy::blueprints::assets::BlueprintAsset": { + "additionalProperties": false, + "isComponent": true, + "isResource": false, + "long_name": "blenvy::blueprints::assets::BlueprintAsset", + "properties": { + "name": { + "type": { + "$ref": "#/$defs/alloc::string::String" + } + }, + "path": { + "type": { + "$ref": "#/$defs/alloc::string::String" + } + } + }, + "required": [ + "name", + "path" + ], + "short_name": "BlueprintAsset", + "type": "object", + "typeInfo": "Struct" + }, "blenvy::blueprints::assets::BlueprintAssets": { "additionalProperties": false, "isComponent": true, @@ -13362,7 +13387,7 @@ "properties": { "assets": { "type": { - "$ref": "#/$defs/alloc::vec::Vec" + "$ref": "#/$defs/alloc::vec::Vec" } }, "loaded": { @@ -13385,31 +13410,6 @@ "type": "object", "typeInfo": "Struct" }, - "blenvy::blueprints::assets::MyAsset": { - "additionalProperties": false, - "isComponent": true, - "isResource": false, - "long_name": "blenvy::blueprints::assets::MyAsset", - "properties": { - "name": { - "type": { - "$ref": "#/$defs/alloc::string::String" - } - }, - "path": { - "type": { - "$ref": "#/$defs/alloc::string::String" - } - } - }, - "required": [ - "name", - "path" - ], - "short_name": "MyAsset", - "type": "object", - "typeInfo": "Struct" - }, "blenvy::blueprints::materials::MaterialInfo": { "additionalProperties": false, "isComponent": true,