Beispiel #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)
# Box in the world coordinate system
frame = Frame([1, 0, 0], [-0.45, 0.1, 0.3], [1, 0, 0])
width, length, height = 1, 1, 1
box = Box(frame, width, length, height)

# Frame F representing a coordinate system
F = Frame([2, 2, 2], [0.978, 0.010, -0.210], [0.090, 0.882, 0.463])

# Get transformation between frames and apply transformation on box.
T = Transformation.from_frame_to_frame(Frame.worldXY(), F)
box_transformed = box.transformed(T)

# make Mesh from box
mesh_transformed = Mesh.from_shape(box_transformed)

# create Projection
P = Projection.from_plane_and_direction(Plane((0, 0, 0), (0, 0, 1)), (3, 5, 5))
P = Projection.from_plane(Plane((0, 0, 0), (0, 0, 1)))
P = Projection.from_plane_and_point(Plane((0, 0, 0), (0, 0, 1)), (3, 5, 5))

# apply transformation on mesh
mesh_projected = mesh_transformed.transformed(P)

# create artists
artist1 = BoxArtist(box_transformed)
artist2 = MeshArtist(mesh_projected)

# draw
artist1.draw()
artist2.draw()
Beispiel #3
0
import compas
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

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

artist = MeshArtist(mesh, layer="ITA20::Tubemesh")
artist.clear_layer()
artist.draw()
Beispiel #4
0
mesh = Mesh.from_off(compas.get('tubemesh.off'))

start = random.choice(list(mesh.edges()))
loop = mesh.edge_loop(start)
strip = [mesh.edge_faces(*edge) for edge in mesh.edge_strip(start)]
strip[:] = list(set(flatten(strip)))

edgecolor = {}
for edge in loop:
    edgecolor[edge] = (0, 255, 0)

edgecolor[start] = (255, 0, 0)

facecolor = {}
for face in strip:
    facecolor[face] = (255, 200, 200)

artist = MeshArtist(mesh, layer='Tubemesh')
artist.clear_layer()
artist.draw_faces(color=facecolor)
# artist.draw_edges(color=edgecolor)

for edge in edgecolor:
    o = mesh.edge_midpoint(*edge)
    n = mesh.edge_direction(*edge)
    h = mesh.edge_length(*edge)

    cylinder = Cylinder([(o, n), 0.02], h)
    artist = CylinderArtist(cylinder, color=(0, 255, 0), layer='Tubemesh')
    artist.draw(show_vertices=False)