[Bf-blender-cvs] [500045a0d3b] master: Geometry Nodes: Support volumes in the bounding box node

Hans Goudey noreply at git.blender.org
Thu Apr 8 21:32:50 CEST 2021


Commit: 500045a0d3b57f4333527cb710f05f666acaf904
Author: Hans Goudey
Date:   Thu Apr 8 14:32:41 2021 -0500
Branches: master
https://developer.blender.org/rB500045a0d3b57f4333527cb710f05f666acaf904

Geometry Nodes: Support volumes in the bounding box node

Where possible, nodes in the "Geometry" category should support all
geometry component types. This adds support for volumes in the
recently added bounding box node, based on functions added in the
previous two commits.

Differential Revision: https://developer.blender.org/D10906

===================================================================

M	source/blender/blenkernel/intern/geometry_set.cc
M	source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index fd86f4e550c..3e457e48076 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -178,6 +178,10 @@ void GeometrySet::compute_boundbox_without_instances(float3 *r_min, float3 *r_ma
   if (mesh != nullptr) {
     BKE_mesh_wrapper_minmax(mesh, *r_min, *r_max);
   }
+  const Volume *volume = this->get_volume_for_read();
+  if (volume != nullptr) {
+    BKE_volume_min_max(volume, *r_min, *r_max);
+  }
 }
 
 std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc b/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc
index 702fca242ea..96455f080e7 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc
@@ -14,6 +14,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include "BKE_volume.h"
+
 #include "node_geometry_util.hh"
 
 static bNodeSocketTemplate geo_node_bounding_box_in[] = {
@@ -52,6 +54,36 @@ static void compute_min_max_from_position_and_transform(const GeometryComponent
   }
 }
 
+static void compute_min_max_from_volume_and_transforms(const VolumeComponent &volume_component,
+                                                       Span<float4x4> transforms,
+                                                       float3 &r_min,
+                                                       float3 &r_max)
+{
+#ifdef WITH_OPENVDB
+  const Volume *volume = volume_component.get_for_read();
+  if (volume == nullptr) {
+    return;
+  }
+  for (const int i : IndexRange(BKE_volume_num_grids(volume))) {
+    const VolumeGrid *volume_grid = BKE_volume_grid_get_for_read(volume, i);
+    openvdb::GridBase::ConstPtr grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid);
+
+    for (const float4x4 &transform : transforms) {
+      openvdb::GridBase::ConstPtr instance_grid = BKE_volume_grid_shallow_transform(grid,
+                                                                                    transform);
+      float3 grid_min = float3(FLT_MAX);
+      float3 grid_max = float3(-FLT_MAX);
+      if (BKE_volume_grid_bounds(instance_grid, grid_min, grid_max)) {
+        DO_MIN(grid_min, r_min);
+        DO_MAX(grid_max, r_max);
+      }
+    }
+  }
+#else
+  UNUSED_VARS(volume_component, transforms, r_min, r_max);
+#endif
+}
+
 static void compute_geometry_set_instances_boundbox(const GeometrySet &geometry_set,
                                                     float3 &r_min,
                                                     float3 &r_max)
@@ -71,6 +103,10 @@ static void compute_geometry_set_instances_boundbox(const GeometrySet &geometry_
       compute_min_max_from_position_and_transform(
           *set.get_component_for_read<MeshComponent>(), transforms, r_min, r_max);
     }
+    if (set.has<VolumeComponent>()) {
+      compute_min_max_from_volume_and_transforms(
+          *set.get_component_for_read<VolumeComponent>(), transforms, r_min, r_max);
+    }
   }
 }



More information about the Bf-blender-cvs mailing list