Skip to content

Commit

Permalink
chore(): cleanup & simplification pass (kaosat-dev#122)
Browse files Browse the repository at this point in the history
* closes kaosat-dev#118 
* closes kaosat-dev#110 
* closes kaosat-dev#99
  • Loading branch information
kaosat-dev authored Feb 7, 2024
1 parent 537f08b commit 0d708b8
Show file tree
Hide file tree
Showing 387 changed files with 1,413 additions and 21,038 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ members = [
"crates/bevy_gltf_blueprints",
"crates/bevy_gltf_save_load",
"crates/bevy_registry_export",

"examples/common/",

"examples/bevy_gltf_components/basic/",
"examples/bevy_gltf_components/basic_wasm/",

"examples/bevy_gltf_blueprints/basic/",
"examples/bevy_gltf_blueprints/basic_wasm/",
"examples/bevy_gltf_blueprints/basic_scene_components/",
"examples/bevy_gltf_blueprints/basic_xpbd_physics/",
"examples/bevy_gltf_blueprints/nested_blueprints/",
"examples/bevy_gltf_blueprints/animation/",
"examples/bevy_gltf_blueprints/multiple_levels/",
"examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles",
"examples/bevy_gltf_blueprints/materials/",

"examples/bevy_gltf_save_load/basic/",

"examples/bevy_registry_export/basic"

]
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gltf_blueprints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_gltf_blueprints"
version = "0.7.0"
version = "0.7.1"
authors = ["Mark 'kaosat-dev' Moissette"]
description = "Adds the ability to define Blueprints/Prefabs for [Bevy](https://bevyengine.org/) inside gltf files and spawn them in Bevy."
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"
Expand Down
6 changes: 0 additions & 6 deletions crates/bevy_gltf_blueprints/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,10 @@ https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/example

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic_xpbd_physics

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic_scene_components

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/multiple_levels

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/materials

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/nested_blueprints

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles


Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_gltf_blueprints/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn compute_descendant_aabb(
if let Ok(aabb) = existing_aabbs.get(*child) {
chilren_aabbs.push(*aabb);
} else {
let aabb = compute_descendant_aabb(*child, children, &existing_aabbs);
let aabb = compute_descendant_aabb(*child, children, existing_aabbs);
chilren_aabbs.push(aabb);
}
}
Expand All @@ -57,5 +57,5 @@ pub fn compute_descendant_aabb(
return aabb;
}

return Aabb::default();
Aabb::default()
}
6 changes: 3 additions & 3 deletions crates/bevy_gltf_blueprints/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use bevy::utils::HashMap;

#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// storage for animations for a given entity (hierarchy), essentially a clone of gltf's named_animations
/// storage for animations for a given entity (hierarchy), essentially a clone of gltf's `named_animations`
pub struct Animations {
pub named_animations: HashMap<String, Handle<AnimationClip>>,
}

