Panda3D

rigidBodyCombiner.h

00001 // Filename: rigidBodyCombiner.h
00002 // Created by:  drose (22Feb07)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef RIGIDBODYCOMBINER_H
00016 #define RIGIDBODYCOMBINER_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "pandaNode.h"
00021 #include "nodeVertexTransform.h"
00022 #include "pvector.h"
00023 
00024 class NodePath;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : RigidBodyCombiner
00028 // Description : This is a special node that combines multiple
00029 //               independently-moving rigid nodes into one Geom
00030 //               internally (or as few Geoms as possible), for the
00031 //               purposes of improving rendering performance.
00032 //
00033 //               To use it, parent a number of moving objects to this
00034 //               node and call collect().  A child node is identified
00035 //               as "moving" if (a) it has a non-identity transform
00036 //               initially, or (b) it is a ModelNode with the
00037 //               preserve_transform flag set.  Any other nodes will be
00038 //               considered static, and later transforms applied to
00039 //               them will not be identified.
00040 //
00041 //               You should call collect() only at startup or if you
00042 //               change the set of children; it is a relatively
00043 //               expensive call.
00044 //
00045 //               Once you call collect(), you may change the
00046 //               transforms on the child nodes freely without having
00047 //               to call collect() again.
00048 //
00049 //               RenderEffects such as Billboards are not supported
00050 //               below this node.
00051 ////////////////////////////////////////////////////////////////////
00052 class EXPCL_PANDA_GRUTIL RigidBodyCombiner : public PandaNode {
00053 PUBLISHED:
00054   RigidBodyCombiner(const string &name);
00055 protected:
00056   RigidBodyCombiner(const RigidBodyCombiner &copy);
00057   virtual PandaNode *make_copy() const;
00058 
00059 PUBLISHED:
00060   void collect();
00061 
00062   NodePath get_internal_scene();
00063 
00064 public:
00065   // From parent class PandaNode
00066   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00067 
00068 private:
00069   void r_collect(PandaNode *node, const RenderState *state, 
00070                  const VertexTransform *transform);
00071   PT(GeomVertexData) convert_vd(const VertexTransform *transform, 
00072                                 const GeomVertexData *orig);
00073 
00074   PT(PandaNode) _internal_root;
00075 
00076   typedef pvector< PT(NodeVertexTransform) > Transforms;
00077   Transforms _internal_transforms;
00078 
00079   class VDUnifier {
00080   public:
00081     INLINE VDUnifier(const VertexTransform *transform, 
00082                      const GeomVertexData *orig);
00083     INLINE bool operator < (const VDUnifier &other) const;
00084 
00085     const VertexTransform *_transform;
00086     const GeomVertexData *_orig;
00087   };
00088 
00089   typedef pmap<VDUnifier, PT(GeomVertexData) > VDTable;
00090   VDTable _vd_table;
00091 
00092 
00093 public:
00094   static TypeHandle get_class_type() {
00095     return _type_handle;
00096   }
00097   static void init_type() {
00098     PandaNode::init_type();
00099     register_type(_type_handle, "RigidBodyCombiner",
00100                   PandaNode::get_class_type());
00101   }
00102   virtual TypeHandle get_type() const {
00103     return get_class_type();
00104   }
00105   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00106 
00107 private:
00108   static TypeHandle _type_handle;
00109 };
00110 
00111 #include "rigidBodyCombiner.I"
00112 
00113 #endif
 All Classes Functions Variables Enumerations