Panda3D
eggVertex.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 eggVertex.I
10  * @author drose
11  * @date 1999-01-16
12  */
13 
14 /**
15  * Returns the vertex pool this vertex belongs in. This may be NULL if the
16  * vertex has not been added to a pool.
17  */
19 get_pool() const {
20  return _pool;
21 }
22 
23 /**
24  * Returns true if the vertex is a forward reference to some vertex that
25  * hasn't been defined yet. In this case, the vertex may not have any
26  * properties filled in yet.
27  *
28  * This can only happen if you implicitly create a vertex via
29  * EggVertexPool::get_forward_vertex(). Presumably, when the vertex pool is
30  * later filled in, this vertex will be replaced with real data.
31  */
32 INLINE bool EggVertex::
34  return _forward_reference;
35 }
36 
37 /**
38  * Sets the vertex position. This variant sets the vertex to a one-
39  * dimensional value.
40  */
41 INLINE void EggVertex::
42 set_pos(double pos) {
43  _num_dimensions = 1;
44  _pos.set(pos, 0.0, 0.0, 1.0);
45 }
46 
47 
48 /**
49  * Sets the vertex position. This variant sets the vertex to a two-
50  * dimensional value.
51  */
52 INLINE void EggVertex::
53 set_pos(const LPoint2d &pos) {
54  _num_dimensions = 2;
55  _pos.set(pos[0], pos[1], 0.0, 1.0);
56 }
57 
58 
59 /**
60  * Sets the vertex position. This variant sets the vertex to a three-
61  * dimensional value.
62  */
63 INLINE void EggVertex::
64 set_pos(const LPoint3d &pos) {
65  _num_dimensions = 3;
66  _pos.set(pos[0], pos[1], pos[2], 1.0);
67 }
68 
69 
70 /**
71  * Sets the vertex position. This variant sets the vertex to a four-
72  * dimensional value.
73  */
74 INLINE void EggVertex::
75 set_pos(const LPoint4d &pos) {
76  _num_dimensions = 4;
77  _pos = pos;
78 }
79 
80 
81 /**
82  * This special flavor of set_pos() sets the vertex as a four-component value,
83  * but does not change the set number of dimensions. It's handy for
84  * retrieving the vertex position via get_pos4, manipulating it, then storing
85  * it back again, without worrying about the number of dimensions it actually
86  * had.
87  */
88 INLINE void EggVertex::
89 set_pos4(const LPoint4d &pos) {
90  _pos = pos;
91 }
92 
93 
94 /**
95  * Returns the number of dimensions the vertex uses. Usually this will be 3,
96  * but it may be 1, 2, 3, or 4.
97  */
98 INLINE int EggVertex::
100  return _num_dimensions;
101 }
102 
103 
104 /**
105  * Only valid if get_num_dimensions() returns 1. Returns the position as a
106  * one-dimensional value.
107  */
108 INLINE double EggVertex::
109 get_pos1() const {
110  nassertr(_num_dimensions == 1, 0.0);
111  return _pos[0];
112 }
113 
114 
115 /**
116  * Only valid if get_num_dimensions() returns 2. Returns the position as a
117  * two-dimensional value.
118  */
119 INLINE LPoint2d EggVertex::
120 get_pos2() const {
121  nassertr(_num_dimensions == 2, LPoint2d(0.0, 0.0));
122  return LPoint2d(_pos[0], _pos[1]);
123 }
124 
125 
126 /**
127  * Valid if get_num_dimensions() returns 3 or 4. Returns the position as a
128  * three-dimensional value.
129  */
130 INLINE LVertexd EggVertex::
131 get_pos3() const {
132  nassertr(_num_dimensions == 3 || _num_dimensions == 4,
133  LPoint3d(0.0, 0.0, 0.0));
134  return LVertexd(_pos[0] / _pos[3], _pos[1] / _pos[3], _pos[2] / _pos[3]);
135 }
136 
137 
138 /**
139  * This is always valid, regardless of the value of get_num_dimensions. It
140  * returns the position as a four-dimensional value. If the pos has fewer
141  * than four dimensions, this value represents the pos extended into four-
142  * dimensional homogenous space, e.g. by adding 1 as the fourth component.
143  */
144 INLINE LPoint4d EggVertex::
145 get_pos4() const {
146  return _pos;
147 }
148 
149 /**
150  * Returns true if the vertex has an unnamed UV coordinate pair, false
151  * otherwise.
152  *
153  * This is the more restrictive interface, and is generally useful only in the
154  * absence of multitexturing; see has_uv(name) for the interface that supports
155  * multitexturing.
156  */
157 INLINE bool EggVertex::
158 has_uv() const {
159  return has_uv("");
160 }
161 
162 /**
163  * Returns true if the vertex has any auxiliary data, false otherwise.
164  */
165 INLINE bool EggVertex::
166 has_aux() const {
167  return (_aux_map.size() != 0);
168 }
169 
170 /**
171  * Returns the unnamed UV coordinate pair on the vertex. It is an error to
172  * call this if has_uv() has returned false.
173  *
174  * This is the more restrictive interface, and is generally useful only in the
175  * absence of multitexturing; see get_uv(name) for the interface that supports
176  * multitexturing.
177  */
178 INLINE LTexCoordd EggVertex::
179 get_uv() const {
180  nassertr(has_uv(), LTexCoordd::zero());
181  return get_uv("");
182 }
183 
184 /**
185  * Replaces the unnamed UV coordinate pair on the vertex with the indicated
186  * value.
187  *
188  * This is the more restrictive interface, and is generally useful only in the
189  * absence of multitexturing; see set_uv(name, uv) for the interface that
190  * supports multitexturing.
191  */
192 INLINE void EggVertex::
193 set_uv(const LTexCoordd &uv) {
194  set_uv("", uv);
195 }
196 
197 /**
198  * Removes all UV coordinate pairs from the vertex.
199  */
200 INLINE void EggVertex::
202  _uv_map.clear();
203 }
204 
205 /**
206  * Removes all auxiliary data from the vertex.
207  */
208 INLINE void EggVertex::
210  _aux_map.clear();
211 }
212 
213 /**
214  * Returns an iterator that allows walking through the complete set of named
215  * UV's on the vertex.
216  *
217  * This interface is not safe to use outside of PANDAEGG.DLL.
218  */
220 uv_begin() const {
221  return _uv_map.begin();
222 }
223 
224 /**
225  * Returns an iterator that allows walking through the complete set of
226  * auxiliary data on the vertex.
227  *
228  * This interface is not safe to use outside of PANDAEGG.DLL.
229  */
231 aux_begin() const {
232  return _aux_map.begin();
233 }
234 
235 /**
236  * Returns an iterator that allows walking through the complete set of named
237  * UV's on the vertex.
238  *
239  * This interface is not safe to use outside of PANDAEGG.DLL.
240  */
242 uv_end() const {
243  return _uv_map.end();
244 }
245 
246 /**
247  * Returns an iterator that allows walking through the complete set of
248  * auxiliary data on the vertex.
249  *
250  * This interface is not safe to use outside of PANDAEGG.DLL.
251  */
253 aux_end() const {
254  return _aux_map.end();
255 }
256 
257 /**
258  * Returns the number of named UV's on the vertex.
259  */
260 INLINE EggVertex::uv_size_type EggVertex::
261 uv_size() const {
262  return _uv_map.size();
263 }
264 
265 /**
266  * Returns the number of auxiliary datas on the vertex.
267  */
268 INLINE EggVertex::aux_size_type EggVertex::
269 aux_size() const {
270  return _aux_map.size();
271 }
272 
273 /**
274  * Returns the index number of the vertex within its pool.
275  */
276 INLINE int EggVertex::
277 get_index() const {
278  return _index;
279 }
280 
281 /**
282  * Sets a special index number that is associated with the EggVertex (but is
283  * not written to the egg file). This number is not interpreted by any egg
284  * code; it is simply maintained along with the vertex. It *is* used to
285  * differentiate otherwise identical vertices in
286  * EggVertexPool::create_unique_vertex(), however.
287  *
288  * The intention of this number is as an aid for file converters, to associate
289  * an EggVertex back to the index number of the original source vertex.
290  */
291 INLINE void EggVertex::
292 set_external_index(int external_index) {
293  _external_index = external_index;
294 }
295 
296 /**
297  * Returns the number set by set_external_index(). See set_external_index().
298  */
299 INLINE int EggVertex::
301  return _external_index;
302 }
303 
304 /**
305  * Similar to set_external_index(), but this is a different number which may
306  * be used for a different purpose by the calling code. The egg library does
307  * not assign any meaning to this number or use it in any way.
308  */
309 INLINE void EggVertex::
310 set_external_index2(int external_index2) {
311  _external_index2 = external_index2;
312 }
313 
314 /**
315  * Returns the number set by set_external_index2(). See
316  * set_external_index2().
317  */
318 INLINE int EggVertex::
320  return _external_index2;
321 }
322 
323 /**
324  * An ordering operator to compare two vertices for sorting order. This
325  * imposes an arbitrary ordering useful to identify unique vertices.
326  */
327 INLINE bool EggVertex::
328 sorts_less_than(const EggVertex &other) const {
329  return (compare_to(other) < 0);
330 }
331 
332 
333 
334 
335 
336 /**
337  *
338  */
339 INLINE bool UniqueEggVertices::
340 operator ()(const EggVertex *v1, const EggVertex *v2) const {
341  return v1->sorts_less_than(*v2);
342 }
This is an iterator adaptor that converts any iterator that returns a pair (e.g.
int get_num_dimensions() const
Returns the number of dimensions the vertex uses.
Definition: eggVertex.I:99
void clear_aux()
Removes all auxiliary data from the vertex.
Definition: eggVertex.I:209
int get_external_index2() const
Returns the number set by set_external_index2().
Definition: eggVertex.I:319
void set_pos(double pos)
Sets the vertex position.
Definition: eggVertex.I:42
bool has_aux() const
Returns true if the vertex has any auxiliary data, false otherwise.
Definition: eggVertex.I:166
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
Definition: eggVertex.I:19
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
Definition: eggVertex.I:179
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:89
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:253
LPoint2d get_pos2() const
Only valid if get_num_dimensions() returns 2.
Definition: eggVertex.I:120
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
Definition: eggVertex.I:131
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:292
uv_size_type uv_size() const
Returns the number of named UV's on the vertex.
Definition: eggVertex.I:261
int get_index() const
Returns the index number of the vertex within its pool.
Definition: eggVertex.I:277
void clear_uv()
Removes all UV coordinate pairs from the vertex.
Definition: eggVertex.I:201
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition: eggVertex.h:39
aux_size_type aux_size() const
Returns the number of auxiliary datas on the vertex.
Definition: eggVertex.I:269
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
Definition: eggVertex.I:158
int compare_to(const EggVertex &other) const
An ordering operator to compare two vertices for sorting order.
Definition: eggVertex.cxx:553
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:231
bool is_forward_reference() const
Returns true if the vertex is a forward reference to some vertex that hasn't been defined yet.
Definition: eggVertex.I:33
bool sorts_less_than(const EggVertex &other) const
An ordering operator to compare two vertices for sorting order.
Definition: eggVertex.I:328
const_uv_iterator uv_begin() const
Returns an iterator that allows walking through the complete set of named UV's on the vertex.
Definition: eggVertex.I:220
LPoint4d get_pos4() const
This is always valid, regardless of the value of get_num_dimensions.
Definition: eggVertex.I:145
int get_external_index() const
Returns the number set by set_external_index().
Definition: eggVertex.I:300
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:310
double get_pos1() const
Only valid if get_num_dimensions() returns 1.
Definition: eggVertex.I:109
void set_uv(const LTexCoordd &texCoord)
Replaces the unnamed UV coordinate pair on the vertex with the indicated value.
Definition: eggVertex.I:193
A collection of vertices.
Definition: eggVertexPool.h:41
const_uv_iterator uv_end() const
Returns an iterator that allows walking through the complete set of named UV's on the vertex.
Definition: eggVertex.I:242