41 _forward_reference =
false;
44 _external_index2 = -1;
45 set_pos(LPoint3d(0.0, 0.0, 0.0));
46 test_pref_integrity();
47 test_gref_integrity();
58 _external_index(copy._external_index),
59 _external_index2(copy._external_index2),
61 _num_dimensions(copy._num_dimensions),
62 _uv_map(copy._uv_map),
63 _aux_map(copy._aux_map)
66 _forward_reference =
false;
68 test_pref_integrity();
69 test_gref_integrity();
79 EggObject::operator = (copy);
80 EggAttributes::operator = (copy);
82 _external_index = copy._external_index;
83 _external_index2 = copy._external_index2;
85 _num_dimensions = copy._num_dimensions;
86 _uv_map = copy._uv_map;
87 _aux_map = copy._aux_map;
89 test_pref_integrity();
90 test_gref_integrity();
102 nassertv(_pool ==
nullptr);
106 nassertv(_gref.empty());
107 nassertv(_pref.empty());
117 if (ui != _uv_map.end()) {
119 return !uv_obj->
has_w();
131 if (ui != _uv_map.end()) {
133 return uv_obj->
has_w();
143 AuxMap::const_iterator xi = _aux_map.find(name);
144 return (xi != _aux_map.end());
154 nassertr(ui != _uv_map.end(), LTexCoordd::zero());
155 return (*ui).second->get_uv();
165 nassertr(ui != _uv_map.end(), LTexCoord3d::zero());
166 return (*ui).second->get_uvw();
175 AuxMap::const_iterator xi = _aux_map.find(name);
176 nassertr(xi != _aux_map.end(), LVecBase4d::zero());
177 return (*xi).second->get_aux();
186 set_uv(
const string &name,
const LTexCoordd &uv) {
190 if (uv_obj.is_null()) {
197 nassertv(
get_uv(fname) == uv);
206 set_uvw(
const string &name,
const LTexCoord3d &uvw) {
210 if (uv_obj.is_null()) {
214 uv_obj->set_uvw(uvw);
217 nassertv(
get_uvw(fname) == uvw);
225 set_aux(
const string &name,
const LVecBase4d &aux) {
228 if (aux_obj.is_null()) {
232 aux_obj->set_aux(aux);
235 nassertv(
get_aux(name) == aux);
247 if (ui != _uv_map.end()) {
261 AuxMap::const_iterator xi = _aux_map.find(name);
262 if (xi != _aux_map.end()) {
276 if (ui != _uv_map.end()) {
277 if ((*ui).second->get_ref_count() != 1) {
294 AuxMap::iterator xi = _aux_map.find(name);
295 if (xi != _aux_map.end()) {
296 if ((*xi).second->get_ref_count() != 1) {
313 _uv_map[uv->get_name()] = uv;
322 _aux_map[aux->get_name()] = aux;
339 _aux_map.erase(name);
352 nassertr(pool == second->
get_pool(),
nullptr);
357 if (pool ==
nullptr) {
360 middle = pool->make_new_vertex();
365 if (first->has_normal() && second->has_normal()) {
366 LNormald normal = (first->get_normal() + second->get_normal()) / 2;
368 middle->set_normal(normal);
370 if (first->has_color() && second->has_color()) {
376 const_uv_iterator it;
381 if (first_uv !=
nullptr && second_uv !=
nullptr) {
382 middle->set_uv_obj(EggVertexUV::make_average(first_uv, second_uv));
387 const_aux_iterator ai;
392 if (first_aux !=
nullptr && second_aux !=
nullptr) {
393 middle->set_aux_obj(EggVertexAux::make_average(first_aux, second_aux));
398 EggMorphVertexList::const_iterator vi, vi2;
399 for (vi = first->_dxyzs.begin(); vi != first->_dxyzs.end(); ++vi) {
400 for (vi2 = second->_dxyzs.begin(); vi2 != second->_dxyzs.end(); ++vi2) {
401 if (vi->get_name() == vi2->get_name()) {
403 (vi->get_offset() + vi2->get_offset()) / 2));
409 EggMorphNormalList::const_iterator ni, ni2;
410 for (ni = first->_dxyzs.begin(); ni != first->_dxyzs.end(); ++ni) {
411 for (ni2 = second->_dxyzs.begin(); ni2 != second->_dxyzs.end(); ++ni2) {
412 if (ni->get_name() == ni2->get_name()) {
414 (ni->get_offset() + ni2->get_offset()) / 2));
420 EggMorphColorList::const_iterator ci, ci2;
421 for (ci = first->_drgbas.begin(); ci != first->_drgbas.end(); ++ci) {
422 for (ci2 = second->_drgbas.begin(); ci2 != second->_drgbas.end(); ++ci2) {
423 if (ci->get_name() == ci2->get_name()) {
425 (ci->get_offset() + ci2->get_offset()) / 2));
432 GroupRef::iterator gi;
433 for (gi = first->_gref.begin(); gi != first->_gref.end(); ++gi) {
435 if (second->_gref.count(group)) {
448 for (gi = second->_gref.begin(); gi != second->_gref.end(); ++gi) {
450 if (second->_gref.count(group) == 0) {
462 class GroupRefEntry {
464 GroupRefEntry(
EggGroup *group,
double membership)
465 : _group(group), _membership(membership) { }
467 bool operator < (
const GroupRefEntry &other)
const {
468 return _group->get_name() < other._group->get_name();
470 void output(ostream &out)
const {
471 out << _group->get_name() <<
":" << _membership;
478 INLINE ostream &operator << (ostream &out,
const GroupRefEntry &gre) {
487 write(ostream &out,
int indent_level)
const {
488 test_pref_integrity();
489 test_gref_integrity();
492 <<
"<Vertex> " << _index <<
" {\n";
496 indent(out, indent_level+1);
497 for (
int i = 0; i < _num_dimensions; i++) {
498 out <<
" " << _pos[i];
502 UVMap::const_iterator ui;
503 for (ui = _uv_map.begin(); ui != _uv_map.end(); ++ui) {
504 (*ui).second->write(out, indent_level + 2);
507 AuxMap::const_iterator xi;
508 for (xi = _aux_map.begin(); xi != _aux_map.end(); ++xi) {
509 (*xi).second->write(out, indent_level + 2);
514 _dxyzs.write(out, indent_level + 2,
"<Dxyz>", 3);
518 if (!_gref.empty()) {
522 GroupRef::const_iterator gi;
523 for (gi = _gref.begin(); gi != _gref.end(); ++gi) {
524 gre.insert(GroupRefEntry(*gi, (*gi)->get_vertex_membership(
this)));
554 if (_external_index != other._external_index) {
555 return (
int)_external_index - (int)other._external_index;
557 if (_external_index2 != other._external_index2) {
558 return (
int)_external_index2 - (int)other._external_index2;
560 if (_num_dimensions != other._num_dimensions) {
561 return (
int)_num_dimensions - (int)other._num_dimensions;
565 _pos.compare_to(other._pos, egg_parameters->_pos_threshold);
569 compare = _dxyzs.
compare_to(other._dxyzs, egg_parameters->_pos_threshold);
575 UVMap::const_iterator ai, bi;
576 ai = _uv_map.begin();
577 bi = other._uv_map.begin();
578 while (ai != _uv_map.end() && bi != other._uv_map.end()) {
579 if ((*ai).first < (*bi).first) {
582 }
else if ((*bi).first < (*ai).first) {
586 int compare = (*ai).second->compare_to(*(*bi).second);
594 if (bi != other._uv_map.end()) {
597 if (ai != _uv_map.end()) {
602 AuxMap::const_iterator ci, di;
603 ci = _aux_map.begin();
604 di = other._aux_map.begin();
605 while (ci != _aux_map.end() && di != other._aux_map.end()) {
606 if ((*ci).first < (*di).first) {
609 }
else if ((*di).first < (*ci).first) {
613 int compare = (*ci).second->compare_to(*(*di).second);
621 if (di != other._aux_map.end()) {
624 if (ci != _aux_map.end()) {
637 test_pref_integrity();
639 PrimitiveRef::const_iterator pri;
655 test_pref_integrity();
657 PrimitiveRef::const_iterator pri;
675 EggMorphVertexList::iterator mi;
676 for (mi = _dxyzs.begin(); mi != _dxyzs.end(); ++mi) {
682 morph.set_offset((*mi).get_offset() * mat);
686 for (ui = _uv_map.begin(); ui != _uv_map.end(); ++ui) {
687 (*ui).second->transform(mat);
703 return _gref.begin();
734 return _gref.count((
EggGroup *)group) != 0;
748 if (&other ==
this) {
751 test_gref_integrity();
752 other.test_gref_integrity();
755 test_gref_integrity();
757 GroupRef::const_iterator gri;
761 nassertv(group !=
nullptr);
774 GroupRef::const_iterator gri;
775 for (gri = gref_copy.begin(); gri != gref_copy.end(); ++gri) {
777 nassertv(group !=
nullptr);
782 nassertv(_gref.empty());
792 EggVertex::PrimitiveRef::const_iterator
EggVertex:: 794 return _pref.begin();
804 EggVertex::PrimitiveRef::const_iterator
EggVertex:: 835 test_gref_integrity()
const {
838 GroupRef::const_iterator gri;
842 nassertv(group !=
nullptr);
846 nassertv(membership != 0.0);
855 test_pref_integrity()
const {
858 PrimitiveRef::const_iterator pri;
862 nassertv(prim !=
nullptr);
865 EggPrimitive::iterator vi;
866 vi = find(prim->begin(), prim->end(),
this);
867 nassertv(vi != prim->end());
877 output(ostream &out)
const {
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
The set of UV's that may or may not be assigned to a vertex.
GroupRef::size_type gref_size() const
Returns the number of elements between gref_begin() and gref_end().
GroupRef::const_iterator gref_end() const
Returns an iterator that can, in conjunction with gref_begin(), be used to traverse the entire set of...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PrimitiveRef::size_type pref_size() const
Returns the number of elements between pref_begin() and pref_end().
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 clear_aux()
Removes all auxiliary data from the vertex.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_pos(double pos)
Sets the vertex position.
bool has_aux() const
Returns true if the vertex has any auxiliary data, false otherwise.
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write(std::ostream &out, int indent_level) const
Writes the vertex to the indicated output stream in Egg format.
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
void transform(const LMatrix4d &mat)
Applies the indicated transformation matrix to the attributes.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
const_aux_iterator aux_end() const
Returns an iterator that allows walking through the complete set of auxiliary data on the vertex.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn't completely bogus.
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...
void clear_grefs()
Removes all group references from the vertex, so that it is not assigned to any group.
A single <Dxyz> or <Duv> or some such entry.
LColor get_color() const
Returns the color set on this particular attribute.
EggVertex & operator=(const EggVertex ©)
Copies all properties of the vertex except its vertex pool, index number, and group membership.
void write(std::ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
void unref_vertex(EggVertex *vert)
Removes the vertex from the set of those referenced by the group.
bool has_gref(const EggGroup *group) const
Returns true if the indicated group references this vertex, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
const LTexCoord3d & get_uvw(const std::string &name) const
Returns the named UV coordinate triple on the vertex.
The set of attributes that may be applied to vertices as well as polygons, such as surface normal and...
int get_index() const
Returns the index number of the vertex within its pool.
void clear_uv()
Removes all UV coordinate pairs from the vertex.
bool has_w() const
Returns true if the texture coordinate has a third, w component, false if it is just a normal 2-d tex...
bool is_local_coord() const
Returns true if this node's vertices are not in the global coordinate space.
static std::string filter_name(const std::string &name)
Returns the actual name that should be set for a given name string.
void set_uv_obj(EggVertexUV *vertex_uv)
Sets the indicated EggVertexUV on the vertex.
void transform(const LMatrix4d &mat)
Applies the indicated transformation matrix to the vertex.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
void set_uvw(const std::string &name, const LTexCoord3d &texCoord)
Sets the indicated UV coordinate triple on the vertex.
void set_vertex_membership(EggVertex *vert, double membership)
Explicitly sets the net membership of the indicated vertex in this group to the given value.
PrimitiveRef::const_iterator pref_end() const
Returns an iterator that can, in conjunction with pref_begin(), be used to traverse the entire set of...
void write_long_list(std::ostream &out, int indent_level, InputIterator ifirst, InputIterator ilast, std::string first_prefix="", std::string later_prefix="", int max_col=72)
Writes a list of things to the indicated output stream, with a space separating each item.
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
double get_vertex_membership(const EggVertex *vert) const
Returns the amount of membership of the indicated vertex in this group.
The set of named auxiliary data that may or may not be assigned to a vertex.
int compare_to(const EggVertex &other) const
An ordering operator to compare two vertices for sorting order.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
const_aux_iterator aux_begin() const
Returns an iterator that allows walking through the complete set of auxiliary data on the vertex.
PT(EggVertex) EggVertex
Creates a new vertex that lies in between the two given vertices.
EggVertexUV * modify_uv_obj(const std::string &name)
Returns a modifiable pointer to the named EggVertexUV object, which defines both the UV coordinate pa...
int compare_to(const EggMorphList< MorphType > &other, double threshold) const
compare_to() compares a different space than the operator methods, which only check the morph's name.
EggVertexAux * modify_aux_obj(const std::string &name)
Returns a modifiable pointer to the named EggVertexAux object, which defines the auxiliary data for t...
const EggVertexAux * get_aux_obj(const std::string &name) const
Returns the named EggVertexAux object, which defines the auxiliary data for this name.
const_uv_iterator uv_begin() const
Returns an iterator that allows walking through the complete set of named UV's on the vertex.
void set_aux_obj(EggVertexAux *vertex_aux)
Sets the indicated EggVertexAux on the vertex.
void set_aux(const std::string &name, const LVecBase4d &aux)
Sets the indicated auxiliary data quadruple on the vertex.
void ref_vertex(EggVertex *vert, double membership=1.0)
Adds the vertex to the set of those referenced by the group, at the indicated membership level.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LPoint4d get_pos4() const
This is always valid, regardless of the value of get_num_dimensions.
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 ...
int get_num_global_coord() const
Returns the number of primitives that own this vertex whose vertices are interpreted in the global co...
This is our own Panda specialization on the default STL set.
const LVecBase4d & get_aux(const std::string &name) const
Returns the named auxiliary data quadruple on the vertex.
void copy_grefs_from(const EggVertex &other)
Copies all the group references from the other vertex onto this one.
TypeHandle is the identifier used to differentiate C++ class types.
int get_num_local_coord() const
Returns the number of primitives that own this vertex whose vertices are interpreted to be in a local...
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_uv(const LTexCoordd &texCoord)
Replaces the unnamed UV coordinate pair on the vertex with the indicated value.
A collection of vertices.
The highest-level base class in the egg directory.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int compare_to(const EggAttributes &other) const
An ordering operator to compare two vertices for sorting order.
const_uv_iterator uv_end() const
Returns an iterator that allows walking through the complete set of named UV's on the vertex.