a = Mesh.from_obj(igl.get('libigl-tutorial-data/cube.obj')) b = Mesh.from_obj(igl.get('libigl-tutorial-data/sphere.obj')) c = Mesh.from_obj(igl.get('libigl-tutorial-data/xcylinder.obj')) d = Mesh.from_obj(igl.get('libigl-tutorial-data/ycylinder.obj')) e = Mesh.from_obj(igl.get('libigl-tutorial-data/zcylinder.obj')) VA = numpy.array(a.get_vertices_attributes('xyz'), dtype=numpy.float64) FA = numpy.array([a.face_vertices(face) for face in a.faces()], dtype=numpy.int32) VB = numpy.array(b.get_vertices_attributes('xyz'), dtype=numpy.float64) FB = numpy.array([b.face_vertices(face) for face in b.faces()], dtype=numpy.int32) VC = numpy.array(c.get_vertices_attributes('xyz'), dtype=numpy.float64) FC = numpy.array([c.face_vertices(face) for face in c.faces()], dtype=numpy.int32) VD = numpy.array(d.get_vertices_attributes('xyz'), dtype=numpy.float64) FD = numpy.array([d.face_vertices(face) for face in d.faces()], dtype=numpy.int32) VE = numpy.array(e.get_vertices_attributes('xyz'), dtype=numpy.float64) FE = numpy.array([e.face_vertices(face) for face in e.faces()], dtype=numpy.int32) result = igl.mesh_csgtree(VA, FA, VB, FB, VC, FC, VD, FD, VE, FE) m = Mesh.from_vertices_and_faces(result.vertices, result.faces) viewer = MultiMeshViewer() viewer.meshes = [m] viewer.show()
A, B = mesh.cut(plane) for _ in range(0, 7): plane = cutting_plane(A, ry=-40, rz=0) A, b = A.cut(plane) red.append(b) vector = plane.normal.scaled(0.1) T = Translation(vector) A.transform(T) red.append(A) for _ in range(0, 7): plane = cutting_plane(B, ry=40, rz=0) a, B = B.cut(plane) blue.append(a) vector = plane.normal.scaled(-0.1) T = Translation(vector) B.transform(T) blue.append(B) # ============================================================================== # Visualize # ============================================================================== meshes = [MeshObject(mesh, color='#0000ff') for mesh in blue] meshes += [MeshObject(mesh, color='#ff0000') for mesh in red] viewer = MultiMeshViewer() viewer.meshes = meshes viewer.show()
b = Mesh.from_vertices_and_faces(* sphere.to_vertices_and_faces(u=30, v=30)) c = Mesh.from_vertices_and_faces(* xcyl.to_vertices_and_faces(u=30)) d = Mesh.from_vertices_and_faces(* ycyl.to_vertices_and_faces(u=30)) e = Mesh.from_vertices_and_faces(* zcyl.to_vertices_and_faces(u=30)) mesh_quads_to_triangles(a) mesh_quads_to_triangles(b) mesh_quads_to_triangles(c) mesh_quads_to_triangles(d) mesh_quads_to_triangles(e) VA = numpy.array(a.get_vertices_attributes('xyz'), dtype=numpy.float64) FA = numpy.array([a.face_vertices(face) for face in a.faces()], dtype=numpy.int32) VB = numpy.array(b.get_vertices_attributes('xyz'), dtype=numpy.float64) FB = numpy.array([b.face_vertices(face) for face in b.faces()], dtype=numpy.int32) VC = numpy.array(c.get_vertices_attributes('xyz'), dtype=numpy.float64) FC = numpy.array([c.face_vertices(face) for face in c.faces()], dtype=numpy.int32) VD = numpy.array(d.get_vertices_attributes('xyz'), dtype=numpy.float64) FD = numpy.array([d.face_vertices(face) for face in d.faces()], dtype=numpy.int32) VE = numpy.array(e.get_vertices_attributes('xyz'), dtype=numpy.float64) FE = numpy.array([e.face_vertices(face) for face in e.faces()], dtype=numpy.int32) result = igl.mesh_csgtree(VA, FA, VB, FB, VC, FC, VD, FD, VE, FE) m = Mesh.from_vertices_and_faces(result.vertices, result.faces) viewer = MultiMeshViewer() # viewer.meshes = [MeshObject(a, '#ff0000'), MeshObject(b, '#00ff00'), MeshObject(c, '#0000ff'), MeshObject(d, '#0000ff'), MeshObject(e, '#0000ff')] viewer.meshes = [MeshObject(m, '#cccccc')] viewer.show()
import compas from compas.datastructures import Mesh, mesh_transformed from compas.utilities import download_file_from_remote from compas_viewers.multimeshviewer import MultiMeshViewer source_glb = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BoxInterleaved/glTF-Binary/BoxInterleaved.glb' filepath_glb = os.path.join(compas.APPDATA, 'data', 'gltfs', 'khronos', 'BoxInterleaved.glb') download_file_from_remote(source_glb, filepath_glb, overwrite=False) gltf = GLTF(filepath_glb) gltf.read() default_scene = gltf.content.default_or_first_scene transformed_meshes = [] for vertex_name, gltf_node in default_scene.nodes.items(): if gltf_node.mesh_data is None: continue t = gltf_node.transform m = Mesh.from_vertices_and_faces(gltf_node.vertices, gltf_node.faces) transformed_mesh = mesh_transformed(m, t) transformed_meshes.append(transformed_mesh) viewer = MultiMeshViewer() viewer.meshes = transformed_meshes viewer.show()
loop = trimesh_subdivide_loop frames = mesh_subdivide_frames box = Box.from_corner_corner_height((0.0, 0.0, 0.0), (1.0, 1.0, 0.0), 1.0) mesh = Mesh.from_shape(box) trimesh = mesh.copy() mesh_quads_to_triangles(trimesh) tri_mesh = tri(mesh, k=3) quad_mesh = quad(mesh, k=3) ck_mesh = ck(mesh, k=3) corner_mesh = corner(mesh, k=3) doosabin_mesh = doosabin(mesh, k=3) loop_mesh = loop(trimesh, k=3) frames_mesh = frames(mesh, 0.1) mesh_transform(quad_mesh, Translation([1.2, 0.0, 0.0])) mesh_transform(corner_mesh, Translation([1.2 * 2, 0.0, 0.0])) mesh_transform(frames_mesh, Translation([1.2 * 3, 0.0, 0.0])) mesh_transform(ck_mesh, Translation([1.2 * 4, 0.0, 0.0])) mesh_transform(doosabin_mesh, Translation([1.2 * 5, 0.0, 0.0])) mesh_transform(loop_mesh, Translation([1.2 * 6, 0.0, 0.0])) viewer = MultiMeshViewer() viewer.meshes = [ tri_mesh, quad_mesh, corner_mesh, frames_mesh, ck_mesh, doosabin_mesh, loop_mesh ] viewer.show()
from compas.geometry import Translation from compas.geometry import Rotation from compas_viewers.multimeshviewer import MultiMeshViewer from compas_viewers.multimeshviewer import MeshObject # make 10 random meshes # with random position and orientation meshes = [] for i in range(10): T = Translation( [random.randint(0, 10), random.randint(0, 10), random.randint(0, 5)]) R = Rotation.from_axis_and_angle([0, 0, 1.0], radians(random.randint(0, 180))) X = T * R box = Box.from_width_height_depth(random.randint(1, 3), random.randint(1, 3), random.randint(1, 3)) mesh = Mesh.from_shape(box) mesh_transform_numpy(mesh, X) # this is not ideal and should be handled behind the screens meshes.append(MeshObject(mesh, color=rgb_to_hex((210, 210, 210)))) viewer = MultiMeshViewer() viewer.meshes = meshes viewer.zoom_extents() viewer.show()