Local Coordinates
Blocks to origin with flat face on bottom
import os
import json
from compas.geometry import subtract_vectors, cross_vectors
from compas.geometry import Frame, Transformation
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist
HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'blocksflat.json')
with open(FILE_I, 'r') as f:
blocks = [Mesh.from_data(data) for data in json.load(f)]
world = Frame.worldXY()
for block in blocks:
point = block.face_centroid(1)
normal = block.face_normal(1)
vertices = block.face_vertices(1)
xaxis = subtract_vectors(block.vertex_attributes(vertices[0], 'xyz'), point)
yaxis = cross_vectors(xaxis, normal)
local = Frame(point, xaxis, yaxis)
X = Transformation.from_frame_to_frame(local, world)
block.transform(X)
artist = MeshArtist(None, layer="RV2::BlocksTransformed")
artist.clear_layer()
for block in blocks:
artist.mesh = block
artist.draw_faces(color=(0, 255, 0), join_faces=True)
artist.redraw()
Last updated