예제 #1
0
 def apply_append_poly(self):
     #print 'try to check last edge:',self.sub_edges
     if self.sub_edges:
         self.check_last_edge()
     if len(self.num_list) < 3:
         return
     #self.all_edges = common.conv_comp(self.mesh, mode='edge')
     try:
         #print '*+*+**+**+*+*+*append polyton to :', self.num_list[:3]
         num_list = self.num_list[:3]
         cmds.polyAppendVertex(a=num_list)
         #print 'append polygon :'
         self.check_normal_uv()
         if self.last_edge:
             #print 'delete last edge', self.last_edge
             cmds.delete(self.last_edge)
         self.after_edges = common.conv_comp(self.mesh, mode='edge')
         sub_edge = len(self.all_edges) - len(self.after_edges)
         if sub_edge != 0:
             self.sub_edges = self.after_edges[sub_edge:]
         else:
             self.reset_var()
         self.num_list = self.num_list[3:]
         #print 'sub edges :', self.sub_edges
     except Exception as e:
         print e.message, common.location()
         print(traceback.format_exc())
         #print 'append error'
         self.reset_var()
     #選択が3以上なら次の面張りへ再帰
     #print 'try to next append :', self.num_list
     if self.num_list:
         self.apply_append_poly()
     if self.fix_mode.checkedId() == 0:
         self.reset_var()
예제 #2
0
    def createPolygon(self, tis, *a):
        self.executeCondition()
        tis = cmds.treeView('tree_apsbPL', q=1, children=1)  # tree items
        if len(tis) < 3:
            cmds.warning('Position List most more than 3.')
            return 0
        sl = cmds.ls(selection=1)

        cpl = []  # created polygon name list
        for mn in sl:  # mesh name
            if (cmds.nodeType(mn) == 'transform'):
                c = cmds.listRelatives(mn, shapes=1, noIntermediate=1)
                if (len(c) == 0): cmds.warning('Selection most be polygon.')
                else: mn = c[0]
            elif (cmds.nodeType(mn) == 'mesh'):
                mns = mn.split('.')
                if len(mns) > 1: mn = mns[0]
            else: cmds.warning('Selection most be polygon.')

            pl = []  # position list
            for ti in tis:  # tree item
                xList = ti.split(',')
                xx = 0.0
                xy = 0.0
                xz = 0.0
                for sti in xList:  # splited tree item
                    vn = mn + '.' + sti  # vertex name
                    if cmds.objExists(vn):
                        yPos = cmds.xform(vn, q=1, translation=1, worldSpace=1)
                        xx = xx + yPos[0]
                        xy = xy + yPos[1]
                        xz = xz + yPos[2]
                xx = xx / len(xList)
                xy = xy / len(xList)
                xz = xz / len(xList)
                pl.append([xx, xy, xz])

            cpl.append(cmds.polyCreateFacet(point=[pl[0], pl[1], pl[2]])[0])
            for i in range(3, len(tis)):
                cmds.polyAppendVertex(a=[i - 2, i - 1, pl[i]])

        cmds.select(cpl, replace=1)
예제 #3
0
def off_translation(filename):

    print("Debut du parsing")
    f = open(filename, 'r')
    # On passe les lignes inutiles
    line = f.readline()
    line = f.readline()
    if line[0] == '#':
        line = f.readline()
        if line[0] == '#':
            line = f.readline()
    # On considere la ligne comme une liste de string separes par des espaces
    line = line.split(' ')
    nb_vert = int(line[0])
    nb_faces = int(line[1])
    list_vert = []
    list_faces = []
    # On remplit la liste des sommets
    for i in range(0, nb_vert):
        line = f.readline()
        line = line.split(' ')
        coord = [float(line[0]), float(line[1]), float(line[2])]
        list_vert.append(coord)
    line = f.readline()
    line = line.split(' ')
    # On remplit la liste des faces
    for i in range(0, nb_faces):
        index1, index2, index3 = int(line[1]), int(line[2]), int(line[3])
        points = [list_vert[index1], list_vert[index2], list_vert[index3]]
        list_faces.append(points)
        line = f.readline()
        line = line.split(' ')
    f.close()
    print("Parsing fini, debut de la creation du maillage")

    print(list_faces[0])
    # print(list_faces[1])
    obj = cm.polyCreateFacet(ch=False, p=list_faces[0])
    cm.select(obj)
    for i in range(1, nb_faces):
        cm.polyAppendVertex(a=list_faces[i])
    print("Maillage cree")
예제 #4
0
def polyAppendVertex(*args, **kwargs):
    res = cmds.polyAppendVertex(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
예제 #5
0
def maya_mel_make_poly_geometry(mesh, verbose=False):
    first_triangle = True
    used = [False for _ in mesh.vertices]
    for triangle in mesh.triangles:
        i = triangle[0]
        j = triangle[1]
        k = triangle[2]

        pi = mesh.vertices[i]
        pj = mesh.vertices[j]
        pk = mesh.vertices[k]

        pattern = int(used[k]) << 2 | int(used[j]) << 1 | int(used[i]) << 0

        if pattern == 0:
            if first_triangle:
                cmds.polyCreateFacet(constructionHistory=False, p=[pi, pj, pk], name=mesh.name)
                first_triangle = False
            else:
                cmds.polyAppendVertex(constructionHistory=False, a=[pi, pj, pk])
        elif pattern == 1:
            cmds.polyAppendVertex(constructionHistory=False, a=[i, pj, pk])
        elif pattern == 2:
            cmds.polyAppendVertex(constructionHistory=False, a=[pi, j, pk])
        elif pattern == 3:
            cmds.polyAppendVertex(constructionHistory=False, a=[i, j, pk])
        elif pattern == 4:
            cmds.polyAppendVertex(constructionHistory=False, a=[pi, pj, k])
        elif pattern == 5:
            cmds.polyAppendVertex(constructionHistory=False, a=[i, pj, k])
        elif pattern == 6:
            cmds.polyAppendVertex(constructionHistory=False, a=[pi, j, k])
        elif pattern == 7:
            cmds.polyAppendVertex(constructionHistory=False, a=[i, j, k])
        else:
            raise RuntimeError('Internal error, illegal pattern value detected')
        used[i] = True
        used[j] = True
        used[k] = True
    cmds.polySetToFaceNormal()
    if verbose:
        print 'Created maya poly mesh of', mesh.name