aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/model_mounts.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 06:24:01 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 06:24:01 +0300
commitb0c3a064c29c2bf97981f45806696c2dd0d4dd90 (patch)
treea677357a8519520a49cd4ccad3daa9cfde68d28e /apps/fparkan-game/src/model_mounts.rs
parent7b3a106ff7a376b95b3bb9e52d3186ebe1a9bcaa (diff)
downloadfparkan-b0c3a064c29c2bf97981f45806696c2dd0d4dd90.tar.xz
fparkan-b0c3a064c29c2bf97981f45806696c2dd0d4dd90.zip
feat(ui): preview new warbot geometry during a mission
On stock Field Camp, open a compatible Unit DAT created after start, resize the preview, switch to a resident project, reopen the new project, and return to the mission with Vulkan validation clean. The factory reserve for new geometry is still prepared at mission load.
Diffstat (limited to 'apps/fparkan-game/src/model_mounts.rs')
-rw-r--r--apps/fparkan-game/src/model_mounts.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/fparkan-game/src/model_mounts.rs b/apps/fparkan-game/src/model_mounts.rs
new file mode 100644
index 00000000..331e616a
--- /dev/null
+++ b/apps/fparkan-game/src/model_mounts.rs
@@ -0,0 +1,53 @@
+//! Initial AniMesh attachment transforms shared by placed and previewed units.
+
+use super::{
+ compose_unit_pose, node38_pose, node38_pose_from_hierarchy, node38_pose_relative_to_root,
+ node38_pose_relative_to_root_from_hierarchy, unit_component_is_visible, NodePoseBuffer,
+ PreparedModel, PreparedVisual, VulkanNodePose,
+};
+use fparkan_prototype::{UnitComponentRecord, UnitComponentTreeNode};
+
+pub(super) fn initial_mount(
+ index: usize,
+ records: &[UnitComponentRecord],
+ tree: &[UnitComponentTreeNode],
+ components: &[(&PreparedVisual, Option<&PreparedModel>)],
+ poses: &[Option<NodePoseBuffer>],
+ mounts: &[Option<VulkanNodePose>],
+ animation_frame: Option<u16>,
+) -> Result<Option<VulkanNodePose>, String> {
+ let Some(parent) = tree[index].parent_index else {
+ return Ok(None);
+ };
+ let Some((visual, model)) = components.get(parent) else {
+ return Ok(None);
+ };
+ if !unit_component_is_visible(parent, visual.source_type) {
+ return Ok(None);
+ }
+ let model = model.ok_or_else(|| {
+ format!("unit component {index} parent {parent} has no model for mount socket")
+ })?;
+ let link = records[index].parent_or_link;
+ let socket = usize::try_from(link)
+ .map_err(|_| format!("unit component {index} has negative mount socket {link}"))?;
+ let parent_mount = mounts[parent];
+ let parent_socket = match (poses[parent].as_ref(), parent_mount.is_some()) {
+ (Some(hierarchy), true) => node38_pose_relative_to_root_from_hierarchy(hierarchy, socket),
+ (Some(hierarchy), false) => node38_pose_from_hierarchy(hierarchy, socket),
+ (None, true) => node38_pose_relative_to_root(&model.validated, animation_frame, socket),
+ (None, false) => node38_pose(&model.validated, animation_frame, socket),
+ }.ok_or_else(|| {
+ format!(
+ "unit component {index} mount socket {socket} is absent from parent {parent} (parent source={:?}, node_count={}, slots={}, animation={})",
+ model.source, model.validated.node_count, model.validated.slots.len(), model.validated.animation.is_some()
+ )
+ })?;
+ Ok(Some(compose_unit_pose(
+ parent_mount.unwrap_or(VulkanNodePose {
+ translation: [0.0; 3],
+ rotation: [0.0, 0.0, 0.0, 1.0],
+ }),
+ parent_socket,
+ )))
+}