Panda3D
Public Member Functions | List of all members
HeightfieldTesselator Class Reference

Converts a height field in the form of a greyscale image into a scene consisting of a number of GeomNodes. More...

#include "heightfieldTesselator.h"

Inheritance diagram for HeightfieldTesselator:
Namable MemoryBase

Public Member Functions

 HeightfieldTesselator (const std::string &name)
 
NodePath generate ()
 Generates a tree of nodes that represents the heightfield. More...
 
double get_elevation (double x, double y)
 Fetches the elevation at (x,y), where the input coordinate is specified in pixels. More...
 
PNMImageheightfield ()
 Returns a reference to the heightfield (a PNMImage) contained inside the HeightfieldTesselator. More...
 
void set_focal_point (int x, int y)
 Sets the focal point. More...
 
bool set_heightfield (const Filename &filename, PNMFileType *type=nullptr)
 Loads the specified greyscale image file into the heightfield. More...
 
void set_horizontal_scale (double h)
 Sets the horizontal scale. More...
 
void set_max_triangles (int n)
 Sets the max triangles per geom. More...
 
void set_poly_count (int n)
 Sets the polygon-count target. More...
 
void set_vertical_scale (double v)
 Sets the vertical scale. More...
 
void set_visibility_radius (int r)
 Sets the visibility radius. More...
 
- Public Member Functions inherited from Namable
 Namable (const std::string &initial_name="")
 
void clear_name ()
 Resets the Namable's name to empty. More...
 
const std::string & get_name () const
 
bool has_name () const
 Returns true if the Namable has a nonempty name set, false if the name is empty. More...
 
void output (std::ostream &out) const
 Outputs the Namable. More...
 
void set_name (const std::string &name)
 

Additional Inherited Members

- Static Public Member Functions inherited from Namable
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Public Attributes inherited from Namable
 get_name
 
 set_name
 

Detailed Description

Converts a height field in the form of a greyscale image into a scene consisting of a number of GeomNodes.

The tesselation uses an LOD algorithm. You supply a "focal point" (X,Y) which tells the tesselator where the bulk of the detail should be concentrated. The intent is that as the player walks around the terrain, you should occasionally move the focal point to wherever the player is. You should not move the focal point every frame: tesselation is not that fast. Also, changing the focal point may cause popping, so it is best to minimize the number of changes. There are a number of parameters that you can use to control tesselation, such as a target polygon count, and a visibility radius.

The heightfield needs to be a multiple of 128 pixels in each dimension. It does not need to be square, and it does not need to be a power of two. For example, a 384 x 640 heightfield is fine. Be aware that tesselation time is proportional to heightfield area, so if you plan to use a size larger than about 512x512, it may be desirable to benchmark.

Altering parameters, such as the poly count, the view radius, or the focal point, does not alter any GeomNodes already generated. Parameter changes only affect subsequently-generated GeomNodes. It is possible to cache many different tesselations of the same terrain.

Definition at line 58 of file heightfieldTesselator.h.

Member Function Documentation

◆ generate()

NodePath HeightfieldTesselator::generate ( )

Generates a tree of nodes that represents the heightfield.

This can be reparented into the scene.

Definition at line 128 of file heightfieldTesselator.cxx.

◆ get_elevation()

double HeightfieldTesselator::get_elevation ( double  x,
double  y 
)

Fetches the elevation at (x,y), where the input coordinate is specified in pixels.

This ignores the current tesselation level and instead provides an accurate number. Linear blending is used for non-integral coordinates.

Definition at line 66 of file heightfieldTesselator.cxx.

◆ heightfield()

PNMImage & HeightfieldTesselator::heightfield ( )
inline

Returns a reference to the heightfield (a PNMImage) contained inside the HeightfieldTesselator.

You can use the reference to alter the heightfield.

Definition at line 41 of file heightfieldTesselator.I.

◆ set_focal_point()

void HeightfieldTesselator::set_focal_point ( int  x,
int  y 
)
inline

Sets the focal point.

The tesselator generates high-resolution terrain around the focal point, and progressively lower and lower resolution terrain as you get farther away. The units are in pixels.

Definition at line 85 of file heightfieldTesselator.I.

◆ set_heightfield()

bool HeightfieldTesselator::set_heightfield ( const Filename filename,
PNMFileType type = nullptr 
)
inline

Loads the specified greyscale image file into the heightfield.

Definition at line 49 of file heightfieldTesselator.I.

References PNMImage::read().

◆ set_horizontal_scale()

void HeightfieldTesselator::set_horizontal_scale ( double  h)
inline

Sets the horizontal scale.

The default scale is 1.0, meaning that each pixel in the heightfield is 1x1 panda units wide.

Definition at line 95 of file heightfieldTesselator.I.

◆ set_max_triangles()

void HeightfieldTesselator::set_max_triangles ( int  n)
inline

Sets the max triangles per geom.

Definition at line 112 of file heightfieldTesselator.I.

◆ set_poly_count()

void HeightfieldTesselator::set_poly_count ( int  n)
inline

Sets the polygon-count target.

The tesselator usually manages to come within about 20% of the target, plus or minus.

Definition at line 59 of file heightfieldTesselator.I.

◆ set_vertical_scale()

void HeightfieldTesselator::set_vertical_scale ( double  v)
inline

Sets the vertical scale.

The default scale is 255.0, meaning that each as the gray value ranges from (0-1), the elevation ranges from (0-255) feet.

Definition at line 104 of file heightfieldTesselator.I.

◆ set_visibility_radius()

void HeightfieldTesselator::set_visibility_radius ( int  radius)
inline

Sets the visibility radius.

Polygons that are completely outside the radius (relative to the focal point) are cropped away. The cropping is imperfect (all approximations are conservative), so this should be used in conjunction with a far clipping plane, fog, or some other visibility limiting mechanism. The units are in pixels.

Definition at line 72 of file heightfieldTesselator.I.


The documentation for this class was generated from the following files: