Blender V5.3
editmesh_undo.cc File Reference
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
#include "DNA_key_types.h"
#include "DNA_layer_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_array_utils_c.hh"
#include "BLI_implicit_sharing.hh"
#include "BLI_listbase.hh"
#include "BLI_math_base_c.hh"
#include "BLI_multi_value_map.hh"
#include "BLI_string.hh"
#include "BLI_task.hh"
#include "BLI_vector.hh"
#include "BKE_attribute_legacy_convert.hh"
#include "BKE_context.hh"
#include "BKE_customdata.hh"
#include "BKE_deform.hh"
#include "BKE_editmesh.hh"
#include "BKE_key.hh"
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_mesh.hh"
#include "BKE_object.hh"
#include "BKE_undo_system.hh"
#include "DEG_depsgraph.hh"
#include "ED_mesh.hh"
#include "ED_object.hh"
#include "ED_undo.hh"
#include "ED_util.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "BLI_array_store.hh"
#include "BLI_array_store_utils.hh"
#include "BLI_task_c.hh"

Go to the source code of this file.

Classes

struct  blender::BArrayCustomData
struct  blender::UndoMesh
struct  blender::UMArrayData
struct  blender::MeshUndoStep_Elem
struct  blender::MeshUndoStep_SceneData
struct  blender::MeshUndoStep

Namespaces

namespace  blender
 BMesh Iterators.

Macros

#define USE_ARRAY_STORE
#define ARRAY_CHUNK_SIZE_IN_BYTES   65536
#define ARRAY_CHUNK_NUM_MIN   256
#define USE_ARRAY_STORE_THREAD
#define USE_ARRAY_STORE_RLE

Functions

Undo Conversion
static size_t blender::array_chunk_size_calc (const size_t stride)
static bool blender::um_customdata_layer_use_rle (const eCustomDataType type)
Array Store Utilities
static UndoMesh ** blender::mesh_undostep_reference_elems_from_objects (Object **object, int object_len)
Undo/Redo Helper Functions
static void * blender::undomesh_from_editmesh (UndoMesh *um, BMEditMesh *em, Key *key, const ListBaseT< bDeformGroup > *vertex_group_names, const int vertex_group_active_index, UndoMesh *um_ref)
static void blender::undomesh_to_editmesh (UndoMesh *um, BMEditMesh *em, ListBaseT< bDeformGroup > *vertex_group_names, int *vertex_group_active_index)
static void blender::undomesh_free_data (UndoMesh *um)
static Object * blender::editmesh_object_from_context (bContext *C)
Implements ED Undo System
static bool blender::mesh_undosys_poll (bContext *C)
static bool blender::mesh_undosys_step_encode (bContext *C, Main *bmain, UndoStep *us_p)
static void blender::mesh_undosys_step_decode (bContext *C, Main *bmain, UndoStep *us_p, const eUndoStepDir, bool)
static void blender::mesh_undosys_step_free (UndoStep *us_p)
static void blender::mesh_undosys_foreach_ID_ref (UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
void blender::ED_mesh_undosys_type (UndoType *ut)

Variables

static CLG_LogRef blender::LOG = {"undo.mesh"}

Array Store

#define ARRAY_STORE_INDEX_NUM   (ARRAY_STORE_INDEX_MSEL + 1)
enum  {
  blender::ARRAY_STORE_INDEX_VERT = 0 , blender::ARRAY_STORE_INDEX_EDGE , blender::ARRAY_STORE_INDEX_LOOP , blender::ARRAY_STORE_INDEX_POLY ,
  blender::ARRAY_STORE_INDEX_POLY_OFFSETS , blender::ARRAY_STORE_INDEX_SHAPE , blender::ARRAY_STORE_INDEX_MSEL
}
static struct  blender::um_arraystore = {{{nullptr}}}
static void blender::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)
static BArrayCustomData * blender::um_arraystore_cd_create (CustomData *cdata, Span< bke::Attribute * > attributes, const size_t data_len, const int bs_index, const BArrayCustomData *bcd_reference)
static void blender::um_arraystore_cd_clear (CustomData *cdata)
static uint8_t * blender::get_arraystore_data (const BArrayState *state, const size_t data_len, const eCustomDataType type)
static void blender::um_arraystore_cd_expand (const BArrayCustomData *bcd, CustomData *cdata, Span< bke::Attribute * > attributes, const size_t data_len)
static void blender::um_arraystore_cd_free (BArrayCustomData *bcd, const int bs_index)
static MultiValueMap< bke::AttrDomain, bke::Attribute * > blender::get_attributes_by_domain (Mesh &mesh)
static void blender::um_arraystore_compact (UndoMesh *um, const UndoMesh *um_ref)
static void blender::um_arraystore_expand_clear (UndoMesh *um)
static void blender::um_arraystore_compact_with_info (UndoMesh *um, const UndoMesh *um_ref)
static void blender::um_arraystore_compact_cb (TaskPool *__restrict, void *taskdata)
static void blender::um_arraystore_expand (UndoMesh *um)
static void blender::um_arraystore_free (UndoMesh *um)

Macro Definition Documentation

◆ ARRAY_CHUNK_NUM_MIN

#define ARRAY_CHUNK_NUM_MIN   256

Definition at line 73 of file editmesh_undo.cc.

Referenced by blender::array_chunk_size_calc().

◆ ARRAY_CHUNK_SIZE_IN_BYTES

#define ARRAY_CHUNK_SIZE_IN_BYTES   65536

This used to be much smaller (256), but this caused too much overhead when selection moved to boolean arrays. Especially with high-poly meshes where managing a large number of small chunks could be slow, blocking user interactivity. Use a larger value (in bytes) which calculates the chunk size using #array_chunk_size_calc. See: #105046 & #105205.

Definition at line 72 of file editmesh_undo.cc.

Referenced by blender::array_chunk_size_calc().

◆ ARRAY_STORE_INDEX_NUM

#define ARRAY_STORE_INDEX_NUM   (ARRAY_STORE_INDEX_MSEL + 1)

◆ USE_ARRAY_STORE

#define USE_ARRAY_STORE

Definition at line 54 of file editmesh_undo.cc.

◆ USE_ARRAY_STORE_RLE

#define USE_ARRAY_STORE_RLE

Use run length encoding for boolean custom-data.

Avoid poor performance caused by boolean arrays not having enough uniqueness to efficiently de-duplicate, see: #136737.

NOTE(@ideasman42): This has the down-side that creating undo steps needs to encode data before comparing it with the previous state (when creating each undo step). Adding additional work even when nothing change.

Since there is overhead for RLE encoding this is only used on boolean array, typically used for storing selection/hidden state as well as edge flags. The encoding has also been optimized for performance instead of "compression" which would pack bits into the smallest possible space.

In practice, arrays of 32 million booleans (on an AMD TRX 3990X):

  • ~0.11 seconds for random data.
  • ~0.0025 seconds uniform arrays. ... so the tradeoff seems reasonable.

There is also the benefit of reduced memory use, although that isn't the goal.

Definition at line 99 of file editmesh_undo.cc.

◆ USE_ARRAY_STORE_THREAD

#define USE_ARRAY_STORE_THREAD

Definition at line 75 of file editmesh_undo.cc.