Panda3D
|
GeoMipTerrain, meaning Panda3D GeoMipMapping, can convert a heightfield image into a 3D terrain, consisting of several GeomNodes. More...
#include "geoMipTerrain.h"
Public Types | |
enum | AutoFlattenMode { AFM_off = 0, AFM_light = 1, AFM_medium = 2, AFM_strong = 3 } |
Public Member Functions | |
GeoMipTerrain (const string &name) | |
~GeoMipTerrain () | |
This will not remove the terrain node itself. | |
TypedObject * | as_typed_object () |
Returns the object, upcast (if necessary) to a TypedObject pointer. | |
const TypedObject * | as_typed_object () const |
Returns the object, upcast (if necessary) to a TypedObject pointer. | |
void | clear_color_map () |
Clears the color map. | |
PNMImage & | color_map () |
Returns a reference to the color map (a PNMImage) contained inside GeoMipTerrain. | |
virtual TypeHandle | force_init_type () |
void | generate () |
(Re)generates the entire terrain, erasing the current. | |
int | get_best_parent_from_Set (const std::set< int > &) const |
LVecBase2f | get_block_from_pos (double x, double y) |
Gets the coordinates of the block at the specified position. | |
const NodePath | get_block_node_path (unsigned short mx, unsigned short my) |
Returns the NodePath of the specified block. | |
unsigned short | get_block_size () |
Gets the block size. | |
bool | get_border_stitching () |
Returns the current stitching setting. | |
bool | get_bruteforce () |
Returns a boolean whether the terrain is rendered bruteforce or not. | |
double | get_elevation (double x, double y) |
Fetches the elevation at (x, y), where the input coordinate is specified in pixels. | |
double | get_far () |
Returns the far LOD distance in the terrain coordinate space. | |
int | get_flatten_mode () |
Returns the automatic-flatten mode (e.g., off, flatten_light, flatten_medium, or flatten_strong) | |
NodePath | get_focal_point () const |
Returns the focal point, as a NodePath. | |
unsigned short | get_max_level () |
Returns the highest level possible for this block size. | |
unsigned short | get_min_level () |
Gets the minimum level of detail at which blocks may be generated by generate() or update(). | |
double | get_near () |
Returns the near LOD distance in the terrain coordinate space. | |
LVector3f | get_normal (unsigned short mx, unsigned short my, int x, int y) |
Fetches the terrain normal at (x,y), where the input coordinate is specified in pixels. | |
LVector3f | get_normal (int x, int y) |
Fetches the terrain normal at (x, y), where the input coordinate is specified in pixels. | |
NodePath | get_root () const |
Returns the root of the terrain. | |
virtual TypeHandle | get_type () const |
int | get_type_index () const |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. | |
bool | has_color_map () |
Returns whether a color map has been set. | |
PNMImage & | heightfield () |
Returns a reference to the heightfield (a PNMImage) contained inside GeoMipTerrain. | |
bool | is_dirty () |
Returns a bool indicating whether the terrain is marked 'dirty', that means the terrain has to be regenerated on the next update() call, because for instance the heightfield has changed. | |
bool | is_exact_type (TypeHandle handle) const |
Returns true if the current object is the indicated type exactly. | |
bool | is_of_type (TypeHandle handle) const |
Returns true if the current object is or derives from the indicated type. | |
PNMImage | make_slope_image () |
Returns a new grayscale image containing the slope angles. | |
void | operator delete (void *ptr) |
void | operator delete (void *ptr, void *) |
void | operator delete[] (void *, void *) |
void | operator delete[] (void *ptr) |
void * | operator new (size_t size, void *ptr) |
void * | operator new (size_t size) |
void * | operator new[] (size_t size, void *ptr) |
void * | operator new[] (size_t size) |
void | set_auto_flatten (int mode) |
The terrain can be automatically flattened (using flatten_light, flatten_medium, or flatten_strong) after each update. | |
void | set_block_size (unsigned short newbs) |
Sets the block size. | |
void | set_border_stitching (bool stitching) |
If this value is true, the LOD level at the borders of the terrain will be 0. | |
void | set_bruteforce (bool bf) |
Sets a boolean specifying whether the terrain will be rendered bruteforce. | |
bool | set_color_map (const Filename &filename, PNMFileType *type=NULL) |
Loads the specified image as color map. | |
bool | set_color_map (const PNMImage &image) |
bool | set_color_map (const Texture *image) |
bool | set_color_map (const string &path) |
void | set_factor (float factor) |
DEPRECATED method. | |
void | set_far (double input_far) |
Sets the far LOD distance, at which the terrain will be rendered at lowest quality. | |
void | set_focal_point (LPoint3f fp) |
void | set_focal_point (double x, double y) |
Sets the focal point. | |
void | set_focal_point (LPoint3d fp) |
void | set_focal_point (LPoint2d fp) |
void | set_focal_point (NodePath fnp) |
void | set_focal_point (LPoint2f fp) |
bool | set_heightfield (const string &path) |
bool | set_heightfield (const PNMImage &image) |
Loads the specified heightmap image file into the heightfield. | |
bool | set_heightfield (const Filename &filename, PNMFileType *type=NULL) |
Loads the specified heightmap image file into the heightfield. | |
void | set_min_level (unsigned short minlevel) |
Sets the minimum level of detail at which blocks may be generated by generate() or update(). | |
void | set_near (double input_near) |
Sets the near LOD distance, at which the terrain will be rendered at highest quality. | |
void | set_near_far (double input_near, double input_far) |
Sets the near and far LOD distances in one call. | |
bool | update () |
Loops through all of the terrain blocks, and checks whether they need to be updated. | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
This function is declared non-inline to work around a compiler bug in g++ 2.96. |
GeoMipTerrain, meaning Panda3D GeoMipMapping, can convert a heightfield image into a 3D terrain, consisting of several GeomNodes.
It uses the GeoMipMapping algorithm, or Geometrical MipMapping, based on the LOD (Level of Detail) algorithm. For more information about the GeoMipMapping algoritm, see this paper, written by Willem H. de Boer: http://flipcode.com/articles/article_geomipmaps.pdf
Definition at line 42 of file geoMipTerrain.h.
GeoMipTerrain::~GeoMipTerrain | ( | ) | [inline] |
This will not remove the terrain node itself.
To have the terrain itself also deleted, please call remove_node() prior to destruction.
Definition at line 55 of file geoMipTerrain.I.
TypedObject * TypedObject::as_typed_object | ( | ) | [inline, inherited] |
Returns the object, upcast (if necessary) to a TypedObject pointer.
Definition at line 99 of file typedObject.I.
const TypedObject * TypedObject::as_typed_object | ( | ) | const [inline, inherited] |
Returns the object, upcast (if necessary) to a TypedObject pointer.
Definition at line 110 of file typedObject.I.
void GeoMipTerrain::clear_color_map | ( | ) | [inline] |
PNMImage & GeoMipTerrain::color_map | ( | ) | [inline] |
Returns a reference to the color map (a PNMImage) contained inside GeoMipTerrain.
You can use the reference to alter the color map.
Definition at line 78 of file geoMipTerrain.I.
void GeoMipTerrain::generate | ( | ) |
(Re)generates the entire terrain, erasing the current.
This call un-flattens the terrain, so make sure you have set auto-flatten if you want to keep your terrain flattened.
Definition at line 374 of file geoMipTerrain.cxx.
References NodePath::attach_new_node(), NodePath::node(), and PandaNode::remove_all_children().
Referenced by update().
LVecBase2f GeoMipTerrain::get_block_from_pos | ( | double | x, |
double | y | ||
) | [inline] |
Gets the coordinates of the block at the specified position.
This position must be relative to the terrain, not to render. Returns an array containing two values: the block x and the block y coords. If the positions are out of range, the closest block is taken. Note that the VecBase returned does not represent a vector, position, or rotation, but it contains the block index of the block which you can use in GeoMipTerrain::get_block_node_path.
Definition at line 407 of file geoMipTerrain.I.
const NodePath GeoMipTerrain::get_block_node_path | ( | unsigned short | mx, |
unsigned short | my | ||
) | [inline] |
Returns the NodePath of the specified block.
If auto-flatten is enabled and the node is getting removed during the flattening process, it will still return a NodePath with the appropriate terrain chunk, but it will be in a temporary scenegraph. Please note that this returns a const object and you can not modify the node. Modify the heightfield instead.
Definition at line 389 of file geoMipTerrain.I.
unsigned short GeoMipTerrain::get_block_size | ( | ) | [inline] |
Gets the block size.
Definition at line 241 of file geoMipTerrain.I.
bool GeoMipTerrain::get_border_stitching | ( | ) | [inline] |
Returns the current stitching setting.
False by default, unless set_stitching has been set.
Definition at line 567 of file geoMipTerrain.I.
bool GeoMipTerrain::get_bruteforce | ( | ) | [inline] |
Returns a boolean whether the terrain is rendered bruteforce or not.
See set_bruteforce for more information.
Definition at line 107 of file geoMipTerrain.I.
double GeoMipTerrain::get_elevation | ( | double | x, |
double | y | ||
) |
Fetches the elevation at (x, y), where the input coordinate is specified in pixels.
This ignores the current LOD level and instead provides an accurate number. Linear blending is used for non-integral coordinates. Terrain scale is NOT taken into account! To get accurate normals, please multiply this with the terrain Z scale!
trueElev = terr.get_elevation(x,y) * terr.get_sz();
Definition at line 274 of file geoMipTerrain.cxx.
double GeoMipTerrain::get_far | ( | ) | [inline] |
Returns the far LOD distance in the terrain coordinate space.
Definition at line 349 of file geoMipTerrain.I.
int GeoMipTerrain::get_flatten_mode | ( | ) | [inline] |
Returns the automatic-flatten mode (e.g., off, flatten_light, flatten_medium, or flatten_strong)
Definition at line 371 of file geoMipTerrain.I.
NodePath GeoMipTerrain::get_focal_point | ( | ) | const [inline] |
Returns the focal point, as a NodePath.
If you have set it to be just a point, it will return an empty node at the focal position.
Definition at line 177 of file geoMipTerrain.I.
unsigned short GeoMipTerrain::get_max_level | ( | ) | [inline] |
Returns the highest level possible for this block size.
When a block is at this level, it will be the worst quality possible.
Definition at line 231 of file geoMipTerrain.I.
unsigned short GeoMipTerrain::get_min_level | ( | ) | [inline] |
Gets the minimum level of detail at which blocks may be generated by generate() or update().
The default value is 0, which is the highest quality.
Definition at line 219 of file geoMipTerrain.I.
double GeoMipTerrain::get_near | ( | ) | [inline] |
Returns the near LOD distance in the terrain coordinate space.
Definition at line 360 of file geoMipTerrain.I.
LVector3f GeoMipTerrain::get_normal | ( | int | x, |
int | y | ||
) |
Fetches the terrain normal at (x, y), where the input coordinate is specified in pixels.
This ignores the current LOD level and instead provides an accurate number. Terrain scale is NOT taken into account! To get accurate normals, please divide it by the terrain scale and normalize it again, like this:
LVector3f normal (terr.get_normal(x, y)); normal.set(normal.get_x() / root.get_sx(), normal.get_y() / root.get_sy(), normal.get_z() / root.get_sz()); normal.normalize();
Definition at line 315 of file geoMipTerrain.cxx.
References LVecBase3f::normalize().
Referenced by get_normal(), and make_slope_image().
LVector3f GeoMipTerrain::get_normal | ( | unsigned short | mx, |
unsigned short | my, | ||
int | x, | ||
int | y | ||
) | [inline] |
Fetches the terrain normal at (x,y), where the input coordinate is specified in pixels.
This ignores the current LOD level and instead provides an accurate number. Terrain scale is NOT taken into account! To get accurate normals, please divide it by the terrain scale and normalize it again!
Definition at line 610 of file geoMipTerrain.I.
References get_normal().
NodePath GeoMipTerrain::get_root | ( | ) | const [inline] |
Returns the root of the terrain.
This is a single PandaNode to which all the rest of the terrain is parented. The generate and update operations replace the nodes which are parented to this root, but they don't replace this root itself.
Definition at line 192 of file geoMipTerrain.I.
int TypedObject::get_type_index | ( | ) | const [inline, inherited] |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.
This is equivalent to get_type().get_index().
Definition at line 52 of file typedObject.I.
References TypeHandle::get_index().
bool GeoMipTerrain::has_color_map | ( | ) | [inline] |
Returns whether a color map has been set.
Definition at line 523 of file geoMipTerrain.I.
PNMImage & GeoMipTerrain::heightfield | ( | ) | [inline] |
Returns a reference to the heightfield (a PNMImage) contained inside GeoMipTerrain.
You can use the reference to alter the heightfield.
Definition at line 66 of file geoMipTerrain.I.
static void GeoMipTerrain::init_type | ( | ) | [inline, static] |
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Making it inline seems to cause problems in the optimizer.
Reimplemented from TypedObject.
Definition at line 163 of file geoMipTerrain.h.
References TypedObject::init_type().
bool GeoMipTerrain::is_dirty | ( | ) | [inline] |
Returns a bool indicating whether the terrain is marked 'dirty', that means the terrain has to be regenerated on the next update() call, because for instance the heightfield has changed.
Once the terrain has been regenerated, the dirty flag automatically gets reset internally.
Definition at line 282 of file geoMipTerrain.I.
bool TypedObject::is_exact_type | ( | TypeHandle | handle | ) | const [inline, inherited] |
Returns true if the current object is the indicated type exactly.
Definition at line 74 of file typedObject.I.
References TypeHandle::get_name().
Referenced by GraphicsStateGuardian::async_reload_texture(), PortalNode::combine_with(), PandaNode::combine_with(), GeomNode::combine_with(), CollisionNode::combine_with(), Character::combine_with(), PGItem::cull_callback(), FactoryParams::get_param_of_type(), CollisionHandlerPusher::handle_entries(), SceneGraphReducer::r_flatten(), ConnectionWriter::send(), FltToEggLevelState::set_transform(), and VirtualFileSystem::unmount().
bool TypedObject::is_of_type | ( | TypeHandle | handle | ) | const [inline, inherited] |
Returns true if the current object is or derives from the indicated type.
Definition at line 63 of file typedObject.I.
References TypeHandle::is_derived_from().
Referenced by EggSliderData::add_back_pointer(), EggJointData::add_back_pointer(), CIntervalManager::add_c_interval(), XFileNode::add_child(), CollisionTraverser::add_collider(), CollisionHandlerPhysical::add_collider(), EggXfmSAnim::add_data(), CharacterJointBundle::add_node(), NonlinearImager::add_screen(), EggGroupNode::apply_first_attribute(), EggGroupNode::apply_last_attribute(), DeferredNodeProperty::apply_to_node(), RecorderController::begin_playback(), NodePath::clear_clip_plane(), EggGroupNode::clear_connected_shading(), NodePath::clear_light(), EggBase::convert_paths(), NodePath::decode_from_bam_stream(), VrpnClient::disconnect_device(), PhysicsManager::do_physics(), GraphicsStateGuardian::fetch_specified_part(), EggRenderState::fill_state(), AnimBundleNode::find_anim_bundle(), EggGroupNode::find_coordsys_entry(), XFile::find_data_object(), Character::find_joint(), EggGroupNode::find_materials(), Character::find_slider(), XFile::find_template(), EggGroupNode::find_textures(), EggMaterialCollection::find_used_materials(), EggTextureCollection::find_used_textures(), EggGroupNode::force_filenames(), EggJointData::force_initial_rest_frame(), WindowFramework::get_aspect_2d(), EggPoolUniquifier::get_category(), EggGroupUniquifier::get_category(), EggGroupNode::get_connected_shading(), PandaFramework::get_mouse(), FactoryParams::get_param_of_type(), EggGroupNode::has_absolute_pathnames(), NodePath::has_clip_plane(), NodePath::has_clip_plane_off(), NodePath::has_light(), PandaFramework::hide_collision_solids(), x11GraphicsWindow::open_window(), eglGraphicsWindow::open_window(), EggNode::parse_egg(), CharacterMaker::part_to_node(), EggGroupNode::post_apply_flat_attribute(), EggBinner::prepare_node(), PortalClipper::prepare_portal(), NodePath::project_texture(), EggMatrixTablePointer::quantize_channels(), ParametricCurveCollection::r_add_curves(), SceneGraphReducer::r_collect_vertex_data(), EggGroupNode::r_load_externals(), EggGroupNode::rebuild_vertex_pools(), EggGroupNode::recompute_polygon_normals(), EggGroupNode::remove_invalid_primitives(), EggGroupNode::remove_unused_vertices(), EggLoader::reparent_decals(), EggMaterialCollection::replace_materials(), EggTextureCollection::replace_textures(), EggGroupNode::resolve_filenames(), EggGroupNode::reverse_vertex_ordering(), NodePath::set_clip_plane(), NodePath::set_clip_plane_off(), NodePath::set_light(), ProjectionScreen::set_projector(), NonlinearImager::set_source_camera(), EggXfmSAnim::set_value(), NonlinearImager::set_viewer_camera(), PandaFramework::show_collision_solids(), BamCache::store(), XFileToEggConverter::strip_nodes(), EggGroupNode::strip_normals(), DataGraphTraverser::traverse(), DataGraphTraverser::traverse_below(), EggGroupNode::triangulate_polygons(), EggGroupNode::unify_attributes(), EggNameUniquifier::uniquify(), NodeCullCallbackData::upcall(), PhysicsCollisionHandler::validate_target(), EggXfmSAnim::write(), EggGroup::write(), EggToDXFLayer::write_3d_face(), and EggToDXFLayer::write_entities().
PNMImage GeoMipTerrain::make_slope_image | ( | ) |
Returns a new grayscale image containing the slope angles.
A white pixel value means a vertical slope, while a black pixel will mean that the terrain is entirely flat at that pixel. You can translate it to degrees by mapping the greyscale values from 0 to 90 degrees. The resulting image will have the same size as the heightfield image. The scale will be taken into respect -- meaning, if you change the terrain scale, the slope image will need to be regenerated in order to be correct.
Definition at line 348 of file geoMipTerrain.cxx.
References LVector3f::angle_deg(), get_normal(), PNMImage::make_grayscale(), LVecBase3f::normalize(), PNMImage::set_gray(), and LVector3f::up().
void GeoMipTerrain::set_auto_flatten | ( | int | mode | ) | [inline] |
The terrain can be automatically flattened (using flatten_light, flatten_medium, or flatten_strong) after each update.
This only affects future updates, it doesn't flatten the current terrain.
Definition at line 120 of file geoMipTerrain.I.
void GeoMipTerrain::set_block_size | ( | unsigned short | newbs | ) | [inline] |
Sets the block size.
If it is not a power of two, the closest power of two is used.
Definition at line 252 of file geoMipTerrain.I.
void GeoMipTerrain::set_border_stitching | ( | bool | stitching | ) | [inline] |
If this value is true, the LOD level at the borders of the terrain will be 0.
This is useful if you have multiple terrains attached and you want to stitch them together, to fix seams. This setting also has effect when bruteforce is enabled, although in that case you are probably better off with setting the minlevels to the same value.
Definition at line 553 of file geoMipTerrain.I.
void GeoMipTerrain::set_bruteforce | ( | bool | bf | ) | [inline] |
Sets a boolean specifying whether the terrain will be rendered bruteforce.
If the terrain is rendered bruteforce, there will be no Level of Detail, and the update() call will only update the terrain if it is marked dirty.
Definition at line 92 of file geoMipTerrain.I.
bool GeoMipTerrain::set_color_map | ( | const Filename & | filename, |
PNMFileType * | ftype = NULL |
||
) | [inline] |
Loads the specified image as color map.
The next time generate() is called, the terrain is painted with this color map using the vertex color column. Returns a boolean indicating whether the operation has succeeded.
Definition at line 488 of file geoMipTerrain.I.
References PNMImage::read().
void GeoMipTerrain::set_factor | ( | float | factor | ) | [inline] |
DEPRECATED method.
Use set_near/far instead. Sets the quality factor at which blocks must be generated. The higher this level, the better quality the terrain will be, but more expensive to render. A value of 0 makes the terrain the lowest quality possible, depending on blocksize. The default value is 100.
Definition at line 298 of file geoMipTerrain.I.
void GeoMipTerrain::set_far | ( | double | input_far | ) | [inline] |
Sets the far LOD distance, at which the terrain will be rendered at lowest quality.
This distance is in the terrain's coordinate space!
Definition at line 337 of file geoMipTerrain.I.
void GeoMipTerrain::set_focal_point | ( | double | x, |
double | y | ||
) | [inline] |
Sets the focal point.
GeoMipTerrain generates high-resolution terrain around the focal point, and progressively lower and lower resolution terrain as you get farther away. If a point is supplied and not a NodePath, make sure it's relative to the terrain. Only the x and y coordinates of the focal point are taken in respect.
Definition at line 136 of file geoMipTerrain.I.
References NodePath::set_pos().
bool GeoMipTerrain::set_heightfield | ( | const Filename & | filename, |
PNMFileType * | ftype = NULL |
||
) |
Loads the specified heightmap image file into the heightfield.
Returns true if succeeded, or false if an error has occured. If the heightmap is not a power of two plus one, it is scaled up using a gaussian filter.
Definition at line 616 of file geoMipTerrain.cxx.
References PNMImage::clear_read_size(), PNMImage::copy_header_from(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImage::read(), PNMImageHeader::read_header(), and PNMImage::set_read_size().
bool GeoMipTerrain::set_heightfield | ( | const PNMImage & | image | ) | [inline] |
Loads the specified heightmap image file into the heightfield.
Returns true if succeeded, or false if an error has occured. If the heightmap is not a power of two plus one, it is scaled up using a gaussian filter.
Definition at line 459 of file geoMipTerrain.I.
References PNMImageHeader::get_x_size(), and PNMImageHeader::get_y_size().
void GeoMipTerrain::set_min_level | ( | unsigned short | minlevel | ) | [inline] |
Sets the minimum level of detail at which blocks may be generated by generate() or update().
The default value is 0, which is the highest quality. This value is also taken in respect when generating the terrain bruteforce.
Definition at line 206 of file geoMipTerrain.I.
void GeoMipTerrain::set_near | ( | double | input_near | ) | [inline] |
Sets the near LOD distance, at which the terrain will be rendered at highest quality.
This distance is in the terrain's coordinate space!
Definition at line 324 of file geoMipTerrain.I.
void GeoMipTerrain::set_near_far | ( | double | input_near, |
double | input_far | ||
) | [inline] |
Sets the near and far LOD distances in one call.
Definition at line 310 of file geoMipTerrain.I.
bool GeoMipTerrain::update | ( | ) |
Loops through all of the terrain blocks, and checks whether they need to be updated.
If that is indeed the case, it regenerates the mipmap. Returns a true when the terrain has changed. Returns false when the terrain isn't updated at all. If there is no terrain yet, it generates the entire terrain. This call un-flattens the terrain, so make sure you have set auto-flatten if you want to keep your terrain flattened.
Definition at line 418 of file geoMipTerrain.cxx.
References generate(), NodePath::node(), and PandaNode::remove_all_children().