[Bf-blender-cvs] [d8a03c77d79] blender2.8: Allocate/free meshes with generic library functions.

Sybren A. Stüvel noreply at git.blender.org
Fri May 4 14:04:01 CEST 2018


Commit: d8a03c77d796db4ae2546fbcbe230dbf4846b0ea
Author: Sybren A. Stüvel
Date:   Thu May 3 15:42:55 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBd8a03c77d796db4ae2546fbcbe230dbf4846b0ea

Allocate/free meshes with generic library functions.

This avoids the need to use Mesh-specific functions, and makes allocation
and freeing easy oneliners.

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

M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/mesh_merge.c
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/modifiers/intern/MOD_armature.c
M	source/blender/modifiers/intern/MOD_lattice.c
M	source/blender/modifiers/intern/MOD_mirror.c
M	source/blender/modifiers/intern/MOD_skin.c

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

diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 2baa8c6edf4..3163ea6551e 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -47,6 +47,7 @@
 #include "BLI_utildefines_stack.h"
 
 #include "BKE_animsys.h"
+#include "BKE_idcode.h"
 #include "BKE_main.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
@@ -621,8 +622,7 @@ static Mesh *mesh_from_template_ex(
 {
 	const bool do_tessface = ((me_src->totface != 0) && (me_src->totpoly == 0)); /* only do tessface if we have no polys */
 
-	Mesh *me_dst = MEM_callocN(sizeof(struct Mesh), "Mesh");
-	BKE_mesh_init(me_dst);
+	Mesh *me_dst = BKE_id_new_nomain(ID_ME, NULL);
 
 	me_dst->mat = MEM_dupallocN(me_src->mat);
 	me_dst->mselect = MEM_dupallocN(me_dst->mselect);
@@ -703,8 +703,7 @@ BMesh *BKE_mesh_to_bmesh(
 
 Mesh *BKE_bmesh_to_mesh(BMesh *bm, const struct BMeshToMeshParams *params)
 {
-	Mesh *mesh = BKE_libblock_alloc_notest(ID_ME);
-	BKE_mesh_init(mesh);
+	Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL);
 	BM_mesh_bm_to_me(bm, mesh, params);
 	return mesh;
 }
diff --git a/source/blender/blenkernel/intern/mesh_merge.c b/source/blender/blenkernel/intern/mesh_merge.c
index 78e470dda4e..899de970fdd 100644
--- a/source/blender/blenkernel/intern/mesh_merge.c
+++ b/source/blender/blenkernel/intern/mesh_merge.c
@@ -39,6 +39,7 @@
 #include "BLI_ghash.h"
 
 #include "BKE_customdata.h"
+#include "BKE_library.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
 
@@ -677,8 +678,7 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh, const int *vtargetmap, const int tot_vtar
 	if (poly_map_mem != NULL)
 		MEM_freeN(poly_map_mem);
 
-	BKE_mesh_free(mesh);
-	MEM_freeN(mesh);
+	BKE_id_free(NULL, mesh);
 
 	return result;
 }
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 6722ed2aab1..5d2061f3bc6 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -60,6 +60,7 @@
 
 #include "BKE_appdir.h"
 #include "BKE_cdderivedmesh.h"
+#include "BKE_idcode.h"
 #include "BKE_key.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
@@ -1001,16 +1002,14 @@ void modifier_deformVerts_DM_deprecated(struct ModifierData *md, const ModifierE
 		/* TODO(sybren): deduplicate all the copies of this code in this file. */
 		Mesh *mesh = NULL;
 		if (dm != NULL) {
-			mesh = BKE_libblock_alloc_notest(ID_ME);
-			BKE_mesh_init(mesh);
+			mesh = BKE_id_new_nomain(ID_ME, NULL);
 			DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
 		}
 
 		mti->deformVerts(md, ctx, mesh, vertexCos, numVerts);
 
 		if (mesh != NULL) {
-			BKE_mesh_free(mesh);
-			MEM_freeN(mesh);
+			BKE_id_free(NULL, mesh);
 		}
 	}
 }
