Compare commits

..

No commits in common. "ce473a357e08332d9da5648e497f761c6fd2989f" and "0b64de79da443c9d8e6d4155b8aeea4e0f10d04f" have entirely different histories.

7 changed files with 50 additions and 258 deletions

View File

@ -4,7 +4,7 @@ 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`
pub struct BlueprintAnimations {
pub struct Animations {
pub named_animations: HashMap<String, Handle<AnimationClip>>,
}
@ -13,25 +13,10 @@ pub struct BlueprintAnimations {
/// 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 BlueprintAnimationPlayerLink(pub Entity);
pub struct AnimationPlayerLink(pub Entity);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct Animated{
pub animations: Vec<String>
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// storage for animations for a given entity (hierarchy), essentially a clone of gltf's `named_animations`
pub struct InstanceAnimations {
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"
/// ie armature/root for animated models, which means more complex queries to trigger animations that we want to avoid
pub struct InstanceAnimationPlayerLink(pub Entity);

View File

@ -119,11 +119,8 @@ impl Plugin for BlueprintsPlugin {
.register_type::<BlueprintName>()
.register_type::<MaterialInfo>()
.register_type::<SpawnHere>()
.register_type::<BlueprintAnimations>()
.register_type::<InstanceAnimations>()
.register_type::<Animations>()
.register_type::<Animated>()
.register_type::<BlueprintsList>()
.register_type::<Vec<String>>()
.register_type::<HashMap<String, Vec<String>>>()

View File

@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
use bevy::{gltf::Gltf, prelude::*, utils::HashMap};
use crate::{BlueprintAnimations, BluePrintsConfig};
use crate::{Animations, BluePrintsConfig};
/// this is a flag component for our levels/game world
#[derive(Component)]
@ -279,11 +279,11 @@ pub(crate) fn spawn_from_blueprints(
transform: transforms,
..Default::default()
},
Animations {
named_animations: gltf.named_animations.clone(),
},
Spawned,
OriginalChildren(original_children),
BlueprintAnimations { // these are animations specific to the inside of the blueprint
named_animations: gltf.named_animations.clone(),
}
));
if add_to_world.is_some() {

View File

@ -5,7 +5,7 @@ use bevy::prelude::*;
use bevy::scene::SceneInstance;
// use bevy::utils::hashbrown::HashSet;
use super::{BlueprintAnimationPlayerLink, BlueprintAnimations};
use super::{AnimationPlayerLink, Animations};
use super::{SpawnHere, Spawned};
use crate::{
AssetsToLoad, BlueprintAssetsLoaded, CopyComponents, InBlueprint, NoInBlueprint,
@ -24,7 +24,7 @@ pub(crate) fn spawned_blueprint_post_process(
Entity,
&Children,
&OriginalChildren,
&BlueprintAnimations,
&Animations,
Option<&NoInBlueprint>,
Option<&Name>,
),
@ -85,7 +85,7 @@ pub(crate) fn spawned_blueprint_post_process(
// FIXME: stopgap solution: since we cannot use an AnimationPlayer at the root entity level
// and we cannot update animation clips so that the EntityPaths point to one level deeper,
// BUT we still want to have some marker/control at the root entity level, we add this
commands.entity(original).insert(BlueprintAnimationPlayerLink(added));
commands.entity(original).insert(AnimationPlayerLink(added));
}
}
}

View File

@ -2947,39 +2947,6 @@
"type": "object",
"typeInfo": "Struct"
},
"bevy_example::game::Marker1": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
"properties": {},
"required": [],
"short_name": "Marker1",
"title": "bevy_example::game::Marker1",
"type": "object",
"typeInfo": "Struct"
},
"bevy_example::game::Marker2": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
"properties": {},
"required": [],
"short_name": "Marker2",
"title": "bevy_example::game::Marker2",
"type": "object",
"typeInfo": "Struct"
},
"bevy_example::game::Marker3": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
"properties": {},
"required": [],
"short_name": "Marker3",
"title": "bevy_example::game::Marker3",
"type": "object",
"typeInfo": "Struct"
},
"bevy_example::test_components::AComponentWithAnExtremlyExageratedOrMaybeNotButCouldBeNameOrWut": {
"additionalProperties": false,
"isComponent": true,
@ -3568,7 +3535,7 @@
"type": "object",
"typeInfo": "Struct"
},
"bevy_gltf_blueprints::animation::BlueprintAnimations": {
"bevy_gltf_blueprints::animation::Animations": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
@ -3582,27 +3549,8 @@
"required": [
"named_animations"
],
"short_name": "BlueprintAnimations",
"title": "bevy_gltf_blueprints::animation::BlueprintAnimations",
"type": "object",
"typeInfo": "Struct"
},
"bevy_gltf_blueprints::animation::InstanceAnimations": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
"properties": {
"named_animations": {
"type": {
"$ref": "#/$defs/bevy_utils::hashbrown::HashMap<alloc::string::String, bevy_asset::handle::Handle<bevy_animation::AnimationClip>, bevy_utils::hashbrown::hash_map::DefaultHashBuilder>"
}
}
},
"required": [
"named_animations"
],
"short_name": "InstanceAnimations",
"title": "bevy_gltf_blueprints::animation::InstanceAnimations",
"short_name": "Animations",
"title": "bevy_gltf_blueprints::animation::Animations",
"type": "object",
"typeInfo": "Struct"
},

View File

@ -3,7 +3,7 @@ use std::{
collections::HashMap, fs, time::Duration
};
use bevy_gltf_blueprints::{Animated, BlueprintAnimationPlayerLink, BlueprintAnimations, InstanceAnimationPlayerLink, InstanceAnimations, BlueprintName, BlueprintsList, GltfBlueprintsSet};
use bevy_gltf_blueprints::{Animated, AnimationPlayerLink, Animations, BlueprintName, BlueprintsList};
pub use in_game::*;
use bevy::{
@ -29,7 +29,7 @@ fn validate_export(
children: Query<&Children>,
names: Query<&Name>,
blueprints: Query<(Entity, &Name, &BlueprintName)>,
animation_player_links: Query<(Entity, &BlueprintAnimationPlayerLink)>,
animation_player_links: Query<(Entity, &AnimationPlayerLink)>,
empties_candidates: Query<(Entity, &Name, &GlobalTransform)>,
blueprints_list: Query<(Entity, &BlueprintsList)>,
@ -138,23 +138,22 @@ fn setup_main_scene_animations(
commands.insert_resource(AnimTest(asset_server.load("models/World.glb")));
}
fn animations(
added_animation_players:Query<(Entity, &Name, &AnimationPlayer)>,
addded_animateds:Query<(Entity, &Name, &Animated),(Added<Animated>)>,
animtest: Res<AnimTest>,
foo:Query<(Entity, &Name, &AnimationPlayer),(Added<AnimationPlayer>)>,
bla:Query<(Entity, &Name, &Animated),(Added<Animated>, Without<AnimationPlayerLink>)>,
blurp: Res<AnimTest>,
asset_server: Res<AssetServer>,
mut commands: Commands,
assets_gltf: Res<Assets<Gltf>>,
parents: Query<&Parent>,
names: Query<&Name>,
) {
for (entity, name, animated) in addded_animateds.iter() {
for (entity, name, animated) in bla.iter() {
// println!("animated stuf {:?} on entity {}", animated, name);
let gltf = assets_gltf.get(&animtest.0).unwrap();
let gltf = assets_gltf.get(&blurp.0).unwrap();
let animations_list = animated;
let mut matching_data = true;
@ -167,180 +166,43 @@ fn animations(
if matching_data {
println!("inserting Animations components into {} ({:?})", name, entity);
println!("Found match {:?}", gltf.named_animations);
// commands.entity(entity).remove::<Animations>();
// FIXME: for some reason this does NOT overwrite the component ??
commands.entity(entity).insert(
InstanceAnimations {
named_animations: gltf.named_animations.clone(),
},
);
//animations.named_animations = gltf.named_animations.clone();
for ancestor in parents.iter_ancestors(entity) {
if added_animation_players.contains(ancestor) {
println!("found match with animationPlayer !! {:?}",names.get(ancestor));
commands.entity(entity).insert(InstanceAnimationPlayerLink(ancestor));
commands.entity(entity).remove::<Animations>();
commands.entity(entity).insert((
Animations {
named_animations: gltf.named_animations.clone()
}
// info!("{:?} is an ancestor of {:?}", ancestor, player);
));
}
}
/*for bla in foo.iter() {
let mut counter = 0;
counter +=1;
println!("found some animations {} {}", counter, bla.1);
if bla.1.to_string() == "Collection".to_string(){
/*commands.insert_resource(Animations(vec![
asset_server.load("models/World.glb#Animation0"),
asset_server.load("models/World.glb#Animation1"),
]));*/
/*commands.entity(bla.0).insert(Animations {
named_animations:
})*/
}
}*/
}
fn play_animations(
animated_marker1: Query<(&InstanceAnimationPlayerLink, &InstanceAnimations), (With<Animated>, With<Marker1>)>,
animated_marker2: Query<(&InstanceAnimationPlayerLink, &InstanceAnimations), (With<Animated>, With<Marker2>)>,
animated_marker3: Query<(&InstanceAnimationPlayerLink, &InstanceAnimations, &BlueprintAnimationPlayerLink, &BlueprintAnimations), (With<Animated>, With<Marker3>)>,
mut animation_players: Query<&mut AnimationPlayer>,
keycode: Res<ButtonInput<KeyCode>>,
) {
if keycode.just_pressed(KeyCode::KeyM) {
for (link, animations) in animated_marker1.iter() {
println!("animations {:?}", animations.named_animations);
let mut animation_player = animation_players.get_mut(link.0).unwrap();
let anim_name = "Blueprint1_move";
animation_player
.play_with_transition(
animations
.named_animations
.get(anim_name)
.expect("animation name should be in the list")
.clone(),
Duration::from_secs(5),
)
.repeat();
}
}
if keycode.just_pressed(KeyCode::KeyJ) {
for (link, animations) in animated_marker1.iter() {
println!("animations {:?}", animations.named_animations);
let mut animation_player = animation_players.get_mut(link.0).unwrap();
let anim_name = "Blueprint1_jump";
animation_player
.play_with_transition(
animations
.named_animations
.get(anim_name)
.expect("animation name should be in the list")
.clone(),
Duration::from_secs(5),
)
.repeat();
}
}
if keycode.just_pressed(KeyCode::KeyA) {
for (link, animations) in animated_marker2.iter() {
println!("animations {:?}", animations.named_animations);
let mut animation_player = animation_players.get_mut(link.0).unwrap();
let anim_name = "Blueprint1_move";
animation_player
.play_with_transition(
animations
.named_animations
.get(anim_name)
.expect("animation name should be in the list")
.clone(),
Duration::from_secs(5),
)
.repeat();
}
}
if keycode.just_pressed(KeyCode::KeyB) {
for (link, animations) in animated_marker2.iter() {
println!("animations {:?}", animations.named_animations);
let mut animation_player = animation_players.get_mut(link.0).unwrap();
let anim_name = "Blueprint1_jump";
animation_player
.play_with_transition(
animations
.named_animations
.get(anim_name)
.expect("animation name should be in the list")
.clone(),
Duration::from_secs(5),
)
.repeat();
}
}
// play instance animation
if keycode.just_pressed(KeyCode::KeyW) {
for (link, animations, _, _) in animated_marker3.iter() {
println!("animations {:?}", animations.named_animations);
let mut animation_player = animation_players.get_mut(link.0).unwrap();
let anim_name = "Blueprint8_move";
animation_player
.play_with_transition(
animations
.named_animations
.get(anim_name)
.expect("animation name should be in the list")
.clone(),
Duration::from_secs(5),
)
.repeat();
}
}
// play blueprint animation
if keycode.just_pressed(KeyCode::KeyX) {
for (_, _, link, animations) in animated_marker3.iter() {
println!("animations {:?}", animations.named_animations);
let mut animation_player = animation_players.get_mut(link.0).unwrap();
let anim_name = "Walk";
animation_player
.play_with_transition(
animations
.named_animations
.get(anim_name)
.expect("animation name should be in the list")
.clone(),
Duration::from_secs(5),
)
.repeat();
}
}
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// flag component for testing
pub struct Marker1;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// flag component for testing
pub struct Marker2;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// flag component for testing
pub struct Marker3;
pub struct GamePlugin;
impl Plugin for GamePlugin {
fn build(&self, app: &mut App) {
app.register_type::<Marker1>()
.register_type::<Marker2>()
.register_type::<Marker3>()
.add_systems(Update, (spawn_test).run_if(in_state(GameState::InGame)))
app.add_systems(Update, (spawn_test).run_if(in_state(GameState::InGame)))
.add_systems(Update, validate_export)
.add_systems(OnEnter(AppState::MenuRunning), start_game)
.add_systems(OnEnter(AppState::AppRunning), setup_game)
.add_systems(OnEnter(AppState::MenuRunning), setup_main_scene_animations)
.add_systems(Update, animations
.run_if(in_state(AppState::AppRunning))
.after(GltfBlueprintsSet::AfterSpawn)
)
.add_systems(Update, play_animations)
.add_systems(Update, animations.run_if(in_state(AppState::AppRunning)))
/* .add_systems(Update, generate_screenshot.run_if(on_timer(Duration::from_secs_f32(0.2)))) // TODO: run once
.add_systems(
Update,