A node that holds Geom objects, renderable pieces of geometry. More...

#include "geomNode.h"

Inheritance diagram for GeomNode:
PandaNode TypedWritable Namable LinkedListNode ReferenceCount TypedObject MemoryBase MemoryBase PhysxClothNode PhysxDebugGeomNode PhysxSoftBodyNode

List of all members.

Classes

class  BamAuxData
class  CData
class  GeomEntry
class  Geoms

Public Member Functions

 GeomNode (const string &name)
virtual void add_for_draw (CullTraverser *trav, CullTraverserData &data)
 Adds the node's contents to the CullResult we are building up during the cull traversal, so that it will be drawn at render time.
void add_geom (Geom *geom, const RenderState *state=RenderState::make_empty())
 Adds a new Geom to the node.
void add_geoms_from (const GeomNode *other)
 Copies the Geoms (and their associated RenderStates) from the indicated GeomNode into this one.
virtual void apply_attribs_to_vertices (const AccumulatedAttribs &attribs, int attrib_types, GeomTransformer &transformer)
 Applies whatever attributes are specified in the AccumulatedAttribs object (and by the attrib_types bitmask) to the vertices on this node, if appropriate.
bool check_valid () const
 Verifies that the each Geom within the GeomNode reference vertices that actually exist within its GeomVertexData.
virtual PandaNodecombine_with (PandaNode *other)
 Collapses this node with the other node, if possible, and returns a pointer to the combined node, or NULL if the two nodes cannot safely be combined.
 CPT (Geom) get_geom(int n) const
