[054d837e650] blender2.8: Modifiers: ported Laplacian Deform DerivedMesh → Mesh

Christian Hubert noreply at git.blender.org
Fri May 11 18:10:47 CEST 2018


Commit: 054d837e650250f62b4af4c8a5943cd74244e48e
Author: Christian Hubert
Date:   Fri May 11 17:30:57 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB054d837e650250f62b4af4c8a5943cd74244e48e

Modifiers: ported Laplacian Deform DerivedMesh → Mesh

Reviewers: sybren

Differential Revision: https://developer.blender.org/D3326

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

M	source/blender/editors/object/object_modifier.c
M	source/blender/modifiers/intern/MOD_laplaciandeform.c

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

diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 917210390b1..43cd65c55cd 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2281,17 +2281,43 @@ static int laplaciandeform_poll(bContext *C)
 
 static int laplaciandeform_bind_exec(bContext *C, wmOperator *op)
 {
+	Scene *scene = CTX_data_scene(C);
 	Object *ob = ED_object_active_context(C);
+	Depsgraph *depsgraph = CTX_data_depsgraph(C);
 	LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)edit_modifier_property_get(op, ob, eModifierType_LaplacianDeform);
 
 	if (!lmd)
 		return OPERATOR_CANCELLED;
 	if (lmd->flag & MOD_LAPLACIANDEFORM_BIND) {
+		/* Un-binding happens inside the modifier when it's evaluated. */
 		lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND;
 	}
 	else {
+		DerivedMesh *dm;
+		int mode = lmd->modifier.mode;
+
+		/* Force modifier to run, it will call binding routine. */
+		/* TODO(Sybren): deduplicate the code below, it's used multiple times here. */
+		lmd->modifier.mode |= eModifierMode_Realtime;
 		lmd->flag |= MOD_LAPLACIANDEFORM_BIND;
+
+		if (ob->type == OB_MESH) {
+			dm = mesh_create_derived_view(depsgraph, scene, ob, 0);
+			dm->release(dm);
+		}
+		else if (ob->type == OB_LATTICE) {
+			BKE_lattice_modifiers_calc(depsgraph, scene, ob);
+		}
+		else if (ob->type == OB_MBALL) {
+			BKE_displist_make_mball(depsgraph, scene, ob);
+		}
+		else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
+			BKE_displist_make_curveTypes(depsgraph, scene, ob, 0);
+		}
+
+		lmd->modifier.mode = mode;
 	}
+
 	DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
 	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
 	return OPERATOR_FINISHED;
diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c
index 2dbe2af763b..83d5c915482 100644
--- a/source/blender/modifiers/intern/MOD_laplaciandeform.c
+++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c
@@ -35,10 +35,15 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BKE_deform.h"
+#include "BKE_editmesh.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
-#include "BKE_cdderivedmesh.h"
 #include "BKE_particle.h"
-#include "BKE_deform.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
 
 #include "MOD_util.h"
 
@@ -499,17 +504,17 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
 	}
 }
 
-static bool isValidVertexGroup(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh *dm)
+static bool isValidVertexGroup(LaplacianDeformModifierData *lmd, Object *ob, Mesh *mesh)
 {
 	int defgrp_index;
 	MDeformVert *dvert = NULL;
 
-	modifier_get_vgroup(ob, dm, lmd->anchor_grp_name, &dvert, &defgrp_index);
+	modifier_get_vgroup_mesh(ob, mesh, lmd->anchor_grp_name, &dvert, &defgrp_index);
 
 	return  (dvert != NULL);
 }
 
