diff --git a/panda/src/egg/eggVertex.cxx b/panda/src/egg/eggVertex.cxx index 5efa82b1a6..0f37000f9d 100644 --- a/panda/src/egg/eggVertex.cxx +++ b/panda/src/egg/eggVertex.cxx @@ -260,6 +260,56 @@ transform(const LMatrix4d &mat) { EggAttributes::transform(mat); } + +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::copy_grefs_from +// Access: Public +// Description: Copies all the group references from the other vertex +// onto this one. This assigns the current vertex to +// exactly the same groups, with exactly the same +// memberships, as the given one. +//////////////////////////////////////////////////////////////////// +void EggVertex:: +copy_grefs_from(const EggVertex &other) { + if (&other == this) { + return; + } + test_gref_integrity(); + other.test_gref_integrity(); + + clear_grefs(); + test_gref_integrity(); + + GroupRef::const_iterator gri; + + for (gri = other.gref_begin(); gri != other.gref_end(); ++gri) { + EggGroup *group = *gri; + nassertv(group != NULL); + + group->ref_vertex(this, group->get_vertex_membership(&other)); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::clear_grefs +// Access: Public +// Description: Removes all group references from the vertex, so that +// it is not assigned to any group. +//////////////////////////////////////////////////////////////////// +void EggVertex:: +clear_grefs() { + GroupRef gref_copy = _gref; + GroupRef::const_iterator gri; + for (gri = gref_copy.begin(); gri != gref_copy.end(); ++gri) { + EggGroup *group = *gri; + nassertv(group != NULL); + group->unref_vertex(this); + } + + // Now we should have no more refs. + nassertv(_gref.empty()); +} + #ifndef NDEBUG //////////////////////////////////////////////////////////////////// @@ -309,6 +359,7 @@ test_pref_integrity() const { } } +#endif // NDEBUG //////////////////////////////////////////////////////////////////// // Function: EggVertex::output @@ -323,5 +374,3 @@ output(ostream &out) const { out << get_pool()->get_name() << ":" << get_index(); } } - -#endif // NDEBUG diff --git a/panda/src/egg/eggVertex.h b/panda/src/egg/eggVertex.h index fc0bfd505b..b251c32913 100644 --- a/panda/src/egg/eggVertex.h +++ b/panda/src/egg/eggVertex.h @@ -68,20 +68,22 @@ public: void transform(const LMatrix4d &mat); - INLINE GroupRef::const_iterator gref_begin() const; INLINE GroupRef::const_iterator gref_end() const; INLINE GroupRef::size_type gref_size() const; INLINE bool has_gref(const EggGroup *group) const; + void copy_grefs_from(const EggVertex &other); + void clear_grefs(); + INLINE PrimitiveRef::const_iterator pref_begin() const; INLINE PrimitiveRef::const_iterator pref_end() const; INLINE PrimitiveRef::size_type pref_size() const; INLINE int has_pref(const EggPrimitive *prim) const; #ifndef NDEBUG - void test_pref_integrity() const; void test_gref_integrity() const; + void test_pref_integrity() const; #else void test_gref_integrity() const { } void test_pref_integrity() const { }