From 2f75b9792c98c4d32b0349810080dd226357b505 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 09:42:38 +0400 Subject: feat(render): throw detached chassis nodes as fragments Pass the depleted node to an authored Op10 with a built-in mesh request. Reuse its existing draw ranges for the flight and keep the hull alive. The fixed-camera fixture shows the heavy track section separate and rotate after impact. --- crates/fparkan-runtime/src/destruction.rs | 47 +++++++++++++++++++++++++++---- crates/fparkan-runtime/src/lib.rs | 2 +- crates/fparkan-runtime/src/projectile.rs | 7 +++-- crates/fparkan-runtime/src/unit_combat.rs | 5 ++-- 4 files changed, 49 insertions(+), 12 deletions(-) (limited to 'crates/fparkan-runtime') diff --git a/crates/fparkan-runtime/src/destruction.rs b/crates/fparkan-runtime/src/destruction.rs index 8fb3a1bf..7ed316da 100644 --- a/crates/fparkan-runtime/src/destruction.rs +++ b/crates/fparkan-runtime/src/destruction.rs @@ -6,10 +6,28 @@ use crate::{ }; use fparkan_world::{identity_metadata, transform_state}; +/// Geometry supplied by the destroyed object to its authored explosion. +pub enum DestroyedMesh { + /// Mounted models after the loss of the whole chassis. + Mounted { + /// Prepared actor index. + object_index: usize, + }, + /// One separated node of a still live chassis. + ChassisNode { + /// Prepared actor index. + object_index: usize, + /// Local node of the root model. + node: usize, + /// World position of the hull at impact. + hull_origin: [f32; 3], + }, +} + /// Position and attached EXPL resource of a destroyed chassis or building part. pub struct UnitDestructionEffect { - /// Prepared draft index for the destroyed actor when it has an authored layout. - pub object_index: Option, + /// Prepared mesh to move when the effect requests built-in fragments. + pub mesh: Option, /// World-space origin of the effect. pub position: [f32; 3], /// Archive containing the explosion description. @@ -67,13 +85,30 @@ pub fn unit_destruction_effect_sources( } pub(super) fn part_effect( + engine: &Engine, row: &MissionControlNodeProviderRow, - position: [f32; 3], + contact: super::ProjectileContact, ) -> Option { let (archive, name) = node_effect(row)?; + let mesh = match contact.node { + Some(super::ProjectileNode::Chassis(node)) + if row.current_flags.is_some_and(|flags| flags & 2 == 0) => + { + let id = identity_metadata(&engine.world, contact.handle) + .ok()? + .original_id?; + let hull = transform_state(&engine.world, contact.handle).ok()?; + Some(DestroyedMesh::ChassisNode { + object_index: id.0 as usize, + node: node as usize, + hull_origin: hull.position.map(f32::from_bits), + }) + } + _ => None, + }; Some(UnitDestructionEffect { - object_index: None, - position, + mesh, + position: contact.position, archive, name, }) @@ -104,7 +139,7 @@ pub(super) fn pending_effect( .position .map(f32::from_bits); Some(UnitDestructionEffect { - object_index, + mesh: object_index.map(|object_index| DestroyedMesh::Mounted { object_index }), position, archive, name, diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 20613c00..1fcb00ae 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -80,7 +80,7 @@ pub use debris_motion::DebrisMotion; mod destruction; pub use destruction::{ collect_unit_destruction_effects, take_unit_destruction_effects, - unit_destruction_effect_sources, UnitDestructionEffect, + unit_destruction_effect_sources, DestroyedMesh, UnitDestructionEffect, }; mod flight_altitude; mod ground_support; diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs index 70c9ab77..d4f23243 100644 --- a/crates/fparkan-runtime/src/projectile.rs +++ b/crates/fparkan-runtime/src/projectile.rs @@ -313,7 +313,7 @@ pub fn apply_projectile_contact( } // shortcut: feed the projectile NDP volume into the native reduction while impact falloff is open. let effect = (volume >= remaining && engine.destruction_effects.is_some()) - .then(|| super::destruction::part_effect(row, contact.position)) + .then(|| super::destruction::part_effect(engine, row, contact)) .flatten(); let updated = apply_loaded_mission_control_node_delta(engine, contact.handle, key, -volume)?; if updated.is_some() { @@ -465,6 +465,9 @@ mod tests { let effects = take_unit_destruction_effects(&mut engine); assert_eq!(effects.len(), 1); assert_eq!(effects[0].position, contact.position); + assert!( + matches!(effects[0].mesh, Some(crate::DestroyedMesh::ChassisNode { object_index: 14, node: key, .. }) if key == node as usize) + ); } #[test] @@ -515,7 +518,7 @@ mod tests { panic!("expected one EXPL at the failed part"); }; assert_eq!(effect.position, contact.position); - assert_eq!(effect.object_index, None); + assert!(effect.mesh.is_none()); assert_eq!(effect.name, "explode_frt_b.exp"); assert!(unit_destruction_effect_sources(&engine) .any(|source| source == (effect.archive.clone(), effect.name.clone()))); diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs index eaab747a..593570cf 100644 --- a/crates/fparkan-runtime/src/unit_combat.rs +++ b/crates/fparkan-runtime/src/unit_combat.rs @@ -911,9 +911,8 @@ mod tests { assert!(destruction_effects.iter().any(|event| { event.archive == "system.rlb" && event.name == "explode_rbr_b.exp" - && event.object_index.is_some_and(|index| { - drafts[index].original_id.map(|id| id.0) == retired.original_id - }) + && matches!(event.mesh, Some(crate::DestroyedMesh::Mounted { object_index }) + if drafts[object_index].original_id.map(|id| id.0) == retired.original_id) && event .position .iter() -- cgit v1.2.3