def flow(mesh_id=None, step=1):
    """Performs one step of the harmonic flow of the given mesh,
    replacing that mesh with a new one.
    """
    # TODO(mikhaildubov): This flow results in a degenerate case at the poles of sphere134.3dm.
    #                     Fix this by making it a true MCF (i.e. by using the angles).

    # If mesh_id is None, then get the mesh from the user.
    # Check that all its faces are correctly set up.
    mesh_id = mu.get_and_check_mesh(mesh_id)

    # Various precomputations (including motion vectors for each vertex)
    v = rs.MeshVertices(mesh_id)
    n = len(v)
    harmonic_vectors = get_motion_vectors(mesh_id, step)

    # Move each vertex by its motion vector
    new_vertices = []
    for i in xrange(n):
        new_vertices.append(rs.PointAdd(v[i], harmonic_vectors[i]))

    # Update the mesh
    new_mesh_id = rs.AddMesh(new_vertices, rs.MeshFaceVertices(mesh_id))
    rs.DeleteObject(mesh_id)
    return new_mesh_id
def flow(mesh_id=None, step=1):
    """Performs one step of the harmonic flow of the given mesh,
    replacing that mesh with a new one.
    """
    # TODO(mikhaildubov): This flow results in a degenerate case at the poles of sphere134.3dm.
    #                     Fix this by making it a true MCF (i.e. by using the angles).
    
    # If mesh_id is None, then get the mesh from the user.
    # Check that all its faces are correctly set up.
    mesh_id = mu.get_and_check_mesh(mesh_id)
    
    # Various precomputations (including motion vectors for each vertex)
    v = rs.MeshVertices(mesh_id)
    n = len(v)
    harmonic_vectors = get_motion_vectors(mesh_id, step)
    
    # Move each vertex by its motion vector
    new_vertices = []
    for i in xrange(n):
        new_vertices.append(rs.PointAdd(v[i], harmonic_vectors[i]))

    # Update the mesh
    new_mesh_id = rs.AddMesh(new_vertices, rs.MeshFaceVertices(mesh_id))
    rs.DeleteObject(mesh_id)
    return new_mesh_id
示例#3
0
def flow(mesh_id=None, step=1):
    """Performs one step of the face flow of the given mesh,
    replacing that mesh with a new one.
    """
    # If mesh_id is None, then get the mesh from the user.
    # Check that all its faces are correctly set up.
    mesh_id = mu.get_and_check_mesh(mesh_id)

    # Various precomputations (including motion vectors for each face)
    normals = get_motion_vectors(mesh_id, step)
    adj_faces = adjacent_faces(mesh_id)
    n = len(rs.MeshVertices(mesh_id))
    face_planes = mu.get_face_planes(mesh_id)

    # Shift all the planes by their normal vectors.
    # NOTE(mikhaildubov): This computation relies on the fact that normals are
    #                     listed in the same order as the corresponding faces.
    face_planes_translated = [
        translate_plane(face_planes[i], normals[i])
        for i in xrange(len(face_planes))
    ]

    # Calculate the intersections of the shifted planes.
    # Those are going to be the vertices of the updated mesh.
    new_vertices = []
    for i in xrange(n):
        adj_planes = [face_planes_translated[j] for j in adj_faces[i]]
        adj_planes_eq = [rs.PlaneEquation(plane) for plane in adj_planes]
        intersection_point = planes_intersection(adj_planes_eq)
        new_vertices.append(intersection_point)

    # Update the mesh
    new_mesh_id = rs.AddMesh(new_vertices, rs.MeshFaceVertices(mesh_id))
    rs.DeleteObject(mesh_id)
    return new_mesh_id
示例#4
0
def draw_motion_vectors(mesh_id=None, step=1):
    """Draws the motion vectors for the face flow of the given mesh."""
    mesh_id = mu.get_and_check_mesh(mesh_id)
    normals = get_motion_vectors(mesh_id, step)
    centers = rs.MeshFaceCenters(mesh_id)
    for i in xrange(len(normals)):
        vu.VectorDraw(normals[i], centers[i])
def flow(mesh_id=None, step=1):
    """Performs one step of the face flow of the given mesh,
    replacing that mesh with a new one.
    """
    # If mesh_id is None, then get the mesh from the user.
    # Check that all its faces are correctly set up.
    mesh_id = mu.get_and_check_mesh(mesh_id)
    
    # Various precomputations (including motion vectors for each face)
    normals = get_motion_vectors(mesh_id, step)
    adj_faces = adjacent_faces(mesh_id)
    n = len(rs.MeshVertices(mesh_id))
    face_planes = mu.get_face_planes(mesh_id)
    
    # Shift all the planes by their normal vectors.
    # NOTE(mikhaildubov): This computation relies on the fact that normals are
    #                     listed in the same order as the corresponding faces.
    face_planes_translated = [translate_plane(face_planes[i], normals[i])
                              for i in xrange(len(face_planes))]

    # Calculate the intersections of the shifted planes.
    # Those are going to be the vertices of the updated mesh.
    new_vertices = []
    for i in xrange(n):
        adj_planes = [face_planes_translated[j] for j in adj_faces[i]]
        adj_planes_eq = [rs.PlaneEquation(plane) for plane in adj_planes]
        intersection_point = planes_intersection(adj_planes_eq)
        new_vertices.append(intersection_point)

    # Update the mesh
    new_mesh_id = rs.AddMesh(new_vertices, rs.MeshFaceVertices(mesh_id))
    rs.DeleteObject(mesh_id)
    return new_mesh_id
def draw_motion_vectors(mesh_id=None, step=1):
    """Draws the motion vectors for the face flow of the given mesh."""
    mesh_id = mu.get_and_check_mesh(mesh_id)
    normals = get_motion_vectors(mesh_id, step)
    centers = rs.MeshFaceCenters(mesh_id)
    for i in xrange(len(normals)):
        vu.VectorDraw(normals[i], centers[i])
def draw_motion_vectors(mesh_id=None, step=1):
    """Draws the motion vectors for the harmonic flow of the given mesh."""
    mesh_id = mu.get_and_check_mesh(mesh_id)
    harmonic_vectors = get_motion_vectors(mesh_id, step)
    v = rs.MeshVertices(mesh_id)
    n = len(v)
    for i in xrange(n):
        vu.VectorDraw(harmonic_vectors[i], v[i])
def draw_motion_vectors(mesh_id=None, step=1):
    """Draws the motion vectors for the harmonic flow of the given mesh."""
    mesh_id = mu.get_and_check_mesh(mesh_id)
    harmonic_vectors = get_motion_vectors(mesh_id, step)
    v = rs.MeshVertices(mesh_id)
    n = len(v)
    for i in xrange(n):
        vu.VectorDraw(harmonic_vectors[i], v[i])