[Bf-blender-cvs] [3d288c58d26] sculpt-mode-features: first attempt for allowing different voxel sizes on operands

Martin Felke noreply at git.blender.org
Sat Apr 13 01:12:46 CEST 2019


Commit: 3d288c58d268feff8c0f5627de898e8d9572766b
Author: Martin Felke
Date:   Sat Apr 13 01:10:15 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB3d288c58d268feff8c0f5627de898e8d9572766b

first attempt for allowing different voxel sizes on operands

the grids should not have offsets any more, they are being transformed and resampled.
but does not look overly great yet... and is very slow, too.

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

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

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

diff --git a/intern/openvdb/openvdb_capi.cc b/intern/openvdb/openvdb_capi.cc
index 08057faccf2..0d8e178553d 100644
--- a/intern/openvdb/openvdb_capi.cc
+++ b/intern/openvdb/openvdb_capi.cc
@@ -304,11 +304,59 @@ void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out, struct OpenVDBLe
 	out->OpenVDB_level_set_set_grid(grid);
 }
 
-void OpenVDBLevelSet_set_transform(struct OpenVDBLevelSet *level_set, float* transform)
-{
-	openvdb::FloatGrid::Ptr grid = level_set->OpenVDB_level_set_get_grid();
-	openvdb::math::Mat4f mat(transform);
-	openvdb::math::Transform::Ptr trans = openvdb::math::Transform::createLinearTransform(mat);
-	grid->setTransform(trans);
-	openvdb::tools::resampleToMatch<openvdb::tools::BoxSampler>(*grid, *grid);
+OpenVDBLevelSet* OpenVDBLevelSet_transform_and_resample(struct OpenVDBLevelSet *level_setA,
+                                                        struct OpenVDBLevelSet *level_setB,
+														char sampler)
+{
+	openvdb::FloatGrid::Ptr sourceGrid = level_setA->OpenVDB_level_set_get_grid();
+	openvdb::FloatGrid::Ptr targetGrid = level_setB->OpenVDB_level_set_get_grid()->deepCopy();
+
+	const openvdb::math::Transform
+	    &sourceXform = sourceGrid->transform(),
+	    &targetXform = targetGrid->transform();
+
+	// Compute a source grid to target grid transform.
+	// (For this example, we assume that both grids' transforms are linear,
+	// so that they can be represented as 4 x 4 matrices.)
+	openvdb::Mat4R xform =
+	    sourceXform.baseMap()->getAffineMap()->getMat4()*
+	    targetXform.baseMap()->getAffineMap()->getMat4().inverse();
+
+	// Create the transformer.
+	openvdb::tools::GridTransformer transformer(xform);
+
+	switch (sampler) {
+		case OPENVDB_LEVELSET_GRIDSAMPLER_POINT:
+			// Resample using nearest-neighbor interpolation.
+			transformer.transformGrid<openvdb::tools::PointSampler, openvdb::FloatGrid>(
+				*sourceGrid, *targetGrid);
+			// Prune the target tree for optimal sparsity.
+			targetGrid->tree().prune();
+		break;
+
+		case OPENVDB_LEVELSET_GRIDSAMPLER_BOX:
+			// Resample using trilinear interpolation.
+			transformer.transformGrid<openvdb::tools::BoxSampler, openvdb::FloatGrid>(
+				*sourceGrid, *targetGrid);
+			// Prune the target tree for optimal sparsity.
+			targetGrid->tree().prune();
+		break;
+
+		case OPENVDB_LEVELSET_GRIDSAMPLER_QUADRATIC:
+			// Resample using triquadratic interpolation.
+			transformer.transformGrid<openvdb::tools::QuadraticSampler, openvdb::FloatGrid>(
+				*sourceGrid, *targetGrid);
+			// Prune the target tree for optimal sparsity.
+			targetGrid->tree().prune();
+		break;
+
+		case OPENVDB_LEVELSET_GRIDSAMPLER_NONE:
+			//targetGrid = sourceGrid->deepCopy();
+		break;
+	}
+
+	OpenVDBLevelSet* level_set = OpenVDBLevelSet_create(false, NULL);
+	level_set->OpenVDB_level_set_set_grid(targetGrid);
+
+	return level_set;
 }
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index 912c5135460..d5e2fd363bc 100644
--- a/intern/openvdb/openvdb_capi.h
+++ b/intern/openvdb/openvdb_capi.h
@@ -52,6 +52,13 @@ typedef enum OpenVDBLevelSet_CSGOperation {
 	OPENVDB_LEVELSET_CSG_INTERSECTION = 2,
 } OpenVDBLevelSet_CSGOperation;
 
+typedef enum OpenVDBLevelSet_GridSampler {
+	OPENVDB_LEVELSET_GRIDSAMPLER_NONE = 0,
+	OPENVDB_LEVELSET_GRIDSAMPLER_POINT = 1,
+	OPENVDB_LEVELSET_GRIDSAMPLER_BOX = 2,
+	OPENVDB_LEVELSET_GRIDSAMPLER_QUADRATIC = 3,
+} OpenVDBLevelSet_Gridsampler;
+
 struct OpenVDBReader;
 struct OpenVDBWriter;
 struct OpenVDBTransform;
@@ -172,7 +179,10 @@ void OpenVDBLevelSet_filter(struct OpenVDBLevelSet *level_set, OpenVDBLevelSet_F
 							int iterations, OpenVDBLevelSet_FilterBias bias);
 void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out, struct OpenVDBLevelSet *gridA, struct OpenVDBLevelSet *gridB,
 								   OpenVDBLevelSet_CSGOperation operation);
