Ejemplo n.º 1
0
def subdivide_catmull_2d(vertices):
    newNodes = []
    for i in range(len(vertices)):
        a = vertices[i]
        newNodes.append(Vertex(a.x,a.y,a.z))
        b = vertices[(i + 1) % len(vertices)]
        center = utils_vertex.vertex_add(a, b)
        newNodes.append(utils_vertex.vertex_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()
        # [average.add(v) for v in [a,b,b,c]]
        average.add(a)
        average.add(b)
        average.add(b)
        average.add(c)
        average.divide(4.0)
        # average = utils_vertex.vertex_add(average,a)
        # average = utils_vertex.vertex_add(average,b)
        # average = utils_vertex.vertex_add(average,b)
        # average = utils_vertex.vertex_add(average,c)
        # average /= 4
        # average = utils_vertex.vertex_divide(average,4.0)
        newNodes2.append(average)
    return newNodes2
Ejemplo n.º 2
0
def mesh_smooth_laplacian(mesh, factor=0.3):
    smoothed = mesh.copy()
    #smoothed.update_topology()
    for i, v in enumerate(mesh.vertices):
        adjacent_vertices = [e.other_vertex(v) for e in v.edges]
        v_sum = Vertex()
        [v_sum.add(av) for av in adjacent_vertices]
        v_sum.divide(len(adjacent_vertices))
        delta = v_sum - v
        sv = smoothed.vertices[i]
        delta.scale(factor)
        sv.add(delta)
    return smoothed
Ejemplo n.º 3
0
def mesh_smooth_laplacian(mesh, factor=0.3):
    """
    Applies Laplacian smoothing to a mesh.
    It works by moving each vertex in the direction of the average position of its neighbors.
    Note: this does not increase the face count.
    """
    smoothed = mesh.copy()
    #smoothed.update_topology()
    for i, v in enumerate(mesh.vertices):
        adjacent_vertices = [e.other_vertex(v) for e in v.edges]
        v_sum = Vertex()
        [v_sum.add(av) for av in adjacent_vertices]
        v_sum.divide(len(adjacent_vertices))
        delta = v_sum - v
        sv = smoothed.vertices[i]
        delta.scale(factor)
        sv.add(delta)
    return smoothed