chore(Blenvy:Bevy): cargo fmt

This commit is contained in:
kaosat.dev 2024-07-08 13:18:21 +02:00
parent c326a11243
commit 459bb868e0
28 changed files with 561 additions and 526 deletions

View File

@ -73,7 +73,7 @@ pub struct AnimationMarkerReached {
/////////////////////
/*
/*
/// triggers events when a given animation marker is reached for INSTANCE animations
pub fn trigger_instance_animation_markers_events(
animation_infos: Query<(
@ -218,4 +218,4 @@ pub fn trigger_blueprint_animation_markers_events(
}
}
}
*/
*/

View File

@ -7,9 +7,9 @@ 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 MyAsset {
pub name: String,
pub path: String
pub path: String,
}
/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints
@ -22,10 +22,8 @@ pub struct LocalAssets(pub Vec<MyAsset>);
#[reflect(Component)]
pub struct BlueprintAssets(pub Vec<MyAsset>);
////////////////////////
///
///
/// flag component, usually added when a blueprint is loaded
#[derive(Component)]
pub(crate) struct BlueprintAssetsLoaded;
@ -44,7 +42,6 @@ pub(crate) struct AssetLoadTracker {
pub handle: Handle<LoadedUntypedAsset>,
}
/// helper component, for tracking loaded assets
#[derive(Component, Debug)]
pub(crate) struct AssetsToLoad {

View File

@ -90,7 +90,7 @@ impl Default for BlueprintsPlugin {
fn default() -> Self {
Self {
aabbs: false,
material_library: false
material_library: false,
}
}
}

View File

@ -41,8 +41,6 @@ pub(crate) fn materials_inject(
asset_server: Res<AssetServer>,
mut commands: Commands,
) {
for (entity, material_info) in material_infos.iter() {
println!("Entity with material info {:?} {:?}", entity, material_info);
let material_full_path = format!("{}#{}", material_info.path, material_info.name);
@ -59,9 +57,9 @@ pub(crate) fn materials_inject(
.entity(entity)
.insert(BlueprintMaterialAssetsLoaded);
} else {
let material_file_handle = asset_server.load_untyped(&material_info.path.clone()); // : Handle<Gltf>
let material_file_handle = asset_server.load_untyped(&material_info.path.clone()); // : Handle<Gltf>
let material_file_id = material_file_handle.id();
let asset_infos: Vec<AssetLoadTracker> = vec![AssetLoadTracker {
name: material_info.name.clone(),
id: material_file_id,
@ -77,7 +75,6 @@ pub(crate) fn materials_inject(
..Default::default()
})
.insert(BlueprintMaterialAssetsNotLoaded);
}
}
}
@ -160,7 +157,10 @@ pub(crate) fn materials_inject2(
let mat_gltf = assets_gltf
.get(model_handle.id())
.expect("material should have been preloaded");
if mat_gltf.named_materials.contains_key(&material_info.name as &str) {
if mat_gltf
.named_materials
.contains_key(&material_info.name as &str)
{
let material = mat_gltf
.named_materials
.get(&material_info.name as &str)

View File

@ -2,7 +2,10 @@ use std::path::{Path, PathBuf};
use bevy::{gltf::Gltf, prelude::*, utils::hashbrown::HashMap};
use crate::{BlueprintAssets, AssetsToLoad, AssetLoadTracker, BluePrintsConfig, BlueprintAnimations, BlueprintAssetsLoaded, BlueprintAssetsNotLoaded};
use crate::{
AssetLoadTracker, AssetsToLoad, BluePrintsConfig, BlueprintAnimations, BlueprintAssets,
BlueprintAssetsLoaded, BlueprintAssetsNotLoaded,
};
/// this is a flag component for our levels/game world
#[derive(Component)]
@ -27,9 +30,8 @@ pub struct SpawnHere;
/// flag component for dynamically spawned scenes
pub struct Spawned;
#[derive(Component, Debug)]
/// flag component added when a Blueprint instance ist Ready : ie :
/// flag component added when a Blueprint instance ist Ready : ie :
/// - its assets have loaded
/// - it has finished spawning
pub struct BlueprintInstanceReady;
@ -58,15 +60,11 @@ pub struct AddToGameWorld;
/// helper component, just to transfer child data
pub(crate) struct OriginalChildren(pub Vec<Entity>);
pub(crate) fn test_thingy(
spawn_placeholders: Query<
(
Entity,
&BlueprintPath,
),
(Added<BlueprintPath>, Without<Spawned>, Without<SpawnHere>)>,
(Entity, &BlueprintPath),
(Added<BlueprintPath>, Without<Spawned>, Without<SpawnHere>),
>,
// before 0.14 we have to use a seperate query, after migrating we can query at the root level
entities_with_assets: Query<
@ -81,17 +79,12 @@ pub(crate) fn test_thingy(
(Added<BlueprintAssets>), // Added<BlueprintAssets>
>,
bla_bla : Query<
(Entity,
&BlueprintName,
&BlueprintPath,
Option<&Parent>,),(Added<BlueprintPath>)
bla_bla: Query<
(Entity, &BlueprintName, &BlueprintPath, Option<&Parent>),
(Added<BlueprintPath>),
>,
mut commands: Commands,
asset_server: Res<AssetServer>,
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
for (entity, blueprint_path) in spawn_placeholders.iter() {
//println!("added blueprint_path {:?}", blueprint_path);
@ -105,7 +98,10 @@ asset_server: Res<AssetServer>,
}
for (entity, blueprint_name, blueprint_path, parent) in bla_bla.iter() {
println!("added blueprint to spawn {:?} {:?}", blueprint_name, blueprint_path);
println!(
"added blueprint to spawn {:?} {:?}",
blueprint_name, blueprint_path
);
let untyped_handle = asset_server.load_untyped(&blueprint_path.0);
let asset_id = untyped_handle.id();
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
@ -135,7 +131,7 @@ asset_server: Res<AssetServer>,
}
}
for (child_entity, child_entity_name, all_assets) in entities_with_assets.iter(){
for (child_entity, child_entity_name, all_assets) in entities_with_assets.iter() {
println!("added assets {:?} to {:?}", all_assets, child_entity_name);
if all_assets.is_some() {
let mut asset_infos: Vec<AssetLoadTracker> = vec![];
@ -184,21 +180,23 @@ pub(crate) fn check_for_loaded2(
asset_server: Res<AssetServer>,
mut commands: Commands,
) {
for (entity,entity_name, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
for (entity, entity_name, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
let mut all_loaded = true;
let mut loaded_amount = 0;
let total = assets_to_load.asset_infos.len();
for tracker in assets_to_load.asset_infos.iter_mut() {
let asset_id = tracker.id;
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
println!("loading {}: // load state: {:?}", tracker.name, asset_server.load_state(asset_id));
println!(
"loading {}: // load state: {:?}",
tracker.name,
asset_server.load_state(asset_id)
);
// FIXME: hack for now
let mut failed = false;// asset_server.load_state(asset_id) == bevy::asset::LoadState::Failed(_error);
let mut failed = false; // asset_server.load_state(asset_id) == bevy::asset::LoadState::Failed(_error);
match asset_server.load_state(asset_id) {
bevy::asset::LoadState::Failed(_) => {
failed = true
},
bevy::asset::LoadState::Failed(_) => failed = true,
_ => {}
}
tracker.loaded = loaded || failed;
@ -209,7 +207,7 @@ pub(crate) fn check_for_loaded2(
}
}
let progress: f32 = loaded_amount as f32 / total as f32;
println!("progress: {}",progress);
println!("progress: {}", progress);
assets_to_load.progress = progress;
if all_loaded {
@ -219,14 +217,11 @@ pub(crate) fn check_for_loaded2(
.entity(entity)
.insert(BlueprintAssetsLoaded)
.remove::<BlueprintAssetsNotLoaded>()
.remove::<AssetsToLoad>()
;
.remove::<AssetsToLoad>();
}
}
}
pub(crate) fn spawn_from_blueprints2(
spawn_placeholders: Query<
(
@ -254,15 +249,8 @@ pub(crate) fn spawn_from_blueprints2(
children: Query<&Children>,
) {
for (
entity,
blupeprint_name,
blueprint_path,
transform,
original_parent,
add_to_world,
name,
) in spawn_placeholders.iter()
for (entity, blupeprint_name, blueprint_path, transform, original_parent, add_to_world, name) in
spawn_placeholders.iter()
{
info!(
"attempting to spawn blueprint {:?} for entity {:?}, id: {:?}, parent:{:?}",
@ -272,12 +260,9 @@ pub(crate) fn spawn_from_blueprints2(
// info!("attempting to spawn {:?}", model_path);
let model_handle: Handle<Gltf> = asset_server.load(blueprint_path.0.clone()); // FIXME: kinda weird now
let gltf = assets_gltf.get(&model_handle).unwrap_or_else(|| {
panic!(
"gltf file {:?} should have been loaded",
&blueprint_path.0
)
});
let gltf = assets_gltf
.get(&model_handle)
.unwrap_or_else(|| panic!("gltf file {:?} should have been loaded", &blueprint_path.0));
// WARNING we work under the assumtion that there is ONLY ONE named scene, and that the first one is the right one
let main_scene_name = gltf
@ -301,7 +286,7 @@ pub(crate) fn spawn_from_blueprints2(
}
}
let mut named_animations:HashMap<String, Handle<AnimationClip>> = HashMap::new() ;
let mut named_animations: HashMap<String, Handle<AnimationClip>> = HashMap::new();
for (key, value) in gltf.named_animations.iter() {
named_animations.insert(key.to_string(), value.clone());
}
@ -317,7 +302,7 @@ pub(crate) fn spawn_from_blueprints2(
OriginalChildren(original_children),
BlueprintAnimations {
// these are animations specific to the inside of the blueprint
named_animations: named_animations//gltf.named_animations.clone(),
named_animations: named_animations, //gltf.named_animations.clone(),
},
));
@ -329,8 +314,3 @@ pub(crate) fn spawn_from_blueprints2(
}
}
}

View File

@ -16,36 +16,42 @@ use bevy::{
use crate::{ronstring_to_reflect_component, GltfProcessed};
// , mut entity_components: HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>>
fn find_entity_components(entity: Entity, name: &Name, parent: &Parent, reflect_components: Vec<(Box<dyn Reflect>, TypeRegistration)>, entity_components: &HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>>) -> (Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>){
// we assign the components specified /xxx_components objects to their parent node
let mut target_entity = entity;
// if the node contains "components" or ends with "_pa" (ie add to parent), the components will not be added to the entity itself but to its parent
// this is mostly used for Blender collections
if name.as_str().contains("components") || name.as_str().ends_with("_pa") {
debug!("adding components to parent");
target_entity = parent.get();
}
debug!("adding to {:?}", target_entity);
fn find_entity_components(
entity: Entity,
name: &Name,
parent: &Parent,
reflect_components: Vec<(Box<dyn Reflect>, TypeRegistration)>,
entity_components: &HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>>,
) -> (Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>) {
// we assign the components specified /xxx_components objects to their parent node
let mut target_entity = entity;
// if the node contains "components" or ends with "_pa" (ie add to parent), the components will not be added to the entity itself but to its parent
// this is mostly used for Blender collections
if name.as_str().contains("components") || name.as_str().ends_with("_pa") {
debug!("adding components to parent");
target_entity = parent.get();
}
debug!("adding to {:?}", target_entity);
// if there where already components set to be added to this entity (for example when entity_data was refering to a parent), update the vec of entity_components accordingly
// this allows for example blender collection to provide basic ecs data & the instances to override/ define their own values
if entity_components.contains_key(&target_entity) {
let mut updated_components: Vec<(Box<dyn Reflect>, TypeRegistration)> = Vec::new();
let current_components = &entity_components[&target_entity];
// first inject the current components
for (component, type_registration) in current_components {
updated_components.push((component.clone_value(), type_registration.clone()));
}
// then inject the new components: this also enables overwrite components set in the collection
for (component, type_registration) in reflect_components {
updated_components.push((component.clone_value(), type_registration));
}
return (target_entity, updated_components)
//entity_components.insert(target_entity, updated_components);
} else {
return (target_entity, reflect_components);
// entity_components.insert(target_entity, reflect_components);
}
// if there where already components set to be added to this entity (for example when entity_data was refering to a parent), update the vec of entity_components accordingly
// this allows for example blender collection to provide basic ecs data & the instances to override/ define their own values
if entity_components.contains_key(&target_entity) {
let mut updated_components: Vec<(Box<dyn Reflect>, TypeRegistration)> = Vec::new();
let current_components = &entity_components[&target_entity];
// first inject the current components
for (component, type_registration) in current_components {
updated_components.push((component.clone_value(), type_registration.clone()));
}
// then inject the new components: this also enables overwrite components set in the collection
for (component, type_registration) in reflect_components {
updated_components.push((component.clone_value(), type_registration));
}
return (target_entity, updated_components);
//entity_components.insert(target_entity, updated_components);
} else {
return (target_entity, reflect_components);
// entity_components.insert(target_entity, reflect_components);
}
}
/// main function: injects components into each entity in gltf files that have `gltf_extras`, using reflection
@ -72,11 +78,11 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
let (target_entity, updated_components) = find_entity_components(entity, name, parent, reflect_components, &entity_components);
let (target_entity, updated_components) =
find_entity_components(entity, name, parent, reflect_components, &entity_components);
entity_components.insert(target_entity, updated_components);
}
for (entity, name, extra, parent) in scene_extras.iter(world) {
debug!(
"Name: {}, entity {:?}, parent: {:?}, scene_extras {:?}",
@ -87,7 +93,8 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
let (target_entity, updated_components) = find_entity_components(entity, name, parent, reflect_components, &entity_components);
let (target_entity, updated_components) =
find_entity_components(entity, name, parent, reflect_components, &entity_components);
entity_components.insert(target_entity, updated_components);
}
@ -101,7 +108,8 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
let (target_entity, updated_components) = find_entity_components(entity, name, parent, reflect_components, &entity_components);
let (target_entity, updated_components) =
find_entity_components(entity, name, parent, reflect_components, &entity_components);
entity_components.insert(target_entity, updated_components);
}
@ -115,11 +123,11 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
let (target_entity, updated_components) = find_entity_components(entity, name, parent, reflect_components, &entity_components);
let (target_entity, updated_components) =
find_entity_components(entity, name, parent, reflect_components, &entity_components);
entity_components.insert(target_entity, updated_components);
}
for (entity, components) in entity_components {
let type_registry: &AppTypeRegistry = world.resource();
let type_registry = type_registry.clone();

View File

@ -16,9 +16,7 @@ pub fn ronstring_to_reflect_component(
// println!("ron_string {:?}", ron_string);
for (name, value) in lookup.into_iter() {
let parsed_value: String = match value.clone() {
Value::String(str) => {
str
}
Value::String(str) => str,
_ => ron::to_string(&value).unwrap().to_string(),
};
@ -95,9 +93,7 @@ fn bevy_components_string_to_components(
let lookup: HashMap<String, Value> = ron::from_str(&parsed_value).unwrap();
for (key, value) in lookup.into_iter() {
let parsed_value: String = match value.clone() {
Value::String(str) => {
str
}
Value::String(str) => str,
_ => ron::to_string(&value).unwrap().to_string(),
};

View File

@ -22,13 +22,18 @@ pub fn compute_scene_aabbs(
.aabb_cache
.get(&name.to_string())
.expect("we should have the aabb available");
commands.entity(root_entity).insert(*aabb).insert(BlueprintReadyForFinalizing);
commands
.entity(root_entity)
.insert(*aabb)
.insert(BlueprintReadyForFinalizing);
} else {
let aabb = compute_descendant_aabb(root_entity, &children, &existing_aabbs);
blenvy_config.aabb_cache.insert(name.to_string(), aabb);
info!("generating aabb for {:?}", name);
commands.entity(root_entity).insert(aabb).insert(BlueprintReadyForFinalizing);
commands
.entity(root_entity)
.insert(aabb)
.insert(BlueprintReadyForFinalizing);
}
}
for entity in other_entities.iter() {

View File

@ -7,7 +7,7 @@ use bevy::utils::HashMap;
pub struct BlueprintAnimations {
pub named_animations: HashMap<String, Handle<AnimationClip>>,
pub named_indices: HashMap<String, AnimationNodeIndex>,
pub graph: Handle<AnimationGraph>
pub graph: Handle<AnimationGraph>,
}
#[derive(Component, Debug)]
@ -22,7 +22,7 @@ pub struct BlueprintAnimationPlayerLink(pub Entity);
/// storage for scene level animations for a given entity (hierarchy), essentially a clone of gltf's `named_animations`
pub struct SceneAnimations {
pub named_animations: HashMap<String, Handle<AnimationClip>>,
pub named_indices: HashMap<String, AnimationNodeIndex>
pub named_indices: HashMap<String, AnimationNodeIndex>,
}
#[derive(Component, Debug)]
@ -76,7 +76,7 @@ pub struct AnimationMarkerReached {
/////////////////////
/*
/*
/// triggers events when a given animation marker is reached for INSTANCE animations
pub fn trigger_instance_animation_markers_events(
animation_infos: Query<(
@ -221,4 +221,4 @@ pub fn trigger_blueprint_animation_markers_events(
}
}
}
*/
*/

View File

@ -8,9 +8,9 @@ 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 MyAsset {
pub name: String,
pub path: String
pub path: String,
}
/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints
@ -27,16 +27,14 @@ pub struct BlueprintAssets {
#[serde(default)]
#[reflect(default)]
pub progress: f32,
#[reflect(ignore)]
#[reflect(ignore)]
#[serde(skip)]
pub asset_infos: Vec<AssetLoadTracker>,
}
//(pub Vec<MyAsset>);
////////////////////////
///
///
/// flag component, usually added when a blueprint is loaded
#[derive(Component)]
pub(crate) struct BlueprintAssetsLoaded;

View File

@ -1,35 +1,41 @@
use bevy::prelude::*;
use bevy::asset::{AssetEvent, LoadedUntypedAsset};
use bevy::scene::SceneInstance;
use crate::{BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintInfo, SpawnBlueprint};
use bevy::asset::{AssetEvent, LoadedUntypedAsset};
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 blueprint_assets: Query<(Entity, Option<&Name>, &BlueprintInfo, &mut BlueprintAssetsLoadState, Option<&Children>)>,
mut blueprint_assets: Query<(
Entity,
Option<&Name>,
&BlueprintInfo,
&mut BlueprintAssetsLoadState,
Option<&Children>,
)>,
asset_server: Res<AssetServer>,
mut commands: Commands,
) {
for event in gltf_events.read() {
// LoadedUntypedAsset
match event {
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 blueprint_assets.iter_mut() {
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() {
if asset_server.get_path(*id).is_some() {
if tracker.path == asset_server.get_path(*id).unwrap().to_string() {
println!("HOLY MOLY IT DETECTS !!, now respawn {:?}", entity_name);
if children.is_some() {
for child in children.unwrap().iter(){
for child in children.unwrap().iter() {
commands.entity(*child).despawn_recursive();
}
}
commands.entity(entity)
commands
.entity(entity)
.remove::<BlueprintAssetsLoaded>()
.remove::<SceneInstance>()
.remove::<BlueprintAssetsLoadState>()
@ -40,9 +46,8 @@ pub(crate) fn react_to_asset_changes(
}
}
}
}
_ => {}
}
}
}
}

View File

@ -13,18 +13,16 @@ pub struct MaterialInfo {
#[derive(Component, Default, Debug)]
pub struct MaterialProcessed;
/// system that injects / replaces materials from material library
pub(crate) fn inject_materials(
mut blenvy_config: ResMut<BlenvyConfig>,
material_infos: Query<
(Entity, &MaterialInfo, &Children),
Without<MaterialProcessed>
// (With<BlueprintReadyForPostProcess>)
/*(
Added<BlueprintMaterialAssetsLoaded>,
With<BlueprintMaterialAssetsLoaded>,
),*/
Without<MaterialProcessed>, // (With<BlueprintReadyForPostProcess>)
/*(
Added<BlueprintMaterialAssetsLoaded>,
With<BlueprintMaterialAssetsLoaded>,
),*/
>,
with_materials_and_meshes: Query<
(),
@ -55,10 +53,14 @@ pub(crate) fn inject_materials(
material_found = Some(material);
} else {
let model_handle: Handle<Gltf> = asset_server.load(material_info.path.clone()); // FIXME: kinda weird now
let mat_gltf = assets_gltf
.get(model_handle.id())
.expect(&format!("materials file {} should have been preloaded", material_info.path));
if mat_gltf.named_materials.contains_key(&material_info.name as &str) {
let mat_gltf = assets_gltf.get(model_handle.id()).expect(&format!(
"materials file {} should have been preloaded",
material_info.path
));
if mat_gltf
.named_materials
.contains_key(&material_info.name as &str)
{
let material = mat_gltf
.named_materials
.get(&material_info.name as &str)
@ -86,4 +88,4 @@ pub(crate) fn inject_materials(
}
}
}
}
}

View File

@ -41,13 +41,15 @@ pub struct BluePrintBundle {
impl Default for BluePrintBundle {
fn default() -> Self {
BluePrintBundle {
blueprint: BlueprintInfo{ name: "default".into(), path:"".into()},
blueprint: BlueprintInfo {
name: "default".into(),
path: "".into(),
},
spawn_here: SpawnBlueprint,
}
}
}
#[derive(Debug, Clone)]
/// Plugin for gltf blueprints
pub struct BlueprintsPlugin {
@ -61,7 +63,7 @@ impl Default for BlueprintsPlugin {
fn default() -> Self {
Self {
aabbs: false,
material_library: false
material_library: false,
}
}
}
@ -74,7 +76,6 @@ fn hot_reload(watching_for_changes: Res<WatchingForChanges>) -> bool {
watching_for_changes.0
}
trait BlenvyApp {
fn register_watching_for_changes(&mut self) -> &mut Self;
}
@ -95,14 +96,10 @@ impl BlenvyApp for App {
pub(crate) struct WatchingForChanges(pub(crate) bool);
const ASSET_ERROR: &str = ""; // TODO
impl Plugin for BlueprintsPlugin {
fn build(&self, app: &mut App) {
app
.register_watching_for_changes()
app.register_watching_for_changes()
.add_event::<BlueprintEvent>()
.register_type::<BlueprintInfo>()
.register_type::<MaterialInfo>()
.register_type::<SpawnBlueprint>()
@ -119,10 +116,8 @@ impl Plugin for BlueprintsPlugin {
.register_type::<Vec<MyAsset>>()
.register_type::<Vec<String>>()
.register_type::<BlueprintAssets>()
.register_type::<HashMap<String, Vec<String>>>()
.register_type::<HideUntilReady>()
.configure_sets(
Update,
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
@ -137,13 +132,10 @@ impl Plugin for BlueprintsPlugin {
blueprints_assets_ready,
blueprints_scenes_spawned,
blueprints_cleanup_spawned_scene,
// post process
inject_materials,
compute_scene_aabbs,// .run_if(aabbs_enabled),
compute_scene_aabbs, // .run_if(aabbs_enabled),
blueprints_finalize_instances,
)
.chain()
.in_set(GltfBlueprintsSet::Spawn),
@ -156,7 +148,6 @@ impl Plugin for BlueprintsPlugin {
),
)*/
// hot reload
.add_systems(Update, react_to_asset_changes.run_if(hot_reload))
;
.add_systems(Update, react_to_asset_changes.run_if(hot_reload));
}
}

View File

@ -3,7 +3,10 @@ use std::path::{Path, PathBuf};
use bevy::{gltf::Gltf, prelude::*, scene::SceneInstance, utils::hashbrown::HashMap};
use serde_json::Value;
use crate::{AssetLoadTracker, BlenvyConfig, BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintAssets, BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintAssetsNotLoaded};
use crate::{
AssetLoadTracker, BlenvyConfig, BlueprintAnimationPlayerLink, BlueprintAnimations,
BlueprintAssets, BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintAssetsNotLoaded,
};
/// this is a flag component for our levels/game world
#[derive(Component)]
@ -11,7 +14,7 @@ pub struct GameWorldTag;
/// Main component for the blueprints
/// has both name & path of the blueprint to enable injecting the data from the correct blueprint
/// into the entity that contains this component
/// into the entity that contains this component
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct BlueprintInfo {
@ -25,7 +28,7 @@ pub struct BlueprintInfo {
pub struct SpawnBlueprint;
#[derive(Component, Debug)]
/// flag component added when a Blueprint instance ist Ready : ie :
/// flag component added when a Blueprint instance ist Ready : ie :
/// - its assets have loaded
/// - it has finished spawning
pub struct BlueprintInstanceReady;
@ -54,17 +57,15 @@ pub struct AddToGameWorld;
/// helper component, just to transfer child data
pub(crate) struct OriginalChildren(pub Vec<Entity>);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// You can add this component to a blueprint instance, and the instance will be hidden until it is ready
/// You can add this component to a blueprint instance, and the instance will be hidden until it is ready
/// You usually want to use this for worlds/level spawning , or dynamic spawning at runtime, but not when you are adding blueprint instances to an existing entity
/// as it would first become invisible before re-appearing again
pub struct HideUntilReady;
#[derive(Event, Debug)]
pub enum BlueprintEvent {
/// event fired when a blueprint has finished loading all of its assets & before it attempts spawning
AssetsLoaded {
entity: Entity,
@ -72,30 +73,27 @@ pub enum BlueprintEvent {
blueprint_path: String,
// TODO: add assets list ?
},
///
///
InstanceReady {
entity: Entity,
blueprint_name: String,
blueprint_path: String,
}
},
}
// TODO: move this somewhere else ?
#[derive(Component, Reflect, Debug, Default)]
#[reflect(Component)]
/// component used to mark any entity as Dynamic: aka add this to make sure your entity is going to be saved
pub struct DynamicBlueprintInstance;
// TODO: move these somewhere else ?
#[derive(Component, Reflect, Debug, Default)]
#[reflect(Component)]
/// component gets added when a blueprint starts spawning, removed when spawning is completely done
pub struct BlueprintSpawning;
use gltf::Gltf as RawGltf;
/*
@ -108,25 +106,22 @@ Overview of the Blueprint Spawning process
- Blueprint post process
- generate aabb (need full hierarchy in its final form)
- inject materials from library if needed
- Blueprint Ready
- Blueprint Ready
- bubble information up to parent blueprint instance
- if all sub_blueprints are ready => Parent blueprint Instance is ready
- if all sub_blueprints are ready => Parent blueprint Instance is ready
=> distinguish between blueprint instances inside blueprint instances vs blueprint instances inside blueprints ??
*/
pub(crate) fn blueprints_prepare_spawn(
blueprint_instances_to_spawn : Query<
(
Entity,
&BlueprintInfo,
),(Added<SpawnBlueprint>)
>,
mut commands: Commands,
asset_server: Res<AssetServer>,
blueprint_instances_to_spawn: Query<(Entity, &BlueprintInfo), (Added<SpawnBlueprint>)>,
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
for (entity, blueprint_info) in blueprint_instances_to_spawn.iter() {
info!("BLUEPRINT: to spawn detected: {:?} path:{:?}", blueprint_info.name, blueprint_info.path);
info!(
"BLUEPRINT: to spawn detected: {:?} path:{:?}",
blueprint_info.name, blueprint_info.path
);
//println!("all assets {:?}", all_assets);
//////////////
// we add the asset of the blueprint itself
@ -152,11 +147,12 @@ asset_server: Res<AssetServer>,
for scene in gltf.scenes() {
let scene_extras = scene.extras().clone().unwrap();
let lookup: HashMap<String, Value> = serde_json::from_str(&scene_extras.get()).unwrap();
if lookup.contains_key("BlueprintAssets"){
if lookup.contains_key("BlueprintAssets") {
let assets_raw = &lookup["BlueprintAssets"];
//println!("ASSETS RAW {}", assets_raw);
let all_assets: BlueprintAssets = ron::from_str(&assets_raw.as_str().unwrap()).unwrap();
let all_assets: BlueprintAssets =
ron::from_str(&assets_raw.as_str().unwrap()).unwrap();
// println!("all_assets {:?}", all_assets);
for asset in all_assets.assets.iter() {
@ -179,21 +175,18 @@ asset_server: Res<AssetServer>,
// now insert load tracker
// if there are assets to load
if !asset_infos.is_empty() {
commands
.entity(entity)
.insert((
BlueprintAssetsLoadState {
all_loaded: false,
asset_infos,
..Default::default()
},
BlueprintAssetsNotLoaded
))
;
commands.entity(entity).insert((
BlueprintAssetsLoadState {
all_loaded: false,
asset_infos,
..Default::default()
},
BlueprintAssetsNotLoaded,
));
} else {
commands.entity(entity).insert(BlueprintAssetsLoaded);
}
// add the blueprint spawning marker
// add the blueprint spawning marker
commands.entity(entity).insert(BlueprintSpawning);
}
}
@ -207,7 +200,6 @@ pub(crate) fn blueprints_check_assets_loading(
asset_server: Res<AssetServer>,
mut commands: Commands,
mut blueprint_events: EventWriter<BlueprintEvent>,
) {
for (entity, blueprint_info, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
let mut all_loaded = true;
@ -218,11 +210,9 @@ pub(crate) fn blueprints_check_assets_loading(
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
// FIXME: hack for now
let mut failed = false;// asset_server.load_state(asset_id) == bevy::asset::LoadState::Failed(_error);
let mut failed = false; // asset_server.load_state(asset_id) == bevy::asset::LoadState::Failed(_error);
match asset_server.load_state(asset_id) {
bevy::asset::LoadState::Failed(_) => {
failed = true
},
bevy::asset::LoadState::Failed(_) => failed = true,
_ => {}
}
tracker.loaded = loaded || failed;
@ -239,7 +229,11 @@ pub(crate) fn blueprints_check_assets_loading(
if all_loaded {
assets_to_load.all_loaded = true;
// println!("LOADING: DONE for ALL assets of {:?} (instance of {}), preparing for spawn", entity_name, blueprint_info.path);
blueprint_events.send(BlueprintEvent::AssetsLoaded {entity: entity,blueprint_name: blueprint_info.name.clone(), blueprint_path: blueprint_info.path.clone() });
blueprint_events.send(BlueprintEvent::AssetsLoaded {
entity: entity,
blueprint_name: blueprint_info.name.clone(),
blueprint_path: blueprint_info.path.clone(),
});
commands
.entity(entity)
@ -251,23 +245,23 @@ pub(crate) fn blueprints_check_assets_loading(
}
}
pub(crate) fn blueprints_assets_ready(spawn_placeholders: Query<
(
Entity,
&BlueprintInfo,
Option<&Transform>,
Option<&Parent>,
Option<&AddToGameWorld>,
Option<&Name>,
Option<&HideUntilReady>
),
(
With<BlueprintAssetsLoaded>,
Added<BlueprintAssetsLoaded>,
Without<BlueprintAssetsNotLoaded>,
),
>,
pub(crate) fn blueprints_assets_ready(
spawn_placeholders: Query<
(
Entity,
&BlueprintInfo,
Option<&Transform>,
Option<&Parent>,
Option<&AddToGameWorld>,
Option<&Name>,
Option<&HideUntilReady>,
),
(
With<BlueprintAssetsLoaded>,
Added<BlueprintAssetsLoaded>,
Without<BlueprintAssetsNotLoaded>,
),
>,
all_children: Query<&Children>,
mut game_world: Query<Entity, With<GameWorldTag>>,
assets_gltf: Res<Assets<Gltf>>,
@ -276,8 +270,7 @@ pub(crate) fn blueprints_assets_ready(spawn_placeholders: Query<
mut graphs: ResMut<Assets<AnimationGraph>>,
mut commands: Commands,
)
{
) {
for (
entity,
blueprint_info,
@ -333,8 +326,8 @@ pub(crate) fn blueprints_assets_ready(spawn_placeholders: Query<
// TODO: not a fan of this
// prepare data for animations
let mut graph = AnimationGraph::new();
let mut named_animations:HashMap<String, Handle<AnimationClip>> = HashMap::new() ;
let mut animation_indices:HashMap<String, AnimationNodeIndex> = HashMap::new();
let mut named_animations: HashMap<String, Handle<AnimationClip>> = HashMap::new();
let mut animation_indices: HashMap<String, AnimationNodeIndex> = HashMap::new();
for (key, clip) in gltf.named_animations.iter() {
named_animations.insert(key.to_string(), clip.clone());
@ -350,37 +343,35 @@ pub(crate) fn blueprints_assets_ready(spawn_placeholders: Query<
..Default::default()
},
OriginalChildren(original_children),
BlueprintAnimations {
// these are animations specific to the inside of the blueprint
named_animations: named_animations, //gltf.named_animations.clone(),
named_indices: animation_indices,
graph
graph,
},
));
if original_parent.is_none() {
// only allow hiding until ready when the entity does not have a parent (?)
if hide_until_ready.is_some() {
commands.entity(entity).insert(Visibility::Hidden); // visibility:
commands.entity(entity).insert(Visibility::Hidden); // visibility:
}
// only allow automatically adding a newly spawned blueprint instance to the "world", if the entity does not have a parent
if add_to_world.is_some() {
// only allow automatically adding a newly spawned blueprint instance to the "world", if the entity does not have a parent
if add_to_world.is_some() {
let world = game_world
.get_single_mut()
.expect("there should be a game world present");
commands.entity(world).add_child(entity);
}
}
}
}
}
#[derive(Component, Reflect, Debug, Default)]
#[reflect(Component)]
pub struct SubBlueprintsSpawnTracker{
pub sub_blueprint_instances: HashMap<Entity, bool>
pub struct SubBlueprintsSpawnTracker {
pub sub_blueprint_instances: HashMap<Entity, bool>,
}
#[derive(Component, Reflect, Debug)]
@ -391,14 +382,21 @@ pub struct SubBlueprintSpawnRoot(pub Entity);
#[reflect(Component)]
pub struct BlueprintSceneSpawned;
#[derive(Component, Reflect, Debug)]
#[reflect(Component)]
pub struct BlueprintChildrenReady;
pub(crate) fn blueprints_scenes_spawned(
spawned_blueprint_scene_instances: Query<(Entity, Option<&Name>, Option<&Children>, Option<&SubBlueprintSpawnRoot>), (With<BlueprintSpawning>, Added<SceneInstance>)>,
with_blueprint_infos : Query<(Entity, Option<&Name>), With<BlueprintInfo>>,
spawned_blueprint_scene_instances: Query<
(
Entity,
Option<&Name>,
Option<&Children>,
Option<&SubBlueprintSpawnRoot>,
),
(With<BlueprintSpawning>, Added<SceneInstance>),
>,
with_blueprint_infos: Query<(Entity, Option<&Name>), With<BlueprintInfo>>,
all_children: Query<&Children>,
all_parents: Query<&Parent>,
@ -407,36 +405,48 @@ pub(crate) fn blueprints_scenes_spawned(
mut commands: Commands,
all_names: Query<&Name>
all_names: Query<&Name>,
) {
for (entity, name, children, track_root) in spawned_blueprint_scene_instances.iter(){
info!("Done spawning blueprint scene for entity named {:?} (track root: {:?})", name, track_root);
for (entity, name, children, track_root) in spawned_blueprint_scene_instances.iter() {
info!(
"Done spawning blueprint scene for entity named {:?} (track root: {:?})",
name, track_root
);
let mut sub_blueprint_instances: Vec<Entity> = vec![];
let mut sub_blueprint_instance_names: Vec<Name> = vec![];
let mut tracker_data: HashMap<Entity, bool> = HashMap::new();
if track_root.is_none() {
for parent in all_parents.iter_ancestors(entity) {
if with_blueprint_infos.get(parent).is_ok() {
println!("found a parent with blueprint_info {:?} for {:?}", all_names.get(parent), all_names.get(entity));
commands.entity(entity).insert(SubBlueprintSpawnRoot(parent));// Injecting to know which entity is the root
println!(
"found a parent with blueprint_info {:?} for {:?}",
all_names.get(parent),
all_names.get(entity)
);
commands
.entity(entity)
.insert(SubBlueprintSpawnRoot(parent)); // Injecting to know which entity is the root
break;
}
}
}
if children.is_some() {
for child in all_children.iter_descendants(entity) {
if with_blueprint_infos.get(child).is_ok() {
// println!("Parent blueprint instance of {:?} is {:?}", all_names.get(child), all_names.get(entity));
for parent in all_parents.iter_ancestors(child) {
if with_blueprint_infos.get(parent).is_ok() {
if parent == entity {
//println!("yohoho");
println!("Parent blueprint instance of {:?} is {:?}", all_names.get(child), all_names.get(parent));
println!(
"Parent blueprint instance of {:?} is {:?}",
all_names.get(child),
all_names.get(parent)
);
commands.entity(child).insert(SubBlueprintSpawnRoot(entity));// Injecting to know which entity is the root
commands.entity(child).insert(SubBlueprintSpawnRoot(entity)); // Injecting to know which entity is the root
tracker_data.insert(child, false);
@ -459,25 +469,24 @@ pub(crate) fn blueprints_scenes_spawned(
}
}
}
println!("sub blueprint instances {:?}", sub_blueprint_instance_names);
if tracker_data.keys().len() > 0 {
commands
.entity(entity)
.insert(SubBlueprintsSpawnTracker{sub_blueprint_instances: tracker_data.clone()});
}else {
commands.entity(entity).insert(BlueprintChildrenReady);
commands.entity(entity).insert(SubBlueprintsSpawnTracker {
sub_blueprint_instances: tracker_data.clone(),
});
} else {
commands.entity(entity).insert(BlueprintChildrenReady);
}
}
}
// could be done differently, by notifying each parent of a spawning blueprint that this child is done spawning ?
// perhaps using component hooks or observers (ie , if a ComponentSpawning + Parent)
use crate:: CopyComponents;
use crate::CopyComponents;
use std::any::TypeId;
#[derive(Component, Reflect, Debug)]
#[reflect(Component)]
pub struct BlueprintReadyForPostProcess;
@ -488,16 +497,17 @@ pub struct BlueprintReadyForPostProcess;
/// - it copies the children of the blueprint scene into the original entity
/// - it adds an `AnimationLink` component containing the entity that has the AnimationPlayer so that animations can be controlled from the original entity
pub(crate) fn blueprints_cleanup_spawned_scene(
foo: Query<(
Entity,
&Children,
&OriginalChildren,
Option<&Name>,
Option<&SubBlueprintSpawnRoot>,
&BlueprintAnimations,
Option<&NoInBlueprint>
),
Added<BlueprintChildrenReady>
foo: Query<
(
Entity,
&Children,
&OriginalChildren,
Option<&Name>,
Option<&SubBlueprintSpawnRoot>,
&BlueprintAnimations,
Option<&NoInBlueprint>,
),
Added<BlueprintChildrenReady>,
>,
added_animation_players: Query<(Entity, &Parent), Added<AnimationPlayer>>,
@ -506,10 +516,11 @@ pub(crate) fn blueprints_cleanup_spawned_scene(
mut commands: Commands,
all_names: Query<&Name>
all_names: Query<&Name>,
) {
for (original, children, original_children, name, track_root, animations, no_inblueprint) in foo.iter() {
for (original, children, original_children, name, track_root, animations, no_inblueprint) in
foo.iter()
{
info!("YOOO ready !! removing empty nodes {:?}", name);
if children.len() == 0 {
@ -518,8 +529,8 @@ pub(crate) fn blueprints_cleanup_spawned_scene(
}
// the root node is the first & normally only child inside a scene, it is the one that has all relevant components
let mut blueprint_root_entity = Entity::PLACEHOLDER; //FIXME: and what about childless ones ?? => should not be possible normally
// let diff = HashSet::from_iter(original_children.0).difference(HashSet::from_iter(children));
// we find the first child that was not in the entity before (aka added during the scene spawning)
// let diff = HashSet::from_iter(original_children.0).difference(HashSet::from_iter(children));
// we find the first child that was not in the entity before (aka added during the scene spawning)
for child in children.iter() {
if !original_children.0.contains(child) {
blueprint_root_entity = *child;
@ -551,7 +562,6 @@ pub(crate) fn blueprints_cleanup_spawned_scene(
}
}
if animations.named_animations.keys().len() > 0 {
for (added, parent) in added_animation_players.iter() {
if parent.get() == blueprint_root_entity {
@ -560,27 +570,22 @@ pub(crate) fn blueprints_cleanup_spawned_scene(
// BUT we still want to have some marker/control at the root entity level, we add this
commands
.entity(original)
.insert((
BlueprintAnimationPlayerLink(added),
));
.insert((BlueprintAnimationPlayerLink(added),));
// since v0.14 you need both AnimationTransitions and AnimationGraph components/handle on the same entity as the animationPlayer
let transitions = AnimationTransitions::new();
commands
.entity(added)
.insert((
transitions,
animations.graph.clone()
));
.insert((transitions, animations.graph.clone()));
}
}
}
commands.entity(original)
.insert(BlueprintReadyForPostProcess); // Tag the entity so any systems dealing with post processing can know it is now their "turn"
commands.entity(blueprint_root_entity).despawn_recursive(); // Remove the root entity that comes from the spawned-in scene
commands
.entity(original)
.insert(BlueprintReadyForPostProcess); // Tag the entity so any systems dealing with post processing can know it is now their "turn"
commands.entity(blueprint_root_entity).despawn_recursive(); // Remove the root entity that comes from the spawned-in scene
// now check if the current entity is a child blueprint instance of another entity
// this should always be done last, as children should be finished before the parent can be processed correctly
@ -588,8 +593,13 @@ 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) {
tracker.sub_blueprint_instances.entry(original).or_insert(true);
if let Ok((s_entity, mut tracker, bp_info)) =
sub_blueprint_trackers.get_mut(track_root.0)
{
tracker
.sub_blueprint_instances
.entry(original)
.or_insert(true);
tracker.sub_blueprint_instances.insert(original, true);
// TODO: ugh, my limited rust knowledge, this is bad code
@ -603,41 +613,49 @@ pub(crate) fn blueprints_cleanup_spawned_scene(
if all_spawned {
// println!("ALLLLL SPAAAAWNED for {} named {:?}", track_root.0, root_name);
commands.entity(track_root.0).insert(BlueprintChildrenReady);
}
}
}
}
}
}
}
#[derive(Component, Reflect, Debug)]
#[reflect(Component)]
pub struct BlueprintReadyForFinalizing;
pub(crate) fn blueprints_finalize_instances(
blueprint_instances: Query<(Entity, Option<&Name>, &BlueprintInfo, Option<&HideUntilReady>), (With<BlueprintSpawning>, With<BlueprintReadyForFinalizing>)>,
blueprint_instances: Query<
(
Entity,
Option<&Name>,
&BlueprintInfo,
Option<&HideUntilReady>,
),
(With<BlueprintSpawning>, With<BlueprintReadyForFinalizing>),
>,
mut blueprint_events: EventWriter<BlueprintEvent>,
mut commands: Commands,
) {
for (entity, name, blueprint_info, hide_until_ready) in blueprint_instances.iter() {
info!("Finalizing blueprint instance {:?}", name);
commands.entity(entity)
commands
.entity(entity)
.remove::<SpawnBlueprint>()
.remove::<BlueprintSpawning>()
.remove::<BlueprintReadyForPostProcess>()
// .remove::<Handle<Scene>>(); // FIXME: if we delete the handle to the scene, things get despawned ! not what we want
//.remove::<Handle<Scene>>(); // FIXME: if we delete the handle to the scene, things get despawned ! not what we want
//.remove::<BlueprintAssetsLoadState>(); // also clear the sub assets tracker to free up handles, perhaps just freeing up the handles and leave the rest would be better ?
//.remove::<BlueprintAssetsLoaded>();
.insert(BlueprintInstanceReady)
;
.insert(BlueprintInstanceReady);
if hide_until_ready.is_some() {
println!("REVEAAAL");
commands.entity(entity).insert(Visibility::Visible);
}
blueprint_events.send(BlueprintEvent::InstanceReady {entity: entity, blueprint_name: blueprint_info.name.clone(), blueprint_path: blueprint_info.path.clone()});
blueprint_events.send(BlueprintEvent::InstanceReady {
entity: entity,
blueprint_name: blueprint_info.name.clone(),
blueprint_path: blueprint_info.path.clone(),
});
}
}

View File

@ -11,10 +11,15 @@ pub(crate) fn plugin(app: &mut App) {
.register_type::<BlenderLightShadows>()
.register_type::<BlenderToneMapping>()
.register_type::<BlenderColorGrading>()
.add_systems(
Update,
(process_lights, process_shadowmap, process_background_shader, process_tonemapping, process_colorgrading)
(
process_lights,
process_shadowmap,
process_background_shader,
process_tonemapping,
process_colorgrading,
)
.after(GltfComponentsSet::Injection),
);
}
@ -45,26 +50,25 @@ pub struct BlenderShadowSettings {
pub cascade_size: usize,
}
/// Not all possible Blender ToneMappings are available in Bevy & vice versa
/// Not all possible Blender ToneMappings are available in Bevy & vice versa
#[derive(Component, Reflect, Default, Debug, PartialEq, Clone)]
#[reflect(Component)]
#[non_exhaustive]
pub enum BlenderToneMapping {
pub enum BlenderToneMapping {
#[default]
None,
AgX,
Filmic
Filmic,
}
#[derive(Component, Reflect, Default, Debug, PartialEq, Clone)]
#[reflect(Component)]
#[non_exhaustive]
pub struct BlenderColorGrading {
pub struct BlenderColorGrading {
exposure: f32,
gamma: f32,
}
fn process_lights(
mut directional_lights: Query<
(&mut DirectionalLight, Option<&BlenderLightShadows>),
@ -76,12 +80,12 @@ fn process_lights(
for (mut light, blender_light_shadows) in directional_lights.iter_mut() {
if let Some(blender_light_shadows) = blender_light_shadows {
light.shadows_enabled = blender_light_shadows.enabled;
}
}
}
for (mut light, blender_light_shadows) in spot_lights.iter_mut() {
if let Some(blender_light_shadows) = blender_light_shadows {
light.shadows_enabled = blender_light_shadows.enabled;
}
}
}
for (mut light, blender_light_shadows) in point_lights.iter_mut() {
@ -113,19 +117,17 @@ fn process_background_shader(
brightness: background_shader.strength * 400.0,
});
commands.insert_resource(ClearColor(background_shader.color));
}
}
// FIXME: this logic should not depend on if toneMapping or Cameras where added first
fn process_tonemapping(
tonemappings: Query<(Entity, &BlenderToneMapping) , Added<BlenderToneMapping>>,
tonemappings: Query<(Entity, &BlenderToneMapping), Added<BlenderToneMapping>>,
cameras: Query<Entity, With<Camera>>,
mut commands: Commands,
){
for entity in cameras.iter(){
for (scene_id, tone_mapping) in tonemappings.iter(){
) {
for entity in cameras.iter() {
for (scene_id, tone_mapping) in tonemappings.iter() {
match tone_mapping {
BlenderToneMapping::None => {
//println!("TONEMAPPING NONE");
@ -143,42 +145,37 @@ fn process_tonemapping(
commands.entity(scene_id).remove::<BlenderToneMapping>();
}
}
}
// FIXME: this logic should not depend on if toneMapping or Cameras where added first
fn process_colorgrading(
blender_colorgradings: Query<(Entity, &BlenderColorGrading) , Added<BlenderColorGrading>>,
blender_colorgradings: Query<(Entity, &BlenderColorGrading), Added<BlenderColorGrading>>,
cameras: Query<Entity, With<Camera>>,
mut commands: Commands,
){
for entity in cameras.iter(){
for (scene_id, blender_colorgrading) in blender_colorgradings.iter(){
commands.entity(entity).insert(
ColorGrading{
global: ColorGradingGlobal{
exposure: blender_colorgrading.exposure,
..Default::default()
},
shadows: ColorGradingSection{
gamma: blender_colorgrading.gamma,
..Default::default()
},
midtones: ColorGradingSection{
gamma: blender_colorgrading.gamma,
..Default::default()
},
highlights: ColorGradingSection{
gamma: blender_colorgrading.gamma,
..Default::default()
},
) {
for entity in cameras.iter() {
for (scene_id, blender_colorgrading) in blender_colorgradings.iter() {
commands.entity(entity).insert(ColorGrading {
global: ColorGradingGlobal {
exposure: blender_colorgrading.exposure,
..Default::default()
}
);
commands.entity(scene_id).remove::<ColorGrading>();
},
shadows: ColorGradingSection {
gamma: blender_colorgrading.gamma,
..Default::default()
},
midtones: ColorGradingSection {
gamma: blender_colorgrading.gamma,
..Default::default()
},
highlights: ColorGradingSection {
gamma: blender_colorgrading.gamma,
..Default::default()
},
..Default::default()
});
commands.entity(scene_id).remove::<ColorGrading>();
}
}
}
}

View File

@ -16,36 +16,43 @@ use bevy::{
use crate::{ronstring_to_reflect_component, GltfProcessed};
// , mut entity_components: HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>>
fn find_entity_components(entity: Entity, name: &Name, parent: Option<&Parent>, reflect_components: Vec<(Box<dyn Reflect>, TypeRegistration)>, entity_components: &HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>>) -> (Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>){
// we assign the components specified /xxx_components objects to their parent node
let mut target_entity = entity;
// if the node contains "components" or ends with "_pa" (ie add to parent), the components will not be added to the entity itself but to its parent
// this is mostly used for Blender collections
if parent.is_some() && (name.as_str().contains("components") || name.as_str().ends_with("_pa")) {
debug!("adding components to parent");
target_entity = parent.expect("the target entity had a parent ").get();
}
debug!("adding to {:?}", target_entity);
fn find_entity_components(
entity: Entity,
name: &Name,
parent: Option<&Parent>,
reflect_components: Vec<(Box<dyn Reflect>, TypeRegistration)>,
entity_components: &HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>>,
) -> (Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>) {
// we assign the components specified /xxx_components objects to their parent node
let mut target_entity = entity;
// if the node contains "components" or ends with "_pa" (ie add to parent), the components will not be added to the entity itself but to its parent
// this is mostly used for Blender collections
if parent.is_some() && (name.as_str().contains("components") || name.as_str().ends_with("_pa"))
{
debug!("adding components to parent");
target_entity = parent.expect("the target entity had a parent ").get();
}
debug!("adding to {:?}", target_entity);
// if there where already components set to be added to this entity (for example when entity_data was refering to a parent), update the vec of entity_components accordingly
// this allows for example blender collection to provide basic ecs data & the instances to override/ define their own values
if entity_components.contains_key(&target_entity) {
let mut updated_components: Vec<(Box<dyn Reflect>, TypeRegistration)> = Vec::new();
let current_components = &entity_components[&target_entity];
// first inject the current components
for (component, type_registration) in current_components {
updated_components.push((component.clone_value(), type_registration.clone()));
}
// then inject the new components: this also enables overwrite components set in the collection
for (component, type_registration) in reflect_components {
updated_components.push((component.clone_value(), type_registration));
}
return (target_entity, updated_components)
//entity_components.insert(target_entity, updated_components);
} else {
return (target_entity, reflect_components);
// entity_components.insert(target_entity, reflect_components);
}
// if there where already components set to be added to this entity (for example when entity_data was refering to a parent), update the vec of entity_components accordingly
// this allows for example blender collection to provide basic ecs data & the instances to override/ define their own values
if entity_components.contains_key(&target_entity) {
let mut updated_components: Vec<(Box<dyn Reflect>, TypeRegistration)> = Vec::new();
let current_components = &entity_components[&target_entity];
// first inject the current components
for (component, type_registration) in current_components {
updated_components.push((component.clone_value(), type_registration.clone()));
}
// then inject the new components: this also enables overwrite components set in the collection
for (component, type_registration) in reflect_components {
updated_components.push((component.clone_value(), type_registration));
}
return (target_entity, updated_components);
//entity_components.insert(target_entity, updated_components);
} else {
return (target_entity, reflect_components);
// entity_components.insert(target_entity, reflect_components);
}
}
/// main function: injects components into each entity in gltf files that have `gltf_extras`, using reflection
@ -70,11 +77,11 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
let (target_entity, updated_components) = find_entity_components(entity, name, parent, reflect_components, &entity_components);
let (target_entity, updated_components) =
find_entity_components(entity, name, parent, reflect_components, &entity_components);
entity_components.insert(target_entity, updated_components);
}
for (entity, name, extra, parent) in scene_extras.iter(world) {
debug!(
"Name: {}, entity {:?}, parent: {:?}, scene_extras {:?}",
@ -85,7 +92,8 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
let (target_entity, updated_components) = find_entity_components(entity, name, parent, reflect_components, &entity_components);
let (target_entity, updated_components) =
find_entity_components(entity, name, parent, reflect_components, &entity_components);
entity_components.insert(target_entity, updated_components);
}
@ -99,7 +107,8 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
let (target_entity, updated_components) = find_entity_components(entity, name, parent, reflect_components, &entity_components);
let (target_entity, updated_components) =
find_entity_components(entity, name, parent, reflect_components, &entity_components);
entity_components.insert(target_entity, updated_components);
}
@ -113,11 +122,11 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
let (target_entity, updated_components) = find_entity_components(entity, name, parent, reflect_components, &entity_components);
let (target_entity, updated_components) =
find_entity_components(entity, name, parent, reflect_components, &entity_components);
entity_components.insert(target_entity, updated_components);
}
for (entity, components) in entity_components {
let type_registry: &AppTypeRegistry = world.resource();
let type_registry = type_registry.clone();

View File

@ -16,9 +16,7 @@ pub fn ronstring_to_reflect_component(
// println!("ron_string {:?}", ron_string);
for (name, value) in lookup.into_iter() {
let parsed_value: String = match value.clone() {
Value::String(str) => {
str
}
Value::String(str) => str,
_ => ron::to_string(&value).unwrap().to_string(),
};
@ -58,7 +56,7 @@ fn components_string_to_components(
parsed_value
);
/*
/*
// usefull to determine what an entity looks like Serialized
let test_struct = Color::Srgba(Srgba { red: 0.2, green: 0.2, blue: 0.2, alpha: 0.2 });
//CameraRenderGraph::new("name");
@ -68,7 +66,6 @@ fn components_string_to_components(
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");
@ -99,9 +96,7 @@ fn bevy_components_string_to_components(
let lookup: HashMap<String, Value> = ron::from_str(&parsed_value).unwrap();
for (key, value) in lookup.into_iter() {
let parsed_value: String = match value.clone() {
Value::String(str) => {
str
}
Value::String(str) => str,
_ => ron::to_string(&value).unwrap().to_string(),
};

View File

@ -1,5 +1,5 @@
use std::path::PathBuf;
use bevy::{prelude::*, render::primitives::Aabb, utils::HashMap};
use std::path::PathBuf;
pub mod components;
pub use components::*;
@ -24,7 +24,6 @@ pub struct BlenvyConfig {
pub(crate) materials_cache: HashMap<String, Handle<StandardMaterial>>, // cache for materials
}
#[derive(Debug, Clone)]
/// Plugin for gltf blueprints
pub struct BlenvyPlugin {
@ -51,9 +50,9 @@ impl Default for BlenvyPlugin {
impl Plugin for BlenvyPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
ComponentsFromGltfPlugin::default(),
ComponentsFromGltfPlugin::default(),
ExportRegistryPlugin::default(),
BlueprintsPlugin::default()
BlueprintsPlugin::default(),
))
.insert_resource(BlenvyConfig {
registry_save_path: self.registry_save_path.clone(),
@ -64,8 +63,6 @@ impl Plugin for BlenvyPlugin {
aabb_cache: HashMap::new(),
materials_cache: HashMap::new(),
})
;
});
}
}
}

View File

@ -1,7 +1,11 @@
use std::{fs::File, path::Path};
use bevy::{log::info, prelude::{AppTypeRegistry, ReflectComponent, ReflectResource, World}, reflect::{TypeInfo, TypeRegistration, VariantInfo}};
use serde_json::{json, Map, Value};
use crate::{AssetRoot, BlenvyConfig};
use bevy::{
log::info,
prelude::{AppTypeRegistry, ReflectComponent, ReflectResource, World},
reflect::{TypeInfo, TypeRegistration, VariantInfo},
};
use serde_json::{json, Map, Value};
use std::{fs::File, path::Path};
pub fn export_types(world: &mut World) {
let config = world

View File

@ -4,7 +4,10 @@ pub mod export_types;
pub use export_types::*;
use bevy::{
app::Startup, asset::AssetPlugin, prelude::{App, Plugin, Resource}, scene::SceneFilter
app::Startup,
asset::AssetPlugin,
prelude::{App, Plugin, Resource},
scene::SceneFilter,
};
pub struct ExportRegistryPlugin {
@ -25,8 +28,7 @@ impl Default for ExportRegistryPlugin {
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);
}
}

View File

@ -21,22 +21,20 @@ impl Plugin for CorePlugin {
// and any other commponent you want to include/exclude
])),
..Default::default()
}
/* ExportRegistryPlugin {
component_filter: SceneFilter::Denylist(HashSet::from([
// this is using Bevy's build in SceneFilter, you can compose what components you want to allow/deny
TypeId::of::<ComponentAToFilterOut>(),
TypeId::of::<ComponentBToFilterOut>(),
// and any other commponent you want to include/exclude
])),
..Default::default()
},
BlueprintsPlugin {
material_library: true,
aabbs: true,
..Default::default()
}, */
}, /* ExportRegistryPlugin {
component_filter: SceneFilter::Denylist(HashSet::from([
// this is using Bevy's build in SceneFilter, you can compose what components you want to allow/deny
TypeId::of::<ComponentAToFilterOut>(),
TypeId::of::<ComponentBToFilterOut>(),
// and any other commponent you want to include/exclude
])),
..Default::default()
},
BlueprintsPlugin {
material_library: true,
aabbs: true,
..Default::default()
}, */
);
}
}

View File

@ -39,7 +39,7 @@ pub fn setup_main_scene_animations(asset_server: Res<AssetServer>, mut commands:
commands.insert_resource(AnimTest(asset_server.load("levels/World.glb")));
}
/*
/*
#[allow(clippy::type_complexity)]
pub fn animations(
added_animation_players: Query<(Entity, &Name, &AnimationPlayer)>,
@ -102,8 +102,7 @@ pub fn play_animations(
),
(With<AnimationInfos>, With<Marker3>),
>, */
mut animation_players: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
mut animation_players: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
keycode: Res<ButtonInput<KeyCode>>,
) {
if keycode.just_pressed(KeyCode::KeyP) {
@ -111,19 +110,20 @@ pub fn play_animations(
for (link, animations) in animated_fox.iter() {
println!("animations {:?}", animations.named_animations);
println!("LINK target {}", link.0);
let (mut animation_player, mut animation_transitions) = animation_players.get_mut(link.0).unwrap();
let (mut animation_player, mut animation_transitions) =
animation_players.get_mut(link.0).unwrap();
let anim_name = "Survey";
let animation_index = animations
.named_indices
.get(anim_name)
.expect("animation name should be in the list")
.clone();
animation_transitions
.play(
&mut animation_player,
animation_index,
Duration::from_secs(5)
&mut animation_player,
animation_index,
Duration::from_secs(5),
)
.repeat();
@ -133,7 +133,6 @@ pub fn play_animations(
let playing_animation = animation_player.animation_mut(playing_animation_index).unwrap();
println!("Playing animation {:?}", playing_animation);
playing_animation.set_repeat(RepeatAnimation::Forever);*/
}
}
@ -245,9 +244,6 @@ pub fn play_animations(
}*/
}
pub fn react_to_animation_markers(
mut animation_marker_events: EventReader<AnimationMarkerReached>,
) {

View File

@ -1,6 +1,9 @@
use bevy::prelude::*;
use blenvy::{AddToGameWorld, BluePrintBundle, BlueprintInfo, DynamicBlueprintInstance, GameWorldTag, HideUntilReady, SpawnBlueprint};
use crate::{GameState, InAppRunning};
use bevy::prelude::*;
use blenvy::{
AddToGameWorld, BluePrintBundle, BlueprintInfo, DynamicBlueprintInstance, GameWorldTag,
HideUntilReady, SpawnBlueprint,
};
//use bevy_rapier3d::prelude::Velocity;
use rand::Rng;
@ -22,7 +25,10 @@ pub fn setup_game(
));*/
commands.spawn((
BlueprintInfo{name: "World".into(), path: "levels/World.glb".into()},
BlueprintInfo {
name: "World".into(),
path: "levels/World.glb".into(),
},
HideUntilReady,
bevy::prelude::Name::from("world"), //FIXME: not really needed ? could be infered from blueprint's name/ path
SpawnBlueprint,
@ -63,7 +69,10 @@ pub fn spawn_test(
let new_entity = commands
.spawn((
BluePrintBundle {
blueprint: BlueprintInfo{name: "Blueprint1".into() , path:"blueprints/Blueprint1.glb".into()}, // FIXME
blueprint: BlueprintInfo {
name: "Blueprint1".into(),
path: "blueprints/Blueprint1.glb".into(),
}, // FIXME
..Default::default()
},
DynamicBlueprintInstance,

View File

@ -7,14 +7,15 @@ pub use animation::*;
use std::{collections::HashMap, fs, time::Duration};
use blenvy::{
BlueprintAssets, BlueprintAnimationPlayerLink, BlueprintEvent, BlueprintInfo, GltfBlueprintsSet, SceneAnimations
BlueprintAnimationPlayerLink, BlueprintAssets, BlueprintEvent, BlueprintInfo,
GltfBlueprintsSet, SceneAnimations,
};
use crate::{AppState, GameState};
use bevy::{
prelude::*, render::view::screenshot::ScreenshotManager, time::common_conditions::on_timer,
window::PrimaryWindow,
};
use crate::{AppState, GameState};
use json_writer::to_json_string;
@ -130,18 +131,32 @@ fn exit_game(mut app_exit_events: ResMut<Events<bevy::app::AppExit>>) {
fn check_for_gltf_events(
mut blueprint_events: EventReader<BlueprintEvent>,
all_names: Query<&Name>,
)
{
) {
for event in blueprint_events.read() {
match event {
BlueprintEvent::InstanceReady{entity, blueprint_name, blueprint_path} => {
info!("BLUEPRINT EVENT: {:?} for {:?}", event, all_names.get(*entity));
},
BlueprintEvent::AssetsLoaded { entity, blueprint_name, blueprint_path }=> {
info!("BLUEPRINT EVENT: {:?} for {:?}", event, all_names.get(*entity));
},
_=> {
match event {
BlueprintEvent::InstanceReady {
entity,
blueprint_name,
blueprint_path,
} => {
info!(
"BLUEPRINT EVENT: {:?} for {:?}",
event,
all_names.get(*entity)
);
}
BlueprintEvent::AssetsLoaded {
entity,
blueprint_name,
blueprint_path,
} => {
info!(
"BLUEPRINT EVENT: {:?} for {:?}",
event,
all_names.get(*entity)
);
}
_ => {
info!("BLUEPRINT EVENT: {:?}", event);
}
}

View File

@ -1,4 +1,7 @@
use bevy::{gltf::{GltfMaterialExtras, GltfMeshExtras, GltfSceneExtras}, prelude::*};
use bevy::{
gltf::{GltfMaterialExtras, GltfMeshExtras, GltfSceneExtras},
prelude::*,
};
use blenvy::{BlueprintAssets, BlueprintInstanceReady};
use crate::{BasicTest, EnumComplex, RedirectPropHitImpulse};
@ -6,13 +9,19 @@ use crate::{BasicTest, EnumComplex, RedirectPropHitImpulse};
#[derive(Component)]
pub struct HiearchyDebugTag;
pub fn setup_hierarchy_debug(mut commands: Commands, asset_server: Res<AssetServer>){
// a place to display the extras on screen
commands.spawn((
pub fn setup_hierarchy_debug(mut commands: Commands, asset_server: Res<AssetServer>) {
// a place to display the extras on screen
commands.spawn((
TextBundle::from_section(
"",
TextStyle {
color: LinearRgba { red: 1.0, green:1.0, blue: 1.0, alpha: 1.0}.into(),
color: LinearRgba {
red: 1.0,
green: 1.0,
blue: 1.0,
alpha: 1.0,
}
.into(),
font_size: 15.,
..default()
},
@ -27,38 +36,45 @@ pub fn setup_hierarchy_debug(mut commands: Commands, asset_server: Res<AssetServ
));
}
pub fn get_descendants(
all_children: &Query<&Children>,
all_names:&Query<&Name>,
root: &Entity,
all_children: &Query<&Children>,
all_names: &Query<&Name>,
root: &Entity,
all_transforms: &Query<&Transform>,
all_global_transforms: &Query<&GlobalTransform>,
nesting: usize,
to_check: &Query<&BasicTest>//&Query<(&BlueprintInstanceReady, &BlueprintAssets)>,
)
-> String
{
nesting: usize,
to_check: &Query<&BasicTest>, //&Query<(&BlueprintInstanceReady, &BlueprintAssets)>,
) -> String {
let mut hierarchy_display: Vec<String> = vec![];
let root_name = all_names.get(*root);
let name;
if root_name.is_ok() {
name = root_name.unwrap().to_string();
}else {
} else {
name = "no_name".to_string()
}
let components_to_check = to_check.get(*root);
hierarchy_display.push( format!("{}{} ({:?}) ({:?})", " ".repeat(nesting), name, all_transforms.get(*root), all_global_transforms.get(*root)) ); //components_to_check ({:?})
hierarchy_display.push(format!(
"{}{} ({:?}) ({:?})",
" ".repeat(nesting),
name,
all_transforms.get(*root),
all_global_transforms.get(*root)
)); //components_to_check ({:?})
if let Ok(children) = all_children.get(*root) {
for child in children.iter() {
let child_descendants_display = get_descendants(&all_children, &all_names, &child, &all_transforms, &all_global_transforms, nesting + 4, &to_check);
let child_descendants_display = get_descendants(
&all_children,
&all_names,
&child,
&all_transforms,
&all_global_transforms,
nesting + 4,
&to_check,
);
hierarchy_display.push(child_descendants_display);
}
}
@ -68,94 +84,99 @@ pub fn get_descendants(
pub fn draw_hierarchy_debug(
root: Query<(Entity, Option<&Name>, &Children), (Without<Parent>)>,
all_children: Query<&Children>,
all_names:Query<&Name>,
all_names: Query<&Name>,
all_transforms: Query<&Transform>,
all_global_transforms: Query<&GlobalTransform>,
to_check: Query<&BasicTest>,//Query<(&BlueprintInstanceReady, &BlueprintAssets)>,
to_check: Query<&BasicTest>, //Query<(&BlueprintInstanceReady, &BlueprintAssets)>,
mut display: Query<&mut Text, With<HiearchyDebugTag>>,
){
) {
let mut hierarchy_display: Vec<String> = vec![];
for (root_entity, name, children) in root.iter() {
// hierarchy_display.push( format!("Hierarchy root{:?}", name) );
hierarchy_display.push(get_descendants(&all_children, &all_names, &root_entity, &all_transforms, &all_global_transforms, 0, &to_check));
hierarchy_display.push(get_descendants(
&all_children,
&all_names,
&root_entity,
&all_transforms,
&all_global_transforms,
0,
&to_check,
));
// let mut children = all_children.get(root_entity);
/*for child in children.iter() {
// hierarchy_display
let name = all_names.get(*child); //.unwrap_or(&Name::new("no name"));
hierarchy_display.push(format!(" {:?}", name))
}*/
//
//
}
let mut display = display.single_mut();
display.sections[0].value = hierarchy_display.join("\n");
}
////////:just some testing for gltf extras
fn check_for_gltf_extras(
gltf_extras_per_entity: Query<(
Entity,
Option<&Name>,
Option<&GltfSceneExtras>,
Option<&GltfExtras>,
Option<&GltfMeshExtras>,
Option<&GltfMaterialExtras>,
)>,
mut display: Query<&mut Text, With<HiearchyDebugTag>>,
gltf_extras_per_entity: Query<(
Entity,
Option<&Name>,
Option<&GltfSceneExtras>,
Option<&GltfExtras>,
Option<&GltfMeshExtras>,
Option<&GltfMaterialExtras>,
)>,
mut display: Query<&mut Text, With<HiearchyDebugTag>>,
) {
let mut gltf_extra_infos_lines: Vec<String> = vec![];
let mut gltf_extra_infos_lines: Vec<String> = vec![];
for (id, name, scene_extras, extras, mesh_extras, material_extras) in
gltf_extras_per_entity.iter()
{
if scene_extras.is_some()
for (id, name, scene_extras, extras, mesh_extras, material_extras) in
gltf_extras_per_entity.iter()
{
if scene_extras.is_some()
//|| extras.is_some()
|| mesh_extras.is_some()
|| material_extras.is_some()
{
let formatted_extras = format!(
"Extras per entity {} ('Name: {}'):
{
let formatted_extras = format!(
"Extras per entity {} ('Name: {}'):
- scene extras: {:?}
- mesh extras: {:?}
- material extras: {:?}
",
id,
name.unwrap_or(&Name::default()),
scene_extras,
//extras,
mesh_extras,
material_extras
);
gltf_extra_infos_lines.push(formatted_extras);
id,
name.unwrap_or(&Name::default()),
scene_extras,
//extras,
mesh_extras,
material_extras
);
gltf_extra_infos_lines.push(formatted_extras);
}
let mut display = display.single_mut();
display.sections[0].value = gltf_extra_infos_lines.join("\n");
}
let mut display = display.single_mut();
display.sections[0].value = gltf_extra_infos_lines.join("\n");
}
}
fn check_for_component(
foo: Query<(Entity, Option<&Name>, &RedirectPropHitImpulse)>,
mut display: Query<&mut Text, With<HiearchyDebugTag>>,
){
) {
let mut info_lines: Vec<String> = vec![];
for (entiity, name , enum_complex) in foo.iter(){
let data = format!(" We have a matching component: {:?} (on {:?})", enum_complex, name);
for (entiity, name, enum_complex) in foo.iter() {
let data = format!(
" We have a matching component: {:?} (on {:?})",
enum_complex, name
);
info_lines.push(data);
println!("yoho component");
}
let mut display = display.single_mut();
display.sections[0].value = info_lines.join("\n");
}
pub struct HiearchyDebugPlugin;
impl Plugin for HiearchyDebugPlugin {
fn build(&self, app: &mut App) {
@ -164,7 +185,6 @@ impl Plugin for HiearchyDebugPlugin {
//.add_systems(Update, check_for_component)
//.add_systems(Update, draw_hierarchy_debug)
//.add_systems(Update, check_for_gltf_extras)
;
}
}

View File

@ -20,7 +20,6 @@ fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(AssetPlugin::default()),
HiearchyDebugPlugin,
// our custom plugins
// CommonPlugin,

View File

@ -52,8 +52,6 @@ pub struct InGameLoading;
pub struct StatePlugin;
impl Plugin for StatePlugin {
fn build(&self, app: &mut App) {
app
.init_state::<AppState>()
.init_state::<GameState>();
app.init_state::<AppState>().init_state::<GameState>();
}
}

View File

@ -214,7 +214,7 @@ pub struct ComponentBToFilterOut;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct ComponentWithFieldsOfIdenticalType{
pub struct ComponentWithFieldsOfIdenticalType {
pub first: f32,
pub second: f32,
pub third: Vec<f32>,
@ -224,9 +224,8 @@ pub struct ComponentWithFieldsOfIdenticalType{
#[reflect(Component)]
pub struct ComponentWithFieldsOfIdenticalType2(f32, f32, f32);
#[derive(Debug, Clone, Copy, PartialEq, Reflect, Component)]
#[reflect(Component, )]
#[reflect(Component)]
pub enum RedirectPropHitImpulse {
Local(Vec3),
}
@ -279,14 +278,11 @@ impl Plugin for ComponentsTestPlugin {
.register_type::<HashmapTestStringColorFlat>()
.register_type::<HashmapTestStringEnum>()
.register_type::<HashmapTestStringStruct>()
.register_type::<ComponentAToFilterOut>()
.register_type::<ComponentBToFilterOut>()
.register_type::<ComponentWithFieldsOfIdenticalType>()
.register_type::<ComponentWithFieldsOfIdenticalType2>()
.register_type::<RedirectPropHitImpulse>()
.add_plugins(MaterialPlugin::<
ExtendedMaterial<StandardMaterial, MyExtension>,
>::default());