[Bf-blender-cvs] [c5fca660bc6] mesh-to-volume-modifier: Volume: add boilerplate code for Mesh To Volume modifier

Jacques Lucke noreply at git.blender.org
Wed Sep 23 15:36:38 CEST 2020


Commit: c5fca660bc62749118962d2b44b7e546418b8231
Author: Jacques Lucke
Date:   Wed Sep 23 15:36:14 2020 +0200
Branches: mesh-to-volume-modifier
https://developer.blender.org/rBc5fca660bc62749118962d2b44b7e546418b8231

Volume: add boilerplate code for Mesh To Volume modifier

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

M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/MOD_modifiertypes.h
A	source/blender/modifiers/intern/MOD_mesh_to_volume.cc
M	source/blender/modifiers/intern/MOD_util.c

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

diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 9e805e2052f..2d3f550058f 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -2287,6 +2287,9 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te)
             case eModifierType_Simulation:
               data.icon = ICON_PHYSICS; /* TODO: Use correct icon. */
               break;
+            case eModifierType_MeshToVolume:
+              data.icon = ICON_VOLUME_DATA; /* TODO: Use correct icon. */
+              break;
               /* Default */
             case eModifierType_None:
             case eModifierType_ShapeKey:
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 9a5b5b8c2ca..2de0bfee966 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -95,6 +95,7 @@ typedef enum ModifierType {
   eModifierType_Weld = 55,
   eModifierType_Fluid = 56,
   eModifierType_Simulation = 57,
+  eModifierType_MeshToVolume = 58,
   NUM_MODIFIER_TYPES,
 } ModifierType;
 
@@ -2209,6 +2210,13 @@ typedef struct SimulationModifierData {
   char *data_path;
 } SimulationModifierData;
 
+typedef struct MeshToVolumeModifierData {
+  ModifierData modifier;
+  struct Object *object;
+  float voxel_size;
+  char _pad[4];
+} MeshToVolumeModifierData;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 38438f66a0f..605cfe7caf8 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -389,6 +389,7 @@ extern StructRNA RNA_MaterialSlot;
 extern StructRNA RNA_Menu;
 extern StructRNA RNA_Mesh;
 extern StructRNA RNA_MeshCacheModifier;
+extern StructRNA RNA_MeshToVolumeModifier;
 extern StructRNA RNA_MeshColor;
 extern StructRNA RNA_MeshDeformModifier;
 extern StructRNA RNA_MeshEdge;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 2463f3c409f..69d9801ea7d 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -193,6 +193,11 @@ const EnumPropertyItem rna_enum_object_modifier_type_items[] = {
      ICON_MOD_WIREFRAME,
      "Wireframe",
      "Convert faces into thickened edges"},
+    {eModifierType_MeshToVolume,
+     "MESH_TO_VOLUME",
+     ICON_VOLUME_DATA,
+     "Mesh to Volume",
+     ""}, /* TODO: Use correct icon. */
     {0, "", 0, N_("Deform"), ""},
     {eModifierType_Armature,
      "ARMATURE",
@@ -726,6 +731,8 @@ static StructRNA *rna_Modifier_refine(struct PointerRNA *ptr)
 #  ifdef WITH_PARTICLE_NODES
       return &RNA_SimulationModifier;
 #  endif
+    case eModifierType_MeshToVolume:
+      return &RNA_MeshToVolumeModifier;
     /* Default */
     case eModifierType_Fluidsim: /* deprecated */
     case eModifierType_None:
@@ -7091,6 +7098,31 @@ static void rna_def_modifier_simulation(BlenderRNA *brna)
 }
 #  endif
 
