diff --git a/doc/ReleaseNotes b/doc/ReleaseNotes index eafbf4f3eb..4baeb47d6c 100644 --- a/doc/ReleaseNotes +++ b/doc/ReleaseNotes @@ -83,6 +83,7 @@ Miscellaneous * Fix interrogate syntax error with C++11-style attributes in declarators * Fix regression with BufferViewer in double-precision build (#1365) * Fix `PandaNode.nested_vertices` not updating properly +* Prevent Panda calculating bounding volume of Geom with custom bounding volume * Add `do_events()` and `process_event()` snake_case aliases in eventMgr * Support second arg of None in `replace_texture()` / `replace_material()` * Support `os.fspath()` for ConfigVariableFilename objects (#1406) diff --git a/panda/src/gobj/geom.I b/panda/src/gobj/geom.I index 3fa32ade36..0f6b5fc7e8 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 = 0; cdata->_internal_bounds_stale = true; } diff --git a/panda/src/gobj/geom.cxx b/panda/src/gobj/geom.cxx index 820c67875e..11c49f14c8 100644 --- a/panda/src/gobj/geom.cxx +++ b/panda/src/gobj/geom.cxx @@ -1119,9 +1119,28 @@ int Geom:: get_nested_vertices(Thread *current_thread) const { CDLockedReader cdata(_cycler, current_thread); if (cdata->_internal_bounds_stale) { - CDWriter cdataw(((Geom *)this)->_cycler, cdata, false); - compute_internal_bounds(cdataw, current_thread); - return cdataw->_nested_vertices; + if (cdata->_user_bounds != nullptr) { + // Don't do the expensive compute_internal_bounds call. + if (cdata->_nested_vertices == 0) { + CDWriter cdataw(((Geom *)this)->_cycler, cdata, false); + int num_vertices = 0; + + Primitives::const_iterator pi; + for (pi = cdataw->_primitives.begin(); + pi != cdataw->_primitives.end(); + ++pi) { + GeomPrimitivePipelineReader reader((*pi).get_read_pointer(current_thread), current_thread); + num_vertices += reader.get_num_vertices(); + } + + cdataw->_nested_vertices = num_vertices; + return num_vertices; + } + } else { + CDWriter cdataw(((Geom *)this)->_cycler, cdata, false); + compute_internal_bounds(cdataw, current_thread); + return cdataw->_nested_vertices; + } } return cdata->_nested_vertices; }