I have a mesh and want to convert it into a polygon. I did some google search and found most answer on converting polygon to mesh. I want to do the opposite.Is there any library or any idea on how to achieve it
Asked
Active
Viewed 277 times
1 Answers
1
Well you can use the Python FME library to take input as a mesh object and return a polygon
import fmeobjects
class MeshToPolygons(object):
def input(self, feature):
mesh = feature.getGeometry()
if isinstance(mesh, fmeobjects.FMEMesh):
vertices = mesh.getVertices()
for part in mesh:
indices = part.getVertexIndices()
if indices:
boundary = fmeobjects.FMELine([vertices[i] for i in indices])
feature.setGeometry(fmeobjects.FMEPolygon(boundary))
self.pyoutput(feature)
If the above doesn't help, you can also check out the python TriMesh library. You could load the object as mesh using
trimesh.load(file_obj, file_type=None, resolver=None, force=None, **kwargs)
Return type: Trimesh, Path2D, Path3D, Scene
Returns: geometry – Loaded geometry as trimesh classes
Now convert the mesh object into a sequence of connected points. After that you can use
trimesh.path.polygons.paths_to_polygons(paths, scale=None)
Return type: (p,) list
Returns: polys – Filled with Polygon or None
Hope it helps

Musabbir Arrafi
- 744
- 4
- 18
-
It gives me an error "object of type 'Trimesh' has no len()". file_obj = "M:\\copy_of_knot.ply" – Purple_Ad Dec 20 '22 at 10:44