Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE CullTraverserData::
18CullTraverserData(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 */
42INLINE CullTraverserData::
43CullTraverserData(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 */
66node() 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 */
82node_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 */
91get_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 */
102INLINE CPT(TransformState) CullTraverserData::
103get_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 */
111INLINE CPT(TransformState) CullTraverserData::
112get_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 */
120INLINE const TransformState *CullTraverserData::
121get_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 */
131INLINE bool CullTraverserData::
132is_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 */
160is_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}
This represents the set of clip planes and/or occluders that are definitely in effect for the current...
Definition cullPlanes.h:42
This collects together the pieces of data that are accumulated for each node while walking the scene ...
PandaNode * node() const
Returns the node traversed to so far.
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 ...
PandaNodePipelineReader * node_reader()
Returns the PipelineReader for the node traversed to so far.
get_node_path
Constructs and returns an actual NodePath that represents the same path we have just traversed.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
const TransformState * get_world_transform() const
Returns the position of the starting node relative to the camera.
SceneSetup * get_scene() const
Returns the SceneSetup object.
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
static NodePath fail()
Creates a NodePath with the ET_fail error type set.
Definition nodePath.I:149
Encapsulates the data from a PandaNode, pre-fetched for one stage of the pipeline.
Definition pandaNode.h:840
const TransformState * get_transform() const
Returns the transform that has been set on this particular node.
Definition pandaNode.I:1441
void check_cached(bool update_bounds) const
Ensures that the draw masks etc.
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
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
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
A thread; that is, a lightweight process.
Definition thread.h:46
Indicates a coordinate-system transform on vertices.
bool is_invalid() const
Returns true if the transform represents an invalid matrix, for instance the result of inverting a si...