diff --git a/crates/blenvy/Cargo.toml b/crates/blenvy/Cargo.toml index c10459e..a4a245d 100644 --- a/crates/blenvy/Cargo.toml +++ b/crates/blenvy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blenvy" -version = "0.1.0-alpha.1" +version = "0.1.0-alpha.2" authors = ["Mark 'kaosat-dev' Moissette"] description = "Allows you to define Bevy components direclty inside gltf files and instanciate the components on the Bevy side." homepage = "https://github.com/kaosat-dev/Blenvy" @@ -14,12 +14,12 @@ license = "MIT OR Apache-2.0" workspace = true [dependencies] -bevy = { version = "0.14", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf", "animation"] } +bevy = { version = "0.15.0-rc.1", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf", "animation"] } serde = "1.0.188" ron = "0.8.1" serde_json = "1.0.108" -bevy_common_assets = {version = "0.11", features = ["ron"]} +bevy_common_assets = {version = "0.12.0-rc.1", features = ["ron"]} [dev-dependencies] -bevy = { version = "0.14", default-features = false, features = ["dynamic_linking"] } \ No newline at end of file +bevy = { version = "0.15.0-rc.1", default-features = false, features = ["dynamic_linking"] } \ No newline at end of file diff --git a/crates/blenvy/src/blueprints/materials.rs b/crates/blenvy/src/blueprints/materials.rs index 3117cfe..6c0da11 100644 --- a/crates/blenvy/src/blueprints/materials.rs +++ b/crates/blenvy/src/blueprints/materials.rs @@ -32,8 +32,8 @@ pub(crate) fn inject_materials( (), ( With, - With>, - With>, + With>, + With, ), >, assets_gltf: Res>, @@ -95,7 +95,7 @@ pub(crate) fn inject_materials( material_info.path.clone() ); - commands.entity(*child).insert(material.clone()); + commands.entity(*child).insert(MeshMaterial3d(material.clone())); } } } diff --git a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs index fdaa411..980fb50 100644 --- a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs +++ b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs @@ -515,7 +515,7 @@ pub(crate) fn blueprints_assets_loaded( commands.entity(entity).insert(( SceneBundle { - scene: scene.clone(), + scene: SceneRoot(scene.clone()), transform: transforms, ..Default::default() }, @@ -709,7 +709,7 @@ pub(crate) fn blueprints_cleanup_spawned_scene( } // copy components into from blueprint instance's blueprint_root_entity to original entity - commands.add(CopyComponents { + commands.queue(CopyComponents { source: blueprint_root_entity, destination: original, exclude: vec![TypeId::of::(), TypeId::of::()], @@ -743,7 +743,7 @@ pub(crate) fn blueprints_cleanup_spawned_scene( let transitions = AnimationTransitions::new(); commands .entity(entity_with_player) - .insert((transitions, animations.graph.clone())); + .insert((transitions, AnimationGraphHandle(animations.graph.clone()))); } } // FIXME VERY convoluted, but it works diff --git a/crates/blenvy/src/components/process_gltfs.rs b/crates/blenvy/src/components/process_gltfs.rs index c7b9edb..9d1d407 100644 --- a/crates/blenvy/src/components/process_gltfs.rs +++ b/crates/blenvy/src/components/process_gltfs.rs @@ -9,7 +9,7 @@ use bevy::{ gltf::{GltfExtras, GltfMaterialExtras, GltfMeshExtras, GltfSceneExtras}, hierarchy::Parent, log::{debug, warn}, - reflect::{Reflect, TypeRegistration}, + reflect::{Reflect, PartialReflect, TypeRegistration}, utils::HashMap, }; @@ -20,9 +20,9 @@ fn find_entity_components( entity: Entity, name: Option<&Name>, parent: Option<&Parent>, - reflect_components: Vec<(Box, TypeRegistration)>, - entity_components: &HashMap, TypeRegistration)>>, -) -> (Entity, Vec<(Box, TypeRegistration)>) { + reflect_components: Vec<(Box, TypeRegistration)>, + entity_components: &HashMap, TypeRegistration)>>, +) -> (Entity, Vec<(Box, 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 @@ -40,10 +40,11 @@ fn find_entity_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, TypeRegistration)> = Vec::new(); + let mut updated_components: Vec<(Box, 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().downcast().unwrap(), type_registration.clone())); updated_components.push((component.clone_value(), type_registration.clone())); } // then inject the new components: this also enables overwrite components set in the collection @@ -62,7 +63,7 @@ pub fn add_components_from_gltf_extras(world: &mut World) { let mut mesh_extras = world.query_filtered::<(Entity, Option<&Name>, &GltfMeshExtras, Option<&Parent>), (Added, Without)>(); let mut material_extras = world.query_filtered::<(Entity, Option<&Name>, &GltfMaterialExtras, Option<&Parent>), (Added, Without)>(); - let mut entity_components: HashMap, TypeRegistration)>> = + let mut entity_components: HashMap, TypeRegistration)>> = HashMap::new(); // let gltf_components_config = world.resource::(); @@ -150,7 +151,7 @@ pub fn add_components_from_gltf_extras(world: &mut World) { entity_mut.insert(GltfProcessed); continue; }; - reflected_component.insert(&mut entity_mut, &*component, &type_registry); + reflected_component.insert(&mut entity_mut, &*component.into_partial_reflect(), &type_registry); entity_mut.insert(GltfProcessed); // } diff --git a/crates/blenvy/src/components/ronstring_to_reflect_component.rs b/crates/blenvy/src/components/ronstring_to_reflect_component.rs index e772d89..92c2e6d 100644 --- a/crates/blenvy/src/components/ronstring_to_reflect_component.rs +++ b/crates/blenvy/src/components/ronstring_to_reflect_component.rs @@ -1,6 +1,6 @@ use bevy::log::{debug, warn}; use bevy::reflect::serde::ReflectDeserializer; -use bevy::reflect::{Reflect, TypeRegistration, TypeRegistry}; +use bevy::reflect::{Reflect, PartialReflect, TypeRegistration, TypeRegistry}; use bevy::utils::HashMap; use ron::Value; use serde::de::DeserializeSeed; @@ -10,9 +10,9 @@ use super::capitalize_first_letter; pub fn ronstring_to_reflect_component( ron_string: &str, type_registry: &TypeRegistry, -) -> Vec<(Box, TypeRegistration)> { +) -> Vec<(Box, TypeRegistration)> { let lookup: HashMap = ron::from_str(ron_string).unwrap(); - let mut components: Vec<(Box, TypeRegistration)> = Vec::new(); + let mut components: Vec<(Box, TypeRegistration)> = Vec::new(); // println!("ron_string {:?}", ron_string); for (name, value) in lookup.into_iter() { let parsed_value: String = match value.clone() { @@ -40,7 +40,7 @@ fn components_string_to_components( value: Value, parsed_value: String, type_registry: &TypeRegistry, - components: &mut Vec<(Box, TypeRegistration)>, + components: &mut Vec<(Box, TypeRegistration)>, ) { let type_string = name.replace("component: ", "").trim().to_string(); let capitalized_type_name = capitalize_first_letter(type_string.as_str()); @@ -97,7 +97,7 @@ fn components_string_to_components( fn bevy_components_string_to_components( parsed_value: String, type_registry: &TypeRegistry, - components: &mut Vec<(Box, TypeRegistration)>, + components: &mut Vec<(Box, TypeRegistration)>, ) { let lookup: HashMap = ron::from_str(&parsed_value).unwrap(); for (key, value) in lookup.into_iter() { diff --git a/crates/blenvy/src/registry/export_types.rs b/crates/blenvy/src/registry/export_types.rs index dd5d784..fc402b7 100644 --- a/crates/blenvy/src/registry/export_types.rs +++ b/crates/blenvy/src/registry/export_types.rs @@ -152,26 +152,26 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) { .collect::>(), "items": false, }), - TypeInfo::List(info) => { - json!({ - "long_name": t.type_path(), - "type": "array", - "typeInfo": "List", - "items": json!({"type": typ(info.item_type_path_table().path())}), - }) - } + TypeInfo::List(info) => json!({ + "long_name": t.type_path(), + "type": "array", + "typeInfo": "List", + "items": json!({ + "type": typ(info.item_ty().path()) + }), + }), TypeInfo::Array(info) => json!({ "long_name": t.type_path(), "type": "array", "typeInfo": "Array", - "items": json!({"type": typ(info.item_type_path_table().path())}), + "items": json!({"type": typ(info.item_ty().path())}), }), TypeInfo::Map(info) => json!({ "long_name": t.type_path(), "type": "object", "typeInfo": "Map", - "valueType": json!({"type": typ(info.value_type_path_table().path())}), - "keyType": json!({"type": typ(info.key_type_path_table().path())}), + "valueType": json!({"type": typ(info.value_ty().path())}), + "keyType": json!({"type": typ(info.key_ty().path())}), }), TypeInfo::Tuple(info) => json!({ "long_name": t.type_path(), @@ -184,7 +184,13 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) { .collect::>(), "items": false, }), - TypeInfo::Value(info) => json!({ + TypeInfo::Set(info) => json!({ + "long_name": t.type_path(), + "type": "set", + "typeInfo": "Set", + "items": json!({"type": typ(info.value_ty().path())}), + }), + TypeInfo::Opaque(info) => json!({ "long_name": t.type_path(), "type": map_json_type(info.type_path()), "typeInfo": "Value", diff --git a/crates/blenvy/src/save_load/loading.rs b/crates/blenvy/src/save_load/loading.rs index 9f9211a..782d99b 100644 --- a/crates/blenvy/src/save_load/loading.rs +++ b/crates/blenvy/src/save_load/loading.rs @@ -84,7 +84,7 @@ pub(crate) fn load_game( let _dynamic_data = commands .spawn(( DynamicSceneBundle { - scene: asset_server.load(load_request.path.clone()), + scene: DynamicSceneRoot(asset_server.load(load_request.path.clone())), ..default() }, bevy::prelude::Name::from("World_dynamic"), diff --git a/crates/blenvy/src/save_load/saving.rs b/crates/blenvy/src/save_load/saving.rs index 826b5a1..d9deea5 100644 --- a/crates/blenvy/src/save_load/saving.rs +++ b/crates/blenvy/src/save_load/saving.rs @@ -138,7 +138,7 @@ pub(crate) fn save_game(world: &mut World) { // for default stuff let scene_builder = DynamicSceneBuilder::from_world(world) - .with_filter(filter.clone()) + .with_component_filter(filter.clone()) .with_resource_filter(filter_resources.clone()); let dyn_scene = scene_builder @@ -149,7 +149,7 @@ pub(crate) fn save_game(world: &mut World) { // for root entities let scene_builder_root = DynamicSceneBuilder::from_world(world) - .with_filter(filter_root.clone()) + .with_component_filter(filter_root.clone()) .with_resource_filter(filter_resources.clone()); let mut __dyn_scene_root = scene_builder_root diff --git a/examples/animation/Cargo.toml b/examples/animation/Cargo.toml index 9ae6458..15d7dae 100644 --- a/examples/animation/Cargo.toml +++ b/examples/animation/Cargo.toml @@ -5,6 +5,6 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -bevy = { version = "0.14", features = ["dynamic_linking"] } +bevy = { version = "0.15.0-rc.1", features = ["dynamic_linking"] } blenvy = { path = "../../crates/blenvy" } rand = "0.8.5" \ No newline at end of file diff --git a/examples/blueprints/Cargo.toml b/examples/blueprints/Cargo.toml index 4e68f38..e167d0c 100644 --- a/examples/blueprints/Cargo.toml +++ b/examples/blueprints/Cargo.toml @@ -5,6 +5,6 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -bevy = { version = "0.14", features = ["dynamic_linking"] } +bevy = { version = "0.15.0-rc.1", features = ["dynamic_linking"] } blenvy = { path = "../../crates/blenvy" } rand = "0.8.5" \ No newline at end of file diff --git a/examples/components/Cargo.toml b/examples/components/Cargo.toml index d4bb71a..d2586fd 100644 --- a/examples/components/Cargo.toml +++ b/examples/components/Cargo.toml @@ -5,5 +5,5 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -bevy = { version = "0.14", features = ["dynamic_linking"] } +bevy = { version = "0.15.0-rc.1", features = ["dynamic_linking"] } blenvy = { path = "../../crates/blenvy" } diff --git a/examples/demo/Cargo.toml b/examples/demo/Cargo.toml index afa31b5..05c2b8e 100644 --- a/examples/demo/Cargo.toml +++ b/examples/demo/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -bevy = { version = "0.14", features = ["dynamic_linking"] } +bevy = { version = "0.15.0-rc.1", features = ["dynamic_linking"] } blenvy = { path = "../../crates/blenvy" } rand = "0.8.5" avian3d = "0.1.2" \ No newline at end of file diff --git a/examples/save_load/Cargo.toml b/examples/save_load/Cargo.toml index e2a8f19..55274bd 100644 --- a/examples/save_load/Cargo.toml +++ b/examples/save_load/Cargo.toml @@ -4,15 +4,19 @@ version = "0.3.0" edition = "2021" license = "MIT OR Apache-2.0" +[features] +default = [] +bevy-inspector = ["bevy-inspector-egui"] + [dependencies] -bevy = { version = "0.14", features = ["dynamic_linking"] } +bevy = { version = "0.15.0-rc.1", features = ["dynamic_linking"] } blenvy = { path = "../../crates/blenvy" } serde_json = "1.0.108" serde = "1.0.193" rand = "0.8.5" -bevy-inspector-egui = { version = "0.25.1"} +bevy-inspector-egui = { version = "0.25.1", optional = true} [dev-dependencies] -bevy-inspector-egui = { version = "0.25.1"} \ No newline at end of file +#bevy-inspector-egui = { version = "0.25.1"} \ No newline at end of file diff --git a/examples/save_load/src/main.rs b/examples/save_load/src/main.rs index b71e6cb..32c17a7 100644 --- a/examples/save_load/src/main.rs +++ b/examples/save_load/src/main.rs @@ -11,6 +11,7 @@ use rand::Rng; // use game::*; mod component_examples; +#[cfg(feature = "bevy-inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; use component_examples::*; @@ -18,6 +19,7 @@ fn main() { App::new() .add_plugins(( DefaultPlugins.set(AssetPlugin::default()), + #[cfg(feature = "bevy-inspector")] WorldInspectorPlugin::new(), BlenvyPlugin { save_component_filter: SceneFilter::Allowlist(HashSet::from([ diff --git a/testing/bevy_example/Cargo.toml b/testing/bevy_example/Cargo.toml index 9614ad8..7be939a 100644 --- a/testing/bevy_example/Cargo.toml +++ b/testing/bevy_example/Cargo.toml @@ -5,11 +5,11 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -bevy = { version = "0.14", features = ["dynamic_linking"] } +bevy = { version = "0.15.0-rc.1", features = ["dynamic_linking"] } blenvy = { path = "../../crates/blenvy" } #bevy_editor_pls = { version = "0.8" } rand = "0.8.5" json-writer ="0.3" [dev-dependencies] -bevy-inspector-egui = { version = "0.25.1"} \ No newline at end of file +#bevy-inspector-egui = { version = "0.25.1"} \ No newline at end of file diff --git a/testing/bevy_example/src/game/mod.rs b/testing/bevy_example/src/game/mod.rs index 23320d3..a4efcba 100644 --- a/testing/bevy_example/src/game/mod.rs +++ b/testing/bevy_example/src/game/mod.rs @@ -13,7 +13,9 @@ use blenvy::{ use crate::{AppState, GameState}; use bevy::{ - prelude::*, render::view::screenshot::ScreenshotManager, time::common_conditions::on_timer, + prelude::*, + time::common_conditions::on_timer, + render::view::screenshot::{save_to_disk, Capturing, Screenshot}, window::PrimaryWindow, }; @@ -116,12 +118,11 @@ fn validate_export( } fn generate_screenshot( - main_window: Query>, - mut screenshot_manager: ResMut, + mut commands: Commands, ) { - screenshot_manager - .save_screenshot_to_disk(main_window.single(), "screenshot.png") - .unwrap(); + commands + .spawn(Screenshot::primary_window()) + .observe(save_to_disk("screenshot.png")); } fn exit_game(mut app_exit_events: ResMut>) { diff --git a/testing/bevy_example/src/hierarchy_debug.rs b/testing/bevy_example/src/hierarchy_debug.rs index 9e83f02..3ebbe14 100644 --- a/testing/bevy_example/src/hierarchy_debug.rs +++ b/testing/bevy_example/src/hierarchy_debug.rs @@ -11,26 +11,26 @@ pub struct HiearchyDebugTag; pub fn setup_hierarchy_debug(mut commands: Commands) { // 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(), - font_size: 15., - ..default() - }, - ) - .with_style(Style { + Node { position_type: PositionType::Absolute, top: Val::Px(12.0), left: Val::Px(12.0), ..default() - }), + }, + Text("".to_string()), + TextFont { + font_size: 15., + ..default() + }, + TextColor(LinearRgba { + red: 1.0, + green: 1.0, + blue: 1.0, + alpha: 1.0, + }.into()), + TextLayout { + ..default() + }, HiearchyDebugTag, )); } @@ -93,7 +93,8 @@ pub fn draw_hierarchy_debug( all_global_transforms: Query<&GlobalTransform>, to_check: Query<&EnumTest>, //Query<(&BlueprintInstanceReady, &BlueprintAssets)>, - mut display: Query<&mut Text, With>, + display: Query>, + mut writer: TextUiWriter, ) { let mut hierarchy_display: Vec = vec![]; @@ -118,8 +119,8 @@ pub fn draw_hierarchy_debug( // } - let mut display = display.single_mut(); - display.sections[0].value = hierarchy_display.join("\n"); + let display = display.single(); + *writer.text(display, 0) = hierarchy_display.join("\n"); } ////////:just some testing for gltf extras @@ -133,7 +134,8 @@ fn __check_for_gltf_extras( Option<&GltfMeshExtras>, Option<&GltfMaterialExtras>, )>, - mut display: Query<&mut Text, With>, + display: Query>, + mut writer: TextUiWriter, ) { let mut gltf_extra_infos_lines: Vec = vec![]; @@ -160,14 +162,15 @@ fn __check_for_gltf_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 display = display.single(); + *writer.text(display, 0) = gltf_extra_infos_lines.join("\n"); } } fn __check_for_component( specific_components: Query<(Entity, Option<&Name>, &RedirectPropHitImpulse)>, - mut display: Query<&mut Text, With>, + display: Query>, + mut writer: TextUiWriter, ) { let mut info_lines: Vec = vec![]; for (__entiity, name, enum_complex) in specific_components.iter() { @@ -178,8 +181,9 @@ fn __check_for_component( info_lines.push(data); println!("yoho component"); } - let mut display = display.single_mut(); - display.sections[0].value = info_lines.join("\n"); + + let display = display.single(); + *writer.text(display, 0) = info_lines.join("\n"); } pub struct HiearchyDebugPlugin;