Cleanup: Return Bounds type directly in mesh to volume code
This commit is contained in:
@@ -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<void(float3 &r_min, float3 &r_max)> bounds_fn,
|
||||
FunctionRef<Bounds<float3>()> bounds_fn,
|
||||
MeshToVolumeResolution resolution,
|
||||
float exterior_band_width,
|
||||
const float4x4 &transform);
|
||||
|
||||
@@ -72,7 +72,7 @@ void OpenVDBMeshAdapter::getIndexSpacePoint(size_t polygon_index,
|
||||
}
|
||||
|
||||
float volume_compute_voxel_size(const Depsgraph *depsgraph,
|
||||
FunctionRef<void(float3 &r_min, float3 &r_max)> bounds_fn,
|
||||
const FunctionRef<Bounds<float3>()> 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<float3> 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. */
|
||||
|
||||
@@ -149,14 +149,12 @@ static Volume *mesh_to_volume(ModifierData *md,
|
||||
}
|
||||
}
|
||||
|
||||
auto bounds_fn = [&](float3 &r_min, float3 &r_max) {
|
||||
const Bounds<float3> 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;
|
||||
|
||||
@@ -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<float>::max()};
|
||||
float3 max{-std::numeric_limits<float>::max()};
|
||||
BKE_mesh_wrapper_minmax(&mesh, min, max);
|
||||
r_min = min;
|
||||
r_max = max;
|
||||
return Bounds<float3>{min, max};
|
||||
};
|
||||
|
||||
const float voxel_size = geometry::volume_compute_voxel_size(
|
||||
|
||||
@@ -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<float>::max()};
|
||||
float3 max{-std::numeric_limits<float>::max()};
|
||||
BKE_mesh_wrapper_minmax(&mesh, min, max);
|
||||
r_min = min;
|
||||
r_max = max;
|
||||
return Bounds<float3>{min, max};
|
||||
};
|
||||
|
||||
const float voxel_size = geometry::volume_compute_voxel_size(
|
||||
|
||||
Reference in New Issue
Block a user