diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 53 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_runtime.c | 60 |
4 files changed, 67 insertions, 57 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 53300e92e67..dfc3b15403d 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -113,9 +113,6 @@ struct Mesh *BKE_mesh_new_nomain_from_template( struct Mesh *BKE_mesh_new_nomain_from_curve(struct Object *ob); struct Mesh *BKE_mesh_new_nomain_from_curve_displist(struct Object *ob, struct ListBase *dispbase); -bool BKE_mesh_ensure_edit_data(struct Mesh *me); -bool BKE_mesh_clear_edit_data(struct Mesh *me); - bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me); bool BKE_mesh_clear_facemap_customdata(struct Mesh *me); @@ -196,6 +193,10 @@ void BKE_mesh_runtime_reset(struct Mesh *mesh); int BKE_mesh_runtime_looptri_len(const struct Mesh *mesh); void BKE_mesh_runtime_looptri_recalc(struct Mesh *mesh); const struct MLoopTri *BKE_mesh_runtime_looptri_ensure(struct Mesh *mesh); +bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh); +bool BKE_mesh_runtime_clear_edit_data(struct Mesh *mesh); +void BKE_mesh_runtime_clear_geometry(struct Mesh *mesh); +void BKE_mesh_runtime_clear_cache(struct Mesh *mesh); /* *** mesh_evaluate.c *** */ diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 003d80c29cc..769c109cc31 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -2487,7 +2487,7 @@ static void editbmesh_calc_modifiers( else { struct Mesh *mesh = ob->data; if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) { - BKE_mesh_ensure_edit_data(mesh); + BKE_mesh_runtime_ensure_edit_data(mesh); mesh->runtime.edit_data->vertexCos = MEM_dupallocN(deformedVerts); } *r_cage = getEditDerivedBMesh( @@ -2529,7 +2529,7 @@ static void editbmesh_calc_modifiers( /* this is just a copy of the editmesh, no need to calc normals */ struct Mesh *mesh = ob->data; if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) { - BKE_mesh_ensure_edit_data(mesh); + BKE_mesh_runtime_ensure_edit_data(mesh); if (mesh->runtime.edit_data->vertexCos != NULL) MEM_freeN((void *)mesh->runtime.edit_data->vertexCos); mesh->runtime.edit_data->vertexCos = MEM_dupallocN(deformedVerts); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index e1739345d19..b16a5a6d75d 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -370,36 +370,6 @@ void BKE_mesh_ensure_skin_customdata(Mesh *me) } } -bool BKE_mesh_ensure_edit_data(struct Mesh *me) -{ - if (me->runtime.edit_data != NULL) { - return false; - } - - me->runtime.edit_data = MEM_callocN(sizeof(EditMeshData), "EditMeshData"); - return true; -} - -bool BKE_mesh_clear_edit_data(struct Mesh *me) -{ - if (me->runtime.edit_data == NULL) { - return false; - } - - if (me->runtime.edit_data->polyCos != NULL) - MEM_freeN((void *)me->runtime.edit_data->polyCos); - if (me->runtime.edit_data->polyNos != NULL) - MEM_freeN((void *)me->runtime.edit_data->polyNos); - if (me->runtime.edit_data->vertexCos != NULL) - MEM_freeN((void *)me->runtime.edit_data->vertexCos); - if (me->runtime.edit_data->vertexNos != NULL) - MEM_freeN((void *)me->runtime.edit_data->vertexNos); - - MEM_SAFE_FREE(me->runtime.edit_data); - return true; -} - - bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me) { BMesh *bm = me->edit_btmesh ? me->edit_btmesh->bm : NULL; @@ -492,8 +462,7 @@ void BKE_mesh_free(Mesh *me) { BKE_animdata_free(&me->id, false); - BKE_mesh_batch_cache_free(me); - BKE_mesh_clear_edit_data(me); + BKE_mesh_runtime_clear_cache(me); CustomData_free(&me->vdata, me->totvert); CustomData_free(&me->edata, me->totedge); @@ -505,9 +474,6 @@ void BKE_mesh_free(Mesh *me) MEM_SAFE_FREE(me->bb); MEM_SAFE_FREE(me->mselect); MEM_SAFE_FREE(me->edit_btmesh); - - MEM_SAFE_FREE(me->runtime.looptris.array); - bvhcache_free(&me->runtime.bvh_cache); } static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata) @@ -1837,20 +1803,3 @@ void BKE_mesh_eval_geometry(Depsgraph *depsgraph, BKE_mesh_texspace_calc(mesh); } } - -/* 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); - } -} 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); + } +} |