def update_plot(k, args):
    plotter.update_vertices()
    plotter.update_edges()
    plotter.update_faces()
    plotter.update(pause=0.001)


# path to the sample file
DATA = os.path.join(os.path.dirname(__file__), '..', 'data')
FILE = os.path.join(DATA, 'faces.obj')

# make a mesh
mesh = Mesh.from_obj(FILE)

# identify fixed points
fixed = list(mesh.vertices_where({'vertex_degree': 2}))

# make a plotter
plotter = MeshPlotter(mesh, figsize=(10, 7))

# draw the original configuration
plotter.draw_vertices(facecolor={key: '#ff0000' for key in fixed})
plotter.draw_edges()
plotter.draw_faces()

# smooth with dynamic viz
mesh_smooth_centroid(mesh, fixed=fixed, kmax=100, callback=update_plot)

# keep plot alive
plotter.show()
Esempio n. 2
0
if __name__ == '__main__':

	import random as rd
	import compas
	from compas_pattern.datastructures.mesh_quad.mesh_quad import QuadMesh
	from compas.datastructures import mesh_smooth_centroid
	from compas_plotters.meshplotter import MeshPlotter

	mesh = QuadMesh.from_obj(compas.get('faces.obj'))
	mesh.collect_strips()
	walker = Walker(mesh)
	walker.start()
	orders = [2,0,2]
	#orders = [rd.randint(0,1) for _ in range(10)]
	#orders = [2] + orders + [2]
	#orders = [2, 1, 3, 0, 3, 2, 1, 3, 2, 2]
	print(orders)
	walker.interpret_orders(orders)
	print(walker.polyedge)
	print('added: ', walker.added_polyedges)
	print('deleted: ', walker.delete_strips)

	mesh_smooth_centroid(walker.mesh, kmax=1)

	plotter = MeshPlotter(walker.mesh)
	plotter.draw_vertices(radius=.1, text='key')
	plotter.draw_edges()
	plotter.draw_faces()
	plotter.show()

        pt = add_vectors(convex_hull_mesh.vertex_coordinates(key), vec_leaf)

        descdent_tree[key][nbr].update({'lp': current_key})

        mesh.add_vertex(current_key)
        mesh.vertex[current_key].update({'x': pt[0], 'y': pt[1], 'z': pt[2]})
        current_key += 1

for key in convex_hull_mesh.vertices():
    nbrs = convex_hull_mesh.vertex_neighbors(key, ordered=True)
    v_keys = nbrs + [nbrs[0]]
    for a, b in pairwise(v_keys):
        face = [
            descdent_tree[key][a]['lp'], descdent_tree[key][a]['jp'],
            descdent_tree[key][b]['jp'], descdent_tree[key][b]['lp']
        ]
        mesh.add_face(face)

fixed = list(mesh.vertices_where({'vertex_degree': 3}))
fixed = list(mesh.vertices())

mesh = mesh_subdivide_catmullclark(mesh, k=1, fixed=fixed)
# mesh = mesh_subdivide_quad(mesh, k=1)
mesh_smooth_centroid(mesh, fixed=fixed)

artist = MeshArtist(mesh)
artist.draw_mesh()
# artist.draw_faces()
# artist.draw_vertices()
# artist.draw_vertexlabels()
Esempio n. 4
0
if __name__ == '__main__':

	import compas
	from compas_pattern.datastructures.mesh_quad_coarse.mesh_quad_coarse import CoarseQuadMesh
	from compas.datastructures import mesh_smooth_centroid
	from compas_pattern.datastructures.mesh.operations import mesh_move_by
	from compas.datastructures import meshes_join
	from compas_plotters.meshplotter import MeshPlotter

	mesh = CoarseQuadMesh.from_obj(compas.get('faces.obj'))
	mesh.collect_strips()
	#polyedge = [0, 1, 2, 8, 14, 13, 12, 6, 0]
	#polyedge = [7, 8, 9, 15, 21, 20, 19, 13, 7]
	polyedge = [0, 1, 7, 6]
	add_strip(mesh, polyedge)
	mesh_smooth_centroid(mesh, kmax=10, fixed=mesh.vertices_on_boundary())
	plotter = MeshPlotter(mesh, figsize=(20, 20))
	plotter.draw_vertices(radius=0.1, text='key')
	plotter.draw_edges()
	plotter.draw_faces()
	plotter.show()

	# plotter = MeshPlotter(mesh, figsize = (20, 20))
	# plotter.draw_vertices(radius = 0.25, text='key')
	# plotter.draw_edges()
	# plotter.draw_faces(text='key')
	# plotter.show()

	# polyedges = [
	# 	[6, 7, 8, 9, 10, 11],
	# 	[0, 1, 2, 3, 4, 5],
Esempio n. 5
0
from random import choice
from numpy import array

import compas

from compas.datastructures import Mesh
from compas.datastructures import mesh_smooth_centroid
from compas.geometry import add_vectors

from compas_plotters import MeshPlotter

mesh = Mesh.from_obj(compas.get('faces.obj'))

key = choice(list(set(mesh.vertices()) - set(mesh.vertices_on_boundary())))

mesh.vertex[key]['x'] += 0.3
mesh.vertex[key]['y'] += 0.3

