Blocks

Blocks with curved surfaces

from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

FILE_I1 = 'form_idos.json'
FILE_I2 = 'form_edos.json'

FILE_O = 'blocks.json'

idos = Mesh.from_json(FILE_I1)
edos = Mesh.from_json(FILE_I2)

blocks = []

for face in idos.faces():
    bottom = idos.face_coordinates(face)
    top = edos.face_coordinates(face)

    f = len(bottom)

    faces = [
        list(range(f)),
        list(range(f + f - 1, f - 1, -1))]

    for i in range(f - 1):
        faces.append([i, i + f, i + f + 1, i + 1])
    faces.append([f - 1, f + f - 1, f, 0])

    block = Mesh.from_vertices_and_faces(bottom + top, faces)
    blocks.append(block)


with open(FILE_O, 'w+') as f:
    data = [block.to_data()for block in blocks]
    json.dump(data, f)

artist = MeshArtist(None, layer="RV2::Blocks")
artist.clear_layer()

for block in blocks:
    artist.mesh = block
    artist.draw_faces(color=(0, 255, 255), join_faces=True)

artist.redraw()

Last updated