Open tencerva opened 1 year ago
This might be fixed by updating shapely to their newer 2.0 withpip install --upgrade shapely
? It looks like the multipolygon check might only work on newer copies of shapely:
# if it returned a multipolygon extend into a flat list
if hasattr(repaired, 'geoms'):
polygons.extend(repaired.geoms)
else:
polygons.append(repaired)
Thanks Mike,
Pip reported "shapely" already at version 2.0.1 in response to --upgrade command. Reran my code this morning with same error resulting.
Gotcha, can you share the code snippet and a model to reproduce? I wasn't able to hit this case on toy data (I tried a bunch of boxes and trimesh.creation.random_soup
).
Mike, Was traveling yesterday and unable to respond. I am checking on supplying the model.
Interestingly, I ran the code on another computer this morning, inadvertantly with "shapely" version 1.8.5, using the following code line:
print(trimesh.path.polygons.projected(clean_mesh, normal=[1, 0, 0], origin=[50, 0, 0]).area)
In this case a reasonable numerical result was generated (no fatal error), but with the following warning message
/home/michael/.local/lib/python3.10/site-packages/trimesh/path/polygons.py:137: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead. polygons.append(repair_invalid(Polygon(vertices[dfs])))
Thanks for the file looks like a good test case! I was playing with it and it seems like the current trimesh algorithm (backface cull into patches, union as 2D polygons) doesn't do a very good job on this curved input from a lot of angles haha. For me trimesh's worst results were when it got hung up on small almost-perpendicular-but-not-quite patches of faces. It did pretty decently on some of the more-perpendicular views.
I'm not sure what the right way to handle these are, I'll keep playing with it. Ideas and PR's welcome!
Getting the following error with trimesh.path.polygons.projected function used as outlined in issue #898...
Traceback (most recent call last): File "/home/michael/Desktop/meshman09.py", line 45, in
print(trimesh.path.polygons.projected(clean_mesh, normal=[1, 0, 0]).area)
File "/home/michael/.local/lib/python3.10/site-packages/trimesh/path/polygons.py", line 792, in projected
polygons.extend(edges_to_polygons(
File "/home/michael/.local/lib/python3.10/site-packages/trimesh/path/polygons.py", line 153, in edges_to_polygons
holes = [polygons[i].exterior.coords for i in interior]
File "/home/michael/.local/lib/python3.10/site-packages/trimesh/path/polygons.py", line 153, in
holes = [polygons[i].exterior.coords for i in interior]
AttributeError: 'MultiPolygon' object has no attribute 'exterior'
I am trying to get the projected area of a mesh onto a plane where some parts of the mesh overlap or shield other parts, similarly for aerodynamic purposes. Input mesh passes "is_volume" test with no duplicate faces or unreferenced vertices.
Trimesh 3.15.4
Thanks, Mike