Panda3D
 All Classes Functions Variables Enumerations
eggVertex.I
1 // Filename: eggVertex.I
2 // Created by: drose (16Jan99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: EggVertex::get_pool
19 // Access: Published
20 // Description: Returns the vertex pool this vertex belongs in. This
21 // may be NULL if the vertex has not been added to a
22 // pool.
23 ////////////////////////////////////////////////////////////////////
25 get_pool() const {
26  return _pool;
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: EggVertex::is_forward_reference
31 // Access: Published
32 // Description: Returns true if the vertex is a forward reference to
33 // some vertex that hasn't been defined yet. In this
34 // case, the vertex may not have any properties filled
35 // in yet.
36 //
37 // This can only happen if you implicitly create a
38 // vertex via EggVertexPool::get_forward_vertex().
39 // Presumably, when the vertex pool is later filled in,
40 // this vertex will be replaced with real data.
41 ////////////////////////////////////////////////////////////////////
42 INLINE bool EggVertex::
44  return _forward_reference;
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: EggVertex::set_pos
49 // Access: Published
50 // Description: Sets the vertex position. This variant sets the
51 // vertex to a one-dimensional value.
52 ////////////////////////////////////////////////////////////////////
53 INLINE void EggVertex::
54 set_pos(double pos) {
55  _num_dimensions = 1;
56  _pos.set(pos, 0.0, 0.0, 1.0);
57 }
58 
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: EggVertex::set_pos
62 // Access: Published
63 // Description: Sets the vertex position. This variant sets the
64 // vertex to a two-dimensional value.
65 ////////////////////////////////////////////////////////////////////
66 INLINE void EggVertex::
67 set_pos(const LPoint2d &pos) {
68  _num_dimensions = 2;
69  _pos.set(pos[0], pos[1], 0.0, 1.0);
70 }
71 
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: EggVertex::set_pos
75 // Access: Published
76 // Description: Sets the vertex position. This variant sets the
77 // vertex to a three-dimensional value.
78 ////////////////////////////////////////////////////////////////////
79 INLINE void EggVertex::
80 set_pos(const LPoint3d &pos) {
81  _num_dimensions = 3;
82  _pos.set(pos[0], pos[1], pos[2], 1.0);
83 }
84 
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: EggVertex::set_pos
88 // Access: Published
89 // Description: Sets the vertex position. This variant sets the
90 // vertex to a four-dimensional value.
91 ////////////////////////////////////////////////////////////////////
92 INLINE void EggVertex::
93 set_pos(const LPoint4d &pos) {
94  _num_dimensions = 4;
95  _pos = pos;
96 }
97 
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: EggVertex::set_pos4
101 // Access: Published
102 // Description: This special flavor of set_pos() sets the vertex as a
103 // four-component value, but does not change the set
104 // number of dimensions. It's handy for retrieving the
105 // vertex position via get_pos4, manipulating it, then
106 // storing it back again, without worrying about the
107 // number of dimensions it actually had.
108 ////////////////////////////////////////////////////////////////////
109 INLINE void EggVertex::
110 set_pos4(const LPoint4d &pos) {
111  _pos = pos;
112 }
113 
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: EggVertex::get_num_dimensions
117 // Access: Published
118 // Description: Returns the number of dimensions the vertex uses.
119 // Usually this will be 3, but it may be 1, 2, 3, or 4.
120 ////////////////////////////////////////////////////////////////////
121 INLINE int EggVertex::
123  return _num_dimensions;
124 }
125 
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: EggVertex::get_pos1
129 // Access: Published
130 // Description: Only valid if get_num_dimensions() returns 1.
131 // Returns the position as a one-dimensional value.
132 ////////////////////////////////////////////////////////////////////
133 INLINE double EggVertex::
134 get_pos1() const {
135  nassertr(_num_dimensions == 1, 0.0);
136  return _pos[0];
137 }
138 
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: EggVertex::get_pos2
142 // Access: Published
143 // Description: Only valid if get_num_dimensions() returns 2.
144 // Returns the position as a two-dimensional value.
145 ////////////////////////////////////////////////////////////////////
146 INLINE LPoint2d EggVertex::
147 get_pos2() const {
148  nassertr(_num_dimensions == 2, LPoint2d(0.0, 0.0));
149  return LPoint2d(_pos[0], _pos[1]);
150 }
151 
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: EggVertex::get_pos3
155 // Access: Published
156 // Description: Valid if get_num_dimensions() returns 3 or 4.
157 // Returns the position as a three-dimensional value.
158 ////////////////////////////////////////////////////////////////////
159 INLINE LVertexd EggVertex::
160 get_pos3() const {
161  nassertr(_num_dimensions == 3 || _num_dimensions == 4,
162  LPoint3d(0.0, 0.0, 0.0));
163  return LVertexd(_pos[0] / _pos[3], _pos[1] / _pos[3], _pos[2] / _pos[3]);
164 }
165 
166 
167 ////////////////////////////////////////////////////////////////////
168 // Function: EggVertex::get_pos4
169 // Access: Published
170 // Description: This is always valid, regardless of the value of
171 // get_num_dimensions. It returns the position as a
172 // four-dimensional value. If the pos has fewer than
173 // four dimensions, this value represents the pos
174 // extended into four-dimensional homogenous space,
175 // e.g. by adding 1 as the fourth component.
176 ////////////////////////////////////////////////////////////////////
177 INLINE LPoint4d EggVertex::
178 get_pos4() const {
179  return _pos;
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: EggVertex::has_uv
184 // Access: Published
185 // Description: Returns true if the vertex has an unnamed UV
186 // coordinate pair, false otherwise.
187 //
188 // This is the more restrictive interface, and is
189 // generally useful only in the absence of
190 // multitexturing; see has_uv(name) for the interface
191 // that supports multitexturing.
192 ////////////////////////////////////////////////////////////////////
193 INLINE bool EggVertex::
194 has_uv() const {
195  return has_uv("");
196 }
197 
198 ////////////////////////////////////////////////////////////////////
199 // Function: EggVertex::has_aux
200 // Access: Published
201 // Description: Returns true if the vertex has any auxiliary
202 // data, false otherwise.
203 ////////////////////////////////////////////////////////////////////
204 INLINE bool EggVertex::
205 has_aux() const {
206  return (_aux_map.size() != 0);
207 }
208 
209 ////////////////////////////////////////////////////////////////////
210 // Function: EggVertex::get_uv
211 // Access: Published
212 // Description: Returns the unnamed UV coordinate pair on the
213 // vertex. It is an error to call this if has_uv() has
214 // returned false.
215 //
216 // This is the more restrictive interface, and is
217 // generally useful only in the absence of
218 // multitexturing; see get_uv(name) for the interface
219 // that supports multitexturing.
220 ////////////////////////////////////////////////////////////////////
221 INLINE LTexCoordd EggVertex::
222 get_uv() const {
223  nassertr(has_uv(), LTexCoordd::zero());
224  return get_uv("");
225 }
226 
227 ////////////////////////////////////////////////////////////////////
228 // Function: EggVertex::set_uv
229 // Access: Published
230 // Description: Replaces the unnamed UV coordinate pair on the vertex
231 // with the indicated value.
232 //
233 // This is the more restrictive interface, and is
234 // generally useful only in the absence of
235 // multitexturing; see set_uv(name, uv) for the
236 // interface that supports multitexturing.
237 ////////////////////////////////////////////////////////////////////
238 INLINE void EggVertex::
239 set_uv(const LTexCoordd &uv) {
240  set_uv("", uv);
241 }
242 
243 ////////////////////////////////////////////////////////////////////
244 // Function: EggVertex::clear_uv
245 // Access: Published
246 // Description: Removes all UV coordinate pairs from the vertex.
247 ////////////////////////////////////////////////////////////////////
248 INLINE void EggVertex::
250  _uv_map.clear();
251 }
252 
253 ////////////////////////////////////////////////////////////////////
254 // Function: EggVertex::clear_aux
255 // Access: Published
256 // Description: Removes all auxiliary data from the vertex.
257 ////////////////////////////////////////////////////////////////////
258 INLINE void EggVertex::
260  _aux_map.clear();
261 }
262 
263 ////////////////////////////////////////////////////////////////////
264 // Function: EggVertex::uv_begin
265 // Access: Public
266 // Description: Returns an iterator that allows walking through the
267 // complete set of named UV's on the vertex.
268 //
269 // This interface is not safe to use outside of
270 // PANDAEGG.DLL.
271 ////////////////////////////////////////////////////////////////////
273 uv_begin() const {
274  return _uv_map.begin();
275 }
276 
277 ////////////////////////////////////////////////////////////////////
278 // Function: EggVertex::aux_begin
279 // Access: Public
280 // Description: Returns an iterator that allows walking through the
281 // complete set of auxiliary data on the vertex.
282 //
283 // This interface is not safe to use outside of
284 // PANDAEGG.DLL.
285 ////////////////////////////////////////////////////////////////////
287 aux_begin() const {
288  return _aux_map.begin();
289 }
290 
291 ////////////////////////////////////////////////////////////////////
292 // Function: EggVertex::uv_end
293 // Access: Public
294 // Description: Returns an iterator that allows walking through the
295 // complete set of named UV's on the vertex.
296 //
297 // This interface is not safe to use outside of
298 // PANDAEGG.DLL.
299 ////////////////////////////////////////////////////////////////////
301 uv_end() const {
302  return _uv_map.end();
303 }
304 
305 ////////////////////////////////////////////////////////////////////
306 // Function: EggVertex::aux_end
307 // Access: Public
308 // Description: Returns an iterator that allows walking through the
309 // complete set of auxiliary data on the vertex.
310 //
311 // This interface is not safe to use outside of
312 // PANDAEGG.DLL.
313 ////////////////////////////////////////////////////////////////////
315 aux_end() const {
316  return _aux_map.end();
317 }
318 
319 ////////////////////////////////////////////////////////////////////
320 // Function: EggVertex::uv_size
321 // Access: Public
322 // Description: Returns the number of named UV's on the vertex.
323 ////////////////////////////////////////////////////////////////////
324 INLINE EggVertex::uv_size_type EggVertex::
325 uv_size() const {
326  return _uv_map.size();
327 }
328 
329 ////////////////////////////////////////////////////////////////////
330 // Function: EggVertex::aux_size
331 // Access: Public
332 // Description: Returns the number of auxiliary datas on the vertex.
333 ////////////////////////////////////////////////////////////////////
334 INLINE EggVertex::aux_size_type EggVertex::
335 aux_size() const {
336  return _aux_map.size();
337 }
338 
339 ////////////////////////////////////////////////////////////////////
340 // Function: EggVertex::get_index
341 // Access: Published
342 // Description: Returns the index number of the vertex within its
343 // pool.
344 ////////////////////////////////////////////////////////////////////
345 INLINE int EggVertex::
346 get_index() const {
347  return _index;
348 }
349 
350 ////////////////////////////////////////////////////////////////////
351 // Function: EggVertex::set_external_index
352 // Access: Published
353 // Description: Sets a special index number that is associated with
354 // the EggVertex (but is not written to the egg file).
355 // This number is not interpreted by any egg code; it is
356 // simply maintained along with the vertex. It *is*
357 // used to differentiate otherwise identical vertices in
358 // EggVertexPool::create_unique_vertex(), however.
359 //
360 // The intention of this number is as an aid for file
361 // converters, to associate an EggVertex back to the
362 // index number of the original source vertex.
363 ////////////////////////////////////////////////////////////////////
364 INLINE void EggVertex::
365 set_external_index(int external_index) {
366  _external_index = external_index;
367 }
368 
369 ////////////////////////////////////////////////////////////////////
370 // Function: EggVertex::get_external_index
371 // Access: Published
372 // Description: Returns the number set by set_external_index(). See
373 // set_external_index().
374 ////////////////////////////////////////////////////////////////////
375 INLINE int EggVertex::
377  return _external_index;
378 }
379 
380 ////////////////////////////////////////////////////////////////////
381 // Function: EggVertex::set_external_index2
382 // Access: Published
383 // Description: Similar to set_external_index(), but this is a
384 // different number which may be used for a different
385 // purpose by the calling code. The egg library does
386 // not assign any meaning to this number or use it in
387 // any way.
388 ////////////////////////////////////////////////////////////////////
389 INLINE void EggVertex::
390 set_external_index2(int external_index2) {
391  _external_index2 = external_index2;
392 }
393 
394 ////////////////////////////////////////////////////////////////////
395 // Function: EggVertex::get_external_index2
396 // Access: Published
397 // Description: Returns the number set by set_external_index2(). See
398 // set_external_index2().
399 ////////////////////////////////////////////////////////////////////
400 INLINE int EggVertex::
402  return _external_index2;
403 }
404 
405 ////////////////////////////////////////////////////////////////////
406 // Function: EggVertex::sorts_less_than
407 // Access: Published
408 // Description: An ordering operator to compare two vertices for
409 // sorting order. This imposes an arbitrary ordering
410 // useful to identify unique vertices.
411 ////////////////////////////////////////////////////////////////////
412 INLINE bool EggVertex::
413 sorts_less_than(const EggVertex &other) const {
414  return (compare_to(other) < 0);
415 }
416 
417 
418 
419 
420 
421 ////////////////////////////////////////////////////////////////////
422 // Function: UniqueEggVertices::Function operator
423 // Access: Public
424 // Description:
425 ////////////////////////////////////////////////////////////////////
426 INLINE bool UniqueEggVertices::
427 operator ()(const EggVertex *v1, const EggVertex *v2) const {
428  return v1->sorts_less_than(*v2);
429 }
430 
static const LPoint2d & zero()
Returns a zero-length point.
Definition: lpoint2.h:543
This is an iterator adaptor that converts any iterator that returns a pair (e.g.
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
Definition: eggVertex.I:222
void clear_aux()
Removes all auxiliary data from the vertex.
Definition: eggVertex.I:259
uv_size_type uv_size() const
Returns the number of named UV&#39;s on the vertex.
Definition: eggVertex.I:325
void set_pos(double pos)
Sets the vertex position.
Definition: eggVertex.I:54
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
Definition: eggVertex.I:194
double get_pos1() const
Only valid if get_num_dimensions() returns 1.
Definition: eggVertex.I:134
This is a four-component point in space.
Definition: lpoint4.h:443
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
Definition: eggVertex.I:160
void set_pos4(const LPoint4d &pos)
This special flavor of set_pos() sets the vertex as a four-component value, but does not change the s...
Definition: eggVertex.I:110
bool sorts_less_than(const EggVertex &other) const
An ordering operator to compare two vertices for sorting order.
Definition: eggVertex.I:413
bool is_forward_reference() const
Returns true if the vertex is a forward reference to some vertex that hasn&#39;t been defined yet...
Definition: eggVertex.I:43
This is a two-component point in space.
Definition: lpoint2.h:411
void set_external_index(int external_index)
Sets a special index number that is associated with the EggVertex (but is not written to the egg file...
Definition: eggVertex.I:365
int compare_to(const EggVertex &other) const
An ordering operator to compare two vertices for sorting order.
Definition: eggVertex.cxx:627
int get_external_index() const
Returns the number set by set_external_index().
Definition: eggVertex.I:376
const_aux_iterator aux_begin() const
Returns an iterator that allows walking through the complete set of auxiliary data on the vertex...
Definition: eggVertex.I:287
const_uv_iterator uv_begin() const
Returns an iterator that allows walking through the complete set of named UV&#39;s on the vertex...
Definition: eggVertex.I:273
bool has_aux() const
Returns true if the vertex has any auxiliary data, false otherwise.
Definition: eggVertex.I:205
const_uv_iterator uv_end() const
Returns an iterator that allows walking through the complete set of named UV&#39;s on the vertex...
Definition: eggVertex.I:301
LPoint4d get_pos4() const
This is always valid, regardless of the value of get_num_dimensions.
Definition: eggVertex.I:178
void clear_uv()
Removes all UV coordinate pairs from the vertex.
Definition: eggVertex.I:249
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
const_aux_iterator aux_end() const
Returns an iterator that allows walking through the complete set of auxiliary data on the vertex...
Definition: eggVertex.I:315
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:531
LPoint2d get_pos2() const
Only valid if get_num_dimensions() returns 2.
Definition: eggVertex.I:147
int get_external_index2() const
Returns the number set by set_external_index2().
Definition: eggVertex.I:401
int get_num_dimensions() const
Returns the number of dimensions the vertex uses.
Definition: eggVertex.I:122
void set_external_index2(int external_index2)
Similar to set_external_index(), but this is a different number which may be used for a different pur...
Definition: eggVertex.I:390
aux_size_type aux_size() const
Returns the number of auxiliary datas on the vertex.
Definition: eggVertex.I:335
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
Definition: eggVertex.I:25
void set_uv(const LTexCoordd &texCoord)
Replaces the unnamed UV coordinate pair on the vertex with the indicated value.
Definition: eggVertex.I:239
A collection of vertices.
Definition: eggVertexPool.h:46
int get_index() const
Returns the index number of the vertex within its pool.
Definition: eggVertex.I:346