navis-org/skeletor

Loading a custom mesh and skeletonizing it?

eyildiz-ugoe opened this issue · 2 comments

The example given in the docs is based on a randomly created mesh which is not helpful for someone who wants to test the skeletonization on his own mesh(es). I think it's good to include an example where a mesh is loaded and skeletonized as this is more of a more generic usage.

To this end, could an example be there to load a mesh so that it could be skeletonized? Because if I use open3d, and load the mesh, it would not get skeletonized. It complains about a package called trimesh.

mesh = make_trimesh(mesh, validate=False)
File "../python3.9/site-packages/skeletor/utilities.py", line 59, in make_trimesh
    raise TypeError('Unable to construct a trimesh.Trimesh from object of '
TypeError: Unable to construct a trimesh.Trimesh from object of type "<class 'open3d.cuda.pybind.geometry.TriangleMesh'>"

Apparently, a package called trimesh is being used and that contradicts with open3d meshes. Long story short: How could we even test this on our own mesh?

Fortune favours the bold - or those that bother reading the docstrings. For example:

>>> import skeletor as sk
>>> help(sk.pre.fix_mesh)
[...]
Parameters
----------
mesh :                  mesh-like object
                        Mesh to fix. Must have `.vertices` and `.faces`
                        properties.
[...]

So in your case, the problem is that open3d meshes have no .faces but instead use .triangles.

The easy work-around is to either convert your mesh to a trimesh mesh before passing it to a skeleton function or use trimesh from the start to load your mesh from disk.

>>> import trimesh as tm
>>> mesh = tm.Trimesh(vertices,  # (N, 3) array of vertices
...                   faces)  # (M, 3) array of vertex indices
>>> mesh2 = tm.load_mesh('filepath/to/some_mesh.obj')

The main point of the packaged mesh (which is not "random") is to have something that's reproducible and that people can run right away. It also avoids people using their own, potentially corrupt meshes and then claiming skeletor isn't working.

Hope this helps.

Fortune favours the bold - or those that bother reading the docstrings.

And those who write down things as they are, rather than going for a description that's misleading. Skeletor does not work on any mesh, rather a specifically loaded mesh.

Nevertheless, with your latest commit, this is now clear.

Happy to have contributed to your repository's README, you're welcome.