Panda3D
Loading...
Searching...
No Matches
eggNode.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 eggNode.I
10 * @author drose
11 * @date 1999-02-10
12 */
13
14/**
15 *
16 */
17INLINE EggNode::
18EggNode(const std::string &name) : EggNamedObject(name) {
19 _parent = nullptr;
20 _depth = 0;
21 _under_flags = 0;
22}
23
24/**
25 *
26 */
27INLINE EggNode::
28EggNode(const EggNode &copy) : EggNamedObject(copy) {
29 _parent = nullptr;
30 _depth = 0;
31 _under_flags = 0;
32}
33
34
35/**
36 *
37 */
38INLINE EggNode &EggNode::
39operator = (const EggNode &copy) {
40 EggNamedObject::operator = (copy);
41 update_under(0);
42 return *this;
43}
44
45
46/**
47 *
48 */
49INLINE EggGroupNode *EggNode::
50get_parent() const {
51 return _parent;
52}
53
54/**
55 * Returns the number of nodes above this node in the egg hierarchy.
56 */
57INLINE int EggNode::
58get_depth() const {
59 return _depth;
60}
61
62
63/**
64 * Returns true if there is an <Instance> node somewhere in the egg tree at or
65 * above this node, false otherwise.
66 */
67INLINE bool EggNode::
68is_under_instance() const {
69 return (_under_flags & UF_under_instance) != 0;
70}
71
72/**
73 * Returns true if there is a <Transform> entry somewhere in the egg tree at
74 * or above this node, false otherwise.
75 */
76INLINE bool EggNode::
77is_under_transform() const {
78 return (_under_flags & UF_under_transform) != 0;
79}
80
81/**
82 * Returns true if this node's vertices are not in the global coordinate
83 * space. This will be the case if there was an <Instance> node under a
84 * transform at or above this node.
85 */
86INLINE bool EggNode::
87is_local_coord() const {
88 return (_under_flags & UF_local_coord) != 0;
89}
90
91
92/**
93 * Returns the coordinate frame of the vertices referenced by primitives at or
94 * under this node. This is not the same as get_node_frame().
95 *
96 * Generally, vertices in an egg file are stored in the global coordinate
97 * space, regardless of the transforms defined at each node. Thus,
98 * get_vertex_frame() will usually return the identity transform (global
99 * coordinate space). However, primitives under an <Instance> entry reference
100 * their vertices in the coordinate system under effect at the time of the
101 * <Instance>. Thus, nodes under an <Instance> entry may return this non-
102 * identity matrix.
103 *
104 * Specifically, this may return a non-identity matrix only if
105 * is_local_coord() is true.
106 */
107INLINE const LMatrix4d &EggNode::
108get_vertex_frame() const {
109 if (_vertex_frame == nullptr) {
110 return LMatrix4d::ident_mat();
111 } else {
112 return *_vertex_frame;
113 }
114}
115
116
117/**
118 * Returns the coordinate frame of the node itself. This is simply the net
119 * product of all transformations up to the root.
120 */
121INLINE const LMatrix4d &EggNode::
122get_node_frame() const {
123 if (_node_frame == nullptr) {
124 return LMatrix4d::ident_mat();
125 } else {
126 return *_node_frame;
127 }
128}
129
130/**
131 * Returns the inverse of the matrix returned by get_vertex_frame(). See
132 * get_vertex_frame().
133 */
134INLINE const LMatrix4d &EggNode::
135get_vertex_frame_inv() const {
136 if (_vertex_frame_inv == nullptr) {
137 return LMatrix4d::ident_mat();
138 } else {
139 return *_vertex_frame_inv;
140 }
141}
142
143
144/**
145 * Returns the inverse of the matrix returned by get_node_frame(). See
146 * get_node_frame().
147 */
148INLINE const LMatrix4d &EggNode::
149get_node_frame_inv() const {
150 if (_node_frame_inv == nullptr) {
151 return LMatrix4d::ident_mat();
152 } else {
153 return *_node_frame_inv;
154 }
155}
156
157/**
158 * Returns the transformation matrix suitable for converting the vertices as
159 * read from the egg file into the coordinate space of the node. This is the
160 * same thing as:
161 *
162 * get_vertex_frame() * get_node_frame_inv()
163 *
164 */
165INLINE const LMatrix4d &EggNode::
166get_vertex_to_node() const {
167 if (_vertex_to_node == nullptr) {
168 return LMatrix4d::ident_mat();
169 } else {
170 return *_vertex_to_node;
171 }
172}
173
174/**
175 * Returns the transformation matrix suitable for converting vertices in the
176 * coordinate space of the node to the appropriate coordinate space for
177 * storing in the egg file. This is the same thing as:
178 *
179 * get_node_frame() * get_vertex_frame_inv()
180 *
181 */
182INLINE const LMatrix4d &EggNode::
183get_node_to_vertex() const {
184 if (_node_to_vertex == nullptr) {
185 return LMatrix4d::ident_mat();
186 } else {
187 return *_node_to_vertex;
188 }
189}
190
191/**
192 * Returns either a NULL pointer or a unique pointer shared by nodes with the
193 * same get_vertex_frame() matrix.
194 */
195INLINE const LMatrix4d *EggNode::
196get_vertex_frame_ptr() const {
197 return _vertex_frame;
198}
199
200
201/**
202 * Returns either a NULL pointer or a unique pointer shared by nodes with the
203 * same get_node_frame() matrix.
204 */
205INLINE const LMatrix4d *EggNode::
206get_node_frame_ptr() const {
207 return _node_frame;
208}
209
210/**
211 * Returns either a NULL pointer or a unique pointer shared by nodes with the
212 * same get_vertex_frame_inv() matrix.
213 */
214INLINE const LMatrix4d *EggNode::
216 return _vertex_frame_inv;
217}
218
219
220/**
221 * Returns either a NULL pointer or a unique pointer shared by nodes with the
222 * same get_node_frame_inv() matrix.
223 */
224INLINE const LMatrix4d *EggNode::
226 return _node_frame_inv;
227}
228
229/**
230 * Returns either a NULL pointer or a unique pointer shared by nodes with the
231 * same get_vertex_to_node() matrix.
232 */
233INLINE const LMatrix4d *EggNode::
235 return _vertex_to_node;
236}
237
238/**
239 * Returns either a NULL pointer or a unique pointer shared by nodes with the
240 * same get_node_to_vertex() matrix.
241 */
242INLINE const LMatrix4d *EggNode::
244 return _node_to_vertex;
245}
246
247
248/**
249 * Applies the indicated transformation to the node and all of its
250 * descendants.
251 */
252INLINE void EggNode::
253transform(const LMatrix4d &mat) {
254 LMatrix4d inv = invert(mat);
255
256 r_transform(mat, inv, CS_default);
257 r_transform_vertices(mat);
258
259 // Now we have to recompute the under_flags to ensure that all the cached
260 // relative matrices are correct.
261 update_under(0);
262}
263
264/**
265 * Applies the indicated transformation only to vertices that appear in global
266 * space within vertex pools at this node and below. Joints and other
267 * transforms are not affected, nor are local vertices.
268 */
269INLINE void EggNode::
270transform_vertices_only(const LMatrix4d &mat) {
271 r_transform_vertices(mat);
272}
273
274/**
275 * Removes any transform and instance records from this node in the scene
276 * graph and below. If an instance node is encountered, removes the instance
277 * and applies the transform to its vertices, duplicating vertices if
278 * necessary.
279 *
280 * Since this function may result in duplicated vertices, it may be a good
281 * idea to call remove_unused_vertices() after calling this.
282 */
283INLINE void EggNode::
285 r_flatten_transforms();
286 update_under(0);
287}
A base class for nodes in the hierarchy that are not leaf nodes.
This is a fairly low-level base class–any egg object that has a name.
A base class for things that may be directly added into the egg hierarchy.
Definition eggNode.h:36
const LMatrix4d & get_vertex_frame_inv() const
Returns the inverse of the matrix returned by get_vertex_frame().
Definition eggNode.I:135
const LMatrix4d & get_vertex_to_node() const
Returns the transformation matrix suitable for converting the vertices as read from the egg file into...
Definition eggNode.I:166
void transform_vertices_only(const LMatrix4d &mat)
Applies the indicated transformation only to vertices that appear in global space within vertex pools...
Definition eggNode.I:270
const LMatrix4d * get_vertex_frame_inv_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_vertex_frame_inv(...
Definition eggNode.I:215
bool is_under_instance() const
Returns true if there is an <Instance> node somewhere in the egg tree at or above this node,...
Definition eggNode.I:68
const LMatrix4d * get_vertex_to_node_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_vertex_to_node() ...
Definition eggNode.I:234
void transform(const LMatrix4d &mat)
Applies the indicated transformation to the node and all of its descendants.
Definition eggNode.I:253
const LMatrix4d * get_node_frame_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_node_frame() matr...
Definition eggNode.I:206
const LMatrix4d & get_node_frame() const
Returns the coordinate frame of the node itself.
Definition eggNode.I:122
const LMatrix4d & get_node_to_vertex() const
Returns the transformation matrix suitable for converting vertices in the coordinate space of the nod...
Definition eggNode.I:183
const LMatrix4d & get_vertex_frame() const
Returns the coordinate frame of the vertices referenced by primitives at or under this node.
Definition eggNode.I:108
const LMatrix4d * get_node_to_vertex_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_node_to_vertex() ...
Definition eggNode.I:243
const LMatrix4d * get_node_frame_inv_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_node_frame_inv() ...
Definition eggNode.I:225
const LMatrix4d * get_vertex_frame_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_vertex_frame() ma...
Definition eggNode.I:196
bool is_under_transform() const
Returns true if there is a <Transform> entry somewhere in the egg tree at or above this node,...
Definition eggNode.I:77
void flatten_transforms()
Removes any transform and instance records from this node in the scene graph and below.
Definition eggNode.I:284
get_depth
Returns the number of nodes above this node in the egg hierarchy.
Definition eggNode.h:49
bool is_local_coord() const
Returns true if this node's vertices are not in the global coordinate space.
Definition eggNode.I:87
const LMatrix4d & get_node_frame_inv() const
Returns the inverse of the matrix returned by get_node_frame().
Definition eggNode.I:149