When a URDF file uses the package:// prefix for mesh paths (common in ROS), you must configure the packages option in URDFLoader so the loader knows where to find those files.
Configuration Methods
1. Using a String (Single Package)
If all your packages reside in one directory, provide that directory as a string. The loader will assume the package name is a subdirectory of this path.
const loader = new URDFLoader();
loader.packages = '/path/to/ros_workspace/src';
2. Using an Object (Multiple Packages)
Map specific ROS package names to their absolute filesystem paths.
const loader = new URDFLoader();
loader.packages = {
'my_robot_description': '/path/to/robot_pkg',
'sensor_msgs': '/path/to/sensor_pkg'
};
3. Using a Function (Dynamic Resolver)
Provide a callback that takes a package name and returns the resolved path.
const loader = new URDFLoader();
loader.packages = (pkgName) => {
return `/custom/path/${pkgName}`;
};