mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 11:50:53 +00:00
feat():
* cleaned up crate code * added duplicate named component to testing project to resolve issues with clashing short_names for bevy components
This commit is contained in:
parent
9138c81c60
commit
49917e3b17
@ -111,74 +111,74 @@ fn materials_library_enabled(blueprints_config: Res<BluePrintsConfig>) -> bool {
|
|||||||
impl Plugin for BlueprintsPlugin {
|
impl Plugin for BlueprintsPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_plugins(ComponentsFromGltfPlugin {})
|
app.add_plugins(ComponentsFromGltfPlugin {})
|
||||||
.register_type::<BlueprintName>()
|
.register_type::<BlueprintName>()
|
||||||
.register_type::<MaterialInfo>()
|
.register_type::<MaterialInfo>()
|
||||||
.register_type::<SpawnHere>()
|
.register_type::<SpawnHere>()
|
||||||
.register_type::<BlueprintAnimations>()
|
.register_type::<BlueprintAnimations>()
|
||||||
.register_type::<SceneAnimations>()
|
.register_type::<SceneAnimations>()
|
||||||
.register_type::<AnimationInfo>()
|
.register_type::<AnimationInfo>()
|
||||||
.register_type::<AnimationInfos>()
|
.register_type::<AnimationInfos>()
|
||||||
.register_type::<Vec<AnimationInfo>>()
|
.register_type::<Vec<AnimationInfo>>()
|
||||||
.register_type::<AnimationMarkers>()
|
.register_type::<AnimationMarkers>()
|
||||||
.register_type::<HashMap<u32, Vec<String>>>()
|
.register_type::<HashMap<u32, Vec<String>>>()
|
||||||
.register_type::<HashMap<String, HashMap<u32, Vec<String>>>>()
|
.register_type::<HashMap<String, HashMap<u32, Vec<String>>>>()
|
||||||
.add_event::<AnimationMarkerReached>()
|
.add_event::<AnimationMarkerReached>()
|
||||||
.register_type::<BlueprintsList>()
|
.register_type::<BlueprintsList>()
|
||||||
.register_type::<HashMap<String, Vec<String>>>()
|
.register_type::<HashMap<String, Vec<String>>>()
|
||||||
.insert_resource(BluePrintsConfig {
|
.insert_resource(BluePrintsConfig {
|
||||||
format: self.format,
|
format: self.format,
|
||||||
library_folder: self.library_folder.clone(),
|
library_folder: self.library_folder.clone(),
|
||||||
|
|
||||||
aabbs: self.aabbs,
|
aabbs: self.aabbs,
|
||||||
aabb_cache: HashMap::new(),
|
aabb_cache: HashMap::new(),
|
||||||
|
|
||||||
material_library: self.material_library,
|
material_library: self.material_library,
|
||||||
material_library_folder: self.material_library_folder.clone(),
|
material_library_folder: self.material_library_folder.clone(),
|
||||||
material_library_cache: HashMap::new(),
|
material_library_cache: HashMap::new(),
|
||||||
})
|
})
|
||||||
.configure_sets(
|
.configure_sets(
|
||||||
Update,
|
Update,
|
||||||
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
|
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
|
||||||
.chain()
|
|
||||||
.after(GltfComponentsSet::Injection),
|
|
||||||
)
|
|
||||||
.add_systems(
|
|
||||||
Update,
|
|
||||||
(
|
|
||||||
(
|
|
||||||
prepare_blueprints,
|
|
||||||
check_for_loaded,
|
|
||||||
spawn_from_blueprints,
|
|
||||||
apply_deferred,
|
|
||||||
)
|
|
||||||
.chain(),
|
|
||||||
(compute_scene_aabbs, apply_deferred)
|
|
||||||
.chain()
|
.chain()
|
||||||
.run_if(aabbs_enabled),
|
.after(GltfComponentsSet::Injection),
|
||||||
apply_deferred,
|
|
||||||
(
|
|
||||||
materials_inject,
|
|
||||||
check_for_material_loaded,
|
|
||||||
materials_inject2,
|
|
||||||
)
|
|
||||||
.chain()
|
|
||||||
.run_if(materials_library_enabled),
|
|
||||||
)
|
)
|
||||||
.chain()
|
.add_systems(
|
||||||
.in_set(GltfBlueprintsSet::Spawn),
|
Update,
|
||||||
)
|
(
|
||||||
.add_systems(
|
(
|
||||||
Update,
|
prepare_blueprints,
|
||||||
(spawned_blueprint_post_process, apply_deferred)
|
check_for_loaded,
|
||||||
.chain()
|
spawn_from_blueprints,
|
||||||
.in_set(GltfBlueprintsSet::AfterSpawn),
|
apply_deferred,
|
||||||
)
|
)
|
||||||
.add_systems(
|
.chain(),
|
||||||
Update,
|
(compute_scene_aabbs, apply_deferred)
|
||||||
(
|
.chain()
|
||||||
trigger_instance_animation_markers_events,
|
.run_if(aabbs_enabled),
|
||||||
trigger_blueprint_animation_markers_events,
|
apply_deferred,
|
||||||
),
|
(
|
||||||
);
|
materials_inject,
|
||||||
|
check_for_material_loaded,
|
||||||
|
materials_inject2,
|
||||||
|
)
|
||||||
|
.chain()
|
||||||
|
.run_if(materials_library_enabled),
|
||||||
|
)
|
||||||
|
.chain()
|
||||||
|
.in_set(GltfBlueprintsSet::Spawn),
|
||||||
|
)
|
||||||
|
.add_systems(
|
||||||
|
Update,
|
||||||
|
(spawned_blueprint_post_process, apply_deferred)
|
||||||
|
.chain()
|
||||||
|
.in_set(GltfBlueprintsSet::AfterSpawn),
|
||||||
|
)
|
||||||
|
.add_systems(
|
||||||
|
Update,
|
||||||
|
(
|
||||||
|
trigger_instance_animation_markers_events,
|
||||||
|
trigger_blueprint_animation_markers_events,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,7 @@ pub use process_gltfs::*;
|
|||||||
pub mod blender_settings;
|
pub mod blender_settings;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
app::Startup,
|
ecs::{component::Component, reflect::ReflectComponent, system::Resource},
|
||||||
ecs::{
|
|
||||||
component::Component,
|
|
||||||
reflect::ReflectComponent,
|
|
||||||
system::{Res, Resource},
|
|
||||||
},
|
|
||||||
log::warn,
|
|
||||||
prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update},
|
prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update},
|
||||||
reflect::Reflect,
|
reflect::Reflect,
|
||||||
};
|
};
|
||||||
@ -68,16 +62,14 @@ pub enum GltfComponentsSet {
|
|||||||
#[derive(Clone, Resource)]
|
#[derive(Clone, Resource)]
|
||||||
pub struct GltfComponentsConfig {}
|
pub struct GltfComponentsConfig {}
|
||||||
|
|
||||||
pub struct ComponentsFromGltfPlugin {
|
pub struct ComponentsFromGltfPlugin {}
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ComponentsFromGltfPlugin {
|
impl Default for ComponentsFromGltfPlugin {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { }
|
Self {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Plugin for ComponentsFromGltfPlugin {
|
impl Plugin for ComponentsFromGltfPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_plugins(blender_settings::plugin)
|
app.add_plugins(blender_settings::plugin)
|
||||||
|
@ -13,7 +13,7 @@ use bevy::{
|
|||||||
utils::HashMap,
|
utils::HashMap,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{ronstring_to_reflect_component, GltfComponentsConfig, GltfProcessed};
|
use crate::{ronstring_to_reflect_component, GltfProcessed};
|
||||||
|
|
||||||
/// main function: injects components into each entity in gltf files that have `gltf_extras`, using reflection
|
/// main function: injects components into each entity in gltf files that have `gltf_extras`, using reflection
|
||||||
pub fn add_components_from_gltf_extras(world: &mut World) {
|
pub fn add_components_from_gltf_extras(world: &mut World) {
|
||||||
@ -22,7 +22,7 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
|
|||||||
let mut entity_components: HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>> =
|
let mut entity_components: HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>> =
|
||||||
HashMap::new();
|
HashMap::new();
|
||||||
|
|
||||||
let gltf_components_config = world.resource::<GltfComponentsConfig>();
|
// let gltf_components_config = world.resource::<GltfComponentsConfig>();
|
||||||
|
|
||||||
for (entity, name, extra, parent) in extras.iter(world) {
|
for (entity, name, extra, parent) in extras.iter(world) {
|
||||||
debug!(
|
debug!(
|
||||||
@ -33,10 +33,7 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
|
|||||||
let type_registry: &AppTypeRegistry = world.resource();
|
let type_registry: &AppTypeRegistry = world.resource();
|
||||||
let type_registry = type_registry.read();
|
let type_registry = type_registry.read();
|
||||||
|
|
||||||
let reflect_components = ronstring_to_reflect_component(
|
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
|
||||||
&extra.value,
|
|
||||||
&type_registry,
|
|
||||||
);
|
|
||||||
|
|
||||||
// we assign the components specified /xxx_components objects to their parent node
|
// we assign the components specified /xxx_components objects to their parent node
|
||||||
let mut target_entity = entity;
|
let mut target_entity = entity;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use bevy::log::{debug, warn};
|
use bevy::log::{debug, warn};
|
||||||
use bevy::reflect::serde::UntypedReflectDeserializer;
|
use bevy::reflect::serde::UntypedReflectDeserializer;
|
||||||
use bevy::reflect::{Reflect, TypeInfo, TypeRegistration, TypeRegistry};
|
use bevy::reflect::{Reflect, TypeRegistration, TypeRegistry};
|
||||||
use bevy::utils::HashMap;
|
use bevy::utils::HashMap;
|
||||||
use ron::Value;
|
use ron::Value;
|
||||||
use serde::de::DeserializeSeed;
|
use serde::de::DeserializeSeed;
|
||||||
@ -17,7 +17,7 @@ pub fn ronstring_to_reflect_component(
|
|||||||
let type_string = key.replace("component: ", "").trim().to_string();
|
let type_string = key.replace("component: ", "").trim().to_string();
|
||||||
let capitalized_type_name = capitalize_first_letter(type_string.as_str());
|
let capitalized_type_name = capitalize_first_letter(type_string.as_str());
|
||||||
|
|
||||||
let mut parsed_value: String;
|
let parsed_value: String;
|
||||||
match value.clone() {
|
match value.clone() {
|
||||||
Value::String(str) => {
|
Value::String(str) => {
|
||||||
parsed_value = str;
|
parsed_value = str;
|
||||||
|
@ -2960,6 +2960,22 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"typeInfo": "Struct"
|
"typeInfo": "Struct"
|
||||||
},
|
},
|
||||||
|
"bevy_example::dupe_components::EnumTest": {
|
||||||
|
"isComponent": true,
|
||||||
|
"isResource": false,
|
||||||
|
"oneOf": [
|
||||||
|
"Metal",
|
||||||
|
"Wood",
|
||||||
|
"Rock",
|
||||||
|
"Cloth",
|
||||||
|
"Squishy",
|
||||||
|
"None"
|
||||||
|
],
|
||||||
|
"short_name": "EnumTest",
|
||||||
|
"title": "bevy_example::dupe_components::EnumTest",
|
||||||
|
"type": "string",
|
||||||
|
"typeInfo": "Enum"
|
||||||
|
},
|
||||||
"bevy_example::game::animation::Marker1": {
|
"bevy_example::game::animation::Marker1": {
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"isComponent": true,
|
"isComponent": true,
|
||||||
|
13
testing/bevy_example/src/dupe_components/mod.rs
Normal file
13
testing/bevy_example/src/dupe_components/mod.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component, Reflect, Default, Debug)]
|
||||||
|
#[reflect(Component)]
|
||||||
|
pub enum EnumTest {
|
||||||
|
Metal,
|
||||||
|
Wood,
|
||||||
|
Rock,
|
||||||
|
Cloth,
|
||||||
|
Squishy,
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
|
}
|
@ -7,6 +7,7 @@ use crate::core::*;
|
|||||||
mod game;
|
mod game;
|
||||||
use game::*;
|
use game::*;
|
||||||
|
|
||||||
|
mod dupe_components;
|
||||||
mod test_components;
|
mod test_components;
|
||||||
use test_components::*;
|
use test_components::*;
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::dupe_components;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
pbr::{ExtendedMaterial, MaterialExtension},
|
pbr::{ExtendedMaterial, MaterialExtension},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
@ -164,6 +165,7 @@ impl Plugin for ComponentsTestPlugin {
|
|||||||
.register_type::<TupleVec2>()
|
.register_type::<TupleVec2>()
|
||||||
.register_type::<TupleVec3>()
|
.register_type::<TupleVec3>()
|
||||||
.register_type::<EnumTest>()
|
.register_type::<EnumTest>()
|
||||||
|
.register_type::<dupe_components::EnumTest>()
|
||||||
.register_type::<TupleTestColor>()
|
.register_type::<TupleTestColor>()
|
||||||
.register_type::<TupleVec>()
|
.register_type::<TupleVec>()
|
||||||
.register_type::<Vec<String>>()
|
.register_type::<Vec<String>>()
|
||||||
|
Loading…
Reference in New Issue
Block a user