virtual CPT (TransformState) calc_tight_bounds(LPoint3f &min_point
void decompose ()
 Calls decompose() on each Geom with the GeomNode.
void do_premunge (GraphicsStateGuardianBase *gsg, const RenderState *node_state, GeomTransformer &transformer)
 Uses the indicated GSG to premunge the Geoms in this node to optimize them for eventual rendering.
virtual void finalize (BamReader *manager)
 Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.
virtual TypeHandle force_init_type ()
const RenderStateget_geom_state (int n) const
 Returns the RenderState associated with the nth geom of the node.
Geoms get_geoms (Thread *current_thread=Thread::get_current_thread()) const
 Returns an object that can be used to walk through the list of geoms of the node.
virtual CollideMask get_legal_collide_mask () const
 Returns the subset of CollideMask bits that may be set for this particular type of PandaNode.
int get_num_geoms () const
 Returns the number of geoms in the node.
bool get_preserved () const
 Returns the "preserved" flag.
virtual TypeHandle get_type () const
virtual bool is_geom_node () const
 A simple downcast check.
virtual bool is_renderable () const
 Returns true if there is some value to visiting this particular node during the cull traversal for any camera, false otherwise.
virtual PandaNodemake_copy () const
 Returns a newly-allocated PandaNode that is a shallow copy of this one.
 MAKE_SEQ (get_geom_states, get_num_geoms, get_geom_state)
 MAKE_SEQ (get_geoms, get_num_geoms, get_geom)
virtual void output (ostream &out) const
 Outputs the Namable.
 PT (Geom) modify_geom(int n)
virtual void r_prepare_scene (const RenderState *state, PreparedGraphicsObjects *prepared_objects, Thread *current_thread)
 The recursive implementation of prepare_scene().
void remove_all_geoms ()
 Removes all the geoms from the node at once.
void remove_geom (int n)
 Removes the nth geom from the node.
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_flatten () const
 Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating instances (by calling dupe_for_flatten()), false otherwise (for instance, a Camera cannot be safely flattened, because the Camera pointer itself is meaningful).
void set_geom (int n, Geom *geom)
 Replaces the nth Geom of the node with a new pointer.
void set_geom_state (int n, const RenderState *state)
 Changes the RenderState associated with the nth geom of the node.
void set_preserved (bool value)
 Sets the "preserved" flag.
void unify (int max_indices, bool preserve_order)
 Attempts to unify all of the Geoms contained within this node into a single Geom, or at least as few Geoms as possible.
virtual void write_datagram (BamWriter *manager, Datagram &dg)
 Writes the contents of this object to the datagram for shipping out to a Bam file.
void write_geoms (ostream &out, int indent_level) const
 Writes a short description of all the Geoms in the node.
void write_verbose (ostream &out, int indent_level) const
 Writes a detailed description of all the Geoms in the node.
virtual void xform (const LMatrix4f &mat)
 Transforms the contents of this node by the indicated matrix, if it means anything to do so.

Static Public Member Functions

static TypeHandle get_class_type ()
static CollideMask get_default_collide_mask ()
 Returns the default into_collide_mask assigned to new GeomNodes.
static void init_type ()
static void register_with_read_factory ()
 Tells the BamReader how to create objects of type GeomNode.

Public Attributes

virtual LPoint3f bool const
TransformState Thread
*current_thread 
const
virtual LPoint3f bool & found_any
virtual LPoint3fmax_point
virtual LPoint3f bool const
TransformState
transform

Protected Member Functions

 GeomNode (const GeomNode &copy)
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 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 GeomNode.
virtual void r_mark_geom_bounds_stale (Thread *current_thread)
 Recursively calls Geom::mark_bounds_stale() on every Geom at this node and below.

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 GeomNode is encountered in the Bam file.

Friends

class GeomTransformer

Detailed Description

A node that holds Geom objects, renderable pieces of geometry.

This is the primary kind of leaf node in the scene graph; almost all visible objects will be contained in a GeomNode somewhere.

Definition at line 37 of file geomNode.h.


Member Function Documentation

void GeomNode::add_for_draw ( CullTraverser trav,
CullTraverserData data 
) [virtual]

Adds the node's contents to the CullResult we are building up during the cull traversal, so that it will be drawn at render time.

For most nodes other than GeomNodes, this is a do-nothing operation.

Reimplemented from PandaNode.

Definition at line 505 of file geomNode.cxx.

References CullTraverser::get_cull_handler(), CullTraverser::get_current_thread(), GeomNode::Geoms::get_geom_state(), get_geoms(), CullTraverser::get_gsg(), CullTraverserData::get_net_transform(), GeomNode::Geoms::get_num_geoms(), Geom::is_empty(), and CullHandler::record_object().

void GeomNode::add_geom ( Geom geom,
const RenderState state = RenderState::make_empty() 
)

Adds a new Geom to the node.

The geom is given the indicated state (which may be RenderState::make_empty(), to completely inherit its state from the scene graph).

Definition at line 598 of file geomNode.cxx.

References Geom::check_valid(), Thread::get_current_thread(), and PandaNode::mark_internal_bounds_stale().

Referenced by LineSegs::create(), GeomTransformer::doubleside(), Spotlight::fill_viz_geom(), and WindowFramework::load_default_model().

void GeomNode::add_geoms_from ( const GeomNode other)

Copies the Geoms (and their associated RenderStates) from the indicated GeomNode into this one.

Definition at line 621 of file geomNode.cxx.

References Thread::get_current_thread(), and PandaNode::mark_internal_bounds_stale().

Referenced by combine_with().

void GeomNode::apply_attribs_to_vertices ( const AccumulatedAttribs attribs,
int  attrib_types,
GeomTransformer transformer 
) [virtual]
bool GeomNode::check_valid ( ) const

Verifies that the each Geom within the GeomNode reference vertices that actually exist within its GeomVertexData.

Returns true if the GeomNode appears to be valid, false otherwise.

Definition at line 676 of file geomNode.cxx.

References Geom::check_valid(), and get_num_geoms().

PandaNode * GeomNode::combine_with ( PandaNode other) [virtual]

Collapses this node with the other node, if possible, and returns a pointer to the combined node, or NULL if the two nodes cannot safely be combined.

The return value may be this, other, or a new node altogether.

This function is called from GraphReducer::flatten(), and need not deal with children; its job is just to decide whether to collapse the two nodes and what the collapsed node should look like.

Reimplemented from PandaNode.

Definition at line 430 of file geomNode.cxx.

References add_geoms_from(), and TypedObject::is_exact_type().

void GeomNode::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 965 of file geomNode.cxx.

References BoundingVolume::around(), and PandaNode::get_bounds_type().

void GeomNode::decompose ( )

Calls decompose() on each Geom with the GeomNode.

This decomposes higher-order primitive types, like triangle strips, into lower-order types like indexed triangles. Normally there is no reason to do this, but it can be useful as an early preprocessing step, to allow a later call to unify() to proceed more quickly.

See also SceneGraphReducer::decompose(), which is the normal way this is called.

Definition at line 703 of file geomNode.cxx.

References Thread::get_current_thread().

Referenced by SceneGraphReducer::r_decompose().

void GeomNode::do_premunge ( GraphicsStateGuardianBase gsg,
const RenderState node_state,
GeomTransformer transformer 
)

Uses the indicated GSG to premunge the Geoms in this node to optimize them for eventual rendering.

See SceneGraphReducer::premunge().

Definition at line 911 of file geomNode.cxx.

References Thread::get_current_thread().

Referenced by SceneGraphReducer::r_premunge().

void GeomNode::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 GeomNode.

Reimplemented from PandaNode.

Definition at line 1136 of file geomNode.cxx.

References BamReader::read_cdata().

Referenced by make_from_bam().

void GeomNode::finalize ( BamReader manager) [virtual]

Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.

Reimplemented from TypedWritable.

Definition at line 1055 of file geomNode.cxx.

References BamReader::finalize_now(), Thread::get_current_thread(), BamReader::get_file_minor_ver(), and BamReader::set_aux_data().

CollideMask GeomNode::get_default_collide_mask ( ) [inline, static]

Returns the default into_collide_mask assigned to new GeomNodes.

Definition at line 172 of file geomNode.I.

const RenderState * GeomNode::get_geom_state ( int  n) const [inline]

Returns the RenderState associated with the nth geom of the node.

This is just the RenderState directly associated with the Geom; the actual state in which the Geom is rendered will also be affected by RenderStates that appear on the scene graph in nodes above this GeomNode.

Definition at line 106 of file geomNode.I.

Referenced by GeomTransformer::doubleside().

GeomNode::Geoms GeomNode::get_geoms ( Thread current_thread = Thread::get_current_thread()) const [inline]

Returns an object that can be used to walk through the list of geoms of the node.

When you intend to visit multiple geoms, using this is slightly faster than calling get_geom() directly on the GeomNode, since this object avoids reopening the PipelineCycler each time.

This object also protects you from self-modifying loops (e.g. adding or removing geoms during traversal), since a virtual copy of the geoms is made ahead of time. The virtual copy is fast--it is a form of copy-on-write, so the list is not actually copied unless it is modified during the traversal.

Definition at line 223 of file geomNode.I.

Referenced by add_for_draw().

CollideMask GeomNode::get_legal_collide_mask ( ) const [virtual]

Returns the subset of CollideMask bits that may be set for this particular type of PandaNode.

For most nodes, this is 0; it doesn't make sense to set a CollideMask for most kinds of nodes.

For nodes that can be collided with, such as GeomNode and CollisionNode, this returns all bits on.

Reimplemented from PandaNode.

Definition at line 585 of file geomNode.cxx.

References BitMask< WType, nbits >::all_on().

bool GeomNode::get_preserved ( ) const [inline]

Returns the "preserved" flag.

When this is true, the GeomNode will be left untouched by any flatten operations.

Definition at line 36 of file geomNode.I.

bool GeomNode::is_geom_node ( ) const [virtual]

A simple downcast check.

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

This is provided as a a faster alternative to calling is_of_type(GeomNode::get_class_type()), since this test is so important to rendering.

Reimplemented from PandaNode.

Definition at line 899 of file geomNode.cxx.

bool GeomNode::is_renderable ( ) const [virtual]

Returns true if there is some value to visiting this particular node during the cull traversal for any camera, false otherwise.

This will be used to optimize the result of get_net_draw_show_mask(), so that any subtrees that contain only nodes for which is_renderable() is false need not be visited.

Reimplemented from PandaNode.

Definition at line 492 of file geomNode.cxx.

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

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

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

Reimplemented from PandaNode.

Definition at line 89 of file geomNode.cxx.

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

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

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

Reimplemented from PandaNode.

Definition at line 1113 of file geomNode.cxx.

References fillin(), BamReader::get_file_minor_ver(), and BamReader::register_finalize().

Referenced by register_with_read_factory().

void GeomNode::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.

Definition at line 858 of file geomNode.cxx.

void GeomNode::r_mark_geom_bounds_stale ( Thread current_thread) [protected, virtual]

Recursively calls Geom::mark_bounds_stale() on every Geom at this node and below.

Reimplemented from PandaNode.

Definition at line 939 of file geomNode.cxx.

References PandaNode::mark_internal_bounds_stale().

void GeomNode::r_prepare_scene ( const RenderState state,
PreparedGraphicsObjects prepared_objects,
Thread current_thread 
) [virtual]

The recursive implementation of prepare_scene().

Don't call this directly; call PandaNode::prepare_scene() or NodePath::prepare_scene() instead.

Reimplemented from PandaNode.

Definition at line 387 of file geomNode.cxx.

References TextureAttrib::get_num_on_stages(), TextureAttrib::get_on_stage(), TextureAttrib::get_on_texture(), and Texture::prepare().

void GeomNode::register_with_read_factory ( ) [static]

Tells the BamReader how to create objects of type GeomNode.

Reimplemented from PandaNode.

Definition at line 1031 of file geomNode.cxx.

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

void GeomNode::remove_all_geoms ( ) [inline]

Removes all the geoms from the node at once.

Definition at line 159 of file geomNode.I.

References PandaNode::mark_internal_bounds_stale().

Referenced by SpriteParticleRenderer::~SpriteParticleRenderer().

void GeomNode::remove_geom ( int  n) [inline]

Removes the nth geom from the node.

Definition at line 144 of file geomNode.I.

References PandaNode::mark_internal_bounds_stale().

bool GeomNode::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 370 of file geomNode.cxx.

bool GeomNode::safe_to_flatten ( ) const [virtual]

Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating instances (by calling dupe_for_flatten()), false otherwise (for instance, a Camera cannot be safely flattened, because the Camera pointer itself is meaningful).

Reimplemented from PandaNode.

Definition at line 351 of file geomNode.cxx.

void GeomNode::set_geom ( int  n,
Geom geom 
)

Replaces the nth Geom of the node with a new pointer.

There must already be a Geom in this slot.

Note that if this method is called in a downstream stage (for instance, during cull or draw), then it will propagate the new list of Geoms upstream all the way to pipeline stage 0, which may step on changes that were made independently in pipeline stage 0. Use with caution.

Definition at line 655 of file geomNode.cxx.

References Geom::check_valid(), and PandaNode::mark_internal_bounds_stale().

void GeomNode::set_geom_state ( int  n,
const RenderState state 
) [inline]

Changes the RenderState associated with the nth geom of the node.

This is just the RenderState directly associated with the Geom; the actual state in which the Geom is rendered will also be affected by RenderStates that appear on the scene graph in nodes above this GeomNode.

Note that if this method is called in a downstream stage (for instance, during cull or draw), then it will propagate the new list of Geoms upstream all the way to pipeline stage 0, which may step on changes that were made independently in pipeline stage 0. Use with caution.

Definition at line 131 of file geomNode.I.

void GeomNode::set_preserved ( bool  value) [inline]

Sets the "preserved" flag.

When this is true, the GeomNode will be left untouched by any flatten operations.

Definition at line 24 of file geomNode.I.

void GeomNode::unify ( int  max_indices,
bool  preserve_order 
)

Attempts to unify all of the Geoms contained within this node into a single Geom, or at least as few Geoms as possible.

In turn, the individual GeomPrimitives contained within each resulting Geom are also unified. The goal is to reduce the number of GeomPrimitives within the node as far as possible. This may result in composite primitives, such as triangle strips and triangle fans, being decomposed into triangles. See also Geom::unify().

max_indices represents the maximum number of indices that will be put in any one GeomPrimitive. If preserve_order is true, then the primitives will not be reordered during the operation, even if this results in a suboptimal result.

In order for this to be successful, the primitives must reference the same GeomVertexData, have the same fundamental primitive type, and have compatible shade models.

Definition at line 745 of file geomNode.cxx.

References Thread::get_current_thread(), and PandaNode::mark_internal_bounds_stale().

Referenced by SceneGraphReducer::r_unify().

void GeomNode::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.

Definition at line 1042 of file geomNode.cxx.

References BamWriter::write_cdata().

void GeomNode::write_geoms ( ostream &  out,
int  indent_level 
) const

Writes a short description of all the Geoms in the node.

Definition at line 819 of file geomNode.cxx.

void GeomNode::write_verbose ( ostream &  out,
int  indent_level 
) const

Writes a detailed description of all the Geoms in the node.

Definition at line 838 of file geomNode.cxx.

void GeomNode::xform ( const LMatrix4f mat) [virtual]

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

For most kinds of nodes, this does nothing.

For a GeomNode, this does the right thing, but it is better to use a GeomTransformer instead, since it will share the new arrays properly between different GeomNodes.

Reimplemented from PandaNode.

Definition at line 334 of file geomNode.cxx.

References GeomTransformer::transform_vertices().


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