like the topic says, how to properly create mirror rotation for pose bone?
I’d like to use mirror rotations similar to what one can do with pose copy paste, but from Python, without using ops. I can get mirrored position and rotation using something like this with matrix, but it will ruin the scale:
I don’t specifically need to use matrices to do this, as I’m not very familiar with them, but it used to work fine in 3ds Max for example… with existing helper methods… and in general, it makes it easy to do the mirroring in object space (like flipping legs while walking diagonally relative to world main axes).
I am currently not working or coding in Blender, but here is some gawd-awful function I created several years back for my automatic animation program that maybe you can figure out by playing around with it, it is a short function, the input parameters are pretty clear, so it may fit the purpose:
# Rotate the easy way
def rotate(bipedStrName, str_bone_name, rad=0, axis=0):
bpy.ops.object.mode_set(mode='POSE')
ob = bpy.context.object
euler = ob.pose.bones[str_bone_name]
euler.rotation_mode = 'XYZ'
bpy.data.objects[bipedStrName].pose.bones[str_bone_name].rotation_euler[axis] = rad
You will notice the “=” sign in the parameters, those are default values, as I recall. Also, one of the tricks I use to use to get the opposite action was just use the same code, but use the negative sign on the rotation. The code for the automatic animation is on my github website, you may find other gems there: https://github.com/Skywola/anim I am currently non-active in this particular line of work, so you are pretty much on your own as far as working out how it all works, I am gearing up for a new project that will use artificial intelligence.
this should work using pose copy/paste/paste-flipped operators.
armature = bpy.data.objects['armature']
for p_bone in armature.pose.bones[:]:
clean = True
for filter in ["muscle", "IK_" 'reverse', 'helper']: # Use this filter bones/groups
if filter in p_bone.name:
clean = False
break
if clean:
print(p_bone.name)
p_bone.bone.select = True
bpy.ops.pose.copy()
bpy.ops.pose.paste(flipped=True) # False if not flipped