Panda3D
|
00001 // Filename: eggNode.I 00002 // Created by: drose (10Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: EggNode::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE EggNode:: 00022 EggNode(const string &name) : EggNamedObject(name) { 00023 _parent = NULL; 00024 _depth = 0; 00025 _under_flags = 0; 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: EggNode::Copy constructor 00030 // Access: Public 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE EggNode:: 00034 EggNode(const EggNode ©) : EggNamedObject(copy) { 00035 _parent = NULL; 00036 _depth = 0; 00037 _under_flags = 0; 00038 } 00039 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: EggNode::Copy assignment operator 00043 // Access: Public 00044 // Description: 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE EggNode &EggNode:: 00047 operator = (const EggNode ©) { 00048 EggNamedObject::operator = (copy); 00049 update_under(0); 00050 return *this; 00051 } 00052 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: EggNode::get_parent 00056 // Access: Public 00057 // Description: 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE EggGroupNode *EggNode:: 00060 get_parent() const { 00061 return _parent; 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: EggNode::get_depth 00066 // Access: Public 00067 // Description: Returns the number of nodes above this node in the 00068 // egg hierarchy. 00069 //////////////////////////////////////////////////////////////////// 00070 INLINE int EggNode:: 00071 get_depth() const { 00072 return _depth; 00073 } 00074 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: EggNode::is_under_instance 00078 // Access: Public 00079 // Description: Returns true if there is an <Instance> node somewhere 00080 // in the egg tree at or above this node, false 00081 // otherwise. 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE bool EggNode:: 00084 is_under_instance() const { 00085 return (_under_flags & UF_under_instance) != 0; 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: EggNode::is_under_transform 00090 // Access: Public 00091 // Description: Returns true if there is a <Transform> entry somewhere 00092 // in the egg tree at or above this node, false 00093 // otherwise. 00094 //////////////////////////////////////////////////////////////////// 00095 INLINE bool EggNode:: 00096 is_under_transform() const { 00097 return (_under_flags & UF_under_transform) != 0; 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: EggNode::is_local_coord 00102 // Access: Public 00103 // Description: Returns true if this node's vertices are not in the 00104 // global coordinate space. This will be the case if 00105 // there was an <Instance> node under a transform at or 00106 // above this node. 00107 //////////////////////////////////////////////////////////////////// 00108 INLINE bool EggNode:: 00109 is_local_coord() const { 00110 return (_under_flags & UF_local_coord) != 0; 00111 } 00112 00113 00114 //////////////////////////////////////////////////////////////////// 00115 // Function: EggNode::get_vertex_frame 00116 // Access: Public 00117 // Description: Returns the coordinate frame of the vertices 00118 // referenced by primitives at or under this node. This 00119 // is not the same as get_node_frame(). 00120 // 00121 // Generally, vertices in an egg file are stored in the 00122 // global coordinate space, regardless of the transforms 00123 // defined at each node. Thus, get_vertex_frame() will 00124 // usually return the identity transform (global 00125 // coordinate space). However, primitives under an 00126 // <Instance> entry reference their vertices in the 00127 // coordinate system under effect at the time of the 00128 // <Instance>. Thus, nodes under an <Instance> entry 00129 // may return this non-identity matrix. 00130 // 00131 // Specifically, this may return a non-identity matrix 00132 // only if is_local_coord() is true. 00133 //////////////////////////////////////////////////////////////////// 00134 INLINE const LMatrix4d &EggNode:: 00135 get_vertex_frame() const { 00136 if (_vertex_frame == (LMatrix4d *)NULL) { 00137 return LMatrix4d::ident_mat(); 00138 } else { 00139 return *_vertex_frame; 00140 } 00141 } 00142 00143 00144 //////////////////////////////////////////////////////////////////// 00145 // Function: EggNode::get_node_frame 00146 // Access: Public 00147 // Description: Returns the coordinate frame of the node itself. 00148 // This is simply the net product of all transformations 00149 // up to the root. 00150 //////////////////////////////////////////////////////////////////// 00151 INLINE const LMatrix4d &EggNode:: 00152 get_node_frame() const { 00153 if (_node_frame == (LMatrix4d *)NULL) { 00154 return LMatrix4d::ident_mat(); 00155 } else { 00156 return *_node_frame; 00157 } 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: EggNode::get_vertex_frame_inv 00162 // Access: Public 00163 // Description: Returns the inverse of the matrix returned by 00164 // get_vertex_frame(). See get_vertex_frame(). 00165 //////////////////////////////////////////////////////////////////// 00166 INLINE const LMatrix4d &EggNode:: 00167 get_vertex_frame_inv() const { 00168 if (_vertex_frame_inv == (LMatrix4d *)NULL) { 00169 return LMatrix4d::ident_mat(); 00170 } else { 00171 return *_vertex_frame_inv; 00172 } 00173 } 00174 00175 00176 //////////////////////////////////////////////////////////////////// 00177 // Function: EggNode::get_node_frame_inv 00178 // Access: Public 00179 // Description: Returns the inverse of the matrix returned by 00180 // get_node_frame(). See get_node_frame(). 00181 //////////////////////////////////////////////////////////////////// 00182 INLINE const LMatrix4d &EggNode:: 00183 get_node_frame_inv() const { 00184 if (_node_frame_inv == (LMatrix4d *)NULL) { 00185 return LMatrix4d::ident_mat(); 00186 } else { 00187 return *_node_frame_inv; 00188 } 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: EggNode::get_vertex_to_node 00193 // Access: Public 00194 // Description: Returns the transformation matrix suitable for 00195 // converting the vertices as read from the egg file 00196 // into the coordinate space of the node. This is the 00197 // same thing as: 00198 // 00199 // get_vertex_frame() * get_node_frame_inv() 00200 // 00201 //////////////////////////////////////////////////////////////////// 00202 INLINE const LMatrix4d &EggNode:: 00203 get_vertex_to_node() const { 00204 if (_vertex_to_node == (LMatrix4d *)NULL) { 00205 return LMatrix4d::ident_mat(); 00206 } else { 00207 return *_vertex_to_node; 00208 } 00209 } 00210 00211 //////////////////////////////////////////////////////////////////// 00212 // Function: EggNode::get_node_to_vertex 00213 // Access: Public 00214 // Description: Returns the transformation matrix suitable for 00215 // converting vertices in the coordinate space of the 00216 // node to the appropriate coordinate space for storing 00217 // in the egg file. This is the same thing as: 00218 // 00219 // get_node_frame() * get_vertex_frame_inv() 00220 // 00221 //////////////////////////////////////////////////////////////////// 00222 INLINE const LMatrix4d &EggNode:: 00223 get_node_to_vertex() const { 00224 if (_node_to_vertex == (LMatrix4d *)NULL) { 00225 return LMatrix4d::ident_mat(); 00226 } else { 00227 return *_node_to_vertex; 00228 } 00229 } 00230 00231 //////////////////////////////////////////////////////////////////// 00232 // Function: EggNode::get_vertex_frame_ptr 00233 // Access: Public 00234 // Description: Returns either a NULL pointer or a unique pointer 00235 // shared by nodes with the same get_vertex_frame() 00236 // matrix. 00237 //////////////////////////////////////////////////////////////////// 00238 INLINE const LMatrix4d *EggNode:: 00239 get_vertex_frame_ptr() const { 00240 return _vertex_frame; 00241 } 00242 00243 00244 //////////////////////////////////////////////////////////////////// 00245 // Function: EggNode::get_node_frame_ptr 00246 // Access: Public 00247 // Description: Returns either a NULL pointer or a unique pointer 00248 // shared by nodes with the same get_node_frame() 00249 // matrix. 00250 //////////////////////////////////////////////////////////////////// 00251 INLINE const LMatrix4d *EggNode:: 00252 get_node_frame_ptr() const { 00253 return _node_frame; 00254 } 00255 00256 //////////////////////////////////////////////////////////////////// 00257 // Function: EggNode::get_vertex_frame_inv_ptr 00258 // Access: Public 00259 // Description: Returns either a NULL pointer or a unique pointer 00260 // shared by nodes with the same get_vertex_frame_inv() 00261 // matrix. 00262 //////////////////////////////////////////////////////////////////// 00263 INLINE const LMatrix4d *EggNode:: 00264 get_vertex_frame_inv_ptr() const { 00265 return _vertex_frame_inv; 00266 } 00267 00268 00269 //////////////////////////////////////////////////////////////////// 00270 // Function: EggNode::get_node_frame_inv_ptr 00271 // Access: Public 00272 // Description: Returns either a NULL pointer or a unique pointer 00273 // shared by nodes with the same get_node_frame_inv() 00274 // matrix. 00275 //////////////////////////////////////////////////////////////////// 00276 INLINE const LMatrix4d *EggNode:: 00277 get_node_frame_inv_ptr() const { 00278 return _node_frame_inv; 00279 } 00280 00281 //////////////////////////////////////////////////////////////////// 00282 // Function: EggNode::get_vertex_to_node_ptr 00283 // Access: Public 00284 // Description: Returns either a NULL pointer or a unique pointer 00285 // shared by nodes with the same get_vertex_to_node() 00286 // matrix. 00287 //////////////////////////////////////////////////////////////////// 00288 INLINE const LMatrix4d *EggNode:: 00289 get_vertex_to_node_ptr() const { 00290 return _vertex_to_node; 00291 } 00292 00293 //////////////////////////////////////////////////////////////////// 00294 // Function: EggNode::get_node_to_vertex_ptr 00295 // Access: Public 00296 // Description: Returns either a NULL pointer or a unique pointer 00297 // shared by nodes with the same get_node_to_vertex() 00298 // matrix. 00299 //////////////////////////////////////////////////////////////////// 00300 INLINE const LMatrix4d *EggNode:: 00301 get_node_to_vertex_ptr() const { 00302 return _node_to_vertex; 00303 } 00304 00305 00306 //////////////////////////////////////////////////////////////////// 00307 // Function: EggNode::transform 00308 // Access: Public 00309 // Description: Applies the indicated transformation to the node and 00310 // all of its descendants. 00311 //////////////////////////////////////////////////////////////////// 00312 INLINE void EggNode:: 00313 transform(const LMatrix4d &mat) { 00314 LMatrix4d inv = invert(mat); 00315 00316 r_transform(mat, inv, CS_default); 00317 r_transform_vertices(mat); 00318 00319 // Now we have to recompute the under_flags to ensure that all the 00320 // cached relative matrices are correct. 00321 update_under(0); 00322 } 00323 00324 //////////////////////////////////////////////////////////////////// 00325 // Function: EggNode::transform_vertices_only 00326 // Access: Public 00327 // Description: Applies the indicated transformation only to vertices 00328 // that appear in global space within vertex pools at 00329 // this node and below. Joints and other transforms are 00330 // not affected, nor are local vertices. 00331 //////////////////////////////////////////////////////////////////// 00332 INLINE void EggNode:: 00333 transform_vertices_only(const LMatrix4d &mat) { 00334 r_transform_vertices(mat); 00335 } 00336 00337 //////////////////////////////////////////////////////////////////// 00338 // Function: EggNode::flatten_transforms 00339 // Access: Public 00340 // Description: Removes any transform and instance records from this 00341 // node in the scene graph and below. If an instance 00342 // node is encountered, removes the instance and applies 00343 // the transform to its vertices, duplicating vertices 00344 // if necessary. 00345 // 00346 // Since this function may result in duplicated 00347 // vertices, it may be a good idea to call 00348 // remove_unused_vertices() after calling this. 00349 //////////////////////////////////////////////////////////////////// 00350 INLINE void EggNode:: 00351 flatten_transforms() { 00352 r_flatten_transforms(); 00353 update_under(0); 00354 }