[Bf-blender-cvs] [701fc52cc6d] master: Volumes: lower minimal voxel size in Mesh to Volume modifier

Jacques Lucke noreply at git.blender.org
Fri Oct 9 12:55:56 CEST 2020


Commit: 701fc52cc6dcbe4f3fd3af7070f1e985c280a7cb
Author: Jacques Lucke
Date:   Fri Oct 9 12:55:13 2020 +0200
Branches: master
https://developer.blender.org/rB701fc52cc6dcbe4f3fd3af7070f1e985c280a7cb

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.

===================================================================

M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_mesh_to_volume.cc

===================================================================

diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 766497d53c1..5a03c2c236a 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -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);
diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
index 6fdc78c6ce9..ba6c4207497 100644
--- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
+++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
@@ -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);



More information about the Bf-blender-cvs mailing list