Blender V5.0
sculpt_undo.cc File Reference
#include "sculpt_undo.hh"
#include <mutex>
#include <zstd.h>
#include "CLG_log.h"
#include "BLI_array.hh"
#include "BLI_bit_group_vector.hh"
#include "BLI_compression.hh"
#include "BLI_enumerable_thread_specific.hh"
#include "BLI_listbase.h"
#include "BLI_map.hh"
#include "BLI_memory_counter.hh"
#include "BLI_string_utf8.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
#include "DNA_key_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "BKE_attribute.hh"
#include "BKE_attribute_legacy_convert.hh"
#include "BKE_ccg.hh"
#include "BKE_context.hh"
#include "BKE_customdata.hh"
#include "BKE_global.hh"
#include "BKE_key.hh"
#include "BKE_layer.hh"
#include "BKE_main.hh"
#include "BKE_mesh.hh"
#include "BKE_multires.hh"
#include "BKE_object.hh"
#include "BKE_paint.hh"
#include "BKE_paint_types.hh"
#include "BKE_scene.hh"
#include "BKE_subdiv_ccg.hh"
#include "BKE_undo_system.hh"
#include "BKE_subdiv_eval.hh"
#include "DEG_depsgraph.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "ED_geometry.hh"
#include "ED_object.hh"
#include "ED_sculpt.hh"
#include "ED_undo.hh"
#include "bmesh.hh"
#include "mesh_brush_common.hh"
#include "paint_hide.hh"
#include "sculpt_color.hh"
#include "sculpt_dyntopo.hh"
#include "sculpt_face_set.hh"
#include "sculpt_intern.hh"

Go to the source code of this file.

Classes

struct  blender::ed::sculpt_paint::undo::Node
struct  blender::ed::sculpt_paint::undo::SculptAttrRef
struct  blender::ed::sculpt_paint::undo::NodeGeometry
struct  blender::ed::sculpt_paint::undo::StepData
struct  blender::ed::sculpt_paint::undo::PositionUndoStorage
struct  blender::ed::sculpt_paint::undo::SculptUndoStep

Namespaces

namespace  blender
namespace  blender::ed
namespace  blender::ed::sculpt_paint
namespace  blender::ed::sculpt_paint::undo
namespace  blender::ed::sculpt_paint::undo::compression

Macros

#define NO_ACTIVE_LAYER   bke::AttrDomain::Auto

Functions

