Panda3D

Loading...
Searching...
No Matches
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 */
18INLINE EggVertexPool *EggVertex::
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 */
32INLINE bool EggVertex::
33 is_forward_reference() const {
34 return _forward_reference;
35}
36
37/**
38 * Sets the vertex position. This variant sets the vertex to a one-
39 * dimensional value.
40 */
41INLINE 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 */
52INLINE 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 */
63INLINE 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 */
74INLINE 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 */
88INLINE 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 */
98INLINE int EggVertex::
99 get_num_dimensions() const {
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 */
108INLINE 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 */
119INLINE 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 */
130INLINE 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 */
144INLINE 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 */
157INLINE 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 */
165INLINE 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 */
178INLINE 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 */
192INLINE 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 */
200INLINE void EggVertex::
201 clear_uv() {
202 _uv_map.clear();
203}
204
205/**
206 * Removes all auxiliary data from the vertex.
207 */
208INLINE void EggVertex::
209 clear_aux() {
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 */
219INLINE EggVertex::const_uv_iterator EggVertex::
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 */
230INLINE EggVertex::const_aux_iterator EggVertex::
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 */
241INLINE EggVertex::const_uv_iterator EggVertex::
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 */
252INLINE EggVertex::const_aux_iterator EggVertex::
253 aux_end() const {
254 return _aux_map.end();
255}
256
257/**
258 * Returns the number of named UV's on the vertex.
259 */
260INLINE 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 */
268INLINE 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 */
276INLINE 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 */
291INLINE 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 */
299INLINE int EggVertex::
300 get_external_index() const {
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 */
309INLINE 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 */
318INLINE int EggVertex::
319 get_external_index2() const {
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 */
327INLINE 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 */
339INLINE bool UniqueEggVertices::
340operator ()(const EggVertex *v1, const EggVertex *v2) const {
341 return v1->sorts_less_than(*v2);
342}
EggVertex
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition eggVertex.h:39
EggVertex::set_pos4
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
EggVertex::has_uv
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
Definition eggVertex.I:158
EggVertex::aux_size
aux_size_type aux_size() const
Returns the number of auxiliary datas on the vertex.
Definition eggVertex.I:269
EggVertex::get_index
int get_index() const
Returns the index number of the vertex within its pool.
Definition eggVertex.I:277
EggVertex::compare_to
int compare_to(const EggVertex &other) const
An ordering operator to compare two vertices for sorting order.
Definition eggVertex.cxx:553
EggVertex::has_aux
bool has_aux() const
Returns true if the vertex has any auxiliary data, false otherwise.
Definition eggVertex.I:166
EggVertex::get_external_index
int get_external_index() const
Returns the number set by set_external_index().
Definition eggVertex.I:300
EggVertex::uv_size
uv_size_type uv_size() const
Returns the number of named UV's on the vertex.
Definition eggVertex.I:261
EggVertex::get_pool
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
Definition eggVertex.I:19
EggVertex::set_external_index
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
EggVertex::is_forward_reference
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
EggVertex::get_uv
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
Definition eggVertex.I:179
EggVertex::set_external_index2
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
EggVertex::set_pos
void set_pos(double pos)
Sets the vertex position.
Definition eggVertex.I:42
EggVertex::aux_begin
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
EggVertex::get_external_index2
int get_external_index2() const
Returns the number set by set_external_index2().
Definition eggVertex.I:319
EggVertex::clear_uv
void clear_uv()
Removes all UV coordinate pairs from the vertex.
Definition eggVertex.I:201
EggVertex::uv_end
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
EggVertex::get_pos2
LPoint2d get_pos2() const
Only valid if get_num_dimensions() returns 2.
Definition eggVertex.I:120
EggVertex::sorts_less_than
bool sorts_less_than(const EggVertex &other) const
An ordering operator to compare two vertices for sorting order.
Definition eggVertex.I:328
EggVertex::uv_begin
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
EggVertex::clear_aux
void clear_aux()
Removes all auxiliary data from the vertex.
Definition eggVertex.I:209
EggVertex::get_num_dimensions
int get_num_dimensions() const
Returns the number of dimensions the vertex uses.
Definition eggVertex.I:99
EggVertex::get_pos1
double get_pos1() const
Only valid if get_num_dimensions() returns 1.
Definition eggVertex.I:109
EggVertex::get_pos3
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
Definition eggVertex.I:131
EggVertex::set_uv
void set_uv(const LTexCoordd &texCoord)
Replaces the unnamed UV coordinate pair on the vertex with the indicated value.
Definition eggVertex.I:193
EggVertex::get_pos4
LPoint4d get_pos4() const
This is always valid, regardless of the value of get_num_dimensions.
Definition eggVertex.I:145
EggVertex::aux_end
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