diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 04:58:15 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 04:58:15 +0300 |
| commit | 4e4a0795fccbcc4a2dd2f4b51c8f8f7802812791 (patch) | |
| tree | 3cd67b59d94feb1fd1515be4f0c69134a86a6cde /apps/fparkan-game/src/chassis_animation.rs | |
| parent | 531753ef5fbfa846b4291864458f511d5c7e1b59 (diff) | |
| download | fparkan-4e4a0795fccbcc4a2dd2f4b51c8f8f7802812791.tar.xz fparkan-4e4a0795fccbcc4a2dd2f4b51c8f8f7802812791.zip | |
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.
Diffstat (limited to 'apps/fparkan-game/src/chassis_animation.rs')
| -rw-r--r-- | apps/fparkan-game/src/chassis_animation.rs | 74 |
1 files changed, 74 insertions, 0 deletions
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<f32>], +) -> 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 +} |