template<typename T>
void blender::ed::sculpt_paint::undo::compression::filter_compress (const Span< T > src, Vector< std::byte > &filter_buffer, Vector< std::byte > &compress_buffer)
template<typename T>
void blender::ed::sculpt_paint::undo::compression::filter_decompress (const Span< std::byte > src, Vector< std::byte > &buffer, Vector< T > &dst)
template void blender::ed::sculpt_paint::undo::compression::filter_compress< float3 > (Span< float3 >, Vector< std::byte > &, Vector< std::byte > &)
template void blender::ed::sculpt_paint::undo::compression::filter_compress< int > (Span< int >, Vector< std::byte > &, Vector< std::byte > &)
template void blender::ed::sculpt_paint::undo::compression::filter_decompress< float3 > (Span< std::byte >, Vector< std::byte > &, Vector< float3 > &)
template void blender::ed::sculpt_paint::undo::compression::filter_decompress< int > (Span< std::byte >, Vector< std::byte > &, Vector< int > &)
size_t blender::ed::sculpt_paint::undo::step_memory_size_get (UndoStep *step)
static SculptUndoStepblender::ed::sculpt_paint::undo::get_active_step ()
static StepDatablender::ed::sculpt_paint::undo::get_step_data ()
static bool blender::ed::sculpt_paint::undo::use_multires_undo (const StepData &step_data, const SculptSession &ss)
static bool blender::ed::sculpt_paint::undo::topology_matches (const StepData &step_data, const Object &object)
static bool blender::ed::sculpt_paint::undo::indices_contain_true (const Span< bool > data, const Span< int > indices)
static bool blender::ed::sculpt_paint::undo::restore_active_shape_key (bContext &C, Depsgraph &depsgraph, const StepData &step_data, Object &object)
template<typename T>
static void blender::ed::sculpt_paint::undo::swap_indexed_data (MutableSpan< T > full, const Span< int > indices, MutableSpan< T > indexed)
static void blender::ed::sculpt_paint::undo::restore_position_mesh (Object &object, PositionUndoStorage &undo_data, const MutableSpan< bool > modified_verts)
static void blender::ed::sculpt_paint::undo::restore_position_grids (const MutableSpan< float3 > positions, const CCGKey &key, PositionUndoStorage &undo_data, const MutableSpan< bool > modified_grids)
static void blender::ed::sculpt_paint::undo::restore_vert_visibility_mesh (Object &object, Node &unode, const MutableSpan< bool > modified_verts)
static void blender::ed::sculpt_paint::undo::restore_vert_visibility_grids (SubdivCCG &subdiv_ccg, Node &unode, const MutableSpan< bool > modified_grids)
static void blender::ed::sculpt_paint::undo::restore_hidden_face (Object &object, Node &unode, const MutableSpan< bool > modified_faces)
static void blender::ed::sculpt_paint::undo::restore_color (Object &object, StepData &step_data, const MutableSpan< bool > modified_verts)
static void blender::ed::sculpt_paint::undo::restore_mask_mesh (Object &object, Node &unode, const MutableSpan< bool > modified_verts)
static void blender::ed::sculpt_paint::undo::restore_mask_grids (Object &object, Node &unode, const MutableSpan< bool > modified_grids)
static bool blender::ed::sculpt_paint::undo::restore_face_sets (Object &object, Node &unode, const MutableSpan< bool > modified_face_set_faces)
static void blender::ed::sculpt_paint::undo::bmesh_restore_generic (StepData &step_data, Object &object)
static void blender::ed::sculpt_paint::undo::bmesh_enable (Object &object, const StepData &step_data)
static void blender::ed::sculpt_paint::undo::bmesh_handle_dyntopo_begin (bContext *C, StepData &step_data, Object &object)
static void blender::ed::sculpt_paint::undo::bmesh_handle_dyntopo_end (bContext *C, StepData &step_data, Object &object)
static void blender::ed::sculpt_paint::undo::store_geometry_data (NodeGeometry *geometry, const Object &object)
static void blender::ed::sculpt_paint::undo::restore_geometry_data (const NodeGeometry *geometry, Mesh *mesh)
static void blender::ed::sculpt_paint::undo::geometry_free_data (NodeGeometry *geometry)
static void blender::ed::sculpt_paint::undo::restore_geometry (StepData &step_data, Object &object)
static int blender::ed::sculpt_paint::undo::bmesh_restore (bContext *C, Depsgraph &depsgraph, StepData &step_data, Object &object)
void blender::ed::sculpt_paint::undo::restore_from_bmesh_enter_geometry (const StepData &step_data, Mesh &mesh)
bool blender::ed::sculpt_paint::undo::has_bmesh_log_entry ()
static void blender::ed::sculpt_paint::undo::refine_subdiv (Depsgraph *depsgraph, const SculptSession &ss, Object &object, bke::subdiv::Subdiv *subdiv)
static void blender::ed::sculpt_paint::undo::restore_list (bContext *C, Depsgraph *depsgraph, StepData &step_data)
static void blender::ed::sculpt_paint::undo::free_step_data (StepData &step_data)
static const Nodeblender::ed::sculpt_paint::undo::get_node (const bke::pbvh::Node *node, const Type type)
static void blender::ed::sculpt_paint::undo::store_vert_visibility_grids (const SubdivCCG &subdiv_ccg, const bke::pbvh::GridsNode &node, Node &unode)
static void blender::ed::sculpt_paint::undo::store_positions_mesh (const Depsgraph &depsgraph, const Object &object, Node &unode)
static void blender::ed::sculpt_paint::undo::store_positions_grids (const SubdivCCG &subdiv_ccg, Node &unode)
static void blender::ed::sculpt_paint::undo::store_vert_visibility_mesh (const Mesh &mesh, const bke::pbvh::Node &node, Node &unode)
static void blender::ed::sculpt_paint::undo::store_face_visibility (const Mesh &mesh, Node &unode)
static void blender::ed::sculpt_paint::undo::store_mask_mesh (const Mesh &mesh, Node &unode)
static void blender::ed::sculpt_paint::undo::store_mask_grids (const SubdivCCG &subdiv_ccg, Node &unode)
static void blender::ed::sculpt_paint::undo::store_color (const Mesh &mesh, const bke::pbvh::MeshNode &node, Node &unode)
static NodeGeometryblender::ed::sculpt_paint::undo::geometry_get (StepData &step_data)
static void blender::ed::sculpt_paint::undo::geometry_push (const Object &object)
static void blender::ed::sculpt_paint::undo::store_face_sets (const Mesh &mesh, Node &unode)
static void blender::ed::sculpt_paint::undo::fill_node_data_mesh (const Depsgraph &depsgraph, const Object &object, const bke::pbvh::MeshNode &node, const Type type, Node &unode)
static void blender::ed::sculpt_paint::undo::fill_node_data_grids (const Object &object, const bke::pbvh::GridsNode &node, const Type type, Node &unode)
static BLI_NOINLINE void blender::ed::sculpt_paint::undo::bmesh_push (const Object &object, const bke::pbvh::BMeshNode *node, Type type)
static Nodeblender::ed::sculpt_paint::undo::ensure_node (StepData &step_data, const bke::pbvh::Node &node, bool &r_new)
void blender::ed::sculpt_paint::undo::push_node (const Depsgraph &depsgraph, const Object &object, const bke::pbvh::Node *node, const Type type)
void blender::ed::sculpt_paint::undo::push_nodes (const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const Type type)
static void blender::ed::sculpt_paint::undo::save_active_attribute (Object &object, SculptAttrRef *attr)
static void blender::ed::sculpt_paint::undo::save_common_data (Object &ob, SculptUndoStep *us)
void blender::ed::sculpt_paint::undo::push_begin_ex (const Scene &, Object &ob, const char *name)
void blender::ed::sculpt_paint::undo::push_begin (const Scene &scene, Object &ob, const wmOperator *op)
void blender::ed::sculpt_paint::undo::push_enter_sculpt_mode (const Scene &, Object &ob, const wmOperator *op)
static size_t blender::ed::sculpt_paint::undo::node_size_in_bytes (const Node &node)
void blender::ed::sculpt_paint::undo::push_end_ex (Object &ob, const bool use_nested_undo)
void blender::ed::sculpt_paint::undo::push_end (Object &ob)
std::optional< OrigPositionDatablender::ed::sculpt_paint::orig_position_data_lookup_mesh_all_verts (const Object &object, const bke::pbvh::MeshNode &node)
std::optional< OrigPositionDatablender::ed::sculpt_paint::orig_position_data_lookup_mesh (const Object &object, const bke::pbvh::MeshNode &node)
std::optional< OrigPositionDatablender::ed::sculpt_paint::orig_position_data_lookup_grids (const Object &object, const bke::pbvh::GridsNode &node)
void blender::ed::sculpt_paint::orig_position_data_gather_bmesh (const BMLog &bm_log, const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions, MutableSpan< float3 > normals)
std::optional< Span< float4 > > blender::ed::sculpt_paint::orig_color_data_lookup_mesh (const Object &object, const bke::pbvh::MeshNode &node)
std::optional< Span< int > > blender::ed::sculpt_paint::orig_face_set_data_lookup_mesh (const Object &object, const bke::pbvh::MeshNode &node)
std::optional< Span< int > > blender::ed::sculpt_paint::orig_face_set_data_lookup_grids (const Object &object, const bke::pbvh::GridsNode &node)
std::optional< Span< float > > blender::ed::sculpt_paint::orig_mask_data_lookup_mesh (const Object &object, const bke::pbvh::MeshNode &node)
std::optional< Span< float > > blender::ed::sculpt_paint::orig_mask_data_lookup_grids (const Object &object, const bke::pbvh::GridsNode &node)
Implements ED Undo System
static void blender::ed::sculpt_paint::undo::set_active_layer (bContext *C, const SculptAttrRef *attr)
static void blender::ed::sculpt_paint::undo::step_encode_init (bContext *, UndoStep *us_p)
static bool blender::ed::sculpt_paint::undo::step_encode (bContext *, Main *bmain, UndoStep *us_p)
static void blender::ed::sculpt_paint::undo::step_decode_undo_impl (bContext *C, Depsgraph *depsgraph, SculptUndoStep *us)
static void blender::ed::sculpt_paint::undo::step_decode_redo_impl (bContext *C, Depsgraph *depsgraph, SculptUndoStep *us)
static void blender::ed::sculpt_paint::undo::step_decode_undo (bContext *C, Depsgraph *depsgraph, SculptUndoStep *us, const bool is_final)
static void blender::ed::sculpt_paint::undo::step_decode_redo (bContext *C, Depsgraph *depsgraph, SculptUndoStep *us)
static void blender::ed::sculpt_paint::undo::step_decode (bContext *C, Main *bmain, UndoStep *us_p, const eUndoStepDir dir, const bool is_final)
static void blender::ed::sculpt_paint::undo::step_free (UndoStep *us_p)
void blender::ed::sculpt_paint::undo::geometry_begin (const Scene &scene, Object &ob, const wmOperator *op)
void blender::ed::sculpt_paint::undo::geometry_begin_ex (const Scene &scene, Object &ob, const char *name)
static size_t blender::ed::sculpt_paint::undo::calculate_node_geometry_allocated_size (const NodeGeometry &node_geometry)
static size_t blender::ed::sculpt_paint::undo::estimate_geometry_step_size (const StepData &step_data)
void blender::ed::sculpt_paint::undo::geometry_end (Object &ob)
void blender::ed::sculpt_paint::undo::register_type (UndoType *ut)
Multires + Base Mesh Undo

