Panda3D
|
00001 // Filename: eggVertex.I 00002 // Created by: drose (16Jan99) 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 //////////////////////////////////////////////////////////////////// 00018 // Function: EggVertex::get_pool 00019 // Access: Published 00020 // Description: Returns the vertex pool this vertex belongs in. This 00021 // may be NULL if the vertex has not been added to a 00022 // pool. 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE EggVertexPool *EggVertex:: 00025 get_pool() const { 00026 return _pool; 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: EggVertex::is_forward_reference 00031 // Access: Published 00032 // Description: Returns true if the vertex is a forward reference to 00033 // some vertex that hasn't been defined yet. In this 00034 // case, the vertex may not have any properties filled 00035 // in yet. 00036 // 00037 // This can only happen if you implicitly create a 00038 // vertex via EggVertexPool::get_forward_vertex(). 00039 // Presumably, when the vertex pool is later filled in, 00040 // this vertex will be replaced with real data. 00041 //////////////////////////////////////////////////////////////////// 00042 INLINE bool EggVertex:: 00043 is_forward_reference() const { 00044 return _forward_reference; 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: EggVertex::set_pos 00049 // Access: Published 00050 // Description: Sets the vertex position. This variant sets the 00051 // vertex to a one-dimensional value. 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE void EggVertex:: 00054 set_pos(double pos) { 00055 _num_dimensions = 1; 00056 _pos.set(pos, 0.0, 0.0, 1.0); 00057 } 00058 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: EggVertex::set_pos 00062 // Access: Published 00063 // Description: Sets the vertex position. This variant sets the 00064 // vertex to a two-dimensional value. 00065 //////////////////////////////////////////////////////////////////// 00066 INLINE void EggVertex:: 00067 set_pos(const LPoint2d &pos) { 00068 _num_dimensions = 2; 00069 _pos.set(pos[0], pos[1], 0.0, 1.0); 00070 } 00071 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: EggVertex::set_pos 00075 // Access: Published 00076 // Description: Sets the vertex position. This variant sets the 00077 // vertex to a three-dimensional value. 00078 //////////////////////////////////////////////////////////////////// 00079 INLINE void EggVertex:: 00080 set_pos(const LPoint3d &pos) { 00081 _num_dimensions = 3; 00082 _pos.set(pos[0], pos[1], pos[2], 1.0); 00083 } 00084 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: EggVertex::set_pos 00088 // Access: Published 00089 // Description: Sets the vertex position. This variant sets the 00090 // vertex to a four-dimensional value. 00091 //////////////////////////////////////////////////////////////////// 00092 INLINE void EggVertex:: 00093 set_pos(const LPoint4d &pos) { 00094 _num_dimensions = 4; 00095 _pos = pos; 00096 } 00097 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: EggVertex::set_pos4 00101 // Access: Published 00102 // Description: This special flavor of set_pos() sets the vertex as a 00103 // four-component value, but does not change the set 00104 // number of dimensions. It's handy for retrieving the 00105 // vertex position via get_pos4, manipulating it, then 00106 // storing it back again, without worrying about the 00107 // number of dimensions it actually had. 00108 //////////////////////////////////////////////////////////////////// 00109 INLINE void EggVertex:: 00110 set_pos4(const LPoint4d &pos) { 00111 _pos = pos; 00112 } 00113 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: EggVertex::get_num_dimensions 00117 // Access: Published 00118 // Description: Returns the number of dimensions the vertex uses. 00119 // Usually this will be 3, but it may be 1, 2, 3, or 4. 00120 //////////////////////////////////////////////////////////////////// 00121 INLINE int EggVertex:: 00122 get_num_dimensions() const { 00123 return _num_dimensions; 00124 } 00125 00126 00127 //////////////////////////////////////////////////////////////////// 00128 // Function: EggVertex::get_pos1 00129 // Access: Published 00130 // Description: Only valid if get_num_dimensions() returns 1. 00131 // Returns the position as a one-dimensional value. 00132 //////////////////////////////////////////////////////////////////// 00133 INLINE double EggVertex:: 00134 get_pos1() const { 00135 nassertr(_num_dimensions == 1, 0.0); 00136 return _pos[0]; 00137 } 00138 00139 00140 //////////////////////////////////////////////////////////////////// 00141 // Function: EggVertex::get_pos2 00142 // Access: Published 00143 // Description: Only valid if get_num_dimensions() returns 2. 00144 // Returns the position as a two-dimensional value. 00145 //////////////////////////////////////////////////////////////////// 00146 INLINE LPoint2d EggVertex:: 00147 get_pos2() const { 00148 nassertr(_num_dimensions == 2, LPoint2d(0.0, 0.0)); 00149 return LPoint2d(_pos[0], _pos[1]); 00150 } 00151 00152 00153 //////////////////////////////////////////////////////////////////// 00154 // Function: EggVertex::get_pos3 00155 // Access: Published 00156 // Description: Valid if get_num_dimensions() returns 3 or 4. 00157 // Returns the position as a three-dimensional value. 00158 //////////////////////////////////////////////////////////////////// 00159 INLINE LVertexd EggVertex:: 00160 get_pos3() const { 00161 nassertr(_num_dimensions == 3 || _num_dimensions == 4, 00162 LPoint3d(0.0, 0.0, 0.0)); 00163 return LVertexd(_pos[0] / _pos[3], _pos[1] / _pos[3], _pos[2] / _pos[3]); 00164 } 00165 00166 00167 //////////////////////////////////////////////////////////////////// 00168 // Function: EggVertex::get_pos4 00169 // Access: Published 00170 // Description: This is always valid, regardless of the value of 00171 // get_num_dimensions. It returns the position as a 00172 // four-dimensional value. If the pos has fewer than 00173 // four dimensions, this value represents the pos 00174 // extended into four-dimensional homogenous space, 00175 // e.g. by adding 1 as the fourth component. 00176 //////////////////////////////////////////////////////////////////// 00177 INLINE LPoint4d EggVertex:: 00178 get_pos4() const { 00179 return _pos; 00180 } 00181 00182 //////////////////////////////////////////////////////////////////// 00183 // Function: EggVertex::has_uv 00184 // Access: Published 00185 // Description: Returns true if the vertex has an unnamed UV 00186 // coordinate pair, false otherwise. 00187 // 00188 // This is the more restrictive interface, and is 00189 // generally useful only in the absence of 00190 // multitexturing; see has_uv(name) for the interface 00191 // that supports multitexturing. 00192 //////////////////////////////////////////////////////////////////// 00193 INLINE bool EggVertex:: 00194 has_uv() const { 00195 return has_uv(""); 00196 } 00197 00198 //////////////////////////////////////////////////////////////////// 00199 // Function: EggVertex::has_aux 00200 // Access: Published 00201 // Description: Returns true if the vertex has any auxiliary 00202 // data, false otherwise. 00203 //////////////////////////////////////////////////////////////////// 00204 INLINE bool EggVertex:: 00205 has_aux() const { 00206 return (_aux_map.size() != 0); 00207 } 00208 00209 //////////////////////////////////////////////////////////////////// 00210 // Function: EggVertex::get_uv 00211 // Access: Published 00212 // Description: Returns the unnamed UV coordinate pair on the 00213 // vertex. It is an error to call this if has_uv() has 00214 // returned false. 00215 // 00216 // This is the more restrictive interface, and is 00217 // generally useful only in the absence of 00218 // multitexturing; see get_uv(name) for the interface 00219 // that supports multitexturing. 00220 //////////////////////////////////////////////////////////////////// 00221 INLINE LTexCoordd EggVertex:: 00222 get_uv() const { 00223 nassertr(has_uv(), LTexCoordd::zero()); 00224 return get_uv(""); 00225 } 00226 00227 //////////////////////////////////////////////////////////////////// 00228 // Function: EggVertex::set_uv 00229 // Access: Published 00230 // Description: Replaces the unnamed UV coordinate pair on the vertex 00231 // with the indicated value. 00232 // 00233 // This is the more restrictive interface, and is 00234 // generally useful only in the absence of 00235 // multitexturing; see set_uv(name, uv) for the 00236 // interface that supports multitexturing. 00237 //////////////////////////////////////////////////////////////////// 00238 INLINE void EggVertex:: 00239 set_uv(const LTexCoordd &uv) { 00240 set_uv("", uv); 00241 } 00242 00243 //////////////////////////////////////////////////////////////////// 00244 // Function: EggVertex::clear_uv 00245 // Access: Published 00246 // Description: Removes all UV coordinate pairs from the vertex. 00247 //////////////////////////////////////////////////////////////////// 00248 INLINE void EggVertex:: 00249 clear_uv() { 00250 _uv_map.clear(); 00251 } 00252 00253 //////////////////////////////////////////////////////////////////// 00254 // Function: EggVertex::clear_aux 00255 // Access: Published 00256 // Description: Removes all auxiliary data from the vertex. 00257 //////////////////////////////////////////////////////////////////// 00258 INLINE void EggVertex:: 00259 clear_aux() { 00260 _aux_map.clear(); 00261 } 00262 00263 //////////////////////////////////////////////////////////////////// 00264 // Function: EggVertex::uv_begin 00265 // Access: Public 00266 // Description: Returns an iterator that allows walking through the 00267 // complete set of named UV's on the vertex. 00268 // 00269 // This interface is not safe to use outside of 00270 // PANDAEGG.DLL. 00271 //////////////////////////////////////////////////////////////////// 00272 INLINE EggVertex::const_uv_iterator EggVertex:: 00273 uv_begin() const { 00274 return _uv_map.begin(); 00275 } 00276 00277 //////////////////////////////////////////////////////////////////// 00278 // Function: EggVertex::aux_begin 00279 // Access: Public 00280 // Description: Returns an iterator that allows walking through the 00281 // complete set of auxiliary data on the vertex. 00282 // 00283 // This interface is not safe to use outside of 00284 // PANDAEGG.DLL. 00285 //////////////////////////////////////////////////////////////////// 00286 INLINE EggVertex::const_aux_iterator EggVertex:: 00287 aux_begin() const { 00288 return _aux_map.begin(); 00289 } 00290 00291 //////////////////////////////////////////////////////////////////// 00292 // Function: EggVertex::uv_end 00293 // Access: Public 00294 // Description: Returns an iterator that allows walking through the 00295 // complete set of named UV's on the vertex. 00296 // 00297 // This interface is not safe to use outside of 00298 // PANDAEGG.DLL. 00299 //////////////////////////////////////////////////////////////////// 00300 INLINE EggVertex::const_uv_iterator EggVertex:: 00301 uv_end() const { 00302 return _uv_map.end(); 00303 } 00304 00305 //////////////////////////////////////////////////////////////////// 00306 // Function: EggVertex::aux_end 00307 // Access: Public 00308 // Description: Returns an iterator that allows walking through the 00309 // complete set of auxiliary data on the vertex. 00310 // 00311 // This interface is not safe to use outside of 00312 // PANDAEGG.DLL. 00313 //////////////////////////////////////////////////////////////////// 00314 INLINE EggVertex::const_aux_iterator EggVertex:: 00315 aux_end() const { 00316 return _aux_map.end(); 00317 } 00318 00319 //////////////////////////////////////////////////////////////////// 00320 // Function: EggVertex::uv_size 00321 // Access: Public 00322 // Description: Returns the number of named UV's on the vertex. 00323 //////////////////////////////////////////////////////////////////// 00324 INLINE EggVertex::uv_size_type EggVertex:: 00325 uv_size() const { 00326 return _uv_map.size(); 00327 } 00328 00329 //////////////////////////////////////////////////////////////////// 00330 // Function: EggVertex::aux_size 00331 // Access: Public 00332 // Description: Returns the number of auxiliary datas on the vertex. 00333 //////////////////////////////////////////////////////////////////// 00334 INLINE EggVertex::aux_size_type EggVertex:: 00335 aux_size() const { 00336 return _aux_map.size(); 00337 } 00338 00339 //////////////////////////////////////////////////////////////////// 00340 // Function: EggVertex::get_index 00341 // Access: Published 00342 // Description: Returns the index number of the vertex within its 00343 // pool. 00344 //////////////////////////////////////////////////////////////////// 00345 INLINE int EggVertex:: 00346 get_index() const { 00347 return _index; 00348 } 00349 00350 //////////////////////////////////////////////////////////////////// 00351 // Function: EggVertex::set_external_index 00352 // Access: Published 00353 // Description: Sets a special index number that is associated with 00354 // the EggVertex (but is not written to the egg file). 00355 // This number is not interpreted by any egg code; it is 00356 // simply maintained along with the vertex. It *is* 00357 // used to differentiate otherwise identical vertices in 00358 // EggVertexPool::create_unique_vertex(), however. 00359 // 00360 // The intention of this number is as an aid for file 00361 // converters, to associate an EggVertex back to the 00362 // index number of the original source vertex. 00363 //////////////////////////////////////////////////////////////////// 00364 INLINE void EggVertex:: 00365 set_external_index(int external_index) { 00366 _external_index = external_index; 00367 } 00368 00369 //////////////////////////////////////////////////////////////////// 00370 // Function: EggVertex::get_external_index 00371 // Access: Published 00372 // Description: Returns the number set by set_external_index(). See 00373 // set_external_index(). 00374 //////////////////////////////////////////////////////////////////// 00375 INLINE int EggVertex:: 00376 get_external_index() const { 00377 return _external_index; 00378 } 00379 00380 //////////////////////////////////////////////////////////////////// 00381 // Function: EggVertex::sorts_less_than 00382 // Access: Published 00383 // Description: An ordering operator to compare two vertices for 00384 // sorting order. This imposes an arbitrary ordering 00385 // useful to identify unique vertices. 00386 //////////////////////////////////////////////////////////////////// 00387 INLINE bool EggVertex:: 00388 sorts_less_than(const EggVertex &other) const { 00389 return (compare_to(other) < 0); 00390 } 00391 00392 00393 00394 00395 00396 //////////////////////////////////////////////////////////////////// 00397 // Function: UniqueEggVertices::Function operator 00398 // Access: Public 00399 // Description: 00400 //////////////////////////////////////////////////////////////////// 00401 INLINE bool UniqueEggVertices:: 00402 operator ()(const EggVertex *v1, const EggVertex *v2) const { 00403 return v1->sorts_less_than(*v2); 00404 } 00405