Page MenuHome

Fix T66751: Symmetrizing armature does not symmetrize constraints.
ClosedPublic

Authored by Sebastian Parborg (zeddb) on Oct 7 2019, 3:54 PM.

Details

Summary

The symmetrize operator now tries to make sure that the armature constraints are correctly mirrored.

Before it would only mirror the subtargets for the constraints (and that failed too in some cases).

Diff Detail

Repository
rB Blender

Event Timeline

Sebastian Parborg (zeddb) edited the summary of this revision. (Show Details)

Just a heads up: We've found some issues with this so I'll work a bit more on it before it is actually ready for review

Sybren A. Stüvel (sybren) set the repository for this revision to rB Blender.Oct 29 2019, 6:14 PM

I'm assuming that the // TODO comments aren't going to be part of the commit.

source/blender/editors/armature/armature_add.c
380

There used to be a comment here with a bit of explanation of what parameter is what. I think that's still a good idea here (but possibly a completely different comment because behaviour changed).

447

End sentences with a period. The comment could also be put on two lines, I'm guessing.

453

This block is indented too much. If pchan == NULL or conlist == NULL you can just return. This saves two indent levels.

456

This should be a switch statement, and not a sequence of if/elseif.
Every case should be its own properly-named function, with clearly named parameters.

461

The next code block (i.e. empty-line-delimited bit of code) doesn't mirror anything, so the comment is a bit weird here.

471

What does it mean to "represent X"? This code seems to find the matrix row with the largest first value, but it's not clear why this is even relevant.

480

Where is this mapped? What defines those values? Where do they come from? So many magic numbers.

512

Why not write min_vec[0] = -min_vec[0]? Or write min_vec[0] *= -1? Personally I prefer the latter, as it's clear at first glance that it's only taking the negative (so no swapping min/max or changing the index).

531

Just declare int i as part of the for-loop (so for (int i=0; ...). Outside of a for-loop it's a rather horribly-named variable.

580

act doesn't change within the for-loop, so you can do the DEG update outside the loop.

598

Unclear why the 'min vector' and 'max vector' are relevant concepts at all.

600

Bit of a weird choice in empty lines here, possibly better grouping possible?

812

Same as above, just do if (ob->pose == NULL) { return; }

1144

Same as before, probably can use continue here. Patch wasn't submitted with Arcanist, so I can't see outside it (no context available), so maybe this is not the case.

source/blender/editors/armature/armature_add.c
562–564

Just *= -1 those

588

It's not clamping, it's modulo'ing. And yes, that's a good thing to do. In a separate function, in BLI_whatevermath.

Once working on it anyway, you may want to add two normalisation functions, one producing a result on the interval [-180°, 180°), and one on [0°, 360°).

594

Add something like "This code assumes that bRotLimitConstraint and bLocLimitConstraint have the same fields in the same memory locations."

Possibly it would be prudent to add a similar warning to the types themselves, pointing back at this code.

596

Don't use mat or imat, but give them a descriptive name, something that is a bit closer to "constraint space conversion matrix".

656

tar → target

own, imat → something more descriptive

675

Why not just = -old_max?

712

Don't name things temp, but describe what it is. The fact that it's here in an if in a loop in an if already shows that's temporary.

Declaring where it's needed and then naming descriptively ('copy of scale' is likely better than 'temp vector') is better.

737

switch!

741–742

You could even go further and de-uglify it locally a bit by #define AXIS_X 0 and the like (or use a const char for that). That way at least we have some understandable word there, instead of just a 0.

862

Code style: use underscore instead of camel case

Sebastian Parborg (zeddb) marked 21 inline comments as done.Mar 4 2020, 3:06 PM
Sebastian Parborg (zeddb) added inline comments.
source/blender/editors/armature/armature_add.c
380

The previous comment here was clarify what src_ob and dst_ob was used for.

Now this function simply does what the name suggests, it updates the bone duplicate constraint sub-target.
I don't think this need any further explanation as it would be akin to:

/* add 'a' and 'b' together  and return the result */
float add(float a, float b)
480

This is copy pasted from other parts of the animation system in blender.

If we wish to update this, it should be done in a separate commit.

531

This is because I can't initialize both i and bezt in the for loop then.

I have moved down the declaration to just above the loop instead to make it better.

598

This is so we can easily transform the min/max values of the constraint.

600

Grouped by min/max values. I don't see any better grouping here.

712

In this case, the variable is used to store values temporary.

It stores loc/rot/scale data depending on how the constraint is mapped.

1144

Can't use continue here. I have resubmitted the new revision of the patch with context.

Sebastian Parborg (zeddb) marked 7 inline comments as done.

Fixed most of the feedback comments.

I'm guessing you will have more comments, so I'll submit this new revision to get the ball rolling again.

Sebastian Parborg (zeddb) updated this revision to Diff 22378.EditedMar 4 2020, 4:44 PM

Added a two liner fix for T73980. I guess that the issue could be merged into T66751.

The fix was the following:

if (ebone->head[0] != 0.0f) {
  /* The mirrored bone doesn't start on the mirror axis, so assume that this one should
   * not be connected to the old parent */
  ebone->flag &= ~BONE_CONNECTED;
}
source/blender/editors/armature/armature_add.c
1243

Shouldn't this use head[axis] instead?

Sebastian Parborg (zeddb) marked 3 inline comments as done.

Updated based on the latest comments.

Sebastian Parborg (zeddb) marked an inline comment as done.Mar 23 2020, 4:38 PM
Sebastian Parborg (zeddb) added inline comments.
source/blender/editors/armature/armature_add.c
656

This is what the spaces are called in the constraints themselves.
So I think that these are descriptive enough.

1243

Right you are!

LGTM, assuming you did thorough testing with the example file in T66751 and some others ;-)

This revision is now accepted and ready to land.Apr 7 2020, 10:52 AM

Updated the patch to apply to master (needed to update a comment string).