- 
                Notifications
    
You must be signed in to change notification settings  - Fork 113
 
Description
in compas the parsing of meshes is performed in compas python code, rather than via a dependency.
trimesh would be a solid contender since its easy to install and yields numpy arrays.
loading meshes could be about twice as fast (frankly, I expected an even greater contrast), but 2x is not to be sneezed at.
there are 2 possible routes:
- make 
trimesha hard dependency - make 
trimesha soft dependency - factor out the existing mesh loading implementation and replace by 
trimeshcalls 
I strongly suggest making trimesh a hard dependency (updating requirements.txt) since once a dependency it is complimentary to compas.datastructures.Mesh. The soft route is using trimesh when found (as an alternative code path)
when going for the hard dependency I suggest refactoring mercilessly and factoring out the older implementations.
from line_profiler import profile
def test_mesh_read_performance_old():
    @profile
    def test_import():
        for i in range(10):
            msh: Mesh = Mesh.from_ply(compas.get_bunny())
            print(f"faces parsed {len(msh.facedata)}")
            del msh
    test_import()
def test_mesh_read_performance_trimesh():
    import trimesh
    @profile
    def test_import():
        for i in range(10):
            msh = trimesh.load(compas.get_bunny())
            print(f"faces parsed {len(msh.faces)}")
            del msh
    test_import()
def test_mesh_read_performance_meshio():
    import meshio
    @profile
    def test_import():
        for i in range(10):
            msh = meshio.read(compas.get_bunny())
            print(f"faces parsed {msh.cells_dict['triangle'].shape[0]}")
            del msh
    test_import()
test_robot_library.py::test_mesh_read_performance_old
============================== 1 passed in 4.17s ===============================
PASSED             [100%]faces parsed 69451
faces parsed 69451
faces parsed 69451
test_robot_library.py::test_mesh_read_performance_trimesh
============================== 1 passed in 2.23s ===============================
PASSED             [100%]faces parsed 69451
faces parsed 69451
faces parsed 69451
test_robot_library.py::test_mesh_read_performance_meshio
============================== 1 passed in 2.37s ===============================
PASSED          [100%]faces parsed 69451
faces parsed 69451
faces parsed 69451