@@ -1029,16 +1028,14 @@ void modifier_deformMatrices_DM_deprecated(struct ModifierData *md, const Modifi
 		/* TODO(sybren): deduplicate all the copies of this code in this file. */
 		Mesh *mesh = NULL;
 		if (dm != NULL) {
-			mesh = BKE_libblock_alloc_notest(ID_ME);
-			BKE_mesh_init(mesh);
+			mesh = BKE_id_new_nomain(ID_ME, NULL);
 			DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
 		}
 
 		mti->deformMatrices(md, ctx, mesh, vertexCos, defMats, numVerts);
 
 		if (mesh != NULL) {
-			BKE_mesh_free(mesh);
-			MEM_freeN(mesh);
+			BKE_id_free(NULL, mesh);
 		}
 	}
 }
@@ -1056,16 +1053,14 @@ void modifier_deformVertsEM_DM_deprecated(struct ModifierData *md, const Modifie
 		/* TODO(sybren): deduplicate all the copies of this code in this file. */
 		Mesh *mesh = NULL;
 		if (dm != NULL) {
-			mesh = BKE_libblock_alloc_notest(ID_ME);
-			BKE_mesh_init(mesh);
+			mesh = BKE_id_new_nomain(ID_ME, NULL);
 			DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
 		}
 
 		mti->deformVertsEM(md, ctx, editData, mesh, vertexCos, numVerts);
 
 		if (mesh != NULL) {
-			BKE_mesh_free(mesh);
-			MEM_freeN(mesh);
+			BKE_id_free(NULL, mesh);
 		}
 	}
 }
@@ -1083,16 +1078,14 @@ void modifier_deformMatricesEM_DM_deprecated(struct ModifierData *md, const Modi
 		/* TODO(sybren): deduplicate all the copies of this code in this file. */
 		Mesh *mesh = NULL;
 		if (dm != NULL) {
-			mesh = BKE_libblock_alloc_notest(ID_ME);
-			BKE_mesh_init(mesh);
+			mesh = BKE_id_new_nomain(ID_ME, NULL);
 			DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
 		}
 
 		mti->deformMatricesEM(md, ctx, editData, mesh, vertexCos, defMats, numVerts);
 
 		if (mesh != NULL) {
-			BKE_mesh_free(mesh);
-			MEM_freeN(mesh);
+			BKE_id_free(NULL, mesh);
 		}
 	}
 }
