Exemplo n.º 1
0
    block.attributes['blank'] = blank
    block.attributes['bottom'] = bottom

    blocks.append(block)

# ==============================================================================
# Export
# ==============================================================================

with open(FILE, 'w') as f:
    json.dump(blocks, f, cls=DataEncoder)

# ==============================================================================
# Visualize
# ==============================================================================

compas_rhino.clear_layers(["ITA20::Assignment1"])

for block in blocks:
    artist = MeshArtist(block,
                        layer="ITA20::Assignment1::{}::Block".format(
                            block.name))
    artist.draw_faces(color={block.attributes['bottom']: (255, 0, 0)})

    blank = block.attributes['blank']

    artist = BoxArtist(blank,
                       layer="ITA20::Assignment1::{}::Blank".format(
                           block.name))
    artist.draw(show_edges=True, show_faces=False)
Exemplo n.º 2
0
import compas
import compas_rhino
from compas_rhino.geometry import RhinoSurface
from compas_rhino.artists import MeshArtist


def filterfunc(face):
    return True


FILE = os.path.join(os.path.dirname(__file__), 'armadillo_meshes.json')

guids = []
for guid in compas_rhino.select_surfaces():
    if compas_rhino.rs.IsPolysurface(guid):
        guids.append(guid)

meshes = []
for guid in guids:
    surf = RhinoSurface.from_guid(guid)
    mesh = surf.to_compas(facefilter=filterfunc)
    meshes.append(mesh)

compas.json_dump(meshes, FILE)

compas_rhino.clear_layers(['Armadillo'])

for mesh in meshes:
    artist = MeshArtist(mesh, layer="Armadillo::Meshes")
    artist.draw()
Exemplo n.º 3
0
def draw_volmesh(volmesh,
                 name=None,
                 layer=None,
                 clear=True,
                 redraw=True,
                 show_faces=True,
                 show_vertices=True,
                 show_edges=True,
                 vertex_color=None,
                 edge_color=None,
                 face_color=None):
    """"""
    # set default options
    if not isinstance(vertex_color, dict):
        vertex_color = {}
    if not isinstance(edge_color, dict):
        edge_color = {}
    if not isinstance(face_color, dict):
        face_color = {}
    if name:
        volmesh.attributes['name'] = name
    name = volmesh.setdefault('name', name)
    if layer:
        volmesh.attributes['layer'] = layer
    layer = volmesh.setdefault('layer', layer)
    # delete all relevant objects by name
    objects = compas_rhino.get_objects(name='{0}.mesh'.format(name))
    objects += compas_rhino.get_objects(name='{0}.vertex.*'.format(name))
    objects += compas_rhino.get_objects(name='{0}.edge.*'.format(name))
    compas_rhino.delete_objects(objects)
    # clear the layer if requested
    if clear:
        compas_rhino.clear_layers([layer])
    # draw the requested components
    if show_faces:
        faces = []
        color = volmesh.attributes['color.face']
        for vertices in volmesh.faces():
            points = [
                volmesh.vertex_coordinates(vkey)
                for vkey in vertices + [vertices[0]]
            ]
            faces.append({
                'points': points,
                'name': '',
                'color': color,
            })
        compas_rhino.xdraw_faces(faces, layer=layer, clear=False, redraw=False)
    if show_edges:
        lines = []
        color = volmesh.attributes['color.edge']
        for u, v in volmesh.edges_iter():
            lines.append({
                'start': volmesh.vertex_coordinates(u),
                'end': volmesh.vertex_coordinates(v),
                'name': '{0}.edge.{1}-{2}'.format(name, u, v),
                'color': edge_color.get((u, v), color),
            })
        compas_rhino.xdraw_lines(lines, layer=layer, clear=False, redraw=False)
    if show_vertices:
        points = []
        color = volmesh.attributes['color.vertex']
        for key in volmesh.vertices_iter():
            points.append({
                'pos': volmesh.vertex_coordinates(key),
                'name': '{0}.vertex.{1}'.format(name, key),
                'color': vertex_color.get(key, color),
            })
        compas_rhino.xdraw_points(points,
                                  layer=layer,
                                  clear=False,
                                  redraw=False)
    # redraw if requested
    if redraw:
        rs.Redraw()
Exemplo n.º 4
0
    mpoints.append(p)
    mpoints1.append(p1)
    mpoints2.append(p2)

for (a, b), (a1, b1), (a2, b2) in zip(pairwise(mpoints), pairwise(mpoints1),
                                      pairwise(mpoints2)):
    p = (a + b) * 0.5
    t = (b - a).unitized()
    n = Vector(0, 0, 1).cross(t)
    frame = Frame(p, t, n)
    frames.append(frame)
    l1 = (b1 - a1).length
    l2 = (b2 - a2).length
    block = Box(frame, min(l1, l2) - 0.03, 0.3, 0.1)
    block.transform(Translation.from_vector([0, 0, 0.1]))
    blocks1.append(block)

# ==============================================================================
# Visualization
# ==============================================================================

compas_rhino.clear_layers(["Wall::Blocks"])

for block in blocks0:
    artist = BoxArtist(block, layer="Wall::Blocks")
    artist.draw()

for block in blocks1:
    artist = BoxArtist(block, layer="Wall::Blocks")
    artist.draw()
Exemplo n.º 5
0

def filterfunc(face):
    success, w, h = face.GetSurfaceSize()
    if success:
        if w > 10 and h > 10:
            return True
    return False


FILE = os.path.join(os.path.dirname(__file__), 'crossvault_meshes.json')

guids = []
for guid in compas_rhino.select_surfaces():
    if compas_rhino.rs.IsPolysurface(guid):
        guids.append(guid)

meshes = []
for guid in guids:
    surf = RhinoSurface.from_guid(guid)
    mesh = surf.to_compas(facefilter=filterfunc)
    meshes.append(mesh)

compas.json_dump(meshes, FILE)

compas_rhino.clear_layers(['Crossvault'])

for mesh in meshes:
    artist = MeshArtist(mesh, layer="Crossvault::Meshes")
    artist.draw()