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 {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(ComponentsFromGltfPlugin {})
|
||||
.register_type::<BlueprintName>()
|
||||
.register_type::<MaterialInfo>()
|
||||
.register_type::<SpawnHere>()
|
||||
.register_type::<BlueprintAnimations>()
|
||||
.register_type::<SceneAnimations>()
|
||||
.register_type::<AnimationInfo>()
|
||||
.register_type::<AnimationInfos>()
|
||||
.register_type::<Vec<AnimationInfo>>()
|
||||
.register_type::<AnimationMarkers>()
|
||||
.register_type::<HashMap<u32, Vec<String>>>()
|
||||
.register_type::<HashMap<String, HashMap<u32, Vec<String>>>>()
|
||||
.add_event::<AnimationMarkerReached>()
|
||||
.register_type::<BlueprintsList>()
|
||||
.register_type::<HashMap<String, Vec<String>>>()
|
||||
.insert_resource(BluePrintsConfig {
|
||||
format: self.format,
|
||||
library_folder: self.library_folder.clone(),
|
||||
.register_type::<BlueprintName>()
|
||||
.register_type::<MaterialInfo>()
|
||||
.register_type::<SpawnHere>()
|
||||
.register_type::<BlueprintAnimations>()
|
||||
.register_type::<SceneAnimations>()
|
||||
.register_type::<AnimationInfo>()
|
||||
.register_type::<AnimationInfos>()
|
||||
.register_type::<Vec<AnimationInfo>>()
|
||||
.register_type::<AnimationMarkers>()
|
||||
.register_type::<HashMap<u32, Vec<String>>>()
|
||||
.register_type::<HashMap<String, HashMap<u32, Vec<String>>>>()
|
||||
.add_event::<AnimationMarkerReached>()
|
||||
.register_type::<BlueprintsList>()
|
||||
.register_type::<HashMap<String, Vec<String>>>()
|
||||
.insert_resource(BluePrintsConfig {
|
||||
format: self.format,
|
||||
library_folder: self.library_folder.clone(),
|
||||
|
||||
aabbs: self.aabbs,
|
||||
aabb_cache: HashMap::new(),
|
||||
aabbs: self.aabbs,
|
||||
aabb_cache: HashMap::new(),
|
||||
|
||||
material_library: self.material_library,
|
||||
material_library_folder: self.material_library_folder.clone(),
|
||||
material_library_cache: HashMap::new(),
|
||||
})
|
||||
.configure_sets(
|
||||
Update,
|
||||
(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)
|
||||
material_library: self.material_library,
|
||||
material_library_folder: self.material_library_folder.clone(),
|
||||
material_library_cache: HashMap::new(),
|
||||
})
|
||||
.configure_sets(
|
||||
Update,
|
||||
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
|
||||
.chain()
|
||||
.run_if(aabbs_enabled),
|
||||
apply_deferred,
|
||||
(
|
||||
materials_inject,
|
||||
check_for_material_loaded,
|
||||
materials_inject2,
|
||||
)
|
||||
.chain()
|
||||
.run_if(materials_library_enabled),
|
||||
.after(GltfComponentsSet::Injection),
|
||||
)
|
||||
.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,
|
||||
),
|
||||
);
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
(
|
||||
prepare_blueprints,
|
||||
check_for_loaded,
|
||||
spawn_from_blueprints,
|
||||
apply_deferred,
|
||||
)
|
||||
.chain(),
|
||||
(compute_scene_aabbs, apply_deferred)
|
||||
.chain()
|
||||
.run_if(aabbs_enabled),
|
||||
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;
|
||||
|
||||
use bevy::{
|
||||
app::Startup,
|
||||
ecs::{
|
||||
component::Component,
|
||||
reflect::ReflectComponent,
|
||||
system::{Res, Resource},
|
||||
},
|
||||
log::warn,
|
||||
ecs::{component::Component, reflect::ReflectComponent, system::Resource},
|
||||
prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update},
|
||||
reflect::Reflect,
|
||||
};
|
||||
|
@ -68,16 +62,14 @@ pub enum GltfComponentsSet {
|
|||
#[derive(Clone, Resource)]
|
||||
pub struct GltfComponentsConfig {}
|
||||
|
||||
pub struct ComponentsFromGltfPlugin {
|
||||
}
|
||||
pub struct ComponentsFromGltfPlugin {}
|
||||
|
||||
impl Default for ComponentsFromGltfPlugin {
|
||||
fn default() -> Self {
|
||||
Self { }
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Plugin for ComponentsFromGltfPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(blender_settings::plugin)
|
||||
|
|
|
@ -13,7 +13,7 @@ use bevy::{
|
|||
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
|
||||
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)>> =
|
||||
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) {
|
||||
debug!(
|
||||
|
@ -33,10 +33,7 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
|
|||
let type_registry: &AppTypeRegistry = world.resource();
|
||||
let type_registry = type_registry.read();
|
||||
|
||||
let reflect_components = ronstring_to_reflect_component(
|
||||
&extra.value,
|
||||
&type_registry,
|
||||
);
|
||||
let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
|
||||
|
||||
// we assign the components specified /xxx_components objects to their parent node
|
||||
let mut target_entity = entity;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bevy::log::{debug, warn};
|
||||
use bevy::reflect::serde::UntypedReflectDeserializer;
|
||||
use bevy::reflect::{Reflect, TypeInfo, TypeRegistration, TypeRegistry};
|
||||
use bevy::reflect::{Reflect, TypeRegistration, TypeRegistry};
|
||||
use bevy::utils::HashMap;
|
||||
use ron::Value;
|
||||
use serde::de::DeserializeSeed;
|
||||
|
@ -17,7 +17,7 @@ pub fn ronstring_to_reflect_component(
|
|||
let type_string = key.replace("component: ", "").trim().to_string();
|
||||
let capitalized_type_name = capitalize_first_letter(type_string.as_str());
|
||||
|
||||
let mut parsed_value: String;
|
||||
let parsed_value: String;
|
||||
match value.clone() {
|
||||
Value::String(str) => {
|
||||
parsed_value = str;
|
||||
|
|
|
@ -2960,6 +2960,22 @@
|
|||
"type": "object",
|
||||
"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": {
|
||||
"additionalProperties": false,
|
||||
"isComponent": true,
|
||||
|
|
|
@ -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;
|
||||
use game::*;
|
||||
|
||||
mod dupe_components;
|
||||
mod test_components;
|
||||
use test_components::*;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::dupe_components;
|
||||
use bevy::{
|
||||
pbr::{ExtendedMaterial, MaterialExtension},
|
||||
prelude::*,
|
||||
|
@ -164,6 +165,7 @@ impl Plugin for ComponentsTestPlugin {
|
|||
.register_type::<TupleVec2>()
|
||||
.register_type::<TupleVec3>()
|
||||
.register_type::<EnumTest>()
|
||||
.register_type::<dupe_components::EnumTest>()
|
||||
.register_type::<TupleTestColor>()
|
||||
.register_type::<TupleVec>()
|
||||
.register_type::<Vec<String>>()
|
||||
|
|
Loading…
Reference in New Issue