Ejemplo n.º 1
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
Ejemplo n.º 2
0
def jnt_along_loop():
    import splitLoops
    #reload(splitLoops)
    loops = splitLoops.split_loop()
    if not loops:
        pm.displayInfo("please select only edge loops")
        return None
    else:
        verts = loops[1]
        loops = loops[0]
    #print loops
    #print verts
    pos = []
    for i in range(len(loops)):
        pos.append(CustomScripts.midPos(selected_items=verts[i]))

    print pos
    jnt_lst = []
    for p in pos:
        print p
        jnt = pm.joint(position=p)
        jnt_lst.append(jnt)
        if len(jnt_lst) > 1:
            pm.joint(jnt_lst[pos.index(p) - 1],
                     edit=True,
                     orientJoint='xyz',
                     secondaryAxisOrient='yup',
                     zeroScaleOrient=True)
    return None
Ejemplo n.º 3
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
 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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def jnt_at_object_mid(**kwargs):
    sel = pm.ls(orderedSelection=True, flatten=True)
    for tran in sel:
        if not isinstance(tran, pm.Transform):
            pm.displayinfo("Please select only transform nodes")
            return None
    if not sel:
        pm.displayInfo("please select transform object")
    pos = []
    for obj in sel:
        pos.append(CustomScripts.midPos(selected_items=obj))
    pm.select(clear=True)
    for p in pos:
        pm.joint(position=p)
        pm.select(clear=True)
    return None
    def setup_motion_path(self):
        setup_name = self.get_setup_name()
        path_name = self.get_path_name()
        sample_obj = self.get_sample_objects()
        duplicate_flag = self.get_duplicate_flag()
        placement_type = self.get_placement_type()
        division_count = self.get_division_count()

        if setup_name == self.INVALID_INPUT_FAIL:
            pm.displayError("Invalid Input Entered for setup name")
            return None

        if path_name == self.INVALID_INPUT_FAIL:
            pm.displayError("Invalid Input Entered for path name")
            return None

        if path_name == self.NO_OBJECT_FAIL:
            pm.displayError("path Curve does not exist")
            return None

        if path_name == self.DATA_TYPE_FAIL:
            pm.displayError("Path can be only Nurb Curves")
            return None

        if division_count == self.INVALID_INPUT_FAIL:
            pm.displayError("Invalid Input Entered for divisions")
            return None

        if division_count == self.DATA_TYPE_FAIL:
            pm.displayError("Divisions can take only integer values")
            return None

        if sample_obj == self.NO_OBJECT_FAIL:
            pm.displayError("Sample Object not found")
            return None

        obj_list = []
        path_anim_list = []

        sel_objs = pm.ls(selection=True)

        if duplicate_flag:
            path_name = self.get_duplicate_path(path_crv=path_name)
        path_name = pm.rename(path_name, setup_name + "_path_CRV")

        if placement_type == "uniform":
            obj_list, path_anim_list = self.uniform_distribution(
                name=setup_name,
                path=path_name,
                sample=sample_obj,
                divisions=division_count)
        else:
            if not sel_objs:
                pm.displayError("No Objects selected")
            for obj in sel_objs:
                if not pm.objExists(obj):
                    pm.displayWarning(str(obj), "does not exist")
                    return None
            obj_list, path_anim_list = self.at_selection(
                name=setup_name,
                path=path_name,
                sample=sample_obj,
                selection_list=sel_objs)

        loc_pos = CustomScripts.midPos(selected_items=path_name)
        loc = pm.spaceLocator(name=setup_name + "_up_loc")
        pm.xform(loc, translation=loc_pos)
        control_crv = pm.circle(name=setup_name + "CTRL",
                                normalX=1,
                                normalY=0,
                                normalZ=0)
        pm.xform(control_crv[0], translation=loc_pos, worldSpace=True)
        pm.select(clear=True)
        # add run and speed attributes on parent nurb curve
        pm.addAttr(control_crv[0],
                   longName="run",
                   attributeType="float",
                   keyable=True)
        pm.addAttr(control_crv[0],
                   longName="speed",
                   attributeType="float",
                   keyable=True,
                   minValue=0.0,
                   defaultValue=0.5)
        # edit the existing motion path to assign up locator
        for mtPth in path_anim_list:
            pm.pathAnimation(mtPth,
                             edit=True,
                             worldUpType="object",
                             worldUpObject=loc)
        # parent the setup under the parent nurb curve
        pm.parent(path_name, control_crv[0])
        pm.parent(loc, control_crv[0])
        pm.select(clear=True)
        gp = pm.group(name=setup_name + "GP")
        pm.xform(gp, translation=loc_pos)
        pm.select(clear=True)
        obj_gp = pm.group(obj_list, name=setup_name + "object_GP")
        pm.parent(control_crv[0], gp)
        pm.parent(obj_gp, gp)
        # call to create expression function
        self.createTreadExpression(mtnPth=path_anim_list,
                                   runAttr=str(control_crv[0]) + ".run",
                                   speedAttr=str(control_crv[0]) + ".speed",
                                   exp_nm=setup_name)
        return None