@gov.nasa.jpl.honeycomb/terrain-rendering
v0.0.6
Published
Base class for implementing terrain visualization as meshes, points, or voxels.
Readme
terrain
Set of classes and materials to help with visualizing various terrain artifacts.
Use
TODO
API
RenderMode
POINTS
POINTS : 0Render the terrain as points.
MESH
MESH : 1Render the terrain as a mesh.
INSTANCE_POINTS
INSTANCE_POINTS : 2Render the terrain as instanced points.
Terrain
Terrain class for rendering geometry or set of data as a mesh, points, or voxels.
extends SwitchGroup
renderMode
renderMode : RenderModeAn alias for SwitchGroup.active
points
points : PointsReference to the child used for rendering Points.
mesh
mesh : MeshReference to the child used for rendering Mesh.
instancedPoints
instancedPoints : MeshReference to the child used for rendering Voxels.
constructor
constructor( geometry : BufferGeometry, baseShader : Shader = ShaderLib.phong ) : voidTakes the geometry and shader used to render the meshes.
update
update( ) : voidMust be called when the geometry changes or data affecting dynamic geometry has changed.
updateGeometry
updateGeometry( geometry : BufferGeometry ) : voidOverrideable function called when dynamic geometry msut be updated.
HeightMapTerrain
Height map base class that defines a plane that can be used for visualizing a height map.
extends Terrain
args
args : ...null_setGridDimensions
_setGridDimensions( geometry : BufferGeometry, width : Number, height : Number ) : BooleanEnsures the grid dimensions are set to the given values. If they are not a new plane geometry is created and the old one is discarded. Returns a boolean indicating whether or not the geometry was replaced.
Private function intended to be called internally when implementing Terrain.updateGeometry function.
StructuredPointCloudTerrain
TODO
extends HeightMapTerrain
pointCloudData
pointCloudData : null = nullcameraData
cameraData : null = nullzScale
zScale : null = 1cellWidth
cellWidth : null = 1material
material : null = nullRosPointCloudTerrain
TODO
extends Terrain
args
args : ...nullSwitchGroup
Class for toggling visibility of children based on an active flag.
extends Group
active
active : Number = 0The flag indicating which child is visible.
items
items : null = []SampledTerrain
Heightmap class that derives and updates the heightmap based on a Sampler2D object.
extends HeightMapTerrain
sampler
sampler : Sampler2DThe Sampler2D object to use when retriving values to position the Z component of the vertices.
resolution
resolution : Number = -1The sampling resolution to use when genering the number of vertices on each dimension of the heightmap. If set to - 1 then samples will be used to determine the number of verts.
For example 0.1 will sample the map ever 10 cm.
maxSamplesPerDimension
maxSamplesPerDimension : maxSamplesPerDimension = InfinityThe maximum number of samples per dimension of the heightmap. Useful for ensuring the heightmap does not consume too much memory or take too much time to update.
samples
samples : samples = (0, 0)The number of vertices to generate on X and Y of the heightmap. Only used if
#SampledTerrain#resolution is set to -1.
channel
channel : channel = 0The channel from the Sampler2D to use for the height value.
sampleInWorldFrame
sampleInWorldFrame : sampleInWorldFrame = trueWhether or not to use the Sampler2D.spatialSampleChannel function when sampling
the heightmap. Useful for sampling a heightmap that has a spatial offset or sampling
a sub portion of the map.
sampleMatrix
sampleMatrix : sampleMatrix3x3 2D transform matrix for transforming the positon of the xy sample positions. Useful for generating a heightmap that is offset from the origin.
args
args : ...nullgetBoundsRotation
getBoundsRotation( ) : NumberReturns the rotation of the heightmap based on the #SampledTerrain#sampleMatrix.
getBoundsCenter
getBoundsCenter( target : Vector2 ) : voidReturns the center of the heightmap in target based on the #SampledTerrain#sampleMatrix.
getBoundsSize
getBoundsSize( target : Vector2 ) : voidReturns the size of the heightmap in target based on the #SampledTerrain#sampleMatrix.
setBounds
setBounds(
minX : Number,
minY : Number,
maxX : Number,
maxY : Number,
rotation : Number = 0
) : voidSets the bounds of the heightmap patch to generate.
convertToSampleWorldFrame
convertToSampleWorldFrame( ) : voidSets the #SampledTerrain#sampleInWorldFrame field to true and adjusts #SampledTerrain#sampler inverseMatrix so the terrain is sampled in world frame but is visually unchanged.
Other
Generating wNormalMatrix
From the THREEjs Docs, the normal matrix is the "inverse transpose of modelViewMatrix":
const scene = ...;
const material = ...;
const mesh = ...;
// ensure the world matrix is up to date
scene.add(mesh);
mesh.updateMatrixWorld(true);
// generate the normal matrix
material
.wNormalMatrix
.copy(mesh.matrixWorld).invert()
.transpose();