Ejemplo n.º 1
0
# Process output
# ==============================================================================

polylines = []
for points in pointsets:
    points = [Point(*point) for point in points]
    polyline = Polyline(points)
    polylines.append(polyline)

# ==============================================================================
# Visualize
# ==============================================================================

meshartist = MeshArtist(None)

meshartist.mesh = Mesh.from_vertices_and_faces(*A)
meshartist.layer = "CGAL::Intersections::A"
meshartist.clear_layer()
meshartist.draw_faces(join_faces=True, color=hex_to_rgb('#222222'))

meshartist.mesh = Mesh.from_vertices_and_faces(*B)
meshartist.layer = "CGAL::Intersections::B"
meshartist.clear_layer()
meshartist.draw_faces(join_faces=True, color=hex_to_rgb('#888888'))

polylineartist = PolylineArtist(None, layer="CGAL::Intersections::Polylines")
polylineartist.clear_layer()
pointartist = PointArtist(None, layer='CGAL::Intersections::Points')
pointartist.clear_layer()

for polyline in polylines:
mesh.update_default_vertex_attributes({'is_fixed': False})

# make an artist for visualisation
artist = MeshArtist(mesh, layer='SubdModeling::Control')

# draw the control mesh
draw_mesh()

# allow the user to change the attributes of the vertices
while True:
    keys = VertexSelector.select_vertices(mesh)
    if not keys:
        break
    VertexModifier.update_vertex_attributes(mesh, keys)
    draw_mesh()

# make a subd mesh (using catmullclark)
subd = mesh_subdivide(mesh,
                      scheme='catmullclark',
                      k=4,
                      fixed=mesh.vertices_where({'is_fixed': True}))

# give the subdivision mesh a different name
subd.attributes['name'] = 'Mesh'

# draw the result
artist.mesh = subd
artist.layer = 'SubdModeling::Mesh'
artist.clear_layer()
artist.draw_mesh()
Ejemplo n.º 3
0
        'strip': '10'
    })),
]

STRIPS = SOUTH + SW + WEST + NW + NORTH + RING

# ==============================================================================
# Visualise
# ==============================================================================

ARTIST = MeshArtist(FABRIC, layer="Fabric")
ARTIST.clear_layer()

# INTRADOS

ARTIST.mesh = IDOS

ARTIST.layer = "Fabric::Intrados"

for i, strip in enumerate(STRIPS):
    guid = ARTIST.draw_faces(keys=strip, join_faces=True)
    color = (255, 128, 128) if i % 2 else (255, 0, 0)
    rs.ObjectColor(guid, color)

ARTIST.layer = "Fabric::Normals"
ARTIST.draw_facenormals(color=(255, 0, 0), scale=0.05)

# EXTRADOS

ARTIST.mesh = EDOS
# and select a target surface

guid = compas_rhino.select_mesh()
mesh = mesh_from_guid(Mesh, guid)

guid = compas_rhino.select_surface()
surf = RhinoSurface(guid)

# extract the input for the smoothing algorithm from the mesh
# and identify the boundary as fixed

xyz = mesh.get_vertices_attributes('xyz')
faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
adjacency = [mesh.vertex_faces(key, ordered=True) for key in mesh.vertices()]
fixed = set(mesh.vertices_on_boundary())

# run the smoothing algorithm

smooth_area(xyz, faces, adjacency, fixed=fixed, kmax=100, callback=callback)

# update the mesh when smoothing is done
# and draw the result

for key, attr in mesh.vertices(True):
    attr['x'] = xyz[key][0]
    attr['y'] = xyz[key][1]
    attr['z'] = xyz[key][2]

artist.mesh = mesh
artist.draw_mesh()
FILE_O = os.path.join(HERE, 'data', 'form_blocks.json')

idos = Mesh.from_json(FILE_I1)
edos = Mesh.from_json(FILE_I2)

blocks = []

for face in idos.faces():
    bottom = idos.face_coordinates(face)
    top = edos.face_coordinates(face)

    f = len(bottom)

    faces = [list(range(f)), list(range(f + f - 1, f - 1, -1))]

    for i in range(f - 1):
        faces.append([i, i + f, i + f + 1, i + 1])
    faces.append([f - 1, f + f - 1, f, 0])

    block = Mesh.from_vertices_and_faces(bottom + top, faces)
    blocks.append(block)

compas.json_dump(blocks, FILE_O)

artist = MeshArtist(None, layer="RV2::Blocks")
artist.clear_layer()

for block in blocks:
    artist.mesh = block
    artist.draw_faces(color=(0, 255, 255), join_faces=True)
Ejemplo n.º 6
0
mesh = Mesh.from_json(FILE_I)

idos = mesh.copy()
edos = mesh.copy()

for vertex in mesh.vertices():
    point = mesh.vertex_coordinates(vertex)
    normal = mesh.vertex_normal(vertex)
    thickness = 0.10
    idos.vertex_attributes(
        vertex, 'xyz',
        add_vectors(point, scale_vector(normal, +0.5 * thickness)))
    edos.vertex_attributes(
        vertex, 'xyz',
        add_vectors(point, scale_vector(normal, -0.5 * thickness)))

idos.to_json(FILE_O1)
edos.to_json(FILE_O2)

artist = MeshArtist(None)

artist.mesh = idos
artist.layer = "RV2::Idos"
artist.clear_layer()
artist.draw_faces(color=(255, 0, 0))

artist.mesh = edos
artist.layer = "RV2::Edos"
artist.clear_layer()
artist.draw_faces(color=(0, 0, 255))