diff --git a/panda/src/gobj/geom.I b/panda/src/gobj/geom.I index 3fa32ade36..fb7e858d84 100644 --- a/panda/src/gobj/geom.I +++ b/panda/src/gobj/geom.I @@ -379,6 +379,7 @@ calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, */ INLINE void Geom:: mark_internal_bounds_stale(CData *cdata) { + cdata->_nested_vertices_stale = true; cdata->_internal_bounds_stale = true; } @@ -512,6 +513,7 @@ CData() : _shade_model(SM_uniform), _geom_rendering(0), _nested_vertices(0), + _nested_vertices_stale(true), _internal_bounds_stale(true), _bounds_type(BoundingVolume::BT_default) { @@ -527,6 +529,7 @@ CData(GeomVertexData *data) : _shade_model(SM_uniform), _geom_rendering(0), _nested_vertices(0), + _nested_vertices_stale(true), _internal_bounds_stale(true), _bounds_type(BoundingVolume::BT_default) { diff --git a/panda/src/gobj/geom.cxx b/panda/src/gobj/geom.cxx index 5733c4bee0..624216d38c 100644 --- a/panda/src/gobj/geom.cxx +++ b/panda/src/gobj/geom.cxx @@ -1098,9 +1098,9 @@ get_bounds(Thread *current_thread) const { int Geom:: get_nested_vertices(Thread *current_thread) const { CDLockedReader cdata(_cycler, current_thread); - if (cdata->_internal_bounds_stale) { + if (cdata->_nested_vertices_stale) { CDWriter cdataw(((Geom *)this)->_cycler, cdata, false); - compute_internal_bounds(cdataw, current_thread); + compute_nested_vertices(cdataw, current_thread); return cdataw->_nested_vertices; } return cdata->_nested_vertices; @@ -1468,9 +1468,26 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const { cdata->_internal_bounds = new BoundingBox; } } + cdata->_internal_bounds_stale = false; +} + +/** + * Recomputes the number of nested vertices in this Geom. + */ +void Geom:: +compute_nested_vertices(Geom::CData *cdata, Thread *current_thread) const { + int num_vertices = 0; + + Primitives::const_iterator pi; + for (pi = cdata->_primitives.begin(); + pi != cdata->_primitives.end(); + ++pi) { + GeomPrimitivePipelineReader reader((*pi).get_read_pointer(current_thread), current_thread); + num_vertices += reader.get_num_vertices(); + } cdata->_nested_vertices = num_vertices; - cdata->_internal_bounds_stale = false; + cdata->_nested_vertices_stale = false; } /** diff --git a/panda/src/gobj/geom.h b/panda/src/gobj/geom.h index 073805e7ca..986ca5a827 100644 --- a/panda/src/gobj/geom.h +++ b/panda/src/gobj/geom.h @@ -185,6 +185,7 @@ private: INLINE void mark_internal_bounds_stale(CData *cdata); void compute_internal_bounds(CData *cdata, Thread *current_thread) const; + void compute_nested_vertices(CData *cdata, Thread *current_thread) const; void do_calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, PN_stdfloat &sq_center_dist, bool &found_any, @@ -327,6 +328,7 @@ private: CPT(BoundingVolume) _internal_bounds; int _nested_vertices; + bool _nested_vertices_stale; bool _internal_bounds_stale; BoundingVolume::BoundsType _bounds_type; CPT(BoundingVolume) _user_bounds;