Panda3D
cullTraverserData.I
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 cullTraverserData.I
10  * @author drose
11  * @date 2002-03-06
12  */
13 
14 /**
15  *
16  */
17 INLINE CullTraverserData::
18 CullTraverserData(const NodePath &start,
19  const TransformState *net_transform,
20  const RenderState *state,
21  GeometricBoundingVolume *view_frustum,
22  Thread *current_thread) :
23  _next(nullptr),
24  _start(start._head),
25  _node_reader(start.node(), current_thread),
26  _net_transform(net_transform),
27  _state(state),
28  _view_frustum(view_frustum),
29  _cull_planes(CullPlanes::make_empty()),
30  _draw_mask(DrawMask::all_on()),
31  _portal_depth(0)
32 {
33  // Only update the bounding volume if we're going to end up needing it.
34  bool check_bounds = (view_frustum != nullptr);
35  _node_reader.check_cached(check_bounds);
36 }
37 
38 /**
39  * This constructor creates a CullTraverserData object that reflects the next
40  * node down in the traversal.
41  */
42 INLINE CullTraverserData::
43 CullTraverserData(const CullTraverserData &parent, PandaNode *child) :
44  _next(&parent),
45 #ifdef _DEBUG
46  _start(nullptr),
47 #endif
48  _node_reader(child, parent._node_reader.get_current_thread()),
49  _net_transform(parent._net_transform),
50  _state(parent._state),
51  _view_frustum(parent._view_frustum),
52  _cull_planes(parent._cull_planes),
53  _draw_mask(parent._draw_mask),
54  _portal_depth(parent._portal_depth)
55 {
56  // Only update the bounding volume if we're going to end up needing it.
57  bool check_bounds = !_cull_planes->is_empty() ||
58  (_view_frustum != nullptr);
59  _node_reader.check_cached(check_bounds);
60 }
61 
62 /**
63  * Returns the node traversed to so far.
64  */
66 node() const {
67  return (PandaNode *)_node_reader.get_node();
68 }
69 
70 /**
71  * Returns the PipelineReader for the node traversed to so far.
72  */
75  return &_node_reader;
76 }
77 
78 /**
79  * Returns the PipelineReader for the node traversed to so far.
80  */
82 node_reader() const {
83  return &_node_reader;
84 }
85 
86 /**
87  * Constructs and returns an actual NodePath that represents the same path we
88  * have just traversed.
89  */
90 INLINE NodePath CullTraverserData::
91 get_node_path() const {
92  NodePath result;
93  result._head = r_get_node_path();
94  nassertr(result._head != nullptr, NodePath::fail());
95  return result;
96 }
97 
98 /**
99  * Returns the modelview transform: the relative transform from the camera to
100  * the model.
101  */
102 INLINE CPT(TransformState) CullTraverserData::
103 get_modelview_transform(const CullTraverser *trav) const {
104  return trav->get_world_transform()->compose(_net_transform);
105 }
106 
107 /**
108  * Returns the internal transform: the modelview transform in the GSG's
109  * internal coordinate system.
110  */
111 INLINE CPT(TransformState) CullTraverserData::
112 get_internal_transform(const CullTraverser *trav) const {
113  return trav->get_scene()->get_cs_world_transform()->compose(_net_transform);
114 }
115 
116 /**
117  * Returns the net transform: the relative transform from root of the scene
118  * graph to the current node.
119  */
120 INLINE const TransformState *CullTraverserData::
121 get_net_transform(const CullTraverser *) const {
122  return _net_transform;
123 }
124 
125 /**
126  * Returns true if the current node is within the view frustum, false
127  * otherwise. If the node's bounding volume falls completely within the view
128  * frustum, this will also reset the view frustum pointer, saving some work
129  * for future nodes.
130  */
131 INLINE bool CullTraverserData::
132 is_in_view(const DrawMask &camera_mask) {
133  if (_node_reader.get_transform()->is_invalid()) {
134  // If the transform is invalid, forget it.
135  return false;
136  }
137 
138  if (!_node_reader.compare_draw_mask(_draw_mask, camera_mask)) {
139  // If there are no draw bits in common with the camera, the node is out.
140  return false;
141  }
142 
143  if (_view_frustum == nullptr &&
144  _cull_planes->is_empty()) {
145  // If the transform is valid, but we don't have a frustum or any clip
146  // planes or occluders, it's always in.
147  return true;
148  }
149 
150  // Otherwise, compare the bounding volume to the frustum.
151  return is_in_view_impl();
152 }
153 
154 /**
155  * Returns true if this particular node is hidden, even though we might be
156  * traversing past this node to find a child node that has had show_through()
157  * called for it. If this returns true, the node should not be rendered.
158  */
159 INLINE bool CullTraverserData::
160 is_this_node_hidden(const DrawMask &camera_mask) const {
161  return (_draw_mask & PandaNode::get_overall_bit()).is_zero() ||
162  (_draw_mask & camera_mask).is_zero();
163 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
Indicates a coordinate-system transform on vertices.
const TransformState * get_transform() const
Returns the transform that has been set on this particular node.
Definition: pandaNode.I:1441
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:1269
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:268
This represents the set of clip planes and/or occluders that are definitely in effect for the current...
Definition: cullPlanes.h:42
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:4106
static NodePath fail()
Creates a NodePath with the ET_fail error type set.
Definition: nodePath.I:149
CPT(TransformState) CullTraverserData
Returns the modelview transform: the relative transform from the camera to the model.
const TransformState * get_world_transform() const
Returns the position of the starting node relative to the camera.
Definition: cullTraverser.I:75
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:47
bool is_invalid() const
Returns true if the transform represents an invalid matrix, for instance the result of inverting a si...
A thread; that is, a lightweight process.
Definition: thread.h:46
Encapsulates the data from a PandaNode, pre-fetched for one stage of the pipeline.
Definition: pandaNode.h:842
SceneSetup * get_scene() const
Returns the SceneSetup object.
Definition: cullTraverser.I:35
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45