Support Forum       G3D Web Page     
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::HeightfieldModel Class Reference


A tiled regular heightfield with a single detail level, suitable for very large terrains observed mostly from above. More...

Inherits G3D::Model.

Classes

class  Specification
 
class  Tile
 

Public Member Functions

virtual const StringclassName () const override
 Name of the G3D::Model subclass. More...
 
float elevation (const Point3 &osPoint, Vector3 &faceNormal) const
 
Return the elevation (y value) under (osPoint.x, -, osPoint.z) according to the tessellation used for rendering (i.e., using barycentric interpolation on the triangles, not bilinear interpolation on the grid). More...
 
float elevation (const Point3 &osPoint) const
 
const shared_ptr< ImageelevationImage () const
 
const shared_ptr< TextureelevationTexture () const
 
virtual bool intersect (const Ray &ray, const CoordinateFrame &cframe, float &maxDistance, Model::HitInfo &info=Model::HitInfo::ignore, const Entity *entity=nullptr, const Model::Pose *pose=nullptr) const override
 Determines if the ray intersects the heightfield and fills the info with the proper information. More...
 
virtual const Stringname () const override
 Name of the instance (usually based on the filename it is loaded from) More...
 
void pose (Array< shared_ptr< Surface > > &surfaceArray, const CFrame &rootFrame, const CFrame &prevFrame, const shared_ptr< Entity > &entity, const Model::Pose *pose, const Model::Pose *prevPose, const Surface::ExpressiveLightScatteringProperties &e) override
 This will be replaced soon with a version that takes a shared_ptr<Pose>. More...
 
const Specificationspecification () const
 

Static Public Member Functions

static shared_ptr< HeightfieldModelcreate (const Specification &spec, const String &name="Heightfield")
 
static lazy_ptr< ModellazyCreate (const Specification &s, const String &name="")
 
static lazy_ptr< ModellazyCreate (const String &name, const Any &any)
 
static void setUseOptimizedIntersect (bool b)
 If true, complex models should use TriTree to accelerate intersect() calls where possible. More...
 
static bool useOptimizedIntersect ()
 

Protected Member Functions

 HeightfieldModel (const Specification &spec, const String &name)
 
void generateGeometry ()
 Called from the constructor. More...
 
void loadShaders ()
 Called from the constructor. More...
 
void setShaderArgs (Args &args) const
 This binds attribute arrays, so it cannot accept a UniformTable argument. More...
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

shared_ptr< Shaderm_depthAndColorShader
 Used for depth-only and wire-frame rendering. More...
 
shared_ptr< Texturem_elevation
 Elevation texture. More...
 
shared_ptr< Imagem_elevationImage
 Elevation image. More...
 
shared_ptr< Shaderm_gbufferShader
 
IndexStream m_indexStream
 Indices of the mesh. More...
 
shared_ptr< UniversalMaterialm_material
 
const String m_name
 
AttributeArray m_positionArray
 Shared vertex buffer for the entire mesh. More...
 
int m_quadsPerTileSide
 
shared_ptr< Shaderm_shader
 Used for all normal rendering. More...
 
const Specification m_specification
 

Detailed Description


A tiled regular heightfield with a single detail level, suitable for very large terrains observed mostly from above.

The geometry is procedurally generated in the vertex shader, so this requires much less memory and can therefore represent much larger heightfields than an ArticulatedModel (which can also generate a heightfield at load time from an image).

Restrictions of the current implementation:

To provide more interesting material properties that vary with elevation and angle, consider subclassing HeightfieldModel or making a similar class from its source code.

See also
ArticulatedModel

Constructor & Destructor Documentation

◆ HeightfieldModel()

G3D::HeightfieldModel::HeightfieldModel ( const Specification spec,
const String name 
)
protected

Member Function Documentation

◆ className()

virtual const String& G3D::HeightfieldModel::className ( ) const
overridevirtual

Name of the G3D::Model subclass.

Implements G3D::Model.

◆ create()

static shared_ptr<HeightfieldModel> G3D::HeightfieldModel::create ( const Specification spec,
const String name = "Heightfield" 
)
inlinestatic

Referenced by lazyCreate().

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ elevation() [1/2]

float G3D::HeightfieldModel::elevation ( const Point3 osPoint,
Vector3 faceNormal 
) const


Return the elevation (y value) under (osPoint.x, -, osPoint.z) according to the tessellation used for rendering (i.e., using barycentric interpolation on the triangles, not bilinear interpolation on the grid).

The faceNormal is the normal to the triangle, not the shading normal.

Referenced by elevation().

◆ elevation() [2/2]

float G3D::HeightfieldModel::elevation ( const Point3 osPoint) const
inline

