Panda3D
cullTraverserData.I
1 // Filename: cullTraverserData.I
2 // Created by: drose (06Mar02)
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 ////////////////////////////////////////////////////////////////////
16 // Function: CullTraverserData::Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE CullTraverserData::
21 CullTraverserData(const NodePath &start,
22  const TransformState *net_transform,
23  const RenderState *state,
24  GeometricBoundingVolume *view_frustum,
25  Thread *current_thread) :
26  _node_path(start),
27  _node_reader(start.node(), current_thread),
28  _net_transform(net_transform),
29  _state(state),
30  _view_frustum(view_frustum),
31  _cull_planes(CullPlanes::make_empty()),
32  _draw_mask(DrawMask::all_on()),
33  _portal_depth(0)
34 {
35  // Only update the bounding volume if we're going to end up needing it.
36  bool check_bounds = (view_frustum != (GeometricBoundingVolume *)NULL);
37  _node_reader.check_cached(check_bounds);
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: CullTraverserData::Copy Constructor
42 // Access: Public
43 // Description:
44 ////////////////////////////////////////////////////////////////////
45 INLINE CullTraverserData::
46 CullTraverserData(const CullTraverserData &copy) :
47  _node_path(copy._node_path),
48  _node_reader(copy._node_reader),
49  _net_transform(copy._net_transform),
50  _state(copy._state),
51  _view_frustum(copy._view_frustum),
52  _cull_planes(copy._cull_planes),
53  _draw_mask(copy._draw_mask),
54  _portal_depth(copy._portal_depth)
55 {
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: CullTraverserData::Copy Assignment Operator
60 // Access: Public
61 // Description:
62 ////////////////////////////////////////////////////////////////////
63 INLINE void CullTraverserData::
64 operator = (const CullTraverserData &copy) {
65  _node_path = copy._node_path;
66  _node_reader = copy._node_reader;
67  _net_transform = copy._net_transform;
68  _state = copy._state;
69  _view_frustum = copy._view_frustum;
70  _cull_planes = copy._cull_planes;
71  _draw_mask = copy._draw_mask;
72  _portal_depth = copy._portal_depth;
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: CullTraverserData::Constructor
77 // Access: Public
78 // Description: This constructor creates a CullTraverserData object
79 // that reflects the next node down in the traversal.
80 ////////////////////////////////////////////////////////////////////
81 INLINE CullTraverserData::
82 CullTraverserData(const CullTraverserData &parent, PandaNode *child) :
83  _node_path(parent._node_path, child),
84  _node_reader(child, parent._node_reader.get_current_thread()),
85  _net_transform(parent._net_transform),
86  _state(parent._state),
87  _view_frustum(parent._view_frustum),
88  _cull_planes(parent._cull_planes),
89  _draw_mask(parent._draw_mask),
90  _portal_depth(parent._portal_depth)
91 {
92  // Only update the bounding volume if we're going to end up needing it.
93  bool check_bounds = !_cull_planes->is_empty() ||
94  (_view_frustum != (GeometricBoundingVolume *)NULL);
95  _node_reader.check_cached(check_bounds);
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: CullTraverserData::Destructor
100 // Access: Public
101 // Description:
102 ////////////////////////////////////////////////////////////////////
103 INLINE CullTraverserData::
104 ~CullTraverserData() {
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: CullTraverserData::node
109 // Access: Published
110 // Description: Returns the node traversed to so far.
111 ////////////////////////////////////////////////////////////////////
113 node() const {
114  return _node_path.node();
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: CullTraverserData::node_reader
119 // Access: Public
120 // Description: Returns the PipelineReader for the node traversed to
121 // so far.
122 ////////////////////////////////////////////////////////////////////
125  return &_node_reader;
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: CullTraverserData::node_reader
130 // Access: Public
131 // Description: Returns the PipelineReader for the node traversed to
132 // so far.
133 ////////////////////////////////////////////////////////////////////
135 node_reader() const {
136  return &_node_reader;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: CullTraverserData::get_modelview_transform
141 // Access: Published
142 // Description: Returns the modelview transform: the relative
143 // transform from the camera to the model.
144 ////////////////////////////////////////////////////////////////////
145 INLINE CPT(TransformState) CullTraverserData::
146 get_modelview_transform(const CullTraverser *trav) const {
147  return trav->get_world_transform()->compose(_net_transform);
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: CullTraverserData::get_internal_transform
152 // Access: Published
153 // Description: Returns the internal transform: the modelview
154 // transform in the GSG's internal coordinate system.
155 ////////////////////////////////////////////////////////////////////
156 INLINE CPT(TransformState) CullTraverserData::
157 get_internal_transform(const CullTraverser *trav) const {
158  return trav->get_scene()->get_cs_world_transform()->compose(_net_transform);
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: CullTraverserData::get_net_transform
163 // Access: Published
164 // Description: Returns the net transform: the relative transform
165 // from root of the scene graph to the current node.
166 ////////////////////////////////////////////////////////////////////
167 INLINE const TransformState *CullTraverserData::
168 get_net_transform(const CullTraverser *) const {
169  return _net_transform;
170 }
171 
172 ////////////////////////////////////////////////////////////////////
173 // Function: CullTraverserData::is_in_view
174 // Access: Published
175 // Description: Returns true if the current node is within the view
176 // frustum, false otherwise. If the node's bounding
177 // volume falls completely within the view frustum, this
178 // will also reset the view frustum pointer, saving some
179 // work for future nodes.
180 ////////////////////////////////////////////////////////////////////
181 INLINE bool CullTraverserData::
182 is_in_view(const DrawMask &camera_mask) {
183  if (_node_reader.get_transform()->is_invalid()) {
184  // If the transform is invalid, forget it.
185  return false;
186  }
187 
188  if (!_node_reader.compare_draw_mask(_draw_mask, camera_mask)) {
189  // If there are no draw bits in common with the camera, the node
190  // is out.
191  return false;
192  }
193 
194  if (_view_frustum == (GeometricBoundingVolume *)NULL &&
195  _cull_planes->is_empty()) {
196  // If the transform is valid, but we don't have a frustum or any
197  // clip planes or occluders, it's always in.
198  return true;
199  }
200 
201  // Otherwise, compare the bounding volume to the frustum.
202  return is_in_view_impl();
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: CullTraverserData::is_this_node_hidden
207 // Access: Published
208 // Description: Returns true if this particular node is hidden, even
209 // though we might be traversing past this node to find
210 // a child node that has had show_through() called for
211 // it. If this returns true, the node should not be
212 // rendered.
213 ////////////////////////////////////////////////////////////////////
214 INLINE bool CullTraverserData::
215 is_this_node_hidden(const DrawMask &camera_mask) const {
216  return (_draw_mask & PandaNode::get_overall_bit()).is_zero() ||
217  (_draw_mask & camera_mask).is_zero();
218 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
PandaNode * node() const
Returns the node traversed to so far.
const TransformState * get_transform() const
Returns the transform that has been set on this particular node.
Definition: pandaNode.I:1755
bool is_this_node_hidden(const DrawMask &camera_mask) const
Returns true if this particular node is hidden, even though we might be traversing past this node to ...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
bool compare_draw_mask(DrawMask running_draw_mask, DrawMask camera_mask) const
Compares the running draw mask computed during a traversal with this node's net draw masks...
Definition: pandaNode.I:1542
const TransformState * get_cs_world_transform() const
Returns the position from the starting node relative to the camera, in the GSG's internal coordinate ...
Definition: sceneSetup.I:341
This represents the set of clip planes and/or occluders that are definitely in effect for the current...
Definition: cullPlanes.h:46
PandaNode * node() const
Returns the node traversed to so far.
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
void check_cached(bool update_bounds) const
Ensures that the draw masks etc.
Definition: pandaNode.cxx:4812
const TransformState * get_world_transform() const
Returns the position of the starting node relative to the camera.
Definition: cullTraverser.I:94
PandaNodePipelineReader * node_reader()
Returns the PipelineReader for the node traversed to so far.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
A thread; that is, a lightweight process.
Definition: thread.h:51
Encapsulates the data from a PandaNode, pre-fetched for one stage of the pipeline.
Definition: pandaNode.h:815
SceneSetup * get_scene() const
Returns the SceneSetup object.
Definition: cullTraverser.I:43
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