Esempio n. 1
0
def subdivideCatmull2D(pts):
    newNodes = []
    for i in range(len(pts)):
        a = pts[i]
        newNodes.append(Vertex(a.x, a.y, a.z))
        b = pts[(i + 1) % len(pts)]
        center = vec.add(a, b)
        newNodes.append(vec.scale(center, 0.5))
    newNodes2 = []
    for i in range(len(newNodes)):
        iPrev = i - 1
        if iPrev < 0:
            iPrev = len(newNodes) - 1
        iNext = i + 1
        if iNext >= len(newNodes):
            iNext = 0
        a = newNodes[iPrev]
        b = newNodes[i]
        c = newNodes[iNext]
        average = Vertex(0, 0, 0)
        average = vec.add(average, a)
        average = vec.add(average, b)
        average = vec.add(average, b)
        average = vec.add(average, c)
        average = vec.divide(average, 4.0)
        newNodes2.append(average)
    return newNodes2
Esempio n. 2
0
def _getVerticesBetween(v1,v2,n):
    row = []
    deltaV = vec.subtract(v2, v1)
    deltaV = vec.divide(deltaV, n)
    for i in range(n):
        addV = vec.scale(deltaV, i)
        row.append(vec.add(addV, v1))
    row.append(v2)
    return row
Esempio n. 3
0
def subdivideCatmull(_mesh):
    for face in _mesh.faces:
        face.vertex=faceUtils.center(face)

    for edge in _mesh.edges:
        if edge.face1==None or edge.face2==None:
            edge.v1.fix=True
            edge.v2.fix=True
            edge.vertex = edge.getCenter()
        else:
            vsum=Vertex()
            nElements=2
            vsum=_vec.add(vsum,edge.v1)
            vsum=_vec.add(vsum,edge.v2)
            if edge.face1!=None:
                vsum=_vec.add(vsum,edge.face1.vertex)
                nElements+=1
            if edge.face2!=None:
                vsum=_vec.add(vsum,edge.face2.vertex)
                nElements+=1
            vsum=_vec.divide(vsum,nElements)
            edge.vertex=vsum
        if edge.v1.fix and edge.v2.fix:
            edge.vertex.fix=True

    for vertex in _mesh.vertices:
        if vertex.fix:
            vertex.vertex=copy.copy(vertex)
        else:
            averageFaces=Vertex()
            averageEdges=Vertex()
            nEdges=len(vertex.edges)

            for edge in vertex.edges:
                face=edge.face1
                if edge.v2 is vertex:
                    face=edge.face2
                if face!=None:
                    averageFaces=_vec.add(averageFaces,face.vertex)
                averageEdges=_vec.add(averageEdges,edge.getCenter())
            averageEdges=_vec.scale(averageEdges,2.0/nEdges)
            averageFaces=_vec.scale(averageFaces,1.0/nEdges)

            v=Vertex(vertex.x,vertex.y,vertex.z)
            v=_vec.scale(v,nEdges-3)
            v=_vec.add(v,averageFaces)
            v=_vec.add(v,averageEdges)
            v=_vec.scale(v,1.0/nEdges)
            vertex.vertex=v

    return _collectNewFaces(_mesh)