Panda3D
Loading...
Searching...
No Matches
eggVertex.h
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.h
10 * @author drose
11 * @date 1999-01-16
12 */
13
14#ifndef EGGVERTEX_H
15#define EGGVERTEX_H
16
17#include "pandabase.h"
18
19#include "eggObject.h"
20#include "eggAttributes.h"
21#include "eggMorphList.h"
22#include "eggVertexUV.h"
23#include "eggVertexAux.h"
24
25#include "referenceCount.h"
26#include "luse.h"
27#include "pset.h"
28#include "iterator_types.h"
29
30class EggVertexPool;
31class EggGroup;
32class EggPrimitive;
33
34
35/**
36 * Any one-, two-, three-, or four-component vertex, possibly with attributes
37 * such as a normal.
38 */
39class EXPCL_PANDA_EGG EggVertex : public EggObject, public EggAttributes {
40public:
41 typedef pset<EggGroup *> GroupRef;
42 typedef pmultiset<EggPrimitive *> PrimitiveRef;
43 typedef pmap< std::string, PT(EggVertexUV) > UVMap;
44 typedef pmap< std::string, PT(EggVertexAux) > AuxMap;
45
47 typedef uv_iterator const_uv_iterator;
48 typedef UVMap::size_type uv_size_type;
49
51 typedef aux_iterator const_aux_iterator;
52 typedef AuxMap::size_type aux_size_type;
53
54
55PUBLISHED:
56 EggVertex();
57 EggVertex(const EggVertex &copy);
58 EggVertex &operator = (const EggVertex &copy);
59 virtual ~EggVertex();
60
61 INLINE EggVertexPool *get_pool() const;
62
63 INLINE bool is_forward_reference() const;
64
65 // The pos might have 1, 2, 3, or 4 dimensions. That complicates things a
66 // bit.
67 INLINE void set_pos(double pos);
68 INLINE void set_pos(const LPoint2d &pos);
69 INLINE void set_pos(const LPoint3d &pos);
70 INLINE void set_pos(const LPoint4d &pos);
71 INLINE void set_pos4(const LPoint4d &pos);
72
73 // get_pos[123] return the pos as the corresponding type. It is an error to
74 // call any of these without first verifying that get_num_dimensions()
75 // matches the desired type. However, get_pos4() may always be called; it
76 // returns the pos as a four-component point in homogeneous space (with a
77 // 1.0 in the last position if the pos has fewer than four components).
78 INLINE int get_num_dimensions() const;
79 INLINE double get_pos1() const;
80 INLINE LPoint2d get_pos2() const;
81 INLINE LVertexd get_pos3() const;
82 INLINE LPoint4d get_pos4() const;
83
84 INLINE bool has_uv() const;
85 INLINE LTexCoordd get_uv() const;
86 INLINE void set_uv(const LTexCoordd &texCoord);
87 INLINE void clear_uv();
88 bool has_uv(const std::string &name) const;
89 bool has_uvw(const std::string &name) const;
90 LTexCoordd get_uv(const std::string &name) const;
91 const LTexCoord3d &get_uvw(const std::string &name) const;
92 void set_uv(const std::string &name, const LTexCoordd &texCoord);
93 void set_uvw(const std::string &name, const LTexCoord3d &texCoord);
94 const EggVertexUV *get_uv_obj(const std::string &name) const;
95 EggVertexUV *modify_uv_obj(const std::string &name);
96 void set_uv_obj(EggVertexUV *vertex_uv);
97 void clear_uv(const std::string &name);
98
99 INLINE bool has_aux() const;
100 INLINE void clear_aux();
101 bool has_aux(const std::string &name) const;
102 const LVecBase4d &get_aux(const std::string &name) const;
103 void set_aux(const std::string &name, const LVecBase4d &aux);
104 const EggVertexAux *get_aux_obj(const std::string &name) const;
105 EggVertexAux *modify_aux_obj(const std::string &name);
106 void set_aux_obj(EggVertexAux *vertex_aux);
107 void clear_aux(const std::string &name);
108
109 static PT(EggVertex) make_average(const EggVertex *first,
110 const EggVertex *second);
111
112public:
113 INLINE const_uv_iterator uv_begin() const;
114 INLINE const_uv_iterator uv_end() const;
115 INLINE uv_size_type uv_size() const;
116
117 INLINE const_aux_iterator aux_begin() const;
118 INLINE const_aux_iterator aux_end() const;
119 INLINE aux_size_type aux_size() const;
120
121PUBLISHED:
122 INLINE int get_index() const;
123
124 INLINE void set_external_index(int external_index);
125 INLINE int get_external_index() const;
126 INLINE void set_external_index2(int external_index2);
127 INLINE int get_external_index2() const;
128
129 void write(std::ostream &out, int indent_level) const;
130 INLINE bool sorts_less_than(const EggVertex &other) const;
131 int compare_to(const EggVertex &other) const;
132
133 int get_num_local_coord() const;
134 int get_num_global_coord() const;
135
136 void transform(const LMatrix4d &mat);
137
138public:
139 GroupRef::const_iterator gref_begin() const;
140 GroupRef::const_iterator gref_end() const;
141 GroupRef::size_type gref_size() const;
142PUBLISHED:
143 bool has_gref(const EggGroup *group) const;
144
145 void copy_grefs_from(const EggVertex &other);
146 void clear_grefs();
147
148public:
149 PrimitiveRef::const_iterator pref_begin() const;
150 PrimitiveRef::const_iterator pref_end() const;
151 PrimitiveRef::size_type pref_size() const;
152PUBLISHED:
153 int has_pref(const EggPrimitive *prim) const;
154
155#ifdef _DEBUG
156 void test_gref_integrity() const;
157 void test_pref_integrity() const;
158#else
159 void test_gref_integrity() const { }
160 void test_pref_integrity() const { }
161#endif // _DEBUG
162
163 void output(std::ostream &out) const;
164
165 EggMorphVertexList _dxyzs;
166
167private:
168 EggVertexPool *_pool;
169 bool _forward_reference;
170 int _index;
171 int _external_index, _external_index2;
172 LPoint4d _pos;
173 short _num_dimensions;
174 GroupRef _gref;
175 PrimitiveRef _pref;
176
177 UVMap _uv_map;
178 AuxMap _aux_map;
179
180public:
181 static TypeHandle get_class_type() {
182 return _type_handle;
183 }
184 static void init_type() {
185 EggObject::init_type();
186 EggAttributes::init_type();
187 register_type(_type_handle, "EggVertex",
188 EggObject::get_class_type(),
189 EggAttributes::get_class_type());
190 }
191 virtual TypeHandle get_type() const {
192 return get_class_type();
193 }
194 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
195
196private:
197 static TypeHandle _type_handle;
198
199 friend class EggVertexPool;
200 friend class EggGroup;
201 friend class EggPrimitive;
202};
203
204INLINE std::ostream &operator << (std::ostream &out, const EggVertex &vert) {
205 vert.output(out);
206 return out;
207}
208
209/**
210 * An STL function object for sorting vertices into order by properties.
211 * Returns true if the two referenced EggVertex pointers are in sorted order,
212 * false otherwise.
213 */
214class EXPCL_PANDA_EGG UniqueEggVertices {
215public:
216 INLINE bool operator ()(const EggVertex *v1, const EggVertex *v2) const;
217};
218
219#include "eggVertex.I"
220
221#endif
void transform(const LMatrix4d &mat)
Applies the indicated transformation matrix to the attributes.
int compare_to(const EggAttributes &other) const
An ordering operator to compare two vertices for sorting order.
void write(std::ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
bool sorts_less_than(const EggAttributes &other) const
An ordering operator to compare two vertices for sorting order.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition eggGroup.h:34
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
The set of named auxiliary data that may or may not be assigned to a vertex.
A collection of vertices.
The set of UV's that may or may not be assigned to a vertex.
Definition eggVertexUV.h:29
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition eggVertex.h:39
const EggVertexUV * get_uv_obj(const std::string &name) const
Returns the named EggVertexUV object, which defines both the UV coordinate pair for this name and the...
void set_uv_obj(EggVertexUV *vertex_uv)
Sets the indicated EggVertexUV on the vertex.
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 EggVertexAux * get_aux_obj(const std::string &name) const
Returns the named EggVertexAux object, which defines the auxiliary data for this name.
bool has_uvw(const std::string &name) const
Returns true if the vertex has the named UV coordinate triple, and the named UV coordinate triple is ...
bool has_gref(const EggGroup *group) const
Returns true if the indicated group references this vertex, false otherwise.
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
Definition eggVertex.I:158
void clear_grefs()
Removes all group references from the vertex, so that it is not assigned to any group.
aux_size_type aux_size() const
Returns the number of auxiliary datas on the vertex.
Definition eggVertex.I:269
int get_index() const
Returns the index number of the vertex within its pool.
Definition eggVertex.I:277
int has_pref(const EggPrimitive *prim) const
Returns the number of times the vertex appears in the indicated primitive, or 0 if it does not appear...
EggVertexUV * modify_uv_obj(const std::string &name)
Returns a modifiable pointer to the named EggVertexUV object, which defines both the UV coordinate pa...
bool has_aux() const
Returns true if the vertex has any auxiliary data, false otherwise.
Definition eggVertex.I:166
void set_aux(const std::string &name, const LVecBase4d &aux)
Sets the indicated auxiliary data quadruple on the vertex.
PrimitiveRef::const_iterator pref_begin() const
Returns an iterator that can, in conjunction with pref_end(), be used to traverse the entire set of p...
int get_external_index() const
Returns the number set by set_external_index().
Definition eggVertex.I:300
uv_size_type uv_size() const
Returns the number of named UV's on the vertex.
Definition eggVertex.I:261
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
Definition eggVertex.I:19
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
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
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
Definition eggVertex.I:179
PrimitiveRef::const_iterator pref_end() const
Returns an iterator that can, in conjunction with pref_begin(), be used to traverse the entire set of...
const LTexCoord3d & get_uvw(const std::string &name) const
Returns the named UV coordinate triple on the vertex.
GroupRef::const_iterator gref_end() const
Returns an iterator that can, in conjunction with gref_begin(), be used to traverse the entire set of...
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
void set_pos(double pos)
Sets the vertex position.
Definition eggVertex.I:42
GroupRef::size_type gref_size() const
Returns the number of elements between gref_begin() and gref_end().
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
int get_external_index2() const
Returns the number set by set_external_index2().
Definition eggVertex.I:319
void set_uvw(const std::string &name, const LTexCoord3d &texCoord)
Sets the indicated UV coordinate triple on the vertex.
void clear_uv()
Removes all UV coordinate pairs from the vertex.
Definition eggVertex.I:201
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
PrimitiveRef::size_type pref_size() const
Returns the number of elements between pref_begin() and pref_end().
void copy_grefs_from(const EggVertex &other)
Copies all the group references from the other vertex onto this one.
int get_num_local_coord() const
Returns the number of primitives that own this vertex whose vertices are interpreted to be in a local...
LPoint2d get_pos2() const
Only valid if get_num_dimensions() returns 2.
Definition eggVertex.I:120
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
EggVertexAux * modify_aux_obj(const std::string &name)
Returns a modifiable pointer to the named EggVertexAux object, which defines the auxiliary data for t...
void clear_aux()
Removes all auxiliary data from the vertex.
Definition eggVertex.I:209
int get_num_dimensions() const
Returns the number of dimensions the vertex uses.
Definition eggVertex.I:99
GroupRef::const_iterator gref_begin() const
Returns an iterator that can, in conjunction with gref_end(), be used to traverse the entire set of g...
double get_pos1() const
Only valid if get_num_dimensions() returns 1.
Definition eggVertex.I:109
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
Definition eggVertex.I:131
void set_uv(const LTexCoordd &texCoord)
Replaces the unnamed UV coordinate pair on the vertex with the indicated value.
Definition eggVertex.I:193
LPoint4d get_pos4() const
This is always valid, regardless of the value of get_num_dimensions.
Definition eggVertex.I:145
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
const LVecBase4d & get_aux(const std::string &name) const
Returns the named auxiliary data quadruple on the vertex.
int get_num_global_coord() const
Returns the number of primitives that own this vertex whose vertices are interpreted in the global co...
void set_aux_obj(EggVertexAux *vertex_aux)
Sets the indicated EggVertexAux on the vertex.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
An STL function object for sorting vertices into order by properties.
Definition eggVertex.h:214
This is our own Panda specialization on the default STL multiset.
Definition pset.h:108
This is an iterator adaptor that converts any iterator that returns a pair (e.g.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...