diff --git a/source/blender/geometry/GEO_mesh_to_volume.hh b/source/blender/geometry/GEO_mesh_to_volume.hh index 1fba96a7fda..7ac7bb76496 100644 --- a/source/blender/geometry/GEO_mesh_to_volume.hh +++ b/source/blender/geometry/GEO_mesh_to_volume.hh @@ -2,6 +2,7 @@ * * SPDX-License-Identifier: GPL-2.0-or-later */ +#include "BLI_bounds.hh" #include "BLI_function_ref.hh" #include "BLI_math_matrix_types.hh" #include "BLI_string_ref.hh" @@ -37,7 +38,7 @@ struct MeshToVolumeResolution { * used for deciding the voxel size in "Amount" mode. */ float volume_compute_voxel_size(const Depsgraph *depsgraph, - FunctionRef bounds_fn, + FunctionRef()> bounds_fn, MeshToVolumeResolution resolution, float exterior_band_width, const float4x4 &transform); diff --git a/source/blender/geometry/intern/mesh_to_volume.cc b/source/blender/geometry/intern/mesh_to_volume.cc index a125e6e4393..9a4ff178e1f 100644 --- a/source/blender/geometry/intern/mesh_to_volume.cc +++ b/source/blender/geometry/intern/mesh_to_volume.cc @@ -72,7 +72,7 @@ void OpenVDBMeshAdapter::getIndexSpacePoint(size_t polygon_index, } float volume_compute_voxel_size(const Depsgraph *depsgraph, - FunctionRef bounds_fn, + const FunctionRef()> bounds_fn, const MeshToVolumeResolution res, const float exterior_band_width, const float4x4 &transform) @@ -89,14 +89,12 @@ float volume_compute_voxel_size(const Depsgraph *depsgraph, return 0; } - float3 bb_min; - float3 bb_max; - bounds_fn(bb_min, bb_max); + const Bounds bounds = bounds_fn(); /* Compute the diagonal of the bounding box. This is used because * it will always be bigger than the widest side of the mesh. */ - const float diagonal = math::distance(math::transform_point(transform, bb_max), - math::transform_point(transform, bb_min)); + const float diagonal = math::distance(math::transform_point(transform, bounds.min), + math::transform_point(transform, bounds.max)); /* To get the approximate size per voxel, first subtract the exterior band from the requested * voxel amount, then divide the diagonal with this value if it's bigger than 1. */ diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc index ef01b957c17..03d05c808f2 100644 --- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc +++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc @@ -149,14 +149,12 @@ static Volume *mesh_to_volume(ModifierData *md, } } - auto bounds_fn = [&](float3 &r_min, float3 &r_max) { - const Bounds bounds = *mesh->bounds_min_max(); - r_min = bounds.min; - r_max = bounds.max; - }; - const float voxel_size = geometry::volume_compute_voxel_size( - ctx->depsgraph, bounds_fn, resolution, 0.0f, mesh_to_own_object_space_transform); + ctx->depsgraph, + [&]() { return *mesh->bounds_min_max(); }, + resolution, + 0.0f, + mesh_to_own_object_space_transform); /* Create a new volume. */ Volume *volume; diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_sdf_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_sdf_volume.cc index a5be0dbcfb5..e0ebc35b90c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_sdf_volume.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_sdf_volume.cc @@ -109,12 +109,11 @@ static Volume *create_volume_from_mesh(const Mesh &mesh, GeoNodeExecParams ¶ const float4x4 mesh_to_volume_space_transform = float4x4::identity(); - auto bounds_fn = [&](float3 &r_min, float3 &r_max) { + auto bounds_fn = [&]() { float3 min{std::numeric_limits::max()}; float3 max{-std::numeric_limits::max()}; BKE_mesh_wrapper_minmax(&mesh, min, max); - r_min = min; - r_max = max; + return Bounds{min, max}; }; const float voxel_size = geometry::volume_compute_voxel_size( diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc index 47f7e75ebf6..248c2357a78 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc @@ -104,12 +104,11 @@ static Volume *create_volume_from_mesh(const Mesh &mesh, GeoNodeExecParams ¶ const float4x4 mesh_to_volume_space_transform = float4x4::identity(); - auto bounds_fn = [&](float3 &r_min, float3 &r_max) { + auto bounds_fn = [&]() { float3 min{std::numeric_limits::max()}; float3 max{-std::numeric_limits::max()}; BKE_mesh_wrapper_minmax(&mesh, min, max); - r_min = min; - r_max = max; + return Bounds{min, max}; }; const float voxel_size = geometry::volume_compute_voxel_size(