Fix undo overreach in various paint modes for #69760 and related. #117417

Open
Alexander Gavrilov wants to merge 1 commits from angavrilov/blender:pr-undo-fixes into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

This tries to fix undo overreach on selection of vertex groups,
shape keys, uv maps, colors and attributes in various modes.

  • The Vertex Paint mode is now a subtype of Sculpt, so it should
    use a sculpt undo step on entering the mode, and property changes
    shouldn't write undo steps.
  • Sculpt undo modes were deliberately over-undoing color attribute
    selection changes for some reason.
  • The Texture Paint mode always writes texture steps, so saving
    steps for property changes is simply pointless.
  • The Weight Paint mode uses memfile, so it should save steps
    for property changes, except for those excluded from undo,
    e.g. by bc0a6b0400.
  • If a memfile undo step happens anyway for some reason in sculpt
    and vertex paint modes, immediately following property changes
    to object and mesh datablocks should also push to avoid over-undo
    if the immediately following scuplt step is reverted (unrelated
    ones like materials or scene seem safe).

This fix addresses these cases:

Prepare Change
(should push undo)
Change
(should not push undo)
Test
(should not undo the change)
Enter Weight Paint Mode Object viewport visibility,
Collection viewport visibility,
Active vertex group. [1]
Brush settings,
Tool settings (e.g. Auto-Normalize)
Paint single stroke, Undo.
Enter Sculpt Mode Active vertex group,
Active shape key,
Active vertex color,
Object viewport visibility,
Collection viewport visibility,
Brush/tool settings.
Sculpt single stroke, Undo.[3]
Enter Sculpt Mode,
Use a non-sculpt operator
(e.g. Mirror Shape Key)
Active vertex group,
Active shape key,
Active vertex color.[2]
Object viewport visibility,
Collection viewport visibility,
Brush/tool settings.
Sculpt single stroke, Undo.
Enter Vertex Paint Mode Active vertex color[4] Paint single stroke, Undo.[3]
Enter Vertex Paint Mode,
Use a non-sculpt operator
(e.g. Mirror Shape Key)
Active vertex color.[2] Paint single stroke, Undo.
  1. Weight paint cases are fixed by changes in ed_undo.cc
  2. Sculpt with operator cases are fixed by changes in interface_handler.cc
  3. Active vertex color in Sculpt and Vertex Paint is fixed by the removal in sculpt_undo.cc
  4. Without changes in paint_vertex.cc, the action of entering Vertex Paint Mode itself counts as a 'non-sculpt operator'.

Note: internally Sculpt and Vertex Paint are essentially the same and only differ in the shown set of tools.

This tries to fix undo overreach on selection of vertex groups, shape keys, uv maps, colors and attributes in various modes. - The Vertex Paint mode is now a subtype of Sculpt, so it should use a sculpt undo step on entering the mode, and property changes shouldn't write undo steps. - Sculpt undo modes were deliberately over-undoing color attribute selection changes for some reason. - The Texture Paint mode always writes texture steps, so saving steps for property changes is simply pointless. - The Weight Paint mode uses memfile, so it should save steps for property changes, except for those excluded from undo, e.g. by bc0a6b0400. - If a memfile undo step happens anyway for some reason in sculpt and vertex paint modes, immediately following property changes to object and mesh datablocks should also push to avoid over-undo if the immediately following scuplt step is reverted (unrelated ones like materials or scene seem safe). ------------------ This fix addresses these cases: | Prepare | Change<br>(should push undo) | Change<br>(should not push undo) | Test<br>(should not undo the change) | | :---: | :---: | :---: | :---: | | Enter Weight Paint Mode | _Object viewport visibility,<br>Collection viewport visibility,<br>Active vertex group. [1]_ | Brush settings,<br>Tool settings (e.g. Auto-Normalize) | Paint single stroke, Undo. | | Enter Sculpt Mode | | Active vertex group,<br>Active shape key,<br>Active vertex color,<br>Object viewport visibility,<br>Collection viewport visibility,<br>Brush/tool settings. | _Sculpt single stroke, Undo.[3]_ | | Enter Sculpt Mode,<br>Use a non-sculpt operator<br>(e.g. Mirror Shape Key) | _Active vertex group,<br>Active shape key,<br>Active vertex color.[2]_ | Object viewport visibility,<br>Collection viewport visibility,<br>Brush/tool settings. | Sculpt single stroke, Undo. | | Enter Vertex Paint Mode | | _Active vertex color[4]_ | _Paint single stroke, Undo.[3]_ | | Enter Vertex Paint Mode,<br>Use a non-sculpt operator<br>(e.g. Mirror Shape Key) | _Active vertex color.[2]_ | | Paint single stroke, Undo. | 1. Weight paint cases are fixed by changes in ed_undo.cc 2. Sculpt with operator cases are fixed by changes in interface_handler.cc 3. Active vertex color in Sculpt and Vertex Paint is fixed by the removal in sculpt_undo.cc 4. Without changes in paint_vertex.cc, the action of entering Vertex Paint Mode itself counts as a 'non-sculpt operator'. Note: internally Sculpt and Vertex Paint are essentially the same and only differ in the shown set of tools.
Alexander Gavrilov requested review from Sybren A. Stüvel 2024-01-22 18:08:30 +01:00
Alexander Gavrilov added the
Interest
Undo
label 2024-01-23 12:26:16 +01:00
Sybren A. Stüvel reviewed 2024-01-23 14:12:52 +01:00
Sybren A. Stüvel left a comment
Member

