From 06cb321f337fdff0cb71814d955c6f929c8d354c Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 31 Mar 2020 15:34:39 +0200 Subject: Sculpt: Give a brief explanation of undo stack Should make it a bit more clear overview of what is going on in this module. While some of the details might still be missing, having some sort of top-level overview is better than nothing. Differential Revision: https://developer.blender.org/D7300 --- source/blender/editors/sculpt_paint/sculpt_undo.c | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index bb463d29f1c..cccc5e29ba7 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -67,6 +67,45 @@ #include "bmesh.h" #include "sculpt_intern.h" +/* Implementation of undo system for objects in sculpt mode. + * + * Each undo step in sculpt mode consists of list of nodes, each node contains: + * - Node type + * - Data for this type. + * + * Node type used for undo depends on specific operation and active sculpt mode + * ("regular" or dynamic topology). + * + * Regular sculpt brushes will use COORDS, HIDDEN or MASK nodes. These nodes are + * created for every BVH node which is affected by the brush. The undo push for + * the node happens BEFORE modifications. This makes the operation undo to work + * in the following way: for every node in the undo step swap happens between + * node in the undo stack and the corresponding value in the BVH. This is how + * redo is possible after undo. + * + * The COORDS, HIDDEN or MASK type of nodes contains arrays of the corresponding + * values. + * + * Operations like Symmetrize are using GEOMETRY type of nodes which pushes the + * entire state of the mesh to the undo stack. This node contains all CustomData + * layers. + * + * The tricky aspect of this undo node type is that it stores mesh before and + * after modification. This allows the undo system to both undo and redo the + * symmetrize operation within the pre-modified-push of other node type + * behavior, but it uses more memory that it seems it should be. + * + * The dynamic topology undo nodes are handled somewhat separately from all + * other ones and the idea there is to store log of operations: which verticies + * and faces have been added or removed. + * + * Begin of dynamic topology sculpting mode have own node type. It contains an + * entire copy of mesh since just enabling the dynamic topology mode already + * does modifications on it. + * + * End of dynamic topology and symmetrize in this mode are handled in a special + * manner as well. */ + typedef struct UndoSculpt { ListBase nodes; -- cgit v1.2.3