mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-12-22 23:54:10 +00:00
refactor(): removed remains of legacy mode
This commit is contained in:
parent
eda18b7d25
commit
9138c81c60
@ -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
|
||||
|
@ -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<BluePrintsConfig>) -> 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::<BlueprintName>()
|
||||
.register_type::<MaterialInfo>()
|
||||
.register_type::<SpawnHere>()
|
||||
|
@ -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::<f32>().unwrap().to_string();
|
||||
}
|
||||
"f64" => {
|
||||
formated = parsed_value.parse::<f64>().unwrap().to_string();
|
||||
}
|
||||
"u8" => {
|
||||
formated = parsed_value.parse::<u8>().unwrap().to_string();
|
||||
}
|
||||
"u16" => {
|
||||
formated = parsed_value.parse::<u16>().unwrap().to_string();
|
||||
}
|
||||
"u32" => {
|
||||
formated = parsed_value.parse::<u32>().unwrap().to_string();
|
||||
}
|
||||
"u64" => {
|
||||
formated = parsed_value.parse::<u64>().unwrap().to_string();
|
||||
}
|
||||
"u128" => {
|
||||
formated = parsed_value.parse::<u128>().unwrap().to_string();
|
||||
}
|
||||
"glam::Vec2" => {
|
||||
let parsed: Vec<f32> = ron::from_str(&parsed_value).unwrap();
|
||||
formated = format!("(x:{},y:{})", parsed[0], parsed[1]);
|
||||
}
|
||||
"glam::Vec3" => {
|
||||
let parsed: Vec<f32> = ron::from_str(&parsed_value).unwrap();
|
||||
formated =
|
||||
format!("(x:{},y:{},z:{})", parsed[0], parsed[1], parsed[2]);
|
||||
}
|
||||
"bevy_render::color::Color" => {
|
||||
let parsed: Vec<f32> = 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
|
||||
|
||||
|
@ -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<GltfComponentsConfig>) {
|
||||
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::<GltfProcessed>()
|
||||
.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),
|
||||
|
@ -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
|
||||
|
@ -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<dyn Reflect>, TypeRegistration)> {
|
||||
let lookup: HashMap<String, Value> = ron::from_str(ron_string).unwrap();
|
||||
let mut components: Vec<(Box<dyn Reflect>, 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::<f32>().unwrap().to_string();
|
||||
}
|
||||
"f64" => {
|
||||
formated = parsed_value.parse::<f64>().unwrap().to_string();
|
||||
}
|
||||
"u8" => {
|
||||
formated = parsed_value.parse::<u8>().unwrap().to_string();
|
||||
}
|
||||
"u16" => {
|
||||
formated = parsed_value.parse::<u16>().unwrap().to_string();
|
||||
}
|
||||
"u32" => {
|
||||
formated = parsed_value.parse::<u32>().unwrap().to_string();
|
||||
}
|
||||
"u64" => {
|
||||
formated = parsed_value.parse::<u64>().unwrap().to_string();
|
||||
}
|
||||
"u128" => {
|
||||
formated = parsed_value.parse::<u128>().unwrap().to_string();
|
||||
}
|
||||
"glam::Vec2" => {
|
||||
let parsed: Vec<f32> = ron::from_str(&parsed_value).unwrap();
|
||||
formated = format!("(x:{},y:{})", parsed[0], parsed[1]);
|
||||
}
|
||||
"glam::Vec3" => {
|
||||
let parsed: Vec<f32> = ron::from_str(&parsed_value).unwrap();
|
||||
formated =
|
||||
format!("(x:{},y:{},z:{})", parsed[0], parsed[1], parsed[2]);
|
||||
}
|
||||
"bevy_render::color::Color" => {
|
||||
let parsed: Vec<f32> = 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(),
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -11,7 +11,6 @@ impl Plugin for CorePlugin {
|
||||
..Default::default()
|
||||
},
|
||||
BlueprintsPlugin {
|
||||
legacy_mode: false,
|
||||
library_folder: "models/library".into(),
|
||||
format: GltfFormat::GLB,
|
||||
aabbs: true,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user