pub struct HeightFieldSurface {
pub noise: NoiseSource,
pub origin: Vec2,
pub size: Vec2,
pub resolution_x: usize,
pub resolution_z: usize,
pub heights: Vec<f32>,
pub time: f32,
pub animations: Vec<HeightFieldAnimation>,
}Expand description
A height field surface driven by a noise source.
The surface occupies a rectangular region in XZ-space. Each grid cell stores a height value (Y coordinate). Heights are lazily generated from the noise source.
Fields§
§noise: NoiseSourceThe noise source generating heights.
origin: Vec2World-space origin (bottom-left corner of the heightfield in XZ).
size: Vec2World-space size of the heightfield in XZ.
resolution_x: usizeNumber of samples along X.
resolution_z: usizeNumber of samples along Z.
heights: Vec<f32>Computed height values. Row-major: heights[z * resolution_x + x].
time: f32Time parameter for animated deformations.
animations: Vec<HeightFieldAnimation>Animation modes applied to the surface.
Implementations§
Source§impl HeightFieldSurface
impl HeightFieldSurface
Sourcepub fn new(
noise: NoiseSource,
origin: Vec2,
size: Vec2,
resolution_x: usize,
resolution_z: usize,
) -> Self
pub fn new( noise: NoiseSource, origin: Vec2, size: Vec2, resolution_x: usize, resolution_z: usize, ) -> Self
Create a new height field surface.
Sourcepub fn regenerate(&mut self)
pub fn regenerate(&mut self)
Regenerate all height values from the noise source.
Sourcepub fn height_at_index(&self, ix: usize, iz: usize) -> f32
pub fn height_at_index(&self, ix: usize, iz: usize) -> f32
Get the height at grid indices (ix, iz).
Sourcepub fn set_height(&mut self, ix: usize, iz: usize, h: f32)
pub fn set_height(&mut self, ix: usize, iz: usize, h: f32)
Set the height at grid indices (ix, iz).
Sourcepub fn sample_height(&self, x: f32, z: f32) -> f32
pub fn sample_height(&self, x: f32, z: f32) -> f32
Sample height at world-space (x, z) using bilinear interpolation.
Sourcepub fn normal_at(&self, x: f32, z: f32) -> Vec3
pub fn normal_at(&self, x: f32, z: f32) -> Vec3
Compute the surface normal at world-space (x, z) using central differences.
Sourcepub fn normal_at_index(&self, ix: usize, iz: usize) -> Vec3
pub fn normal_at_index(&self, ix: usize, iz: usize) -> Vec3
Compute the normal at grid index using central differences.
Sourcepub fn deform_brush(&mut self, cx: f32, cz: f32, radius: f32, strength: f32)
pub fn deform_brush(&mut self, cx: f32, cz: f32, radius: f32, strength: f32)
Apply a deformation brush: raise or lower terrain in a radius around (cx, cz).
Sourcepub fn flatten_brush(
&mut self,
cx: f32,
cz: f32,
radius: f32,
target: f32,
strength: f32,
)
pub fn flatten_brush( &mut self, cx: f32, cz: f32, radius: f32, target: f32, strength: f32, )
Flatten terrain in a radius around (cx, cz) toward a target height.
Sourcepub fn world_position(&self, ix: usize, iz: usize) -> Vec3
pub fn world_position(&self, ix: usize, iz: usize) -> Vec3
Get the world-space position of a grid vertex.
Sourcepub fn bounding_box(&self) -> (Vec3, Vec3)
pub fn bounding_box(&self) -> (Vec3, Vec3)
Compute the bounding box: (min, max).
Sourcepub fn to_vertex_data(&self) -> (Vec<Vec3>, Vec<Vec3>)
pub fn to_vertex_data(&self) -> (Vec<Vec3>, Vec<Vec3>)
Export to a list of positions and normals (interleaved grid).
Sourcepub fn generate_indices(&self) -> Vec<[u32; 3]>
pub fn generate_indices(&self) -> Vec<[u32; 3]>
Generate triangle indices for the height field grid.
Sourcepub fn sample_noise(&self, x: f32, z: f32) -> f32
pub fn sample_noise(&self, x: f32, z: f32) -> f32
Sample height directly from noise (without grid interpolation).
Trait Implementations§
Source§impl Clone for HeightFieldSurface
impl Clone for HeightFieldSurface
Source§fn clone(&self) -> HeightFieldSurface
fn clone(&self) -> HeightFieldSurface
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for HeightFieldSurface
impl RefUnwindSafe for HeightFieldSurface
impl Send for HeightFieldSurface
impl Sync for HeightFieldSurface
impl Unpin for HeightFieldSurface
impl UnsafeUnpin for HeightFieldSurface
impl UnwindSafe for HeightFieldSurface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.