2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2006 by Nicholas Bishop
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
27 * Implements the Sculpt Mode tools
31 /** \file blender/editors/sculpt_paint/sculpt_undo.c
37 #include "MEM_guardedalloc.h"
40 #include "BLI_utildefines.h"
41 #include "BLI_string.h"
42 #include "BLI_listbase.h"
43 #include "BLI_ghash.h"
44 #include "BLI_threads.h"
46 #include "DNA_meshdata_types.h"
47 #include "DNA_object_types.h"
48 #include "DNA_scene_types.h"
49 #include "DNA_mesh_types.h"
52 #include "BKE_cdderivedmesh.h"
53 #include "BKE_context.h"
54 #include "BKE_depsgraph.h"
55 #include "BKE_modifier.h"
56 #include "BKE_multires.h"
57 #include "BKE_paint.h"
60 #include "BKE_subsurf.h"
65 #include "GPU_buffers.h"
67 #include "ED_sculpt.h"
69 #include "paint_intern.h"
70 #include "sculpt_intern.h"
72 /************************** Undo *************************/
74 static void update_cb(PBVHNode *node, void *rebuild)
76 BKE_pbvh_node_mark_update(node);
77 if (*((int *)rebuild))
78 BKE_pbvh_node_mark_rebuild_draw(node);
79 BKE_pbvh_node_fully_hidden_set(node, 0);
82 static void sculpt_undo_restore_deformed(const SculptSession *ss,
83 SculptUndoNode *unode,
84 int uindex, int oindex,
88 swap_v3_v3(coord, unode->orig_co[uindex]);
89 copy_v3_v3(unode->co[uindex], ss->deform_cos[oindex]);
92 swap_v3_v3(coord, unode->co[uindex]);
96 static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNode *unode)
98 Scene *scene = CTX_data_scene(C);
99 Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
100 Object *ob = CTX_data_active_object(C);
101 SculptSession *ss = ob->sculpt;
105 if (unode->maxvert) {
106 /* regular mesh restore */
108 if (ss->kb && strcmp(ss->kb->name, unode->shapeName)) {
109 /* shape key has been changed before calling undo operator */
111 Key *key = BKE_key_from_object(ob);
112 KeyBlock *kb = key ? BKE_keyblock_find_name(key, unode->shapeName) : NULL;
115 ob->shapenr = BLI_findindex(&key->block, kb) + 1;
117 sculpt_update_mesh_elements(scene, sd, ob, 0, false);
118 WM_event_add_notifier(C, NC_OBJECT | ND_DATA, ob);
121 /* key has been removed -- skip this undo node */
126 index = unode->index;
131 vertCos = BKE_key_convert_to_vertcos(ob, ss->kb);
133 for (i = 0; i < unode->totvert; i++) {
134 if (ss->modifiers_active) {
135 sculpt_undo_restore_deformed(ss, unode, i, index[i], vertCos[index[i]]);
138 if (unode->orig_co) swap_v3_v3(vertCos[index[i]], unode->orig_co[i]);
139 else swap_v3_v3(vertCos[index[i]], unode->co[i]);
143 /* propagate new coords to keyblock */
144 sculpt_vertcos_to_key(ob, ss->kb, vertCos);
146 /* pbvh uses it's own mvert array, so coords should be */
147 /* propagated to pbvh here */
148 BKE_pbvh_apply_vertCos(ss->pbvh, vertCos);
153 for (i = 0; i < unode->totvert; i++) {
154 if (ss->modifiers_active) {
155 sculpt_undo_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co);
158 if (unode->orig_co) swap_v3_v3(mvert[index[i]].co, unode->orig_co[i]);
159 else swap_v3_v3(mvert[index[i]].co, unode->co[i]);
161 mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
165 else if (unode->maxgrid && dm->getGridData) {
166 /* multires restore */
167 CCGElem **grids, *grid;
172 grids = dm->getGridData(dm);
173 gridsize = dm->getGridSize(dm);
174 dm->getGridKey(dm, &key);
177 for (j = 0; j < unode->totgrid; j++) {
178 grid = grids[unode->grids[j]];
180 for (i = 0; i < gridsize * gridsize; i++, co++)
181 swap_v3_v3(CCG_elem_offset_co(&key, grid, i), co[0]);
188 static int sculpt_undo_restore_hidden(bContext *C, DerivedMesh *dm,
189 SculptUndoNode *unode)
191 Object *ob = CTX_data_active_object(C);
192 SculptSession *ss = ob->sculpt;
195 if (unode->maxvert) {
196 MVert *mvert = ss->mvert;
198 for (i = 0; i < unode->totvert; i++) {
199 MVert *v = &mvert[unode->index[i]];
200 int uval = BLI_BITMAP_GET(unode->vert_hidden, i);
202 BLI_BITMAP_MODIFY(unode->vert_hidden, i,
209 v->flag |= ME_VERT_PBVH_UPDATE;
212 else if (unode->maxgrid && dm->getGridData) {
213 BLI_bitmap **grid_hidden = dm->getGridHidden(dm);
215 for (i = 0; i < unode->totgrid; i++) {
217 unode->grid_hidden[i],
218 grid_hidden[unode->grids[i]]);
226 static int sculpt_undo_restore_mask(bContext *C, DerivedMesh *dm, SculptUndoNode *unode)
228 Object *ob = CTX_data_active_object(C);
229 SculptSession *ss = ob->sculpt;
234 if (unode->maxvert) {
235 /* regular mesh restore */
237 index = unode->index;
241 for (i = 0; i < unode->totvert; i++) {
242 SWAP(float, vmask[index[i]], unode->mask[i]);
243 mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
246 else if (unode->maxgrid && dm->getGridData) {
247 /* multires restore */
248 CCGElem **grids, *grid;
253 grids = dm->getGridData(dm);
254 gridsize = dm->getGridSize(dm);
255 dm->getGridKey(dm, &key);
258 for (j = 0; j < unode->totgrid; j++) {
259 grid = grids[unode->grids[j]];
261 for (i = 0; i < gridsize * gridsize; i++, mask++)
262 SWAP(float, *CCG_elem_offset_mask(&key, grid, i), *mask);
269 static void sculpt_undo_bmesh_restore_generic(bContext *C,
270 SculptUndoNode *unode,
274 if (unode->applied) {
275 BM_log_undo(ss->bm, ss->bm_log);
276 unode->applied = false;
279 BM_log_redo(ss->bm, ss->bm_log);
280 unode->applied = true;
283 if (ELEM(unode->type, SCULPT_UNDO_MASK, SCULPT_UNDO_MASK)) {
288 Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
293 BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
295 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP)
296 for (i = 0; i < totnode; i++) {
297 BKE_pbvh_node_mark_redraw(nodes[i]);
304 sculpt_pbvh_clear(ob);
308 /* Create empty sculpt BMesh and enable logging */
309 static void sculpt_undo_bmesh_enable(Object *ob,
310 SculptUndoNode *unode)
312 SculptSession *ss = ob->sculpt;
315 sculpt_pbvh_clear(ob);
317 /* Create empty BMesh and enable logging */
318 ss->bm = BM_mesh_create(&bm_mesh_allocsize_default);
319 BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK);
320 sculpt_dyntopo_node_layers_add(ss);
321 me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY;
323 /* Restore the BMLog using saved entries */
324 ss->bm_log = BM_log_from_existing_entries_create(ss->bm,
328 static void sculpt_undo_bmesh_restore_begin(bContext *C,
329 SculptUndoNode *unode,
333 if (unode->applied) {
334 sculpt_dynamic_topology_disable(C, unode);
335 unode->applied = false;
338 sculpt_undo_bmesh_enable(ob, unode);
340 /* Restore the mesh from the first log entry */
341 BM_log_redo(ss->bm, ss->bm_log);
343 unode->applied = true;
347 static void sculpt_undo_bmesh_restore_end(bContext *C,
348 SculptUndoNode *unode,
352 if (unode->applied) {
353 sculpt_undo_bmesh_enable(ob, unode);
355 /* Restore the mesh from the last log entry */
356 BM_log_undo(ss->bm, ss->bm_log);
358 unode->applied = false;
361 /* Disable dynamic topology sculpting */
362 sculpt_dynamic_topology_disable(C, NULL);
363 unode->applied = true;
367 /* Handle all dynamic-topology updates
369 * Returns true if this was a dynamic-topology undo step, otherwise
370 * returns false to indicate the non-dyntopo code should run. */
371 static int sculpt_undo_bmesh_restore(bContext *C,
372 SculptUndoNode *unode,
376 switch (unode->type) {
377 case SCULPT_UNDO_DYNTOPO_BEGIN:
378 sculpt_undo_bmesh_restore_begin(C, unode, ob, ss);
381 case SCULPT_UNDO_DYNTOPO_END:
382 sculpt_undo_bmesh_restore_end(C, unode, ob, ss);
387 sculpt_undo_bmesh_restore_generic(C, unode, ob, ss);
396 static void sculpt_undo_restore(bContext *C, ListBase *lb)
398 Scene *scene = CTX_data_scene(C);
399 Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
400 Object *ob = CTX_data_active_object(C);
402 SculptSession *ss = ob->sculpt;
403 SculptUndoNode *unode;
404 bool update = false, rebuild = false;
405 bool need_mask = false;
407 for (unode = lb->first; unode; unode = unode->next) {
408 if (strcmp(unode->idname, ob->id.name) == 0) {
409 if (unode->type == SCULPT_UNDO_MASK) {
410 /* is possible that we can't do the mask undo (below)
411 * because of the vertex count */
418 sculpt_update_mesh_elements(scene, sd, ob, 0, need_mask);
420 /* call _after_ sculpt_update_mesh_elements() which may update 'ob->derivedFinal' */
421 dm = mesh_get_derived_final(scene, ob, 0);
423 if (lb->first && sculpt_undo_bmesh_restore(C, lb->first, ob, ss))
426 for (unode = lb->first; unode; unode = unode->next) {
427 if (!(strcmp(unode->idname, ob->id.name) == 0))
430 /* check if undo data matches current data well enough to
432 if (unode->maxvert) {
433 if (ss->totvert != unode->maxvert)
436 else if (unode->maxgrid && dm->getGridData) {
437 if ((dm->getNumGrids(dm) != unode->maxgrid) ||
438 (dm->getGridSize(dm) != unode->gridsize))
444 switch (unode->type) {
445 case SCULPT_UNDO_COORDS:
446 if (sculpt_undo_restore_coords(C, dm, unode))
449 case SCULPT_UNDO_HIDDEN:
450 if (sculpt_undo_restore_hidden(C, dm, unode))
453 case SCULPT_UNDO_MASK:
454 if (sculpt_undo_restore_mask(C, dm, unode))
458 case SCULPT_UNDO_DYNTOPO_BEGIN:
459 case SCULPT_UNDO_DYNTOPO_END:
460 case SCULPT_UNDO_DYNTOPO_SYMMETRIZE:
461 BLI_assert(!"Dynamic topology should've already been handled");
466 if (update || rebuild) {
468 /* we update all nodes still, should be more clever, but also
469 * needs to work correct when exiting/entering sculpt mode and
470 * the nodes get recreated, though in that case it could do all */
471 BKE_pbvh_search_callback(ss->pbvh, NULL, NULL, update_cb, &rebuild);
472 BKE_pbvh_update(ss->pbvh, PBVH_UpdateBB | PBVH_UpdateOriginalBB | PBVH_UpdateRedraw, NULL);
474 if (sculpt_multires_active(scene, ob)) {
476 multires_mark_as_modified(ob, MULTIRES_HIDDEN_MODIFIED);
478 multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED);
481 tag_update = ((Mesh *)ob->data)->id.us > 1;
483 if (ss->modifiers_active) {
484 Mesh *mesh = ob->data;
485 BKE_mesh_calc_normals_tessface(mesh->mvert, mesh->totvert,
486 mesh->mface, mesh->totface, NULL);
488 free_sculptsession_deformMats(ss);
493 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
496 sculpt_update_object_bounding_box(ob);
499 /* for non-PBVH drawing, need to recreate VBOs */
500 GPU_drawobject_free(ob->derivedFinal);
504 static void sculpt_undo_free(ListBase *lb)
506 SculptUndoNode *unode;
509 for (unode = lb->first; unode; unode = unode->next) {
511 MEM_freeN(unode->co);
513 MEM_freeN(unode->no);
515 MEM_freeN(unode->index);
517 MEM_freeN(unode->grids);
519 MEM_freeN(unode->orig_co);
520 if (unode->vert_hidden)
521 MEM_freeN(unode->vert_hidden);
522 if (unode->grid_hidden) {
523 for (i = 0; i < unode->totgrid; i++) {
524 if (unode->grid_hidden[i])
525 MEM_freeN(unode->grid_hidden[i]);
527 MEM_freeN(unode->grid_hidden);
530 MEM_freeN(unode->mask);
531 if (unode->bm_entry) {
532 BM_log_entry_drop(unode->bm_entry);
534 if (unode->bm_enter_totvert)
535 CustomData_free(&unode->bm_enter_vdata, unode->bm_enter_totvert);
536 if (unode->bm_enter_totedge)
537 CustomData_free(&unode->bm_enter_edata, unode->bm_enter_totedge);
538 if (unode->bm_enter_totloop)
539 CustomData_free(&unode->bm_enter_ldata, unode->bm_enter_totloop);
540 if (unode->bm_enter_totpoly)
541 CustomData_free(&unode->bm_enter_pdata, unode->bm_enter_totpoly);
545 SculptUndoNode *sculpt_undo_get_node(PBVHNode *node)
547 ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH);
553 return BLI_findptr(lb, node, offsetof(SculptUndoNode, node));
556 static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh,
557 SculptUndoNode *unode)
559 PBVHNode *node = unode->node;
560 BLI_bitmap **grid_hidden;
561 int i, *grid_indices, totgrid;
563 grid_hidden = BKE_pbvh_grid_hidden(pbvh);
565 BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid,
566 NULL, NULL, NULL, NULL);
568 unode->grid_hidden = MEM_mapallocN(sizeof(*unode->grid_hidden) * totgrid,
569 "unode->grid_hidden");
571 for (i = 0; i < totgrid; i++) {
572 if (grid_hidden[grid_indices[i]])
573 unode->grid_hidden[i] = MEM_dupallocN(grid_hidden[grid_indices[i]]);
575 unode->grid_hidden[i] = NULL;
579 static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node,
582 ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH);
583 SculptUndoNode *unode;
584 SculptSession *ss = ob->sculpt;
585 int totvert, allvert, totgrid, maxgrid, gridsize, *grids;
587 unode = MEM_callocN(sizeof(SculptUndoNode), "SculptUndoNode");
588 BLI_strncpy(unode->idname, ob->id.name, sizeof(unode->idname));
593 BKE_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert);
594 BKE_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
595 &maxgrid, &gridsize, NULL, NULL);
597 unode->totvert = totvert;
602 /* we will use this while sculpting, is mapalloc slow to access then? */
604 /* general TODO, fix count_alloc */
606 case SCULPT_UNDO_COORDS:
607 unode->co = MEM_mapallocN(sizeof(float) * 3 * allvert, "SculptUndoNode.co");
608 unode->no = MEM_mapallocN(sizeof(short) * 3 * allvert, "SculptUndoNode.no");
609 undo_paint_push_count_alloc(UNDO_PAINT_MESH,
612 sizeof(int)) * allvert);
614 case SCULPT_UNDO_HIDDEN:
616 sculpt_undo_alloc_and_store_hidden(ss->pbvh, unode);
618 unode->vert_hidden = BLI_BITMAP_NEW(allvert, "SculptUndoNode.vert_hidden");
621 case SCULPT_UNDO_MASK:
622 unode->mask = MEM_mapallocN(sizeof(float) * allvert, "SculptUndoNode.mask");
623 undo_paint_push_count_alloc(UNDO_PAINT_MESH, (sizeof(float) * sizeof(int)) * allvert);
625 case SCULPT_UNDO_DYNTOPO_BEGIN:
626 case SCULPT_UNDO_DYNTOPO_END:
627 case SCULPT_UNDO_DYNTOPO_SYMMETRIZE:
628 BLI_assert(!"Dynamic topology should've already been handled");
632 BLI_addtail(lb, unode);
636 unode->maxgrid = maxgrid;
637 unode->totgrid = totgrid;
638 unode->gridsize = gridsize;
639 unode->grids = MEM_mapallocN(sizeof(int) * totgrid, "SculptUndoNode.grids");
643 unode->maxvert = ss->totvert;
644 unode->index = MEM_mapallocN(sizeof(int) * allvert, "SculptUndoNode.index");
647 if (ss->modifiers_active)
648 unode->orig_co = MEM_callocN(allvert * sizeof(*unode->orig_co), "undoSculpt orig_cos");
653 static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode)
655 SculptSession *ss = ob->sculpt;
658 BKE_pbvh_vertex_iter_begin(ss->pbvh, unode->node, vd, PBVH_ITER_ALL)
660 copy_v3_v3(unode->co[vd.i], vd.co);
661 if (vd.no) copy_v3_v3_short(unode->no[vd.i], vd.no);
662 else normal_float_to_short_v3(unode->no[vd.i], vd.fno);
664 if (ss->modifiers_active)
665 copy_v3_v3(unode->orig_co[vd.i], ss->orig_cos[unode->index[vd.i]]);
667 BKE_pbvh_vertex_iter_end;
670 static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode)
672 PBVH *pbvh = ob->sculpt->pbvh;
673 PBVHNode *node = unode->node;
676 /* already stored during allocation */
680 int *vert_indices, allvert;
683 BKE_pbvh_node_num_verts(pbvh, node, NULL, &allvert);
684 BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert);
685 for (i = 0; i < allvert; i++) {
686 BLI_BITMAP_MODIFY(unode->vert_hidden, i,
687 mvert[vert_indices[i]].flag & ME_HIDE);
692 static void sculpt_undo_store_mask(Object *ob, SculptUndoNode *unode)
694 SculptSession *ss = ob->sculpt;
697 BKE_pbvh_vertex_iter_begin(ss->pbvh, unode->node, vd, PBVH_ITER_ALL)
699 unode->mask[vd.i] = *vd.mask;
701 BKE_pbvh_vertex_iter_end;
704 static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob,
708 ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH);
709 SculptUndoNode *unode = lb->first;
710 SculptSession *ss = ob->sculpt;
714 unode = MEM_callocN(sizeof(*unode), __func__);
716 BLI_strncpy(unode->idname, ob->id.name, sizeof(unode->idname));
718 unode->applied = true;
720 if (type == SCULPT_UNDO_DYNTOPO_END) {
721 unode->bm_entry = BM_log_entry_add(ss->bm_log);
722 BM_log_before_all_removed(ss->bm, ss->bm_log);
724 else if (type == SCULPT_UNDO_DYNTOPO_BEGIN) {
727 /* Store a copy of the mesh's current vertices, loops, and
728 * polys. A full copy like this is needed because entering
729 * dynamic-topology immediately does topological edits
730 * (converting polys to triangles) that the BMLog can't
731 * fully restore from */
732 CustomData_copy(&me->vdata, &unode->bm_enter_vdata, CD_MASK_MESH,
733 CD_DUPLICATE, me->totvert);
734 CustomData_copy(&me->edata, &unode->bm_enter_edata, CD_MASK_MESH,
735 CD_DUPLICATE, me->totedge);
736 CustomData_copy(&me->ldata, &unode->bm_enter_ldata, CD_MASK_MESH,
737 CD_DUPLICATE, me->totloop);
738 CustomData_copy(&me->pdata, &unode->bm_enter_pdata, CD_MASK_MESH,
739 CD_DUPLICATE, me->totpoly);
740 unode->bm_enter_totvert = me->totvert;
741 unode->bm_enter_totedge = me->totedge;
742 unode->bm_enter_totloop = me->totloop;
743 unode->bm_enter_totpoly = me->totpoly;
745 unode->bm_entry = BM_log_entry_add(ss->bm_log);
746 BM_log_all_added(ss->bm, ss->bm_log);
749 unode->bm_entry = BM_log_entry_add(ss->bm_log);
752 BLI_addtail(lb, unode);
757 case SCULPT_UNDO_COORDS:
758 case SCULPT_UNDO_MASK:
759 /* Before any vertex values get modified, ensure their
760 * original positions are logged */
761 BKE_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_ALL) {
762 BM_log_vert_before_modified(ss->bm_log, vd.bm_vert, vd.cd_vert_mask_offset);
764 BKE_pbvh_vertex_iter_end;
767 case SCULPT_UNDO_HIDDEN:
769 GSetIterator gs_iter;
770 GSet *faces = BKE_pbvh_bmesh_node_faces(node);
771 BKE_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_ALL) {
772 BM_log_vert_before_modified(ss->bm_log, vd.bm_vert, vd.cd_vert_mask_offset);
774 BKE_pbvh_vertex_iter_end;
776 GSET_ITER (gs_iter, faces) {
777 BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
778 BM_log_face_modified(ss->bm_log, f);
783 case SCULPT_UNDO_DYNTOPO_BEGIN:
784 case SCULPT_UNDO_DYNTOPO_END:
785 case SCULPT_UNDO_DYNTOPO_SYMMETRIZE:
793 SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node,
796 SculptSession *ss = ob->sculpt;
797 SculptUndoNode *unode;
799 /* list is manipulated by multiple threads, so we lock */
800 BLI_lock_thread(LOCK_CUSTOM1);
804 SCULPT_UNDO_DYNTOPO_BEGIN,
805 SCULPT_UNDO_DYNTOPO_END))
807 /* Dynamic topology stores only one undo node per stroke,
808 * regardless of the number of PBVH nodes modified */
809 unode = sculpt_undo_bmesh_push(ob, node, type);
810 BLI_unlock_thread(LOCK_CUSTOM1);
813 else if ((unode = sculpt_undo_get_node(node))) {
814 BLI_unlock_thread(LOCK_CUSTOM1);
818 unode = sculpt_undo_alloc_node(ob, node, type);
820 BLI_unlock_thread(LOCK_CUSTOM1);
822 /* copy threaded, hopefully this is the performance critical part */
826 BKE_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
827 NULL, NULL, NULL, NULL);
828 memcpy(unode->grids, grids, sizeof(int) * totgrid);
831 int *vert_indices, allvert;
832 BKE_pbvh_node_num_verts(ss->pbvh, node, NULL, &allvert);
833 BKE_pbvh_node_get_verts(ss->pbvh, node, &vert_indices, NULL);
834 memcpy(unode->index, vert_indices, sizeof(int) * unode->totvert);
838 case SCULPT_UNDO_COORDS:
839 sculpt_undo_store_coords(ob, unode);
841 case SCULPT_UNDO_HIDDEN:
842 sculpt_undo_store_hidden(ob, unode);
844 case SCULPT_UNDO_MASK:
845 sculpt_undo_store_mask(ob, unode);
847 case SCULPT_UNDO_DYNTOPO_BEGIN:
848 case SCULPT_UNDO_DYNTOPO_END:
849 case SCULPT_UNDO_DYNTOPO_SYMMETRIZE:
850 BLI_assert(!"Dynamic topology should've already been handled");
854 /* store active shape key */
855 if (ss->kb) BLI_strncpy(unode->shapeName, ss->kb->name, sizeof(ss->kb->name));
856 else unode->shapeName[0] = '\0';
861 void sculpt_undo_push_begin(const char *name)
863 ED_undo_paint_push_begin(UNDO_PAINT_MESH, name,
864 sculpt_undo_restore, sculpt_undo_free);
867 void sculpt_undo_push_end(void)
869 ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH);
870 SculptUndoNode *unode;
872 /* we don't need normals in the undo stack */
873 for (unode = lb->first; unode; unode = unode->next) {
875 MEM_freeN(unode->no);
880 BKE_pbvh_node_layer_disp_free(unode->node);
883 ED_undo_paint_push_end(UNDO_PAINT_MESH);