Browse Source

gobj: Don't wastefully compute bounds for Geom with custom bounds

This was done by `get_nested_vertices()`, which now won't call the expensive `compute_internal_bounds()` if there was a custom bounding volume set.
rdb 3 years ago
parent
commit
7f916eeb74
3 changed files with 24 additions and 3 deletions
  1. 1 0
      doc/ReleaseNotes
  2. 1 0
      panda/src/gobj/geom.I
  3. 22 3
      panda/src/gobj/geom.cxx

+ 1 - 0
doc/ReleaseNotes

@@ -83,6 +83,7 @@ Miscellaneous
 * Fix interrogate syntax error with C++11-style attributes in declarators
 * Fix interrogate syntax error with C++11-style attributes in declarators
 * Fix regression with BufferViewer in double-precision build (#1365)
 * Fix regression with BufferViewer in double-precision build (#1365)
 * Fix `PandaNode.nested_vertices` not updating properly
 * 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
 * Add `do_events()` and `process_event()` snake_case aliases in eventMgr
 * Support second arg of None in `replace_texture()` / `replace_material()`
 * Support second arg of None in `replace_texture()` / `replace_material()`
 * Support `os.fspath()` for ConfigVariableFilename objects (#1406)
 * Support `os.fspath()` for ConfigVariableFilename objects (#1406)

+ 1 - 0
panda/src/gobj/geom.I

@@ -379,6 +379,7 @@ calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
  */
  */
 INLINE void Geom::
 INLINE void Geom::
 mark_internal_bounds_stale(CData *cdata) {
 mark_internal_bounds_stale(CData *cdata) {
+  cdata->_nested_vertices = 0;
   cdata->_internal_bounds_stale = true;
   cdata->_internal_bounds_stale = true;
 }
 }
 
 

+ 22 - 3
panda/src/gobj/geom.cxx

@@ -1119,9 +1119,28 @@ int Geom::
 get_nested_vertices(Thread *current_thread) const {
 get_nested_vertices(Thread *current_thread) const {
   CDLockedReader cdata(_cycler, current_thread);
   CDLockedReader cdata(_cycler, current_thread);
   if (cdata->_internal_bounds_stale) {
   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;
   return cdata->_nested_vertices;
 }
 }