-static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh *dm,
+static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, Mesh *mesh,
                        float (*vertexCos)[3], int numVerts)
 {
 	int i;
@@ -520,7 +525,7 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh
 	MDeformVert *dv = NULL;
 	LaplacianSystem *sys;
 
-	if (isValidVertexGroup(lmd, ob, dm)) {
+	if (isValidVertexGroup(lmd, ob, mesh)) {
 		int *index_anchors = MEM_malloc_arrayN(numVerts, sizeof(int), __func__);  /* over-alloc */
 		const MLoopTri *mlooptri;
 		const MLoop *mloop;
@@ -529,7 +534,7 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh
 
 		STACK_INIT(index_anchors, numVerts);
 
-		modifier_get_vgroup(ob, dm, lmd->anchor_grp_name, &dvert, &defgrp_index);
+		modifier_get_vgroup_mesh(ob, mesh, lmd->anchor_grp_name, &dvert, &defgrp_index);
 		BLI_assert(dvert != NULL);
 		dv = dvert;
 		for (i = 0; i < numVerts; i++) {
@@ -541,8 +546,8 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh
 		}
 
 		total_anchors = STACK_SIZE(index_anchors);
-		lmd->cache_system = initLaplacianSystem(numVerts, dm->getNumEdges(dm), dm->getNumLoopTri(dm),
-		                                       total_anchors, lmd->anchor_grp_name, lmd->repeat);
+		lmd->cache_system = initLaplacianSystem(numVerts, mesh->totedge, BKE_mesh_runtime_looptri_len(mesh),
+		                                        total_anchors, lmd->anchor_grp_name, lmd->repeat);
 		sys = (LaplacianSystem *)lmd->cache_system;
 		memcpy(sys->index_anchors, index_anchors, sizeof(int) * total_anchors);
 		memcpy(sys->co, vertexCos, sizeof(float[3]) * numVerts);
@@ -552,15 +557,15 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh
 		lmd->total_verts = numVerts;
 
 		createFaceRingMap(
-		            dm->getNumVerts(dm), dm->getLoopTriArray(dm), dm->getNumLoopTri(dm),
-		            dm->getLoopArray(dm), &sys->ringf_map, &sys->ringf_indices);
+		            mesh->totvert, BKE_mesh_runtime_looptri_ensure(mesh), BKE_mesh_runtime_looptri_len(mesh),
+		            mesh->mloop, &sys->ringf_map, &sys->ringf_indices);
 		createVertRingMap(
-		            dm->getNumVerts(dm), dm->getEdgeArray(dm), dm->getNumEdges(dm),
+		            mesh->totvert, mesh->medge, mesh->totedge,
 		            &sys->ringv_map, &sys->ringv_indices);
 
 
-		mlooptri = dm->getLoopTriArray(dm);
-		mloop = dm->getLoopArray(dm);
+		mlooptri = BKE_mesh_runtime_looptri_ensure(mesh);
+		mloop = mesh->mloop;;
 
 		for (i = 0; i < sys->total_tris; i++) {
 			sys->tris[i][0] = mloop[mlooptri[i].tri[0]].v;
@@ -570,7 +575,7 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh
 	}
 }
 
-static int isSystemDifferent(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh *dm, int numVerts)
+static int isSystemDifferent(LaplacianDeformModifierData *lmd, Object *ob, Mesh *mesh, int numVerts)
 {
 	int i;
 	int defgrp_index;
@@ -583,13 +588,13 @@ static int isSystemDifferent(LaplacianDeformModifierData *lmd, Object *ob, Deriv
 	if (sys->total_verts != numVerts) {
 		return LAPDEFORM_SYSTEM_CHANGE_VERTEXES;
 	}
-	if (sys->total_edges != dm->getNumEdges(dm)) {
+	if (sys->total_edges != mesh->totedge) {
 		return LAPDEFORM_SYSTEM_CHANGE_EDGES;
 	}
 	if (!STREQ(lmd->anchor_grp_name, sys->anchor_grp_name)) {
 		return LAPDEFORM_SYSTEM_ONLY_CHANGE_GROUP;
 	}
-	modifier_get_vgroup(ob, dm, lmd->anchor_grp_name, &dvert, &defgrp_index);
+	modifier_get_vgroup_mesh(ob, mesh, lmd->anchor_grp_name, &dvert, &defgrp_index);
 	if (!dvert) {
 		return LAPDEFORM_SYSTEM_CHANGE_NOT_VALID_GROUP;
 	}
@@ -609,7 +614,7 @@ static int isSystemDifferent(LaplacianDeformModifierData *lmd, Object *ob, Deriv
 }
 
 static void LaplacianDeformModifier_do(
-        LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh *dm,
+        LaplacianDeformModifierData *lmd, Object *ob, Mesh *mesh,
         float (*vertexCos)[3], int numVerts)
 {
 	float (*filevertexCos)[3];
@@ -627,7 +632,7 @@ static void LaplacianDeformModifier_do(
 		return;
 	}
 	if (lmd->cache_system) {
-		sysdif = isSystemDifferent(lmd, ob, dm, numVerts);
+		sysdif = isSystemDifferent(lmd, ob, mesh, numVerts);
 		sys = lmd->cache_system;
 		if (sysdif) {
 			if (sysdif == LAPDEFORM_SYSTEM_ONLY_CHANGE_ANCHORS || sysdif == LAPDEFORM_SYSTEM_ONLY_CHANGE_GROUP) {
@@ -637,7 +642,7 @@ static void LaplacianDeformModifier_do(
 				lmd->total_verts = 0;
 				deleteLaplacianSystem(sys);
 				lmd->cache_system = NULL;
-				initSystem(lmd, ob, dm, filevertexCos, numVerts);
+				initSystem(lmd, ob, mesh, filevertexCos, numVerts);
 				sys = lmd->cache_system; /* may have been reallocated */
 				MEM_SAFE_FREE(filevertexCos);
 				if (sys) {
@@ -649,7 +654,7 @@ static void LaplacianDeformModifier_do(
 					modifier_setError(&lmd->modifier, "Vertices changed from %d to %d", lmd->total_verts, numVerts);
 				}
 				else if (sysdif == LAPDEFORM_SYSTEM_CHANGE_EDGES) {
-					modifier_setError(&lmd->modifier, "Edges changed from %d to %d", sys->total_edges, dm->getNumEdges(dm));
+					modifier_setError(&lmd->modifier, "Edges changed from %d to %d", sys->total_edges, mesh->totedge);
 				}
 				else if (sysdif == LAPDEFORM_SYSTEM_CHANGE_NOT_VALID_GROUP) {
 					modifier_setError(&lmd->modifier, "Vertex group '%s' is not valid", sys->anchor_grp_name);
@@ -662,7 +667,7 @@ static void LaplacianDeformModifier_do(
 		}
 	}
 	else {
-		if (!isValidVertexGroup(lmd, ob, dm)) {
+		if (!isValidVertexGroup(lmd, ob, mesh)) {
 			modifier_setError(&lmd->modifier, "Vertex group '%s' is not valid", lmd->anchor_grp_name);
 			lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND;
 		}
@@ -671,13 +676,13 @@ static void LaplacianDeformModifier_do(
 			memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * numVerts);
 			MEM_SAFE_FREE(lmd->vertexco);
 			lmd->total_verts = 0;
-			initSystem(lmd, ob, dm, filevertexCos, numVerts);
+			initSystem(lmd, ob, mesh, filevertexCos, numVerts);
 			sys = lmd->cache_system;
 			MEM_SAFE_FREE(filevertexCos);
 			laplacianDeformPreview(sys, vertexCos);
 		}
 		else {
-			initSystem(lmd, ob, dm, vertexCos, numVerts);
+			initSystem(lmd, ob, mesh, vertexCos, numVerts);
 			sys = lmd->cache_system;
 			laplacianDeformPreview(sys, vertexCos);
 		}
@@ -724,26 +729,26 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
 	return dataMask;
 }
 
-static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh,
                         float (*vertexCos)[3], int numVerts)
 {
-	DerivedMesh *dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
+	Mesh *mesh_src = get_mesh(ctx->object, NULL, mesh, NULL, false, false);
 
-	LaplacianDeformModifier_do((LaplacianDeformModifierData *)md, ctx->object, dm, vertexCos, numVerts);
-	if (dm != derivedData) {
-		dm->release(dm);
+	LaplacianDeformModifier_do((LaplacianDeformModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts);
+	if (mesh_src != mesh) {
+		BKE_id_free(NULL, mesh_src);
 	}
 }
 
 static void deformVertsEM(
         ModifierData *md, const ModifierEvalContext *ctx, struc

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list