fix character animation loading and flickering
This commit is contained in:
Binary file not shown.
@@ -12,6 +12,9 @@ pub struct ProjectileOrigin;
|
|||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct AnimatedCharacter(pub usize);
|
pub struct AnimatedCharacter(pub usize);
|
||||||
|
|
||||||
|
#[derive(Component, Debug)]
|
||||||
|
struct AnimatedCharacterAsset(pub Handle<Gltf>);
|
||||||
|
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct CharacterHierarchy<'w, 's> {
|
pub struct CharacterHierarchy<'w, 's> {
|
||||||
descendants: Query<'w, 's, &'static Children>,
|
descendants: Query<'w, 's, &'static Children>,
|
||||||
@@ -49,12 +52,12 @@ pub fn plugin(app: &mut App) {
|
|||||||
|
|
||||||
fn spawn(
|
fn spawn(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut query: Query<(Entity, &AnimatedCharacter), Added<AnimatedCharacter>>,
|
query: Query<(Entity, &AnimatedCharacter), Added<AnimatedCharacter>>,
|
||||||
gltf_assets: Res<Assets<Gltf>>,
|
gltf_assets: Res<Assets<Gltf>>,
|
||||||
assets: Res<GameAssets>,
|
assets: Res<GameAssets>,
|
||||||
heads_db: Res<HeadsDatabase>,
|
heads_db: Res<HeadsDatabase>,
|
||||||
) {
|
) {
|
||||||
for (entity, character) in &mut query {
|
for (entity, character) in query.iter() {
|
||||||
let key = heads_db.head_key(character.0);
|
let key = heads_db.head_key(character.0);
|
||||||
|
|
||||||
let handle = assets
|
let handle = assets
|
||||||
@@ -72,6 +75,7 @@ fn spawn(
|
|||||||
.insert((
|
.insert((
|
||||||
Transform::from_translation(Vec3::new(0., -1.45, 0.)).with_scale(Vec3::splat(1.2)),
|
Transform::from_translation(Vec3::new(0., -1.45, 0.)).with_scale(Vec3::splat(1.2)),
|
||||||
SceneRoot(asset.scenes[0].clone()),
|
SceneRoot(asset.scenes[0].clone()),
|
||||||
|
AnimatedCharacterAsset(handle.clone()),
|
||||||
))
|
))
|
||||||
.observe(find_marker_bones);
|
.observe(find_marker_bones);
|
||||||
}
|
}
|
||||||
@@ -123,21 +127,20 @@ fn setup_once_loaded(
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut query: Query<(Entity, &mut AnimationPlayer), Added<AnimationPlayer>>,
|
mut query: Query<(Entity, &mut AnimationPlayer), Added<AnimationPlayer>>,
|
||||||
parent: Query<&ChildOf>,
|
parent: Query<&ChildOf>,
|
||||||
animated_character: Query<&AnimatedCharacter>,
|
animated_character: Query<(&AnimatedCharacter, &AnimatedCharacterAsset)>,
|
||||||
assets: Res<GameAssets>,
|
|
||||||
gltf_assets: Res<Assets<Gltf>>,
|
gltf_assets: Res<Assets<Gltf>>,
|
||||||
mut graphs: ResMut<Assets<AnimationGraph>>,
|
mut graphs: ResMut<Assets<AnimationGraph>>,
|
||||||
) {
|
) {
|
||||||
for (entity, mut player) in &mut query {
|
for (entity, mut player) in &mut query {
|
||||||
let Some(_animated_character) = parent
|
let Some((_character, asset)) = parent
|
||||||
.iter_ancestors(entity)
|
.iter_ancestors(entity)
|
||||||
.find_map(|ancestor| animated_character.get(ancestor).ok())
|
.find_map(|ancestor| animated_character.get(ancestor).ok())
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let (_, handle) = assets.characters.iter().next().unwrap();
|
let asset = gltf_assets.get(asset.0.id()).unwrap();
|
||||||
let asset = gltf_assets.get(handle).unwrap();
|
|
||||||
|
|
||||||
let animations = asset
|
let animations = asset
|
||||||
.named_animations
|
.named_animations
|
||||||
|
|||||||
Reference in New Issue
Block a user