Blender  V2.93
editmesh_undo.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "MEM_guardedalloc.h"
22 
23 #include "CLG_log.h"
24 
25 #include "DNA_key_types.h"
26 #include "DNA_layer_types.h"
27 #include "DNA_mesh_types.h"
28 #include "DNA_meshdata_types.h"
29 #include "DNA_object_types.h"
30 #include "DNA_scene_types.h"
31 
32 #include "BLI_array_utils.h"
33 #include "BLI_listbase.h"
34 
35 #include "BKE_context.h"
36 #include "BKE_editmesh.h"
37 #include "BKE_key.h"
38 #include "BKE_layer.h"
39 #include "BKE_lib_id.h"
40 #include "BKE_main.h"
41 #include "BKE_mesh.h"
42 #include "BKE_object.h"
43 #include "BKE_undo_system.h"
44 
45 #include "DEG_depsgraph.h"
46 
47 #include "ED_mesh.h"
48 #include "ED_object.h"
49 #include "ED_undo.h"
50 #include "ED_util.h"
51 
52 #include "WM_api.h"
53 #include "WM_types.h"
54 
55 #define USE_ARRAY_STORE
56 
57 #ifdef USE_ARRAY_STORE
58 // # define DEBUG_PRINT
59 // # define DEBUG_TIME
60 # ifdef DEBUG_TIME
61 # include "PIL_time_utildefines.h"
62 # endif
63 
64 # include "BLI_array_store.h"
65 # include "BLI_array_store_utils.h"
66 /* check on best size later... */
67 # define ARRAY_CHUNK_SIZE 256
68 
69 # define USE_ARRAY_STORE_THREAD
70 #endif
71 
72 #ifdef USE_ARRAY_STORE_THREAD
73 # include "BLI_task.h"
74 #endif
75 
77 static CLG_LogRef LOG = {"ed.undo.mesh"};
78 
79 /* -------------------------------------------------------------------- */
83 #ifdef USE_ARRAY_STORE
84 
85 /* Single linked list of layers stored per type */
86 typedef struct BArrayCustomData {
89  int states_len; /* number of layers for each type */
92 
93 #endif
94 
95 typedef struct UndoMesh {
98 
107  int shapenr;
108 
109 #ifdef USE_ARRAY_STORE
110  /* NULL arrays are considered empty */
111  struct { /* most data is stored as 'custom' data */
115  } store;
116 #endif /* USE_ARRAY_STORE */
117 
118  size_t undo_size;
120 
121 #ifdef USE_ARRAY_STORE
122 
123 /* -------------------------------------------------------------------- */
127 static struct {
129  int users;
130 
131  /* We could have the undo API pass in the previous state, for now store a local list */
133 
134 # ifdef USE_ARRAY_STORE_THREAD
136 # endif
137 
139 
140 static void um_arraystore_cd_compact(struct CustomData *cdata,
141  const size_t data_len,
142  bool create,
143  const BArrayCustomData *bcd_reference,
144  BArrayCustomData **r_bcd_first)
145 {
146  if (data_len == 0) {
147  if (create) {
148  *r_bcd_first = NULL;
149  }
150  }
151 
152  const BArrayCustomData *bcd_reference_current = bcd_reference;
153  BArrayCustomData *bcd = NULL, *bcd_first = NULL, *bcd_prev = NULL;
154  for (int layer_start = 0, layer_end; layer_start < cdata->totlayer; layer_start = layer_end) {
155  const CustomDataType type = cdata->layers[layer_start].type;
156 
157  /* Perform a full copy on dynamic layers.
158  *
159  * Unfortunately we can't compare dynamic layer types as they contain allocated pointers,
160  * which burns CPU cycles looking for duplicate data that doesn't exist.
161  * The array data isn't comparable once copied from the mesh,
162  * this bottlenecks on high poly meshes, see T84114.
163  *
164  * Notes:
165  *
166  * - Ideally the data would be expanded into a format that could be de-duplicated effectively,
167  * this would require a flat representation of each dynamic custom-data layer.
168  *
169  * - The data in the layer could be kept as-is to save on the extra copy,
170  * it would complicate logic in this function.
171  */
172  const bool layer_type_is_dynamic = CustomData_layertype_is_dynamic(type);
173 
174  layer_end = layer_start + 1;
175  while ((layer_end < cdata->totlayer) && (type == cdata->layers[layer_end].type)) {
176  layer_end++;
177  }
178 
179  const int stride = CustomData_sizeof(type);
181  &um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE) :
182  NULL;
183  const int layer_len = layer_end - layer_start;
184 
185  if (create) {
186  if (bcd_reference_current && (bcd_reference_current->type == type)) {
187  /* common case, the reference is aligned */
188  }
189  else {
190  bcd_reference_current = NULL;
191 
192  /* Do a full lookup when unaligned. */
193  if (bcd_reference) {
194  const BArrayCustomData *bcd_iter = bcd_reference;
195  while (bcd_iter) {
196  if (bcd_iter->type == type) {
197  bcd_reference_current = bcd_iter;
198  break;
199  }
200  bcd_iter = bcd_iter->next;
201  }
202  }
203  }
204  }
205 
206  if (create) {
207  bcd = MEM_callocN(sizeof(BArrayCustomData) + (layer_len * sizeof(BArrayState *)), __func__);
208  bcd->next = NULL;
209  bcd->type = type;
210  bcd->states_len = layer_end - layer_start;
211 
212  if (bcd_prev) {
213  bcd_prev->next = bcd;
214  bcd_prev = bcd;
215  }
216  else {
217  bcd_first = bcd;
218  bcd_prev = bcd;
219  }
220  }
221 
222  CustomDataLayer *layer = &cdata->layers[layer_start];
223  for (int i = 0; i < layer_len; i++, layer++) {
224  if (create) {
225  if (layer->data) {
226  BArrayState *state_reference = (bcd_reference_current &&
227  i < bcd_reference_current->states_len) ?
228  bcd_reference_current->states[i] :
229  NULL;
230  /* See comment on `layer_type_is_dynamic` above. */
231  if (layer_type_is_dynamic) {
232  state_reference = NULL;
233  }
234 
236  bs, layer->data, (size_t)data_len * stride, state_reference);
237  }
238  else {
239  bcd->states[i] = NULL;
240  }
241  }
242 
243  if (layer->data) {
244  MEM_freeN(layer->data);
245  layer->data = NULL;
246  }
247  }
248 
249  if (create) {
250  if (bcd_reference_current) {
251  bcd_reference_current = bcd_reference_current->next;
252  }
253  }
254  }
255 
256  if (create) {
257  *r_bcd_first = bcd_first;
258  }
259 }
260 
266  struct CustomData *cdata,
267  const size_t data_len)
268 {
269  CustomDataLayer *layer = cdata->layers;
270  while (bcd) {
271  const int stride = CustomData_sizeof(bcd->type);
272  for (int i = 0; i < bcd->states_len; i++) {
273  BLI_assert(bcd->type == layer->type);
274  if (bcd->states[i]) {
275  size_t state_len;
276  layer->data = BLI_array_store_state_data_get_alloc(bcd->states[i], &state_len);
277  BLI_assert(stride * data_len == state_len);
278  UNUSED_VARS_NDEBUG(stride, data_len);
279  }
280  else {
281  layer->data = NULL;
282  }
283  layer++;
284  }
285  bcd = bcd->next;
286  }
287 }
288 
290 {
291  while (bcd) {
292  BArrayCustomData *bcd_next = bcd->next;
293  const int stride = CustomData_sizeof(bcd->type);
295  for (int i = 0; i < bcd->states_len; i++) {
296  if (bcd->states[i]) {
298  }
299  }
300  MEM_freeN(bcd);
301  bcd = bcd_next;
302  }
303 }
304 
310 static void um_arraystore_compact_ex(UndoMesh *um, const UndoMesh *um_ref, bool create)
311 {
312  Mesh *me = &um->me;
313 
315  &me->vdata, me->totvert, create, um_ref ? um_ref->store.vdata : NULL, &um->store.vdata);
317  &me->edata, me->totedge, create, um_ref ? um_ref->store.edata : NULL, &um->store.edata);
319  &me->ldata, me->totloop, create, um_ref ? um_ref->store.ldata : NULL, &um->store.ldata);
321  &me->pdata, me->totpoly, create, um_ref ? um_ref->store.pdata : NULL, &um->store.pdata);
322 
323  if (me->key && me->key->totkey) {
324  const size_t stride = me->key->elemsize;
326  &um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE) :
327  NULL;
328  if (create) {
329  um->store.keyblocks = MEM_mallocN(me->key->totkey * sizeof(*um->store.keyblocks), __func__);
330  }
331  KeyBlock *keyblock = me->key->block.first;
332  for (int i = 0; i < me->key->totkey; i++, keyblock = keyblock->next) {
333  if (create) {
334  BArrayState *state_reference = (um_ref && um_ref->me.key && (i < um_ref->me.key->totkey)) ?
335  um_ref->store.keyblocks[i] :
336  NULL;
338  bs, keyblock->data, (size_t)keyblock->totelem * stride, state_reference);
339  }
340 
341  if (keyblock->data) {
342  MEM_freeN(keyblock->data);
343  keyblock->data = NULL;
344  }
345  }
346  }
347 
348  if (me->mselect && me->totselect) {
349  BLI_assert(create == (um->store.mselect == NULL));
350  if (create) {
351  BArrayState *state_reference = um_ref ? um_ref->store.mselect : NULL;
352  const size_t stride = sizeof(*me->mselect);
354  &um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE);
356  bs, me->mselect, (size_t)me->totselect * stride, state_reference);
357  }
358 
359  /* keep me->totselect for validation */
360  MEM_freeN(me->mselect);
361  me->mselect = NULL;
362  }
363 
364  if (create) {
365  um_arraystore.users += 1;
366  }
367 
369 }
370 
374 static void um_arraystore_compact(UndoMesh *um, const UndoMesh *um_ref)
375 {
376  um_arraystore_compact_ex(um, um_ref, true);
377 }
378 
379 static void um_arraystore_compact_with_info(UndoMesh *um, const UndoMesh *um_ref)
380 {
381 # ifdef DEBUG_PRINT
382  size_t size_expanded_prev, size_compacted_prev;
384  &um_arraystore.bs_stride, &size_expanded_prev, &size_compacted_prev);
385 # endif
386 
387 # ifdef DEBUG_TIME
388  TIMEIT_START(mesh_undo_compact);
389 # endif
390 
391  um_arraystore_compact(um, um_ref);
392 
393 # ifdef DEBUG_TIME
394  TIMEIT_END(mesh_undo_compact);
395 # endif
396 
397 # ifdef DEBUG_PRINT
398  {
399  size_t size_expanded, size_compacted;
401  &um_arraystore.bs_stride, &size_expanded, &size_compacted);
402 
403  const double percent_total = size_expanded ?
404  (((double)size_compacted / (double)size_expanded) * 100.0) :
405  -1.0;
406 
407  size_t size_expanded_step = size_expanded - size_expanded_prev;
408  size_t size_compacted_step = size_compacted - size_compacted_prev;
409  const double percent_step = size_expanded_step ?
410  (((double)size_compacted_step / (double)size_expanded_step) *
411  100.0) :
412  -1.0;
413 
414  printf("overall memory use: %.8f%% of expanded size\n", percent_total);
415  printf("step memory use: %.8f%% of expanded size\n", percent_step);
416  }
417 # endif
418 }
419 
420 # ifdef USE_ARRAY_STORE_THREAD
421 
422 struct UMArrayData {
424  const UndoMesh *um_ref; /* can be NULL */
425 };
426 static void um_arraystore_compact_cb(TaskPool *__restrict UNUSED(pool), void *taskdata)
427 {
428  struct UMArrayData *um_data = taskdata;
429  um_arraystore_compact_with_info(um_data->um, um_data->um_ref);
430 }
431 
432 # endif /* USE_ARRAY_STORE_THREAD */
433 
438 {
440 }
441 
443 {
444  Mesh *me = &um->me;
445 
446  um_arraystore_cd_expand(um->store.vdata, &me->vdata, me->totvert);
447  um_arraystore_cd_expand(um->store.edata, &me->edata, me->totedge);
449  um_arraystore_cd_expand(um->store.pdata, &me->pdata, me->totpoly);
450 
451  if (um->store.keyblocks) {
452  const size_t stride = me->key->elemsize;
453  KeyBlock *keyblock = me->key->block.first;
454  for (int i = 0; i < me->key->totkey; i++, keyblock = keyblock->next) {
456  size_t state_len;
457  keyblock->data = BLI_array_store_state_data_get_alloc(state, &state_len);
458  BLI_assert(keyblock->totelem == (state_len / stride));
460  }
461  }
462 
463  if (um->store.mselect) {
464  const size_t stride = sizeof(*me->mselect);
466  size_t state_len;
468  BLI_assert(me->totselect == (state_len / stride));
470  }
471 
472  /* not essential, but prevents accidental dangling pointer access */
474 }
475 
477 {
478  Mesh *me = &um->me;
479 
484 
485  if (um->store.keyblocks) {
486  const size_t stride = me->key->elemsize;
488  for (int i = 0; i < me->key->totkey; i++) {
491  }
493  um->store.keyblocks = NULL;
494  }
495 
496  if (um->store.mselect) {
497  const size_t stride = sizeof(*me->mselect);
501  um->store.mselect = NULL;
502  }
503 
504  um_arraystore.users -= 1;
505 
506  BLI_assert(um_arraystore.users >= 0);
507 
508  if (um_arraystore.users == 0) {
509 # ifdef DEBUG_PRINT
510  printf("mesh undo store: freeing all data!\n");
511 # endif
513 
514 # ifdef USE_ARRAY_STORE_THREAD
516  um_arraystore.task_pool = NULL;
517 # endif
518  }
519 }
520 
523 #endif /* USE_ARRAY_STORE */
524 
525 /* for callbacks */
526 /* undo simply makes copies of a bmesh */
528 {
530 #ifdef USE_ARRAY_STORE_THREAD
531  /* changes this waits is low, but must have finished */
532  if (um_arraystore.task_pool) {
534  }
535 #endif
536  /* make sure shape keys work */
537  if (key != NULL) {
538  um->me.key = (Key *)BKE_id_copy_ex(
540  }
541  else {
542  um->me.key = NULL;
543  }
544 
545  /* BM_mesh_validate(em->bm); */ /* for troubleshooting */
546 
548  NULL,
549  em->bm,
550  &um->me,
551  (&(struct BMeshToMeshParams){
552  /* Undo code should not be manipulating 'G_MAIN->object' hooks/vertex-parent. */
553  .calc_object_remap = false,
554  .update_shapekey_indices = false,
555  .cd_mask_extra = {.vmask = CD_MASK_SHAPE_KEYINDEX},
556  }));
557 
558  um->selectmode = em->selectmode;
559  um->shapenr = em->bm->shapenr;
560 
561 #ifdef USE_ARRAY_STORE
562  {
563  /* We could be more clever here,
564  * the previous undo state may be from a separate mesh. */
565  const UndoMesh *um_ref = um_arraystore.local_links.last ?
566  ((LinkData *)um_arraystore.local_links.last)->data :
567  NULL;
568 
569  /* Add ourselves. */
571 
572 # ifdef USE_ARRAY_STORE_THREAD
573  if (um_arraystore.task_pool == NULL) {
575  }
576 
577  struct UMArrayData *um_data = MEM_mallocN(sizeof(*um_data), __func__);
578  um_data->um = um;
579  um_data->um_ref = um_ref;
580 
582 # else
584 # endif
585  }
586 #endif
587 
588  return um;
589 }
590 
591 static void undomesh_to_editmesh(UndoMesh *um, Object *ob, BMEditMesh *em, Key *key)
592 {
593  BMEditMesh *em_tmp;
594  BMesh *bm;
595 
596 #ifdef USE_ARRAY_STORE
597 # ifdef USE_ARRAY_STORE_THREAD
598  /* changes this waits is low, but must have finished */
600 # endif
601 
602 # ifdef DEBUG_TIME
603  TIMEIT_START(mesh_undo_expand);
604 # endif
605 
607 
608 # ifdef DEBUG_TIME
609  TIMEIT_END(mesh_undo_expand);
610 # endif
611 #endif /* USE_ARRAY_STORE */
612 
613  const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(&um->me);
614 
615  em->bm->shapenr = um->shapenr;
616 
617  EDBM_mesh_free(em);
618 
619  bm = BM_mesh_create(&allocsize,
620  &((struct BMeshCreateParams){
621  .use_toolflags = true,
622  }));
623 
625  &um->me,
626  (&(struct BMeshFromMeshParams){
627  .calc_face_normal = true,
628  .active_shapekey = um->shapenr,
629  }));
630 
631  em_tmp = BKE_editmesh_create(bm, true);
632  *em = *em_tmp;
633 
634  em->selectmode = um->selectmode;
636 
638 
639  /* T35170: Restore the active key on the RealMesh. Otherwise 'fake' offset propagation happens
640  * if the active is a basis for any other. */
641  if (key && (key->type == KEY_RELATIVE)) {
642  /* Since we can't add, remove or reorder keyblocks in editmode, it's safe to assume
643  * shapenr from restored bmesh and keyblock indices are in sync. */
644  const int kb_act_idx = ob->shapenr - 1;
645 
646  /* If it is, let's patch the current mesh key block to its restored value.
647  * Else, the offsets won't be computed and it won't matter. */
648  if (BKE_keyblock_is_basis(key, kb_act_idx)) {
649  KeyBlock *kb_act = BLI_findlink(&key->block, kb_act_idx);
650 
651  if (kb_act->totelem != um->me.totvert) {
652  /* The current mesh has some extra/missing verts compared to the undo, adjust. */
653  MEM_SAFE_FREE(kb_act->data);
654  kb_act->data = MEM_mallocN((size_t)(key->elemsize) * bm->totvert, __func__);
655  kb_act->totelem = um->me.totvert;
656  }
657 
659  }
660  }
661 
662  ob->shapenr = um->shapenr;
663 
664  MEM_freeN(em_tmp);
665 
666 #ifdef USE_ARRAY_STORE
668 #endif
669 }
670 
672 {
673  Mesh *me = &um->me;
674 
675 #ifdef USE_ARRAY_STORE
676 
677 # ifdef USE_ARRAY_STORE_THREAD
678  /* changes this waits is low, but must have finished */
680 # endif
681 
682  /* we need to expand so any allocations in custom-data are freed with the mesh */
684 
685  {
686  LinkData *link = BLI_findptr(&um_arraystore.local_links, um, offsetof(LinkData, data));
687  BLI_remlink(&um_arraystore.local_links, link);
688  MEM_freeN(link);
689  }
691 #endif
692 
693  if (me->key) {
694  BKE_key_free(me->key);
695  MEM_freeN(me->key);
696  }
697 
698  BKE_mesh_free_data(me);
699 }
700 
702 {
703  ViewLayer *view_layer = CTX_data_view_layer(C);
704  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
705  if (obedit && obedit->type == OB_MESH) {
706  Mesh *me = obedit->data;
707  if (me->edit_mesh != NULL) {
708  return obedit;
709  }
710  }
711  return NULL;
712 }
713 
716 /* -------------------------------------------------------------------- */
722 typedef struct MeshUndoStep_Elem {
724  UndoRefID_Object obedit_ref;
727 
728 typedef struct MeshUndoStep {
733 
735 {
737 }
738 
739 static bool mesh_undosys_step_encode(struct bContext *C, struct Main *bmain, UndoStep *us_p)
740 {
741  MeshUndoStep *us = (MeshUndoStep *)us_p;
742 
743  /* Important not to use the 3D view when getting objects because all objects
744  * outside of this list will be moved out of edit-mode when reading back undo steps. */
745  ViewLayer *view_layer = CTX_data_view_layer(C);
746  uint objects_len = 0;
747  Object **objects = ED_undo_editmode_objects_from_view_layer(view_layer, &objects_len);
748 
749  us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__);
750  us->elems_len = objects_len;
751 
752  for (uint i = 0; i < objects_len; i++) {
753  Object *ob = objects[i];
754  MeshUndoStep_Elem *elem = &us->elems[i];
755 
756  elem->obedit_ref.ptr = ob;
757  Mesh *me = elem->obedit_ref.ptr->data;
758  BMEditMesh *em = me->edit_mesh;
759  undomesh_from_editmesh(&elem->data, me->edit_mesh, me->key);
760  em->needs_flush_to_id = 1;
761  us->step.data_size += elem->data.undo_size;
762  }
763  MEM_freeN(objects);
764 
765  bmain->is_memfile_undo_flush_needed = true;
766 
767  return true;
768 }
769 
770 static void mesh_undosys_step_decode(struct bContext *C,
771  struct Main *bmain,
772  UndoStep *us_p,
773  const eUndoStepDir UNUSED(dir),
774  bool UNUSED(is_final))
775 {
776  MeshUndoStep *us = (MeshUndoStep *)us_p;
777 
779  C, &us->elems[0].obedit_ref.ptr, us->elems_len, sizeof(*us->elems));
780 
782 
783  for (uint i = 0; i < us->elems_len; i++) {
784  MeshUndoStep_Elem *elem = &us->elems[i];
785  Object *obedit = elem->obedit_ref.ptr;
786  Mesh *me = obedit->data;
787  if (me->edit_mesh == NULL) {
788  /* Should never fail, may not crash but can give odd behavior. */
789  CLOG_ERROR(&LOG,
790  "name='%s', failed to enter edit-mode for object '%s', undo state invalid",
791  us_p->name,
792  obedit->id.name);
793  continue;
794  }
795  BMEditMesh *em = me->edit_mesh;
796  undomesh_to_editmesh(&elem->data, obedit, em, me->key);
797  em->needs_flush_to_id = 1;
799  }
800 
801  /* The first element is always active */
803  CTX_data_scene(C), CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG);
804 
805  /* Check after setting active. */
807 
810 
811  bmain->is_memfile_undo_flush_needed = true;
812 
814 }
815 
817 {
818  MeshUndoStep *us = (MeshUndoStep *)us_p;
819 
820  for (uint i = 0; i < us->elems_len; i++) {
821  MeshUndoStep_Elem *elem = &us->elems[i];
822  undomesh_free_data(&elem->data);
823  }
824  MEM_freeN(us->elems);
825 }
826 
828  UndoTypeForEachIDRefFn foreach_ID_ref_fn,
829  void *user_data)
830 {
831  MeshUndoStep *us = (MeshUndoStep *)us_p;
832 
833  for (uint i = 0; i < us->elems_len; i++) {
834  MeshUndoStep_Elem *elem = &us->elems[i];
835  foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref));
836  }
837 }
838 
839 /* Export for ED_undo_sys. */
841 {
842  ut->name = "Edit Mesh";
843  ut->poll = mesh_undosys_poll;
847 
849 
851 
852  ut->step_size = sizeof(MeshUndoStep);
853 }
854 
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
bool CustomData_layertype_is_dynamic(int type)
Definition: customdata.c:4303
int CustomData_sizeof(int type)
Definition: customdata.c:4277
BMEditMesh * BKE_editmesh_create(BMesh *bm, const bool do_tessellate)
Definition: editmesh.c:42
bool BKE_keyblock_is_basis(struct Key *key, const int index)
Definition: key.c:2600
void BKE_keyblock_update_from_mesh(struct Mesh *me, struct KeyBlock *kb)
Definition: key.c:2188
void BKE_key_free(struct Key *key)
Definition: key.c:242
@ LIB_ID_COPY_LOCALIZE
Definition: BKE_lib_id.h:145
@ LIB_ID_COPY_NO_ANIMDATA
Definition: BKE_lib_id.h:120
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
void BKE_mesh_free_data(struct Mesh *me)
Definition: mesh.c:796
void BKE_mesh_update_customdata_pointers(struct Mesh *me, const bool do_ensure_tess_cd)
Definition: mesh.c:766
General operations, lookup, etc. for blender objects.
bool BKE_object_is_in_editmode(const struct Object *ob)
eUndoStepDir
@ UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE
void(* UndoTypeForEachIDRefFn)(void *user_data, struct UndoRefID *id_ref)
Efficient in-memory storage of multiple similar arrays.
void * BLI_array_store_state_data_get_alloc(BArrayState *state, size_t *r_data_len)
Definition: array_store.c:1654
void BLI_array_store_state_remove(BArrayStore *bs, BArrayState *state)
Definition: array_store.c:1609
BArrayState * BLI_array_store_state_add(BArrayStore *bs, const void *data, const size_t data_len, const BArrayState *state_reference)
Definition: array_store.c:1556
void BLI_array_store_at_size_clear(struct BArrayStore_AtSize *bs_stride)
void BLI_array_store_at_size_calc_memory_usage(struct BArrayStore_AtSize *bs_stride, size_t *r_size_expanded, size_t *r_size_compacted)
BArrayStore * BLI_array_store_at_size_ensure(struct BArrayStore_AtSize *bs_stride, const int stride, const int chunk_size)
BArrayStore * BLI_array_store_at_size_get(struct BArrayStore_AtSize *bs_stride, const int stride)
Generic array manipulation API.
#define BLI_array_is_zeroed(arr, arr_len)
#define BLI_assert(a)
Definition: BLI_assert.h:58
struct LinkData * BLI_genericNodeN(void *data)
Definition: listbase.c:923
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int uint
Definition: BLI_sys_types.h:83
TaskPool * BLI_task_pool_create_background(void *userdata, TaskPriority priority)
Definition: task_pool.cc:423
void BLI_task_pool_work_and_wait(TaskPool *pool)
Definition: task_pool.cc:496
void BLI_task_pool_free(TaskPool *pool)
Definition: task_pool.cc:456
@ TASK_PRIORITY_LOW
Definition: BLI_task.h:66
void BLI_task_pool_push(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
Definition: task_pool.cc:475
#define UNUSED_VARS_NDEBUG(...)
#define UNUSED(x)
typedef double(DMatrix)[4][4]
#define CLOG_ERROR(clg_ref,...)
Definition: CLG_log.h:204
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
CustomDataType
@ KEY_RELATIVE
Object is a sort of wrapper for general info.
@ OB_MESH
#define OBEDIT_FROM_VIEW_LAYER(view_layer)
void EDBM_mesh_free(struct BMEditMesh *em)
void ED_undo_object_editmode_restore_helper(struct bContext *C, struct Object **object_array, uint object_array_len, uint object_array_stride)
Definition: ed_undo.c:897
void ED_undo_object_set_active_or_warn(struct Scene *scene, struct ViewLayer *view_layer, struct Object *ob, const char *info, struct CLG_LogRef *log)
Definition: ed_undo.c:877
struct Object ** ED_undo_editmode_objects_from_view_layer(struct ViewLayer *view_layer, uint *r_len)
Definition: ed_undo.c:968
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
Utility defines for timing/benchmarks.
#define TIMEIT_START(var)
#define TIMEIT_END(var)
#define C
Definition: RandGen.cpp:39
#define NC_GEOM
Definition: WM_types.h:294
#define ND_DATA
Definition: WM_types.h:408
@ BM_SPACEARR_DIRTY_ALL
Definition: bmesh_class.h:416
ATTR_WARN_UNUSED_RESULT BMesh * bm
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const struct BMeshCreateParams *params)
BMesh Make Mesh.
Definition: bmesh_mesh.c:157
#define BMALLOC_TEMPLATE_FROM_ME(...)
Definition: bmesh_mesh.h:163
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshParams *params)
Mesh -> BMesh.
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
Scene scene
void * user_data
static void um_arraystore_expand(UndoMesh *um)
static void um_arraystore_cd_compact(struct CustomData *cdata, const size_t data_len, bool create, const BArrayCustomData *bcd_reference, BArrayCustomData **r_bcd_first)
static void um_arraystore_free(UndoMesh *um)
struct MeshUndoStep MeshUndoStep
struct MeshUndoStep_Elem MeshUndoStep_Elem
static void undomesh_free_data(UndoMesh *um)
static void * undomesh_from_editmesh(UndoMesh *um, BMEditMesh *em, Key *key)
static void um_arraystore_compact_cb(TaskPool *__restrict UNUSED(pool), void *taskdata)
struct BArrayCustomData BArrayCustomData
#define ARRAY_CHUNK_SIZE
Definition: editmesh_undo.c:67
void ED_mesh_undosys_type(UndoType *ut)
static void um_arraystore_compact(UndoMesh *um, const UndoMesh *um_ref)
static void um_arraystore_cd_expand(const BArrayCustomData *bcd, struct CustomData *cdata, const size_t data_len)
static struct @458 um_arraystore
static void um_arraystore_cd_free(BArrayCustomData *bcd)
static void mesh_undosys_step_decode(struct bContext *C, struct Main *bmain, UndoStep *us_p, const eUndoStepDir UNUSED(dir), bool UNUSED(is_final))
TaskPool * task_pool
static void um_arraystore_expand_clear(UndoMesh *um)
ListBase local_links
static bool mesh_undosys_poll(bContext *C)
static void mesh_undosys_foreach_ID_ref(UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
static Object * editmesh_object_from_context(bContext *C)
struct UndoMesh UndoMesh
static void undomesh_to_editmesh(UndoMesh *um, Object *ob, BMEditMesh *em, Key *key)
int users
static CLG_LogRef LOG
Definition: editmesh_undo.c:77
static void mesh_undosys_step_free(UndoStep *us_p)
struct BArrayStore_AtSize bs_stride
static void um_arraystore_compact_with_info(UndoMesh *um, const UndoMesh *um_ref)
static bool mesh_undosys_step_encode(struct bContext *C, struct Main *bmain, UndoStep *us_p)
static void um_arraystore_compact_ex(UndoMesh *um, const UndoMesh *um_ref, bool create)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
static ulong state[N]
BArrayState * states[0]
Definition: editmesh_undo.c:90
struct BArrayCustomData * next
Definition: editmesh_undo.c:87
CustomDataType type
Definition: editmesh_undo.c:88
short selectmode
Definition: BKE_editmesh.h:72
struct BMesh * bm
Definition: BKE_editmesh.h:52
char needs_flush_to_id
Definition: BKE_editmesh.h:82
int totvert
Definition: bmesh_class.h:297
int shapenr
Definition: bmesh_class.h:353
short selectmode
Definition: bmesh_class.h:350
char spacearr_dirty
Definition: bmesh_class.h:344
CustomDataLayer * layers
char name[66]
Definition: DNA_ID.h:283
struct KeyBlock * next
Definition: DNA_key_types.h:41
void * data
Definition: DNA_key_types.h:66
int totkey
ID id
Definition: DNA_key_types.h:79
int elemsize
Definition: DNA_key_types.h:96
char type
ListBase block
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
char is_memfile_undo_flush_needed
Definition: BKE_main.h:130
struct MeshUndoStep_Elem * prev
UndoRefID_Object obedit_ref
struct MeshUndoStep_Elem * next
MeshUndoStep_Elem * elems
UndoStep step
struct BMEditMesh * edit_mesh
struct CustomData pdata ldata
int totedge
int totvert
int totpoly
int totloop
struct Key * key
int totselect
struct MSelect * mselect
short shapenr
void * data
struct ToolSettings * toolsettings
const UndoMesh * um_ref
UndoMesh * um
size_t undo_size
BArrayState * mselect
BArrayCustomData * ldata
BArrayCustomData * vdata
BArrayState ** keyblocks
int selectmode
Definition: editmesh_undo.c:97
struct UndoMesh::@459 store
BArrayCustomData * pdata
BArrayCustomData * edata
size_t data_size
char name[64]
size_t step_size
void(* step_decode)(struct bContext *C, struct Main *bmain, UndoStep *us, const eUndoStepDir dir, bool is_final)
bool(* step_encode)(struct bContext *C, struct Main *bmain, UndoStep *us)
void(* step_foreach_ID_ref)(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
const char * name
void(* step_free)(UndoStep *us)
bool(* poll)(struct bContext *C)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)