Hello all! I am working on a script for FK to IK switching. The main problem in this case seems to be updating the position of IK pole target bone based on FK pose
My presumed algorithm was: calculate the “forward” vectors for first and second bones in a chain (vectors A and B), then interpolating between A and B (mathutils.Vector.slerp) to get offset vector (C), and finding the final position of pole target as a sum of vector C and the position of the second bone in a chain. But when I try to set the resulting position in Pose mode (using PoseBone.location), the result is nowhere near the expected position. Either I calculate the directional vectors wrong (I multiply the bones’ rotation quaternions to vectors) or the way I set the bone position is wrong (PoseBone.location) Which is it? The code is the following:
import mathutils
import math
import bpy
this = bpy.data.objects["Armature"]
pole = this.pose.bones["ikHint"]
thigh = this.pose.bones["thigh"]
calf = this.pose.bones["calf"]
thighDir = thigh.rotation_quaternion * mathutils.Vector((1.0,-0.0,0.0))
calfDir = calf.rotation_quaternion * mathutils.Vector((1.0,-0.0,0.0))
jointDir = mathutils.Vector.slerp(thighDir,calfDir,0.5).normalized()
pole.location = calf.location + jointDir