# trimesh.remesh

## remesh.py

Deal with re- triangulation of existing meshes.

trimesh.remesh.subdivide(vertices, faces, face_index=None, vertex_attributes=None, return_index=False)

Subdivide a mesh into smaller triangles.

Note that if face_index is passed, only those faces will be subdivided and their neighbors won’t be modified making the mesh no longer “watertight.”

Parameters
• vertices ((n, 3) float) – Vertices in space

• faces ((m, 3) int) – Indexes of vertices which make up triangular faces

• face_index (faces to subdivide.) – if None: all faces of mesh will be subdivided if (n,) int array of indices: only specified faces

• vertex_attributes (dict) – Contains (n, d) attribute data

• return_index (bool) – If True, return index of original face for new faces

Returns

• new_vertices ((q, 3) float) – Vertices in space

• new_faces ((p, 3) int) – Remeshed faces

• index_dict (dict) – Only returned if return_index, {index of original face : index of new faces}.

trimesh.remesh.subdivide_loop(vertices, faces, iterations=None)

Subdivide a mesh by dividing each triangle into four triangles and approximating their smoothed surface (loop subdivision). This function is an array-based implementation of loop subdivision, which avoids slow for loop and enables faster calculation.

Overall process: 1. Calculate odd vertices.

Assign a new odd vertex on each edge and calculate the value for the boundary case and the interior case. The value is calculated as follows.

v2

/ f0 0

v0–e–v1 /
f1 / v0–e–v1

v3

• interior case : 3:1 ratio of mean(v0,v1) and mean(v2,v3)

• boundary case : mean(v0,v1)

1. Calculate even vertices.

The new even vertices are calculated with the existing vertices and their adjacent vertices.

1—2

/ / 0—1

0—v—3 / /
// b0—v—b1

k…4

• interior case : (1-kB):B ratio of v and k adjacencies

• boundary case : 3:1 ratio of v and mean(b0,b1)

1. Compose new faces with new vertices.

Parameters
• vertices ((n, 3) float) – Vertices in space

• faces ((m, 3) int) – Indices of vertices which make up triangles

Returns

• vertices ((j, 3) float) – Vertices in space

• faces ((q, 3) int) – Indices of vertices

• iterations (int) – Number of iterations to run subdivision

trimesh.remesh.subdivide_to_size(vertices, faces, max_edge, max_iter=10, return_index=False)

Subdivide a mesh until every edge is shorter than a specified length.

Will return a triangle soup, not a nicely structured mesh.

Parameters
• vertices ((n, 3) float) – Vertices in space

• faces ((m, 3) int) – Indices of vertices which make up triangles

• max_edge (float) – Maximum length of any edge in the result

• max_iter (int) – The maximum number of times to run subdivision

• return_index (bool) – If True, return index of original face for new faces

Returns

• vertices ((j, 3) float) – Vertices in space

• faces ((q, 3) int) – Indices of vertices

• index ((q, 3) int) – Only returned if return_index, index of original face for each new face.