diff --git a/panda/src/egg/eggGroup.cxx b/panda/src/egg/eggGroup.cxx index 3116d85879..85181ad837 100644 --- a/panda/src/egg/eggGroup.cxx +++ b/panda/src/egg/eggGroup.cxx @@ -505,6 +505,38 @@ get_vertex_membership(const EggVertex *vert) const { } } +//////////////////////////////////////////////////////////////////// +// Function: EggGroup::set_vertex_membership +// Access: Public +// Description: Explicitly sets the net membership of the indicated +// vertex in this group to the given value. +//////////////////////////////////////////////////////////////////// +void EggGroup:: +set_vertex_membership(EggVertex *vert, double membership) { + if (membership == 0.0) { + unref_vertex(vert); + return; + } + + VertexRef::iterator vri = _vref.find(vert); + + if (vri != _vref.end()) { + // The vertex was already being reffed; just change its membership + // amount. + (*vri).second = membership; + + } else { + // The vertex was not already reffed; ref it. + _vref[vert] = membership; + + bool inserted = vert->_gref.insert(this).second; + // Did the group not exist previously in the vertex's gref list? + // If it was there already, we must be out of sync between + // vertices and groups. + nassertv(inserted); + } +} + //////////////////////////////////////////////////////////////////// // Function: EggGroup::steal_vrefs // Access: Public diff --git a/panda/src/egg/eggGroup.h b/panda/src/egg/eggGroup.h index b0bf95e39a..9a77ef8763 100644 --- a/panda/src/egg/eggGroup.h +++ b/panda/src/egg/eggGroup.h @@ -198,6 +198,7 @@ public: void unref_vertex(EggVertex *vert); void unref_all_vertices(); double get_vertex_membership(const EggVertex *vert) const; + void set_vertex_membership(EggVertex *vert, double membership); void steal_vrefs(EggGroup *other); INLINE VertexRef::const_iterator vref_begin() const; diff --git a/panda/src/egg/eggVertex.I b/panda/src/egg/eggVertex.I index 0c4df8833c..b79b4c9a72 100644 --- a/panda/src/egg/eggVertex.I +++ b/panda/src/egg/eggVertex.I @@ -206,98 +206,6 @@ get_external_index() const { } -//////////////////////////////////////////////////////////////////// -// Function: EggVertex::gref_begin -// Access: Public -// Description: Returns an iterator that can, in conjunction with -// gref_end(), be used to traverse the entire set of -// groups that reference this vertex. Each iterator -// returns a pointer to a group. -// -// This interface is not safe to use outside of -// PANDAEGG.DLL. -//////////////////////////////////////////////////////////////////// -INLINE EggVertex::GroupRef::const_iterator EggVertex:: -gref_begin() const { - return _gref.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: EggVertex::gref_end -// Access: Public -// Description: Returns an iterator that can, in conjunction with -// gref_begin(), be used to traverse the entire set of -// groups that reference this vertex. Each iterator -// returns a pointer to a group. -// -// This interface is not safe to use outside of -// PANDAEGG.DLL. -//////////////////////////////////////////////////////////////////// -INLINE EggVertex::GroupRef::const_iterator EggVertex:: -gref_end() const { - return _gref.end(); -} - -//////////////////////////////////////////////////////////////////// -// Function: EggVertex::gref_size -// Access: Public -// Description: Returns the number of elements between gref_begin() -// and gref_end(). -// -// This interface is not safe to use outside of -// PANDAEGG.DLL. -//////////////////////////////////////////////////////////////////// -INLINE EggVertex::GroupRef::size_type EggVertex:: -gref_size() const { - return _gref.size(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggVertex::pref_begin -// Access: Public -// Description: Returns an iterator that can, in conjunction with -// pref_end(), be used to traverse the entire set of -// primitives that reference this vertex. Each iterator -// returns a pointer to a primitive. -// -// This interface is not safe to use outside of -// PANDAEGG.DLL. -//////////////////////////////////////////////////////////////////// -INLINE EggVertex::PrimitiveRef::const_iterator EggVertex:: -pref_begin() const { - return _pref.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: EggVertex::pref_end -// Access: Public -// Description: Returns an iterator that can, in conjunction with -// pref_begin(), be used to traverse the entire set of -// primitives that reference this vertex. Each iterator -// returns a pointer to a primitive. -// -// This interface is not safe to use outside of -// PANDAEGG.DLL. -//////////////////////////////////////////////////////////////////// -INLINE EggVertex::PrimitiveRef::const_iterator EggVertex:: -pref_end() const { - return _pref.end(); -} - -//////////////////////////////////////////////////////////////////// -// Function: EggVertex::pref_size -// Access: Public -// Description: Returns the number of elements between pref_begin() -// and pref_end(). -// -// This interface is not safe to use outside of -// PANDAEGG.DLL. -//////////////////////////////////////////////////////////////////// -INLINE EggVertex::GroupRef::size_type EggVertex:: -pref_size() const { - return _pref.size(); -} diff --git a/panda/src/egg/eggVertex.cxx b/panda/src/egg/eggVertex.cxx index 88d063dda7..5f3b0cd69a 100644 --- a/panda/src/egg/eggVertex.cxx +++ b/panda/src/egg/eggVertex.cxx @@ -294,6 +294,52 @@ transform(const LMatrix4d &mat) { } +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::gref_begin +// Access: Public +// Description: Returns an iterator that can, in conjunction with +// gref_end(), be used to traverse the entire set of +// groups that reference this vertex. Each iterator +// returns a pointer to a group. +// +// This interface is not safe to use outside of +// PANDAEGG.DLL. +//////////////////////////////////////////////////////////////////// +EggVertex::GroupRef::const_iterator EggVertex:: +gref_begin() const { + return _gref.begin(); +} + +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::gref_end +// Access: Public +// Description: Returns an iterator that can, in conjunction with +// gref_begin(), be used to traverse the entire set of +// groups that reference this vertex. Each iterator +// returns a pointer to a group. +// +// This interface is not safe to use outside of +// PANDAEGG.DLL. +//////////////////////////////////////////////////////////////////// +EggVertex::GroupRef::const_iterator EggVertex:: +gref_end() const { + return _gref.end(); +} + +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::gref_size +// Access: Public +// Description: Returns the number of elements between gref_begin() +// and gref_end(). +// +// This interface is not safe to use outside of +// PANDAEGG.DLL. +//////////////////////////////////////////////////////////////////// +EggVertex::GroupRef::size_type EggVertex:: +gref_size() const { + return _gref.size(); +} + //////////////////////////////////////////////////////////////////// // Function: EggVertex::has_gref // Access: Public @@ -359,6 +405,52 @@ clear_grefs() { nassertv(_gref.empty()); } +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::pref_begin +// Access: Public +// Description: Returns an iterator that can, in conjunction with +// pref_end(), be used to traverse the entire set of +// primitives that reference this vertex. Each iterator +// returns a pointer to a primitive. +// +// This interface is not safe to use outside of +// PANDAEGG.DLL. +//////////////////////////////////////////////////////////////////// +EggVertex::PrimitiveRef::const_iterator EggVertex:: +pref_begin() const { + return _pref.begin(); +} + +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::pref_end +// Access: Public +// Description: Returns an iterator that can, in conjunction with +// pref_begin(), be used to traverse the entire set of +// primitives that reference this vertex. Each iterator +// returns a pointer to a primitive. +// +// This interface is not safe to use outside of +// PANDAEGG.DLL. +//////////////////////////////////////////////////////////////////// +EggVertex::PrimitiveRef::const_iterator EggVertex:: +pref_end() const { + return _pref.end(); +} + +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::pref_size +// Access: Public +// Description: Returns the number of elements between pref_begin() +// and pref_end(). +// +// This interface is not safe to use outside of +// PANDAEGG.DLL. +//////////////////////////////////////////////////////////////////// +EggVertex::GroupRef::size_type EggVertex:: +pref_size() const { + return _pref.size(); +} + //////////////////////////////////////////////////////////////////// // Function: EggVertex::has_pref // Access: Public diff --git a/panda/src/egg/eggVertex.h b/panda/src/egg/eggVertex.h index 6ec48f821b..13743c623e 100644 --- a/panda/src/egg/eggVertex.h +++ b/panda/src/egg/eggVertex.h @@ -84,17 +84,17 @@ 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; + GroupRef::const_iterator gref_begin() const; + GroupRef::const_iterator gref_end() const; + GroupRef::size_type gref_size() const; 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; + PrimitiveRef::const_iterator pref_begin() const; + PrimitiveRef::const_iterator pref_end() const; + PrimitiveRef::size_type pref_size() const; int has_pref(const EggPrimitive *prim) const; #ifndef NDEBUG