Пример #1
0
 def create_attr(self):
     # Create enum attribute on selected control object
     sel = pm.ls(selection=True)
     if not sel:
         pm.displayWarning("Select Control object")
         return None
     attr = self.attr_nm.getText()
     attr_lst = self.enum_val.getText().split("\n")
     enum_attr_val = ""
     for index in range(len(attr_lst)):
         if attr_lst[index]:
             enum_attr_val += attr_lst[index]
             if not index == len(attr_lst) - 1:
                 enum_attr_val += ":"
     for obj in sel:
         pm.addAttr(obj,
                    longName=attr,
                    attributeType="enum",
                    enumName=enum_attr_val,
                    keyable=True,
                    readable=True,
                    storable=True,
                    writable=True)
     self.populate_list()
     return None
Пример #2
0
 def edit_blinn(self, *args):
     if not self.normal_shader:
         if not self.blinn_tex_warning:
             pm.displayWarning('you havent made a blinn yet you potato!')
             self.blinn_tex_warning = True
     else:
         newColour = pm.colorSliderGrp(self.blinnCol, q=True, rgbValue=True)
         pm.setAttr('%s.color' % self.normal_shader,
                    newColour,
                    type='double3')
Пример #3
0
 def populate_list(self):
     # display the list of enum attributes
     self.text_lst.removeAll()
     self.ctr = pm.ls(selection=True)
     if not self.ctr:
         pm.displayWarning("Control not selected")
         return None
     attr_list = self.get_attr_name()
     if attr_list:
         self.text_lst.append(attr_list)
     return None
Пример #4
0
 def find_node_type(self, **kwargs):
     check_node = kwargs.get("check_node", None)
     nd_typ = None
     if not check_node:
         pm.displayWarning("No nodes received")
         return None
     if isinstance(check_node, pm.GeometryFilter):
         if check_node.type() == "nonLinear":
             nd_typ = self.get_non_linear_type(non_linear_node=check_node)
         else:
             nd_typ = check_node.type()
     return nd_typ
 def show_type(self):
     sel_nd = pm.ls(selection=True)
     if not sel_nd:
         pm.displayWarning("No node selected")
         return None
     if len(sel_nd) > 1:
         pm.displayWarning("More than one node selected")
         return None
     typ = self.node_fun.find_node_type(check_node=sel_nd[0])
     if not typ:
         typ = sel_nd[0].type()
     self.nd_typ_txt.setText(typ.lower())
     return None
 def get_def_history_nodes(self, **kwargs):
     sel = kwargs.get("sel_nd", None)
     if not sel:
         sel = pm.ls(selection=True)
     if not sel:
         pm.displayWarning("No objects selected")
         return None
     def_list = []
     self.hist_nodes = self.node_fun.get_history_list(sel_obj=sel)
     for nd in self.hist_nodes:
         if isinstance(nd, pm.GeometryFilter):
             def_list.append(nd)
     return def_list
    def extract_loops(self, **kwargs):
        max_count = kwargs.get("max", 0)
        if not max_count:
            max_count = 2
        prev_con_edg = kwargs.get("prev_con_edg", [])
        selected_edges = kwargs.get("next_edg", [])
        self.safe_count += 1
        if self.safe_count > max_count:
            pm.displayWarning("Loop not ending")
            return self.FAIL
        if not selected_edges:
            selected_edges = pm.ls(orderedSelection=True, flatten=True)
        if self.init_flag:
            if len(selected_edges) < 2:
                pm.displayError("Minimum 2 edge selection needed")
                return self.FAIL
            if len(selected_edges) > 3:
                pm.displayError("More than 3 edges selected")
                return self.FAIL
            if len(selected_edges) == 3:
                self.stop_edge = selected_edges.pop(2)

            self.transform_node, self.shape_node = self.get_transform_from_component(
                comp=selected_edges[0])
            max_count = len(
                pm.ls(str(self.transform_node) + ".e[*]", flatten=True))

        next_edge = None
        for sel_edg in selected_edges:
            loop = self.get_loop_from_edge(edg=sel_edg,
                                           obj=self.transform_node)
            self.loop.append(loop)
            con_edg = pm.ls(sel_edg.connectedEdges(), flatten=True)
            if self.init_flag:
                self.init_flag = False
                prev_con_edg = con_edg
                self.init_loop = loop
                continue
            next_edge = self.get_next_edge(edg_con=con_edg,
                                           edg_loop=loop,
                                           prev_edg_con=prev_con_edg)
            if self.stop_edge in loop:
                return None
        if next_edge and len(next_edge) == 1:
            if next_edge[0] in self.init_loop:
                return None
            self.extract_loops(prev_con_edg=con_edg,
                               next_edg=next_edge,
                               max=max_count)

        return self.SUCCESS
