From 9138c81c60a611469a1381f91b68ef042a909fbd Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Tue, 30 Apr 2024 11:33:05 +0200 Subject: [PATCH] refactor(): removed remains of legacy mode --- crates/bevy_gltf_blueprints/README.md | 18 ----- crates/bevy_gltf_blueprints/src/lib.rs | 7 +- crates/bevy_gltf_components/README.md | 77 +++++++++++++++++-- crates/bevy_gltf_components/src/lib.rs | 17 +--- .../bevy_gltf_components/src/process_gltfs.rs | 1 - .../src/ronstring_to_reflect_component.rs | 66 ---------------- crates/bevy_registry_export/README.md | 2 - .../basic/src/core/mod.rs | 1 - testing/bevy_example/src/core/mod.rs | 1 - tools/bevy_components/README.md | 8 +- tools/bevy_components/TODO.md | 4 +- tools/gltf_auto_export/README.md | 6 -- tools/gltf_auto_export/todo.md | 6 ++ 13 files changed, 82 insertions(+), 132 deletions(-) diff --git a/crates/bevy_gltf_blueprints/README.md b/crates/bevy_gltf_blueprints/README.md index 4be5ee9..31eeffb 100644 --- a/crates/bevy_gltf_blueprints/README.md +++ b/crates/bevy_gltf_blueprints/README.md @@ -306,24 +306,6 @@ see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/exa Generating optimised blueprints and material libraries can be automated using the latests version of the [Blender plugin](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/tools/gltf_auto_export) -## Legacy mode - -Starting in version 0.7 there is a new parameter ```legacy_mode``` for backwards compatibility - -To disable the legacy mode: (enabled by default) - -```rust no_run -BlueprintsPlugin{legacy_mode: false} -``` - - -You **need** to disable legacy mode if you want to use the [```bevy_components```](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/tools_bevy_blueprints/tools/bevy_components) Blender addon + the [```bevy_registry_export crate```](https://crates.io/crates/bevy_registry_export) ! -As it create custom properties that are writen in real **ron** file format instead of a simplified version (the one in the legacy mode) - - -> Note: the legacy mode support will be dropped in future versions, and the default behaviour will be NO legacy mode - - ## Examples https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic diff --git a/crates/bevy_gltf_blueprints/src/lib.rs b/crates/bevy_gltf_blueprints/src/lib.rs index 7fbe551..5ada1da 100644 --- a/crates/bevy_gltf_blueprints/src/lib.rs +++ b/crates/bevy_gltf_blueprints/src/lib.rs @@ -78,8 +78,6 @@ impl fmt::Display for GltfFormat { #[derive(Debug, Clone)] /// Plugin for gltf blueprints pub struct BlueprintsPlugin { - pub legacy_mode: bool, // flag that gets passed on to bevy_gltf_components - pub format: GltfFormat, /// The base folder where library/blueprints assets are loaded from, relative to the executable. pub library_folder: PathBuf, @@ -93,7 +91,6 @@ pub struct BlueprintsPlugin { impl Default for BlueprintsPlugin { fn default() -> Self { Self { - legacy_mode: true, format: GltfFormat::GLB, library_folder: PathBuf::from("models/library"), aabbs: false, @@ -113,9 +110,7 @@ fn materials_library_enabled(blueprints_config: Res) -> bool { impl Plugin for BlueprintsPlugin { fn build(&self, app: &mut App) { - app.add_plugins(ComponentsFromGltfPlugin { - legacy_mode: self.legacy_mode, - }) + app.add_plugins(ComponentsFromGltfPlugin {}) .register_type::() .register_type::() .register_type::() diff --git a/crates/bevy_gltf_components/README.md b/crates/bevy_gltf_components/README.md index 9ac3657..91f3c2e 100644 --- a/crates/bevy_gltf_components/README.md +++ b/crates/bevy_gltf_components/README.md @@ -78,17 +78,78 @@ Use the default configuration: ComponentsFromGltfPlugin::default() ``` -Or disable the legacy mode: (enabled by default) +As of v0.6 Legacy mode has been removed , you can emulate it using a system that should run BEFORE bevy_gltf_components + +```rust no run + if simplified_types { + if let TypeInfo::TupleStruct(info) = type_registration.type_info() { + // we handle tupple strucs with only one field differently, as Blender's custom properties with custom ui (float, int, bool, etc) always give us a tupple struct + if info.field_len() == 1 { + let field = info + .field_at(0) + .expect("we should always have at least one field here"); + let field_name = field.type_path(); + let mut formated = parsed_value.clone(); + match field_name { + "f32" => { + formated = parsed_value.parse::().unwrap().to_string(); + } + "f64" => { + formated = parsed_value.parse::().unwrap().to_string(); + } + "u8" => { + formated = parsed_value.parse::().unwrap().to_string(); + } + "u16" => { + formated = parsed_value.parse::().unwrap().to_string(); + } + "u32" => { + formated = parsed_value.parse::().unwrap().to_string(); + } + "u64" => { + formated = parsed_value.parse::().unwrap().to_string(); + } + "u128" => { + formated = parsed_value.parse::().unwrap().to_string(); + } + "glam::Vec2" => { + let parsed: Vec = ron::from_str(&parsed_value).unwrap(); + formated = format!("(x:{},y:{})", parsed[0], parsed[1]); + } + "glam::Vec3" => { + let parsed: Vec = ron::from_str(&parsed_value).unwrap(); + formated = + format!("(x:{},y:{},z:{})", parsed[0], parsed[1], parsed[2]); + } + "bevy_render::color::Color" => { + let parsed: Vec = ron::from_str(&parsed_value).unwrap(); + if parsed.len() == 3 { + formated = format!( + "Rgba(red:{},green:{},blue:{}, alpha: 1.0)", + parsed[0], parsed[1], parsed[2] + ); + } + if parsed.len() == 4 { + formated = format!( + "Rgba(red:{},green:{},blue:{}, alpha:{})", + parsed[0], parsed[1], parsed[2], parsed[3] + ); + } + } + _ => {} + } + + parsed_value = format!("({formated})"); + } + } + + if parsed_value.is_empty() { + parsed_value = "()".to_string(); + } + } -```rust no_run -ComponentsFromGltfPlugin{legacy_mode: false} ``` -You **need** to disable legacy mode if you want to use the [```bevy_components```](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/tools/bevy_components) Blender addon + the [```bevy_registry_export crate```](https://crates.io/crates/bevy_registry_export) ! -As it create custom properties that are writen in real **ron** file format -instead of a simplified version (the one in the legacy mode) - -> Note: the legacy mode support will be dropped in future versions, and the default behaviour will be NO legacy mode ## SystemSet diff --git a/crates/bevy_gltf_components/src/lib.rs b/crates/bevy_gltf_components/src/lib.rs index ccba12f..28f72bb 100644 --- a/crates/bevy_gltf_components/src/lib.rs +++ b/crates/bevy_gltf_components/src/lib.rs @@ -66,34 +66,23 @@ pub enum GltfComponentsSet { } #[derive(Clone, Resource)] -pub struct GltfComponentsConfig { - pub(crate) legacy_mode: bool, -} +pub struct GltfComponentsConfig {} pub struct ComponentsFromGltfPlugin { - pub legacy_mode: bool, } impl Default for ComponentsFromGltfPlugin { fn default() -> Self { - Self { legacy_mode: true } + Self { } } } -fn check_for_legacy_mode(gltf_components_config: Res) { - if gltf_components_config.legacy_mode { - warn!("using simplified component definitions is deprecated since 0.3, prefer defining components with real ron values (use the bevy_components tool for Blender for simplicity) "); - } -} impl Plugin for ComponentsFromGltfPlugin { fn build(&self, app: &mut App) { app.add_plugins(blender_settings::plugin) .register_type::() - .insert_resource(GltfComponentsConfig { - legacy_mode: self.legacy_mode, - }) - .add_systems(Startup, check_for_legacy_mode) + .insert_resource(GltfComponentsConfig {}) .add_systems( Update, (add_components_from_gltf_extras).in_set(GltfComponentsSet::Injection), diff --git a/crates/bevy_gltf_components/src/process_gltfs.rs b/crates/bevy_gltf_components/src/process_gltfs.rs index a37f537..bd6f7c3 100644 --- a/crates/bevy_gltf_components/src/process_gltfs.rs +++ b/crates/bevy_gltf_components/src/process_gltfs.rs @@ -36,7 +36,6 @@ pub fn add_components_from_gltf_extras(world: &mut World) { let reflect_components = ronstring_to_reflect_component( &extra.value, &type_registry, - gltf_components_config.legacy_mode, ); // we assign the components specified /xxx_components objects to their parent node diff --git a/crates/bevy_gltf_components/src/ronstring_to_reflect_component.rs b/crates/bevy_gltf_components/src/ronstring_to_reflect_component.rs index dc095f5..1642621 100644 --- a/crates/bevy_gltf_components/src/ronstring_to_reflect_component.rs +++ b/crates/bevy_gltf_components/src/ronstring_to_reflect_component.rs @@ -10,7 +10,6 @@ use super::capitalize_first_letter; pub fn ronstring_to_reflect_component( ron_string: &str, type_registry: &TypeRegistry, - simplified_types: bool, ) -> Vec<(Box, TypeRegistration)> { let lookup: HashMap = ron::from_str(ron_string).unwrap(); let mut components: Vec<(Box, TypeRegistration)> = Vec::new(); @@ -30,72 +29,7 @@ pub fn ronstring_to_reflect_component( type_registry.get_with_short_type_path(capitalized_type_name.as_str()) { debug!("TYPE INFO {:?}", type_registration.type_info()); - if simplified_types { - if let TypeInfo::TupleStruct(info) = type_registration.type_info() { - // we handle tupple strucs with only one field differently, as Blender's custom properties with custom ui (float, int, bool, etc) always give us a tupple struct - if info.field_len() == 1 { - let field = info - .field_at(0) - .expect("we should always have at least one field here"); - let field_name = field.type_path(); - let mut formated = parsed_value.clone(); - match field_name { - "f32" => { - formated = parsed_value.parse::().unwrap().to_string(); - } - "f64" => { - formated = parsed_value.parse::().unwrap().to_string(); - } - "u8" => { - formated = parsed_value.parse::().unwrap().to_string(); - } - "u16" => { - formated = parsed_value.parse::().unwrap().to_string(); - } - "u32" => { - formated = parsed_value.parse::().unwrap().to_string(); - } - "u64" => { - formated = parsed_value.parse::().unwrap().to_string(); - } - "u128" => { - formated = parsed_value.parse::().unwrap().to_string(); - } - "glam::Vec2" => { - let parsed: Vec = ron::from_str(&parsed_value).unwrap(); - formated = format!("(x:{},y:{})", parsed[0], parsed[1]); - } - "glam::Vec3" => { - let parsed: Vec = ron::from_str(&parsed_value).unwrap(); - formated = - format!("(x:{},y:{},z:{})", parsed[0], parsed[1], parsed[2]); - } - "bevy_render::color::Color" => { - let parsed: Vec = ron::from_str(&parsed_value).unwrap(); - if parsed.len() == 3 { - formated = format!( - "Rgba(red:{},green:{},blue:{}, alpha: 1.0)", - parsed[0], parsed[1], parsed[2] - ); - } - if parsed.len() == 4 { - formated = format!( - "Rgba(red:{},green:{},blue:{}, alpha:{})", - parsed[0], parsed[1], parsed[2], parsed[3] - ); - } - } - _ => {} - } - parsed_value = format!("({formated})"); - } - } - - if parsed_value.is_empty() { - parsed_value = "()".to_string(); - } - } let ron_string = format!( "{{ \"{}\":{} }}", type_registration.type_info().type_path(), diff --git a/crates/bevy_registry_export/README.md b/crates/bevy_registry_export/README.md index 20a2a6e..7c45031 100644 --- a/crates/bevy_registry_export/README.md +++ b/crates/bevy_registry_export/README.md @@ -100,8 +100,6 @@ fn main() { All examples are here: -> the examples use ```bevy_gltf_blueprints``` with the **legacy_mode** set to **FALSE** as the new custom properties generated by the Blender add-on require newer/ non legacy logic. - - https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_registry_export/basic diff --git a/examples/bevy_registry_export/basic/src/core/mod.rs b/examples/bevy_registry_export/basic/src/core/mod.rs index 73dccf1..de9b473 100644 --- a/examples/bevy_registry_export/basic/src/core/mod.rs +++ b/examples/bevy_registry_export/basic/src/core/mod.rs @@ -11,7 +11,6 @@ impl Plugin for CorePlugin { ..Default::default() }, BlueprintsPlugin { - legacy_mode: false, library_folder: "models/library".into(), format: GltfFormat::GLB, aabbs: true, diff --git a/testing/bevy_example/src/core/mod.rs b/testing/bevy_example/src/core/mod.rs index 795b1c4..e64a5f8 100644 --- a/testing/bevy_example/src/core/mod.rs +++ b/testing/bevy_example/src/core/mod.rs @@ -8,7 +8,6 @@ impl Plugin for CorePlugin { app.add_plugins(( ExportRegistryPlugin::default(), BlueprintsPlugin { - legacy_mode: false, library_folder: "blueprints".into(), format: GltfFormat::GLB, material_library: true, diff --git a/tools/bevy_components/README.md b/tools/bevy_components/README.md index 623712f..d6f19fa 100644 --- a/tools/bevy_components/README.md +++ b/tools/bevy_components/README.md @@ -276,14 +276,8 @@ given object is located) > IMPORTANT !! use this if you have previously used v0.1 , as v0.2 had a breaking change, that makes it **necessary** to use this **once** to upgrade the UI data -## Additional important information - -- for the components to work correctly with [```bevy_gltf_components```](https://crates.io/crates/bevy_gltf_components) or [```bevy_gltf_blueprints```](https://crates.io/crates/bevy_gltf_blueprints) you will need to set the ```legacy_mode``` for those plugins to **FALSE** -as the component data generated by this add on is a complete, clean **ron** data that is incompatible with the previous (legacy versions). -Please see the documentation of those crates for more information. - -> Note: the legacy mode support will be dropped in future versions, and the default behaviour will be NO legacy mode +> Note: the legacy mode support has been removed since version ## Examples diff --git a/tools/bevy_components/TODO.md b/tools/bevy_components/TODO.md index 0fa7f88..c006fce 100644 --- a/tools/bevy_components/TODO.md +++ b/tools/bevy_components/TODO.md @@ -115,11 +115,11 @@ UI: - [x] check if output "string" in custom properties are correct - gltf_auto_export - - [ ] add support for "enabled" flag + - [x] add support for "enabled" flag - [ ] add special components - "AutoExport" => Needed - "Dynamic" ? naah wait that should be exported by the Bevy side - - [ ] filter out Components_meta ?? + - [x] filter out Components_meta ?? - [x] add legacy mode to the persisted parameters - bevy_gltf_components: diff --git a/tools/gltf_auto_export/README.md b/tools/gltf_auto_export/README.md index 61076b5..fb577bd 100644 --- a/tools/gltf_auto_export/README.md +++ b/tools/gltf_auto_export/README.md @@ -120,12 +120,6 @@ This issue has been resolved in v0.9. - materials path: where to export materials to - - Legacy mode for bevy: the export of custom properties is slightly different - when using bevy_gltf_components or bevy_gltf_blueprints with ```legacy_mode``` turned on (the default currently), toggle this on to keep using the older variant - - > tldr: legacy mode in this add on should match your use of legacy mode on the Bevy side - > if you use the ```bevy_components``` add-on **legacy mode** should be turned **OFF** - * and your standard gltf export parameters in the **gltf** panel ![blender addon use2](./docs/blender_addon_use2.png) diff --git a/tools/gltf_auto_export/todo.md b/tools/gltf_auto_export/todo.md index 4249f9d..299b5f9 100644 --- a/tools/gltf_auto_export/todo.md +++ b/tools/gltf_auto_export/todo.md @@ -47,6 +47,12 @@ - [ ] update cleanup_materials +- [x] remove legacy mode + - [x] from auto_export + - [x] from rust code + - [x] from examples + - [x] added notes & workaround information in docs + - [ ] remove bulk of tracker related code - [ ] clean up - [x] split up change detection in settings to its own panel \ No newline at end of file