from compas.geometry import Point
from compas.geometry import Polyline, Bezier
from compas_occ.geometry import OCCNurbsCurve
from compas_view2.app import App
from compas_view2.objects import Collection


points = [Point(0, 0, 0), Point(3, 6, 0), Point(6, -3, 3), Point(10, 0, 0)]
bezier = Bezier(points)
points = bezier.locus(10)

curve = OCCNurbsCurve.from_interpolation(points)

# ==============================================================================
# Visualisation
# ==============================================================================

view = App()

view.add(Polyline(curve.locus()), linewidth=3)
view.add(Collection(points))

view.run()
Exemplo n.º 2
0
# ==============================================================================

assembly = Assembly()
for mesh in meshes:
    block = mesh.copy(cls=Block)
    assembly.add_block(block)

# ==============================================================================
# Export
# ==============================================================================

compas.json_dump(assembly, FILE_O)

# ==============================================================================
# Viz
# ==============================================================================

viewer = App()

nodes = []
blocks = []

for node in assembly.nodes():
    nodes.append(Point(* assembly.node_coordinates(node)))
    blocks.append(assembly.node_attribute(node, 'block'))

viewer.add(Collection(nodes))
viewer.add(Collection(blocks), show_faces=True, show_edges=True, facecolor=(0.8, 0.8, 0.8), linecolor=(0, 0, 0))

viewer.run()
Exemplo n.º 3
0
spline1 = BSplineCurve.from_points(points1)

points2 = []
points2.append(Point(-4, 0, 2))
points2.append(Point(-2, 2, 0))
points2.append(Point(2, 3, -1))
points2.append(Point(3, 7, -2))
points2.append(Point(4, 9, -1))
spline2 = BSplineCurve.from_points(points2)

surface = BSplineSurface.from_fill(spline1, spline2)
points = surface.xyz(nu=30, nv=20)

n = len(points)

colors = [i_to_rgb(i / n, normalize=True) for i in range(n)]

# ==============================================================================
# Viz
# ==============================================================================

mesh = surface.to_vizmesh()
boundary = Polyline(
    mesh.vertices_attributes('xyz', keys=mesh.vertices_on_boundary()))

view = App()
view.add(mesh)
view.add(boundary, linewidth=2)
view.add(Collection(points), colors=colors, size=10)
view.run()
Exemplo n.º 4
0
points1.append(Point(-7, 2, 2))
points1.append(Point(-6, 3, 1))
points1.append(Point(-4, 3, -1))
points1.append(Point(-3, 5, -2))
spline1 = BSplineCurve.from_points(points1)

points2 = []
points2.append(Point(-4, 0, 2))
points2.append(Point(-2, 2, 0))
points2.append(Point(2, 3, -1))
points2.append(Point(3, 7, -2))
points2.append(Point(4, 9, -1))
spline2 = BSplineCurve.from_points(points2)

surface = BSplineSurface.from_fill(spline1, spline2)

points = Collection(surface.xyz(nu=100, nv=100))

# ==============================================================================
# Viz
# ==============================================================================

mesh = surface.to_vizmesh()
boundary = Polyline(
    mesh.vertices_attributes('xyz', keys=mesh.vertices_on_boundary()))

view = App()
view.add(boundary, linewidth=2)
view.add(points, color=(1, 0, 0), size=30)
view.run()
Exemplo n.º 5
0
# ==============================================================================

view = App(viewmode='ghosted')

for row in surface.points:
    view.add(Polyline(row),
             show_points=True,
             pointsize=20,
             pointcolor=(1, 0, 0),
             linewidth=2,
             linecolor=(0.3, 0.3, 0.3))

for col in zip(*surface.points):
    view.add(Polyline(col),
             show_points=True,
             pointsize=20,
             pointcolor=(1, 0, 0),
             linewidth=2,
             linecolor=(0.3, 0.3, 0.3))

view.add(Collection(intersections), size=30, color=(0, 0, 1))

for x in intersections:
    view.add(Line(base, base + (x - base).scaled(1.2)),
             linewidth=1,
             color=(0, 0, 1))

view.add(surface.to_mesh(), show_edges=False)