Пример #8
0
 def skin(self, **kwargs):
     obj = kwargs.get("cur_obj", None)
     ctr = kwargs.get("ctr", None)
     pm.select(clear=True)
     shp = obj.getShape()
     if not shp:
         shp = pm.ls(obj, dag=True, type=["mesh", "nurbsCurve"])
     else:
         shp = [shp]
     if shp:
         for item in shp:
             try:
                 pm.skinCluster(ctr, item)
             except Exception, e:
                 pm.displayWarning(str(e) + " Skipping skin bind operation")
Пример #9
0
 def lock_scale_vis_rad(self, **kwargs):
     ctrl = kwargs.get("ctr")
     ctrl.scale.setLocked(True)
     ctrl.visibility.setLocked(True)
     ctrl.scaleX.setKeyable(False)
     ctrl.scaleX.showInChannelBox(False)
     ctrl.scaleY.setKeyable(False)
     ctrl.scaleY.showInChannelBox(False)
     ctrl.scaleZ.setKeyable(False)
     ctrl.scaleZ.showInChannelBox(False)
     ctrl.visibility.setKeyable(False)
     ctrl.visibility.showInChannelBox(False)
     try:
         ctrl.radius.setLocked(True)
         ctrl.radius.setKeyable(False)
         ctrl.radius.showInChannelBox(False)
     except e:
         pm.displayWarning(e+"\nradius attribute not found")
     return None
Пример #10
0
 def get_area_ratio(self, **kwargs):
     flag = kwargs.get("flag", None)
     sel_face = kwargs.get("sel_face", None)
     sel_face = pm.ls(sel_face, flatten=True)
     if not sel_face:
         pm.displayWarning("NO FACES SELECTED")
         return None
     mesh_world_area = 0.0
     uv_area = 0.0
     print(sel_face)
     for fc in sel_face:
         mesh_world_area += fc.getArea(space="world")
         uv_area += fc.getUVArea()
     ratio = mesh_world_area / uv_area
     if flag == "CUR":
         return mesh_world_area, uv_area, ratio
     else:
         return ratio
     return None
 def reorder_deformer_nodes(self, **kwargs):
     sel = pm.ls(selection=True)
     if not sel:
         pm.displayWarning("No object selected")
     ordered_def_list = kwargs.get("ordered_def_list", None)
     for obj in sel:
         # get list of history nodes that are deformers
         def_hist_nodes = self.get_def_history_nodes(sel_nd=obj)
         # arrange the obtained history node list
         ordered_def_list = self.node_fun.reorder_list(
             ref_list=self.file_ord_list, in_list=def_hist_nodes)
         if not ordered_def_list:
             pm.displayWarning("No ordered list returned")
             return None
         # set initial flag to true to start the node shuffle
         init_flag = True
         for index in range(len(ordered_def_list)):
             if not init_flag:
                 # move each deformers in the arranged list
                 pm.reorderDeformers(ordered_def_list[index - 1],
                                     ordered_def_list[index], obj)
                 pass
             else:
                 # First shuffle
                 # move the first node from arranged list to position
                 #    next to first deformer on the object history
                 # swap the first and second deformers bringing the
                 #    first deformer in list to first in deformers l
                 #    ist on the object
                 if not def_hist_nodes[0] == ordered_def_list[0]:
                     pm.reorderDeformers(def_hist_nodes[0],
                                         ordered_def_list[0], obj)
                     pm.reorderDeformers(ordered_def_list[0],
                                         def_hist_nodes[0], obj)
                 # set the initial contition to False to indicate the
                 # first run is passed
                 init_flag = False
                 pass
         pm.select(clear=True)
         pm.select(sel)
     return None
