- Notifications
You must be signed in to change notification settings - Fork0
micycle1/PMesh
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
PMesh is a Java library that provides a robust half-edge data structure for representing and manipulating mesh-like PShape objects in Processing.
The core idea behind PMesh is toseparate the topology (how vertices, edges, and faces are connected) from thegeometry (the actual coordinates of the vertices). This separation of concerns allows you to perform operations like smoothing, subdivision, or deformation without worrying about accidentally altering the mesh's connectivity. For example, when smoothing a mesh, you can move vertices based on their connected neighbors, knowing that the underlying structure of the mesh remains intact.
In PMesh, the topology is represented using ahalf-edge data structure, where each edge is split into two directed half-edges. These half-edges form counter-clockwise cycles (via their.next
pointers) thatimplicitly define the faces of the mesh. This means that faces are emergent from the connectivity of the half-edges, rather than being explicitly stored.
By keeping topology and geometry distinct, PMesh ensures that changes to vertex positions don't disrupt the mesh's structure, making it a powerful tool for mesh processing tasks.
- Half-Edge Data Structure: Efficiently represents the topology of a mesh using half-edges, which are useful for navigating and manipulating mesh connectivity.
- Topological Operations: 🚧Supports operations like vertex and edge deletion, face traversal, and boundary detection🚧.
- Smoothing Algorithms: Includes an abstract base class (
MeshSmoother
) for implementing various mesh smoothing algorithms. - Graph Representation: Converts the mesh into an undirected graph (weighted or unweighted) for further analysis or processing.
To create aPMesh
from aPShape
, you can use the following code:
PMesh mesh = new PMesh(meshShape);
You can access the vertices, edges, and faces of the mesh using the provided getter methods:
List<HEVertex>vertices =mesh.getVertices();// HEVertices have an underlying `position` variable.List<HalfEdge>edges =mesh.getEdges();List<HEFace>faces =mesh.getFaces();
To smooth the mesh use one of the built-in smoothers, or implement a customMeshSmoother
and apply it to the mesh.
// UsageMeshSmoothersmoother =newSimultaneousLaplacianSmoother(mesh);smoother.smooth(10,true);// Smooth for 10 iterations, preserving the boundary
You can convert thePMesh
back to aPShape
for rendering:
PShapesmoothedShape =mesh.toPShape();shape(smoothedShape);
This method extracts the updated vertex positions from the PMesh and reconstructs the mesh as a PShape, also preserving the existing topology.
The mesh can also be represented as ajGraphT graph for further analysis:
Graph<HEVertex,HalfEdge>graph =mesh.toUnweightedGraph();// Or, for a weighted graph:Graph<HEVertex,HalfEdge>weightedGraph =mesh.toWeightedGraph(he ->he.length());// with a user-supplied edge weight function
About
Half-edge representation for mesh-like Processing PShapes