From 5503e2565b2e7a213327053cd0210031dc5bad92 Mon Sep 17 00:00:00 2001 From: Germano Date: Fri, 11 May 2018 15:48:14 -0300 Subject: Bmesh: Clear possible geometry saved at runtime when converting bmesh to mesh. --- source/blender/blenkernel/intern/mesh_runtime.c | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'source/blender/blenkernel/intern/mesh_runtime.c') diff --git a/source/blender/blenkernel/intern/mesh_runtime.c b/source/blender/blenkernel/intern/mesh_runtime.c index 96d31fa9a42..577b7327181 100644 --- a/source/blender/blenkernel/intern/mesh_runtime.c +++ b/source/blender/blenkernel/intern/mesh_runtime.c @@ -39,6 +39,7 @@ #include "BLI_math_geom.h" #include "BLI_threads.h" +#include "BKE_bvhutils.h" #include "BKE_mesh.h" @@ -52,6 +53,13 @@ void BKE_mesh_runtime_reset(Mesh *mesh) memset(&mesh->runtime, 0, sizeof(mesh->runtime)); } +void BKE_mesh_runtime_clear_cache(Mesh *mesh) +{ + BKE_mesh_runtime_clear_geometry(mesh); + BKE_mesh_batch_cache_free(mesh); + BKE_mesh_runtime_clear_edit_data(mesh); +} + /* This is a ported copy of DM_ensure_looptri_data(dm) */ /** * Ensure the array is large enough @@ -135,3 +143,55 @@ const MLoopTri *BKE_mesh_runtime_looptri_ensure(Mesh *mesh) } return looptri; } + +bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh) +{ + if (mesh->runtime.edit_data != NULL) { + return false; + } + + mesh->runtime.edit_data = MEM_callocN(sizeof(EditMeshData), "EditMeshData"); + return true; +} + +bool BKE_mesh_runtime_clear_edit_data(Mesh *mesh) +{ + if (mesh->runtime.edit_data == NULL) { + return false; + } + + if (mesh->runtime.edit_data->polyCos != NULL) + MEM_freeN((void *)mesh->runtime.edit_data->polyCos); + if (mesh->runtime.edit_data->polyNos != NULL) + MEM_freeN((void *)mesh->runtime.edit_data->polyNos); + if (mesh->runtime.edit_data->vertexCos != NULL) + MEM_freeN((void *)mesh->runtime.edit_data->vertexCos); + if (mesh->runtime.edit_data->vertexNos != NULL) + MEM_freeN((void *)mesh->runtime.edit_data->vertexNos); + + MEM_SAFE_FREE(mesh->runtime.edit_data); + return true; +} + +void BKE_mesh_runtime_clear_geometry(Mesh *mesh) +{ + bvhcache_free(&mesh->runtime.bvh_cache); + MEM_SAFE_FREE(mesh->runtime.looptris.array); +} + +/* Draw Engine */ +void (*BKE_mesh_batch_cache_dirty_cb)(Mesh *me, int mode) = NULL; +void (*BKE_mesh_batch_cache_free_cb)(Mesh *me) = NULL; + +void BKE_mesh_batch_cache_dirty(Mesh *me, int mode) +{ + if (me->runtime.batch_cache) { + BKE_mesh_batch_cache_dirty_cb(me, mode); + } +} +void BKE_mesh_batch_cache_free(Mesh *me) +{ + if (me->runtime.batch_cache) { + BKE_mesh_batch_cache_free_cb(me); + } +} -- cgit v1.2.3