[Bf-blender-cvs] [5845c06a63a] master: Volumes: new Mesh to Volume modifier
Jacques Lucke
noreply at git.blender.org
Tue Sep 29 16:05:43 CEST 2020
Commit: 5845c06a63a6b96f038f5a46d538b0f9737102e9
Author: Jacques Lucke
Date: Tue Sep 29 16:02:40 2020 +0200
Branches: master
https://developer.blender.org/rB5845c06a63a6b96f038f5a46d538b0f9737102e9
Volumes: new Mesh to Volume modifier
This modifier can only be added to Volume objects. It takes a mesh
as input and generates a "density" grid near the surface or in
the enclosed volume.
Ref T73201.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D9032
===================================================================
M source/blender/blenkernel/BKE_volume.h
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/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h
index b3437454f31..4481c1b4332 100644
--- a/source/blender/blenkernel/BKE_volume.h
+++ b/source/blender/blenkernel/BKE_volume.h
@@ -157,4 +157,16 @@ openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_read(const struct Volume
openvdb::GridBase::Ptr BKE_volume_grid_openvdb_for_write(const struct Volume *volume,
struct VolumeGrid *grid,
const bool clear);
+
+template<typename GridType>
+typename GridType::Ptr BKE_volume_grid_openvdb_for_write(const struct Volume *volume,
+ struct VolumeGrid *grid,
+ const bool clear)
+{
+ openvdb::GridBase::Ptr openvdb_grid = BKE_volume_grid_openvdb_for_write(volume, grid, clear);
+ BLI_assert(openvdb_grid->isType<GridType>());
+ typename GridType::Ptr typed_openvdb_grid = openvdb::gridPtrCast<GridType>(openvdb_grid);
+ return typed_openvdb_grid;
+}
+
#endif
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index c0716388f28..7218e75a404 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;
@@ -2208,6 +2209,39 @@ typedef struct SimulationModifierData {
char *data_path;
} SimulationModifierData;
+typedef struct MeshToVolumeModifierData {
+ ModifierData modifier;
+
+ /** This is the object that is supposed to be converted to a volume. */
+ struct Object *object;
+
+ /** MeshToVolumeModifierResolutionMode */
+ int resolution_mode;
+ /** Size of a voxel in object space. */
+ float voxel_size;
+ /** The desired amount of voxels along one axis. The actual amount of voxels might be slightly
+ * different. */
+ int voxel_amount;
+
+ /** If true, every cell in the enclosed volume gets a density. Otherwise, the interior_band_width
+ * is used. */
+ char fill_volume;
+ char _pad1[3];
+
+ /** Band widths are in object space. */
+ float interior_band_width;
+ float exterior_band_width;
+
+ float density;
+ char _pad2[4];
+} MeshToVolumeModifierData;
+
+/* MeshToVolumeModifierData->resolution_mode */
+typedef enum MeshToVolumeModifierResolutionMode {
+ MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_AMOUNT = 0,
+ MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE = 1,
+} MeshToVolumeModifierResolutionMode;
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 10c122171e4..cfd87f14d48 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 0e83ee150d6..b433c938bd6 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",
@@ -6973,6 +6978,77 @@ static void rna_def_modifier_simulation(BlenderRNA *brna)
}
# endif
+static void rna_def_modifier_mesh_to_volume(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ static EnumPropertyItem resolution_mode_items[] = {
+ {MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_AMOUNT,
+ "VOXEL_AMOUNT",
+ 0,
+ "Voxel Amount",
+ "Desired number of voxels along one axis"},
+ {MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE,
+ "VOXEL_SIZE",
+ 0,
+ "Voxel Size",
+ "Desired voxel side length"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ 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, "resolution_mode", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, resolution_mode_items);
+ RNA_def_property_ui_text(
+ prop, "Resolution Mode", "Mode for how the desired voxel size is specified");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ 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_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "voxel_amount", PROP_INT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Voxel Amount", "Approximate number of voxels along one axis");
+ RNA_def_property_range(prop, 0, INT_MAX);
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "fill_volume", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_ui_text(
+ prop, "Fill Volume", "Initialize the density grid in every cell inside the enclosed volume");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "interior_band_width", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Interior Band Width", "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_band_width", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Exterior Band Width", "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");
+
+ prop = RNA_def_property(srna, "density", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Density", "Density of the new volume");
+ RNA_def_property_range(prop, 0.0, FLT_MAX);
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ RNA_define_lib_overridable(false);
+}
+
void RNA_def_modifier(BlenderRNA *brna)
{
StructRNA *srna;
@@ -7104,6 +7180,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 8425d9bf569..3bc8a23184b 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
@@ -177,6 +178,20 @@ if(WITH_GMP)
add_definitions(-DWITH_GMP)
endif()
+if(WITH_OPENVDB)
+ list(APPEND INC
+ ../../../intern/openvdb
+ )
+ list(APPEND INC_SYS
+ ${OPENVDB_INCLUDE_DIRS}
+ )
+ list(APPEND LIB
+ bf_intern_openvdb
+ ${OPENVDB_LIBRARIES}
+ )
+ add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS})
+endif()
+
if(WITH_EXPERIMENTAL_FEATURES)
add_definitions(-DWITH_PARTICLE_NODES)
add_definitions(-DWITH_HAIR_NODES)
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..4ec8e8fc44e
--- /dev/null
+++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
@@ -0,0 +1,306 @@
+/*
+ * 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 <vector>
+
+#include "BKE_lib_query.h"
+#include "BKE_mesh_runtime.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_volume.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_screen_types.h"
+#inc
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list