diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-05-15 12:54:05 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-05-15 12:54:05 +0400 |
commit | 9c510330d982d92a7c5b1475200b885fbc5e8f32 (patch) | |
tree | 7665d8f9b11998b1d6c17af58af7e1daf5d0bd34 /source/blender/blenkernel/intern/paint.c | |
parent | 4fcd44d3897403e6c87abf5a6020153c0d220d2d (diff) |
Move sculptsession functions implementation from object.c to paint.c
This functios are declared in BKE_paint.h header and using
SculptSession structure which is also declared there.
Anyway, does not make sense such a splitting of header and
implementation files, better be consistent here.
Diffstat (limited to 'source/blender/blenkernel/intern/paint.c')
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 3912a79e703..74542321a62 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -32,6 +32,8 @@ #include <stdlib.h> #include <string.h> +#include "MEM_guardedalloc.h" + #include "DNA_object_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" @@ -45,9 +47,12 @@ #include "BKE_brush.h" #include "BKE_context.h" +#include "BKE_depsgraph.h" #include "BKE_global.h" +#include "BKE_image.h" #include "BKE_library.h" #include "BKE_paint.h" +#include "BKE_pbvh.h" #include "BKE_subsurf.h" #include "bmesh.h" @@ -376,3 +381,115 @@ void paint_calculate_rake_rotation(UnifiedPaintSettings *ups, const float mouse_ mouse_pos, u); } } + +void free_sculptsession_deformMats(SculptSession *ss) +{ + if (ss->orig_cos) MEM_freeN(ss->orig_cos); + if (ss->deform_cos) MEM_freeN(ss->deform_cos); + if (ss->deform_imats) MEM_freeN(ss->deform_imats); + + ss->orig_cos = NULL; + ss->deform_cos = NULL; + ss->deform_imats = NULL; +} + +/* Write out the sculpt dynamic-topology BMesh to the Mesh */ +static void sculptsession_bm_to_me_update_data_only(Object *ob, bool reorder) +{ + SculptSession *ss = ob->sculpt; + + if (ss->bm) { + if (ob->data) { + BMIter iter; + BMFace *efa; + BM_ITER_MESH (efa, &iter, ss->bm, BM_FACES_OF_MESH) { + BM_elem_flag_set(efa, BM_ELEM_SMOOTH, + ss->bm_smooth_shading); + } + if (reorder) + BM_log_mesh_elems_reorder(ss->bm, ss->bm_log); + BM_mesh_bm_to_me(ss->bm, ob->data, FALSE); + } + } +} + +void sculptsession_bm_to_me(Object *ob, int reorder) +{ + if (ob && ob->sculpt) { + sculptsession_bm_to_me_update_data_only(ob, reorder); + + /* ensure the objects DerivedMesh mesh doesn't hold onto arrays now realloc'd in the mesh [#34473] */ + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + } +} + +void sculptsession_bm_to_me_for_render(Object *object) +{ + if (object && object->sculpt) { + if (object->sculpt->bm) { + /* Ensure no points to old arrays are stored in DM + * + * Apparently, we could not use DAG_id_tag_update + * here because this will lead to the while object + * surface to disappear, so we'll release DM in place. + */ + if (object->derivedFinal) { + object->derivedFinal->needsFree = 1; + object->derivedFinal->release(object->derivedFinal); + object->derivedFinal = NULL; + } + if (object->sculpt->pbvh) { + BKE_pbvh_free(object->sculpt->pbvh); + object->sculpt->pbvh = NULL; + } + + sculptsession_bm_to_me_update_data_only(object, false); + + /* In contrast with sculptsession_bm_to_me no need in + * DAG tag update here - derived mesh was freed and + * old pointers are nowhere stored. + */ + } + } +} + +void free_sculptsession(Object *ob) +{ + if (ob && ob->sculpt) { + SculptSession *ss = ob->sculpt; + DerivedMesh *dm = ob->derivedFinal; + + if (ss->bm) { + sculptsession_bm_to_me(ob, TRUE); + BM_mesh_free(ss->bm); + } + + if (ss->pbvh) + BKE_pbvh_free(ss->pbvh); + if (ss->bm_log) + BM_log_free(ss->bm_log); + + if (dm && dm->getPBVH) + dm->getPBVH(NULL, dm); /* signal to clear */ + + if (ss->texcache) + MEM_freeN(ss->texcache); + + if (ss->tex_pool) + BKE_image_pool_free(ss->tex_pool); + + if (ss->layer_co) + MEM_freeN(ss->layer_co); + + if (ss->orig_cos) + MEM_freeN(ss->orig_cos); + if (ss->deform_cos) + MEM_freeN(ss->deform_cos); + if (ss->deform_imats) + MEM_freeN(ss->deform_imats); + + MEM_freeN(ss); + + ob->sculpt = NULL; + } +} |