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