aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-terrain/src/lib.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-07-18 09:21:43 +0300
committerValentin Popov <valentin@popov.link>2026-07-18 09:21:43 +0300
commit8ac6a11100cfe41a8a139f9b6d19c4e82a3bf1c5 (patch)
tree6243ceed21daa0d68dbd1a50932a63cbb094d5b3 /crates/fparkan-terrain/src/lib.rs
parent46851518fe1fde39d81ad4cf6805aa404f05016c (diff)
downloadfparkan-8ac6a11100cfe41a8a139f9b6d19c4e82a3bf1c5.tar.xz
fparkan-8ac6a11100cfe41a8a139f9b6d19c4e82a3bf1c5.zip
feat(render): compose terrain with preview root
Diffstat (limited to 'crates/fparkan-terrain/src/lib.rs')
-rw-r--r--crates/fparkan-terrain/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
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<Vec<ArealId>>,
surfaces: Vec<RuntimeTriangle>,
+ source_mesh: Option<LandMeshDocument>,
}
/// 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<Self, TerrainError> {
Ok(Self {
surfaces: build_surfaces(mesh)?,
+ source_mesh: Some(mesh.clone()),
..Self::default()
})
}
@@ -260,6 +263,7 @@ impl TerrainWorld {
) -> Result<Self, TerrainError> {
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],