0

I've been following a tutorial (https://vimeo.com/240328348) which involves creating a locator and placing it in the correct location for a pole vector. For some reason when I run my script, it consistently places the locator directly on the middle joint instead of moving the it a specified length behind the joint.

any assistance would be greatly appreciated.

    import maya.cmds as cmds
import maya.OpenMaya as om

def create_loc(pos):
    loc = cmds.spaceLocator()
    cmds.move(pos.x, pos.y, pos.z, loc)

def get_pole_vec_pos(root_pos,rot_pos, mid_pos, low_pos, end_pos):
    root_joint_vec = om.MVector(root_pos[0], root_pos[1], root_pos[2])
    rot_joint_vec = om.MVector(rot_pos[0], rot_pos[1], rot_pos[2])
    mid_joint_vec = om.MVector(mid_pos[0], mid_pos[1], mid_pos[2])
    low_joint_vec = om.MVector(low_pos[0], low_pos[1], low_pos[2])
    end_joint_vec = om.MVector(end_pos[0], end_pos[1], end_pos[2])


    line = (end_joint_vec - root_joint_vec)
    point = (mid_joint_vec - root_joint_vec)

    scale_value = (line * point)/(line * line)
    proj_vec = line * scale_value + root_joint_vec

    root_to_mid_len = (mid_joint_vec - rot_joint_vec - root_joint_vec).length()
    mid_to_end_len = (end_joint_vec - low_joint_vec - mid_joint_vec).length()
    total_length = (root_to_mid_len + mid_to_end_len)

    pole_vec_pos = (mid_joint_vec - proj_vec).normal() * 5 + mid_joint_vec

    return pole_vec_pos

def get_ikh_pole_vec_pos(ik_handle):

    ik_joint_list = cmds.ikHandle(ik_handle, q=True, jointList=True)
    ik_joint_list.append(cmds.listRelatives(ik_joint_list[1],children=True, type='joint')[0])

    root_joint_pos = cmds.xform(ik_joint_list[0], q=True, ws=True, t=True)
    rot_joint_pos = cmds.xform(ik_joint_list[1], q=True, ws=True, t=True)
    mid_joint_pos = cmds.xform(ik_joint_list[2], q=True, ws=True, t=True)
    low_joint_pos = cmds.xform(ik_joint_list[3], q=True, ws=True, t=True)
    end_joint_pos = cmds.xform(ik_joint_list[4], q=True, ws=True, t=True)
    pole_vec_pos = get_pole_vec_pos(root_joint_pos,rot_joint_pos, mid_joint_pos, low_joint_pos, end_joint_pos)
    return pole_vec_pos

pole_vec_pos = get_ikh_pole_vec_pos('ikHandle1')
create_loc(pole_vec_pos)
  • I tried creating a 6 joint chain and running this created a locator a bit of distance in front of the middle joint. Are you getting a different result? If yes then you might want to include the creation of your joints so we get the same result. – Green Cell Jul 03 '19 at 03:40
  • @GreenCell Yes I am, it places the locator directly on the joint. I even tried it on a new file and it does the same thing. here's a file I just tested out [link]https://mega.nz/#!eNQ1HYQZ!NHLiOayvVl3Oh4S4ox2_RDPYBN16IG_F3pN_Ag6I5Ks – AbberantAeons Jul 04 '19 at 06:17
  • Ah you're trying to apply it on joints that are in a straight line. The issue happens when calculating `pole_vec_pos`. Both `mid_joint_vec` and `proj_vec` are in the same position, so it results as 0 when trying to offset from the middle position. It works as expected with a joint chain that's bent, like a leg. – Green Cell Jul 04 '19 at 06:37

0 Answers0