[Bf-blender-cvs] [f5a2d932249] master: Geometry Nodes: Support curve instances in the bounding box node

Hans Goudey noreply at git.blender.org
Tue Jun 8 17:52:32 CEST 2021


Commit: f5a2d932249ad9639bdc1f8ebd73120d9d71ad20
Author: Hans Goudey
Date:   Tue Jun 8 10:51:52 2021 -0500
Branches: master
https://developer.blender.org/rBf5a2d932249ad9639bdc1f8ebd73120d9d71ad20

Geometry Nodes: Support curve instances in the bounding box node

Currently curve instances are misleading, since `CurveEval` is created
from scratch from the original `Curve`, but this won't always be true.

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

M	source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc

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

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 b6fa4c0d48f..f1731052515 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,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include "BKE_spline.hh"
 #include "BKE_volume.h"
 
 #include "node_geometry_util.hh"
@@ -81,6 +82,28 @@ static void compute_min_max_from_volume_and_transforms(const VolumeComponent &vo
 #endif
 }
 
+static void compute_min_max_from_curve_and_transforms(const CurveComponent &curve_component,
+                                                      Span<float4x4> transforms,
+                                                      float3 &r_min,
+                                                      float3 &r_max)
+{
+  const CurveEval *curve = curve_component.get_for_read();
+  if (curve == nullptr) {
+    return;
+  }
+  for (const SplinePtr &spline : curve->splines()) {
+    Span<float3> positions = spline->evaluated_positions();
+
+    for (const float4x4 &transform : transforms) {
+      for (const int i : positions.index_range()) {
+        const float3 position = positions[i];
+        const float3 transformed_position = transform * position;
+        minmax_v3v3_v3(r_min, r_max, transformed_position);
+      }
+    }
+  }
+}
+
 static void compute_geometry_set_instances_boundbox(const GeometrySet &geometry_set,
                                                     float3 &r_min,
                                                     float3 &r_max)
@@ -104,6 +127,10 @@ static void compute_geometry_set_instances_boundbox(const GeometrySet &geometry_
       compute_min_max_from_volume_and_transforms(
           *set.get_component_for_read<VolumeComponent>(), transforms, r_min, r_max);
     }
+    if (set.has<CurveComponent>()) {
+      compute_min_max_from_curve_and_transforms(
+          *set.get_component_for_read<CurveComponent>(), transforms, r_min, r_max);
+    }
   }
 }



More information about the Bf-blender-cvs mailing list