mesh_smooth_centroid(mesh, fixed=list(mesh.vertices_on_boundary()))

plotter = MeshPlotter(mesh, figsize=(8, 5), tight=True)

plotter.draw_vertices()
plotter.draw_edges()
plotter.draw_faces()

plotter.show()
Esempio n. 6
0
class SkeletonVol(Mesh):
    """ SkeletonVol is typologically constructed low poly mesh.
    It construct a branch like volumetric mesh from input lines. 
    """
    def __init__(self):
        super(SkeletonVol, self).__init__()

    @classmethod
    def from_skeleton_lines(cls, lines=[]):
        skeleton_vol = cls()

        network = Network.from_lines(lines)
        convex_hull_mesh = get_convex_hull_mesh(points)

    def get_convex_hull_mesh(points):
        faces = convex_hull(points)
        vertices = list(set(flatten(faces)))

        i_index = {i: index for index, i in enumerate(vertices)}
        vertices = [points[index] for index in vertices]
        faces = [[i_index[i] for i in face] for face in faces]
        faces = unify_cycles(vertices, faces)

        mesh = Mesh.from_vertices_and_faces(vertices, faces)

        return mesh

    guids = compas_rhino.select_lines()
    lines = compas_rhino.get_line_coordinates(guids)

    network = Network.from_lines(lines)

    leafs = []
    joints = []
    for key in network.node:
        if network.is_leaf(key):
            leafs.append(key)
        else:
            joints.append(key)

    pt_center = network.node_coordinates(joints[0])
    pts = [network.node_coordinates(key) for key in leafs]

    convex_hull_mesh = get_convex_hull_mesh(pts)

    mesh = Mesh()
    # for key in convex_hull_mesh.vertices():
    #     mesh.add_vertex(key)
    #     mesh.vertex[key].update(convex_hull_mesh.vertex[key])

    descdent_tree = copy.deepcopy(convex_hull_mesh.halfedge)

    for u, v in convex_hull_mesh.edges():
        descdent_tree[u][v] = {'jp': None, 'lp': None}
        descdent_tree[v][u] = {'jp': None, 'lp': None}

    # current_key = convex_hull_mesh.number_of_vertices()
    current_key = 0

    for fkey in convex_hull_mesh.faces():
        f_centroid = convex_hull_mesh.face_centroid(fkey)
        vec = Vector.from_start_end(pt_center, f_centroid)

        # if the branches has a 'convex' corner,
        # flip the vec to the corresponding face.
        f_normal = convex_hull_mesh.face_normal(fkey)
        angle = angle_vectors(f_normal, vec, False)
        if angle > math.pi * 0.5:
            pln = Plane(pt_center, f_normal)
            pt_mirror = mirror_point_plane(f_centroid, pln)
            vec = Vector.from_start_end(pt_center, pt_mirror)

        vec.unitize()
        vec.scale(joint_width)

        pt = add_vectors(pt_center, vec)

        face = convex_hull_mesh.face[fkey]
        v_keys = face + [face[0]]
        for u, v in pairwise(v_keys):
            descdent_tree[u][v].update({'jp': current_key})

        mesh.add_vertex(current_key)
        mesh.vertex[current_key].update({'x': pt[0], 'y': pt[1], 'z': pt[2]})

        current_key += 1

    for key in convex_hull_mesh.vertices():
        nbrs = convex_hull_mesh.vertex_neighbors(key)
        for nbr in nbrs:
            halfedge = (key, nbr)
            pt_joint_descendent = mesh.vertex_coordinates(
                descdent_tree[key][nbr]['jp'])

            vec_edge = Vector.from_start_end(
                pt_center, convex_hull_mesh.vertex_coordinates(key))
            pln_end = Plane(convex_hull_mesh.vertex_coordinates(key), vec_edge)
            pt = project_point_plane(pt_joint_descendent, pln_end)
            vec_leaf = Vector.from_start_end(
                convex_hull_mesh.vertex_coordinates(key), pt)
            vec_leaf.unitize()
            vec_leaf.scale(leaf_width)
            pt = add_vectors(convex_hull_mesh.vertex_coordinates(key),
                             vec_leaf)

            descdent_tree[key][nbr].update({'lp': current_key})

            mesh.add_vertex(current_key)
            mesh.vertex[current_key].update({
                'x': pt[0],
                'y': pt[1],
                'z': pt[2]
            })
            current_key += 1

    for key in convex_hull_mesh.vertices():
        nbrs = convex_hull_mesh.vertex_neighbors(key, ordered=True)
        v_keys = nbrs + [nbrs[0]]
        for a, b in pairwise(v_keys):
            face = [
                descdent_tree[key][a]['lp'], descdent_tree[key][a]['jp'],
                descdent_tree[key][b]['jp'], descdent_tree[key][b]['lp']
            ]
            mesh.add_face(face)

    fixed = list(mesh.vertices_where({'vertex_degree': 3}))
    fixed = list(mesh.vertices())

    mesh = mesh_subdivide_catmullclark(mesh, k=1, fixed=fixed)
    # mesh = mesh_subdivide_quad(mesh, k=1)
    mesh_smooth_centroid(mesh, fixed=fixed)

    artist = MeshArtist(mesh)
    artist.draw_mesh()