Blender V5.3
editmesh_undo.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "MEM_guardedalloc.h"
12
13#include "CLG_log.h"
14
15#include "DNA_key_types.h"
16#include "DNA_layer_types.h"
17#include "DNA_mesh_types.h"
18#include "DNA_meshdata_types.h"
19#include "DNA_object_types.h"
20#include "DNA_scene_types.h"
21
22#include "BLI_array_utils_c.hh"
24#include "BLI_listbase.hh"
25#include "BLI_math_base_c.hh"
27#include "BLI_string.hh"
28#include "BLI_task.hh"
29#include "BLI_vector.hh"
30
32#include "BKE_context.hh"
33#include "BKE_customdata.hh"
34#include "BKE_deform.hh"
35#include "BKE_editmesh.hh"
36#include "BKE_key.hh"
37#include "BKE_layer.hh"
38#include "BKE_lib_id.hh"
39#include "BKE_main.hh"
40#include "BKE_mesh.hh"
41#include "BKE_object.hh"
42#include "BKE_undo_system.hh"
43
44#include "DEG_depsgraph.hh"
45
46#include "ED_mesh.hh"
47#include "ED_object.hh"
48#include "ED_undo.hh"
49#include "ED_util.hh"
50
51#include "WM_api.hh"
52#include "WM_types.hh"
53
54#define USE_ARRAY_STORE
55
56#ifdef USE_ARRAY_STORE
57// # define DEBUG_PRINT
58// # define DEBUG_TIME
59# ifdef DEBUG_TIME
61# endif
62
63# include "BLI_array_store.hh"
72# define ARRAY_CHUNK_SIZE_IN_BYTES 65536
73# define ARRAY_CHUNK_NUM_MIN 256
74
75# define USE_ARRAY_STORE_THREAD
76
99# define USE_ARRAY_STORE_RLE
100#endif
101
102#ifdef USE_ARRAY_STORE_THREAD
103# include "BLI_task_c.hh"
104#endif
105
106namespace blender {
107
109static CLG_LogRef LOG = {"undo.mesh"};
110
111/* -------------------------------------------------------------------- */
114
115#ifdef USE_ARRAY_STORE
116
117static size_t array_chunk_size_calc(const size_t stride)
118{
119 /* Return a chunk size that targets a size in bytes,
120 * this is done so boolean arrays don't add so much overhead and
121 * larger arrays aren't so big as to waste memory, see: #105205. */
123}
124
134
135# ifdef USE_ARRAY_STORE_RLE
137{
138 /* NOTE(@ideasman42): This could be enabled for all byte sized layers.
139 * for now only use for boolean layers to address: #136737. */
140 if (type == CD_PROP_BOOL) {
141 return true;
142 }
143 return false;
144}
145# endif
146
147#endif
148
149struct UndoMesh {
155
158
171
172#ifdef USE_ARRAY_STORE
173 /* Null arrays are considered empty. */
174 struct { /* most data is stored as 'custom' data */
180#endif /* USE_ARRAY_STORE */
181
182 size_t undo_size;
183};
184
186
187#ifdef USE_ARRAY_STORE
188
189/* -------------------------------------------------------------------- */
192
197enum {
205};
206# define ARRAY_STORE_INDEX_NUM (ARRAY_STORE_INDEX_MSEL + 1)
207
208struct UndoMesh;
209
210static struct {
212 int users;
213
218 ListBaseT<UndoMesh> local_links;
219
220# ifdef USE_ARRAY_STORE_THREAD
222# endif
223
224} um_arraystore = {{{nullptr}}};
225
226static void store_layer(const eCustomDataType type,
227 const void *data,
228 const ImplicitSharingInfo *sharing_info,
229 const size_t data_len,
230 const int bs_index,
231 const BArrayCustomData *bcd_reference,
232 Map<eCustomDataType, int> &index_in_type,
233 BArrayCustomData &bcd)
234{
235 int &i = index_in_type.lookup_or_add(type, 0);
236 BLI_SCOPED_DEFER([&]() { i++; });
237
238 /* Perform a full copy on dynamic layers.
239 *
240 * Unfortunately we can't compare dynamic layer types as they contain allocated pointers,
241 * which burns CPU cycles looking for duplicate data that doesn't exist.
242 * The array data isn't comparable once copied from the mesh,
243 * this bottlenecks on high poly meshes, see #84114.
244 *
245 * Ideally the data would be expanded into a format that could be de-duplicated effectively,
246 * this would require a flat representation of each dynamic custom-data layer.
247 *
248 * Instead, these non-trivial custom data layer are stored in the undo system using implicit
249 * sharing, to avoid the copy from the undo mesh.
250 */
252 ImplicitSharingInfoAndData state = {sharing_info, data};
253 if (state.data) {
254 state.sharing_info->add_user();
255 }
256 bcd.non_trivial_arrays.lookup_or_add_default(type).append(state);
257 return;
258 }
259
260 Vector<BArrayState *> &states = bcd.trivial_arrays.lookup_or_add_default(type);
261
262 const int stride = CustomData_sizeof(type);
264 &um_arraystore.bs_stride[bs_index], stride, array_chunk_size_calc(stride));
265
266 const Vector<BArrayState *> *bcd_reference_current =
267 bcd_reference ? bcd_reference->trivial_arrays.lookup_ptr(type) : nullptr;
268
269 if (!data) {
270 states.append(nullptr);
271 return;
272 }
273
274 const BArrayState *state_reference = nullptr;
275 if (bcd_reference_current && i < bcd_reference_current->size()) {
276 state_reference = (*bcd_reference_current)[i];
277 }
278
279 const void *data_final = data;
280 size_t data_final_size = size_t(data_len) * stride;
281
282# ifdef USE_ARRAY_STORE_RLE
283 const bool use_rle = um_customdata_layer_use_rle(type);
284 uint8_t *data_enc = nullptr;
285 if (use_rle) {
286 /* Store the size in the encoded data (for convenience). */
287 size_t data_enc_extra_size = sizeof(size_t);
288 size_t data_enc_len;
289 data_enc = BLI_array_store_rle_encode(reinterpret_cast<const uint8_t *>(data_final),
290 data_final_size,
291 data_enc_extra_size,
292 &data_enc_len);
293 memcpy(data_enc, &data_final_size, data_enc_extra_size);
294 data_final = data_enc;
295 data_final_size = data_enc_extra_size + data_enc_len;
296 }
297# endif
298
299 states.append(BLI_array_store_state_add(bs, data_final, data_final_size, state_reference));
300
301# ifdef USE_ARRAY_STORE_RLE
302 if (use_rle) {
303 MEM_delete(data_enc);
304 }
305# endif
306}
307
309 Span<bke::Attribute *> attributes,
310 const size_t data_len,
311 const int bs_index,
312 const BArrayCustomData *bcd_reference)
313{
315
316 Map<eCustomDataType, int> index_in_type;
317
318 for (CustomDataLayer &layer : MutableSpan(cdata->layers, cdata->totlayer)) {
320 layer.data,
321 layer.sharing_info,
322 data_len,
323 bs_index,
324 bcd_reference,
325 index_in_type,
326 bcd);
327 if (layer.data) {
328 layer.sharing_info->remove_user_and_delete_if_last();
329 layer.sharing_info = nullptr;
330 layer.data = nullptr;
331 }
332 }
333
334 for (bke::Attribute *attribute : attributes) {
336 switch (attribute->storage_type()) {
338 const auto &data = std::get<bke::Attribute::ArrayData>(attribute->data());
339 store_layer(type,
340 data.data,
341 data.sharing_info.get(),
342 data_len,
343 bs_index,
344 bcd_reference,
345 index_in_type,
346 bcd);
347 attribute->assign_data(bke::Attribute::ArrayData{});
348 break;
349 }
351 int &i = index_in_type.lookup_or_add(type, 0);
352 BLI_SCOPED_DEFER([&]() { i++; });
354 bcd.non_trivial_arrays.lookup_or_add_default(type).append(ImplicitSharingInfoAndData{});
355 break;
356 }
357 const int stride = CustomData_sizeof(type);
359 &um_arraystore.bs_stride[bs_index], stride, array_chunk_size_calc(stride));
360 bcd.trivial_arrays.lookup_or_add_default(type).append(nullptr);
361 break;
362 }
363 }
364 }
365
366 if (bcd.trivial_arrays.is_empty() && bcd.non_trivial_arrays.is_empty()) {
367 return nullptr;
368 }
369
370 return MEM_new<BArrayCustomData>(__func__, std::move(bcd));
371}
372
374{
375 for (CustomDataLayer &layer : MutableSpan(cdata->layers, cdata->totlayer)) {
376 if (layer.data) {
377 layer.sharing_info->remove_user_and_delete_if_last();
378 layer.sharing_info = nullptr;
379 layer.data = nullptr;
380 }
381 }
382}
383
386 const size_t data_len,
387 const eCustomDataType type)
388{
389 size_t state_len;
391
392 const int stride = CustomData_sizeof(type);
393
394# ifdef USE_ARRAY_STORE_RLE
395 const bool use_rle = um_customdata_layer_use_rle(type);
396 if (use_rle) {
397 /* Store the size in the encoded data (for convenience). */
398 size_t data_enc_extra_size = sizeof(size_t);
399 const uint8_t *data_enc = reinterpret_cast<uint8_t *>(data);
400 size_t data_dec_len;
401 memcpy(&data_dec_len, data_enc, sizeof(size_t));
402 uint8_t *data_dec = MEM_new_array_uninitialized<uint8_t>(data_dec_len, __func__);
404 data_enc + data_enc_extra_size, state_len - data_enc_extra_size, data_dec, data_dec_len);
406 data = static_cast<void *>(data_dec);
407 /* Just for the assert to succeed. */
408 state_len = data_dec_len;
409 }
410# endif
411
412 BLI_assert(stride * data_len == state_len);
413 UNUSED_VARS_NDEBUG(stride, data_len);
414
415 return static_cast<uint8_t *>(data);
416}
417
425 CustomData *cdata,
426 Span<bke::Attribute *> attributes,
427 const size_t data_len)
428{
429 if (bcd == nullptr) {
430 return;
431 }
432
433 Map<eCustomDataType, int> index_in_type;
434
435 for (CustomDataLayer &layer : MutableSpan(cdata->layers, cdata->totlayer)) {
436 const eCustomDataType type = eCustomDataType(layer.type);
437
438 int &i = index_in_type.lookup_or_add(type, 0);
439 BLI_SCOPED_DEFER([&]() { i++; });
440
441 if (bcd->non_trivial_arrays.contains(type)) {
442 const ImplicitSharingInfoAndData &state = bcd->non_trivial_arrays.lookup(type)[i];
443 if (!state.data) {
444 BLI_assert(data_len == 0);
445 layer.data = nullptr;
446 layer.sharing_info = nullptr;
447 continue;
448 }
449 layer.data = const_cast<void *>(state.data);
450 layer.sharing_info = state.sharing_info;
451 layer.sharing_info->add_user();
452 continue;
453 }
454 const BArrayState *state = bcd->trivial_arrays.lookup(type)[i];
455 if (!state) {
456 layer.data = nullptr;
457 layer.sharing_info = nullptr;
458 continue;
459 }
460
461 uint8_t *data = get_arraystore_data(state, data_len, type);
462 layer.data = data;
464 }
465
466 for (bke::Attribute *attribute : attributes) {
468
469 int &i = index_in_type.lookup_or_add(type, 0);
470 BLI_SCOPED_DEFER([&]() { i++; });
471
472 if (attribute->storage_type() == bke::AttrStorageType::Single) {
473 continue;
474 }
475
476 bke::Attribute::ArrayData array_data{};
477 if (bcd->non_trivial_arrays.contains(type)) {
478 const ImplicitSharingInfoAndData &state = bcd->non_trivial_arrays.lookup(type)[i];
479 array_data.data = const_cast<void *>(state.data);
480 array_data.size = data_len;
481 array_data.sharing_info = ImplicitSharingPtr<>(state.sharing_info);
482 array_data.sharing_info->add_user();
483 }
484 else {
485 const BArrayState *state = bcd->trivial_arrays.lookup(type)[i];
486 uint8_t *data = get_arraystore_data(state, data_len, type);
487 array_data.data = data;
488 array_data.size = data_len;
490 }
491
492 attribute->assign_data(std::move(array_data));
493 }
494}
495
496static void um_arraystore_cd_free(BArrayCustomData *bcd, const int bs_index)
497{
498 if (bcd == nullptr) {
499 return;
500 }
501
502 for (Vector<ImplicitSharingInfoAndData> &states : bcd->non_trivial_arrays.values()) {
503 for (ImplicitSharingInfoAndData &state : states) {
504 if (state.data) {
505 state.sharing_info->remove_user_and_delete_if_last();
506 }
507 }
508 }
509
510 for (const auto &item : bcd->trivial_arrays.items()) {
511 const int stride = CustomData_sizeof(item.key);
512 BArrayStore *bs = BLI_array_store_at_size_get(&um_arraystore.bs_stride[bs_index], stride);
513 for (BArrayState *state : item.value) {
514 if (state) {
516 }
517 }
518 }
519 MEM_delete(bcd);
520}
521
523{
525 for (bke::Attribute &attr : mesh.attribute_storage.wrap()) {
526 result.add(attr.domain(), &attr);
527 }
528 return result;
529}
530
534static void um_arraystore_compact(UndoMesh *um, const UndoMesh *um_ref)
535{
536 Mesh *mesh = um->mesh;
537
538 /* Compacting can be time consuming, run in parallel.
539 *
540 * NOTE(@ideasman42): this could be further parallelized with every custom-data layer
541 * running in its own thread. If this is a bottleneck it's worth considering.
542 * At the moment it seems fast enough to split by domain.
543 * Since this is itself a background thread, using too many threads here could
544 * interfere with foreground tasks. */
545
546# ifdef USE_ARRAY_STORE_THREAD
547 const bool use_threading = 4096 < (mesh->verts_num + mesh->edges_num + mesh->corners_num +
548 mesh->faces_num);
549# else
550 const bool use_threading = false;
551# endif
552
554
556 use_threading,
557 [&]() {
558 um->store.vdata = um_arraystore_cd_create(&mesh->vert_data,
559 attributes.lookup(bke::AttrDomain::Point),
560 mesh->verts_num,
562 um_ref ? um_ref->store.vdata : nullptr);
563 },
564 [&]() {
565 um->store.edata = um_arraystore_cd_create(&mesh->edge_data,
566 attributes.lookup(bke::AttrDomain::Edge),
567 mesh->edges_num,
569 um_ref ? um_ref->store.edata : nullptr);
570 },
571 [&]() {
572 um->store.ldata = um_arraystore_cd_create(&mesh->corner_data,
574 mesh->corners_num,
576 um_ref ? um_ref->store.ldata : nullptr);
577 },
578 [&]() {
579 um->store.pdata = um_arraystore_cd_create(&mesh->face_data,
580 attributes.lookup(bke::AttrDomain::Face),
581 mesh->faces_num,
583 um_ref ? um_ref->store.pdata : nullptr);
584 },
585 [&]() {
586 if (mesh->face_offset_indices) {
587 const BArrayState *state_reference = um_ref ? um_ref->store.face_offset_indices :
588 nullptr;
589 const size_t stride = sizeof(*mesh->face_offset_indices);
592 stride,
593 array_chunk_size_calc(stride));
594 um->store.face_offset_indices = BLI_array_store_state_add(bs,
595 mesh->face_offset_indices,
596 size_t(mesh->faces_num + 1) *
597 stride,
598 state_reference);
599
600 implicit_sharing::free_shared_data(&mesh->face_offset_indices,
601 &mesh->runtime->face_offsets_sharing_info);
602 }
603 },
604 [&]() {
605 if (mesh->key && mesh->key->totkey) {
606 const size_t stride = mesh->key->elemsize;
609 stride,
610 array_chunk_size_calc(stride));
612 mesh->key->totkey, "um_arraystore_compact keyblocks");
613
614 KeyBlock *keyblock = mesh->key->block.first();
615 for (int i = 0; i < mesh->key->totkey; i++, keyblock = keyblock->next) {
616 const BArrayState *state_reference = (um_ref && um_ref->mesh->key &&
617 (i < um_ref->mesh->key->totkey)) ?
618 um_ref->store.keyblocks[i] :
619 nullptr;
620 um->store.keyblocks[i] = BLI_array_store_state_add(
621 bs, keyblock->data, size_t(keyblock->totelem) * stride, state_reference);
622
623 if (keyblock->data) {
624 MEM_delete_void(keyblock->data);
625 keyblock->data = nullptr;
626 }
627 }
628 }
629 },
630 [&]() {
631 if (mesh->mselect && mesh->totselect) {
632 const BArrayState *state_reference = um_ref ? um_ref->store.mselect : nullptr;
633 const size_t stride = sizeof(*mesh->mselect);
636 stride,
637 array_chunk_size_calc(stride));
638 um->store.mselect = BLI_array_store_state_add(
639 bs, mesh->mselect, size_t(mesh->totselect) * stride, state_reference);
640
641 /* keep mesh->totselect for validation */
642 MEM_delete(mesh->mselect);
643 mesh->mselect = nullptr;
644 }
645 });
646
647 um_arraystore.users += 1;
648}
649
654{
655 Mesh *mesh = um->mesh;
656 um_arraystore_cd_clear(&mesh->vert_data);
657 um_arraystore_cd_clear(&mesh->edge_data);
658 um_arraystore_cd_clear(&mesh->corner_data);
659 um_arraystore_cd_clear(&mesh->face_data);
660 for (bke::Attribute &attr : mesh->attribute_storage.wrap()) {
661 if (attr.storage_type() == bke::AttrStorageType::Single) {
662 continue;
663 }
664 attr.assign_data(bke::Attribute::ArrayData{});
665 }
666 if (mesh->face_offset_indices) {
667 implicit_sharing::free_shared_data(&mesh->face_offset_indices,
668 &mesh->runtime->face_offsets_sharing_info);
669 }
670 if (mesh->key && mesh->key->totkey) {
671 KeyBlock *keyblock = mesh->key->block.first();
672 for (int i = 0; i < mesh->key->totkey; i++, keyblock = keyblock->next) {
673 if (keyblock->data) {
674 MEM_delete_void(keyblock->data);
675 keyblock->data = nullptr;
676 }
677 }
678 }
679 if (mesh->mselect && mesh->totselect) {
680 /* keep mesh->totselect for validation */
681 MEM_delete(mesh->mselect);
682 mesh->mselect = nullptr;
683 }
684}
685
686static void um_arraystore_compact_with_info(UndoMesh *um, const UndoMesh *um_ref)
687{
688# ifdef DEBUG_PRINT
689 size_t size_expanded_prev = 0, size_compacted_prev = 0;
690
691 for (int bs_index = 0; bs_index < ARRAY_STORE_INDEX_NUM; bs_index++) {
692 size_t size_expanded_prev_iter, size_compacted_prev_iter;
694 &um_arraystore.bs_stride[bs_index], &size_expanded_prev_iter, &size_compacted_prev_iter);
695 size_expanded_prev += size_expanded_prev_iter;
696 size_compacted_prev += size_compacted_prev_iter;
697 }
698# endif
699
700# ifdef DEBUG_TIME
701 TIMEIT_START(mesh_undo_compact);
702# endif
703
704 um_arraystore_compact(um, um_ref);
705
706# ifdef DEBUG_TIME
707 TIMEIT_END(mesh_undo_compact);
708# endif
709
710# ifdef DEBUG_PRINT
711 {
712 size_t size_expanded = 0, size_compacted = 0;
713
714 for (int bs_index = 0; bs_index < ARRAY_STORE_INDEX_NUM; bs_index++) {
715 size_t size_expanded_iter, size_compacted_iter;
717 &um_arraystore.bs_stride[bs_index], &size_expanded_iter, &size_compacted_iter);
718 size_expanded += size_expanded_iter;
719 size_compacted += size_compacted_iter;
720 }
721
722 const double percent_total = size_expanded ?
723 ((double(size_compacted) / double(size_expanded)) * 100.0) :
724 -1.0;
725
726 size_t size_expanded_step = size_expanded - size_expanded_prev;
727 size_t size_compacted_step = size_compacted - size_compacted_prev;
728 const double percent_step = size_expanded_step ?
729 ((double(size_compacted_step) / double(size_expanded_step)) *
730 100.0) :
731 -1.0;
732
733 printf("overall memory use: %.8f%% of expanded size\n", percent_total);
734 printf("step memory use: %.8f%% of expanded size\n", percent_step);
735 }
736# endif
737}
738
739# ifdef USE_ARRAY_STORE_THREAD
740
743 const UndoMesh *um_ref; /* can be nullptr */
744};
745static void um_arraystore_compact_cb(TaskPool *__restrict /*pool*/, void *taskdata)
746{
747 UMArrayData *um_data = static_cast<UMArrayData *>(taskdata);
748 um_arraystore_compact_with_info(um_data->um, um_data->um_ref);
749}
750
751# endif /* USE_ARRAY_STORE_THREAD */
752
754{
755 Mesh *mesh = um->mesh;
756
758
760 &mesh->vert_data,
761 attributes.lookup(bke::AttrDomain::Point),
762 mesh->verts_num);
764 &mesh->edge_data,
765 attributes.lookup(bke::AttrDomain::Edge),
766 mesh->edges_num);
768 &mesh->corner_data,
770 mesh->corners_num);
772 &mesh->face_data,
773 attributes.lookup(bke::AttrDomain::Face),
774 mesh->faces_num);
775
776 if (um->store.keyblocks) {
777 const size_t stride = mesh->key->elemsize;
778 KeyBlock *keyblock = mesh->key->block.first();
779 for (int i = 0; i < mesh->key->totkey; i++, keyblock = keyblock->next) {
780 const BArrayState *state = um->store.keyblocks[i];
781 size_t state_len;
782 keyblock->data = BLI_array_store_state_data_get_alloc(state, &state_len);
783 BLI_assert(keyblock->totelem == (state_len / stride));
784 UNUSED_VARS_NDEBUG(stride);
785 }
786 }
787
788 if (um->store.face_offset_indices) {
789 const size_t stride = sizeof(*mesh->face_offset_indices);
790 const BArrayState *state = um->store.face_offset_indices;
791 size_t state_len;
792 mesh->face_offset_indices = static_cast<int *>(
794 mesh->runtime->face_offsets_sharing_info = implicit_sharing::info_for_mem_free(
795 mesh->face_offset_indices);
796 BLI_assert((mesh->faces_num + 1) == (state_len / stride));
797 UNUSED_VARS_NDEBUG(stride);
798 }
799 if (um->store.mselect) {
800 const size_t stride = sizeof(*mesh->mselect);
801 const BArrayState *state = um->store.mselect;
802 size_t state_len;
803 mesh->mselect = static_cast<MSelect *>(
805 BLI_assert(mesh->totselect == (state_len / stride));
806 UNUSED_VARS_NDEBUG(stride);
807 }
808}
809
811{
812 Mesh *mesh = um->mesh;
813
818
819 if (um->store.keyblocks) {
820 const size_t stride = mesh->key->elemsize;
822 &um_arraystore.bs_stride[ARRAY_STORE_INDEX_SHAPE], stride);
823 for (int i = 0; i < mesh->key->totkey; i++) {
824 BArrayState *state = um->store.keyblocks[i];
826 }
827 MEM_delete(um->store.keyblocks);
828 um->store.keyblocks = nullptr;
829 }
830
831 if (um->store.face_offset_indices) {
832 const size_t stride = sizeof(*mesh->face_offset_indices);
835 BArrayState *state = um->store.face_offset_indices;
837 um->store.face_offset_indices = nullptr;
838 }
839 if (um->store.mselect) {
840 const size_t stride = sizeof(*mesh->mselect);
842 stride);
843 BArrayState *state = um->store.mselect;
845 um->store.mselect = nullptr;
846 }
847
848 um_arraystore.users -= 1;
849
850 BLI_assert(um_arraystore.users >= 0);
851
852 if (um_arraystore.users == 0) {
853# ifdef DEBUG_PRINT
854 printf("mesh undo store: freeing all data!\n");
855# endif
856 for (int bs_index = 0; bs_index < ARRAY_STORE_INDEX_NUM; bs_index++) {
857 BLI_array_store_at_size_clear(&um_arraystore.bs_stride[bs_index]);
858 }
859# ifdef USE_ARRAY_STORE_THREAD
861 um_arraystore.task_pool = nullptr;
862# endif
863 }
864}
865
867
868/* -------------------------------------------------------------------- */
871
884{
885 /* Map: `Mesh.id.session_uid` -> `UndoMesh`. */
886 Map<int, UndoMesh **> uuid_map;
887 uuid_map.reserve(object_len);
888 UndoMesh **um_references = MEM_new_array_zeroed<UndoMesh *>(object_len, __func__);
889 for (int i = 0; i < object_len; i++) {
890 const Mesh *mesh = id_cast<const Mesh *>(object[i]->data);
891 uuid_map.add(mesh->id.session_uid, &um_references[i]);
892 }
893 int uuid_map_len = object_len;
894
895 /* Loop backwards over all previous mesh undo data until either:
896 * - All elements have been found (where `um_references` we'll have every element set).
897 * - There are no undo steps left to look for. */
898 UndoMesh *um_iter = um_arraystore.local_links.last();
899 while (um_iter && (uuid_map_len != 0)) {
900 if (UndoMesh **um_p = uuid_map.pop_default(um_iter->mesh->id.session_uid, nullptr)) {
901 *um_p = um_iter;
902 uuid_map_len--;
903 }
904 um_iter = um_iter->local_prev;
905 }
906 BLI_assert(uuid_map_len == uuid_map.size());
907 if (uuid_map_len == object_len) {
908 MEM_delete(um_references);
909 um_references = nullptr;
910 }
911 return um_references;
912}
913
915
916#endif /* USE_ARRAY_STORE */
917
918/* -------------------------------------------------------------------- */
921
922/* for callbacks */
923/* undo simply makes copies of a bmesh */
933 BMEditMesh *em,
934 Key *key,
935 const ListBaseT<bDeformGroup> *vertex_group_names,
936 const int vertex_group_active_index,
937 UndoMesh *um_ref)
938{
940#ifdef USE_ARRAY_STORE_THREAD
941 /* changes this waits is low, but must have finished */
942 if (um_arraystore.task_pool) {
944 }
945#endif
946
947 BMesh *bm = em->bm;
948
949 um->mesh = bke::mesh_new_no_attributes(0, 0, 0, 0);
950
951 /* make sure shape keys work */
952 if (key != nullptr) {
953 um->mesh->key = id_cast<Key *>(BKE_id_copy_ex(
954 nullptr, &key->id, nullptr, LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA));
955 }
956 else {
957 um->mesh->key = nullptr;
958 }
959
960 /* Uncomment for troubleshooting. */
961 if (false) {
963
964 /* Ensure UV's are in a valid state. */
966 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
967 bool check_flush = true;
968 /* This should check the sticky mode too (currently the scene isn't available). */
969 bool check_contiguous = (cd_loop_uv_offset != -1);
971 bool is_valid = BM_mesh_uvselect_is_valid(
972 bm, cd_loop_uv_offset, true, check_flush, check_contiguous, &info);
973 if (is_valid == false) {
974 fprintf(stderr, "ERROR: UV sync check failed!\n");
975 }
976 // BLI_assert(is_valid);
977 }
978 }
979
980 CustomData_MeshMasks cd_mask_extra{};
981 cd_mask_extra.vmask = CD_MASK_SHAPE_KEYINDEX;
982 BMeshToMeshParams params{};
983 /* Undo code should not be manipulating 'G_MAIN->object' hooks/vertex-parent. */
984 params.calc_object_remap = false;
985 params.update_shapekey_indices = false;
986 params.cd_mask_extra = cd_mask_extra;
987 params.active_shapekey_to_mvert = true;
988 BM_mesh_bm_to_me(nullptr, bm, um->mesh, &params);
989 BKE_defgroup_copy_list(&um->mesh->vertex_group_names, vertex_group_names);
990 um->mesh->vertex_group_active_index = vertex_group_active_index;
991
992 um->selectmode = em->selectmode;
993 um->shapenr = bm->shapenr;
994
995#ifdef USE_ARRAY_STORE
996 {
997 /* Add ourselves. */
998 BLI_addtail(&um_arraystore.local_links, um);
999
1000# ifdef USE_ARRAY_STORE_THREAD
1001 if (um_arraystore.task_pool == nullptr) {
1003 }
1004
1006 um_data->um = um;
1007 um_data->um_ref = um_ref;
1008
1009 BLI_task_pool_push(um_arraystore.task_pool, um_arraystore_compact_cb, um_data, true, nullptr);
1010# else
1012# endif
1013 }
1014#else
1015 UNUSED_VARS(um_ref);
1016#endif
1017
1018 return um;
1019}
1020
1030 BMEditMesh *em,
1031 ListBaseT<bDeformGroup> *vertex_group_names,
1032 int *vertex_group_active_index)
1033{
1034 BMEditMesh *em_tmp;
1035
1036#ifdef USE_ARRAY_STORE
1037# ifdef USE_ARRAY_STORE_THREAD
1038 /* changes this waits is low, but must have finished */
1040# endif
1041
1042# ifdef DEBUG_TIME
1043 TIMEIT_START(mesh_undo_expand);
1044# endif
1045
1047
1048# ifdef DEBUG_TIME
1049 TIMEIT_END(mesh_undo_expand);
1050# endif
1051#endif /* USE_ARRAY_STORE */
1052
1053 const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(um->mesh);
1054
1055 em->bm->shapenr = um->shapenr;
1056
1058
1059 BMeshCreateParams create_params{};
1060 create_params.use_toolflags = true;
1061 BMesh *bm = BM_mesh_create(&allocsize, &create_params);
1062
1063 BMeshFromMeshParams convert_params{};
1064 /* Handled with tessellation. */
1065 convert_params.calc_face_normal = false;
1066 convert_params.calc_vert_normal = false;
1067 convert_params.active_shapekey = um->shapenr;
1068 BM_mesh_bm_from_me(bm, um->mesh, &convert_params);
1069 vertex_group_names->free_no_destruct();
1070 BKE_defgroup_copy_list(vertex_group_names, &um->mesh->vertex_group_names);
1071 *vertex_group_active_index = um->mesh->vertex_group_active_index;
1072
1073 em_tmp = BKE_editmesh_create(bm);
1074 *em = *em_tmp;
1075
1076 /* Calculate face normals and tessellation at once since it's multi-threaded. */
1078
1079 em->selectmode = um->selectmode;
1080 bm->selectmode = um->selectmode;
1081
1083
1084 MEM_delete(em_tmp);
1085
1086#ifdef USE_ARRAY_STORE
1088#endif
1089}
1090
1092{
1093 Mesh *mesh = um->mesh;
1094
1095#ifdef USE_ARRAY_STORE
1096
1097# ifdef USE_ARRAY_STORE_THREAD
1098 /* Chances this waits is low, but must have finished. */
1100# endif
1101
1102 /* We need to expand so any allocations in custom-data are freed with the mesh. */
1104
1105 BLI_assert(BLI_findindex(&um_arraystore.local_links, um) != -1);
1106 BLI_remlink(&um_arraystore.local_links, um);
1107
1109#endif
1110
1111 if (mesh->key) {
1112 BKE_id_free(nullptr, mesh->key);
1113 mesh->key = nullptr;
1114 }
1115
1116 BKE_id_free(nullptr, mesh);
1117 um->mesh = nullptr;
1118}
1119
1121{
1122 const Main *bmain = CTX_data_main(C);
1123 Scene *scene = CTX_data_scene(C);
1124 ViewLayer *view_layer = CTX_data_view_layer(C);
1125 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1126 Object *obedit = BKE_view_layer_edit_object_get(view_layer);
1127 if (obedit && obedit->type == OB_MESH) {
1128 const Mesh *mesh = id_cast<Mesh *>(obedit->data);
1129 if (mesh->runtime->edit_mesh != nullptr) {
1130 return obedit;
1131 }
1132 }
1133 return nullptr;
1134}
1135
1137
1138/* -------------------------------------------------------------------- */
1143
1145 UndoRefID_Object obedit_ref;
1147};
1148
1159
1169
1171{
1172 return editmesh_object_from_context(C) != nullptr;
1173}
1174
1176{
1177 MeshUndoStep *us = reinterpret_cast<MeshUndoStep *>(us_p);
1178
1179 /* Important not to use the 3D view when getting objects because all objects
1180 * outside of this list will be moved out of edit-mode when reading back undo steps. */
1181 Scene *scene = CTX_data_scene(C);
1182 ViewLayer *view_layer = CTX_data_view_layer(C);
1183 const ToolSettings *ts = scene->toolsettings;
1184 Vector<Object *> objects = ED_undo_editmode_objects_from_view_layer(*bmain, scene, view_layer);
1185
1186 us->scene_ref.ptr = scene;
1187 us->elems = MEM_new_array_zeroed<MeshUndoStep_Elem>(objects.size(), __func__);
1188 us->elems_len = objects.size();
1189
1190 UndoMesh **um_references = nullptr;
1191
1192#ifdef USE_ARRAY_STORE
1193 um_references = mesh_undostep_reference_elems_from_objects(objects.data(), objects.size());
1194#endif
1195
1196 {
1197 MeshUndoStep_SceneData &scene_data = us->scene_data;
1198 scene_data.selectmode = ts->selectmode;
1199 scene_data.uv_selectmode = ts->uv_selectmode;
1200 scene_data.uv_sticky = ts->uv_sticky;
1201 scene_data.uv_flag = ts->uv_flag;
1202 }
1203
1204 for (uint i = 0; i < objects.size(); i++) {
1205 Object *obedit = objects[i];
1206 MeshUndoStep_Elem *elem = &us->elems[i];
1207
1208 elem->obedit_ref.ptr = obedit;
1209 Mesh *mesh = id_cast<Mesh *>(elem->obedit_ref.ptr->data);
1210 BMEditMesh *em = mesh->runtime->edit_mesh.get();
1212 em,
1213 mesh->key,
1214 &mesh->vertex_group_names,
1215 mesh->vertex_group_active_index,
1216 um_references ? um_references[i] : nullptr);
1217
1218 em->needs_flush_to_id = 1;
1219 us->step.data_size += elem->data.undo_size;
1220
1221#ifdef USE_ARRAY_STORE
1223 elem->data.mesh->id.session_uid = mesh->id.session_uid;
1224#endif
1225 }
1226
1227 if (um_references != nullptr) {
1228 MEM_delete(um_references);
1229 }
1230
1231 bmain->is_memfile_undo_flush_needed = true;
1232
1233 return true;
1234}
1235
1237 bContext *C, Main *bmain, UndoStep *us_p, const eUndoStepDir /*dir*/, bool /*is_final*/)
1238{
1239 MeshUndoStep *us = reinterpret_cast<MeshUndoStep *>(us_p);
1240 Scene *scene = CTX_data_scene(C);
1241 ViewLayer *view_layer = CTX_data_view_layer(C);
1242
1244 CTX_wm_manager(C), us->scene_ref.ptr, &scene, &view_layer);
1246 scene, view_layer, &us->elems[0].obedit_ref.ptr, us->elems_len, sizeof(*us->elems));
1247
1249
1250 for (uint i = 0; i < us->elems_len; i++) {
1251 MeshUndoStep_Elem *elem = &us->elems[i];
1252 Object *obedit = elem->obedit_ref.ptr;
1253 Mesh *mesh = id_cast<Mesh *>(obedit->data);
1254 if (mesh->runtime->edit_mesh == nullptr) {
1255 /* Should never fail, may not crash but can give odd behavior. */
1256 CLOG_ERROR(&LOG,
1257 "name='%s', failed to enter edit-mode for object '%s', undo state invalid",
1258 us_p->name,
1259 obedit->id.name);
1260 continue;
1261 }
1262 BMEditMesh *em = mesh->runtime->edit_mesh.get();
1264 &elem->data, em, &mesh->vertex_group_names, &mesh->vertex_group_active_index);
1265
1266 obedit->shapenr = em->bm->shapenr;
1267
1268 em->needs_flush_to_id = 1;
1270 }
1271
1272 /* The first element is always active */
1274 *bmain, scene, view_layer, us->elems[0].obedit_ref.ptr, us_p->name, &LOG);
1275
1276 /* Check after setting active (unless undoing into another scene). */
1278
1279 /* NOTE: Changes here must be accounted for:
1280 * - With properties flags, since tool-settings disables undo for all members by default,
1281 * #PROP_FORCE_UNDO needs to be enabled for these settings.
1282 * - #ED_undo_is_legacy_compatible_for_property
1283 * which disables undo for all non-mesh ID's in edit-mode.
1284 */
1285 {
1286 /* Follow settings related to selection.
1287 * While other flags could be included too: it's important the user doesn't
1288 * undo into a state where the scene settings would show a different selection
1289 * to the selection the user was previously editing. */
1290 constexpr eTool_UvFlag uv_flag_undo = UV_FLAG_SELECT_SYNC | UV_FLAG_SELECT_ISLAND;
1291
1292 ToolSettings *ts = scene->toolsettings;
1293 const MeshUndoStep_SceneData &scene_data = us->scene_data;
1294 ts->selectmode = scene_data.selectmode;
1295 ts->uv_selectmode = scene_data.uv_selectmode;
1296 ts->uv_sticky = scene_data.uv_sticky;
1297 ts->uv_flag = (ts->uv_flag & ~uv_flag_undo) | (scene_data.uv_flag & uv_flag_undo);
1298 }
1299
1300 bmain->is_memfile_undo_flush_needed = true;
1301
1303}
1304
1306{
1307 MeshUndoStep *us = reinterpret_cast<MeshUndoStep *>(us_p);
1308
1309 for (uint i = 0; i < us->elems_len; i++) {
1310 MeshUndoStep_Elem *elem = &us->elems[i];
1311 undomesh_free_data(&elem->data);
1312 }
1313 MEM_delete(us->elems);
1314}
1315
1317 UndoTypeForEachIDRefFn foreach_ID_ref_fn,
1318 void *user_data)
1319{
1320 MeshUndoStep *us = reinterpret_cast<MeshUndoStep *>(us_p);
1321
1322 foreach_ID_ref_fn(user_data, (reinterpret_cast<UndoRefID *>(&us->scene_ref)));
1323 for (uint i = 0; i < us->elems_len; i++) {
1324 MeshUndoStep_Elem *elem = &us->elems[i];
1325 foreach_ID_ref_fn(user_data, (reinterpret_cast<UndoRefID *>(&elem->obedit_ref)));
1326 }
1327}
1328
1343
1345
1346} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
General operations, lookup, etc. for blender objects.
Efficient in-memory storage of multiple similar arrays.
Generic array manipulation API.
#define BLI_array_is_zeroed(arr, arr_len)
#define BLI_SCOPED_DEFER(function_to_defer)
Utility defines for timing/benchmarks.
#define TIMEIT_START(var)
#define TIMEIT_END(var)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define BMALLOC_TEMPLATE_FROM_ME(...)
#define CD_MASK_SHAPE_KEYINDEX
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
int64_t size() const
Definition BLI_map.hh:976
void reserve(int64_t n)
Definition BLI_map.hh:1028
Value pop_default(const Key &key, const Value &default_value)
Definition BLI_map.hh:439
Value & lookup_or_add(const Key &key, const Value &value)
Definition BLI_map.hh:588
Span< Value > lookup(const Key &key) const
constexpr MutableSpan()=default
int64_t size() const
void append(const T &value)
#define ARRAY_CHUNK_NUM_MIN
#define ARRAY_CHUNK_SIZE_IN_BYTES
#define ARRAY_STORE_INDEX_NUM
#define attribute(slot)
#define layer
const int state
std::optional< eCustomDataType > attr_type_to_custom_data_type(AttrType attr_type)
Mesh * mesh_new_no_attributes(int verts_num, int edges_num, int faces_num, int corners_num)
void free_shared_data(T **data, const ImplicitSharingInfo **sharing_info)
const ImplicitSharingInfo * info_for_mem_free(T *data)
void parallel_invoke(Functions &&...functions)
Definition BLI_task.hh:197
BMesh Iterators.
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static BArrayCustomData * um_arraystore_cd_create(CustomData *cdata, Span< bke::Attribute * > attributes, const size_t data_len, const int bs_index, const BArrayCustomData *bcd_reference)
@ ARRAY_STORE_INDEX_POLY
@ ARRAY_STORE_INDEX_LOOP
@ ARRAY_STORE_INDEX_EDGE
@ ARRAY_STORE_INDEX_POLY_OFFSETS
@ ARRAY_STORE_INDEX_SHAPE
@ ARRAY_STORE_INDEX_VERT
@ ARRAY_STORE_INDEX_MSEL
void BLI_array_store_state_remove(BArrayStore *bs, BArrayState *state)
struct BArrayStore * BLI_array_store_at_size_get(struct BArrayStore_AtSize *bs_stride, int stride)
@ BM_SPACEARR_DIRTY_ALL
unsigned int uint
Definition BKE_text.h:55
bool BM_mesh_uvselect_is_valid(BMesh *bm, const int cd_loop_uv_offset, const bool check_sync, const bool check_flush, const bool check_contiguous, UVSelectValidateInfo *info_p)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
@ UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE
@ UNDOTYPE_FLAG_ENCODE_PRE_MEMFILE_SUPPORTED
static bool mesh_undosys_step_encode(bContext *C, Main *bmain, UndoStep *us_p)
struct BArrayStore * BLI_array_store_at_size_ensure(struct BArrayStore_AtSize *bs_stride, int stride, int chunk_size)
static size_t array_chunk_size_calc(const size_t stride)
@ TASK_PRIORITY_LOW
Definition BLI_task_c.hh:60
static void um_arraystore_cd_clear(CustomData *cdata)
void ED_undo_object_set_active_or_warn(const Main &bmain, Scene *scene, ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
Definition ed_undo.cc:1024
BArrayState * BLI_array_store_state_add(BArrayStore *bs, const void *data, size_t data_len, const BArrayState *state_reference)
BMEditMesh * BKE_editmesh_create(BMesh *bm)
Definition editmesh.cc:30
static void um_arraystore_cd_expand(const BArrayCustomData *bcd, CustomData *cdata, Span< bke::Attribute * > attributes, const size_t data_len)
MINLINE int power_of_2_max_i(int n)
static void um_arraystore_compact_with_info(UndoMesh *um, const UndoMesh *um_ref)
static bool um_customdata_layer_use_rle(const eCustomDataType type)
static Object * editmesh_object_from_context(bContext *C)
int CustomData_sizeof(eCustomDataType type)
static void um_arraystore_cd_free(BArrayCustomData *bcd, const int bs_index)
Vector< Object * > ED_undo_editmode_objects_from_view_layer(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
Definition ed_undo.cc:1109
static void um_arraystore_expand_clear(UndoMesh *um)
bool BM_mesh_is_valid(BMesh *bm)
void MEM_delete_void(void *vmemh)
void * BLI_array_store_state_data_get_alloc(const BArrayState *state, size_t *r_data_len)
@ LIB_ID_COPY_LOCALIZE
@ LIB_ID_COPY_NO_ANIMDATA
ViewLayer * CTX_data_view_layer(const bContext *C)
uint8_t * BLI_array_store_rle_encode(const uint8_t *data_dec, size_t data_dec_len, size_t data_enc_extra_size, size_t *r_data_enc_len)
void BLI_task_pool_work_and_wait(TaskPool *pool)
Definition task_pool.cc:455
static bool mesh_undosys_poll(bContext *C)
void BLI_array_store_at_size_calc_memory_usage(const struct BArrayStore_AtSize *bs_stride, size_t *r_size_expanded, size_t *r_size_compacted)
void EDBM_mesh_free_data(BMEditMesh *em)
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *mesh, const BMeshFromMeshParams *params)
Mesh -> BMesh.
static void um_arraystore_expand(UndoMesh *um)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
static uint8_t * get_arraystore_data(const BArrayState *state, const size_t data_len, const eCustomDataType type)
void ED_mesh_undosys_type(UndoType *ut)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
Object * BKE_view_layer_edit_object_get(const ViewLayer *view_layer)
void DEG_id_tag_update(ID *id, unsigned int flags)
BMesh const char void * data
wmWindowManager * CTX_wm_manager(const bContext *C)
unsigned char uint8_t
Definition BKE_text.h:79
static void um_arraystore_compact(UndoMesh *um, const UndoMesh *um_ref)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void BKE_editmesh_looptris_and_normals_calc(BMEditMesh *em, BMesh *bm)
Definition editmesh.cc:122
static void * undomesh_from_editmesh(UndoMesh *um, BMEditMesh *em, Key *key, const ListBaseT< bDeformGroup > *vertex_group_names, const int vertex_group_active_index, UndoMesh *um_ref)
void BKE_id_free(Main *bmain, void *idv)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static MultiValueMap< bke::AttrDomain, bke::Attribute * > get_attributes_by_domain(Mesh &mesh)
void BLI_task_pool_free(TaskPool *pool)
Definition task_pool.cc:441
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
static void mesh_undosys_foreach_ID_ref(UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
static struct blender::@371041351336020310265046031215105036126137144353 um_arraystore
void BLI_array_store_at_size_clear(struct BArrayStore_AtSize *bs_stride)
static void undomesh_to_editmesh(UndoMesh *um, BMEditMesh *em, ListBaseT< bDeformGroup > *vertex_group_names, int *vertex_group_active_index)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
static UndoMesh ** mesh_undostep_reference_elems_from_objects(Object **object, int object_len)
static void mesh_undosys_step_decode(bContext *C, Main *bmain, UndoStep *us_p, const eUndoStepDir, bool)
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
Definition deform.cc:75
static CLG_LogRef LOG
Definition logging.cpp:12
void ED_undo_object_editmode_restore_helper(Scene *scene, ViewLayer *view_layer, Object **object_array, uint object_array_len, uint object_array_stride)
Definition ed_undo.cc:1064
static void um_arraystore_compact_cb(TaskPool *__restrict, void *taskdata)
void(*)(void *user_data, UndoRefID *id_ref) UndoTypeForEachIDRefFn
Scene * CTX_data_scene(const bContext *C)
static void store_layer(const eCustomDataType type, const void *data, const ImplicitSharingInfo *sharing_info, const size_t data_len, const int bs_index, const BArrayCustomData *bcd_reference, Map< eCustomDataType, int > &index_in_type, BArrayCustomData &bcd)
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParams *params)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
void BLI_array_store_rle_decode(const uint8_t *data_enc, const size_t data_enc_len, void *data_dec_v, const size_t data_dec_len)
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
BMesh Make Mesh.
void BLI_task_pool_push(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
Definition task_pool.cc:446
static void undomesh_free_data(UndoMesh *um)
bool CustomData_layertype_is_dynamic(eCustomDataType type)
static void um_arraystore_free(UndoMesh *um)
void ED_undo_object_editmode_validate_scene_from_windows(wmWindowManager *wm, const Scene *scene_ref, Scene **scene_p, ViewLayer **view_layer_p)
Definition ed_undo.cc:1047
static void mesh_undosys_step_free(UndoStep *us_p)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
TaskPool * BLI_task_pool_create_background(void *userdata, eTaskPriority priority)
Definition task_pool.cc:409
Map< eCustomDataType, Vector< BArrayState * > > trivial_arrays
Map< eCustomDataType, Vector< ImplicitSharingInfoAndData > > non_trivial_arrays
struct CustomData_MeshMasks cd_mask_extra
char name[258]
Definition DNA_ID.h:433
unsigned int session_uid
Definition DNA_ID.h:463
struct KeyBlock * next
bool is_memfile_undo_flush_needed
Definition BKE_main.hh:302
UndoRefID_Scene scene_ref
MeshUndoStep_Elem * elems
MeshUndoStep_SceneData scene_data
ListBaseT< bDeformGroup > vertex_group_names
int vertex_group_active_index
struct Key * key
struct ToolSettings * toolsettings
eTool_UvSelectMode uv_selectmode
const UndoMesh * um_ref
struct blender::UndoMesh::@074033166222353333153373215135331131330176206323 store
bool(*) poll(bContext *C)
void(*) step_free(UndoStep *us)
void(*) step_decode(bContext *C, Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final)
void(*) step_foreach_ID_ref(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
bool(*) step_encode(bContext *C, Main *bmain, UndoStep *us)
const char * identifier
ListBaseT< UndoMesh > local_links
BArrayStore_AtSize bs_stride[ARRAY_STORE_INDEX_NUM]