mirrorize pose bones. Quaternion problem.

Hello,

After a moment searching internet how the fuck i could mirrorize a left sided bone position to the corresponding right sided bone, i realised that i would have to do my own script for it.

Then, i realized (after a lot of effort finding the correct way to find a potential mirror) that we cant just “set” head or tail positions of pose bones, we got to set rotations for it.

Then, i realized, than to find a bone quaternion mirror, some times changing just someposebone.rotation_quaternion[1] by, -someposebone.rotation_quaternion[1] isnt effective in all cases, changing two values isnt efficive too, some times we got to swap two values to get the mirrored, other times just a minus somewhere is ok.

SO…

i started to become crazy x)

and i decided to search for every possible change, if one correspond to the desired mirror (looking if the pose_bone_mirror.vector, was the mirror of the someposebone.vector), but, then, i realised, that blender changes that vector only after execution, not while the script is running…

SO, i dediced to apply and check the rotation on the pose_bone_mirror.bone.tail_local - pose_bone_mirror.bone.head_local instead, comparating to the vector,

but… i realised before comming crazy again, than even just rotate the someposebone.bone.tail_local - someposebone.bone.head_local by someposebone.rotation_quaternion, doesnt give us the same vector as someposebone.vector

-_-’

my head has started burning already.

So i tried to multiply the someposebone.vector by someposebone.matrix , i tried .matrix_basis, i tried .matrix_channel, but cant fucking figure out how the fuck blender apply its quaternion to the pose_bone.

My heart tell me to investigate more, but my head is a fuckin firework right now.

TO RESUME:

How can we obtain someposebone.vector from: someposebone.bone.tail, someposebone.bone.head, someposebone.rotation_quaternion. ?

if you got a clue, your the better of the better.

Anyway, thank you by advance.

Are you on Pose mode or Edit mode?

In Pose mode mirroring might not be properly supported (I do some tests now and transformations seem awkward).

However in Edit mode things look better.
by executing the mirror operator you can see the immediate effect.

This is copied from the information window.
bpy.ops.transform.mirror(constraint_axis=(True, False, False), constraint_orientation=‘GLOBAL’, proportional=‘DISABLED’, proportional_edit_falloff=‘SMOOTH’, proportional_size=1)

There could be some math solution as well, but in favor of the mirror operator it seem much better option.