Reputation: 21
I'm trying to calculate the volume of the intersection of two convex meshes using Trimesh. Using the trimesh.Trimesh.intersection() method, even basic, clearly overlapping shapes are returning with an empty intersection.
As a simple example, I tried calculating the intersection of two boxes offset from one another.
# Create offset transformation matrix
T = np.eye(4)
T[:3, 3] = np.array([0.5, 0.5, 0.5])
# Form basic box meshes
mesh1 = trimesh.creation.box(extents=[1.0, 1.0, 1.0])
mesh2 = trimesh.creation.box(extents=[1.0, 1.0, 1.0], transform=T)
# Calculate intersection
test_intersection = mesh1.intersection(mesh2)
print(test_intersection)
print(test_intersection.volume)
# Visualize
scene = trimesh.Scene([mesh1, mesh2])
scene.show()
The resulting outputs indicate an empty intersection between the two shapes:
<trimesh.Trimesh(vertices.shape=(0, 3), faces.shape=(0, 3))>
0.0
Yet visualizing the boxes, they are clearly overlapping:
Why is the mesh intersection empty? Am I misunderstanding the use of the .intersection() method?
(I'm using python 3.12.7, trimesh 4.5.2 installed from pip)
Upvotes: 1
Views: 258
Reputation: 21
I solved my issue by installing the additional dependency
pip install manifold3d
Which I tried after looking through the source code for the trimesh.Trimesh.intersection method and seeing the following docstring:
Parameters
------------
other : trimesh.Trimesh, or list of trimesh.Trimesh objects
Meshes to calculate intersections with
engine
Which backend to use, the default
recommendation is: `pip install manifold3d`.
Without this dependency, calling the intersection method on a trimesh object returns an empty mesh rather than indicating the missing engine / dependency
Upvotes: 1