aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/chassis_animation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fparkan-game/src/chassis_animation.rs')
-rw-r--r--apps/fparkan-game/src/chassis_animation.rs74
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
+}