Mesh Operations Tutorial¶
This tutorial covers common mesh operations in detail.
Loading Meshes¶
PyGEL3D supports several mesh formats:
import pygel3d.hmesh as hmesh
# Auto-detect format
m = hmesh.load("model.obj")
# Specific format loaders
m = hmesh.obj_load("model.obj")
m = hmesh.off_load("model.off")
m = hmesh.ply_load("model.ply")
m = hmesh.x3d_load("model.x3d")
Mesh Traversal¶
Iterating Over Elements¶
# Iterate over vertices
for v in m.vertices():
pos = m.positions()[3*v:3*v+3]
print(f"Vertex {v}: {pos}")
# Iterate over faces
for f in m.faces():
print(f"Face {f}")
# Iterate over halfedges
for h in m.halfedges():
print(f"Halfedge {h}")
Circulating Around Elements¶
# Circulate around a vertex
vertex_id = 0
neighbors = m.circulate_vertex(vertex_id, mode='v')
print(f"Neighbor vertices: {neighbors}")
# Circulate around a face
face_id = 0
vertices = m.circulate_face(face_id, mode='v')
print(f"Face vertices: {vertices}")
Mesh Repair¶
Stitching Coincident Vertices¶
# Merge vertices that are very close
threshold = 1e-6
num_merged = hmesh.stitch_mesh(m, threshold)
print(f"Merged {num_merged} vertex pairs")
Closing Holes¶
Removing Degenerate Features¶
# Remove caps (nearly flat triangles at edges)
hmesh.remove_caps(m, threshold=0.1)
# Remove needles (very thin triangles)
hmesh.remove_needles(m, threshold=0.1, averagePositions=True)
Mesh Smoothing¶
Catmull-Clark Smoothing¶
Laplacian Smoothing¶
Taubin Smoothing¶
Mesh Subdivision¶
Catmull-Clark¶
Loop Subdivision¶
Mesh Simplification¶
# Simplify to 50% of faces
hmesh.quadric_simplify(
m,
keep_fraction=0.5,
singular_thresh=1e-10,
error_thresh=1e10
)
Mesh Optimization¶
Edge Flipping¶
# Optimize valency (tries to make vertices degree 6)
hmesh.optimize_valency(m, anneal=True)
# Maximize minimum angle
hmesh.maximize_min_angle(m, thresh=0.1, anneal=True)
# Minimize curvature
hmesh.minimize_curvature(m, anneal=True)
See the API Reference for complete function documentation.