Animation: Armature symmetrize ebones refactor #106487

Manually merged
Sybren A. Stüvel merged 5 commits from cgtinker/blender:symmetrize-refactoring into main 2023-05-15 11:09:36 +02:00
Contributor

This patch removes some nested if-statements to improve readablilty - there is no functional change. My main intention has been to improve readability and therefore making it easier to implement changes in the future.

Seperating the symmetrize operator selection logic from the temp pointer logic may reduces performance but it seems acceptable in this case. The change allows focussing on the selection logic without taking care of the temp pointers at the same time.

This patch removes some nested `if-statements` to improve readablilty - there is no functional change. My main intention has been to improve readability and therefore making it easier to implement changes in the future. Seperating the symmetrize operator selection logic from the temp pointer logic may reduces performance but it seems acceptable in this case. The change allows focussing on the selection logic without taking care of the temp pointers at the same time.
Denys Hsu added 1 commit 2023-04-03 11:45:23 +02:00
Sybren A. Stüvel added the
Module
Animation & Rigging
label 2023-04-07 12:50:53 +02:00
Sybren A. Stüvel added this to the Animation & Rigging project 2023-04-07 12:51:12 +02:00
Sybren A. Stüvel reviewed 2023-04-07 12:52:16 +02:00
Sybren A. Stüvel changed title from WIP: Animation: Armature symmetrize ebones refactor to Animation: Armature symmetrize ebones refactor 2023-04-07 12:54:42 +02:00
Sybren A. Stüvel requested review from Sybren A. Stüvel 2023-04-07 12:54:53 +02:00
Sybren A. Stüvel requested changes 2023-04-07 13:08:55 +02:00
Sybren A. Stüvel left a comment
Member

I think this refactor is a much-needed improvement, thanks.

Seperating the symmetrize operator selection logic from the temp pointer logic may reduces performance but it seems acceptable in this case. The change allows focussing on the selection logic without taking care of the temp pointers at the same time.

I 100% agree with the separation of concerns, but I do have a few concerns myself about the resulting code.

The name comparison (STREQ(name_flip, ebone_iter->name)): in the original code, this was used to entirely skip the handling of the bone. Now it only skips the deselection, but not the setting of the temp pointer.

The logic of skipping invisible/deselected bones is now also duplicated.

How about this?

  • Move the 'can we even mirror this?' logic (the name comparison) back into the loop in armature_symmetrize_exec().
  • Change ED_armature_set_symmetrizable_ebone_selection to handle a single bone only, and call it from within the above loop.

I think that would address things.

I think this refactor is a much-needed improvement, thanks. > Seperating the symmetrize operator selection logic from the temp pointer logic may reduces performance but it seems acceptable in this case. The change allows focussing on the selection logic without taking care of the temp pointers at the same time. I 100% agree with the separation of concerns, but I do have a few concerns myself about the resulting code. The name comparison (`STREQ(name_flip, ebone_iter->name)`): in the original code, this was used to entirely skip the handling of the bone. Now it only skips the deselection, but not the setting of the temp pointer. The logic of skipping invisible/deselected bones is now also duplicated. How about this? - Move the 'can we even mirror this?' logic (the name comparison) back into the loop in `armature_symmetrize_exec()`. - Change `ED_armature_set_symmetrizable_ebone_selection` to handle a single bone only, and call it from within the above loop. I think that would address things.
@ -1089,6 +1096,71 @@ static EditBone *get_symmetrized_bone(bArmature *arm, EditBone *bone)
return (mirror != NULL) ? mirror : bone;
}
static void ED_armature_set_symmetrizable_ebone_selection(bArmature *arm, int axis, int direction)

No need to have an ED_armature prefix, those are only for functions that are declared in the header files (and thus part of Blender's internal API).

Also axis and direction can be declared as const int.

No need to have an `ED_armature` prefix, those are only for functions that are declared in the header files (and thus part of Blender's internal API). Also `axis` and `direction` can be declared as `const int`.
@ -1199,3 +1229,3 @@
BLI_string_flip_side_name(name_flip, ebone_iter->name, false, sizeof(name_flip));
/* bones must have a side-suffix */
/* mirrored bones must have a side-suffix */

Comments nowadays should be a full sentence, so start with a capital and end with a period. Touching is fixing ;-)

Comments nowadays should be a full sentence, so start with a capital and end with a period. Touching is fixing ;-)
Denys Hsu added 1 commit 2023-04-07 17:14:46 +02:00
Denys Hsu added 1 commit 2023-04-07 17:24:18 +02:00
Author
Contributor

At first a tried to move only the selection part to a seperate method but it leads to issues. When both bones are selected and if the ebone_iter gets deselected no temp pointer gets set.

