From d8a03c77d796db4ae2546fbcbe230dbf4846b0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 3 May 2018 15:42:55 +0200 Subject: Allocate/free meshes with generic library functions. This avoids the need to use Mesh-specific functions, and makes allocation and freeing easy oneliners. --- source/blender/blenkernel/intern/modifier.c | 43 ++++++++++------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'source/blender/blenkernel/intern/modifier.c') 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; -- cgit v1.2.3