diff options
Diffstat (limited to 'source/blender/editors/sculpt_paint/sculpt_undo.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_undo.c | 212 |
1 files changed, 106 insertions, 106 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index 73fa546b357..5378ce7872a 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -71,7 +71,7 @@ static void update_cb(PBVHNode *node, void *rebuild) { BLI_pbvh_node_mark_update(node); - if (*((int*)rebuild)) + if (*((int *)rebuild)) BLI_pbvh_node_mark_rebuild_draw(node); BLI_pbvh_node_fully_hidden_set(node, 0); } @@ -89,10 +89,10 @@ static void sculpt_undo_restore_deformed(SculptSession *ss, SculptUndoNode *unod static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNode *unode) { - Scene *scene= CTX_data_scene(C); - Sculpt *sd= CTX_data_tool_settings(C)->sculpt; - Object *ob= CTX_data_active_object(C); - SculptSession *ss= ob->sculpt; + Scene *scene = CTX_data_scene(C); + Sculpt *sd = CTX_data_tool_settings(C)->sculpt; + Object *ob = CTX_data_active_object(C); + SculptSession *ss = ob->sculpt; MVert *mvert; int *index, i, j; @@ -102,14 +102,14 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo if (ss->kb && strcmp(ss->kb->name, unode->shapeName)) { /* shape key has been changed before calling undo operator */ - Key *key= ob_get_key(ob); - KeyBlock *kb= key_get_named_keyblock(key, unode->shapeName); + Key *key = ob_get_key(ob); + KeyBlock *kb = key_get_named_keyblock(key, unode->shapeName); if (kb) { - ob->shapenr= BLI_findindex(&key->block, kb) + 1; + ob->shapenr = BLI_findindex(&key->block, kb) + 1; sculpt_update_mesh_elements(scene, sd, ob, 0); - WM_event_add_notifier(C, NC_OBJECT|ND_DATA, ob); + WM_event_add_notifier(C, NC_OBJECT | ND_DATA, ob); } else { /* key has been removed -- skip this undo node */ @@ -117,14 +117,14 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo } } - index= unode->index; - mvert= ss->mvert; + index = unode->index; + mvert = ss->mvert; if (ss->kb) { float (*vertCos)[3]; - vertCos= key_to_vertcos(ob, ss->kb); + vertCos = key_to_vertcos(ob, ss->kb); - for (i=0; i<unode->totvert; i++) { + for (i = 0; i < unode->totvert; i++) { if (ss->modifiers_active) sculpt_undo_restore_deformed(ss, unode, i, index[i], vertCos[index[i]]); else { if (unode->orig_co) swap_v3_v3(vertCos[index[i]], unode->orig_co[i]); @@ -142,7 +142,7 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo MEM_freeN(vertCos); } else { - for (i=0; i<unode->totvert; i++) { + for (i = 0; i < unode->totvert; i++) { if (ss->modifiers_active) sculpt_undo_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co); else { if (unode->orig_co) swap_v3_v3(mvert[index[i]].co, unode->orig_co[i]); @@ -158,14 +158,14 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo float (*co)[3]; int gridsize; - grids= dm->getGridData(dm); - gridsize= dm->getGridSize(dm); + grids = dm->getGridData(dm); + gridsize = dm->getGridSize(dm); co = unode->co; - for (j=0; j<unode->totgrid; j++) { - grid= grids[unode->grids[j]]; + for (j = 0; j < unode->totgrid; j++) { + grid = grids[unode->grids[j]]; - for (i=0; i<gridsize*gridsize; i++, co++) + for (i = 0; i < gridsize * gridsize; i++, co++) swap_v3_v3(grid[i].co, co[0]); } } @@ -174,21 +174,21 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo } static int sculpt_undo_restore_hidden(bContext *C, DerivedMesh *dm, - SculptUndoNode *unode) + SculptUndoNode *unode) { Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; int i; if (unode->maxvert) { - MVert *mvert= ss->mvert; + MVert *mvert = ss->mvert; - for (i=0; i<unode->totvert; i++) { + for (i = 0; i < unode->totvert; i++) { MVert *v = &mvert[unode->index[i]]; - int uval= BLI_BITMAP_GET(unode->vert_hidden, i); + int uval = BLI_BITMAP_GET(unode->vert_hidden, i); BLI_BITMAP_MODIFY(unode->vert_hidden, i, - v->flag & ME_HIDE); + v->flag & ME_HIDE); if (uval) v->flag |= ME_HIDE; else @@ -200,10 +200,10 @@ static int sculpt_undo_restore_hidden(bContext *C, DerivedMesh *dm, else if (unode->maxgrid && dm->getGridData) { BLI_bitmap *grid_hidden = dm->getGridHidden(dm); - for (i=0; i<unode->totgrid; i++) { + for (i = 0; i < unode->totgrid; i++) { SWAP(BLI_bitmap, - unode->grid_hidden[i], - grid_hidden[unode->grids[i]]); + unode->grid_hidden[i], + grid_hidden[unode->grids[i]]); } } @@ -220,12 +220,12 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb) SculptSession *ss = ob->sculpt; SculptUndoNode *unode; MultiresModifierData *mmd; - int update= 0, rebuild= 1; + int update = 0, rebuild = 1; sculpt_update_mesh_elements(scene, sd, ob, 0); - for (unode=lb->first; unode; unode=unode->next) { - if (!(strcmp(unode->idname, ob->id.name)==0)) + for (unode = lb->first; unode; unode = unode->next) { + if (!(strcmp(unode->idname, ob->id.name) == 0)) continue; /* check if undo data matches current data well enough to @@ -236,48 +236,48 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb) } else if (unode->maxgrid && dm->getGridData) { if ((dm->getNumGrids(dm) != unode->maxgrid) || - (dm->getGridSize(dm) != unode->gridsize)) + (dm->getGridSize(dm) != unode->gridsize)) continue; } else { continue; } - switch(unode->type) { - case SCULPT_UNDO_COORDS: - if (sculpt_undo_restore_coords(C, dm, unode)) - update= 1; - break; - case SCULPT_UNDO_HIDDEN: - if (sculpt_undo_restore_hidden(C, dm, unode)) - rebuild= 1; - break; + switch (unode->type) { + case SCULPT_UNDO_COORDS: + if (sculpt_undo_restore_coords(C, dm, unode)) + update = 1; + break; + case SCULPT_UNDO_HIDDEN: + if (sculpt_undo_restore_hidden(C, dm, unode)) + rebuild = 1; + break; } } if (update || rebuild) { - int tag_update= 0; + int tag_update = 0; /* we update all nodes still, should be more clever, but also * needs to work correct when exiting/entering sculpt mode and * the nodes get recreated, though in that case it could do all */ BLI_pbvh_search_callback(ss->pbvh, NULL, NULL, update_cb, &rebuild); - BLI_pbvh_update(ss->pbvh, PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw, NULL); + BLI_pbvh_update(ss->pbvh, PBVH_UpdateBB | PBVH_UpdateOriginalBB | PBVH_UpdateRedraw, NULL); - if ((mmd=sculpt_multires_active(scene, ob))) { + if ((mmd = sculpt_multires_active(scene, ob))) { if (rebuild) multires_mark_as_modified(ob, MULTIRES_HIDDEN_MODIFIED); else multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); } - tag_update= ((Mesh*)ob->data)->id.us > 1; + tag_update = ((Mesh *)ob->data)->id.us > 1; if (ss->modifiers_active) { - Mesh *mesh= ob->data; + Mesh *mesh = ob->data; mesh_calc_normals_mapping(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL); free_sculptsession_deformMats(ss); - tag_update|= 1; + tag_update |= 1; } if (tag_update) @@ -293,7 +293,7 @@ static void sculpt_undo_free(ListBase *lb) SculptUndoNode *unode; int i; - for (unode=lb->first; unode; unode=unode->next) { + for (unode = lb->first; unode; unode = unode->next) { if (unode->co) MEM_freeN(unode->co); if (unode->no) @@ -309,7 +309,7 @@ static void sculpt_undo_free(ListBase *lb) if (unode->vert_hidden) MEM_freeN(unode->vert_hidden); if (unode->grid_hidden) { - for (i=0; i<unode->totgrid; i++) { + for (i = 0; i < unode->totgrid; i++) { if (unode->grid_hidden[i]) MEM_freeN(unode->grid_hidden[i]); } @@ -320,13 +320,13 @@ static void sculpt_undo_free(ListBase *lb) SculptUndoNode *sculpt_undo_get_node(PBVHNode *node) { - ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH); + ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH); SculptUndoNode *unode; if (!lb) return NULL; - for (unode=lb->first; unode; unode=unode->next) + for (unode = lb->first; unode; unode = unode->next) if (unode->node == node) return unode; @@ -334,19 +334,19 @@ SculptUndoNode *sculpt_undo_get_node(PBVHNode *node) } static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh, - SculptUndoNode *unode) + SculptUndoNode *unode) { - PBVHNode *node= unode->node; + PBVHNode *node = unode->node; BLI_bitmap *grid_hidden; int i, *grid_indices, totgrid; - grid_hidden= BLI_pbvh_grid_hidden(pbvh); + grid_hidden = BLI_pbvh_grid_hidden(pbvh); BLI_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL); - unode->grid_hidden= MEM_mapallocN(sizeof(BLI_bitmap) * totgrid, - "unode->grid_hidden"); + unode->grid_hidden = MEM_mapallocN(sizeof(BLI_bitmap) * totgrid, + "unode->grid_hidden"); for (i = 0; i < totgrid; i++) { if (grid_hidden[grid_indices[i]]) @@ -357,59 +357,59 @@ static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh, } static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, - SculptUndoType type) + SculptUndoType type) { - ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH); + ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH); SculptUndoNode *unode; - SculptSession *ss= ob->sculpt; + SculptSession *ss = ob->sculpt; int totvert, allvert, totgrid, maxgrid, gridsize, *grids; - unode= MEM_callocN(sizeof(SculptUndoNode), "SculptUndoNode"); + unode = MEM_callocN(sizeof(SculptUndoNode), "SculptUndoNode"); BLI_strncpy(unode->idname, ob->id.name, sizeof(unode->idname)); - unode->type= type; - unode->node= node; + unode->type = type; + unode->node = node; BLI_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert); BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid, - &maxgrid, &gridsize, NULL, NULL); + &maxgrid, &gridsize, NULL, NULL); - unode->totvert= totvert; + unode->totvert = totvert; /* we will use this while sculpting, is mapalloc slow to access then? */ /* general TODO, fix count_alloc */ - switch(type) { - case SCULPT_UNDO_COORDS: - unode->co= MEM_mapallocN(sizeof(float)*3*allvert, "SculptUndoNode.co"); - unode->no= MEM_mapallocN(sizeof(short)*3*allvert, "SculptUndoNode.no"); - undo_paint_push_count_alloc(UNDO_PAINT_MESH, (sizeof(float)*3 + sizeof(short)*3 + sizeof(int))*allvert); - break; - case SCULPT_UNDO_HIDDEN: - if (maxgrid) - sculpt_undo_alloc_and_store_hidden(ss->pbvh, unode); - else - unode->vert_hidden= BLI_BITMAP_NEW(allvert, "SculptUndoNode.vert_hidden"); + switch (type) { + case SCULPT_UNDO_COORDS: + unode->co = MEM_mapallocN(sizeof(float) * 3 * allvert, "SculptUndoNode.co"); + unode->no = MEM_mapallocN(sizeof(short) * 3 * allvert, "SculptUndoNode.no"); + undo_paint_push_count_alloc(UNDO_PAINT_MESH, (sizeof(float) * 3 + sizeof(short) * 3 + sizeof(int)) * allvert); + break; + case SCULPT_UNDO_HIDDEN: + if (maxgrid) + sculpt_undo_alloc_and_store_hidden(ss->pbvh, unode); + else + unode->vert_hidden = BLI_BITMAP_NEW(allvert, "SculptUndoNode.vert_hidden"); - break; + break; } BLI_addtail(lb, unode); if (maxgrid) { /* multires */ - unode->maxgrid= maxgrid; - unode->totgrid= totgrid; - unode->gridsize= gridsize; - unode->grids= MEM_mapallocN(sizeof(int)*totgrid, "SculptUndoNode.grids"); + unode->maxgrid = maxgrid; + unode->totgrid = totgrid; + unode->gridsize = gridsize; + unode->grids = MEM_mapallocN(sizeof(int) * totgrid, "SculptUndoNode.grids"); } else { /* regular mesh */ - unode->maxvert= ss->totvert; - unode->index= MEM_mapallocN(sizeof(int)*allvert, "SculptUndoNode.index"); + unode->maxvert = ss->totvert; + unode->index = MEM_mapallocN(sizeof(int) * allvert, "SculptUndoNode.index"); } if (ss->modifiers_active) - unode->orig_co= MEM_callocN(allvert*sizeof(*unode->orig_co), "undoSculpt orig_cos"); + unode->orig_co = MEM_callocN(allvert * sizeof(*unode->orig_co), "undoSculpt orig_cos"); return unode; } @@ -432,12 +432,12 @@ static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode) static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode) { - PBVH *pbvh= ob->sculpt->pbvh; - PBVHNode *node= unode->node; + PBVH *pbvh = ob->sculpt->pbvh; + PBVHNode *node = unode->node; if (unode->grids) { /* already stored during allocation */ - } + } else { MVert *mvert; int *vert_indices, allvert; @@ -447,13 +447,13 @@ static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode) BLI_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert); for (i = 0; i < allvert; i++) { BLI_BITMAP_MODIFY(unode->vert_hidden, i, - mvert[vert_indices[i]].flag & ME_HIDE); + mvert[vert_indices[i]].flag & ME_HIDE); } } } SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node, - SculptUndoType type) + SculptUndoType type) { SculptSession *ss = ob->sculpt; SculptUndoNode *unode; @@ -461,41 +461,41 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node, /* list is manipulated by multiple threads, so we lock */ BLI_lock_thread(LOCK_CUSTOM1); - if ((unode= sculpt_undo_get_node(node))) { + if ((unode = sculpt_undo_get_node(node))) { BLI_unlock_thread(LOCK_CUSTOM1); return unode; } - unode= sculpt_undo_alloc_node(ob, node, type); + unode = sculpt_undo_alloc_node(ob, node, type); BLI_unlock_thread(LOCK_CUSTOM1); /* copy threaded, hopefully this is the performance critical part */ - switch(type) { - case SCULPT_UNDO_COORDS: - sculpt_undo_store_coords(ob, unode); - break; - case SCULPT_UNDO_HIDDEN: - sculpt_undo_store_hidden(ob, unode); - break; + switch (type) { + case SCULPT_UNDO_COORDS: + sculpt_undo_store_coords(ob, unode); + break; + case SCULPT_UNDO_HIDDEN: + sculpt_undo_store_hidden(ob, unode); + break; } if (unode->grids) { int totgrid, *grids; BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid, - NULL, NULL, NULL, NULL); - memcpy(unode->grids, grids, sizeof(int)*totgrid); + NULL, NULL, NULL, NULL); + memcpy(unode->grids, grids, sizeof(int) * totgrid); } else { int *vert_indices, allvert; BLI_pbvh_node_num_verts(ss->pbvh, node, NULL, &allvert); BLI_pbvh_node_get_verts(ss->pbvh, node, &vert_indices, NULL); - memcpy(unode->index, vert_indices, sizeof(int)*unode->totvert); + memcpy(unode->index, vert_indices, sizeof(int) * unode->totvert); } /* store active shape key */ if (ss->kb) BLI_strncpy(unode->shapeName, ss->kb->name, sizeof(ss->kb->name)); - else unode->shapeName[0]= '\0'; + else unode->shapeName[0] = '\0'; return unode; } @@ -503,24 +503,24 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node, void sculpt_undo_push_begin(const char *name) { undo_paint_push_begin(UNDO_PAINT_MESH, name, - sculpt_undo_restore, sculpt_undo_free); + sculpt_undo_restore, sculpt_undo_free); } void sculpt_undo_push_end(void) { - ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH); + ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH); SculptUndoNode *unode; /* we don't need normals in the undo stack */ - for (unode=lb->first; unode; unode=unode->next) { + for (unode = lb->first; unode; unode = unode->next) { if (unode->no) { MEM_freeN(unode->no); - unode->no= NULL; + unode->no = NULL; } if (unode->layer_disp) { MEM_freeN(unode->layer_disp); - unode->layer_disp= NULL; + unode->layer_disp = NULL; } } |