Пример #12
0
    def delete_shader(self, sh, Utile, Vtile):

        if not pm.objExists(sh):
            pm.displayWarning("Shader does not exist")
            return None

        # get the shading engine connected
        sh_con = pm.listConnections(sh + ".outColor")
        obj = None
        for con in sh_con:
            print(con)
            # find the mesh connected with the shading engine
            obj = pm.listConnections(con, type="mesh")

        pm.delete(sh)
        pm.delete(sh + "_fileTexture")
        pm.delete(sh_con)
        pm.delete(sh + "_2dTex")
        if obj:
            pm.select(obj)
            pm.hyperShade(assign="lambert1")
        self.clear_uv_tile_val(sh, Utile, Vtile)
        return None
Пример #13
0
 def set_ref_shell(self):
     self.ref_shell = pm.ls(selection=True, flatten=True)
     if not self.ref_shell:
         pm.button(self.ref_shell_btn,
                   edit=True,
                   backgroundColor=(.863, 0.078, 0.235))
         self.ref_shell = None
         self.assign_btn.setEnable(False)
         self.sel_shell_btn.setEnable(False)
         self.ch_bx.setEnable(False)
         return None
     if not isinstance(self.ref_shell[0], pm.MeshFace):
         pm.displayWarning("Please select shells")
         return None
     r = round(random.uniform(0.000, 0.500), 3)
     b = round(random.uniform(0.000, 0.500), 3)
     pm.button(self.ref_shell_btn, edit=True, backgroundColor=(r, .545, b))
     self.ratioREF = self.get_area_ratio(flag="REF",
                                         sel_face=self.ref_shell)
     self.assign_btn.setEnable(True)
     self.sel_shell_btn.setEnable(True)
     self.ch_bx.setEnable(True)
     return None
Пример #14
0
 def rescale_uv(self, **kwargs):
     # if no reference shell is selected stop execution
     if not self.ref_shell:
         pm.displayWarning("Reference shell not set")
         return None
     sel_shell_lst = []
     skipped_selection = []
     mesh_check = self.ch_bx.getValue()
     # if the selection is object get the faces of the object
     if mesh_check:
         print("SELECT MESH")
         sel_obj = pm.ls(selection=True)
         for obj in sel_obj:
             if isinstance(obj.getShape(), pm.Mesh):
                 obj_faces = pm.ls(str(obj) + ".f[*]", flatten=True)
                 sel_shell_lst += obj_faces
             else:
                 skipped_selection.append(obj)
     else:
         sel_shell_lst = pm.ls(selection=True)
     if not sel_shell_lst:
         pm.displayWarning("No face selected")
         return None
     # convert all faces to UV selection
     mel.eval('ConvertSelectionToUVs')
     all_uv = pm.ls(selection=True, flatten=True)
     if not isinstance(sel_shell_lst[0], pm.MeshFace):
         pm.displayWarning("Please select shells")
         return None
     ref_count = len(all_uv)
     # call shell split function to get a list of separate shells
     run_shellp_split = self.split_shells(all_uv, ref_count, count=0)
     # if the self.split_shells runs more than
     #     the number ofvertices, terminate
     if run_shellp_split == "Infinite loop":
         pm.displayError("MAX COUNT REACHED, Shell separation FAIL!!!!!!")
         return None
     # for each shell, find the required area ratio to
     #     match with the reference area ratio
     # scale the shell to tha amount needed
     for ref_uv in self.uv_shells_list:
         sel_faces = pm.ls(self.uv_shells_list[ref_uv])
         mesh_areaCUR, uv_areaCUR, ratioCUR = self.get_area_ratio(
             flag="CUR", sel_face=sel_faces)
         if not self.ratioREF == ratioCUR:
             needed_area = mesh_areaCUR / self.ratioREF
             scaleval = math.sqrt(needed_area / uv_areaCUR)
             pm.select(ref_uv)
             ref = pm.polyEditUVShell(ref_uv,
                                      query=True,
                                      pivotU=True,
                                      pivotV=True)
             pm.polyEditUVShell(pivotU=ref[0],
                                pivotV=ref[1],
                                scaleU=scaleval,
                                scaleV=scaleval)
     self.uv_shells_list = {}
     if skipped_selection:
         print "########Objects skipped########"
         for obj in skipped_selection:
             print obj
         pm.displayWarning("objects have been skipped, check script editor")
     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