Triangulate + Remesh

The examples shown in this section were created using RV2 v1.0.0. They will be updated soon, and be compatible with the latest release of RV2.

Triangulate

To triangulate the Form Diagram mesh we can simply convert all quads to triangles. Note that the quality of the resulting mesh is not considered in this step. This is okay because we will still improve mesh quality through remeshing.

from compas_rv2.datastructures import FormDiagram
from compas_rhino.artists import MeshArtist

FILE_I = 'form.json'
FILE_O = 'form_trimesh.json'

form = FormDiagram.from_json(FILE_I)

form.quads_to_triangles()

form.to_json(FILE_O)

artist = MeshArtist(form, layer="RV2::TriMesh")
artist.clear_layer()
artist.draw_faces(join_faces=True)

Remesh

For the remeshing we will use compas_cgal. The underlying remeshing function in CGAL is documented here.

We will remesh in VS Code using the COMPAS viewer for visualisation, and again export the result to JSON to continue working with the remeshed triangulation in Rhino. The result is available for download at the bottom of this page.

Note that you could also do this directly from Rhino using the RPC cloud. However, the current procedure illustrates an alternative workflow using CPython directly in an editor outside of Rhino.

import os
from compas.datastructures import Mesh
from compas_cgal.meshing import remesh
from compas_viewers.objectviewer import ObjectViewer

HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'form_trimesh.json')
FILE_O = os.path.join(HERE, '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 = remesh(mesh.to_vertices_and_faces(), 0.75 * length)
mesh = Mesh.from_vertices_and_faces(V, F)

mesh.to_json(FILE_O)

viewer = ObjectViewer()
viewer.add(mesh, settings={'color': '#cccccc'})
viewer.update()
viewer.show()

Last updated