@@ -1109,8 +1102,7 @@ struct DerivedMesh *modifier_applyModifier_DM_deprecated(struct ModifierData *md
 		/* TODO(sybren): deduplicate all the copies of this code in this file. */
 		Mesh *mesh = NULL;
 		if (dm != NULL) {
-			mesh = BKE_libblock_alloc_notest(ID_ME);
-			BKE_mesh_init(mesh);
+			mesh = BKE_id_new_nomain(ID_ME, NULL);
 			DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
 		}
 
@@ -1120,12 +1112,10 @@ struct DerivedMesh *modifier_applyModifier_DM_deprecated(struct ModifierData *md
 		DerivedMesh *ndm = CDDM_from_mesh_ex(new_mesh, CD_DUPLICATE);
 
 		if(new_mesh != mesh) {
-			BKE_mesh_free(new_mesh);
-			MEM_freeN(new_mesh);
+			BKE_id_free(NULL, new_mesh);
 		}
 		if (mesh != NULL) {
-			BKE_mesh_free(mesh);
-			MEM_freeN(mesh);
+			BKE_id_free(NULL, mesh);
 		}
 
 		return ndm;
@@ -1145,8 +1135,7 @@ struct DerivedMesh *modifier_applyModifierEM_DM_deprecated(struct ModifierData *
 		/* TODO(sybren): deduplicate all the copies of this code in this file. */
 		Mesh *mesh = NULL;
 		if (dm != NULL) {
-			mesh = BKE_libblock_alloc_notest(ID_ME);
-			BKE_mesh_init(mesh);
+			mesh = BKE_id_new_nomain(ID_ME, NULL);
 			DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
 		}
 
@@ -1156,12 +1145,10 @@ struct DerivedMesh *modifier_applyModifierEM_DM_deprecated(struct ModifierData *
 		DerivedMesh *ndm = CDDM_from_mesh_ex(new_mesh, CD_DUPLICATE);
 
 		if(new_mesh != mesh) {
-			BKE_mesh_free(new_mesh);
-			MEM_freeN(new_mesh);
+			BKE_id_free(NULL, new_mesh);
 		}
 		if (mesh != NULL) {
-			BKE_mesh_free(mesh);
-			MEM_freeN(mesh);
+			BKE_id_free(NULL, mesh);
 		}
 
 		return ndm;
diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c
index 488d04a1466..8e8b095d069 100644
--- a/source/blender/modifiers/intern/MOD_armature.c
+++ b/source/blender/modifiers/intern/MOD_armature.c
@@ -152,8 +152,7 @@ static void deformVertsEM(
 	}
 
 	if (!mesh) {
-		BKE_mesh_free(mesh_src);
-		MEM_freeN(mesh_src);
+		BKE_id_free(NULL, mesh_src);
 	}
 }
 
@@ -173,8 +172,7 @@ static void deformMatricesEM(
 	                      amd->deformflag, NULL, amd->defgrp_name);
 
 	if (!mesh) {
-		BKE_mesh_free(mesh_src);
-		MEM_freeN(mesh_src);
+		BKE_id_free(NULL, mesh_src);
 	}
 }
 
diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c
index 25f1ae1a687..87933558d86 100644
--- a/source/blender/modifiers/intern/MOD_lattice.c
+++ b/source/blender/modifiers/intern/MOD_lattice.c
@@ -41,6 +41,7 @@
 
 #include "BKE_editmesh.h"
 #include "BKE_lattice.h"
+#include "BKE_library.h"
 #include "BKE_library_query.h"
 #include "BKE_mesh.h"
 #include "BKE_modifier.h"
@@ -129,8 +130,7 @@ static void deformVertsEM(
 	deformVerts(md, ctx, mesh_src, vertexCos, numVerts);
 
 	if (!mesh) {
-		BKE_mesh_free(mesh_src);
-		MEM_freeN(mesh_src);
+		BKE_id_free(NULL, mesh_src);
 	}
 }
 
diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c
index 78a2f43c8e2..4edfbd43d7a 100644
--- a/source/blender/modifiers/intern/MOD_mirror.c
+++ b/source/blender/modifiers/intern/MOD_mirror.c
@@ -39,6 +39,7 @@
 
 #include "BLI_math.h"
 
+#include "BKE_library.h"
 #include "BKE_library_query.h"
 #include "BKE_mesh.h"
 #include "BKE_modifier.h"
@@ -313,8 +314,7 @@ static Mesh *mirrorModifier__doMirror(MirrorModifierData *mmd,
 		result = doMirrorOnAxis(mmd, ob, result, 1);
 		if (tmp != mesh) {
 			/* free intermediate results */
-			BKE_mesh_free(tmp);
-			MEM_freeN(tmp);
+			BKE_id_free(NULL, tmp);
 		}
 	}
 	if (mmd->flag & MOD_MIR_AXIS_Z) {
@@ -322,8 +322,7 @@ static Mesh *mirrorModifier__doMirror(MirrorModifierData *mmd,
 		result = doMirrorOnAxis(mmd, ob, result, 2);
 		if (tmp != mesh) {
 			/* free intermediate results */
-			BKE_mesh_free(tmp);
-			MEM_freeN(tmp);
+			BKE_id_free(NULL, tmp);
 		}
 	}
 
diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c
index 080706c00c5..defb661d9d8 100644
--- a/source/blender/modifiers/intern/MOD_skin.c
+++ b/source/blender/modifiers/intern/MOD_skin.c
@@ -72,6 +72,7 @@
 #include "BLI_bitmap.h"
 
 #include "BKE_deform.h"
+#include "BKE_library.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
 #include "BKE_modifier.h"
@@ -1885,9 +1886,7 @@ static Mesh *final_skin(SkinModifierData *smd, Mesh *mesh)
 	mesh = subdivide_base(mesh);
 	result = base_skin(mesh, smd);
 
-	BKE_mesh_free(mesh);
-	MEM_freeN(mesh);
-
+	BKE_id_free(NULL, mesh);
 	return result;
 }



More information about the Bf-blender-cvs mailing list