Panda3D
|
This is the abstract base class that defines the interface needed to describe a terrain for rendering by SpeedTree. More...
#include "stTerrain.h"
Classes | |
class | SplatLayer |
Public Member Functions | |
virtual void | clear () |
Resets the terrain to its initial, unloaded state. | |
virtual void | fill_vertices (GeomVertexData *data, PN_stdfloat start_x, PN_stdfloat start_y, PN_stdfloat size_xy, int num_xy) const |
After load_data() has been called, this will be called occasionally to populate the vertices for a terrain cell. | |
virtual TypeHandle | force_init_type () |
virtual PN_stdfloat | get_height (PN_stdfloat x, PN_stdfloat y) const =0 |
After load_data() has been called, this should return the computed height value at point (x, y) of the terrain, where x and y are unbounded and may refer to any 2-d point in space. | |
PN_stdfloat | get_max_height () const |
Returns the largest height value that might be returned by get_height(). | |
PN_stdfloat | get_min_height () const |
Returns the smallest height value that might be returned by get_height(). | |
const Filename & | get_normal_map () const |
Returns the normal map that should be applied to the terrain. | |
int | get_num_splat_layers () const |
Returns the number of splat layers that are to be applied to the terrain. | |
virtual PN_stdfloat | get_slope (PN_stdfloat x, PN_stdfloat y) const |
After load_data() has been called, this should return the directionless slope at point (x, y) of the terrain, where 0.0 is flat and 1.0 is vertical. | |
virtual PN_stdfloat | get_smooth_height (PN_stdfloat x, PN_stdfloat y, PN_stdfloat radius) const |
After load_data() has been called, this should return the approximate average height value over a circle of the specified radius, centered at point (x, y) of the terrain. | |
const Filename & | get_splat_layer (int n) const |
Returns the nth splat layer that is to be applied to the terrain. | |
LColor | get_splat_layer_color (int n) const |
Returns the overall color of the nth splat layer. | |
PN_stdfloat | get_splat_layer_tiling (int n) const |
Returns the tiling value of the nth splat layer. | |
const Filename & | get_splat_map () const |
Returns the splat map that should be applied to the terrain. | |
const SpeedTree::SVertexAttribDesc * | get_st_vertex_format () const |
Returns a pointer to the SpeedTree array of vertex attribs that defines the vertex format for SpeedTree. | |
virtual TypeHandle | get_type () const |
const GeomVertexFormat * | get_vertex_format () |
Returns the vertex format of the vertex array that is supported by this terrain data. | |
bool | is_valid () const |
Returns true if the terrain data is well-defined and ready to use. | |
virtual void | load_data ()=0 |
This will be called at some point after initialization. | |
virtual void | output (ostream &out) const |
Outputs the Namable. | |
bool | placement_is_acceptable (PN_stdfloat x, PN_stdfloat y, PN_stdfloat height_min, PN_stdfloat height_max, PN_stdfloat slope_min, PN_stdfloat slope_max) |
Returns true if the elevation and slope of point (x, y) fall within the requested limits, false otherwise. | |
virtual void | write (ostream &out, int indent_level=0) const |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
Protected Types | |
typedef pvector< SplatLayer > | SplatLayers |
typedef pvector < SpeedTree::SVertexAttribDesc > | VertexAttribs |
Protected Member Functions | |
STTerrain (const STTerrain ©) | |
CPT (GeomVertexFormat) _vertex_format | |
bool | set_vertex_format (const GeomVertexFormat *format) |
Should be called in load_data() by a derived class to fill in the _vertex_format member. | |
Static Protected Member Functions | |
static bool | convert_vertex_column (SpeedTree::SVertexAttribDesc &st_attrib, const GeomVertexColumn *column) |
Converts the indicated vertex column definition to the corresponding SpeedTree::SVertexAttribDesc format. | |
static bool | convert_vertex_format (VertexAttribs &st_vertex_attribs, const GeomVertexFormat *format) |
Populates the indicated st_vertex_attribs vector with an array of SpeedTree vertex attribute entries that corresponds to the requested format. | |
Protected Attributes | |
bool | _is_valid |
PN_stdfloat | _max_height |
PN_stdfloat | _min_height |
Filename | _normal_map |
SplatLayers | _splat_layers |
Filename | _splat_map |
VertexAttribs | _st_vertex_attribs |
This is the abstract base class that defines the interface needed to describe a terrain for rendering by SpeedTree.
To use it, you must subclass and override the appropriate virtual methods. Or, consider just using STBasicTerrain.
A terrain is defined as a 2-d height function over all space: get_height(x, y) may be called for any point in space and it should return a reasonable value. A terrain also provides normal maps and splat maps, as rendered by SpeedTree's Terrain.hlsl shader file.
Definition at line 39 of file stTerrain.h.
void STTerrain::clear | ( | ) | [virtual] |
Resets the terrain to its initial, unloaded state.
Reimplemented in STBasicTerrain.
Definition at line 65 of file stTerrain.cxx.
References set_vertex_format().
bool STTerrain::convert_vertex_column | ( | SpeedTree::SVertexAttribDesc & | st_attrib, |
const GeomVertexColumn * | column | ||
) | [static, protected] |
Converts the indicated vertex column definition to the corresponding SpeedTree::SVertexAttribDesc format.
Returns true on success, false on failure.
Definition at line 285 of file stTerrain.cxx.
References GeomVertexColumn::get_name(), GeomVertexColumn::get_num_components(), GeomVertexColumn::get_numeric_type(), and GeomVertexColumn::get_total_bytes().
Referenced by convert_vertex_format().
bool STTerrain::convert_vertex_format | ( | STTerrain::VertexAttribs & | st_vertex_attribs, |
const GeomVertexFormat * | format | ||
) | [static, protected] |
Populates the indicated st_vertex_attribs vector with an array of SpeedTree vertex attribute entries that corresponds to the requested format.
Returns true on success, or false if the format cannot be represented in SpeedTree.
Definition at line 249 of file stTerrain.cxx.
References convert_vertex_column(), GeomVertexFormat::get_array(), GeomVertexArrayFormat::get_column(), GeomVertexFormat::get_num_arrays(), and GeomVertexArrayFormat::get_num_columns().
Referenced by set_vertex_format().
void STTerrain::fill_vertices | ( | GeomVertexData * | data, |
PN_stdfloat | start_x, | ||
PN_stdfloat | start_y, | ||
PN_stdfloat | size_xy, | ||
int | num_xy | ||
) | const [virtual] |
After load_data() has been called, this will be called occasionally to populate the vertices for a terrain cell.
It will be passed a GeomVertexData whose format will match get_vertex_format(), and already allocated with num_xy * num_xy rows. This method should fill the rows of the data with the appropriate vertex data for the terrain, over the grid described by the corners (start_x, start_y) up to and including (start_x + size_x, start_y + size_xy)--a square of the terrain with num_xy vertices on a side, arranged in row-major order.
Reimplemented in STBasicTerrain.
Definition at line 173 of file stTerrain.cxx.
PN_stdfloat STTerrain::get_height | ( | PN_stdfloat | x, |
PN_stdfloat | y | ||
) | const [pure virtual] |
After load_data() has been called, this should return the computed height value at point (x, y) of the terrain, where x and y are unbounded and may refer to any 2-d point in space.
Implemented in STBasicTerrain.
Definition at line 101 of file stTerrain.cxx.
PN_stdfloat STTerrain::get_max_height | ( | ) | const [inline] |
Returns the largest height value that might be returned by get_height().
This is used as a culling optimization.
Definition at line 136 of file stTerrain.I.
Referenced by SpeedTreeNode::set_terrain().
PN_stdfloat STTerrain::get_min_height | ( | ) | const [inline] |
Returns the smallest height value that might be returned by get_height().
This is used as a culling optimization.
Definition at line 124 of file stTerrain.I.
Referenced by SpeedTreeNode::set_terrain().
const Filename & STTerrain::get_normal_map | ( | ) | const [inline] |
Returns the normal map that should be applied to the terrain.
This will be loaded and supplied to the shader.
Definition at line 35 of file stTerrain.I.
Referenced by SpeedTreeNode::set_terrain().
int STTerrain::get_num_splat_layers | ( | ) | const [inline] |
Returns the number of splat layers that are to be applied to the terrain.
This must be consistent with c_nNumTerrainSplatLayers in SpeedTree's TerrainRI.h.
Definition at line 61 of file stTerrain.I.
Referenced by SpeedTreeNode::set_terrain().
PN_stdfloat STTerrain::get_slope | ( | PN_stdfloat | x, |
PN_stdfloat | y | ||
) | const [virtual] |
After load_data() has been called, this should return the directionless slope at point (x, y) of the terrain, where 0.0 is flat and 1.0 is vertical.
This is used for determining the legal points to place trees and grass.
Reimplemented in STBasicTerrain.
Definition at line 128 of file stTerrain.cxx.
PN_stdfloat STTerrain::get_smooth_height | ( | PN_stdfloat | x, |
PN_stdfloat | y, | ||
PN_stdfloat | radius | ||
) | const [virtual] |
After load_data() has been called, this should return the approximate average height value over a circle of the specified radius, centered at point (x, y) of the terrain.
Reimplemented in STBasicTerrain.
Definition at line 114 of file stTerrain.cxx.
References STBasicTerrain::get_height().
const Filename & STTerrain::get_splat_layer | ( | int | n | ) | const [inline] |
Returns the nth splat layer that is to be applied to the terrain.
Definition at line 72 of file stTerrain.I.
Referenced by SpeedTreeNode::set_terrain().
LColor STTerrain::get_splat_layer_color | ( | int | n | ) | const [inline] |
Returns the overall color of the nth splat layer.
This is used just to match the color of the grass to its terrain.
Definition at line 98 of file stTerrain.I.
PN_stdfloat STTerrain::get_splat_layer_tiling | ( | int | n | ) | const [inline] |
Returns the tiling value of the nth splat layer.
This is an arbitrary UV scale that is applied to each layer individually, by the terrain shader.
Definition at line 85 of file stTerrain.I.
Referenced by SpeedTreeNode::set_terrain().
const Filename & STTerrain::get_splat_map | ( | ) | const [inline] |
Returns the splat map that should be applied to the terrain.
This will be loaded and supplied to the shader. Presumably, the shader will use the channels of this map to determine which of the splat layers are to be rendered at any given point.
Definition at line 49 of file stTerrain.I.
Referenced by SpeedTreeNode::set_terrain().
const SpeedTree::SVertexAttribDesc * STTerrain::get_st_vertex_format | ( | ) | const |
Returns a pointer to the SpeedTree array of vertex attribs that defines the vertex format for SpeedTree.
Definition at line 206 of file stTerrain.cxx.
const GeomVertexFormat * STTerrain::get_vertex_format | ( | ) | [inline] |
Returns the vertex format of the vertex array that is supported by this terrain data.
A GeomVertexData of the requested format will be passed to fill_vertices().
Definition at line 112 of file stTerrain.I.
bool STTerrain::is_valid | ( | ) | const [inline] |
Returns true if the terrain data is well-defined and ready to use.
Definition at line 23 of file stTerrain.I.
Referenced by SpeedTreeNode::set_terrain().
void STTerrain::load_data | ( | ) | [pure virtual] |
This will be called at some point after initialization.
It should be overridden by a derived class to load up the terrain data from its source and fill in the data members of this class appropriately, especially _is_valid. After this call, if _is_valid is true, then get_height() etc. will be called to query the terrain's data.
Implemented in STBasicTerrain.
Definition at line 89 of file stTerrain.cxx.
Referenced by SpeedTreeNode::set_terrain().
void STTerrain::output | ( | ostream & | out | ) | const [virtual] |
Outputs the Namable.
This function simply writes the name to the output stream; most Namable derivatives will probably redefine this.
Reimplemented from Namable.
Reimplemented in STBasicTerrain.
Definition at line 184 of file stTerrain.cxx.
References STBasicTerrain::output().
bool STTerrain::placement_is_acceptable | ( | PN_stdfloat | x, |
PN_stdfloat | y, | ||
PN_stdfloat | height_min, | ||
PN_stdfloat | height_max, | ||
PN_stdfloat | slope_min, | ||
PN_stdfloat | slope_max | ||
) |
Returns true if the elevation and slope of point (x, y) fall within the requested limits, false otherwise.
Definition at line 139 of file stTerrain.cxx.
References STBasicTerrain::get_height(), and STBasicTerrain::get_slope().
bool STTerrain::set_vertex_format | ( | const GeomVertexFormat * | format | ) | [protected] |
Should be called in load_data() by a derived class to fill in the _vertex_format member.
This will also compute and store the appropriate value for _st_vertex_attribs.
Definition at line 222 of file stTerrain.cxx.
References convert_vertex_format().
Referenced by clear(), and STBasicTerrain::clear().