Panda3D
rigidBodyCombiner.h
1 // Filename: rigidBodyCombiner.h
2 // Created by: drose (22Feb07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef RIGIDBODYCOMBINER_H
16 #define RIGIDBODYCOMBINER_H
17 
18 #include "pandabase.h"
19 
20 #include "pandaNode.h"
21 #include "nodeVertexTransform.h"
22 #include "pvector.h"
23 
24 class NodePath;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : RigidBodyCombiner
28 // Description : This is a special node that combines multiple
29 // independently-moving rigid nodes into one Geom
30 // internally (or as few Geoms as possible), for the
31 // purposes of improving rendering performance.
32 //
33 // To use it, parent a number of moving objects to this
34 // node and call collect(). A child node is identified
35 // as "moving" if (a) it has a non-identity transform
36 // initially, or (b) it is a ModelNode with the
37 // preserve_transform flag set. Any other nodes will be
38 // considered static, and later transforms applied to
39 // them will not be identified.
40 //
41 // You should call collect() only at startup or if you
42 // change the set of children; it is a relatively
43 // expensive call.
44 //
45 // Once you call collect(), you may change the
46 // transforms on the child nodes freely without having
47 // to call collect() again.
48 //
49 // RenderEffects such as Billboards are not supported
50 // below this node.
51 ////////////////////////////////////////////////////////////////////
52 class EXPCL_PANDA_GRUTIL RigidBodyCombiner : public PandaNode {
53 PUBLISHED:
54  RigidBodyCombiner(const string &name);
55 protected:
57  virtual PandaNode *make_copy() const;
58 
59 PUBLISHED:
60  void collect();
61 
62  NodePath get_internal_scene();
63 
64 public:
65  // From parent class PandaNode
66  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
67 
68 private:
69  void r_collect(PandaNode *node, const RenderState *state,
70  const VertexTransform *transform);
71  PT(GeomVertexData) convert_vd(const VertexTransform *transform,
72  const GeomVertexData *orig);
73 
74  PT(PandaNode) _internal_root;
75 
77  Transforms _internal_transforms;
78 
79  class VDUnifier {
80  public:
81  INLINE VDUnifier(const VertexTransform *transform,
82  const GeomVertexData *orig);
83  INLINE bool operator < (const VDUnifier &other) const;
84 
85  const VertexTransform *_transform;
86  const GeomVertexData *_orig;
87  };
88 
90  VDTable _vd_table;
91 
92 
93 public:
94  static TypeHandle get_class_type() {
95  return _type_handle;
96  }
97  static void init_type() {
98  PandaNode::init_type();
99  register_type(_type_handle, "RigidBodyCombiner",
100  PandaNode::get_class_type());
101  }
102  virtual TypeHandle get_type() const {
103  return get_class_type();
104  }
105  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
106 
107 private:
108  static TypeHandle _type_handle;
109 };
110 
111 #include "rigidBodyCombiner.I"
112 
113 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is a special node that combines multiple independently-moving rigid nodes into one Geom internal...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is an abstract base class that holds a pointer to some transform, computed in some arbitrary way...
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48