◆ elevationImage()

const shared_ptr<Image> G3D::HeightfieldModel::elevationImage ( ) const
inline

◆ elevationTexture()

const shared_ptr<Texture> G3D::HeightfieldModel::elevationTexture ( ) const
inline

◆ generateGeometry()

void G3D::HeightfieldModel::generateGeometry ( )
protected

Called from the constructor.

◆ intersect()

virtual bool G3D::HeightfieldModel::intersect ( const Ray ray,
const CoordinateFrame cframe,
float &  maxDistance,
Model::HitInfo info = Model::HitInfo::ignore,
const Entity entity = nullptr,
const Model::Pose pose = nullptr 
) const
overridevirtual

Determines if the ray intersects the heightfield and fills the info with the proper information.

Parameters
maxDistanceMax distance to trace to on input, hit distance written on output if hit

Reimplemented from G3D::Model.

◆ lazyCreate() [1/2]

static lazy_ptr<Model> G3D::HeightfieldModel::lazyCreate ( const Specification s,
const String name = "" 
)
inlinestatic

Referenced by lazyCreate().

◆ lazyCreate() [2/2]

static lazy_ptr<Model> G3D::HeightfieldModel::lazyCreate ( const String name,
const Any any 
)
inlinestatic

◆ loadShaders()

void G3D::HeightfieldModel::loadShaders ( )
protected

Called from the constructor.

◆ name()

virtual const String& G3D::HeightfieldModel::name ( ) const
inlineoverridevirtual

Name of the instance (usually based on the filename it is loaded from)

Implements G3D::Model.

Referenced by create(), and lazyCreate().

◆ pose()

void G3D::HeightfieldModel::pose ( Array< shared_ptr< Surface > > &  surfaceArray,
const CFrame rootFrame,
const CFrame prevFrame,
const shared_ptr< Entity > &  entity,
const Model::Pose pose,
const Model::Pose prevPose,
const Surface::ExpressiveLightScatteringProperties e 
)
overridevirtual

This will be replaced soon with a version that takes a shared_ptr<Pose>.

Parameters
poseMust have the subclass of Model::Pose appropriate to the Model subclass.

Implements G3D::Model.

◆ setShaderArgs()

void G3D::HeightfieldModel::setShaderArgs ( Args args) const
protected

This binds attribute arrays, so it cannot accept a UniformTable argument.

◆ setUseOptimizedIntersect()

static void G3D::Model::setUseOptimizedIntersect ( bool  b)
inlinestaticinherited

If true, complex models should use TriTree to accelerate intersect() calls where possible.

This can make the first intersect() call very slow for the tree build and can make loading slow. It may not affect performance of skinned or articulated models that animate.

This value should be set before the models are loaded. If it is changed after a model is loaded, the Model is not required to respond to it.

Default: false

◆ specification()

const Specification& G3D::HeightfieldModel::specification ( ) const
inline

◆ useOptimizedIntersect()

static bool G3D::Model::useOptimizedIntersect ( )
inlinestaticinherited

Member Data Documentation

◆ m_depthAndColorShader

shared_ptr<Shader> G3D::HeightfieldModel::m_depthAndColorShader
protected

Used for depth-only and wire-frame rendering.

◆ m_elevation

shared_ptr<Texture> G3D::HeightfieldModel::m_elevation
protected

Elevation texture.

Referenced by elevationTexture().

◆ m_elevationImage

shared_ptr<Image> G3D::HeightfieldModel::m_elevationImage
protected

Elevation image.

Referenced by elevationImage().

◆ m_gbufferShader

shared_ptr<Shader> G3D::HeightfieldModel::m_gbufferShader
protected

◆ m_indexStream

IndexStream G3D::HeightfieldModel::m_indexStream
protected

Indices of the mesh.

◆ m_material

shared_ptr<UniversalMaterial> G3D::HeightfieldModel::m_material
protected

◆ m_name

const String G3D::HeightfieldModel::m_name
protected

Referenced by name().

◆ m_positionArray

AttributeArray G3D::HeightfieldModel::m_positionArray
protected

Shared vertex buffer for the entire mesh.

Stored in XY, since the mesh is flat, with unit spacing between vertices (i.e., vertices are at integer positions)

◆ m_quadsPerTileSide

int G3D::HeightfieldModel::m_quadsPerTileSide
protected

◆ m_shader

shared_ptr<Shader> G3D::HeightfieldModel::m_shader
protected

Used for all normal rendering.

◆ m_specification

const Specification G3D::HeightfieldModel::m_specification
protected

Referenced by specification().


documentation generated on Wed Nov 24 2021 08:01:57 using doxygen 1.8.15