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