diff --git a/panda/src/egg/eggGroup.cxx b/panda/src/egg/eggGroup.cxx index 18f8a5edf4..d1d32fdf39 100644 --- a/panda/src/egg/eggGroup.cxx +++ b/panda/src/egg/eggGroup.cxx @@ -805,7 +805,7 @@ steal_vrefs(EggGroup *other) { } -#ifndef NDEBUG +#ifdef _DEBUG //////////////////////////////////////////////////////////////////// // Function: EggGroup::test_vref_integrity @@ -826,7 +826,7 @@ test_vref_integrity() const { } } -#endif // NDEBUG +#endif // _DEBUG //////////////////////////////////////////////////////////////////// // Function: EggGroup::add_group_ref diff --git a/panda/src/egg/eggGroup.h b/panda/src/egg/eggGroup.h index 84d563a233..7dfeb11ddf 100644 --- a/panda/src/egg/eggGroup.h +++ b/panda/src/egg/eggGroup.h @@ -299,11 +299,11 @@ public: INLINE VertexRef::size_type vref_size() const; PUBLISHED: -#ifndef NDEBUG +#ifdef _DEBUG void test_vref_integrity() const; #else void test_vref_integrity() const { } -#endif // NDEBUG +#endif // _DEBUG void add_group_ref(EggGroup *group); int get_num_group_refs() const; diff --git a/panda/src/egg/eggGroupNode.cxx b/panda/src/egg/eggGroupNode.cxx index 876868e933..82d6ced475 100644 --- a/panda/src/egg/eggGroupNode.cxx +++ b/panda/src/egg/eggGroupNode.cxx @@ -856,6 +856,39 @@ mesh_triangles(int flags) { } } +//////////////////////////////////////////////////////////////////// +// Function: EggGroupNode::make_point_primitives +// Access: Published +// Description: Creates PointLight primitives to reference any +// otherwise unreferences vertices discovered in this +// group or below. +//////////////////////////////////////////////////////////////////// +void EggGroupNode:: +make_point_primitives() { + // Create a temporary node to hold the EggPoint objects we might + // create while we iterate. (We don't add them during the iteration + // to avoid invalidating the iterator.) + PT(EggGroupNode) temp = new EggGroup("temp"); + + EggGroupNode::iterator ci; + for (ci = begin(); ci != end(); ++ci) { + if ((*ci)->is_of_type(EggGroupNode::get_class_type())) { + EggGroupNode *group_child = DCAST(EggGroupNode, *ci); + group_child->make_point_primitives(); + + } else if ((*ci)->is_of_type(EggVertexPool::get_class_type())) { + EggVertexPool *vpool = DCAST(EggVertexPool, *ci); + PT(EggPrimitive) prim = new EggPoint; + vpool->add_unused_vertices_to_prim(prim); + if (!prim->empty()) { + temp->add_child(prim); + } + } + } + + steal_children(*temp); +} + //////////////////////////////////////////////////////////////////// // Function: EggGroupNode::rename_nodes // Access: Published diff --git a/panda/src/egg/eggGroupNode.h b/panda/src/egg/eggGroupNode.h index f719fe9de3..b8b2ea30cd 100644 --- a/panda/src/egg/eggGroupNode.h +++ b/panda/src/egg/eggGroupNode.h @@ -142,6 +142,7 @@ PUBLISHED: int triangulate_polygons(int flags); void mesh_triangles(int flags); + void make_point_primitives(); int rename_nodes(vector_string strip_prefix, bool recurse); diff --git a/panda/src/egg/eggNode.cxx b/panda/src/egg/eggNode.cxx index a71ffbefc7..d93d510081 100644 --- a/panda/src/egg/eggNode.cxx +++ b/panda/src/egg/eggNode.cxx @@ -287,7 +287,7 @@ parse_egg(const string &egg_syntax) { return (egg_error_count() == 0); } -#ifndef NDEBUG +#ifdef _DEBUG //////////////////////////////////////////////////////////////////// // Function: EggNode::test_under_integrity @@ -324,7 +324,7 @@ test_under_integrity() const { } } -#endif // NDEBUG +#endif // _DEBUG //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggNode.h b/panda/src/egg/eggNode.h index 2cc06f02d7..1292b1e2f0 100644 --- a/panda/src/egg/eggNode.h +++ b/panda/src/egg/eggNode.h @@ -84,11 +84,11 @@ PUBLISHED: virtual void write(ostream &out, int indent_level) const=0; bool parse_egg(const string &egg_syntax); -#ifndef NDEBUG +#ifdef _DEBUG void test_under_integrity() const; #else void test_under_integrity() const { } -#endif // NDEBUG +#endif // _DEBUG protected: diff --git a/panda/src/egg/eggPrimitive.cxx b/panda/src/egg/eggPrimitive.cxx index 139e30d579..be1ca432cf 100644 --- a/panda/src/egg/eggPrimitive.cxx +++ b/panda/src/egg/eggPrimitive.cxx @@ -638,12 +638,10 @@ remove_nonunique_verts() { Vertices new_vertices; int num_removed = 0; + pset unique_vertices; for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) { - bool okflag = true; - for (vj = _vertices.begin(); vj != vi && okflag; ++vj) { - okflag = ((*vi) != (*vj)); - } - if (okflag) { + bool inserted = unique_vertices.insert(*vi).second; + if (inserted) { new_vertices.push_back(*vi); } else { prepare_remove_vertex(*vi, vi - _vertices.begin() - num_removed, @@ -803,7 +801,7 @@ copy_vertices(const EggPrimitive &other) { other.test_vref_integrity(); } -#ifndef NDEBUG +#ifdef _DEBUG //////////////////////////////////////////////////////////////////// // Function: EggPrimitive::test_vref_integrity @@ -850,7 +848,7 @@ test_vref_integrity() const { } } -#endif // NDEBUG +#endif // _DEBUG //////////////////////////////////////////////////////////////////// // Function: EggPrimitive::prepare_add_vertex diff --git a/panda/src/egg/eggPrimitive.h b/panda/src/egg/eggPrimitive.h index b3f96ee786..29c2a6bbff 100644 --- a/panda/src/egg/eggPrimitive.h +++ b/panda/src/egg/eggPrimitive.h @@ -182,11 +182,11 @@ PUBLISHED: virtual void write(ostream &out, int indent_level) const=0; -#ifndef NDEBUG +#ifdef _DEBUG void test_vref_integrity() const; #else void test_vref_integrity() const { } -#endif // NDEBUG +#endif // _DEBUG protected: Vertices _vertices; diff --git a/panda/src/egg/eggVertex.cxx b/panda/src/egg/eggVertex.cxx index 3bf4fa413f..9a95dddb8a 100644 --- a/panda/src/egg/eggVertex.cxx +++ b/panda/src/egg/eggVertex.cxx @@ -670,7 +670,7 @@ has_pref(const EggPrimitive *prim) const { return _pref.count((EggPrimitive *)prim); } -#ifndef NDEBUG +#ifdef _DEBUG //////////////////////////////////////////////////////////////////// // Function: EggVertex::test_gref_integrity diff --git a/panda/src/egg/eggVertex.h b/panda/src/egg/eggVertex.h index 95d9856051..0cefb0a1b3 100644 --- a/panda/src/egg/eggVertex.h +++ b/panda/src/egg/eggVertex.h @@ -129,13 +129,13 @@ public: PUBLISHED: int has_pref(const EggPrimitive *prim) const; -#ifndef NDEBUG +#ifdef _DEBUG void test_gref_integrity() const; void test_pref_integrity() const; #else void test_gref_integrity() const { } void test_pref_integrity() const { } -#endif // NDEBUG +#endif // _DEBUG void output(ostream &out) const; diff --git a/panda/src/egg/eggVertexPool.cxx b/panda/src/egg/eggVertexPool.cxx index a29f5fc03b..86d8ae51b7 100644 --- a/panda/src/egg/eggVertexPool.cxx +++ b/panda/src/egg/eggVertexPool.cxx @@ -651,6 +651,23 @@ remove_unused_vertices() { return num_removed; } +//////////////////////////////////////////////////////////////////// +// Function: EggVertexPool::add_unused_vertices_to_prim +// Access: Public +// Description: Adds all of the unused vertices in this vertex pool +// to the indicated primitive, in ascending order. +//////////////////////////////////////////////////////////////////// +void EggVertexPool:: +add_unused_vertices_to_prim(EggPrimitive *prim) { + IndexVertices::iterator ivi; + for (ivi = _index_vertices.begin(); ivi != _index_vertices.end(); ++ivi) { + EggVertex *vertex = (*ivi).second; + if (vertex->pref_size() == 0) { + prim->add_vertex(vertex); + } + } +} + // A function object for split_vertex(), used in transform(), below. class IsLocalVertexSplitter { public: diff --git a/panda/src/egg/eggVertexPool.h b/panda/src/egg/eggVertexPool.h index 8bb424f33e..16781ce53b 100644 --- a/panda/src/egg/eggVertexPool.h +++ b/panda/src/egg/eggVertexPool.h @@ -128,6 +128,7 @@ PUBLISHED: void remove_vertex(EggVertex *vertex); int remove_unused_vertices(); + void add_unused_vertices_to_prim(EggPrimitive *prim); void transform(const LMatrix4d &mat);