nimblephysics icon indicating copy to clipboard operation
nimblephysics copied to clipboard

Loading Rajagopal model fails

Open Okaerikoto opened this issue 2 years ago • 7 comments

Environment

  • Ubuntu 18.04
  • python 3.8
  • Installed with pip install nimblephysics

Current Behavior

In the .Rajagopal example, the skeleton model loading fails with the following errors (for each skeleton part):

Warning [MeshShape.cpp:491] [MeshShape::loadMesh] Failed loading mesh 'file:///home/mkeller2/.pyenv/versions/impproj_env/lib/python3.8/site-packages/nimblephysics/models/rajagopal_data/Geometry/metacarpal5_lvs.vtp.ply' with ASSIMP error 'Unable to open file "file:///home/mkeller2/.pyenv/versions/impproj_env/lib/python3.8/site-packages/nimblephysics/models/rajagopal_data/Geometry/metacarpal5_lvs.vtp.ply".'. Warning [LocalResource.cpp:48] [LocalResource::constructor] Failed opening file '/home/mkeller2/.pyenv/versions/impproj_env/lib/python3.8/site-packages/nimblephysics/models/rajagopal_data/Geometry/little_proximal_lvs.vtp.ply' for reading: No such file or directory Warning [CompositeResourceRetriever.cpp:96] [CompositeResourceRetriever::retrieve] All ResourceRetrievers registered for this schema failed to retrieve the URI 'file:///home/mkeller2/.pyenv/versions/impproj_env/lib/python3.8/site-packages/nimblephysics/models/rajagopal_data/Geometry/little_proximal_lvs.vtp.ply' (tried 1).

The model .osim file do list the proper .vtp paths, and those files exist, but somehow the loader tries to load the files with the extension '.ply' .

Code to Reproduce

import nimblephysics as nimble skel: nimble.biomechanics.OpenSimFile = nimble.models.RajagopalHumanBodyModel()

Okaerikoto avatar Dec 17 '21 17:12 Okaerikoto

Oh yeah, this is an unfortunate wart in the current implementation.

Here's the issue: Nimble uses ASSIMP to load meshes, but ASSIMP doesn't support loading .vtp files currently. Fixing this is a bit obnoxious, since ASSIMP objects are passed around all over the place as the in-memory mesh object format, so adding another mesh loading library means writing a converted to ASSIMP format in-memory, or refactoring a bunch of code to use some other in-memory mesh format.

So, as a hack, when we see a .vtp file, we attempt to load a converted .ply file instead. If you look in the source at python/nimblephysics/models/rajagopal_data/Geometry/* I've got a bunch of pre-converted files that have the extension *.vtp.ply. Those should be bundled with the built pip install wheels wherever your wheel is installed, so if they're not being bundled then that's a bug I need to investigate.

I'd also welcome a PR that lets us load .vtp files. We may actually want to refactor the internal mesh data structure to be something other than ASSIMP data, since there have now been a few features where that's the blocking design-flaw preventing an easy fix.

keenon avatar Dec 17 '21 17:12 keenon

Then the problem is that I don't have the *.vtp.ply files. For me, pip install nimblephysics generated the following folder: my_virtual_env/lib/python3.8/site-packages/nimblephysics/models Containing only:

  • __init__.py
  • rajagopal.py

Since the folder rajagopal_data was missing, I created it and downloaded the model from opensim website, which contains only the *.vtp files. That's why I miss the *.vtp.ply files.

Any idea why the folder rajagopal_data is missing for me ?

Okaerikoto avatar Dec 20 '21 10:12 Okaerikoto

I've had challenges with packaging the rajagopal_data folder into the PyPI package in the past. Here's the models folder you want to download into your my_virtual_env/lib/python3.8/site-packages/nimblephysics/models: https://github.com/nimblephysics/nimblephysics/tree/master/python/nimblephysics/models

I'll try to go fix the packaging of the models into the Python wheel in the next few days.

keenon avatar Dec 20 '21 18:12 keenon

Thanks for the help, I did that and I can load the model now.

Okaerikoto avatar Jan 02 '22 12:01 Okaerikoto

@keenon are there any instructions for generating ply files if using a different set of vtp files? p.s. very nice work here!

peabody124 avatar Oct 09 '22 13:10 peabody124

I wrote a script to do that : vtp_to_ply.py

The command is python vtp_to_ply.py path/to/Geometry/ This lists all the .vtp and .obj contained in the Geometry folder and creates a folder path/to/Geometry_ply/ containing the .ply version of those files such that it can be loaded by nimble.

Note that you will have to rename Geometry_ply to Geometry for nimble to see it.

MarilynKeller avatar Oct 10 '22 17:10 MarilynKeller

Thanks @MarilynKeller !

peabody124 avatar Oct 14 '22 13:10 peabody124