That's why I've been rerunning the "is selected / visible" logic at first. To reduce the overhead I decided to move it back in the main loop and set the temp ptr reference in the last step which kinda seperates it.

Having a method which deselects bones and returns a bool if a ptr should be set seems odd...

At first a tried to move only the selection part to a seperate method but it leads to issues. When both bones are selected and if the ebone_iter gets deselected no temp pointer gets set. That's why I've been rerunning the "is selected / visible" logic at first. To reduce the overhead I decided to move it back in the main loop and set the temp ptr reference in the last step which kinda seperates it. Having a method which deselects bones and returns a bool if a ptr should be set seems odd...
Sybren A. Stüvel reviewed 2023-04-11 16:00:48 +02:00
@ -1176,0 +1189,4 @@
}
/* Set temp pointer to mirrored ebones */
if (ebone) {

When you're here in the code, ebone is guaranteed to be non-NULL.
And even if it were to be NULL, setting ebone_iter->temp.ebone = NULL in that case also wouldn't hurt.

When you're here in the code, `ebone` is guaranteed to be non-`NULL`. And even if it were to be `NULL`, setting `ebone_iter->temp.ebone = NULL` in that case also wouldn't hurt.
Author
Contributor

Right, I've overlooked that, thanks.

Right, I've overlooked that, thanks.

At first a tried to move only the selection part to a seperate method but it leads to issues. When both bones are selected and if the ebone_iter gets deselected no temp pointer gets set.

That's why I've been rerunning the "is selected / visible" logic at first. To reduce the overhead I decided to move it back in the main loop and set the temp ptr reference in the last step which kinda seperates it.

Having a method which deselects bones and returns a bool if a ptr should be set seems odd...

I agree, it would look like the wrong abstraction/grouping of logic to me. Basically the code does:

  • Does the bone have mirrored counterpart?
  • NO: deselect & continue to the next bone.
  • YES: continue the loop body.

So indeed, having the first point and half of the second in one function would be odd.

> At first a tried to move only the selection part to a seperate method but it leads to issues. When both bones are selected and if the ebone_iter gets deselected no temp pointer gets set. > > That's why I've been rerunning the "is selected / visible" logic at first. To reduce the overhead I decided to move it back in the main loop and set the temp ptr reference in the last step which kinda seperates it. > Having a method which deselects bones and returns a bool if a ptr should be set seems odd... I agree, it would look like the wrong abstraction/grouping of logic to me. Basically the code does: - Does the bone have mirrored counterpart? - NO: deselect & continue to the next bone. - YES: continue the loop body. So indeed, having the first point and half of the second in one function would be odd.
Sybren A. Stüvel requested changes 2023-04-11 16:06:46 +02:00
Sybren A. Stüvel left a comment
Member

There's plenty of other improvements you could make to the original code, but I think the more important thing is to make just those improvements that make #105385 trivial to do. If after that you feel like more cleaning up, that's excellent for another PR :)

If you could just look at the removal of that if, then I think this PR is in good shape to get merged.

There's plenty of other improvements you could make to the original code, but I think the more important thing is to make just those improvements that make #105385 trivial to do. If after that you feel like more cleaning up, that's excellent for another PR :) If you could just look at the removal of that `if`, then I think this PR is in good shape to get merged.
Denys Hsu added 1 commit 2023-04-19 17:25:40 +02:00
Denys Hsu requested review from Sybren A. Stüvel 2023-04-19 17:35:02 +02:00
Author
Contributor

There's plenty of other improvements you could make to the original code, but I think the more important thing is to make just those improvements that make #105385 trivial to do. If after that you feel like more cleaning up, that's excellent for another PR :)

If you could just look at the removal of that if, then I think this PR is in good shape to get merged.

Can it get merged?
Then I'd fix #105385

> There's plenty of other improvements you could make to the original code, but I think the more important thing is to make just those improvements that make #105385 trivial to do. If after that you feel like more cleaning up, that's excellent for another PR :) > > If you could just look at the removal of that `if`, then I think this PR is in good shape to get merged. Can it get merged? Then I'd fix #105385
Sybren A. Stüvel approved these changes 2023-05-12 12:09:29 +02:00
Sybren A. Stüvel left a comment
Member

Thanks!

Thanks!
Sybren A. Stüvel added 1 commit 2023-05-12 12:10:17 +02:00
Sybren A. Stüvel manually merged commit aaf56d7aa5 into main 2023-05-15 11:09:36 +02:00
Sybren A. Stüvel removed this from the Animation & Rigging project 2023-05-15 11:37:31 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:40 +02:00
Sign in to join this conversation.
No reviewers
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
2 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#106487
No description provided.