Fix bone resampling breaking hitbox interpolation.
CI / build-and-test (pull_request) Successful in 1m59s
CI / production-build (pull_request) Successful in 11m13s

This commit is contained in:
2026-09-27 13:54:28 +02:00
parent 6f1d8a7706
commit 42ff80e55e
3 changed files with 132 additions and 25 deletions
+26 -1
View File
@@ -8,7 +8,7 @@ pub use crate::math::fixed_transform::FixedMat4;
pub use asset_baking::{BakedAnimationAssetProcessingPlugin, BakedAnimationPlugin}; pub use asset_baking::{BakedAnimationAssetProcessingPlugin, BakedAnimationPlugin};
pub use runtime::{ pub use runtime::{
BakedAnimationClip, BakedFighterAnimations, FighterBoneIndexMap, FighterBoneMatrices, BakedAnimationClip, BakedFighterAnimations, FighterBoneIndexMap, FighterBoneMatrices,
update_fighter_bone_matrices, resample_fighter_bone_matrices, update_fighter_bone_matrices,
}; };
pub const BAKED_ANIMATION_FPS: u32 = 60; pub const BAKED_ANIMATION_FPS: u32 = 60;
@@ -275,6 +275,31 @@ mod tests {
assert_eq!(capacities, matrices.buffer_capacities()); assert_eq!(capacities, matrices.buffer_capacities());
} }
#[test]
fn same_frame_resample_preserves_previous_gameplay_pose() {
let names = ["root".into()];
let parents = [None];
let mut pose_a = FixedMat4::IDENTITY;
pose_a.translate(FGVec3::lit("1", "0", "0"));
let mut pose_b = FixedMat4::IDENTITY;
pose_b.translate(FGVec3::lit("2", "0", "0"));
let mut snapped_pose = FixedMat4::IDENTITY;
snapped_pose.translate(FGVec3::lit("3", "0", "0"));
let mut matrices = FighterBoneMatrices::default();
matrices.set_pose(AnimKind::Wait, &names, &parents, &[pose_a], FGi32::ONE);
matrices.set_pose(AnimKind::Wait, &names, &parents, &[pose_b], FGi32::ONE);
matrices.resample_pose(
AnimKind::Landing,
&names,
&parents,
&[snapped_pose],
FGi32::ONE,
);
assert_eq!(matrices.get_index(0), Some((pose_a, snapped_pose)));
}
#[test] #[test]
fn model_scale_affects_gameplay_bones_without_changing_visual_locals() { fn model_scale_affects_gameplay_bones_without_changing_visual_locals() {
let mut root = FixedMat4::IDENTITY; let mut root = FixedMat4::IDENTITY;
+84 -2
View File
@@ -144,6 +144,27 @@ impl FighterBoneMatrices {
parents: &[Option<usize>], parents: &[Option<usize>],
local: &[FixedMat4], local: &[FixedMat4],
model_scale: FGi32, model_scale: FGi32,
) {
self.sample_pose(kind, bone_names, parents, local, model_scale, true);
}
pub(super) fn resample_pose(
&mut self,
kind: AnimKind,
bone_names: &[String],
parents: &[Option<usize>],
local: &[FixedMat4],
model_scale: FGi32,
) {
self.sample_pose(kind, bone_names, parents, local, model_scale, false);
}
fn sample_pose(
&mut self,
kind: AnimKind,
bone_names: &[String],
parents: &[Option<usize>],
local: &[FixedMat4],
model_scale: FGi32,
advance_history: bool,
) { ) {
assert_eq!( assert_eq!(
bone_names.len(), bone_names.len(),
@@ -167,9 +188,11 @@ impl FighterBoneMatrices {
self.local_matrices.reserve(local.len()); self.local_matrices.reserve(local.len());
self.previous_local_matrices.reserve(local.len()); self.previous_local_matrices.reserve(local.len());
self.model_matrices.reserve(local.len()); self.model_matrices.reserve(local.len());
if advance_history {
std::mem::swap(&mut self.matrices, &mut self.previous_frame_matrices); std::mem::swap(&mut self.matrices, &mut self.previous_frame_matrices);
let animation_changed = self.presentation_kind != Some(kind);
std::mem::swap(&mut self.local_matrices, &mut self.previous_local_matrices); std::mem::swap(&mut self.local_matrices, &mut self.previous_local_matrices);
}
let animation_changed = self.presentation_kind != Some(kind);
self.local_matrices.clear(); self.local_matrices.clear();
self.local_matrices.extend_from_slice(local); self.local_matrices.extend_from_slice(local);
self.model_matrices.resize(local.len(), None); self.model_matrices.resize(local.len(), None);
@@ -215,6 +238,56 @@ pub fn update_fighter_bone_matrices(
manifests: Res<Assets<FighterManifest>>, manifests: Res<Assets<FighterManifest>>,
) { ) {
for (frame, animations, fighter, mut matrices, mut bone_indices) in &mut fighters { for (frame, animations, fighter, mut matrices, mut bone_indices) in &mut fighters {
sample_fighter_bone_matrices(
frame,
animations,
fighter,
&mut matrices,
&mut bone_indices,
&baked_assets,
&manifests,
true,
);
}
}
/// Resamples the current pose after collision-driven state transitions without
/// advancing the previous-frame pose used for swept gameplay volumes.
pub fn resample_fighter_bone_matrices(
mut fighters: Query<(
&FighterAnimationFrame,
&FighterAnimations,
&Fighter,
&mut FighterBoneMatrices,
&mut FighterBoneIndexMap,
)>,
baked_assets: Res<Assets<BakedFighterAnimations>>,
manifests: Res<Assets<FighterManifest>>,
) {
for (frame, animations, fighter, mut matrices, mut bone_indices) in &mut fighters {
sample_fighter_bone_matrices(
frame,
animations,
fighter,
&mut matrices,
&mut bone_indices,
&baked_assets,
&manifests,
false,
);
}
}
fn sample_fighter_bone_matrices(
frame: &FighterAnimationFrame,
animations: &FighterAnimations,
fighter: &Fighter,
matrices: &mut FighterBoneMatrices,
bone_indices: &mut FighterBoneIndexMap,
baked_assets: &Assets<BakedFighterAnimations>,
manifests: &Assets<FighterManifest>,
advance_history: bool,
) {
let baked = baked_assets let baked = baked_assets
.get(&animations.baked) .get(&animations.baked)
.expect("fighter baked animation asset should be loaded before the match starts"); .expect("fighter baked animation asset should be loaded before the match starts");
@@ -228,6 +301,7 @@ pub fn update_fighter_bone_matrices(
let manifest = manifests let manifest = manifests
.get(&fighter.manifest) .get(&fighter.manifest)
.expect("fighter manifest should be loaded before the match starts"); .expect("fighter manifest should be loaded before the match starts");
if advance_history {
matrices.set_pose( matrices.set_pose(
frame.kind, frame.kind,
&baked.bone_names, &baked.bone_names,
@@ -235,6 +309,15 @@ pub fn update_fighter_bone_matrices(
pose, pose,
manifest.model_scale, manifest.model_scale,
); );
} else {
matrices.resample_pose(
frame.kind,
&baked.bone_names,
&baked.parents,
pose,
manifest.model_scale,
);
}
if bone_indices.0.is_empty() { if bone_indices.0.is_empty() {
bone_indices.0.extend( bone_indices.0.extend(
baked baked
@@ -244,7 +327,6 @@ pub fn update_fighter_bone_matrices(
.map(|(index, name)| (name.clone(), index)), .map(|(index, name)| (name.clone(), index)),
); );
} }
}
} }
fn resolve_model_transform( fn resolve_model_transform(
+1 -1
View File
@@ -183,7 +183,7 @@ impl Plugin for FighterPlugin {
GgrsSchedule, GgrsSchedule,
( (
(blast_zones::apply_blast_zones, ecb::update_ecb, ecb::decrement_ecb_lockout, state::state_collision_interrupt_system).chain(), (blast_zones::apply_blast_zones, ecb::update_ecb, ecb::decrement_ecb_lockout, state::state_collision_interrupt_system).chain(),
baked_animation::update_fighter_bone_matrices, baked_animation::resample_fighter_bone_matrices,
) )
.chain() .chain()
.in_set(GameplaySet::Collision), .in_set(GameplaySet::Collision),