Shape Key editing: propagate updates through basis chains #105422

Closed
Alexander Gavrilov wants to merge 1 commits from angavrilov:pr-shapekey-propagate into main

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

It is possible to organize shape keys into a tree through the
reference key setting. Mesh editing and sculpting a reference
key is supposed to update all its children, but this was only
done for one level of dependencies.

This adds a function that finds all dependent keys through
a breadth first search (this avoids any issues with cycles),
and updates the relevant code to use it.


The attached file can be used for testing: it has an object with three shape keys that form a dependency chain.

Without this patch editing the Basis (though sculpt or edit mode) and then enabling the third key cancels out the new changes because the modifications were not propagated.

It is possible to organize shape keys into a tree through the reference key setting. Mesh editing and sculpting a reference key is supposed to update all its children, but this was only done for one level of dependencies. This adds a function that finds all dependent keys through a breadth first search (this avoids any issues with cycles), and updates the relevant code to use it. ----------- The attached file can be used for testing: it has an object with three shape keys that form a dependency chain. Without this patch editing the Basis (though sculpt or edit mode) and then enabling the third key cancels out the new changes because the modifications were not propagated.
Alexander Gavrilov requested review from Campbell Barton 2023-03-03 23:15:05 +01:00
Alexander Gavrilov requested review from Bastien Montagne 2023-03-03 23:15:13 +01:00
Alexander Gavrilov requested review from Joseph Eagar 2023-03-03 23:15:27 +01:00
Hans Goudey changed title from Shape Key editing: propagate updates through basis chains. to Shape Key editing: propagate updates through basis chains 2023-03-03 23:19:10 +01:00
Bastien Montagne refused to review 2023-03-07 16:36:14 +01:00
Bastien Montagne added this to the Modeling project 2023-03-07 16:36:22 +01:00

Not really active in the Mesh/Modelling area nowadays, so will remove myself from here.

Also in general it's better to assign a project to a PR, than directly reviewers, unless you have already talked about the patch with them and they agreed to review it.

Not really active in the Mesh/Modelling area nowadays, so will remove myself from here. Also in general it's better to assign a project to a PR, than directly reviewers, unless you have already talked about the patch with them and they agreed to review it.
Member

Also removing myself. Might want to ping @howardt about it.

Also removing myself. Might want to ping @howardt about it.
Joseph Eagar refused to review 2023-03-10 00:48:45 +01:00
Hans Goudey requested changes 2023-04-06 16:18:11 +02:00
Hans Goudey left a comment
Member

I have no idea about the logic of this shape key stuff, but maybe I can help get some of the typical code cleanup stuff out of the way.

I have no idea about the logic of this shape key stuff, but maybe I can help get some of the typical code cleanup stuff out of the way.
@ -182,2 +182,4 @@
bool BKE_keyblock_is_basis(const struct Key *key, int index);
/**
* Returns an array containing true for every key that has this one as basis.
Member

an array -> an allocated array

Would just help to write down that it's supposed to be freed

`an array` -> `an allocated array` Would just help to write down that it's supposed to be freed
angavrilov marked this conversation as resolved
@ -2594,2 +2594,4 @@
return false;
}
bool *BKE_keyblock_get_dependent_keys(const struct Key *key, int index)
Member

const struct Key *key, int index -> const Key *key, const int index

`const struct Key *key, int index` -> `const Key *key, const int index`
angavrilov marked this conversation as resolved
@ -2596,0 +2596,4 @@
bool *BKE_keyblock_get_dependent_keys(const struct Key *key, int index)
{
/* Simple checks. */
Member

I don't think this Simple checks. comment is adding anything here. Such early return condition checking is not exactly out of the ordinary, and the fact that they're "simple" is already obvious from looking at the code.

I don't think this `Simple checks.` comment is adding anything here. Such early return condition checking is not exactly out of the ordinary, and the fact that they're "simple" is already obvious from looking at the code.
angavrilov marked this conversation as resolved
@ -2596,0 +2608,4 @@
}
/* Seed the table with the specified key. */
bool *marked = static_cast<bool *>(MEM_callocN(sizeof(bool) * count, __func__));
Member

This is a C++ file, might as well use Array or BitVector here

This is a C++ file, might as well use `Array` or `BitVector` here
Author
Member

It's returned to the function caller, which still includes C code.

It's returned to the function caller, which still includes C code.
@ -2596,0 +2621,4 @@
updated = 0;
for (i = 0, kb = static_cast<const KeyBlock *>(key->block.first); kb; i++, kb = kb->next) {
Member

Use the LISTBASE_FOREACH_INDEX macro

Use the `LISTBASE_FOREACH_INDEX` macro
angavrilov marked this conversation as resolved
@ -2596,0 +2634,4 @@
MEM_freeN(marked);
return nullptr;
}
else {
Member

else after return

else after return
angavrilov marked this conversation as resolved
@ -852,2 +855,3 @@
LISTBASE_FOREACH (KeyBlock *, currkey, &key->block) {
int currkey_i;
Member

I think this newline between the index declaration and the loop is just wasting space, it doesn't really help readability

I think this newline between the index declaration and the loop is just wasting space, it doesn't really help readability
angavrilov marked this conversation as resolved
@ -951,6 +955,7 @@ static void bm_to_mesh_shape(BMesh *bm,
if (ofs) {
MEM_freeN(ofs);
MEM_freeN(dependent);
Member

Are ofs and dependent always allocated together? That doesn't seem obvious looking at the code (though it totally might be the case!). A simple MEM_SAFE_FREE(dependent); at the end would be a little simpler though.

Are `ofs` and `dependent` always allocated together? That doesn't seem obvious looking at the code (though it totally might be the case!). A simple `MEM_SAFE_FREE(dependent);` at the end would be a little simpler though.
angavrilov marked this conversation as resolved
Alexander Gavrilov force-pushed pr-shapekey-propagate from 7cfa71a2ff to dca49a5bff 2023-07-14 19:39:33 +02:00 Compare
Alexander Gavrilov requested review from Hans Goudey 2023-07-14 20:33:06 +02:00
Brecht Van Lommel approved these changes 2023-07-18 14:17:19 +02:00
Brecht Van Lommel left a comment
Owner

Looks good to me.

Looks good to me.
Author
Member

Forgot to add the Pull Request line to d32748cdf4.

Forgot to add the Pull Request line to d32748cdf47dd20ea.

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
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
5 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#105422
No description provided.