15 #include "stTerrain.h"
41 _is_valid(copy._is_valid),
42 _normal_map(copy._normal_map),
43 _splat_layers(copy._splat_layers),
44 _min_height(copy._min_height),
45 _max_height(copy._max_height)
47 set_vertex_format(copy._vertex_format);
72 _splat_layers.clear();
74 set_vertex_format(NULL);
140 PN_stdfloat height_min, PN_stdfloat height_max,
141 PN_stdfloat slope_min, PN_stdfloat slope_max) {
143 if (height < height_min || height > height_max) {
148 if (slope < slope_min || slope > slope_max) {
174 PN_stdfloat start_x, PN_stdfloat start_y,
175 PN_stdfloat size_xy,
int num_xy)
const {
184 output(ostream &out)
const {
194 write(ostream &out,
int indent_level)
const {
195 indent(out, indent_level)
208 nassertr(!_st_vertex_attribs.empty(), NULL);
210 return &_st_vertex_attribs[0];
222 set_vertex_format(
const GeomVertexFormat *format) {
223 if (format == NULL) {
224 _vertex_format = NULL;
225 _st_vertex_attribs.clear();
230 _vertex_format = GeomVertexFormat::register_format(format);
231 if (!convert_vertex_format(_st_vertex_attribs, _vertex_format)) {
250 const GeomVertexFormat *format) {
251 st_vertex_attribs.clear();
253 if (format->get_num_arrays() != 1) {
254 speedtree_cat.error()
255 <<
"Cannot represent multi-array vertex format in SpeedTree.\n";
259 const GeomVertexArrayFormat *array = format->get_array(0);
261 int num_columns = array->get_num_columns();
262 for (
int ci = 0; ci < num_columns; ++ci) {
264 st_vertex_attribs.push_back(SpeedTree::SVertexAttribDesc());
265 SpeedTree::SVertexAttribDesc &attrib = st_vertex_attribs.back();
266 if (!convert_vertex_column(attrib, column)) {
267 st_vertex_attribs.clear();
272 st_vertex_attribs.push_back(SpeedTree::st_attrib_end);
285 convert_vertex_column(SpeedTree::SVertexAttribDesc &st_attrib,
288 case GeomEnums::NT_stdfloat:
289 st_attrib.m_eDataType = SpeedTree::VERTEX_ATTRIB_TYPE_FLOAT;
293 speedtree_cat.error()
294 <<
"Unsupported vertex numeric type for " << *column <<
"\n";
300 if (column->
get_name() == InternalName::get_vertex()) {
301 st_attrib.m_eSemantic = SpeedTree::VERTEX_ATTRIB_SEMANTIC_POS;
303 }
else if (column->
get_name() == InternalName::get_texcoord()) {
304 st_attrib.m_eSemantic = SpeedTree::VERTEX_ATTRIB_SEMANTIC_TEXCOORD0;
307 speedtree_cat.error()
308 <<
"Unsupported vertex semantic name for " << *column <<
"\n";
312 nassertr(st_attrib.SizeOfAttrib() == column->
get_total_bytes(),
false);
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 te...
int get_total_bytes() const
Returns the number of bytes used by each element of the column: component_bytes * num_components...
const InternalName * get_name() const
Returns the name of this particular data field, e.g.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is the abstract base class that defines the interface needed to describe a terrain for rendering...
int get_num_components() const
Returns the number of components of the column: the number of instances of the NumericType in each el...
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 cir...
This defines how a single column is interleaved within a vertex array stored within a Geom...
A base class for all things which can have a name.
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...
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
virtual void clear()
Resets the terrain to its initial, unloaded state.
void output(ostream &out) const
Outputs the Namable.
NumericType get_numeric_type() const
Returns the token representing the numeric type of the data storage.
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...
virtual void load_data()=0
This will be called at some point after initialization.
TypeHandle is the identifier used to differentiate C++ class types.
const SpeedTree::SVertexAttribDesc * get_st_vertex_format() const
Returns a pointer to the SpeedTree array of vertex attribs that defines the vertex format for SpeedTr...
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...