surface = RhinoSurface.from_guid(guid) block = surface.to_compas() block.name = str(guid) bottom = sorted( block.faces(), key=lambda face: dot_vectors(block.face_normal(face), [0, 0, -1]))[-1] plane = block.face_centroid(bottom), block.face_normal(bottom) frame = Frame.from_plane(plane) T = Transformation.from_frame_to_frame(frame, world) block.transform(T) blank = Box.from_bounding_box(block.bounding_box()) blank.xsize += 25 blank.ysize += 25 blank.zsize += 25 block.attributes['blank'] = blank block.attributes['bottom'] = bottom blocks.append(block) # ============================================================================== # Export # ============================================================================== with open(FILE, 'w') as f: json.dump(blocks, f, cls=DataEncoder)
# ============================================================================== T = Translation.from_vector(Point(0, 0, 0) - Point(*before.centroid())) S = Scale.from_factors([100, 100, 100]) R = Rotation.from_axis_and_angle([1, 0, 0], radians(90)) before.transform(R * S * T) # ============================================================================== # Remesh # ============================================================================== L = sum(before.edge_length(*edge) for edge in before.edges()) / before.number_of_edges() V, F = trimesh_remesh(before.to_vertices_and_faces(), 3 * L) after = Mesh.from_vertices_and_faces(V, F) # ============================================================================== # Viz # ============================================================================== viewer = App() box = Box.from_bounding_box(before.bounding_box()) dx = 1.5 * box.xsize viewer.add(before) viewer.add(after.transformed(Translation.from_vector([dx, 0, 0]))) viewer.run()
# ============================================================================== box = Box.from_width_height_depth(2, 2, 2) box = Mesh.from_shape(box) box.quads_to_triangles() A = box.to_vertices_and_faces() sphere = Sphere(Point(1, 1, 1), 1) sphere = Mesh.from_shape(sphere, u=30, v=30) sphere.quads_to_triangles() B = sphere.to_vertices_and_faces() bbox = bounding_box(box.vertices_attributes('xyz') + sphere.vertices_attributes('xyz')) bbox = Box.from_bounding_box(bbox) width = bbox.xsize # ============================================================================== # Remesh the sphere # ============================================================================== B = remesh(B, 0.3, 10) # ============================================================================== # Compute the boolean union # ============================================================================== V, F = boolean_union(A, B)
from compas.datastructures import Mesh from compas.geometry import Point, Box from compas.geometry import Translation, Scale from compas_view2 import app box = Box.from_diagonal([(0.0, 0.0, 0.0), (1.0, 1.0, 1.0)]) mesh = Mesh.from_shape(box) trimesh = Mesh.from_polyhedron(4) tribox = Box.from_bounding_box(trimesh.bounding_box()) S = tribox.width / box.width trimesh.transform(Scale.from_factors([S, S, S])) trimesh.transform( Translation.from_vector(Point(0.5, 0.5, 0.5) - Point(0, 0, 0))) tri = mesh.subdivide(k=3, scheme='tri') quad = mesh.subdivide(k=3, scheme='quad') corner = mesh.subdivide(k=3, scheme='corner') ck = mesh.subdivide(k=3, scheme='catmullclark') doosabin = mesh.subdivide(k=3, scheme='doosabin') frames = mesh.subdivide(offset=0.2, scheme='frames') loop = trimesh.subdivide(k=3, scheme='loop') corner.transform(Translation.from_vector([1.2 * 1, 0.0, 0.0])) loop.transform(Translation.from_vector([1.2 * 2, 0.0, 0.0])) quad.transform(Translation.from_vector([1.2 * 3, 0.0, 0.0])) ck.transform(Translation.from_vector([1.2 * 4, 0.0, 0.0])) doosabin.transform(Translation.from_vector([1.2 * 5, 0.0, 0.0])) frames.transform(Translation.from_vector([1.2 * 6, 0.0, 0.0]))