Panda3D
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes

LODNode Class Reference

A Level-of-Detail node. More...

#include "lodNode.h"

Inheritance diagram for LODNode:
PandaNode TypedWritable Namable LinkedListNode ReferenceCount TypedObject MemoryBase MemoryBase MemoryBase FadeLODNode

List of all members.

Classes

class  CData
class  Switch

Public Member Functions

 LODNode (const string &name)
void add_switch (PN_stdfloat in, PN_stdfloat out)
 Adds a switch range to the LODNode.
void clear_force_switch ()
 Undoes the effect of a previous call to force_switch() and releases the LODNode to once again display the normal level.
void clear_switches ()
 Removes the set of switching ranges for the LODNode, presumably in conjunction with removing all of its children.
virtual bool cull_callback (CullTraverser *trav, CullTraverserData &data)
 This function will be called during the cull traversal to perform any additional operations that should be performed at cull time.
virtual TypeHandle force_init_type ()
void force_switch (int index)
 Forces the LODNode to show the indicated level instead of the level that would normally be shown based on the distance from the camera.
const LPoint3get_center () const
 Returns the center of the LOD.
int get_highest_switch () const
 Returns the index number of the child with the highest level of detail; that is, the one that is designed to be seen from the closest to the camera.
PN_stdfloat get_in (int index) const
 Returns the "in" distance of the indicated switch range.
PN_stdfloat get_lod_scale () const
 Returns the multiplier for lod distances.
int get_lowest_switch () const
 Returns the index number of the child with the lowest level of detail; that is, the one that is designed to be seen from the farthest away.
int get_num_switches () const
 Returns the number of switch ranges added to the LODNode.
PN_stdfloat get_out (int index) const
 Returns the "out" distance of the indicated switch range.
virtual TypeHandle get_type () const
void hide_all_switches ()
 Hides all levels, restoring the LODNode to normal operation.
void hide_switch (int index)
 Disables a previous call to show_switch().
bool is_any_shown () const
 Returns true if any switch has been shown with show_switch(), indicating the LODNode is in debug show mode; or false if it is in the normal mode.
virtual bool is_lod_node () const
 A simple downcast check.
virtual PandaNodemake_copy () const
 Returns a newly-allocated Node that is a shallow copy of this one.
 MAKE_SEQ (get_ins, get_num_switches, get_in)
 MAKE_SEQ (get_outs, get_num_switches, get_out)
virtual void output (ostream &out) const
 Outputs the Namable.
virtual bool safe_to_combine () const
 Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of PandaNodes of compatible type, adding children or whatever.
virtual bool safe_to_combine_children () const
 Returns true if it is generally safe to combine the children of this PandaNode with each other.
void set_center (const LPoint3 &center)
 Specifies the center of the LOD.
void set_lod_scale (PN_stdfloat value)
 Sets the multiplier for lod distances.
bool set_switch (int index, PN_stdfloat in, PN_stdfloat out)
 Changes the switching range of a particular child of the LODNode.
void show_all_switches ()
 Shows all levels in their default colors.
void show_switch (int index)
 This is provided as a debugging aid.
void show_switch (int index, const LColor &color)
 This is provided as a debugging aid.
bool verify_child_bounds () const
 Returns true if the bounding volumes for the geometry of each fhild node entirely fits within the switch_in radius for that child, or false otherwise.
virtual void write_datagram (BamWriter *manager, Datagram &dg)
 Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual void xform (const LMatrix4 &mat)
 Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so.

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()
static PT (LODNode) make_default_lod(const string &name)
static void register_with_read_factory ()
 Tells the BamReader how to create objects of type LODNode.

Protected Types

typedef pvector< SwitchSwitchVector

Protected Member Functions

 LODNode (const LODNode &copy)
int compute_child (CullTraverser *trav, CullTraverserData &data)
 Determines which child should be visible according to the current camera position.
virtual void compute_internal_bounds (CPT(BoundingVolume)&internal_bounds, int &internal_vertices, int pipeline_stage, Thread *current_thread) const
 Returns a newly-allocated BoundingVolume that represents the internal contents of the node.
