Skip to content

Commit

Permalink
Fix T44415: Shape keys get out of sync when using undo in edit-mode
Browse files Browse the repository at this point in the history
This is an alternate fix for T35170 since it caused T44415.
Having the undo system manipulate the key-block coordinates is error
prone as (in the case of T44415) there are situations when it's
important to apply the difference with the original shape key.

This reverts dab0bd9, and instead
avoids the problem by not using the data in `Mesh.key` as a reference
for updating shape-keys when exiting edit-mode.

The assumption that the `Mesh.key` in edit-mode won't be modified
until leaving edit-mode isn't always true. Leading to synchronization
errors. (details noted in code-comments).

Resolve this by using shape-key data stored in the BMesh.

Resolving both T35170 & T44415.

Details:

- Remove use of the original vertices when exiting edit mode.
- Remove use of the original shape-key coordinates when exiting
  edit-mode (except as a last resort).
- Move shape-key synchronization into a separate function:
  `bm_to_mesh_key`.
- Split the synchronization loop into two branches,
  depending on the existence of BMesh shape-key coordinates.
- Always write shape-key values back to the BMesh CD_SHAPEKEY layers.
  This was only done in some cases but is now necessary for all
  shape-keys as these are used to calculate offsets where the `Mesh.key`
  was previously used.
- Report a warning when the shape-key layer isn't found as this uses an
  imperfect method of restoring coordinates which should only be used as
  a last resort.

Reviewed By: mont29

Ref D14127
  • Loading branch information
ideasman42 committed Feb 21, 2022
1 parent c3d36b7 commit bfdbc78
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 190 deletions.
1 change: 1 addition & 0 deletions source/blender/bmesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(INC
../depsgraph
../makesdna
../../../intern/atomic
../../../intern/clog
../../../intern/eigen
../../../intern/guardedalloc
../../../extern/rangetree
Expand Down
Loading

0 comments on commit bfdbc78

Please sign in to comment.