From 8ac6a11100cfe41a8a139f9b6d19c4e82a3bf1c5 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 18 Jul 2026 10:21:43 +0400 Subject: feat(render): compose terrain with preview root --- crates/fparkan-terrain/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'crates/fparkan-terrain/src/lib.rs') diff --git a/crates/fparkan-terrain/src/lib.rs b/crates/fparkan-terrain/src/lib.rs index 63ee3ca..d539577 100644 --- a/crates/fparkan-terrain/src/lib.rs +++ b/crates/fparkan-terrain/src/lib.rs @@ -30,6 +30,7 @@ pub struct TerrainWorld { grid: RuntimeGrid, adjacency: Vec>, surfaces: Vec, + source_mesh: Option, } /// Surface hit. @@ -232,6 +233,7 @@ impl TerrainWorld { grid, adjacency, surfaces: Vec::new(), + source_mesh: None, }) } @@ -244,6 +246,7 @@ impl TerrainWorld { pub fn from_land_msh(mesh: &LandMeshDocument) -> Result { Ok(Self { surfaces: build_surfaces(mesh)?, + source_mesh: Some(mesh.clone()), ..Self::default() }) } @@ -260,6 +263,7 @@ impl TerrainWorld { ) -> Result { let mut world = Self::from_land_map(map)?; world.surfaces = build_surfaces(mesh)?; + world.source_mesh = Some(mesh.clone()); Ok(world) } @@ -275,6 +279,24 @@ impl TerrainWorld { self.surfaces.len() } + /// Returns the validated source mesh retained for renderer integration. + /// + /// Runtime collision queries use their own compact triangle representation; + /// keeping this document preserves the original geometry and UV streams for + /// rendering without asking the application layer to decode an archive again. + #[must_use] + pub fn source_mesh(&self) -> Option<&LandMeshDocument> { + self.source_mesh.as_ref() + } + + /// Returns source terrain positions without exposing parser ownership to apps. + #[must_use] + pub fn source_positions(&self) -> Option<&[[f32; 3]]> { + self.source_mesh + .as_ref() + .map(|mesh| mesh.positions.as_slice()) + } + fn locate_by_candidates( &self, position: [f32; 3], -- cgit v1.2.3