Package toxi.geom.mesh
Class Terrain
java.lang.Object
toxi.geom.mesh.Terrain
Implementation of a 2D grid based heightfield with basic intersection
features and conversion to
TriangleMesh
. The terrain is always
located in the XZ plane with the positive Y axis as up vector.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclear()
int
getDepth()
float[]
float
getHeightAtCell
(int x, int z) float
getHeightAtPoint
(float x, float z) Computes the elevation of the terrain at the given 2D world coordinate (based on current terrain scale).getScale()
int
getWidth()
intersectAtPoint
(float x, float z) Computes the 3D position (with elevation) and normal vector at the given 2D location in the terrain.setElevation
(float[] elevation) Sets the elevation of all cells to those of the given array values.setHeightAtCell
(int x, int z, float h) Sets the elevation for a single given grid cell.void
setScale
(float scale) void
toMesh()
toMesh
(float groundLevel) Creates aTriangleMesh
instance of the terrain surface or adds its geometry to an existing mesh.Creates aTriangleMesh
instance of the terrain and constructs side panels and a bottom plane to form a fully enclosed mesh volume, e.g.
-
Constructor Details
-
Terrain
public Terrain(int width, int depth, float scale) Constructs a new and initially flat terrain of the given size in the XZ plane, centred around the world origin.- Parameters:
width
-depth
-scale
-
-
Terrain
-
-
Method Details
-
clear
-
getDepth
public int getDepth()- Returns:
- number of grid cells along the Z axis.
-
getElevation
public float[] getElevation() -
getHeightAtCell
public float getHeightAtCell(int x, int z) - Parameters:
x
-z
-- Returns:
- the elevation at grid point
-
getHeightAtPoint
public float getHeightAtPoint(float x, float z) Computes the elevation of the terrain at the given 2D world coordinate (based on current terrain scale).- Parameters:
x
- scaled world coord xz
- scaled world coord z- Returns:
- interpolated elevation
-
getScale
- Returns:
- the scale
-
getWidth
public int getWidth()- Returns:
- number of grid cells along the X axis.
-
intersectAtPoint
Computes the 3D position (with elevation) and normal vector at the given 2D location in the terrain. The position is in scaled world coordinates based on the given terrain scale. The returned data is encapsulated in aIsectData3D
instance.- Parameters:
x
-z
-- Returns:
- intersection data parcel
-
setElevation
Sets the elevation of all cells to those of the given array values.- Parameters:
elevation
- array of height values- Returns:
- itself
-
setHeightAtCell
Sets the elevation for a single given grid cell.- Parameters:
x
-z
-h
- new elevation value- Returns:
- itself
-
setScale
public void setScale(float scale) -
setScale
- Parameters:
scale
- the scale to set
-
toMesh
-
toMesh
-
toMesh
Creates aTriangleMesh
instance of the terrain surface or adds its geometry to an existing mesh.- Parameters:
mesh
-- Returns:
- mesh instance
-
toMesh
Creates aTriangleMesh
instance of the terrain and constructs side panels and a bottom plane to form a fully enclosed mesh volume, e.g. suitable for CNC fabrication or 3D printing. The bottom plane will be created at the given ground level (can also be negative) and the sides are extended downward to that level too.- Parameters:
mesh
- existing mesh or nullgroundLevel
-- Returns:
- mesh
-
toMesh
-
toMesh
-
updateElevation
-