From b0c3a064c29c2bf97981f45806696c2dd0d4dd90 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 07:24:01 +0400 Subject: 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. --- apps/fparkan-game/src/model_mounts.rs | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 apps/fparkan-game/src/model_mounts.rs (limited to 'apps/fparkan-game/src/model_mounts.rs') 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], + mounts: &[Option], + animation_frame: Option, +) -> Result, 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, + ))) +} -- cgit v1.2.3