+static void rna_def_modifier_mesh_to_volume(BlenderRNA *brna)
+{
+  StructRNA *srna;
+  PropertyRNA *prop;
+
+  srna = RNA_def_struct(brna, "MeshToVolumeModifier", "Modifier");
+  RNA_def_struct_ui_text(srna, "Mesh to Volume Modifier", "");
+  RNA_def_struct_sdna(srna, "MeshToVolumeModifierData");
+  RNA_def_struct_ui_icon(srna, ICON_VOLUME_DATA); /* TODO: Use correct icon. */
+
+  RNA_define_lib_overridable(true);
+
+  prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
+  RNA_def_property_ui_text(prop, "Object", "Object");
+  RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
+  RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+
+  prop = RNA_def_property(srna, "voxel_size", PROP_FLOAT, PROP_NONE);
+  RNA_def_property_ui_text(
+      prop, "Voxel Size", "The smaller this number the higher the resolution of the output");
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+  RNA_define_lib_overridable(false);
+}
+
 void RNA_def_modifier(BlenderRNA *brna)
 {
   StructRNA *srna;
@@ -7222,6 +7254,7 @@ void RNA_def_modifier(BlenderRNA *brna)
 #  ifdef WITH_PARTICLE_NODES
   rna_def_modifier_simulation(brna);
 #  endif
+  rna_def_modifier_mesh_to_volume(brna);
 }
 
 #endif
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index 7f65e72bf3e..fddb26685c7 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -67,6 +67,7 @@ set(SRC
   intern/MOD_laplaciansmooth.c
   intern/MOD_lattice.c
   intern/MOD_mask.cc
+  intern/MOD_mesh_to_volume.cc
   intern/MOD_meshcache.c
   intern/MOD_meshcache_mdd.c
   intern/MOD_meshcache_pc2.c
diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h
index b011abf336d..e12f91ff99b 100644
--- a/source/blender/modifiers/MOD_modifiertypes.h
+++ b/source/blender/modifiers/MOD_modifiertypes.h
@@ -86,6 +86,7 @@ extern ModifierTypeInfo modifierType_MeshSequenceCache;
 extern ModifierTypeInfo modifierType_SurfaceDeform;
 extern ModifierTypeInfo modifierType_WeightedNormal;
 extern ModifierTypeInfo modifierType_Simulation;
+extern ModifierTypeInfo modifierType_MeshToVolume;
 
 /* MOD_util.c */
 void modifier_type_init(ModifierTypeInfo *types[]);
diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
new file mode 100644
index 00000000000..d5f2558d942
--- /dev/null
+++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
@@ -0,0 +1,129 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup modifiers
+ */
+
+#include "BKE_lib_query.h"
+#include "BKE_modifier.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_volume_types.h"
+
+#include "DEG_depsgraph_build.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "BLO_read_write.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "MOD_modifiertypes.h"
+#include "MOD_ui_common.h"
+
+static void initData(ModifierData *md)
+{
+  MeshToVolumeModifierData *mvmd = reinterpret_cast<MeshToVolumeModifierData *>(md);
+  mvmd->object = NULL;
+  mvmd->voxel_size = 0.1f;
+}
+
+static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
+{
+  MeshToVolumeModifierData *mvmd = reinterpret_cast<MeshToVolumeModifierData *>(md);
+  if (mvmd->object) {
+    DEG_add_object_relation(
+        ctx->node, mvmd->object, DEG_OB_COMP_GEOMETRY, "Object that is converted to a volume");
+    DEG_add_object_relation(
+        ctx->node, mvmd->object, DEG_OB_COMP_TRANSFORM, "Object that is converted to a volume");
+  }
+}
+
+static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
+{
+  MeshToVolumeModifierData *mvmd = reinterpret_cast<MeshToVolumeModifierData *>(md);
+
+  walk(userData, ob, &mvmd->object, IDWALK_CB_NOP);
+}
+
+static void panel_draw(const bContext *UNUSED(C), Panel *panel)
+{
+  uiLayout *layout = panel->layout;
+
+  PointerRNA ob_ptr;
+  PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
+
+  uiLayoutSetPropSep(layout, true);
+  uiLayoutSetPropDecorate(layout, false);
+
+  uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE);
+  uiItemR(layout, ptr, "voxel_size", 0, NULL, ICON_NONE);
+
+  modifier_panel_end(layout, ptr);
+}
+
+static void panelRegister(ARegionType *region_type)
+{
+  modifier_panel_register(region_type, eModifierType_MeshToVolume, panel_draw);
+}
+
+static Volume *modifyVolume(ModifierData *md,
+                            const ModifierEvalContext *UNUSED(ctx),
+                            Volume *input_volume)
+{
+  MeshToVolumeModifierData *mvmd = reinterpret_cast<MeshToVolumeModifierData *>(md);
+  printf("%f\n", mvmd->voxel_size);
+
+  return input_volume;
+}
+
+ModifierTypeInfo modifierType_MeshToVolume = {
+    /* name */ "Mesh to Volume",
+    /* structName */ "MeshToVolumeModifierData",
+    /* structSize */ sizeof(MeshToVolumeModifierData),
+    /* type */ eModifierTypeType_Constructive,
+    /* flags */ static_cast<ModifierTypeFlag>(0),
+    /* copyData */ BKE_modifier_copydata_generic,
+
+    /* deformVerts */ NULL,
+    /* deformMatrices */ NULL,
+    /* deformVertsEM */ NULL,
+    /* deformMatricesEM */ NULL,
+    /* modifyMesh */ NULL,
+    /* modifyHair */ NULL,
+    /* modifyPointCloud */ NULL,
+    /* modifyVolume */ modifyVolume,
+
+    /* initData */ NULL,
+    /* requiredDataMask */ NULL,
+    /* freeData */ NULL,
+    /* isDisabled */ NULL,
+    /* updateDepsgraph */ updateDepsgraph,
+    /* dependsOnTime */ NULL,
+    /* dependsOnNormals */ NULL,
+    /* foreachObjectLink */ foreachObjectLink,
+    /* foreachIDLink */ NULL,
+    /* foreachTexLink */ NULL,
+    /* freeRuntimeData */ NULL,
+    /* panelRegister */ panelRegister,
+    /* blendWrite */ NULL,
+    /* blendRead */ NULL,
+};
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index cc844e53603..75436435e97 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -343,5 +343,6 @@ void modifier_type_init(ModifierTypeInfo *types[])
   INIT_TYPE(SurfaceDeform);
   INIT_TYPE(WeightedNormal);
   INIT_TYPE(Simulation);
+  INIT_TYPE(MeshToVolume);
 #undef INIT_TYPE
 }



More information about the Bf-blender-cvs mailing list