matplotlib shows only partial mesh from stl file

814 Views Asked by At

So I have this cute little model of a jeep stored in my stl file:

enter image description here

To display its 3D mesh in my jupyter notebook, I used the following code segment:

from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot

tgtMesh = mesh.Mesh.from_file(r'./miljeep.stl')

figure = pyplot.figure()
axes = mplot3d.Axes3D(figure)
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(tgtMesh.vectors))
scale = tgtMesh.points.flatten(-1)
axes.auto_scale_xyz(scale,scale,scale)
pyplot.show()

Unfortunately, what appeared was this:

enter image description here

By doing a simple print, I see that only a vector array of (376, 3, 3) was stored in the mesh while by right, it should be (53184, 3, 3) when displayed fully using a software online.

So this seems to be an issue with either matplotlib or, more likely, numpy-stl? Any idea, anyone?

1

There are 1 best solutions below

0
On BEST ANSWER

After an unproductive weekend, it turns out that the problem is with the stl file.

It is not corrupted per se, but because it had earlier been converted from a solid model to a surface model using another application, the generated stl file was somehow not formatted properly for numpy-stl to parse fully.

The solution then was simply to use another application to open the stl file (e.g. MeshLab), and then export it once again as an stl file. It was properly displayed afterwards, hooray!