void consider_verify_lods (CullTraverser *trav, CullTraverserData &data)
 To be called internally when the node is rendered, this will raise an assertion if verify-lods is configured true, and verify_child_bounds() returns false.
 CPT (TransformState) get_rel_transform(CullTraverser *trav
void fillin (DatagramIterator &scan, BamReader *manager)
 This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new LODNode.
bool show_switches_cull_callback (CullTraverser *trav, CullTraverserData &data)
 A special version of cull_callback() that is to be invoked when the LODNode is in show_switch() mode.

Static Protected Member Functions

static TypedWritablemake_from_bam (const FactoryParams &params)
 This function is called by the BamReader's factory when a new object of type LODNode is encountered in the Bam file.

Protected Attributes

CullTraverserDatadata

Detailed Description

A Level-of-Detail node.

This selects only one of its children for rendering, according to the distance from the camera and the table indicated in the associated LOD object.

Definition at line 31 of file lodNode.h.


Member Function Documentation

void LODNode::add_switch ( PN_stdfloat  in,
PN_stdfloat  out 
) [inline]

Adds a switch range to the LODNode.

This implies that the corresponding child node has been parented to the node.

The sense of in vs. out distances is as if the object were coming towards you from far away: it switches "in" at the far distance, and switches "out" at the close distance. Thus, "in" should be larger than "out".

Definition at line 55 of file lodNode.I.

References PandaNode::mark_internal_bounds_stale().

void LODNode::clear_force_switch ( ) [inline]

Undoes the effect of a previous call to force_switch() and releases the LODNode to once again display the normal level.

Definition at line 224 of file lodNode.I.

void LODNode::clear_switches ( ) [inline]

Removes the set of switching ranges for the LODNode, presumably in conjunction with removing all of its children.

See add_switch().

Definition at line 97 of file lodNode.I.

References PandaNode::mark_internal_bounds_stale().

int LODNode::compute_child ( CullTraverser trav,
CullTraverserData data 
) [protected]

Determines which child should be visible according to the current camera position.

If a child is visible, returns its index number; otherwise, returns -1.

Definition at line 361 of file lodNode.cxx.

References CullTraverserData::get_net_transform(), and TransformState::is_singular().

Referenced by FadeLODNode::cull_callback().

void LODNode::compute_internal_bounds ( CPT(BoundingVolume)&  internal_bounds,
int &  internal_vertices,
int  pipeline_stage,
Thread current_thread 
) const [protected, virtual]

Returns a newly-allocated BoundingVolume that represents the internal contents of the node.

Should be overridden by PandaNode classes that contain something internally.

Reimplemented from PandaNode.

Definition at line 480 of file lodNode.cxx.

References BoundingVolume::around(), is_any_shown(), and LODNode::Switch::is_shown().

void LODNode::consider_verify_lods ( CullTraverser trav,
CullTraverserData data 
) [inline, protected]

To be called internally when the node is rendered, this will raise an assertion if verify-lods is configured true, and verify_child_bounds() returns false.

Definition at line 281 of file lodNode.I.

Referenced by cull_callback(), and FadeLODNode::cull_callback().

bool LODNode::cull_callback ( CullTraverser trav,
CullTraverserData data 
) [virtual]

This function will be called during the cull traversal to perform any additional operations that should be performed at cull time.

This may include additional manipulation of render state or additional visible/invisible decisions, or any other arbitrary operation.

Note that this function will *not* be called unless set_cull_callback() is called in the constructor of the derived class. It is necessary to call set_cull_callback() to indicated that we require cull_callback() to be called.

By the time this function is called, the node has already passed the bounding-volume test for the viewing frustum, and the node's transform and state have already been applied to the indicated CullTraverserData object.

The return value is true if this node should be visible, or false if it should be culled.

Reimplemented from PandaNode.

Reimplemented in FadeLODNode.

Definition at line 160 of file lodNode.cxx.

References consider_verify_lods(), PandaNode::get_child(), PandaNode::get_num_children(), LODNode::Switch::in_range_2(), is_any_shown(), show_switches_cull_callback(), and CullTraverser::traverse().

void LODNode::fillin ( DatagramIterator scan,
BamReader manager 
) [protected, virtual]

This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new LODNode.

Reimplemented from PandaNode.

Reimplemented in FadeLODNode.

Definition at line 805 of file lodNode.cxx.

References BamReader::read_cdata().

Referenced by make_from_bam().

void LODNode::force_switch ( int  index) [inline]

Forces the LODNode to show the indicated level instead of the level that would normally be shown based on the distance from the camera.

Definition at line 210 of file lodNode.I.

const LPoint3 & LODNode::get_center ( ) const [inline]

Returns the center of the LOD.

This is the point that is compared to the camera (in camera space) to determine the particular LOD that should be chosen.

Definition at line 254 of file lodNode.I.

int LODNode::get_highest_switch ( ) const [inline]

Returns the index number of the child with the highest level of detail; that is, the one that is designed to be seen from the closest to the camera.

This is usually the last child, but it is not necessarily so.

Definition at line 197 of file lodNode.I.

PN_stdfloat LODNode::get_in ( int  index) const [inline]

Returns the "in" distance of the indicated switch range.

This should be larger than the "out" distance of the same range.

Definition at line 154 of file lodNode.I.

PN_stdfloat LODNode::get_lod_scale ( ) const [inline]

Returns the multiplier for lod distances.

Definition at line 128 of file lodNode.I.

int LODNode::get_lowest_switch ( ) const [inline]

Returns the index number of the child with the lowest level of detail; that is, the one that is designed to be seen from the farthest away.

This is usually the first child, but it is not necessarily so.

Definition at line 183 of file lodNode.I.

int LODNode::get_num_switches ( ) const [inline]

Returns the number of switch ranges added to the LODNode.

This should correspond to the number of children of the node in order for the LODNode to function correctly.

Definition at line 117 of file lodNode.I.

PN_stdfloat LODNode::get_out ( int  index) const [inline]

Returns the "out" distance of the indicated switch range.

This should be smaller than the "in" distance of the same range.

Definition at line 168 of file lodNode.I.

Referenced by FadeLODNode::cull_callback().

void LODNode::hide_all_switches ( )

Hides all levels, restoring the LODNode to normal operation.

Definition at line 316 of file lodNode.cxx.

References PandaNode::mark_internal_bounds_stale().

void LODNode::hide_switch ( int  index)

Disables a previous call to show_switch().

Definition at line 289 of file lodNode.cxx.

References PandaNode::mark_internal_bounds_stale().

bool LODNode::is_any_shown ( ) const [inline]

Returns true if any switch has been shown with show_switch(), indicating the LODNode is in debug show mode; or false if it is in the normal mode.

Definition at line 267 of file lodNode.I.

Referenced by compute_internal_bounds(), cull_callback(), and FadeLODNode::cull_callback().

bool LODNode::is_lod_node ( ) const [virtual]

A simple downcast check.

Returns true if this kind of node happens to inherit from LODNode, false otherwise.

This is provided as a a faster alternative to calling is_of_type(LODNode::get_class_type()).

Reimplemented from PandaNode.

Definition at line 233 of file lodNode.cxx.

PandaNode * LODNode::make_copy ( ) const [virtual]

Returns a newly-allocated Node that is a shallow copy of this one.

It will be a different Node pointer, but its internal data may or may not be shared with that of the original Node.

Reimplemented from PandaNode.

Reimplemented in FadeLODNode.

Definition at line 75 of file lodNode.cxx.

TypedWritable * LODNode::make_from_bam ( const FactoryParams params) [static, protected]

This function is called by the BamReader's factory when a new object of type LODNode is encountered in the Bam file.

It should create the LODNode and extract its information from the file.

Reimplemented from PandaNode.

Reimplemented in FadeLODNode.

Definition at line 785 of file lodNode.cxx.

References fillin().

Referenced by register_with_read_factory().

void LODNode::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 PandaNode.

Reimplemented in FadeLODNode.

Definition at line 204 of file lodNode.cxx.

void LODNode::register_with_read_factory ( ) [static]

Tells the BamReader how to create objects of type LODNode.

Reimplemented from PandaNode.

Reimplemented in FadeLODNode.

Definition at line 760 of file lodNode.cxx.

References BamReader::get_factory(), make_from_bam(), and Factory< Type >::register_factory().

bool LODNode::safe_to_combine ( ) const [virtual]

Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of PandaNodes of compatible type, adding children or whatever.

For instance, an LODNode should not be combined with any other PandaNode, because its set of children is meaningful.

Reimplemented from PandaNode.

Definition at line 90 of file lodNode.cxx.

bool LODNode::safe_to_combine_children ( ) const [virtual]

Returns true if it is generally safe to combine the children of this PandaNode with each other.

For instance, an LODNode's children should not be combined with each other, because the set of children is meaningful.

Reimplemented from PandaNode.

Definition at line 104 of file lodNode.cxx.

void LODNode::set_center ( const LPoint3 center) [inline]

Specifies the center of the LOD.

This is the point that is compared to the camera (in camera space) to determine the particular LOD that should be chosen.

Definition at line 237 of file lodNode.I.

References PandaNode::mark_internal_bounds_stale().

void LODNode::set_lod_scale ( PN_stdfloat  value) [inline]

Sets the multiplier for lod distances.

A higher value means you'll see farther switchs than normal

Definition at line 140 of file lodNode.I.

bool LODNode::set_switch ( int  index,
PN_stdfloat  in,
PN_stdfloat  out 
) [inline]

Changes the switching range of a particular child of the LODNode.

See add_switch().

Definition at line 74 of file lodNode.I.

References PandaNode::mark_internal_bounds_stale().

void LODNode::show_all_switches ( )

Shows all levels in their default colors.

Definition at line 301 of file lodNode.cxx.

References PandaNode::mark_internal_bounds_stale().

void LODNode::show_switch ( int  index,
const LColor color 
)

This is provided as a debugging aid.

show_switch() will put the LODNode into a special mode where rather than computing and drawing the appropriate level of the LOD, a ring is drawn around the LODNode center indicating the switch distances from the camera for the indicated level, and the geometry of the indicated level is drawn in wireframe.

Multiple different levels can be visualized this way at once. Call hide_switch() or hide_all_switches() to undo this mode and restore the LODNode to its normal behavior.

Definition at line 277 of file lodNode.cxx.

References PandaNode::mark_internal_bounds_stale().

void LODNode::show_switch ( int  index)

This is provided as a debugging aid.

show_switch() will put the LODNode into a special mode where rather than computing and drawing the appropriate level of the LOD, a ring is drawn around the LODNode center indicating the switch distances from the camera for the indicated level, and the geometry of the indicated level is drawn in wireframe.

Multiple different levels can be visualized this way at once. Call hide_switch() or hide_all_switches() to undo this mode and restore the LODNode to its normal behavior.

Definition at line 254 of file lodNode.cxx.

References PandaNode::mark_internal_bounds_stale().

bool LODNode::show_switches_cull_callback ( CullTraverser trav,
CullTraverserData data 
) [protected]
bool LODNode::verify_child_bounds ( ) const

Returns true if the bounding volumes for the geometry of each fhild node entirely fits within the switch_in radius for that child, or false otherwise.

It is almost always a mistake for the geometry of an LOD level to be larger than its switch_in radius.

Definition at line 334 of file lodNode.cxx.

void LODNode::write_datagram ( BamWriter manager,
Datagram dg 
) [virtual]

Writes the contents of this object to the datagram for shipping out to a Bam file.

Reimplemented from PandaNode.

Reimplemented in FadeLODNode.

Definition at line 771 of file lodNode.cxx.

References BamWriter::write_cdata().

void LODNode::xform ( const LMatrix4 mat) [virtual]

Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so.

For most kinds of PandaNodes, this does nothing.

Reimplemented from PandaNode.

Definition at line 116 of file lodNode.cxx.

References LMatrix4f::get_row3(), and LVecBase3f::length().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations