openrr / urdf-viz

visualize URDF/XACRO file, URDF Viewer works on Windows/MacOS/Linux
Apache License 2.0
427 stars 55 forks source link

Allow switching mesh parser when compiled with assimp feature enabled #218

Closed taiki-e closed 1 year ago

taiki-e commented 1 year ago

Currently, when assimp feature is enabled, urdf-viz prefers to use assimp for mesh parsing.

https://github.com/openrr/urdf-viz/blob/99d3c636b74b11f65fd293202ffe1abeefd4d7a2/src/mesh.rs#L103-L106

However, there are cases where bugs in assimp or assimp-sys do not work well, so it would be nice to add a CLI flag to allow the parser to be switched at startup.

taiki-e commented 1 year ago

By the way, here is an example of mesh that doesn't work with assimp-sys. (It would be great if we could eventually fix that too, but that is outside the scope of this issue.)

git clone https://github.com/ToyotaResearchInstitute/hsr_description
git clone https://github.com/ToyotaResearchInstitute/hsr_meshes
urdf-viz hsr_description/robots/hsrb4s.obj.urdf --package-path hsr_meshes=hsr_meshes
thread 'main' panicked at /Users/taiki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/assimp-sys-0.3.1/src/types/string.rs:26:34:
range end index 8746397738037411848 out of range for slice of length 1024
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e7c502d9309ae6bc6a9750514ba7fe397844e84c/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/e7c502d9309ae6bc6a9750514ba7fe397844e84c/library/core/src/panicking.rs:72:14
   2: core::slice::index::slice_end_index_len_fail_rt
             at /rustc/e7c502d9309ae6bc6a9750514ba7fe397844e84c/library/core/src/slice/index.rs:76:5
   3: core::slice::index::slice_end_index_len_fail
             at /rustc/e7c502d9309ae6bc6a9750514ba7fe397844e84c/library/core/src/slice/index.rs:68:9
   4: <assimp_sys::types::string::AiString as core::convert::AsRef<str>>::as_ref
   5: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
   6: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
   7: urdf_viz::assimp_utils::convert_assimp_scene_to_kiss3d_mesh
   8: urdf_viz::mesh::load_mesh_assimp
   9: urdf_viz::mesh::load_mesh
  10: urdf_viz::urdf::add_geometry
  11: urdf_viz::viewer::Viewer::add_robot_with_base_dir_and_collision_flag
  12: urdf_viz::app::UrdfViewerApp::new
  13: tokio::runtime::park::CachedParkThread::block_on
  14: tokio::runtime::context::runtime::enter_runtime
  15: tokio::runtime::runtime::Runtime::block_on
  16: urdf_viz::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.