Mirroring Objects does not mirror all selected objects
Closed, ArchivedPublic

Description

If i select a bunch of objects and mirror them around the 3D cursor (in center (0,0,0)) along the y axis then some objects get mirrored, but some don't.

I appended a example file. If you select all objects, except the armature, and mirror them along y then some objects will be correctly mirrored, some not.

Philipp Oeser (lichtwerk) added a comment.Via Old WorldAug 3 2012, 4:01 PM

Not sure if this is really a bug

You've got "childof" constraints on all of these objects which cause the problem.
If you delete these constraints prior to mirroring everything should be fine. Seems to me you would have to change the constraints to point to another bone after mirroring anyways - so you could as well delete them before?

Mirror seems to apply a negative scaling on the object (not object data) and the constraints seem to prevent mirror from applying the negative scaling. This is also true if scaling options are disabled in the constraint and even if the constraints influence is set to zero. However, if you dont have the constraints there at all, everything is fine. Will have a look at the operator and investigate further...

Tobias Oelgarte (niabot) added a comment.Via Old WorldAug 3 2012, 4:20 PM

I just wondered why some objects are correctly mirrored and some don't. Yes i would have re-targeted the constraints anyway. But it usually much faster to mirror and rename (L -> R) as to remove all constraints and to add them again.

Sergey Sharybin (sergey) added a comment.Via Old WorldAug 6 2012, 10:41 AM

Developer note:
Mirror is indeed a negative scale which is being applied on a object. The funny stuff begins when object has got constraints -- some of them requires special way of handling this situations.
What's happening here is that if object has got constraints constraintSizeLim is being called. This function converts scale to mat4 which tries to be applied on Size Limit constraint and matrix conversion between space happens. Later, this matrix is being converted back to scale vector. That's where fail happens -- mat4_to_size does not deal with negative scale.
Could think about workaround which would avoid this transformation when there's no Size Limit constraint, but it could still fail in more complicated set ups. Probably using some assumptions about constraint matrix it'll help to decompose it back to scale smoother, not sure yet.

Bastien, would you like to look into this deeper? This doesn't look difficult and your help would really be appreciated here :)

Bastien Montagne (mont29) added a comment.Via Old WorldAug 14 2012, 12:44 PM

I’m giving it a try on my spare free time, and it turns ugly (as usual with constraints :/).

Actually, the problem is not *only* in constraintSizeLim, transform.c’s ElementResize() also uses a special TransMat3ToSize() func to extract (signed!) size from a matrix (which could be moved to BLI, btw), and it looks like here also it’s not working as expected (sometimes returning sizes like (-1, -1, -1) when it should only be (1, -1, 1))…

Still investigating, but all that transform/constraint code is an awful piece of code!

Brecht Van Lommel (brecht) added a comment.Via Old WorldAug 22 2012, 1:16 PM

I didn't investigate the file here, but note that extracting negative scale from a matrix is not a well defined problem. For example a scale of (-1, -1, -1) will result in the same matrix as scale of (-1, 1, 1) + a rotation of (180, 0, 0).

Brecht Van Lommel (brecht) added a comment.Via Old WorldDec 3 2012, 3:10 PM

Forgot to mention it here, but I committed a fix for part of the problem. This makes the mirror work ok for local Y, and for all objects except one for global Y.

The TransMat3ToSize functions seems to have an issue still ... I also don't understand the logic used in tx_vec_sign_flip here, I'm not sure what that method is based on.

Tobias Oelgarte (niabot) added a comment.Via Old WorldDec 3 2012, 3:51 PM

Would it not just be enough to insert four virtual points inside the local coordinate system of the object, transform them into world space coordinates, mirror them along the mirror plane and then to reconstruct a materix for this new coordinate system?

The points are: (0,0,0) [center], (1,0,0) [unit x], (0,1,0) [unit y], (0,0,1) [unit z].
After transforming them to world space coordinates, they can be mirrored (like in edit mode) and then it should be possible to reconstruct an transformation matrix for this coordinate system. It might be only one of infinite possible solutions, but at least it gives the expected visual result. After that there can be still some efforts made by the user himself or an improved algorithm.

That would be a solution that works at least in most cases.

Brecht Van Lommel (brecht) added a comment.Via Old WorldDec 4 2012, 10:24 AM

I think the main issue here is keeping the rotation and scale compatible. The mirror tool only affects scale, and as I mentioned above there is no single way to decompose scale and rotation, so we need to ensure that the scale is compatible with the rotation of the object when we set it.

Anyway, it's not very difficult to fix this probably, just need to take some time to verify what all the matrices are doing here.

Ton Roosendaal (ton) added a comment.Via Old WorldFeb 16 2013, 6:03 PM

Tracker cleaning: Added it to the wiki todo
http://wiki.blender.org/index.php/Dev:2.5/Source/Development/Todo/Animation#Constraints

Child-of constraint has plenty of issues reported... it's a weak method.

Ton Roosendaal (ton) closed this task as "Archived".Via Old WorldFeb 16 2013, 6:03 PM

Add Comment