aboutsummaryrefslogtreecommitdiff
path: root/adapters/fparkan-render-vulkan
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-07-18 14:35:00 +0300
committerValentin Popov <valentin@popov.link>2026-07-18 14:35:00 +0300
commit2a793f1854231be6da930a3692dce691a6426211 (patch)
treefb0cefbdf2d8e2e3dbb883f8fd696b4d25c86a80 /adapters/fparkan-render-vulkan
parent468ecc4e325178c116f0de25f47736eaec2a1e15 (diff)
downloadfparkan-2a793f1854231be6da930a3692dce691a6426211.tar.xz
fparkan-2a793f1854231be6da930a3692dce691a6426211.zip
feat(render): apply recovered TMA orientation
Diffstat (limited to 'adapters/fparkan-render-vulkan')
-rw-r--r--adapters/fparkan-render-vulkan/src/asset_mesh.rs63
-rw-r--r--adapters/fparkan-render-vulkan/src/ffi.rs5
2 files changed, 59 insertions, 9 deletions
diff --git a/adapters/fparkan-render-vulkan/src/asset_mesh.rs b/adapters/fparkan-render-vulkan/src/asset_mesh.rs
index d74e79c..d92f76d 100644
--- a/adapters/fparkan-render-vulkan/src/asset_mesh.rs
+++ b/adapters/fparkan-render-vulkan/src/asset_mesh.rs
@@ -2,7 +2,7 @@
use crate::{VulkanStaticDrawRange, VulkanStaticMesh, VulkanStaticVertex};
use fparkan_msh::ModelAsset;
-use fparkan_render::LegacyPipelineState;
+use fparkan_render::{LegacyIron3dEulerTransform, LegacyPipelineState};
use fparkan_terrain_format::LandMeshDocument;
/// Error returned when a validated MSH cannot enter the current static GPU path.
@@ -185,8 +185,36 @@ pub fn project_msh_to_static_mesh_in_world_space(
translation: [f32; 3],
scale: [f32; 3],
) -> Result<VulkanStaticMesh, VulkanAssetMeshError> {
- if !translation
+ project_msh_to_static_mesh_in_world_space_with_transform(
+ model,
+ LegacyIron3dEulerTransform {
+ translation,
+ orientation_radians: [0.0; 3],
+ },
+ scale,
+ )
+}
+
+/// Projects MSH geometry using the recovered `Iron3D` placement transform.
+///
+/// This preserves source-world coordinates and applies the proven
+/// `Rz(z) * Ry(y) * Rx(x)` rotation after local component-wise scale. It is
+/// intended for the opt-in legacy-camera static preview, not yet for animated
+/// or gameplay-owned transforms.
+///
+/// # Errors
+///
+/// Returns [`VulkanAssetMeshError`] when geometry or transform values cannot
+/// be represented by the static Vulkan input contract.
+pub fn project_msh_to_static_mesh_in_world_space_with_transform(
+ model: &ModelAsset,
+ transform: LegacyIron3dEulerTransform,
+ scale: [f32; 3],
+) -> Result<VulkanStaticMesh, VulkanAssetMeshError> {
+ if !transform
+ .translation
.iter()
+ .chain(transform.orientation_radians.iter())
.chain(scale.iter())
.all(|value| value.is_finite())
{
@@ -201,11 +229,9 @@ pub fn project_msh_to_static_mesh_in_world_space(
if !position.iter().all(|value| value.is_finite()) {
return Err(VulkanAssetMeshError::NonFinitePosition);
}
- let position = [
- position[0] * scale[0] + translation[0],
- position[1] * scale[1] + translation[1],
- position[2] * scale[2] + translation[2],
- ];
+ let position = transform
+ .try_transform_scaled_point(*position, scale)
+ .ok_or(VulkanAssetMeshError::NonFinitePosition)?;
Ok(VulkanStaticVertex {
position,
color: [0.82, 0.72, 0.31],
@@ -553,6 +579,29 @@ mod tests {
}
#[test]
+ fn world_space_msh_applies_recovered_iron3d_orientation_after_scale() {
+ let source = model(
+ vec![[2.0, 3.0, 4.0], [0.0, 0.0, 0.0], [1.0, 0.0, 0.0]],
+ vec![0, 1, 2],
+ vec![batch(0, 3, 0)],
+ );
+
+ let mesh = project_msh_to_static_mesh_in_world_space_with_transform(
+ &source,
+ LegacyIron3dEulerTransform {
+ translation: [10.0, 20.0, 30.0],
+ orientation_radians: [0.0, 0.0, std::f32::consts::FRAC_PI_2],
+ },
+ [2.0, 1.0, 0.5],
+ )
+ .expect("finite recovered transform");
+
+ assert_eq!(mesh.vertices[0].position, [7.0, 24.0, 32.0]);
+ assert_eq!(mesh.vertices[1].position, [10.0, 20.0, 30.0]);
+ assert_eq!(mesh.vertices[2].position, [10.0, 22.0, 30.0]);
+ }
+
+ #[test]
fn retains_each_source_batch_material_selector() {
let mut second = batch(3, 3, 0);
second.material_index = 7;
diff --git a/adapters/fparkan-render-vulkan/src/ffi.rs b/adapters/fparkan-render-vulkan/src/ffi.rs
index 4d2b63e..4c4bfe6 100644
--- a/adapters/fparkan-render-vulkan/src/ffi.rs
+++ b/adapters/fparkan-render-vulkan/src/ffi.rs
@@ -42,8 +42,9 @@ mod validation;
pub use self::asset_mesh::{
project_land_msh_to_static_mesh, project_land_msh_to_static_mesh_in_world_space,
project_land_msh_to_static_mesh_in_xy_frame, project_msh_to_static_mesh,
- project_msh_to_static_mesh_in_world_space, project_msh_to_static_mesh_in_xy_frame,
- VulkanAssetMeshError, VulkanStaticXyFrame,
+ project_msh_to_static_mesh_in_world_space,
+ project_msh_to_static_mesh_in_world_space_with_transform,
+ project_msh_to_static_mesh_in_xy_frame, VulkanAssetMeshError, VulkanStaticXyFrame,
};
pub use self::capabilities::{
probe_vulkan_runtime_capabilities, probe_vulkan_runtime_capabilities_for_request,