[3b6a0f5fe0f] blender2.8: Modifiers: ported Surface DerivedMesh → Mesh

Sybren A. Stüvel noreply at git.blender.org
Thu May 17 16:24:25 CEST 2018


Commit: 3b6a0f5fe0f26d15927c67e7ef4083fd722c9015
Author: Sybren A. Stüvel
Date:   Thu May 17 16:21:04 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB3b6a0f5fe0f26d15927c67e7ef4083fd722c9015

Modifiers: ported Surface DerivedMesh → Mesh

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/modifiers/intern/MOD_surface.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 42984cfefaa..3d1707f2e77 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5204,7 +5204,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 		else if (md->type == eModifierType_Surface) {
 			SurfaceModifierData *surmd = (SurfaceModifierData *)md;
 			
-			surmd->dm = NULL;
+			surmd->mesh = NULL;
 			surmd->bvhtree = NULL;
 			surmd->x = NULL;
 			surmd->v = NULL;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index bd337443edc..1f88c541e78 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -651,7 +651,7 @@ typedef struct SurfaceModifierData {
 	struct MVert *x; /* old position */
 	struct MVert *v; /* velocity */
 
-	struct DerivedMesh *dm;
+	struct Mesh *mesh;
 
 	struct BVHTreeFromMesh *bvhtree; /* bounding volume hierarchy of the mesh faces */
 
diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c
index c05d021a845..7f3fa125cd9 100644
--- a/source/blender/modifiers/intern/MOD_surface.c
+++ b/source/blender/modifiers/intern/MOD_surface.c
@@ -35,14 +35,16 @@
 
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
+#include "BKE_bvhutils.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
+
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
-
-#include "BKE_cdderivedmesh.h"
-
 #include "MOD_modifiertypes.h"
 #include "MOD_util.h"
 
@@ -66,9 +68,9 @@ static void freeData(ModifierData *md)
 			MEM_SAFE_FREE(surmd->bvhtree);
 		}
 
-		if (surmd->dm) {
-			surmd->dm->release(surmd->dm);
-			surmd->dm = NULL;
+		if (surmd->mesh) {
+			BKE_id_free(NULL, surmd->mesh);
+			surmd->mesh = NULL;
 		}
 
 		MEM_SAFE_FREE(surmd->x);
@@ -84,34 +86,44 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
 
 static void deformVerts(
         ModifierData *md, const ModifierEvalContext *ctx,
-        DerivedMesh *derivedData,
+        Mesh *mesh,
         float (*vertexCos)[3],
         int UNUSED(numVerts))
 {
 	SurfaceModifierData *surmd = (SurfaceModifierData *) md;
 	
-	if (surmd->dm)
-		surmd->dm->release(surmd->dm);
+	if (surmd->mesh) {
+		BKE_id_free(NULL, surmd->mesh);
+	}
 
-	/* if possible use/create DerivedMesh */
-	if (derivedData) surmd->dm = CDDM_copy(derivedData);
-	else surmd->dm = get_dm(ctx->object, NULL, NULL, NULL, false, false);
+	if (mesh) {
+		/* Not possible to use get_mesh() in this case as we'll modify its vertices
+		 * and get_mesh() would return 'mesh' directly. */
+		BKE_id_copy_ex(
+		        NULL, (ID *)mesh, (ID **)&surmd->mesh,
+		        LIB_ID_CREATE_NO_MAIN |
+		        LIB_ID_CREATE_NO_USER_REFCOUNT |
+		        LIB_ID_CREATE_NO_DEG_TAG |
+		        LIB_ID_COPY_NO_PREVIEW,
+		        false);
+	}
+	else surmd->mesh = get_mesh(ctx->object, NULL, NULL, NULL, false, false);
 	
 	if (!ctx->object->pd) {
 		printf("SurfaceModifier deformVerts: Should not happen!\n");
 		return;
 	}
 
-	if (surmd->dm) {
+	if (surmd->mesh) {
 		unsigned int numverts = 0, i = 0;
 		int init = 0;
 		float *vec;
 		MVert *x, *v;
 
-		CDDM_apply_vert_coords(surmd->dm, vertexCos);
-		CDDM_calc_normals(surmd->dm);
+		BKE_mesh_apply_vert_coords(surmd->mesh, vertexCos);
+		BKE_mesh_calc_normals(surmd->mesh);
 		
-		numverts = surmd->dm->getNumVerts(surmd->dm);
+		numverts = surmd->mesh->totvert;
 
 		if (numverts != surmd->numverts ||
 		    surmd->x == NULL ||
@@ -137,7 +149,7 @@ static void deformVerts(
 
 		/* convert to global coordinates and calculate velocity */
 		for (i = 0, x = surmd->x, v = surmd->v; i < numverts; i++, x++, v++) {
-			vec = CDDM_get_vert(surmd->dm, i)->co;
+			vec = surmd->mesh->mvert[i].co;
 			mul_m4_v3(ctx->object->obmat, vec);
 
 			if (init)
@@ -155,10 +167,10 @@ static void deformVerts(
 		else
 			surmd->bvhtree = MEM_callocN(sizeof(BVHTreeFromMesh), "BVHTreeFromMesh");
 
-		if (surmd->dm->getNumPolys(surmd->dm))
-			bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_LOOPTRI, 2);
+		if (surmd->mesh->totpoly)
+			BKE_bvhtree_from_mesh_get(surmd->bvhtree, surmd->mesh, BVHTREE_FROM_LOOPTRI, 2);
 		else
-			bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_EDGES, 2);
+			BKE_bvhtree_from_mesh_get(surmd->bvhtree, surmd->mesh, BVHTREE_FROM_EDGES, 2);
 	}
 }
 
@@ -174,14 +186,14 @@ ModifierTypeInfo modifierType_Surface = {
 
 	/* copyData */          NULL,
 
-	/* deformVerts_DM */    deformVerts,
+	/* deformVerts_DM */    NULL,
 	/* deformMatrices_DM */ NULL,
 	/* deformVertsEM_DM */  NULL,
 	/* deformMatricesEM_DM*/NULL,
 	/* applyModifier_DM */  NULL,
 	/* applyModifierEM_DM */NULL,
 
-	/* deformVerts */       NULL,
+	/* deformVerts */       deformVerts,
 	/* deformMatrices */    NULL,
 	/* deformVertsEM */     NULL,
 	/* deformMatricesEM */  NULL,



More information about the Bf-blender-cvs mailing list