예제 #1
0
def jnt_at_mid_vertex_orient(**kwargs):
    sel = pm.ls(orderedSelection=True, flatten=True)
    if not sel:
        pm.displayInfo("Please select vertex")
        return None
    obj_pos_map = {}
    for comp in sel:
        if not isinstance(comp, pm.MeshVertex):
            pm.displayInfo("Please select only vertex")
            return None
    mid_pos = 0
    for comp in sel:
        comp.node()
        transform_node = pm.listTransforms(comp.node())[0]
        if transform_node not in obj_pos_map.keys():
            vrts = CustomScripts.get_vrts(sel_obj=[transform_node])[0]
            pos = CustomScripts.midPos(selected_items=vrts)
            obj_pos_map[transform_node] = pos
            mid_pos = pos
        else:
            mid_pos = obj_pos_map[transform_node]
        comp_pos = pm.pointPosition(comp, world=True)
        pm.select(clear=True)
        jnt1 = pm.joint(position=mid_pos)
        jnt2 = pm.joint(position=comp_pos)
        pm.joint(jnt1,
                 edit=True,
                 orientJoint='xyz',
                 secondaryAxisOrient='yup',
                 zeroScaleOrient=True)
        pm.select([jnt1, jnt2])
        CustomScripts.CopyJntOri()
    return None
예제 #2
0
def get_loop_from_edge():
    sel = pm.ls(orderedSelection=True)
    mid_pos = []
    pm.select(clear=True)
    for edg in sel:
        obj_sh_name = str(edg).split(".")[0]
        obj_name = pm.listRelatives(obj_sh_name, parent=True)
        edg_num = int((edg.split("[")[1]).replace("]", ""))
        pm.polySelect(obj_name, edgeLoopOrBorder=edg_num)
        edg_sel = pm.ls(selection=True)
        mid_pos.append(CustomScripts.midPos(selected_items=edg_sel))
        pm.select(clear=True)
    pm.select(clear=True)
    jnts = []
    for pos in mid_pos:
        cur_jnt = pm.joint(position=pos)
        jnts.append(cur_jnt)
        index = mid_pos.index(pos)
        if index > 0:
            pm.joint(jnts[index - 1],
                     edit=True,
                     orientJoint="xyz",
                     secondaryAxisOrient="yup",
                     children=True,
                     zeroScaleOrient=True)
    pm.select(clear=True)
    pm.select(jnts[-2], jnts[-1])
    CustomScripts.CopyJntOri()
    pm.select(clear=True)
    pm.select(jnts[-1])
    return None
 def place_objects(self, **kwargs):
     interval = kwargs.get("skip", 0)
     if not self.loop:
         pm.displayError("no Loops received")
         return None
     if interval > len(self.loop):
         pm.displayError(
             "Skipping value larger than number of edges present")
         return self.FAIL
     jnt_lst = []
     index = 0
     max_len = len(self.loop)
     while index < max_len:
         pos = CustomScripts.midPos(selected_items=self.loop[index])
         jnt_lst.append(pm.joint(position=pos))
         if len(jnt_lst) > 1:
             pm.parent(jnt_lst[-1], jnt_lst[-2])
             pm.joint(jnt_lst[-2],
                      edit=True,
                      orientJoint='xyz',
                      secondaryAxisOrient='yup',
                      zeroScaleOrient=True)
         index += interval + 1
     pm.select(jnt_lst[-2], jnt_lst[-1])
     CustomScripts.CopyJntOri()
     return jnt_lst
