Volumes: lower minimal voxel size in Mesh to Volume modifier

The 0.1 limit was too large. The issue with making it smaller is that
one can easily crash blender by making it to small. To counteract this,
the step has been reduced as well.

A voxel size/amount of 0 disables the modifier.
This commit is contained in:
Jacques Lucke 2020-10-09 12:55:13 +02:00
parent 2f339eb745
commit 701fc52cc6
2 changed files with 10 additions and 4 deletions

View File

@ -7030,7 +7030,8 @@ static void rna_def_modifier_mesh_to_volume(BlenderRNA *brna)
prop = RNA_def_property(srna, "voxel_size", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(
prop, "Voxel Size", "Smaller values result in a higher resolution output");
RNA_def_property_range(prop, 0.1, FLT_MAX);
RNA_def_property_range(prop, 0.0, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0, FLT_MAX, 0.01, 4);
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "voxel_amount", PROP_INT, PROP_NONE);

View File

@ -181,9 +181,11 @@ static float compute_voxel_size(const MeshToVolumeModifierData *mvmd,
{
using namespace blender;
if (mvmd->resolution_mode == MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE) {
return MAX2(0.0001, mvmd->voxel_size);
return mvmd->voxel_size;
}
if (mvmd->voxel_amount <= 0) {
return 0;
}
/* Compute the voxel size based on the desired number of voxels and the approximated bounding box
* of the volume. */
const BoundBox *bb = BKE_object_boundbox_get(mvmd->object);
@ -194,7 +196,7 @@ static float compute_voxel_size(const MeshToVolumeModifierData *mvmd,
(transform.ref_3x3() * y_axis).length(),
(transform.ref_3x3() * z_axis).length()});
const float approximate_volume_side_length = max_dimension + mvmd->exterior_band_width * 2.0f;
const float voxel_size = approximate_volume_side_length / MAX2(1, mvmd->voxel_amount);
const float voxel_size = approximate_volume_side_length / mvmd->voxel_amount;
return voxel_size;
}
@ -218,6 +220,9 @@ static Volume *modifyVolume(ModifierData *md, const ModifierEvalContext *ctx, Vo
const float4x4 mesh_to_own_object_space_transform = float4x4(ctx->object->imat) *
float4x4(object_to_convert->obmat);
const float voxel_size = compute_voxel_size(mvmd, mesh_to_own_object_space_transform);
if (voxel_size == 0.0f) {
return input_volume;
}
float4x4 mesh_to_index_space_transform;
scale_m4_fl(mesh_to_index_space_transform.values, 1.0f / voxel_size);