Example #1
0
from compas.datastructures import Mesh
from compas.geometry import Translation, Scale, Point

tetra = Mesh.from_polyhedron(4)
hexa = Mesh.from_polyhedron(6)
octa = Mesh.from_polyhedron(8)
dodeca = Mesh.from_polyhedron(12)
icosa = Mesh.from_polyhedron(20)

o = Point(0, 0, 0)

T = Translation.from_vector([2.5, 0, 0])

p = Point(* tetra.vertex_coordinates(tetra.get_any_vertex()))
s = 1 / (p - o).length
S = Scale.from_factors([s, s, s])

tetra.transform(S)
tetra.dual()

p = Point(* hexa.vertex_coordinates(hexa.get_any_vertex()))
s = 1 / (p - o).length
S = Scale.from_factors([s, s, s])

hexa.transform(T * S)
hexa.dual()

p = Point(* octa.vertex_coordinates(octa.get_any_vertex()))
s = 1 / (p - o).length
S = Scale.from_factors([s, s, s])
Example #2
0

# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    from compas.geometry import Point
    from compas.geometry import Line
    from compas.geometry import Frame

    from compas.datastructures import Mesh

    scene = Scene()

    a = Point(1.0, 1.0, 0.0)
    b = Point(5.0, 5.0, 0.0)
    ab = Line(a, b)
    world = Frame.worldXY()

    mesh = Mesh.from_polyhedron(6)

    scene.add(a, name="A", color=(0, 0, 0), layer="A")
    scene.add(b, name="B", color=(255, 255, 255), layer="B")
    scene.add(ab, name="AB", color=(128, 128, 128), layer="AB")
    scene.add(world, name="World", layer="World")
    scene.add(mesh, name="Cube", layer="Cube")

    scene.update()
Example #3
0
 def from_polyhedron(self, f):
     self.mesh = Mesh.from_polyhedron(f)
     self.view.make_buffers()
     self.view.updateGL()
Example #4
0
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]))
Example #5
0
        self.controller = Front(self)
        self.view = View(self.controller)
        self.setup()
        self.init()

    @property
    def mesh(self):
        return self.controller.mesh

    @mesh.setter
    def mesh(self, mesh):
        self.controller.mesh = mesh
        self.controller.center_mesh()

        self.view.glInit()
        self.view.make_buffers()
        self.view.update()


# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    viewer = Viewer()

    viewer.mesh = Mesh.from_polyhedron(6)

    viewer.show()
Example #6
0
def test_from_polyhedron():
    mesh = Mesh.from_polyhedron(8)
    assert mesh.number_of_faces() == 8
    assert mesh.number_of_vertices() == 6
    assert mesh.number_of_edges() == 12
def mesh_tris():
    mesh = Mesh.from_polyhedron(6)
    mesh.quads_to_triangles()
    return mesh
def mesh_quads():
    mesh = Mesh.from_polyhedron(6)
    return mesh
Example #9
0
def cube():
    return Mesh.from_polyhedron(6)
Example #10
0
def tet():
    return Mesh.from_polyhedron(4)
Example #11
0
artist6.draw_edgelabels()

# Subdivide a mesh following the doo-sabin scheme
subd = sd.mesh_subdivide_doosabin(mesh, k=1, fixed=None)
artist7 = MeshArtist(subd, layer="06_subdivide_doosabin")
artist7.clear_layer()
artist7.draw_vertices()
artist7.draw_faces()
artist7.draw_edges()
artist7.draw_vertexlabels()
artist7.draw_facelabels()
artist7.draw_edgelabels()

# 3d mesh - Custom rules
# n of faces - 4, 6, 8, 12, 20
poly = Mesh.from_polyhedron(8)

S = Scale.from_factors([5, 5, 5])
poly.transform(S)

point = [8, 0.5, 0]
T = Translation.from_vector(point)
poly.transform(T)

mesh2 = sd.mesh_subdivide_tri(poly)
mesh3 = mesh_subdivide_pyramid(mesh2, k=1, height=0.5)
mesh4 = sd.trimesh_subdivide_loop(mesh3)
mesh5 = sd.mesh_subdivide_catmullclark(mesh4)

# subdivide each face of the mesh
centers = []