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