I haven't been able to do a functional code review, or try out the changes for myself. As for the code changes, there's a few trivial inline notes.

I haven't been able to do a functional code review, or try out the changes for myself. As for the code changes, there's a few trivial inline notes.
@ -837,2 +837,4 @@
ED_object_vpaintmode_enter_ex(bmain, depsgraph, scene, ob);
BKE_paint_toolslots_brush_validate(bmain, &ts->vpaint->paint);
if (ob->mode & mode_flag) {

This comparison is already stored in is_mode_set. The else clause that contains this code is only run when !is_mode_set, so things get confusing. Add a comment that states that vpaintmode was just entered, and thus the object flags have to be checked again.


(here are just some ponderings that I wanted to share; the actual feedback on this change is above this line)

I actually think that this doubly checking and deeper nesting of the code makes things too complex. For this PR I understand you want to make a minimal change, but the resulting code IMO stretches things a bit too far. BUT, looking at the current code outside of the part that this PR touched, it was IMO already too complex, so let's not bother this PR with that.

Off-topic, this is what I'd do:

  • Move the call to mesh = BKE_mesh_from_object() down to where the mesh is actually used.
  • Replace the use of (Mesh *)ob->data with mesh so that there is one consistent way to refer to the mesh.
  • Merge the if (!is_mode_set) and if (is_mode_set) conditionals, so that there is just one "enter" and one "exit" code path.
This comparison is already stored in `is_mode_set`. The `else` clause that contains this code is only run when `!is_mode_set`, so things get confusing. Add a comment that states that vpaintmode was just entered, and thus the object flags have to be checked again. ----------- (here are just some ponderings that I wanted to share; the actual feedback on this change is above this line) I actually think that this doubly checking and deeper nesting of the code makes things too complex. For this PR I understand you want to make a minimal change, but the resulting code IMO stretches things a bit too far. BUT, looking at the current code outside of the part that this PR touched, it was IMO already too complex, so let's not bother this PR with that. Off-topic, this is what I'd do: - Move the call to `mesh = BKE_mesh_from_object()` down to where the mesh is actually used. - Replace the use of `(Mesh *)ob->data` with `mesh` so that there is one consistent way to refer to the mesh. - Merge the `if (!is_mode_set)` and `if (is_mode_set)` conditionals, so that there is just one "enter" and one "exit" code path.
@ -839,0 +839,4 @@
if (ob->mode & mode_flag) {
/* Without this the memfile undo step is used,
* while it works it causes lag when undoing the first undo step, see T71564. */

This mentions an issue in the old Phabricator notation, so better to change that to #71564. This seems to have been copied from source/blender/editors/sculpt_paint/sculpt_ops.cc, which was already changed to this notation.

This mentions an issue in the old Phabricator notation, so better to change that to `#71564`. This seems to have been copied from `source/blender/editors/sculpt_paint/sculpt_ops.cc`, which was already changed to this notation.
@ -462,0 +483,4 @@
*
* Most other property change undo pushes will be also suppressed
* by another check later unless preceeded by a memfile push;
* however these properties should always be blocked. */

👍 thanks for leaving this as a comment, it helps so much to understand this interdependency with other behaviours.

I wouldn't mind having a mention of the location in the code where this other check can be found. The downside would be that it's a non-code reference to code that could get out of date at some point, so use your own instinct to decide whether to add this or not.

:+1: thanks for leaving this as a comment, it helps so much to understand this interdependency with other behaviours. I wouldn't mind having a mention of the location in the code where this other check can be found. The downside would be that it's a non-code reference to code that could get out of date at some point, so use your own instinct to decide whether to add this or not.

PS: I think it would be good to have someone from the Sculpt/Paint/Texture module as a reviewer as well.

PS: I think it would be good to have someone from the Sculpt/Paint/Texture module as a reviewer as well.
Alexander Gavrilov requested review from Philipp Oeser 2024-01-24 16:53:52 +01:00
Member

Thx for this.

Will honestly take me a bit of time to get up to speed again with the different UndoType, but seeing a refinement on 4a08b974f4 is certainly nice. Again, please allow a bit of time (at least for me) to dig a little deeper (for example, I am now wondering why bc0a6b0400 was even necessary after 4a08b974f4), but I am interested for sure.

So I might not be the ideal candidate to review this, maybe @ideasman42 is?

Thx for this. Will honestly take me a bit of time to get up to speed again with the different `UndoType`, but seeing a refinement on 4a08b974f44e is certainly nice. Again, please allow a bit of time (at least for me) to dig a little deeper (for example, I am now wondering why bc0a6b0400 was even necessary after 4a08b974f44e), but I am interested for sure. So I might not be the ideal candidate to review this, maybe @ideasman42 is?
This pull request has changes conflicting with the target branch.
  • source/blender/editors/sculpt_paint/paint_vertex.cc

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u pr-undo-fixes:angavrilov-pr-undo-fixes
git checkout angavrilov-pr-undo-fixes
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#117417
No description provided.