From 382759d71ff75078d3a1828586c532eb070cdd66 Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Mon, 22 Jul 2024 00:26:02 +0200 Subject: [PATCH] feat(Blenvy:Bevy): * removed file_watcher feature, should be user settable * added root blueprintInfo path to the list of assets to watch for hot reload * removed settable aabb calculation: they will now always be done * added "export_registry" setting to be able to disable registry export for wasm & co (automate later) * minor tweaks * cleanups --- crates/blenvy/Cargo.toml | 2 +- crates/blenvy/src/blueprints/aabb.rs | 3 +- crates/blenvy/src/blueprints/animation.rs | 44 ++++---- crates/blenvy/src/blueprints/assets.rs | 1 - crates/blenvy/src/blueprints/hot_reload.rs | 52 ++++----- crates/blenvy/src/blueprints/materials.rs | 7 +- crates/blenvy/src/blueprints/mod.rs | 9 +- .../src/blueprints/spawn_from_blueprints.rs | 101 ++++++++++++------ .../ronstring_to_reflect_component.rs | 1 - crates/blenvy/src/lib.rs | 12 +-- crates/blenvy/src/registry/mod.rs | 11 +- 11 files changed, 143 insertions(+), 100 deletions(-) diff --git a/crates/blenvy/Cargo.toml b/crates/blenvy/Cargo.toml index 72e90a0..c66ec47 100644 --- a/crates/blenvy/Cargo.toml +++ b/crates/blenvy/Cargo.toml @@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0" workspace = true [dependencies] -bevy = { version = "0.14", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf", "file_watcher"] } +bevy = { version = "0.14", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] } #, "file_watcher" serde = "1.0.188" ron = "0.8.1" serde_json = "1.0.108" diff --git a/crates/blenvy/src/blueprints/aabb.rs b/crates/blenvy/src/blueprints/aabb.rs index 8e46aef..3c3baed 100644 --- a/crates/blenvy/src/blueprints/aabb.rs +++ b/crates/blenvy/src/blueprints/aabb.rs @@ -37,8 +37,7 @@ pub fn compute_scene_aabbs( } } for entity in other_entities.iter() { - println!("already got AABB"); - commands.entity(entity).insert(BlueprintReadyForFinalizing); // FIXME ! Yikes !! + commands.entity(entity).insert(BlueprintReadyForFinalizing); } } diff --git a/crates/blenvy/src/blueprints/animation.rs b/crates/blenvy/src/blueprints/animation.rs index f4db6eb..b226702 100644 --- a/crates/blenvy/src/blueprints/animation.rs +++ b/crates/blenvy/src/blueprints/animation.rs @@ -87,10 +87,14 @@ pub struct AnimationMarkerReached { ///////////////////// - /// triggers events when a given animation marker is reached for BLUEPRINT animations pub fn trigger_blueprint_animation_markers_events( - animation_data: Query<(Entity, &BlueprintAnimationPlayerLink, &BlueprintAnimationInfosLink, &BlueprintAnimations)>, + animation_data: Query<( + Entity, + &BlueprintAnimationPlayerLink, + &BlueprintAnimationInfosLink, + &BlueprintAnimations, + )>, // FIXME: annoying hiearchy issue yet again: the Markers & AnimationInfos are stored INSIDE the blueprint, so we need to access them differently animation_infos: Query<(&AnimationInfos, &AnimationMarkers)>, animation_players: Query<&AnimationPlayer>, @@ -99,9 +103,7 @@ pub fn trigger_blueprint_animation_markers_events( animation_clips: Res>, ) { for (entity, player_link, infos_link, animations) in animation_data.iter() { - for (animation_name, node_index) in animations.named_indices.iter() { - let animation_player = animation_players.get(player_link.0).unwrap(); let (animation_infos, animation_markers) = animation_infos.get(infos_link.0).unwrap(); @@ -109,21 +111,24 @@ pub fn trigger_blueprint_animation_markers_events( if let Some(animation) = animation_player.animation(*node_index) { // animation.speed() // animation.completions() - if let Some(animation_clip_handle) = animations.named_animations.get(animation_name) { + if let Some(animation_clip_handle) = + animations.named_animations.get(animation_name) + { if let Some(animation_clip) = animation_clips.get(animation_clip_handle) { let animation_length_seconds = animation_clip.duration(); - let animation_length_frames = animation_infos // FIXME: horribly inneficient - .animations - .iter() - .find(|anim| &anim.name == animation_name) - .unwrap() - .frames_length; + let animation_length_frames = + animation_infos // FIXME: horribly inneficient + .animations + .iter() + .find(|anim| &anim.name == animation_name) + .unwrap() + .frames_length; - // TODO: we also need to take playback speed into account let time_in_animation = animation.elapsed() - - (animation.completions() as f32) * animation_length_seconds; - let frame_seconds = (animation_length_frames / animation_length_seconds) + - (animation.completions() as f32) * animation_length_seconds; + let frame_seconds = (animation_length_frames + / animation_length_seconds) * time_in_animation; // println!("frame seconds {}", frame_seconds); let frame = frame_seconds.ceil() as u32; // FIXME , bad hack @@ -133,7 +138,10 @@ pub fn trigger_blueprint_animation_markers_events( if matching_animation_marker.contains_key(&frame) { let matching_markers_per_frame = matching_animation_marker.get(&frame).unwrap(); - println!("FOUND A MARKER {:?} at frame {}", matching_markers_per_frame, frame); + println!( + "FOUND A MARKER {:?} at frame {}", + matching_markers_per_frame, frame + ); // FIXME: complete hack-ish solution , otherwise this can fire multiple times in a row, depending on animation length , speed , etc let diff = frame as f32 - frame_seconds; if diff < 0.1 { @@ -155,7 +163,6 @@ pub fn trigger_blueprint_animation_markers_events( } } - /// triggers events when a given animation marker is reached for INSTANCE animations pub fn trigger_instance_animation_markers_events( animation_infos: Query<( @@ -178,9 +185,10 @@ pub fn trigger_instance_animation_markers_events( let animation_player = animation_players.get(player_link.0).unwrap(); if animation_player.animation_is_playing(*node_index) { if let Some(animation) = animation_player.animation(*node_index) { - if let Some(animation_clip_handle) = animations.named_animations.get(animation_name) { + if let Some(animation_clip_handle) = + animations.named_animations.get(animation_name) + { if let Some(animation_clip) = animation_clips.get(animation_clip_handle) { - println!("helooo") } } diff --git a/crates/blenvy/src/blueprints/assets.rs b/crates/blenvy/src/blueprints/assets.rs index 7e3a67c..3659e4e 100644 --- a/crates/blenvy/src/blueprints/assets.rs +++ b/crates/blenvy/src/blueprints/assets.rs @@ -37,7 +37,6 @@ pub struct BlueprintAllAssets { pub assets: Vec, } - //////////////////////// /// /// flag component, usually added when a blueprint is loaded diff --git a/crates/blenvy/src/blueprints/hot_reload.rs b/crates/blenvy/src/blueprints/hot_reload.rs index 98e42fd..0624ff8 100644 --- a/crates/blenvy/src/blueprints/hot_reload.rs +++ b/crates/blenvy/src/blueprints/hot_reload.rs @@ -1,26 +1,23 @@ -use crate::{BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintInfo, BlueprintInstanceReady, BlueprintSpawning, FromBlueprint, SpawnBlueprint, SubBlueprintsSpawnTracker}; +use crate::{ + BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintInfo, BlueprintInstanceReady, + BlueprintSpawning, FromBlueprint, SpawnBlueprint, SubBlueprintsSpawnTracker, +}; use bevy::asset::AssetEvent; use bevy::prelude::*; use bevy::scene::SceneInstance; use bevy::utils::hashbrown::HashMap; - -/// Resource mapping asset paths (ideally untyped ids, but more complex) to a list of blueprint instance entity ids +/// Resource mapping asset paths (ideally untyped ids, but more complex) to a list of blueprint instance entity ids #[derive(Debug, Clone, Resource, Default)] -pub(crate) struct AssetToBlueprintInstancesMapper{ +pub(crate) struct AssetToBlueprintInstancesMapper { // pub(crate) untyped_id_to_blueprint_entity_ids: HashMap> - pub(crate) untyped_id_to_blueprint_entity_ids: HashMap> + pub(crate) untyped_id_to_blueprint_entity_ids: HashMap>, } pub(crate) fn react_to_asset_changes( mut gltf_events: EventReader>, // FIXME: Problem: we need to react to any asset change, not just gltf files ! // mut untyped_events: EventReader>, - blueprint_assets: Query<( - Entity, - Option<&Name>, - &BlueprintInfo, - Option<&Children>, - )>, + blueprint_assets: Query<(Entity, Option<&Name>, &BlueprintInfo, Option<&Children>)>, blueprint_children_entities: Query<&FromBlueprint>, //=> can only be used if the entites are tagged assets_to_blueprint_instances: Res, all_parents: Query<&Parent>, @@ -28,7 +25,6 @@ pub(crate) fn react_to_asset_changes( asset_server: Res, mut commands: Commands, - ) { let mut respawn_candidates: Vec<&Entity> = vec![]; @@ -44,15 +40,19 @@ pub(crate) fn react_to_asset_changes( // let bla = untyped.unwrap().id(); // asset_server.get // in order to avoid respawn both a parent & a child , which would crash Bevy, we do things in two steps - if let Some(entities) = assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.get(&asset_path.to_string()) { + if let Some(entities) = assets_to_blueprint_instances + .untyped_id_to_blueprint_entity_ids + .get(&asset_path.to_string()) + { for entity in entities.iter() { - println!("matching blueprint instance {}", entity); - // disregard entities that are already (re) spawning - if !respawn_candidates.contains(&entity) && blueprint_assets.get(*entity).is_ok() && spawning_blueprints.get(*entity).is_err() + // println!("matching blueprint instance {}", entity); + // disregard entities that are already (re) spawning + if !respawn_candidates.contains(&entity) + && blueprint_assets.get(*entity).is_ok() + && spawning_blueprints.get(*entity).is_err() { respawn_candidates.push(entity); } - } } } @@ -65,27 +65,29 @@ pub(crate) fn react_to_asset_changes( // TODO: improve this, very inneficient let mut retained_candidates: Vec = vec![]; 'outer: for entity in respawn_candidates.iter() { - for parent in all_parents.iter_ancestors(**entity){ + for parent in all_parents.iter_ancestors(**entity) { for ent in respawn_candidates.iter() { if **ent == parent { - if ! retained_candidates.contains(&parent) { + if !retained_candidates.contains(&parent) { retained_candidates.push(parent); } continue 'outer; } } } - if ! retained_candidates.contains(entity) { + if !retained_candidates.contains(entity) { retained_candidates.push(**entity); } } // println!("respawn candidates {:?}", respawn_candidates); for retained in retained_candidates.iter() { - println!("retained {}", retained); + // println!("retained {}", retained); + + if let Ok((entity, entity_name, _blueprint_info, children)) = + blueprint_assets.get(*retained) + { + info!("Change detected !!, now respawn {:?}", entity_name); - if let Ok((entity, entity_name, _blueprint_info, children)) = blueprint_assets.get(*retained) { - println!("HOLY MOLY IT DETECTS !!, now respawn {:?}", entity_name); - // TODO: only remove those that are "in blueprint" if children.is_some() { for child in children.unwrap().iter() { @@ -100,7 +102,7 @@ pub(crate) fn react_to_asset_changes( .remove::() .remove::() .insert(SpawnBlueprint); - } + } } // println!("done with asset updates"); diff --git a/crates/blenvy/src/blueprints/materials.rs b/crates/blenvy/src/blueprints/materials.rs index 2e84770..d91a213 100644 --- a/crates/blenvy/src/blueprints/materials.rs +++ b/crates/blenvy/src/blueprints/materials.rs @@ -53,7 +53,12 @@ pub(crate) fn inject_materials( material_found = Some(material); } else { let model_handle: Handle = asset_server.load(material_info.path.clone()); // FIXME: kinda weird now - let mat_gltf = assets_gltf.get(model_handle.id()).unwrap_or_else(|| panic!("materials file {} should have been preloaded", material_info.path)); + let mat_gltf = assets_gltf.get(model_handle.id()).unwrap_or_else(|| { + panic!( + "materials file {} should have been preloaded", + material_info.path + ) + }); if mat_gltf .named_materials .contains_key(&material_info.name as &str) diff --git a/crates/blenvy/src/blueprints/mod.rs b/crates/blenvy/src/blueprints/mod.rs index fe78ada..4a1c2d2 100644 --- a/crates/blenvy/src/blueprints/mod.rs +++ b/crates/blenvy/src/blueprints/mod.rs @@ -50,19 +50,14 @@ impl Default for BluePrintBundle { #[derive(Debug, Clone)] /// Plugin for gltf blueprints pub struct BlueprintsPlugin { - /// Automatically generate aabbs for the blueprints root objects - pub aabbs: bool, } impl Default for BlueprintsPlugin { fn default() -> Self { - Self { aabbs: false } + Self { } } } -fn aabbs_enabled(blenvy_config: Res) -> bool { - blenvy_config.aabbs -} fn hot_reload(watching_for_changes: Res) -> bool { // println!("hot reload ? {}", watching_for_changes.0); @@ -131,7 +126,7 @@ impl Plugin for BlueprintsPlugin { blueprints_cleanup_spawned_scene, // beyond this point : post processing to finalize blueprint instances inject_materials, - compute_scene_aabbs, // .run_if(aabbs_enabled), + compute_scene_aabbs, blueprints_finalize_instances, ) .chain() diff --git a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs index 07b1b9f..67b9c8a 100644 --- a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs +++ b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs @@ -4,7 +4,10 @@ use bevy::{gltf::Gltf, prelude::*, scene::SceneInstance, utils::hashbrown::HashM use serde_json::Value; use crate::{ - AnimationInfos, AssetLoadTracker, AssetToBlueprintInstancesMapper, BlenvyConfig, BlueprintAnimationInfosLink, BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintAssets, BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintAssetsNotLoaded, InstanceAnimationInfosLink, InstanceAnimationPlayerLink, InstanceAnimations, WatchingForChanges + AnimationInfos, AssetLoadTracker, AssetToBlueprintInstancesMapper, BlueprintAnimationInfosLink, + BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintAssets, BlueprintAssetsLoadState, + BlueprintAssetsLoaded, BlueprintAssetsNotLoaded, InstanceAnimationInfosLink, + InstanceAnimationPlayerLink, InstanceAnimations, WatchingForChanges, }; /// this is a flag component for our levels/game world @@ -38,7 +41,7 @@ pub struct SpawnBlueprint; #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] -/// flag component marking any spawned child of blueprints +/// flag component marking any spawned child of blueprints pub struct FromBlueprint; // TODO: move to save_load @@ -89,7 +92,6 @@ pub enum BlueprintEvent { }, } - #[derive(Component, Reflect, Debug, Default)] #[reflect(Component)] /// component gets added when a blueprint starts spawning, removed when spawning is completely done @@ -97,7 +99,6 @@ pub struct BlueprintSpawning; use gltf::Gltf as RawGltf; - /* Overview of the Blueprint Spawning process - Blueprint Load Assets @@ -115,10 +116,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, // for hot reload @@ -153,9 +151,9 @@ pub(crate) fn blueprints_prepare_spawn( /* prefetch attempt */ let gltf = RawGltf::open(format!("assets/{}", blueprint_info.path)).unwrap(); for scene in gltf.scenes() { - if let Some(scene_extras) = scene.extras().clone() - { - let lookup: HashMap = serde_json::from_str(scene_extras.get()).unwrap(); + if let Some(scene_extras) = scene.extras().clone() { + let lookup: HashMap = + serde_json::from_str(scene_extras.get()).unwrap(); if lookup.contains_key("BlueprintAssets") { let assets_raw = &lookup["BlueprintAssets"]; //println!("ASSETS RAW {}", assets_raw); @@ -183,21 +181,59 @@ pub(crate) fn blueprints_prepare_spawn( // Only do this if hot reload is enabled if watching_for_changes.0 { - if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.contains_key(&path_id) { - assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.insert(path_id.clone(), vec![]); + if !assets_to_blueprint_instances + .untyped_id_to_blueprint_entity_ids + .contains_key(&path_id) + { + assets_to_blueprint_instances + .untyped_id_to_blueprint_entity_ids + .insert(path_id.clone(), vec![]); } + // only insert if not already present in mapping - if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids[&path_id].contains(&entity) { + if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids + [&path_id] + .contains(&entity) + { // println!("adding mapping between {} and entity {:?}", path_id, all_names.get(entity)); - assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.get_mut(&path_id).unwrap().push(entity); + assets_to_blueprint_instances + .untyped_id_to_blueprint_entity_ids + .get_mut(&path_id) + .unwrap() + .push(entity); } } - } } } } + // Only do this if hot reload is enabled + // TODO: should this be added to the list of "all assets" on the blender side instead + if watching_for_changes.0 { + // also add the root blueprint info to the list of hot reload items + if !assets_to_blueprint_instances + .untyped_id_to_blueprint_entity_ids + .contains_key(&blueprint_info.path) + { + assets_to_blueprint_instances + .untyped_id_to_blueprint_entity_ids + .insert(blueprint_info.path.clone(), vec![]); + } + // only insert if not already present in mapping + if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids + [&blueprint_info.path] + .contains(&entity) + { + // println!("adding mapping between {} and entity {:?}", path_id, all_names.get(entity)); + assets_to_blueprint_instances + .untyped_id_to_blueprint_entity_ids + .get_mut(&blueprint_info.path) + .unwrap() + .push(entity); + } + } + // now insert load tracker // if there are assets to load if !asset_infos.is_empty() { @@ -243,7 +279,9 @@ pub(crate) fn blueprints_check_assets_loading( let loaded = asset_server.is_loaded_with_dependencies(asset_id); let mut failed = false; - if let bevy::asset::LoadState::Failed(_) = asset_server.load_state(asset_id) { failed = true } + if let bevy::asset::LoadState::Failed(_) = asset_server.load_state(asset_id) { + failed = true + } tracker.loaded = loaded || failed; if loaded || failed { loaded_amount += 1; @@ -267,12 +305,10 @@ pub(crate) fn blueprints_check_assets_loading( commands .entity(entity) .insert(BlueprintAssetsLoaded) - .remove::() - ; + .remove::(); if !watching_for_changes.0 { - commands.entity(entity) - .remove::(); //we REMOVE this component when in hot reload is OFF, as we + commands.entity(entity).remove::(); //we REMOVE this component when in hot reload is OFF, as we } } } @@ -556,12 +592,11 @@ pub(crate) fn blueprints_cleanup_spawned_scene( all_names: Query<&Name>, ) { - for (original, children, original_children, name, animations) in - blueprint_scenes.iter() - { + for (original, children, original_children, name, animations) in blueprint_scenes.iter() { info!("Cleaning up spawned scene {:?}", name); - if children.len() == 0 { // TODO: investigate, Honestly not sure if this issue from Bevy 0.12 is still present at all anymore + if children.len() == 0 { + // TODO: investigate, Honestly not sure if this issue from Bevy 0.12 is still present at all anymore warn!("timing issue ! no children found, please restart your bevy app (bug being investigated)"); continue; } @@ -581,7 +616,6 @@ pub(crate) fn blueprints_cleanup_spawned_scene( for child in all_children.iter_descendants(blueprint_root_entity) { commands.entity(child).insert(FromBlueprint); // we do this here in order to avoid doing it to normal children } - // copy components into from blueprint instance's blueprint_root_entity to original entity commands.add(CopyComponents { @@ -632,14 +666,10 @@ pub(crate) fn blueprints_cleanup_spawned_scene( all_names.get(child), all_names.get(original) ); - commands - .entity(original) - .insert( + commands.entity(original).insert( //BlueprintAnimationPlayerLink(bla), - BlueprintAnimationInfosLink(child) - ) - ; - + BlueprintAnimationInfosLink(child), + ); } else { for parent in all_parents.iter_ancestors(child) { if animation_players.get(parent).is_ok() { @@ -663,8 +693,9 @@ pub(crate) fn blueprints_cleanup_spawned_scene( )); } if with_animation_infos.get(parent).is_ok() { - commands.entity(child).insert(InstanceAnimationInfosLink(parent)); - + commands + .entity(child) + .insert(InstanceAnimationInfosLink(parent)); } } } diff --git a/crates/blenvy/src/components/ronstring_to_reflect_component.rs b/crates/blenvy/src/components/ronstring_to_reflect_component.rs index faf2cf7..6f9473e 100644 --- a/crates/blenvy/src/components/ronstring_to_reflect_component.rs +++ b/crates/blenvy/src/components/ronstring_to_reflect_component.rs @@ -65,7 +65,6 @@ fn components_string_to_components( ron::ser::to_string_pretty(&serializer, ron::ser::PrettyConfig::default()).unwrap(); println!("serialized Component {}", serialized); */ - debug!("component data ron string {}", ron_string); let mut deserializer = ron::Deserializer::from_str(ron_string.as_str()) .expect("deserialzer should have been generated from string"); diff --git a/crates/blenvy/src/lib.rs b/crates/blenvy/src/lib.rs index 01bc10b..abec7ac 100644 --- a/crates/blenvy/src/lib.rs +++ b/crates/blenvy/src/lib.rs @@ -13,13 +13,13 @@ pub use blueprints::*; #[derive(Clone, Resource)] pub struct BlenvyConfig { // registry + pub(crate) export_registry: bool, pub(crate) registry_save_path: PathBuf, pub(crate) registry_component_filter: SceneFilter, #[allow(dead_code)] pub(crate) registry_resource_filter: SceneFilter, // blueprints - pub(crate) aabbs: bool, pub(crate) aabb_cache: HashMap, // cache for aabbs pub(crate) materials_cache: HashMap>, // cache for materials @@ -31,14 +31,12 @@ pub struct BlenvyConfig { #[derive(Debug, Clone)] /// Plugin for gltf blueprints pub struct BlenvyPlugin { + pub export_registry: bool, pub registry_save_path: PathBuf, pub registry_component_filter: SceneFilter, pub registry_resource_filter: SceneFilter, - /// Automatically generate aabbs for the blueprints root objects - pub aabbs: bool, - // for save & load pub save_component_filter: SceneFilter, pub save_resource_filter: SceneFilter, @@ -47,10 +45,10 @@ pub struct BlenvyPlugin { impl Default for BlenvyPlugin { fn default() -> Self { Self { + export_registry: true, registry_save_path: PathBuf::from("registry.json"), // relative to assets folder registry_component_filter: SceneFilter::default(), registry_resource_filter: SceneFilter::default(), - aabbs: false, save_component_filter: SceneFilter::default(), save_resource_filter: SceneFilter::default(), @@ -66,17 +64,17 @@ impl Plugin for BlenvyPlugin { BlueprintsPlugin::default(), )) .insert_resource(BlenvyConfig { + export_registry: self.export_registry, registry_save_path: self.registry_save_path.clone(), registry_component_filter: self.registry_component_filter.clone(), registry_resource_filter: self.registry_resource_filter.clone(), - aabbs: self.aabbs, aabb_cache: HashMap::new(), materials_cache: HashMap::new(), save_component_filter: self.save_component_filter.clone(), - save_resource_filter: self.save_resource_filter.clone() + save_resource_filter: self.save_resource_filter.clone(), }); } } diff --git a/crates/blenvy/src/registry/mod.rs b/crates/blenvy/src/registry/mod.rs index 12dcc46..0c924e6 100644 --- a/crates/blenvy/src/registry/mod.rs +++ b/crates/blenvy/src/registry/mod.rs @@ -6,10 +6,12 @@ pub use export_types::*; use bevy::{ app::Startup, asset::AssetPlugin, - prelude::{App, Plugin, Resource}, + prelude::{App, IntoSystemConfigs, Plugin, Res, Resource}, scene::SceneFilter, }; +use crate::BlenvyConfig; + pub struct ExportRegistryPlugin { pub component_filter: SceneFilter, pub resource_filter: SceneFilter, @@ -26,9 +28,14 @@ impl Default for ExportRegistryPlugin { } } +fn export_registry(blenvy_config: Res) -> bool { + // TODO: add detection of Release builds, wasm, and android in order to avoid exporting registry in those cases + blenvy_config.export_registry +} + impl Plugin for ExportRegistryPlugin { fn build(&self, app: &mut App) { - app.register_asset_root().add_systems(Startup, export_types); + app.register_asset_root().add_systems(Startup, export_types.run_if(export_registry)); } }