fix(camera): constrain free flight to terrain surface bounds
Docs Deploy / Build and Deploy MkDocs (push) Successful in 36s
Docs Deploy / Build and Deploy MkDocs (push) Successful in 36s
This commit is contained in:
4 files changed
+99
-4
No files matched your search
@@ -409,6 +409,13 @@ impl TerrainWorld {
|
||||
self.surfaces.len()
|
||||
}
|
||||
|
||||
/// Bounds of the indexed surface geometry, excluding unused source vertices.
|
||||
#[must_use]
|
||||
pub fn surface_bounds(&self) -> Option<[[f32; 3]; 2]> {
|
||||
let root = self.surface_bvh.nodes.get(self.surface_bvh.root?)?;
|
||||
Some([root.min, root.max])
|
||||
}
|
||||
|
||||
/// Returns the validated source mesh retained for renderer integration.
|
||||
///
|
||||
/// Runtime collision queries use their own compact triangle representation;
|
||||
@@ -1214,6 +1221,15 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn surface_bounds_cover_query_geometry_and_ignore_unused_positions() {
|
||||
let mut mesh = synthetic_land_mesh();
|
||||
mesh.positions.push([1000.0, -1000.0, 1000.0]);
|
||||
let world = TerrainWorld::from_land_msh(&mesh).expect("world");
|
||||
assert_eq!(world.surface_bounds(), Some([[0.0; 3], [1.0, 1.0, 2.0]]));
|
||||
assert_eq!(TerrainWorld::default().surface_bounds(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn synthetic_surface_height_and_raycast_work() {
|
||||
let world = TerrainWorld::from_land_msh(&synthetic_land_mesh()).expect("world");
|
||||
|
||||
Reference in new issue
Block a user