[Bf-blender-cvs] [ade63efcdf4] sculpt-mode-features: initial implementation of the openvdb remesher inside the remesh modifier

Martin Felke noreply at git.blender.org
Sat Apr 6 19:18:58 CEST 2019


Commit: ade63efcdf46022b919f280f6f8ed50c63cd7763
Author: Martin Felke
Date:   Sat Apr 6 19:17:23 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rBade63efcdf46022b919f280f6f8ed50c63cd7763

initial implementation of the openvdb remesher inside the remesh modifier

this merges my patch now officially to the sculpt-mode-features branch :)

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

M	intern/openvdb/intern/openvdb_level_set.cc
M	intern/openvdb/intern/openvdb_level_set.h
M	intern/openvdb/openvdb_capi.h
M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/editors/object/object_edit.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/intern/MOD_remesh.c

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

diff --git a/intern/openvdb/intern/openvdb_level_set.cc b/intern/openvdb/intern/openvdb_level_set.cc
index 068148f4e04..dad164e6f85 100644
--- a/intern/openvdb/intern/openvdb_level_set.cc
+++ b/intern/openvdb/intern/openvdb_level_set.cc
@@ -30,6 +30,7 @@ void OpenVDB_level_set_remesh(struct OpenVDBRemeshData *rmd){
 	std::vector<openvdb::Vec4I > quads;
 	std::vector<openvdb::Vec3s> out_points;
 	std::vector<openvdb::Vec4I > out_quads;
+	std::vector<openvdb::Vec3I > out_tris;
 	const openvdb::math::Transform xform;
 
 	for(int i = 0; i < rmd->totverts; i++) {
@@ -45,10 +46,41 @@ void OpenVDB_level_set_remesh(struct OpenVDBRemeshData *rmd){
 	openvdb::initialize();
 	openvdb::math::Transform::Ptr transform = openvdb::math::Transform::createLinearTransform((double)rmd->voxel_size);
 	const openvdb::FloatGrid::Ptr grid = openvdb::tools::meshToLevelSet<openvdb::FloatGrid>(*transform, points, triangles, quads, 1);
-	openvdb::tools::volumeToMesh<openvdb::FloatGrid>(*grid, out_points, out_quads, (double)rmd->isovalue);
+
+	if (rmd->filter_type != FILTER_NONE) {
+		openvdb::tools::LevelSetFilter<openvdb::FloatGrid> filter(*grid);
+		filter.setSpatialScheme((openvdb::math::BiasedGradientScheme)rmd->filter_bias);
+
+		switch (rmd->filter_type) {
+			case FILTER_GAUSSIAN:
+				filter.gaussian(rmd->filter_width);
+			break;
+			case FILTER_MEDIAN:
+				filter.median(rmd->filter_width);
+			break;
+			case FILTER_MEAN:
+				filter.mean(rmd->filter_width);
+			break;
+			case FILTER_MEAN_CURVATURE:
+				filter.meanCurvature();
+			break;
+			case FILTER_LAPLACIAN:
+				filter.laplacian();
+			break;
+		}
+	}
+
+	openvdb::tools::volumeToMesh<openvdb::FloatGrid>(*grid, out_points, out_tris, out_quads, (double)rmd->isovalue,
+	                                                 (double)rmd->adaptivity, (bool)rmd->relax_disoriented_triangles);
 	rmd->out_verts = (float *)MEM_malloc_arrayN(out_points.size(), 3 * sizeof (float), "openvdb remesher out verts");
 	rmd->out_faces = (unsigned int*)MEM_malloc_arrayN(out_quads.size(), 4 * sizeof (unsigned int), "openvdb remesh out quads");
+	rmd->out_tris = NULL;
+	if (out_tris.size() > 0) {
+		rmd->out_tris = (unsigned int*)MEM_malloc_arrayN(out_tris.size(), 3 * sizeof (unsigned int), "openvdb remesh out tris");
+	}
+
 	rmd->out_totverts = out_points.size();
+	rmd->out_tottris = out_tris.size();
 	rmd->out_totfaces = out_quads.size();
 
 	for(int i = 0; i < out_points.size(); i++) {
@@ -63,4 +95,10 @@ void OpenVDB_level_set_remesh(struct OpenVDBRemeshData *rmd){
 		rmd->out_faces[i * 4 + 2] = out_quads[i].z();
 		rmd->out_faces[i * 4 + 3] = out_quads[i].w();
 	}
+
+	for(int i = 0; i < rmd->out_tottris; i++) {
+		rmd->out_tris[i * 3] = out_tris[i].x();
+		rmd->out_tris[i * 3 + 1] = out_tris[i].y();
+		rmd->out_tris[i * 3 + 2] = out_tris[i].z();
+	}
 }
diff --git a/intern/openvdb/intern/openvdb_level_set.h b/intern/openvdb/intern/openvdb_level_set.h
index bd1c57a4e86..73dc5007f04 100644
--- a/intern/openvdb/intern/openvdb_level_set.h
+++ b/intern/openvdb/intern/openvdb_level_set.h
@@ -21,8 +21,10 @@
 #define __OPENVDB_LEVEL_SET_H__
 
 #include <openvdb/openvdb.h>
+#include <openvdb/math/FiniteDifference.h>
 #include <openvdb/tools/MeshToVolume.h>
 #include <openvdb/tools/VolumeToMesh.h>
+#include <openvdb/tools/LevelSetFilter.h>
 
 void OpenVDB_level_set_remesh(struct OpenVDBRemeshData *rmd);
 
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index 1af81f70e1b..84ef86946a8 100644
--- a/intern/openvdb/openvdb_capi.h
+++ b/intern/openvdb/openvdb_capi.h
@@ -24,6 +24,26 @@
 extern "C" {
 #endif
 
+/*filter_type */
+enum {
+	FILTER_NONE = 0,
+	FILTER_GAUSSIAN,
+	FILTER_MEAN,
+	FILTER_MEDIAN,
+	FILTER_CURVATURE,
+	FILTER_MEAN_CURVATURE,
+	FILTER_LAPLACIAN
+};
+
+/*filter bias, aligned to openvdb */
+enum {
+	FIRST_BIAS = 0,
+	SECOND_BIAS,
+	THIRD_BIAS,
+	WENO5_BIAS,
+	HJWENO5_BIAS,
+};
+
 struct OpenVDBReader;
 struct OpenVDBWriter;
 struct OpenVDBFloatGrid;
@@ -37,11 +57,18 @@ struct OpenVDBRemeshData {
 
 	float *out_verts;
 	unsigned int *out_faces;
+	unsigned int *out_tris;
 	int out_totverts;
 	int out_totfaces;
+	int out_tottris;
+	int filter_type;
+	int filter_bias;
+	int filter_width; /*parameter for gaussian, median, mean*/
 
 	float voxel_size;
 	float isovalue;
+	float adaptivity;
+	int relax_disoriented_triangles;
 };
 
 
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 59bf820560e..408782ec781 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1195,18 +1195,34 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
         layout.prop(md, "mode")
 
-        row = layout.row()
-        row.prop(md, "octree_depth")
-        row.prop(md, "scale")
+        if md.mode != 'VOXEL':
+            row = layout.row()
+            row.prop(md, "octree_depth")
+            row.prop(md, "scale")
 
         if md.mode == 'SHARP':
             layout.prop(md, "sharpness")
 
-        layout.prop(md, "use_smooth_shade")
-        layout.prop(md, "use_remove_disconnected")
-        row = layout.row()
-        row.active = md.use_remove_disconnected
-        row.prop(md, "threshold")
+        if md.mode == 'VOXEL':
+            col = layout.column(align=True)
+            col.prop(md, "voxel_size")
+            col.prop(md, "isovalue")
+            col.prop(md, "adaptivity")
+            layout.prop(md, "filter_type")
+            if md.filter_type != "NONE":
+                layout.prop(md, "filter_bias")
+                if md.filter_type in {"GAUSSIAN", "MEDIAN", "MEAN"}:
+                    layout.prop(md, "filter_width")
+
+            layout.prop(md, "smooth_normals")
+            layout.prop(md, "relax_triangles")
+            layout.prop(md, "reproject_vertex_paint")
+        else:
+            layout.prop(md, "use_smooth_shade")
+            layout.prop(md, "use_remove_disconnected")
+            row = layout.row()
+            row.active = md.use_remove_disconnected
+            row.prop(md, "threshold")
 
     @staticmethod
     def vertex_weight_mask(layout, ob, md):
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index dbe2ae45130..3b172664232 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1751,7 +1751,6 @@ void OBJECT_OT_link_to_collection(wmOperatorType *ot)
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
-
 static int remesh_exec(bContext *C, wmOperator *op)
 {
 	bool linked_data = false;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 126ef912b15..5ebb6c5403a 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1489,6 +1489,9 @@ enum {
 typedef enum eRemeshModifierFlags {
 	MOD_REMESH_FLOOD_FILL     = (1 << 0),
 	MOD_REMESH_SMOOTH_SHADING = (1 << 1),
+	MOD_REMESH_SMOOTH_NORMALS = (1 << 2),
+	MOD_REMESH_RELAX_TRIANGLES = (1 << 3),
+	MOD_REMESH_REPROJECT_VPAINT = (1 << 4),
 } RemeshModifierFlags;
 
 typedef enum eRemeshModifierMode {
@@ -1498,8 +1501,29 @@ typedef enum eRemeshModifierMode {
 	MOD_REMESH_MASS_POINT     = 1,
 	/* keeps sharp edges */
 	MOD_REMESH_SHARP_FEATURES = 2,
+	/* OpenVDB voxel remesh */
+	MOD_REMESH_VOXEL          = 3,
 } eRemeshModifierMode;
 
+
+typedef enum eVoxelFilterType {
+	VOXEL_FILTER_NONE = 0,
+	VOXEL_FILTER_GAUSSIAN = 1,
+	VOXEL_FILTER_MEDIAN = 2,
+	VOXEL_FILTER_MEAN = 3,
+	VOXEL_FILTER_MEAN_CURVATURE = 4,
+	VOXEL_FILTER_LAPLACIAN = 5,
+} eVoxelFilterType;
+
+/*filter bias, aligned to openvdb */
+typedef enum eVoxelFilterBias{
+	VOXEL_BIAS_FIRST = 0,
+	VOXEL_BIAS_SECOND,
+	VOXEL_BIAS_THIRD,
+	VOXEL_BIAS_WENO5,
+	VOXEL_BIAS_HJWENO5,
+} eVoxelFilterBias;
+
 typedef struct RemeshModifierData {
 	ModifierData modifier;
 
@@ -1511,6 +1535,14 @@ typedef struct RemeshModifierData {
 
 	float hermite_num;
 
+	/* for voxelremesher */
+	float voxel_size;
+	float isovalue;
+	float adaptivity;
+	int filter_type;
+	int filter_bias;
+	int filter_width;
+
 	/* octree depth */
 	char depth;
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 6dca81415f3..139d89697e5 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4063,6 +4063,26 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
 		{MOD_REMESH_MASS_POINT, "SMOOTH", 0, "Smooth", "Output a smooth surface with no sharp-features detection"},
 		{MOD_REMESH_SHARP_FEATURES, "SHARP", 0, "Sharp",
 		                            "Output a surface that reproduces sharp edges and corners from the input mesh"},
+		{MOD_REMESH_VOXEL, "VOXEL", 0, "Voxel", "Invokes the OpenVDB voxel remesher and generates quad only meshes"},
+		{0, NULL, 0, NULL, NULL},
+	};
+
+	static const EnumPropertyItem filter_type_items[] = {
+		{VOXEL_FILTER_NONE, "NONE", 0, "None", "No Filter"},
+		{VOXEL_FILTER_GAUSSIAN, "GAUSSIAN", 0, "Gaussian", "Gaussian Filter"},
+		{VOXEL_FILTER_MEDIAN, "MEDIAN", 0, "Median", "Median Filter"},
+		{VOXEL_FILTER_MEAN, "MEAN", 0, "Mean", "Mean Filter"},
+		{VOXEL_FILTER_MEAN_CURVATURE, "MEAN_CURVATURE", 0, "Mean Curvature", "Mean Curvature Filter"},
+		{VOXEL_FILTER_LAPLACIAN, "LAPLACIAN", 0, "Laplacian", "Laplacian Filter"},
+		{0, NULL, 0, NULL, NULL},
+	};
+
+	static const EnumPropertyItem filter_bias_items[] = {
+		{VOXEL_BIAS_FIRST, "FIRST", 0, "First", "First bias"},
+		{VOXEL_BIAS_SECOND, "SECOND", 0, "Second", "Second bias"},
+		{VOXEL_BIAS_THIRD, "THIRD", 0, "Third", "Third bias"},
+		{VOXEL_BIAS_WENO5, "WENO5", 0, "Weno5", "Weno5 bias"},
+		{VOXEL_BIAS_HJWENO5, "HJWENO5", 0, "HjWeno5", "HjWeno5 bias"},
 		{0, NULL, 0, NULL, NULL},
 	};
 
@@ -4118,6 +4138,58 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_REMESH_SMOOTH_SHADING);
 	RNA_def_property_ui_text(prop, "Smooth Shading", "Output faces with smooth shading rather than flat shaded");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list