[Bf-blender-cvs] [0e9e472bbe7] mesh-to-volume-modifier: expose interior/exterior bandwidth properties

Jacques Lucke noreply at git.blender.org
Thu Sep 24 14:03:55 CEST 2020


Commit: 0e9e472bbe7f9adf729027903f157d43efc28630
Author: Jacques Lucke
Date:   Thu Sep 24 14:01:50 2020 +0200
Branches: mesh-to-volume-modifier
https://developer.blender.org/rB0e9e472bbe7f9adf729027903f157d43efc28630

expose interior/exterior bandwidth properties

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

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

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

diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 2de0bfee966..e8c48ef5972 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -2214,6 +2214,8 @@ typedef struct MeshToVolumeModifierData {
   ModifierData modifier;
   struct Object *object;
   float voxel_size;
+  float interior_bandwidth;
+  float exterior_bandwidth;
   char _pad[4];
 } MeshToVolumeModifierData;
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index a552d90cfd3..ebaab7d5c0d 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -7121,6 +7121,16 @@ static void rna_def_modifier_mesh_to_volume(BlenderRNA *brna)
   RNA_def_property_range(prop, 0.1, FLT_MAX);
   RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+  prop = RNA_def_property(srna, "interior_bandwidth", PROP_FLOAT, PROP_NONE);
+  RNA_def_property_ui_text(prop, "Interior Bandwidth", "Width of the volume inside of the mesh");
+  RNA_def_property_range(prop, 0.0, FLT_MAX);
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+  prop = RNA_def_property(srna, "exterior_bandwidth", PROP_FLOAT, PROP_NONE);
+  RNA_def_property_ui_text(prop, "Exterior Bandwidth", "Width of the volume outside of the mesh");
+  RNA_def_property_range(prop, 0.0, FLT_MAX);
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
   RNA_define_lib_overridable(false);
 }
 
diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
index 30336472105..e41d1f9a291 100644
--- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
+++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
@@ -104,6 +104,8 @@ static void initData(ModifierData *md)
   MeshToVolumeModifierData *mvmd = reinterpret_cast<MeshToVolumeModifierData *>(md);
   mvmd->object = NULL;
   mvmd->voxel_size = 0.1f;
+  mvmd->interior_bandwidth = 1.0f;
+  mvmd->exterior_bandwidth = 1.0f;
 }
 
 static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
@@ -137,6 +139,8 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
 
   uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE);
   uiItemR(layout, ptr, "voxel_size", 0, NULL, ICON_NONE);
+  uiItemR(layout, ptr, "interior_bandwidth", 0, NULL, ICON_NONE);
+  uiItemR(layout, ptr, "exterior_bandwidth", 0, NULL, ICON_NONE);
 
   modifier_panel_end(layout, ptr);
 }
@@ -163,6 +167,8 @@ static Volume *modifyVolume(ModifierData *md, const ModifierEvalContext *ctx, Vo
   Object *object_to_convert = mvmd->object;
   Mesh *mesh = static_cast<Mesh *>(object_to_convert->data);
   const float voxel_size = mvmd->voxel_size;
+  const float exterior_bandwidth = MAX2(0.001f, mvmd->exterior_bandwidth / voxel_size);
+  const float interior_bandwidth = MAX2(0.001f, mvmd->interior_bandwidth / voxel_size);
   UNUSED_VARS(voxel_size);
 
   float4x4 transform;
@@ -173,7 +179,7 @@ static Volume *modifyVolume(ModifierData *md, const ModifierEvalContext *ctx, Vo
   OpenVDBMeshAdapter mesh_adapter{*mesh, transform};
 
   openvdb::FloatGrid::Ptr new_grid = openvdb::tools::meshToVolume<openvdb::FloatGrid>(
-      mesh_adapter, {}, 1.0f, 1.0f);
+      mesh_adapter, {}, exterior_bandwidth, interior_bandwidth);
 
   Volume *volume = BKE_volume_new_for_eval(input_volume);
   VolumeGrid *c_density_grid = BKE_volume_grid_add(volume, "density", VOLUME_GRID_FLOAT);
@@ -182,6 +188,10 @@ static Volume *modifyVolume(ModifierData *md, const ModifierEvalContext *ctx, Vo
   density_grid->merge(*new_grid);
   density_grid->transform().postScale(mvmd->voxel_size);
 
+  openvdb::tools::foreach (
+      density_grid->beginValueOn(),
+      [](const openvdb::FloatGrid::ValueOnIter &iter) { iter.setValue(1.0f); });
+
   return volume;
 
 #else



More information about the Bf-blender-cvs mailing list