Example of a relevant operator is Apply Base.

Usage:

static int operator_exec((bContext *C, wmOperator *op) {

ed::sculpt_paint::undo::push_multires_mesh_begin(C, op->type->name); // Modify base mesh. ed::sculpt_paint::undo::push_multires_mesh_end(C, op->type->name);

return OPERATOR_FINISHED; }

If object is not in Sculpt mode or there is no active multires object, ED_undo_push is used instead.

static bool blender::ed::sculpt_paint::undo::use_multires_mesh (bContext *C)
void blender::ed::sculpt_paint::undo::push_multires_mesh_begin (bContext *C, const char *str)
void blender::ed::sculpt_paint::undo::push_multires_mesh_end (bContext *C, const char *str)

Variables

static CLG_LogRef LOG = {"undo.sculpt"}

Detailed Description

Implements the Sculpt Mode undo system.

Usage Guide

The sculpt undo system is a delta-based system. Each undo step stores the difference with the prior one.

To use the sculpt undo system, you must call #push_begin inside an operator exec or invoke callback (#geometry_begin may be called if you wish to save a non-delta copy of the entire mesh). This will initialize the sculpt undo stack and set up an undo step.

At the end of the operator you should call #push_end.

#push_begin and #geometry_begin both take a wmOperatorType as an argument. There are _ex versions that allow a custom name; try to avoid using them. These can break the redo panel since it requires the undo push to have the same name as the calling operator.

Definition in file sculpt_undo.cc.

Macro Definition Documentation

◆ NO_ACTIVE_LAYER

#define NO_ACTIVE_LAYER   bke::AttrDomain::Auto

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"undo.sculpt"}
static

Definition at line 94 of file sculpt_undo.cc.