-void OpenVDBLevelSet_set_transform(struct OpenVDBLevelSet *level_set, float* transform);
+
+struct OpenVDBLevelSet *OpenVDBLevelSet_transform_and_resample(struct OpenVDBLevelSet *level_setA,
+                                                        struct OpenVDBLevelSet *level_setB,
+                                                        char sampler);
 
 
 #ifdef __cplusplus
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index a66571cb541..e5f34295766 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1236,8 +1236,13 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
                 icon = "RESTRICT_VIEW_ON"
                 if csg.sync_voxel_size:
                     icon = "RESTRICT_VIEW_OFF"
-                row.prop(csg, "sync_voxel_size", text="", icon=icon, emboss=True)
-                row.prop(csg, "voxel_size")
+                row.prop(csg, "use_voxel_percentage", text="", icon='CANCEL', emboss=True)
+                if not csg.use_voxel_percentage:
+                    row.prop(csg, "sync_voxel_size", text="", icon=icon, emboss=True)
+                    row.prop(csg, "voxel_size")
+                else:
+                    row.prop(csg, "voxel_percentage")
+                row.prop(csg, "sampler", text="")
                 row.operator("remesh.csg_remove", text="", icon="REMOVE").index = i
                 row.operator("remesh.csg_move_up", text="", icon="TRIA_UP").index = i
                 row.operator("remesh.csg_move_down", text="", icon="TRIA_DOWN").index = i
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 98369923270..3c70056197f 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2439,6 +2439,9 @@ static int remesh_csg_add_exec(bContext *C, wmOperator *op)
 	vcob->voxel_size = rmd->voxel_size;
 	vcob->flag |= MOD_REMESH_CSG_OBJECT_ENABLED;
 	vcob->flag |= MOD_REMESH_CSG_SYNC_VOXEL_SIZE;
+	vcob->sampler = eRemeshModifierSampler_None;
+	vcob->voxel_percentage = 100.0f;
+
 	BLI_addtail(&rmd->csg_operands, vcob);
 
 	if (remesh_update_check(C, op))
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index ed76eac5786..81ef0d446d8 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1512,6 +1512,13 @@ typedef enum {
 	eRemeshModifierOp_Intersect  = 2,
 } RemeshModifierOp;
 
+typedef enum {
+	eRemeshModifierSampler_None       = 0,
+	eRemeshModifierSampler_Point      = 1,
+	eRemeshModifierSampler_Box        = 2,
+	eRemeshModifierSampler_Quadratic  = 3,
+} RemeshModifierSampler;
+
 typedef enum eVoxelFilterType {
 	VOXEL_FILTER_NONE = 0,
 	VOXEL_FILTER_GAUSSIAN = 1,
@@ -1535,16 +1542,20 @@ typedef enum eVoxelFilterBias{
 typedef enum eCSGVolumeOperandFlags {
 	MOD_REMESH_CSG_OBJECT_ENABLED = (1 << 0),
 	MOD_REMESH_CSG_SYNC_VOXEL_SIZE = (1 << 1),
+	MOD_REMESH_CSG_VOXEL_PERCENTAGE = (1 << 2),
 } eCSGVolumeOperandFlags;
 
 typedef struct CSGVolume_Object {
 	struct CSGVolume_Object *next, *prev;
-	struct RemeshModifierData *md; //modifier we belong to
+	struct RemeshModifierData *md;
+	//modifier we belong to (currently unused, probably should be deprecated/removed ?)
 	struct Object *object;
 	float voxel_size;
+	float voxel_percentage;
 	char operation;
 	char flag;
-	char _pad[2];
+	char sampler;
+	char _pad[5];
 
 } CSGVolume_Object;
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index d2365fa09b9..6d1bc53dd99 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4158,6 +4158,15 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
 		{0, NULL, 0, NULL, NULL},
 	};
 
+	static const EnumPropertyItem prop_sampler_items[] = {
+		{eRemeshModifierSampler_None, "None", 0, "None", "Do not resample to match grid transforms."},
+		{eRemeshModifierSampler_Point, "POINT", 0, "Point", "Use OpenVDBs point sampler to match grid transforms."},
+		{eRemeshModifierSampler_Box, "BOX", 0, "Box", "Use OpenVDBs box sampler to match grid transforms."},
+		{eRemeshModifierSampler_Quadratic, "QUADRATIC", 0, "Quadratic",
+		                               "Use OpenVDBs quadratic sampler to match grid transforms."},
+		{0, NULL, 0, NULL, NULL},
+	};
+
 	StructRNA *srna;
 	PropertyRNA *prop;
 
@@ -4297,7 +4306,7 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_items(prop, prop_operation_items);
-	RNA_def_property_enum_default(prop, eBooleanModifierOp_Difference);
+	RNA_def_property_enum_default(prop, eRemeshModifierOp_Difference);
 	RNA_def_property_ui_text(prop, "Operation", "");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
@@ -4308,15 +4317,33 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Voxel Size", "Voxel size used for volume evaluation");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "voxel_percentage", PROP_FLOAT, PROP_PERCENTAGE);
+	RNA_def_property_range(prop, 1.0, 100.0);
+	RNA_def_property_float_default(prop, 100.0);
+	RNA_def_property_ui_range(prop, 1.0, 100.0, 0.1, 1);
+	RNA_def_property_ui_text(prop, "Voxel Percentage", "Voxel percentage multiplier");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_REMESH_CSG_OBJECT_ENABLED);
 	RNA_def_property_ui_text(prop, "Enabled", "Consider this object as part of the csg operations");
 	RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
 
+	prop = RNA_def_property(srna, "use_voxel_percentage", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_REMESH_CSG_VOXEL_PERCENTAGE);
+	RNA_def_property_ui_text(prop, "Percentage", "Use Voxel percentage multiplier");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "sync_voxel_size", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_pr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list