From f5a2d932249ad9639bdc1f8ebd73120d9d71ad20 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 8 Jun 2021 10:51:52 -0500 Subject: 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. --- .../nodes/geometry/nodes/node_geo_bounding_box.cc | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source/blender/nodes') 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 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 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(), transforms, r_min, r_max); } + if (set.has()) { + compute_min_max_from_curve_and_transforms( + *set.get_component_for_read(), transforms, r_min, r_max); + } } } -- cgit v1.2.3