#[derive(Component, Debug)]
/// Stop gap helper component : this is inserted into a "root" entity (an entity representing a whole gltf file)
/// so that the root entity knows which of its children contains an actualy AnimationPlayer component
/// this is for convenience, because currently , Bevy's gltf parsing inserts AnimationPlayers "one level down"
/// so that the root entity knows which of its children contains an actualy `AnimationPlayer` component
/// this is for convenience, because currently , Bevy's gltf parsing inserts `AnimationPlayers` "one level down"
/// ie armature/root for animated models, which means more complex queries to trigger animations that we want to avoid
pub struct AnimationPlayerLink(pub Entity);
37 changes: 16 additions & 21 deletions crates/bevy_gltf_blueprints/src/copy_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl CopyComponents {
let type_id = component_info.type_id().unwrap();
if self.exclude.contains(&type_id) {
debug!("excluding component: {:?}", component_info.name());
return None;
None
} else {
debug!(
"cloning: component: {:?} {:?}",
Expand All @@ -51,32 +51,27 @@ impl CopyComponents {
);

if let Some(type_registration) = registry.get(type_id) {
return Some(type_registration);
} else {
if self.stringent {
return Some(
registry.get(type_id).expect(
format!(
"cannot clone entity: component: {:?} is not registered",
component_info.name()
)
.as_str(),
),
);
} else {
warn!(
"cannot clone component: component: {:?} is not registered",
Some(type_registration)
} else if self.stringent {
return Some(registry.get(type_id).unwrap_or_else(|| {
panic!(
"cannot clone entity: component: {:?} is not registered",
component_info.name()
);
return None;
}
)
}));
} else {
warn!(
"cannot clone component: component: {:?} is not registered",
component_info.name()
);
None
}
}
})
.map(|type_id| {
return (
type_id.data::<ReflectComponent>().unwrap().clone(),
type_id.type_info().type_id().clone(), // we need the original type_id down the line
type_id.type_info().type_id(), // we need the original type_id down the line
);
})
.collect::<Vec<_>>()
Expand Down Expand Up @@ -104,6 +99,6 @@ impl CopyComponents {
// This allows the command to be used in systems
impl Command for CopyComponents {
fn apply(self, world: &mut World) {
self.transfer_components(world)
self.transfer_components(world);
}
}
80 changes: 40 additions & 40 deletions crates/bevy_gltf_blueprints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,47 +113,47 @@ 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 {
legacy_mode: self.legacy_mode,
})
.register_type::<BlueprintName>()
.register_type::<MaterialInfo>()
.register_type::<SpawnHere>()
.register_type::<Animations>()
.insert_resource(BluePrintsConfig {
format: self.format.clone(),
library_folder: self.library_folder.clone(),

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,
(
spawn_from_blueprints,
compute_scene_aabbs.run_if(aabbs_enabled),
apply_deferred.run_if(aabbs_enabled),
apply_deferred,
materials_inject.run_if(materials_library_enabled),
)
.chain()
.in_set(GltfBlueprintsSet::Spawn),
.register_type::<BlueprintName>()
.register_type::<MaterialInfo>()
.register_type::<SpawnHere>()
.register_type::<Animations>()
.insert_resource(BluePrintsConfig {
format: self.format,
library_folder: self.library_folder.clone(),

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,
(
spawn_from_blueprints,
compute_scene_aabbs.run_if(aabbs_enabled),
apply_deferred.run_if(aabbs_enabled),
apply_deferred,
materials_inject.run_if(materials_library_enabled),
)
.add_systems(
Update,
(spawned_blueprint_post_process, apply_deferred)
.chain()
.in_set(GltfBlueprintsSet::AfterSpawn),
);
.chain()
.in_set(GltfBlueprintsSet::Spawn),
)
.add_systems(
Update,
(spawned_blueprint_post_process, apply_deferred)
.chain()
.in_set(GltfBlueprintsSet::AfterSpawn),
);
}
}
11 changes: 6 additions & 5 deletions crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ pub struct BlueprintName(pub String);
pub struct SpawnHere;

#[derive(Component)]
/// FlagComponent for dynamically spawned scenes
/// flag component for dynamically spawned scenes
pub struct Spawned;

#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// flag component marking any spwaned child of blueprints ..unless the original entity was marked with the 'NoInBlueprint' marker component
/// flag component marking any spwaned child of blueprints ..unless the original entity was marked with the `NoInBlueprint` marker component
pub struct InBlueprint;

#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// flag component preventing any spwaned child of blueprints to be marked with the InBlueprint component
/// flag component preventing any spawned child of blueprints to be marked with the `InBlueprint` component
pub struct NoInBlueprint;

#[derive(Component, Reflect, Default, Debug)]
Expand Down Expand Up @@ -112,14 +112,15 @@ pub(crate) fn spawn_from_blueprints(
let main_scene_name = gltf
.named_scenes
.keys()
.nth(0)
.next()
.expect("there should be at least one named scene in the gltf file to spawn");

let scene = &gltf.named_scenes[main_scene_name];

// transforms are optional, but still deal with them correctly
let mut transforms: Transform = Transform::default();
if transform.is_some() {
transforms = transform.unwrap().clone();
transforms = *transform.unwrap();
}

commands.entity(entity).insert((
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gltf_blueprints/src/spawn_post_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{CopyComponents, InBlueprint, NoInBlueprint, OriginalChildren};
/// - it removes one level of useless nesting
/// - it copies the blueprint's root components to the entity it was spawned on (original entity)
/// - it copies the children of the blueprint scene into the original entity
/// - it add AnimationLink components so that animations can be controlled from the original entity
/// - it add `AnimationLink` components so that animations can be controlled from the original entity
/// - it cleans up/ removes a few , by then uneeded components
pub(crate) fn spawned_blueprint_post_process(
unprocessed_entities: Query<
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gltf_components/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_gltf_components"
version = "0.3.0"
version = "0.3.1"
authors = ["Mark 'kaosat-dev' Moissette"]
description = "Allows you to define [Bevy](https://bevyengine.org/) components direclty inside gltf files and instanciate the components on the Bevy side."
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"
Expand Down
Loading

0 comments on commit 0d708b8

Please sign in to comment.