Exemplo n.º 1
0
def ins_jnt(**kwargs):
    num = kwargs.get("num_jts", 1)
    sel = pm.ls(selection=True)
    chld = pm.listRelatives(sel[0], children=True)
    if not chld[0].type() == "joint":
        print "end joint reached"
        return None
    #position_lst = []
    pos1 = pm.xform(sel[0], query=True, worldSpace=True, translation=True)
    pos2 = pm.xform(chld, query=True, worldSpace=True, translation=True)
    len_vec1 = OpenMaya.MVector(pos1[0], pos1[1], pos1[2])
    len_vec2 = OpenMaya.MVector(pos2[0], pos2[1], pos2[2])
    len_vec = len_vec2 - len_vec1
    print len_vec.x, len_vec.y, len_vec.z
    part_vec = len_vec / (num + 1)
    pos_vec = len_vec1 + len_vec / (num + 1)
    cur_jnt = sel[0]
    for i in range(num):
        new_position = [pos_vec.x, pos_vec.y, pos_vec.z]
        #print new_position
        new_joint = pm.insertJoint(cur_jnt)
        pm.joint(new_joint, edit=True, component=True, position=new_position)
        #pm.xform(new_joint, translation=new_position)
        pos_vec += part_vec
        cur_jnt = new_joint
    return None
Exemplo n.º 2
0
def insJnt():
    selected = pm.ls(selection=True)
    for index in range(len(selected) - 1):
        mid_pos = midPos(selected_items=[selected[index], selected[index + 1]])
        new_joint = pm.insertJoint(selected[index])
        pm.joint(new_joint, edit=True, component=True, position=mid_pos)
    return None
Exemplo n.º 3
0
def dense_chain(**kwargs):
    import pymel.core.datatypes as dt
    joints = kwargs.get("joints", None)
    joints_inbetween = kwargs.get("joints_inbetween", 5)
    if not joints:
        joints = pm.ls(selection=True)
    joints.pop(-1)
    for jnt in joints:
        child = jnt.getChildren()
        pos = pm.xform(jnt, query=True, translation=True, worldSpace=True)
        vpos1 = dt.Vector(pos)
        pos = pm.xform(child[0], query=True, translation=True, worldSpace=True)
        vpos2 = dt.Vector(pos)
        vpos = vpos2 - vpos1
        div_vec = vpos / (joints_inbetween + 1)
        out_vec = vpos1
        cur_jnt = jnt
        for i in range(joints_inbetween):
            out_vec = (out_vec + div_vec)
            pos = [out_vec.x, out_vec.y, out_vec.z]
            new_jnt = pm.insertJoint(cur_jnt)
            pm.joint(new_jnt,
                     edit=True,
                     component=True,
                     position=pos,
                     name=str(i))
            cur_jnt = new_jnt
    return None