view.run()
Exemplo n.º 6
0
viewer = App()

nodes = []
blocks = []
interfaces = []
sides = []
colors = []

for node in assembly.nodes():
    nodes.append(Point(* assembly.node_coordinates(node)))
    blocks.append(assembly.node_attribute(node, 'block'))

for node in assembly.nodes():
    block = assembly.node_attribute(node, 'block')
    faces = sorted(block.faces(), key=lambda face: block.face_area(face))[:-2]
    for face in faces:
        side = Polygon(block.face_coordinates(face))
        mesh = Mesh.from_polygons([side])
        sides.append(mesh)

for mesh in sides:
    face = list(mesh.faces())[0]
    dev = mesh.face_flatness(face)
    colors.append(i_to_red(dev, normalize=True))

viewer.add(Collection(blocks), show_faces=False, show_edges=True)
viewer.add(Collection(sides), colors=colors, show_edges=False)

viewer.run()
Exemplo n.º 7
0
from compas.geometry import Point
from compas.geometry import Line, Polyline
from compas_occ.geometry import OCCNurbsCurve
from compas_view2.app import App
from compas_view2.objects import Collection

line = Line(Point(0, 0, 0), Point(3, 3, 0))
curve = OCCNurbsCurve.from_line(line)

# ==============================================================================
# Visualisation
# ==============================================================================

view = App()

view.add(Polyline(curve.locus()), linewidth=3)
view.add(Collection(curve.points), size=20, color=(1, 0, 0))

view.run()
Exemplo n.º 8
0
# ==============================================================================
# Visualization with viewer
# ==============================================================================

viewer = App(width=1600, height=900)

viewer.view.camera.rz = 0
viewer.view.camera.rx = -85
viewer.view.camera.tx = 0
viewer.view.camera.ty = 0
viewer.view.camera.distance = 7

T = Translation.from_vector([0, 0, 0.5])
for tet in top:
    tet.transform(T)

T = Translation.from_vector([0, 0, -0.5])
for tet in bottom:
    tet.transform(T)

viewer.add(Collection(bottom_exterior), facecolor=(1, 0, 0))
viewer.add(Collection(bottom_interior))

viewer.add(Collection(top_exterior), facecolor=(0, 1, 0))
viewer.add(Collection(top_interior))

# viewer.add(shell)

viewer.run()
Exemplo n.º 9
0
    [Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0), Point(4, 1, 0)],
    [Point(0, 2, 0), Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0), Point(4, 2, 0)],
    [Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)

# ==============================================================================
# Points over UV space
# ==============================================================================

spacepoints = surface.xyz(nu=50, nv=10)

# ==============================================================================
# Visualisation
# ==============================================================================

view = App()

for row in surface.points:
    view.add(Polyline(row), show_points=True, pointsize=20, pointcolor=(1, 0, 0), linewidth=2, linecolor=(1.0, 0.5, 0.5))

for col in zip(* surface.points):
    view.add(Polyline(col), show_points=True, pointsize=20, pointcolor=(1, 0, 0), linewidth=2, linecolor=(0.5, 1.0, 0.5))

view.add(surface.to_mesh(), show_edges=False)

view.add(Collection(spacepoints))

view.run()
Exemplo n.º 10
0
# Viz
# ==============================================================================

viewer = App()

nodes = []
blocks = []
interfaces = []
interactions = []

for node in assembly.nodes():
    nodes.append(Point(* assembly.node_coordinates(node)))
    blocks.append(assembly.node_attribute(node, 'block'))

for edge in assembly.edges():
    interface = assembly.edge_attribute(edge, 'interface')
    polygon = Polygon(interface.points)
    interfaces.append(Mesh.from_polygons([polygon]))

for edge in assembly.edges():
    a = Point(* assembly.node_coordinates(edge[0]))
    b = Point(* assembly.node_coordinates(edge[1]))
    interactions.append(Line(a, b))

viewer.add(Collection(nodes))
viewer.add(Collection(blocks), show_faces=False, show_edges=True)
viewer.add(Collection(interfaces), show_edges=False, color=(0, 0, 1), opacity=0.5)
viewer.add(Collection(interactions))

viewer.run()