B3. Mesh dual
tessellation method: create a triangular mesh and its dual graph
objectives
We will create a tesselation pattern by applying a concept from graph theory know as Duality. more information here: https://mathworld.wolfram.com/DualGraph.html
Procedure
a1. load RV2 session file
For the purpose of this exercise, we will use the FormDiagram of the Armadillo vault
HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'data', 'armadillo_vertical_new_anchors.rv2')
FILE_O = os.path.join(HERE, 'data', 'form.json')
session = compas.json_load(FILE_I)
form = Mesh.from_data(session['data']['form'])
form.to_json(FILE_O)
#================================================
#Visualize
#================================================
artist = MeshArtist(form, layer="CSD2::DISCRETIZATION::form")
artist.clear_layer()
artist.draw_faces(join_faces=False,faces=list(form.faces_where({'_is_loaded': True})))
artist.draw_edges(edges=list(form.edges_where({'_is_edge': True})))
a2. refine mesh
guids = compas_rhino.select_meshes()
meshes = []
for guid in guids:
mesh = RhinoMesh.from_guid(guid).to_compas()
meshes.append(mesh)
mesh_fix = meshes_join_and_weld(meshes)
mesh.unify_cycles()
mesh_fix.to_json(FILE_O)
a2. triangulate the quad mesh
# ==============================================================================
#Imports
# ==============================================================================
import os
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist
import compas_rhino
from compas_rhino.geometry import RhinoMesh
# ==============================================================================
#Load data
# ==============================================================================
HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'data', 'form.json')
FILE_O = os.path.join(HERE, 'data', 'form_trimesh.json')
form = Mesh.from_json(FILE_I)
form.quads_to_triangles()
form.to_json(FILE_O)
#================================================
#Visualize
#================================================
artist = MeshArtist(form, layer="CSD2::DISCRETIZATION::triangulate")
artist.clear_layer()
artist.draw_faces(join_faces=True)
artist.draw_edges()
a4. option_I remesh with proxy
# ==============================================================================
#Imports
# ==============================================================================
import os
from compas.datastructures import Mesh
from compas.rpc import Proxy
from compas.geometry import trimesh_remesh
from compas_rhino.artists import MeshArtist
# ==============================================================================
#Load data
# ==============================================================================
cgal = Proxy('compas_cgal.meshing')
HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'data', 'form_trimesh.json')
FILE_O = os.path.join(HERE, 'data', 'form_remeshed.json')
mesh = Mesh.from_json(FILE_I)
lengths = [mesh.edge_length(*edge) for edge in mesh.edges()]
length = sum(lengths) / mesh.number_of_edges()
V, F = cgal.remesh(mesh.to_vertices_and_faces(),length)
mesh = Mesh.from_vertices_and_faces(V, F)
# ==============================================================================
#Output
# ==============================================================================
mesh.to_json(FILE_O)
#================================================
#Visualize
#================================================
artist = MeshArtist(mesh, layer="CSD2::DISCRETIZATION::remesh")
artist.clear_layer()
artist.draw_faces(join_faces=True)
artist.draw_edges()
a4. option_II step 1 remesh with VScode
mesh = Mesh.from_json(FILE_I)
lengths = [mesh.edge_length(*edge) for edge in mesh.edges()]
length = sum(lengths) / mesh.number_of_edges()
V, F = remesh(mesh.to_vertices_and_faces(), 0.75 * length)
mesh = Mesh.from_vertices_and_faces(V, F)
a4. option_II step 2 remesh with VScode
FILE_I = os.path.join(HERE, 'data', 'form_remeshed.json')
mesh = Mesh.from_json(FILE_I)
a5. dual
mesh = Mesh.from_json(FILE_I)
dual = mesh.dual()
dual.flip_cycles()
dual.to_json(FILE_O, pretty =True)
Last updated