From 4e4a0795fccbcc4a2dd2f4b51c8f8f7802812791 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 05:58:15 +0400 Subject: feat(movement): play authored walking cycles from chassis travel Select a closed forward stride from the model for explicit walking profiles. Drive it from world displacement and subtract baked forward travel before updating geometry, mounts and shadows. Verified light, medium and heavy stock model cycles and watched leg poses change from the normal AutoDemo start with Vulkan validation clean. Stop transitions and terrain-adaptive feet remain open. --- apps/fparkan-game/src/chassis_animation.rs | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 apps/fparkan-game/src/chassis_animation.rs (limited to 'apps/fparkan-game/src/chassis_animation.rs') diff --git a/apps/fparkan-game/src/chassis_animation.rs b/apps/fparkan-game/src/chassis_animation.rs new file mode 100644 index 00000000..77019b2c --- /dev/null +++ b/apps/fparkan-game/src/chassis_animation.rs @@ -0,0 +1,74 @@ +//! Binds locomotion playback to the existing mesh pose update. + +use super::{live_root_pose, ControlAnimationInstance, MissionRenderRoot, StaticPreviewScene}; +use fparkan_runtime::{loaded_mission_assets, loaded_walk_chassis, Engine, WalkAnimation}; +use fparkan_world::WorldSnapshot; +use std::collections::HashMap; + +pub(super) fn connect_walkers(engine: &Engine, scene: &mut StaticPreviewScene) { + let Some(assets) = loaded_mission_assets(engine) else { + return; + }; + let mut clips = HashMap::new(); + for (index, components) in scene.control_animation_instances.iter_mut().enumerate() { + if !loaded_walk_chassis(engine, index) { + continue; + } + let Some(root) = components.first_mut().and_then(Option::as_mut) else { + continue; + }; + if !root.control.bindings.is_empty() { + continue; + } + let Some(model_id) = assets + .visual_for_object(index) + .and_then(|id| assets.visual_by_id(id)) + .and_then(|visual| visual.model_id) + else { + continue; + }; + root.walk = clips + .entry(model_id) + .or_insert_with(|| WalkAnimation::prepare(&root.model)) + .clone(); + if root.walk.is_none() { + continue; + } + for geometry in scene.dynamic_component_geometry[index].iter_mut().flatten() { + geometry.animated = true; + } + for caster in scene + .dynamic_shadow_casters + .iter_mut() + .filter(|caster| caster.object_index == index) + { + caster.animated = true; + } + } +} + +pub(super) fn sample( + instance: &mut ControlAnimationInstance, + root: &MissionRenderRoot, + snapshot: &WorldSnapshot, + node_times: &mut [Option], +) -> bool { + if instance.wheels.is_none() && instance.walk.is_none() { + return false; + } + let Some(pose) = live_root_pose(root.handle, snapshot) else { + return false; + }; + if let Some(wheels) = &mut instance.wheels { + wheels.sample(root.handle, pose, node_times); + } + let Some(frame) = instance + .walk + .as_mut() + .and_then(|walk| walk.sample(root.handle, snapshot.tick, pose)) + else { + return false; + }; + node_times.fill(Some(frame)); + true +} -- cgit v1.2.3