chore(Blenvy:Bevy): more cleanups

This commit is contained in:
kaosat.dev 2024-07-08 13:30:46 +02:00
parent 459bb868e0
commit 70931ee163
10 changed files with 56 additions and 66 deletions

View File

@ -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<MyAsset>);
pub struct LocalAssets(pub Vec<BlueprintAsset>);
/// 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<MyAsset>);
pub struct BlueprintAssets(pub Vec<BlueprintAsset>);
////////////////////////
///

View File

@ -119,8 +119,8 @@ impl Plugin for BlueprintsPlugin {
.register_type::<HashMap<u32, Vec<String>>>()
.register_type::<HashMap<String, HashMap<u32, Vec<String>>>>()
.add_event::<AnimationMarkerReached>()
.register_type::<MyAsset>()
.register_type::<Vec<MyAsset>>()
.register_type::<BlueprintAsset>()
.register_type::<Vec<BlueprintAsset>>()
.register_type::<Vec<String>>()
.register_type::<LocalAssets>()
.register_type::<BlueprintAssets>()

View File

@ -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<MyAsset>,
pub assets: Vec<BlueprintAsset>,
/// set to default when deserializing
#[serde(default)]
#[reflect(default)]
@ -31,7 +27,7 @@ pub struct BlueprintAssets {
#[serde(skip)]
pub asset_infos: Vec<AssetLoadTracker>,
}
//(pub Vec<MyAsset>);
//(pub Vec<BlueprintAsset>);
////////////////////////
///
@ -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,

View File

@ -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<AssetEvent<Gltf>>,
mut untyped_events: EventReader<AssetEvent<LoadedUntypedAsset>>,
// mut untyped_events: EventReader<AssetEvent<LoadedUntypedAsset>>,
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() {

View File

@ -1,6 +1,6 @@
use bevy::prelude::*;
use crate::{BlenvyConfig, BlueprintReadyForPostProcess};
use crate::BlenvyConfig;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]

View File

@ -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::<HashMap<u32, Vec<String>>>()
.register_type::<HashMap<String, HashMap<u32, Vec<String>>>>()
.add_event::<AnimationMarkerReached>()
.register_type::<MyAsset>()
.register_type::<Vec<MyAsset>>()
.register_type::<BlueprintAsset>()
.register_type::<Vec<BlueprintAsset>>()
.register_type::<Vec<String>>()
.register_type::<BlueprintAssets>()
.register_type::<HashMap<String, Vec<String>>>()

View File

@ -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<SpawnBlueprint>)>,
blueprint_instances_to_spawn: Query<(Entity, &BlueprintInfo), Added<SpawnBlueprint>>,
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
@ -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<AnimationPlayer>>,
mut sub_blueprint_trackers: Query<(Entity, &mut SubBlueprintsSpawnTracker, &BlueprintInfo)>,
mut sub_blueprint_trackers: Query<&mut SubBlueprintsSpawnTracker, With<BlueprintInfo>>,
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)

View File

@ -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,
};

View File

@ -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;

View File

@ -250,16 +250,16 @@
"type": "array",
"typeInfo": "List"
},
"alloc::vec::Vec<blenvy::blueprints::assets::MyAsset>": {
"alloc::vec::Vec<blenvy::blueprints::assets::BlueprintAsset>": {
"isComponent": false,
"isResource": false,
"items": {
"type": {
"$ref": "#/$defs/blenvy::blueprints::assets::MyAsset"
"$ref": "#/$defs/blenvy::blueprints::assets::BlueprintAsset"
}
},
"long_name": "alloc::vec::Vec<blenvy::blueprints::assets::MyAsset>",
"short_name": "Vec<MyAsset>",
"long_name": "alloc::vec::Vec<blenvy::blueprints::assets::BlueprintAsset>",
"short_name": "Vec<BlueprintAsset>",
"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<blenvy::blueprints::assets::MyAsset>"
"$ref": "#/$defs/alloc::vec::Vec<blenvy::blueprints::assets::BlueprintAsset>"
}
},
"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,