diff options
author | Hans Goudey <h.goudey@me.com> | 2021-04-08 22:32:41 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-04-08 22:32:41 +0300 |
commit | 500045a0d3b57f4333527cb710f05f666acaf904 (patch) | |
tree | 700f0bb619c8bd9274ff380692e9343a154b4b5c /source/blender/nodes | |
parent | 57fe650b76f85538cad961b738ce6d3e4682404f (diff) |
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
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc | 36 |
1 files changed, 36 insertions, 0 deletions
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); + } } } |