|
| 1 | +# Converting between SDF and USD |
| 2 | + |
| 3 | +This example shows how a world in a SDF file can be converted to [USD](https://graphics.pixar.com/usd/release/index.html). |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +You will need all of the dependencies for sdformat, along with the following additional dependencies: |
| 8 | +* USD: [installation instructions](https://github.com/PixarAnimationStudios/USD/blob/release/README.md#getting-and-building-the-code) |
| 9 | +* [ignition-common4](https://github.com/ignitionrobotics/ign-common) |
| 10 | +* [ignition-utils1 (including the CLI component)](https://github.com/ignitionrobotics/ign-utils) |
| 11 | + |
| 12 | +## Setup |
| 13 | + |
| 14 | +Build sdformat. The steps below follow a traditional cmake build, but sdformat |
| 15 | +can also be built with [colcon](https://colcon.readthedocs.io/en/released/index.html): |
| 16 | +```bash |
| 17 | +git clone https://github.com/ignitionrobotics/sdformat.git |
| 18 | +cd sdformat |
| 19 | +mkdir build |
| 20 | +cd build |
| 21 | +cmake .. |
| 22 | +make |
| 23 | +``` |
| 24 | + |
| 25 | +You should now have an executable named `sdf2usd` in the `sdformat/build/bin` directory. |
| 26 | +This executable can be used to convert a SDF world file to a USD file. |
| 27 | +To see how the executable works, run the following command from the `sdformat/build/bin` directory: |
| 28 | +```bash |
| 29 | +./sdf2usd -h |
| 30 | +``` |
| 31 | + |
| 32 | +To convert [shapes_world.sdf](https://github.com/ignitionrobotics/sdformat/blob/sdf12/test/sdf/shapes_world.sdf) to its USD representation as a file called `shapes.usd`, run the following commands: |
| 33 | + |
| 34 | +```bash |
| 35 | +wget https://raw.githubusercontent.com/ignitionrobotics/sdformat/sdf12/test/sdf/shapes_world.sdf |
| 36 | +./sdf2usd shapes_world.sdf shapes.usd |
| 37 | +``` |
| 38 | + |
| 39 | +You can now view the contents of the generated USD file with `usdcat` (this should have been installed when setting up the USD dependency): |
| 40 | +```bash |
| 41 | +usdcat shapes.usd |
| 42 | +``` |
| 43 | + |
| 44 | +To see the visual representation of the USD world, run `usdview` (this should have also been installed when setting up the USD dependency): |
| 45 | +```bash |
| 46 | +usdview shapes.usd |
| 47 | +``` |
| 48 | + |
| 49 | +### Note about building with colcon |
| 50 | +You may need to add the USD library path to your `LD_LIBRARY_PATH` environment variable after sourcing the colcon workspace. |
| 51 | +If the USD library path is not a part of `LD_LIBRARY_PATH`, you will probably see the following error when running the `sdf2usd` executable: |
| 52 | +```bash |
| 53 | +sdf2usd: error while loading shared libraries: libusd_usd.so: cannot open shared object file: No such file or directory |
| 54 | +``` |
| 55 | +The typical USD library path is `<usd_installation_path>/lib`. |
| 56 | +So, if you installed USD at `/usr/local/USD`, the following command on Linux properly updates the `LD_LIBRARY_PATH` environment variable: |
| 57 | +```bash |
| 58 | +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/USD/lib |
| 59 | +``` |
| 60 | +
|
| 61 | +Another thing to note if building with colcon is that after sourcing the workspace with sdformat, |
| 62 | +the `sdf2usd` executable can be run without having to go to the `sdformat/build/bin` directory. |
| 63 | +So, instead of going to that directory and running `./sdf2usd ...`, you should be able to run `sdf2usd ...` from anywhere. |
0 commit comments