예제 #4
0
def jnt_at_mid_vertex_orient(**kwargs):
    sel = pm.ls(orderedSelection=True, flatten=True)
    if not sel:
        pm.displayInfo("Please select vertex")
        return None
    obj_pos_map = {}
    for comp in sel:
        if not isinstance(comp, pm.MeshVertex):
            pm.displayInfo("Please select only vertex")
            return None
    mid_pos = 0
    for comp in sel:
        #vertex_position = pm.pointPosition(comp, world=True)
        #component_pos.append(vertex_position)
        shape_node = comp.node()
        transform_node = pm.listTransforms(comp.node())[0]
        if transform_node not in obj_pos_map.keys():
            vrts = CustomScripts.get_vrts(sel_obj=[transform_node])[0]
            print vrts
            pos = CustomScripts.midPos(selected_items=vrts)
            obj_pos_map[transform_node] = pos
            mid_pos = pos
        else:
            mid_pos = obj_pos_map[transform_node]
        print obj_pos_map
        comp_pos = pm.pointPosition(comp, world=True)
        pm.select(clear=True)
        jnt1 = pm.joint(position=mid_pos)
        jnt2 = pm.joint(position=comp_pos)
        pm.joint(jnt1,
                 edit=True,
                 orientJoint='xyz',
                 secondaryAxisOrient='yup',
                 zeroScaleOrient=True)
        pm.select([jnt1, jnt2])
        CustomScripts.CopyJntOri()

        #obj_list[comp] = transform_node
        #if transform_node not in obj_list:
        #    obj_list.append(transform_node)

    #vrts = CustomScripts.get_vrts(sel_obj = obj_list)
    #pos = []
    #for vrt in vrts:
    #    pos.append(CustomScripts.midPos(selected_items = vrt))

    #for p in component_pos:
    #    pm.select(clear=True)
    #    jnt1 = pm.joint(position=p)
    #    jnt2 = pm.joint(position = component_pos[pos.index(p)])
    #    pm.joint(jnt1, edit=True, orientJoint='xyz',
    #                 secondaryAxisOrient='yup', zeroScaleOrient=True)
    #    pm.select(clear=True)
    #    pm.select([jnt1, jnt2])
    #    CustomScripts.CopyJntOri()
    #    pm.select(clear=True)
    return None
예제 #5
0
def CustomScripts_UI():

    WINDOW = 'CustomScripts'
    if pm.window(WINDOW, query=True, exists=True):
        pm.deleteUI(WINDOW)
    pm.window(WINDOW,
              title="Custom Scripts",
              iconName='CS',
              widthHeight=(200, 400))
    column_1 = pm.columnLayout(adjustableColumn=True)

    pm.separator(height=20, style='in', parent=column_1)
    pm.button(label='Immediate Parent in Hierarchy',
              command=lambda x: CustomScripts.immediateParent())

    pm.separator(height=20, style='in', parent=column_1)
    hide_jnt_col = pm.rowColumnLayout(parent=column_1,
                                      numberOfColumns=3,
                                      columnWidth=(1, 95))
    pm.button(label='Hide Joint',
              command=lambda x: CustomScripts.jntHide(),
              parent=hide_jnt_col)
    pm.separator(parent=hide_jnt_col, horizontal=False, width=10)
    pm.button(label='Show Joint',
              command=lambda x: CustomScripts.jntShow(),
              parent=hide_jnt_col,
              width=95)

    pm.separator(height=20, style='in', parent=column_1)
    lod_col = pm.rowColumnLayout(parent=column_1,
                                 numberOfColumns=3,
                                 columnWidth=(1, 95))
    pm.button(label='LOD off',
              command=lambda x: CustomScripts.lodOff(),
              parent=lod_col)
    pm.separator(parent=lod_col, horizontal=False, width=10)
    pm.button(label='LOD on',
              command=lambda x: CustomScripts.lodOn(),
              parent=lod_col,
              width=95)

    pm.separator(height=20, style='in', parent=column_1)
    pm.button(label='Parent( in selection order)',
              command=lambda x: CustomScripts.parentChain(),
              parent=column_1)

    # get object name
    pm.separator(height=20, style='in', parent=column_1)
    row_col_2 = pm.rowColumnLayout(numberOfColumns=2,
                                   columnWidth=(1, 150),
                                   parent=column_1,
                                   columnOffset=(2, 'left', 10))
    object_name = pm.TextField(parent=row_col_2)
    pm.button(
        label='<<',
        parent=row_col_2,
        command=lambda x: object_name.setText(str(pm.ls(selection=True)[0])))
    row_col_3 = pm.rowColumnLayout(numberOfColumns=2,
                                   columnWidth=(1, 100),
                                   parent=column_1,
                                   columnOffset=(2, 'left', 10))
    prntChk = pm.checkBox("parent", parent=row_col_3)
    sclChk = pm.checkBox("scale", parent=row_col_3)
    pm.separator(height=5, style='none', parent=column_1)
    pm.button(
        label='Copy Object to selected positions',
        parent=column_1,
        command=lambda x: CustomScripts.copyObjects(obj=object_name.getText(),
                                                    prFlg=prntChk.getValue(),
                                                    scFlg=sclChk.getValue()))

    pm.separator(height=20, style='in', parent=column_1)
    pm.button(label="copy orientation",
              parent=column_1,
              command=lambda x: CustomScripts.CopyJntOri())

    pm.showWindow(WINDOW)
    pm.window(WINDOW, edit=True, widthHeight=(200, 320))
    return None