[Bf-blender-cvs] [2a08dae14e5] sculpt-mode-features: added a new live remesh option.

Martin Felke noreply at git.blender.org
Fri Apr 12 10:32:19 CEST 2019


Commit: 2a08dae14e5880ff53a464af7378f9c150b2aea9
Author: Martin Felke
Date:   Fri Apr 12 10:26:35 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB2a08dae14e5880ff53a464af7378f9c150b2aea9

added a new live remesh option.

If enabled, the modifier will be continously invoked, as usual. If disabled,
it will return the last automatically cached mesh, so basically the remesh
is "frozen", but still nondestructive / not applied yet.
Note, doesnt work yet in sculpt mode. There you may still need to apply
the modifier to update the base mesh. Or you can disable the modifier in
the stack to work on the base mesh, too. A third alternative is having
live remesh enabled with the modifier enabled, but this will cost some
sculpting performance and works at the moment only in material and rendered
mode.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenloader/intern/readfile.c
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/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 52697d1e0d5..a66571cb541 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1215,10 +1215,12 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
                     layout.prop(md, "filter_width")
                 if md.filter_type in {"DILATE", "ERODE"}:
                     layout.prop(md, "filter_iterations")
-
-            layout.prop(md, "smooth_normals")
-            layout.prop(md, "relax_triangles")
-            layout.prop(md, "reproject_vertex_paint")
+            row = layout.row()
+            row.prop(md, "live_remesh")
+            row.prop(md, "smooth_normals")
+            row = layout.row()
+            row.prop(md, "relax_triangles")
+            row.prop(md, "reproject_vertex_paint")
             layout.label(text="CSG Operands")
             layout.operator("remesh.csg_add", text="", icon="ADD")
             for i,csg in enumerate(md.csg_operands):
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a9f00bfac6b..810972efac8 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5793,6 +5793,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 		else if (md->type == eModifierType_Remesh) {
 			RemeshModifierData *rmd = (RemeshModifierData *)md;
 			link_list(fd, &rmd->csg_operands);
+			rmd->mesh_cached = newdataadr(fd, rmd->mesh_cached);
 		}
 	}
 }
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index b40df6158b7..98369923270 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2405,6 +2405,21 @@ void OBJECT_OT_surfacedeform_bind(wmOperatorType *ot)
 	edit_modifier_properties(ot);
 }
 
+static bool remesh_update_check(bContext *C, wmOperator *op)
+{
+	Object *ob = ED_object_active_context(C);
+	RemeshModifierData *rmd = (RemeshModifierData *)edit_modifier_property_get(op, ob, eModifierType_Remesh);
+	bool do_update = true;
+
+	if (rmd->mode == MOD_REMESH_VOXEL) {
+		if (((rmd->flag & MOD_REMESH_LIVE_REMESH) == 0) && rmd->mesh_cached) {
+			do_update = false;
+		}
+	}
+
+	return do_update;
+}
+
 static bool remesh_csg_poll(bContext *C)
 {
 	return edit_modifier_poll_generic(C, &RNA_RemeshModifier, 0);
@@ -2426,13 +2441,16 @@ static int remesh_csg_add_exec(bContext *C, wmOperator *op)
 	vcob->flag |= MOD_REMESH_CSG_SYNC_VOXEL_SIZE;
 	BLI_addtail(&rmd->csg_operands, vcob);
 
-	if (BLI_listbase_is_single(&rmd->csg_operands)) {
-		/*trigger update to detach modifier transform relation from modifier */
-		DEG_relations_tag_update(bmain);
-	}
+	if (remesh_update_check(C, op))
+	{
+		if (BLI_listbase_is_single(&rmd->csg_operands)) {
+			/*trigger update to detach modifier transform relation from modifier */
+			DEG_relations_tag_update(bmain);
+		}
 
-	DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
-	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+		DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+		WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+	}
 
 	return OPERATOR_FINISHED;
 }
@@ -2478,13 +2496,16 @@ static int remesh_csg_remove_exec(bContext *C, wmOperator *op)
 		BLI_remlink(&rmd->csg_operands, vcob);
 	}
 
-	if (BLI_listbase_is_empty(&rmd->csg_operands)) {
-		/*trigger update to detach modifier transform relation from modifier */
-		DEG_relations_tag_update(bmain);
-	}
+	if (remesh_update_check(C, op))
+	{
+		if (BLI_listbase_is_empty(&rmd->csg_operands)) {
+			/*trigger update to detach modifier transform relation from modifier */
+			DEG_relations_tag_update(bmain);
+		}
 
-	DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
-	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+		DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+		WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+	}
 
 	return OPERATOR_FINISHED;
 }
@@ -2533,8 +2554,11 @@ static int remesh_csg_move_up_exec(bContext *C, wmOperator *op)
 		BLI_insertlinkbefore(&rmd->csg_operands, vcob->prev, vcob);
 	}
 
-	DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
-	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+	if (remesh_update_check(C, op))
+	{
+		DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+		WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+	}
 
 	return OPERATOR_FINISHED;
 }
@@ -2583,8 +2607,11 @@ static int remesh_csg_move_down_exec(bContext *C, wmOperator *op)
 		BLI_insertlinkafter(&rmd->csg_operands, vcob->next, vcob);
 	}
 
