mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-24 04:40:53 +00:00
feat(Blenvy:Bevy):
* bumped up Bevy version to v0.14 ! * fixed (albeit in a clunky way) issues with sub blueprint detection * improved error message for missing material library * added HideUntilReady component & logic, to hide 'in-spawning' blueprint instances until they are ready * "add-to-world" is now only trigerred for blueprint instances that have no parents (avoid footgun) * minor cleanups & tweaks * added test component with Vec3 to double check for issues * updated test blend file to include the component above + added a light to the test spawnable blueprint to check for "light flashes" (aka indirectly testing "HideUntilReady")
This commit is contained in:
parent
478be88a55
commit
bef709a0ed
@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0"
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.14.0-rc.3", 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"
|
serde = "1.0.188"
|
||||||
ron = "0.8.1"
|
ron = "0.8.1"
|
||||||
serde_json = "1.0.108"
|
serde_json = "1.0.108"
|
||||||
@ -34,4 +34,4 @@ gltf = { version = "1.4.0", default-features = false, features = [
|
|||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bevy = { version = "0.14.0-rc.3", default-features = false, features = ["dynamic_linking"] }
|
bevy = { version = "0.14", default-features = false, features = ["dynamic_linking"] }
|
@ -57,7 +57,7 @@ pub(crate) fn inject_materials(
|
|||||||
let model_handle: Handle<Gltf> = asset_server.load(material_info.path.clone()); // FIXME: kinda weird now
|
let model_handle: Handle<Gltf> = asset_server.load(material_info.path.clone()); // FIXME: kinda weird now
|
||||||
let mat_gltf = assets_gltf
|
let mat_gltf = assets_gltf
|
||||||
.get(model_handle.id())
|
.get(model_handle.id())
|
||||||
.expect("material should have been preloaded");
|
.expect(&format!("materials file {} should have been preloaded", material_info.path));
|
||||||
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
|
let material = mat_gltf
|
||||||
.named_materials
|
.named_materials
|
||||||
|
@ -60,6 +60,12 @@ pub struct AddToGameWorld;
|
|||||||
pub(crate) struct OriginalChildren(pub Vec<Entity>);
|
pub(crate) struct OriginalChildren(pub Vec<Entity>);
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
/// 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)]
|
#[derive(Event, Debug)]
|
||||||
pub enum BlueprintEvent {
|
pub enum BlueprintEvent {
|
||||||
|
|
||||||
@ -261,6 +267,7 @@ pub(crate) fn blueprints_assets_ready(spawn_placeholders: Query<
|
|||||||
Option<&Parent>,
|
Option<&Parent>,
|
||||||
Option<&AddToGameWorld>,
|
Option<&AddToGameWorld>,
|
||||||
Option<&Name>,
|
Option<&Name>,
|
||||||
|
Option<&HideUntilReady>
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
With<BlueprintAssetsLoaded>,
|
With<BlueprintAssetsLoaded>,
|
||||||
@ -283,6 +290,7 @@ pub(crate) fn blueprints_assets_ready(spawn_placeholders: Query<
|
|||||||
original_parent,
|
original_parent,
|
||||||
add_to_world,
|
add_to_world,
|
||||||
name,
|
name,
|
||||||
|
hide_until_ready,
|
||||||
) in spawn_placeholders.iter()
|
) in spawn_placeholders.iter()
|
||||||
{
|
{
|
||||||
/*info!(
|
/*info!(
|
||||||
@ -336,8 +344,6 @@ pub(crate) fn blueprints_assets_ready(spawn_placeholders: Query<
|
|||||||
SceneBundle {
|
SceneBundle {
|
||||||
scene: scene.clone(),
|
scene: scene.clone(),
|
||||||
transform: transforms,
|
transform: transforms,
|
||||||
visibility: Visibility::Hidden,
|
|
||||||
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
OriginalChildren(original_children),
|
OriginalChildren(original_children),
|
||||||
@ -345,15 +351,19 @@ pub(crate) fn blueprints_assets_ready(spawn_placeholders: Query<
|
|||||||
// these are animations specific to the inside of the blueprint
|
// 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(),
|
||||||
},
|
},
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
/* if add_to_world.is_some() {
|
if hide_until_ready.is_some() {
|
||||||
|
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() && original_parent.is_some() {
|
||||||
let world = game_world
|
let world = game_world
|
||||||
.get_single_mut()
|
.get_single_mut()
|
||||||
.expect("there should be a game world present");
|
.expect("there should be a game world present");
|
||||||
commands.entity(world).add_child(entity);
|
commands.entity(world).add_child(entity);
|
||||||
} */
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,8 +392,6 @@ pub struct BlueprintChildrenReady;
|
|||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct BlueprintReadyForPostProcess;
|
pub struct BlueprintReadyForPostProcess;
|
||||||
|
|
||||||
|
|
||||||
// TODO: disregard blueprints that have been spawned WAIT , we already have BlueprintSpawning
|
|
||||||
pub(crate) fn blueprints_scenes_spawned(
|
pub(crate) fn blueprints_scenes_spawned(
|
||||||
spawned_blueprint_scene_instances: Query<(Entity, Option<&Name>, Option<&Children>, Option<&SpawnTrackRoot>), (With<BlueprintSpawning>, Added<SceneInstance>)>,
|
spawned_blueprint_scene_instances: Query<(Entity, Option<&Name>, Option<&Children>, Option<&SpawnTrackRoot>), (With<BlueprintSpawning>, Added<SceneInstance>)>,
|
||||||
with_blueprint_infos : Query<(Entity, Option<&Name>), With<BlueprintInfo>>,
|
with_blueprint_infos : Query<(Entity, Option<&Name>), With<BlueprintInfo>>,
|
||||||
@ -396,7 +404,6 @@ pub(crate) fn blueprints_scenes_spawned(
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
|
||||||
all_names: Query<&Name>
|
all_names: Query<&Name>
|
||||||
|
|
||||||
) {
|
) {
|
||||||
for (entity, name, children, track_root) in spawned_blueprint_scene_instances.iter(){
|
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);
|
info!("Done spawning blueprint scene for entity named {:?} (track root: {:?})", name, track_root);
|
||||||
@ -405,34 +412,59 @@ pub(crate) fn blueprints_scenes_spawned(
|
|||||||
|
|
||||||
let mut tracker_data: HashMap<Entity, bool> = HashMap::new();
|
let mut tracker_data: HashMap<Entity, bool> = HashMap::new();
|
||||||
|
|
||||||
|
if track_root.is_none() {
|
||||||
for parent in all_parents.iter_ancestors(entity) {
|
for parent in all_parents.iter_ancestors(entity) {
|
||||||
if with_blueprint_infos.get(parent).is_ok() {
|
if with_blueprint_infos.get(parent).is_ok() {
|
||||||
|
|
||||||
println!("found a parent with blueprint_info {:?} for {:?}", all_names.get(parent), all_names.get(entity));
|
println!("found a parent with blueprint_info {:?} for {:?}", all_names.get(parent), all_names.get(entity));
|
||||||
|
commands.entity(entity).insert(SpawnTrackRoot(parent));// Injecting to know which entity is the root
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if children.is_some() {
|
if children.is_some() {
|
||||||
for child in all_children.iter_descendants(entity) {
|
for child in all_children.iter_descendants(entity) {
|
||||||
if with_blueprint_infos.get(child).is_ok() {
|
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));
|
||||||
|
|
||||||
|
commands.entity(child).insert(SpawnTrackRoot(entity));// Injecting to know which entity is the root
|
||||||
|
|
||||||
|
tracker_data.insert(child, false);
|
||||||
|
|
||||||
sub_blueprint_instances.push(child);
|
sub_blueprint_instances.push(child);
|
||||||
if let Ok(nname) = all_names.get(child) {
|
if let Ok(nname) = all_names.get(child) {
|
||||||
sub_blueprint_instance_names.push(nname.clone());
|
sub_blueprint_instance_names.push(nname.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
tracker_data.insert(child, false);
|
/*if track_root.is_some() {
|
||||||
|
|
||||||
if track_root.is_some() {
|
|
||||||
let prev_root = track_root.unwrap().0;
|
let prev_root = track_root.unwrap().0;
|
||||||
// if we already had a track root, and it is different from the current entity , change the previous track root's list of children
|
// if we already had a track root, and it is different from the current entity , change the previous track root's list of children
|
||||||
if prev_root != entity {
|
if prev_root != entity {
|
||||||
let mut tracker = sub_blueprint_trackers.get_mut(prev_root).expect("should have a tracker");
|
let mut tracker = sub_blueprint_trackers.get_mut(prev_root).expect("should have a tracker");
|
||||||
tracker.1.sub_blueprint_instances.remove(&child);
|
tracker.1.sub_blueprint_instances.remove(&child);
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commands.entity(child).insert(SpawnTrackRoot(entity));// Injecting to know which entity is the root
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -481,7 +513,7 @@ pub(crate) fn blueprints_transfer_components(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
for (original, children, original_children, name, track_root) in foo.iter() {
|
for (original, children, original_children, name, track_root) in foo.iter() {
|
||||||
println!("YOOO ready !! {:?}", name);
|
info!("YOOO ready !! removing empty nodes {:?}", name);
|
||||||
|
|
||||||
if children.len() == 0 {
|
if children.len() == 0 {
|
||||||
warn!("timing issue ! no children found, please restart your bevy app (bug being investigated)");
|
warn!("timing issue ! no children found, please restart your bevy app (bug being investigated)");
|
||||||
@ -515,7 +547,7 @@ pub(crate) fn blueprints_transfer_components(
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands.entity(original)
|
commands.entity(original)
|
||||||
.insert(BlueprintReadyForPostProcess); // Tag the entity so any systems dealing with post processing can now it is now their "turn"
|
.insert(BlueprintReadyForPostProcess); // Tag the entity so any systems dealing with post processing can know it is now their "turn"
|
||||||
// commands.entity(original).remove::<Handle<Scene>>(); // FIXME: if we delete the handle to the scene, things get despawned ! not what we want
|
// commands.entity(original).remove::<Handle<Scene>>(); // FIXME: if we delete the handle to the scene, things get despawned ! not what we want
|
||||||
//commands.entity(original).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 ?
|
//commands.entity(original).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 ?
|
||||||
//commands.entity(original).remove::<BlueprintAssetsLoaded>();
|
//commands.entity(original).remove::<BlueprintAssetsLoaded>();
|
||||||
@ -524,6 +556,7 @@ pub(crate) fn blueprints_transfer_components(
|
|||||||
|
|
||||||
// now check if the current entity is a child blueprint instance of another entity
|
// 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
|
// this should always be done last, as children should be finished before the parent can be processed correctly
|
||||||
|
// TODO: perhaps use observers for these
|
||||||
if let Some(track_root) = track_root {
|
if let Some(track_root) = track_root {
|
||||||
let root_name = all_names.get(track_root.0);
|
let root_name = all_names.get(track_root.0);
|
||||||
println!("got some root {:?}", root_name);
|
println!("got some root {:?}", root_name);
|
||||||
@ -555,19 +588,23 @@ pub(crate) fn blueprints_transfer_components(
|
|||||||
pub struct BlueprintReadyForFinalizing;
|
pub struct BlueprintReadyForFinalizing;
|
||||||
|
|
||||||
pub(crate) fn blueprints_finalize_instances(
|
pub(crate) fn blueprints_finalize_instances(
|
||||||
blueprint_instances: Query<(Entity, Option<&Name>, &BlueprintInfo), (With<BlueprintSpawning>, With<BlueprintReadyForFinalizing>)>,
|
blueprint_instances: Query<(Entity, Option<&Name>, &BlueprintInfo, Option<&HideUntilReady>), (With<BlueprintSpawning>, With<BlueprintReadyForFinalizing>)>,
|
||||||
mut blueprint_events: EventWriter<BlueprintEvent>,
|
mut blueprint_events: EventWriter<BlueprintEvent>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
for (entity, name, blueprint_info) in blueprint_instances.iter() {
|
for (entity, name, blueprint_info, hide_until_ready) in blueprint_instances.iter() {
|
||||||
info!("Finalizing blueprint instance {:?}", name);
|
info!("Finalizing blueprint instance {:?}", name);
|
||||||
commands.entity(entity)
|
commands.entity(entity)
|
||||||
.remove::<SpawnHere>()
|
.remove::<SpawnHere>()
|
||||||
.remove::<BlueprintSpawning>()
|
.remove::<BlueprintSpawning>()
|
||||||
.remove::<BlueprintReadyForPostProcess>()
|
.remove::<BlueprintReadyForPostProcess>()
|
||||||
.insert(BlueprintInstanceReady)
|
.insert(BlueprintInstanceReady)
|
||||||
.insert(Visibility::Visible)
|
|
||||||
;
|
;
|
||||||
|
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()});
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ edition = "2021"
|
|||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.14.0-rc.3", features = ["dynamic_linking"] }
|
bevy = { version = "0.14", features = ["dynamic_linking"] }
|
||||||
blenvy = { path = "../../crates/blenvy" }
|
blenvy = { path = "../../crates/blenvy" }
|
||||||
# bevy_gltf_blueprints = { path = "../../crates/bevy_gltf_blueprints" }
|
# bevy_gltf_blueprints = { path = "../../crates/bevy_gltf_blueprints" }
|
||||||
# bevy_registry_export = { path = "../../crates/bevy_registry_export" }
|
# bevy_registry_export = { path = "../../crates/bevy_registry_export" }
|
||||||
|
Binary file not shown.
@ -4182,6 +4182,30 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"typeInfo": "Struct"
|
"typeInfo": "Struct"
|
||||||
},
|
},
|
||||||
|
"bevy_example::test_components::RedirectPropHitImpulse": {
|
||||||
|
"isComponent": true,
|
||||||
|
"isResource": false,
|
||||||
|
"long_name": "bevy_example::test_components::RedirectPropHitImpulse",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"items": false,
|
||||||
|
"long_name": "Local",
|
||||||
|
"prefixItems": [
|
||||||
|
{
|
||||||
|
"type": {
|
||||||
|
"$ref": "#/$defs/glam::Vec3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"short_name": "Local",
|
||||||
|
"type": "array",
|
||||||
|
"typeInfo": "Tuple"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"short_name": "RedirectPropHitImpulse",
|
||||||
|
"type": "object",
|
||||||
|
"typeInfo": "Enum"
|
||||||
|
},
|
||||||
"bevy_example::test_components::TupleTest2": {
|
"bevy_example::test_components::TupleTest2": {
|
||||||
"isComponent": true,
|
"isComponent": true,
|
||||||
"isResource": false,
|
"isResource": false,
|
||||||
@ -8145,11 +8169,6 @@
|
|||||||
"$ref": "#/$defs/bevy_render::alpha::AlphaMode"
|
"$ref": "#/$defs/bevy_render::alpha::AlphaMode"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"anisotropy_channel": {
|
|
||||||
"type": {
|
|
||||||
"$ref": "#/$defs/bevy_pbr::pbr_material::UvChannel"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"anisotropy_rotation": {
|
"anisotropy_rotation": {
|
||||||
"type": {
|
"type": {
|
||||||
"$ref": "#/$defs/f32"
|
"$ref": "#/$defs/f32"
|
||||||
@ -8160,11 +8179,6 @@
|
|||||||
"$ref": "#/$defs/f32"
|
"$ref": "#/$defs/f32"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"anisotropy_texture": {
|
|
||||||
"type": {
|
|
||||||
"$ref": "#/$defs/core::option::Option<bevy_asset::handle::Handle<bevy_render::texture::image::Image>>"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"attenuation_color": {
|
"attenuation_color": {
|
||||||
"type": {
|
"type": {
|
||||||
"$ref": "#/$defs/bevy_color::color::Color"
|
"$ref": "#/$defs/bevy_color::color::Color"
|
||||||
@ -8374,7 +8388,6 @@
|
|||||||
"clearcoat_perceptual_roughness",
|
"clearcoat_perceptual_roughness",
|
||||||
"anisotropy_strength",
|
"anisotropy_strength",
|
||||||
"anisotropy_rotation",
|
"anisotropy_rotation",
|
||||||
"anisotropy_channel",
|
|
||||||
"double_sided",
|
"double_sided",
|
||||||
"unlit",
|
"unlit",
|
||||||
"fog_enabled",
|
"fog_enabled",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use blenvy::{BluePrintBundle, BlueprintInfo, DynamicBlueprintInstance, GameWorldTag, SpawnHere};
|
use blenvy::{BluePrintBundle, BlueprintInfo, DynamicBlueprintInstance, GameWorldTag, HideUntilReady, SpawnHere};
|
||||||
use crate::{GameState, InAppRunning};
|
use crate::{GameState, InAppRunning};
|
||||||
|
|
||||||
//use bevy_rapier3d::prelude::Velocity;
|
//use bevy_rapier3d::prelude::Velocity;
|
||||||
@ -23,6 +23,7 @@ pub fn setup_game(
|
|||||||
|
|
||||||
commands.spawn((
|
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
|
bevy::prelude::Name::from("world"), //FIXME: not really needed ? could be infered from blueprint's name/ path
|
||||||
SpawnHere,
|
SpawnHere,
|
||||||
GameWorldTag,
|
GameWorldTag,
|
||||||
@ -67,6 +68,7 @@ pub fn spawn_test(
|
|||||||
},
|
},
|
||||||
DynamicBlueprintInstance,
|
DynamicBlueprintInstance,
|
||||||
bevy::prelude::Name::from(format!("test{}", name_index)),
|
bevy::prelude::Name::from(format!("test{}", name_index)),
|
||||||
|
HideUntilReady,
|
||||||
// SpawnHere,
|
// SpawnHere,
|
||||||
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
||||||
/*Velocity {
|
/*Velocity {
|
||||||
|
@ -129,11 +129,20 @@ fn exit_game(mut app_exit_events: ResMut<Events<bevy::app::AppExit>>) {
|
|||||||
|
|
||||||
fn check_for_gltf_events(
|
fn check_for_gltf_events(
|
||||||
mut blueprint_events: EventReader<BlueprintEvent>,
|
mut blueprint_events: EventReader<BlueprintEvent>,
|
||||||
|
all_names: Query<&Name>,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
for event in blueprint_events.read() {
|
for event in blueprint_events.read() {
|
||||||
|
match event {
|
||||||
|
BlueprintEvent::InstanceReady{entity, blueprint_name, blueprint_path} => {
|
||||||
|
info!("BLUEPRINT EVENT: {:?} for {:?}", event, all_names.get(*entity));
|
||||||
|
|
||||||
|
}
|
||||||
|
_=> {
|
||||||
info!("BLUEPRINT EVENT: {:?}", event);
|
info!("BLUEPRINT EVENT: {:?}", event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GamePlugin;
|
pub struct GamePlugin;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use bevy::{gltf::{GltfMaterialExtras, GltfMeshExtras, GltfSceneExtras}, prelude::*};
|
use bevy::{gltf::{GltfMaterialExtras, GltfMeshExtras, GltfSceneExtras}, prelude::*};
|
||||||
use blenvy::{BlueprintAssets, BlueprintInstanceReady};
|
use blenvy::{BlueprintAssets, BlueprintInstanceReady};
|
||||||
|
|
||||||
use crate::{BasicTest, EnumComplex};
|
use crate::{BasicTest, EnumComplex, RedirectPropHitImpulse};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct HiearchyDebugTag;
|
pub struct HiearchyDebugTag;
|
||||||
@ -12,7 +12,7 @@ pub fn setup_hierarchy_debug(mut commands: Commands, asset_server: Res<AssetServ
|
|||||||
TextBundle::from_section(
|
TextBundle::from_section(
|
||||||
"",
|
"",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
color: LinearRgba { red: 1.0, green:0.0, blue: 0.0, alpha: 1.0}.into(),
|
color: LinearRgba { red: 1.0, green:1.0, blue: 1.0, alpha: 1.0}.into(),
|
||||||
font_size: 15.,
|
font_size: 15.,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
@ -30,7 +30,10 @@ pub fn setup_hierarchy_debug(mut commands: Commands, asset_server: Res<AssetServ
|
|||||||
|
|
||||||
pub fn get_descendants(
|
pub fn get_descendants(
|
||||||
all_children: &Query<&Children>,
|
all_children: &Query<&Children>,
|
||||||
all_names:&Query<&Name>, root: &Entity,
|
all_names:&Query<&Name>,
|
||||||
|
root: &Entity,
|
||||||
|
all_transforms: &Query<&Transform>,
|
||||||
|
all_global_transforms: &Query<&GlobalTransform>,
|
||||||
nesting: usize,
|
nesting: usize,
|
||||||
to_check: &Query<&BasicTest>//&Query<(&BlueprintInstanceReady, &BlueprintAssets)>,
|
to_check: &Query<&BasicTest>//&Query<(&BlueprintInstanceReady, &BlueprintAssets)>,
|
||||||
)
|
)
|
||||||
@ -48,14 +51,14 @@ pub fn get_descendants(
|
|||||||
|
|
||||||
let components_to_check = to_check.get(*root);
|
let components_to_check = to_check.get(*root);
|
||||||
|
|
||||||
hierarchy_display.push( format!("{}{} ({:?})", " ".repeat(nesting), name, 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) {
|
if let Ok(children) = all_children.get(*root) {
|
||||||
|
|
||||||
for child in children.iter() {
|
for child in children.iter() {
|
||||||
|
|
||||||
let child_descendants_display = get_descendants(&all_children, &all_names, &child, 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);
|
hierarchy_display.push(child_descendants_display);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,6 +69,8 @@ pub fn draw_hierarchy_debug(
|
|||||||
root: Query<(Entity, Option<&Name>, &Children), (Without<Parent>)>,
|
root: Query<(Entity, Option<&Name>, &Children), (Without<Parent>)>,
|
||||||
all_children: Query<&Children>,
|
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>>,
|
mut display: Query<&mut Text, With<HiearchyDebugTag>>,
|
||||||
@ -75,7 +80,7 @@ pub fn draw_hierarchy_debug(
|
|||||||
for (root_entity, name, children) in root.iter() {
|
for (root_entity, name, children) in root.iter() {
|
||||||
// hierarchy_display.push( format!("Hierarchy root{:?}", name) );
|
// hierarchy_display.push( format!("Hierarchy root{:?}", name) );
|
||||||
|
|
||||||
hierarchy_display.push(get_descendants(&all_children, &all_names, &root_entity, 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);
|
// let mut children = all_children.get(root_entity);
|
||||||
/*for child in children.iter() {
|
/*for child in children.iter() {
|
||||||
// hierarchy_display
|
// hierarchy_display
|
||||||
@ -134,13 +139,13 @@ for (id, name, scene_extras, extras, mesh_extras, material_extras) in
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_for_component(
|
fn check_for_component(
|
||||||
foo: Query<(Entity, Option<&Name>, &EnumComplex)>,
|
foo: Query<(Entity, Option<&Name>, &RedirectPropHitImpulse)>,
|
||||||
mut display: Query<&mut Text, With<HiearchyDebugTag>>,
|
mut display: Query<&mut Text, With<HiearchyDebugTag>>,
|
||||||
|
|
||||||
){
|
){
|
||||||
let mut info_lines: Vec<String> = vec![];
|
let mut info_lines: Vec<String> = vec![];
|
||||||
for (entiity, name , enum_complex) in foo.iter(){
|
for (entiity, name , enum_complex) in foo.iter(){
|
||||||
let data = format!(" We have a 'EnumComplex' component: {:?} (on {:?})", enum_complex, name);
|
let data = format!(" We have a matching component: {:?} (on {:?})", enum_complex, name);
|
||||||
info_lines.push(data);
|
info_lines.push(data);
|
||||||
println!("yoho component");
|
println!("yoho component");
|
||||||
|
|
||||||
@ -156,8 +161,8 @@ impl Plugin for HiearchyDebugPlugin {
|
|||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app
|
app
|
||||||
.add_systems(Startup, setup_hierarchy_debug)
|
.add_systems(Startup, setup_hierarchy_debug)
|
||||||
// .add_systems(Update, check_for_component)
|
//.add_systems(Update, check_for_component)
|
||||||
.add_systems(Update, draw_hierarchy_debug)
|
//.add_systems(Update, draw_hierarchy_debug)
|
||||||
//.add_systems(Update, check_for_gltf_extras)
|
//.add_systems(Update, check_for_gltf_extras)
|
||||||
|
|
||||||
;
|
;
|
||||||
|
@ -224,6 +224,12 @@ pub struct ComponentWithFieldsOfIdenticalType{
|
|||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct ComponentWithFieldsOfIdenticalType2(f32, f32, f32);
|
pub struct ComponentWithFieldsOfIdenticalType2(f32, f32, f32);
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Reflect, Component)]
|
||||||
|
#[reflect(Component, )]
|
||||||
|
pub enum RedirectPropHitImpulse {
|
||||||
|
Local(Vec3),
|
||||||
|
}
|
||||||
pub struct ComponentsTestPlugin;
|
pub struct ComponentsTestPlugin;
|
||||||
impl Plugin for ComponentsTestPlugin {
|
impl Plugin for ComponentsTestPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
@ -279,6 +285,8 @@ impl Plugin for ComponentsTestPlugin {
|
|||||||
.register_type::<ComponentWithFieldsOfIdenticalType>()
|
.register_type::<ComponentWithFieldsOfIdenticalType>()
|
||||||
.register_type::<ComponentWithFieldsOfIdenticalType2>()
|
.register_type::<ComponentWithFieldsOfIdenticalType2>()
|
||||||
|
|
||||||
|
.register_type::<RedirectPropHitImpulse>()
|
||||||
|
|
||||||
.add_plugins(MaterialPlugin::<
|
.add_plugins(MaterialPlugin::<
|
||||||
ExtendedMaterial<StandardMaterial, MyExtension>,
|
ExtendedMaterial<StandardMaterial, MyExtension>,
|
||||||
>::default());
|
>::default());
|
||||||
|
Loading…
Reference in New Issue
Block a user