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.
This commit is contained in:
Sergey Sharybin 2013-05-15 08:54:05 +00:00
parent 4fcd44d389
commit 9c510330d9
2 changed files with 117 additions and 114 deletions

@ -87,7 +87,6 @@
#include "BKE_fcurve.h"
#include "BKE_group.h"
#include "BKE_icons.h"
#include "BKE_image.h"
#include "BKE_key.h"
#include "BKE_lamp.h"
#include "BKE_lattice.h"
@ -260,119 +259,6 @@ void BKE_object_free_display(Object *ob)
BKE_displist_free(&ob->disp);
}
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;
}
}
/* do not free object itself */
void BKE_object_free(Object *ob)
{

@ -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;
}
}