-	DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
-	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+	if (remesh_update_check(C, op))
+	{
+		DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+		WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+	}
 
 	return OPERATOR_FINISHED;
 }
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index f07783df8e7..ed76eac5786 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1492,6 +1492,7 @@ typedef enum eRemeshModifierFlags {
 	MOD_REMESH_SMOOTH_NORMALS = (1 << 2),
 	MOD_REMESH_RELAX_TRIANGLES = (1 << 3),
 	MOD_REMESH_REPROJECT_VPAINT = (1 << 4),
+	MOD_REMESH_LIVE_REMESH     =  (1 << 5),
 } RemeshModifierFlags;
 
 typedef enum eRemeshModifierMode {
@@ -1569,6 +1570,7 @@ typedef struct RemeshModifierData {
 
 	/* volume csg */
 	struct ListBase csg_operands;
+	struct Mesh *mesh_cached;
 	int _pad1;
 
 	/* octree depth */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 6084d1499fb..d2365fa09b9 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -478,16 +478,36 @@ static char *rna_Modifier_path(PointerRNA *ptr)
 	return BLI_sprintfN("modifiers[\"%s\"]", name_esc);
 }
 
+static bool rna_Modifier_update_check(PointerRNA *ptr) {
+	ModifierData *md = ptr->data;
+	bool do_update = true;
+
+	if (md->type == eModifierType_Remesh) {
+		RemeshModifierData *rmd = (RemeshModifierData*)md;
+		if (rmd->mode == MOD_REMESH_VOXEL) {
+			if (((rmd->flag & MOD_REMESH_LIVE_REMESH) == 0) && rmd->mesh_cached) {
+				do_update = false;
+			}
+		}
+	}
+
+	return do_update;
+}
+
 static void rna_Modifier_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
-	DEG_id_tag_update(ptr->id.data, ID_RECALC_GEOMETRY);
-	WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ptr->id.data);
+	if (rna_Modifier_update_check(ptr)) {
+		DEG_id_tag_update(ptr->id.data, ID_RECALC_GEOMETRY);
+		WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ptr->id.data);
+	}
 }
 
 static void rna_Modifier_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
-	rna_Modifier_update(bmain, scene, ptr);
-	DEG_relations_tag_update(bmain);
+	if (rna_Modifier_update_check(ptr)) {
+		rna_Modifier_update(bmain, scene, ptr);
+		DEG_relations_tag_update(bmain);
+	}
 }
 
 /* Vertex Groups */
@@ -4250,6 +4270,12 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Reproject Vertex Paint", "Keep the current vertex paint on the new mesh");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "live_remesh", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_REMESH_LIVE_REMESH);
+	RNA_def_property_ui_text(prop, "Live Remesh",
+	                         "Perform remesh on every modifier update, otherwise return cached mesh");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "csg_operands", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_struct_type(prop, "CSGVolume_Object");
 	RNA_def_property_collection_sdna(prop, NULL, "csg_operands", NULL);
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index 7259745a509..77f2c992915 100644
--- a/source/blender/modifiers/intern/MOD_remesh.c
+++ b/source/blender/modifiers/intern/MOD_remesh.c
@@ -73,7 +73,7 @@ static void initData(ModifierData *md)
 	rmd->filter_bias = OPENVDB_LEVELSET_FIRST_BIAS;
 	rmd->filter_type = OPENVDB_LEVELSET_FILTER_NONE;
 	rmd->filter_iterations = 1;
-	//rmd->shared = MEM_callocN(sizeof(RemeshModifierData_Shared), "remesh shared");
+	rmd->flag |= MOD_REMESH_LIVE_REMESH;
 }
 
 #ifdef WITH_MOD_REMESH
@@ -248,6 +248,17 @@ static struct OpenVDBLevelSet* csgOperation(struct OpenVDBLevelSet* level_set, C
 
 	return level_set;
 }
+
+static Mesh* copy_mesh(Mesh *me) {
+	Mesh* result = BKE_mesh_new_nomain(me->totvert,
+									   me->totedge,
+									   me->totface,
+									   me->totloop,
+									   me->totpoly);
+
+	BKE_mesh_nomain_to_mesh(me, result, NULL, &CD_MASK_MESH, false);
+	return result;
+}
 #endif
 
 static Mesh *applyModifier(
@@ -270,7 +281,19 @@ static Mesh *applyModifier(
 		CSGVolume_Object *vcob;
 		struct OpenVDBLevelSet* level_set;
 
+		Object *ob_orig = DEG_get_original_object(ctx->object);
+		RemeshModifierData *rmd_orig = (RemeshModifierData*)modifiers_findByName(ob_orig, md->name);
+
+		if (((rmd->flag & MOD_REMESH_LIVE_REMESH) == 0))
+		{
+			//access mesh cache on ORIGINAL object, cow should not copy / free this over and over again
+			if (rmd_orig->mesh_cached) {
+				return copy_mesh(rmd_orig->mesh_cached);
+			}
+		}
+
 		if (rmd->voxel_size > 0.0f) {
+
 			struct OpenVDBTransform *xform = OpenVDBTransform_create();
 			OpenVDBTransform_create_linear_transform(xform, rmd->voxel_size);
 			level_set = BKE_remesh_voxel_ovdb_mesh_to_level_set_create(mesh, xform);
@@ -284,7 +307,21 @@ static Mesh *applyModifier(
 				}
 			}
 
-			return voxel_remesh(rmd, mesh, level_set);
+			result = voxel_remesh(rmd, mesh, level_set);
+
+			if (result)
+			{
+				//update cache
+				if (rmd_orig->mesh_cached) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list