-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make SDF to USD a separate component of sdformat #817
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
5e13b49
make SDF to USD a separate component of sdformat
adlarkin fa4568b
Added ignition-common4 as a dependency
ahcorde 18f3ac1
create world prim and add physics information
adlarkin 3bbd6ea
add unit test for world conversion
adlarkin 16e0789
Added ci to compile with USD
ahcorde ae3ee43
Added feedback
ahcorde 36d42fc
improved doc
ahcorde 4545723
update CMake code
adlarkin 91629c0
included namespaces
ahcorde 6347953
Added basic test to sdf2usd cmd
ahcorde bb6ee5a
changes in sdf2usd
ahcorde d1d7af6
Fixed usd tutorial
ahcorde bab9e37
Removed unneeded CMakeLists.txt
ahcorde cbdfa49
Moved CMakeLists.txt
ahcorde 99fb170
update example docs and other nits before merge
adlarkin 819d5f5
Merge branch 'sdf12' into ahcorde/sdf_to_usd_cmake
adlarkin 92eca63
clean CI
ahcorde 0618353
Fixed CMake warning
ahcorde bcc282b
Fixed cmake
ahcorde 0fd2568
reverted changes in CMakeLists.txt
ahcorde 0195564
Improved test
ahcorde d91557e
fix search path of sdf2usd executable in UNIT_sdf2usd_TEST
adlarkin f3922f0
alphabetize packages.apt
adlarkin 4c454a3
cleanup before_cmake.sh
ahcorde 95c07e9
changed file structure
ahcorde b29b737
Merge branch 'ahcorde/sdf_to_usd_cmake' of https://github.com/ignitio…
ahcorde c4c189f
File structure
ahcorde 0851949
Added TODO
ahcorde 01aeb57
fix include guard
adlarkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/sh -l | ||
|
||
set -x | ||
|
||
BUILD_DIR=`pwd` | ||
|
||
cd /tmp | ||
|
||
# check that we can compile USD from sources (only Focal) | ||
mkdir cmake_test | ||
cd cmake_test | ||
|
||
echo "cmake_minimum_required(VERSION 3.12)" > CMakeLists.txt | ||
|
||
return_code=0 | ||
cmake . || return_code=$(($return_code + $?)) | ||
if [ $return_code -eq 0 ] | ||
then | ||
# compile USD from sources | ||
cd /tmp | ||
mkdir usd_binaries | ||
cd usd_binaries | ||
|
||
apt-get install libboost-all-dev libtbb-dev p7zip-full -y | ||
|
||
wget https://github.com/PixarAnimationStudios/USD/archive/refs/tags/v21.11.zip | ||
unzip v21.11.zip | ||
cd USD-21.11 | ||
mkdir build | ||
cd build | ||
|
||
cmake -DCMAKE_INSTALL_PREFIX="/tmp/USD" -DCMAKE_PREFIX_PATH="/tmp/USD" \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DPXR_PREFER_SAFETY_OVER_SPEED=ON \ | ||
-DPXR_ENABLE_PYTHON_SUPPORT=OFF \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DTBB_USE_DEBUG_BUILD=OFF \ | ||
-DPXR_BUILD_DOCUMENTATION=OFF \ | ||
-DPXR_BUILD_TESTS=OFF \ | ||
-DPXR_BUILD_EXAMPLES=OFF \ | ||
-DPXR_BUILD_TUTORIALS=OFF \ | ||
-DPXR_BUILD_USD_TOOLS=OFF \ | ||
-DPXR_BUILD_IMAGING=OFF \ | ||
-DPXR_BUILD_USD_IMAGING=OFF \ | ||
-DPXR_BUILD_USDVIEW=OFF \ | ||
-DPXR_BUILD_ALEMBIC_PLUGIN=OFF \ | ||
-DPXR_BUILD_DRACO_PLUGIN=OFF \ | ||
-DPXR_ENABLE_MATERIALX_SUPPORT=OFF \ | ||
-DBoost_INCLUDE_DIR=/usr/include \ | ||
-DBoost_NO_BOOST_CMAKE=FALSE \ | ||
.. | ||
|
||
make -j$(nproc) install | ||
fi | ||
|
||
cd $BUILD_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Converting between SDF and USD | ||
|
||
This example shows how a world in a SDF file can be converted to [USD](https://graphics.pixar.com/usd/release/index.html). | ||
|
||
## Requirements | ||
|
||
You will need all of the dependencies for sdformat, along with the following additional dependencies: | ||
* USD: [installation instructions](https://github.com/PixarAnimationStudios/USD/blob/release/README.md#getting-and-building-the-code) | ||
* [ignition-common4](https://github.com/ignitionrobotics/ign-common) | ||
* [ignition-utils1 (including the CLI component)](https://github.com/ignitionrobotics/ign-utils) | ||
|
||
## Setup | ||
|
||
Build sdformat. The steps below follow a traditional cmake build, but sdformat | ||
can also be built with [colcon](https://colcon.readthedocs.io/en/released/index.html): | ||
```bash | ||
git clone https://github.com/ignitionrobotics/sdformat.git | ||
cd sdformat | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
``` | ||
|
||
You should now have an executable named `sdf2usd` in the `sdformat/build/bin` directory. | ||
This executable can be used to convert a SDF world file to a USD file. | ||
To see how the executable works, run the following command from the `sdformat/build/bin` directory: | ||
```bash | ||
./sdf2usd -h | ||
``` | ||
|
||
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: | ||
|
||
```bash | ||
wget https://raw.githubusercontent.com/ignitionrobotics/sdformat/sdf12/test/sdf/shapes_world.sdf | ||
./sdf2usd shapes_world.sdf shapes.usd | ||
``` | ||
|
||
You can now view the contents of the generated USD file with `usdcat` (this should have been installed when setting up the USD dependency): | ||
```bash | ||
usdcat shapes.usd | ||
``` | ||
|
||
To see the visual representation of the USD world, run `usdview` (this should have also been installed when setting up the USD dependency): | ||
```bash | ||
usdview shapes.usd | ||
``` | ||
|
||
### Note about building with colcon | ||
You may need to add the USD library path to your `LD_LIBRARY_PATH` environment variable after sourcing the colcon workspace. | ||
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: | ||
```bash | ||
sdf2usd: error while loading shared libraries: libusd_usd.so: cannot open shared object file: No such file or directory | ||
``` | ||
The typical USD library path is `<usd_installation_path>/lib`. | ||
So, if you installed USD at `/usr/local/USD`, the following command on Linux properly updates the `LD_LIBRARY_PATH` environment variable: | ||
```bash | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/USD/lib | ||
``` | ||
|
||
Another thing to note if building with colcon is that after sourcing the workspace with sdformat, | ||
the `sdf2usd` executable can be run without having to go to the `sdformat/build/bin` directory. | ||
So, instead of going to that directory and running `./sdf2usd ...`, you should be able to run `sdf2usd ...` from anywhere. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ign_install_all_headers(COMPONENT usd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2022 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#ifndef SDF_USD_SDF_PARSER_WORLD_HH_ | ||
#define SDF_USD_SDF_PARSER_WORLD_HH_ | ||
|
||
#include <string> | ||
|
||
// TODO(ahcorde):this is to remove deprecated "warnings" in usd, these warnings | ||
// are reported using #pragma message so normal diagnostic flags cannot remove | ||
// them. This workaround requires this block to be used whenever usd is | ||
// included. | ||
#pragma push_macro ("__DEPRECATED") | ||
#undef __DEPRECATED | ||
#include <pxr/usd/usd/stage.h> | ||
#pragma pop_macro ("__DEPRECATED") | ||
|
||
#include "sdf/config.hh" | ||
#include "sdf/system_util.hh" | ||
#include "sdf/World.hh" | ||
|
||
namespace sdf | ||
{ | ||
// Inline bracke to help doxygen filtering. | ||
inline namespace SDF_VERSION_NAMESPACE { | ||
// | ||
namespace usd | ||
{ | ||
/// \brief Parse an SDF world into a USD stage. | ||
/// \param[in] _world The SDF world to parse. | ||
/// \param[in] _stage The stage that should contain the USD representation | ||
/// of _world. It must be initialized first | ||
/// \param[in] _path The USD path of the parsed world in _stage, which must be | ||
/// a valid USD path. | ||
/// \return Errors, which is a vector of Error objects. Each Error includes | ||
/// an error code and message. An empty vector indicates no error. | ||
sdf::Errors SDFORMAT_VISIBLE ParseSdfWorld(const sdf::World &_world, | ||
pxr::UsdStageRefPtr &_stage, const std::string &_path); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
set(sources | ||
sdf_parser/World.cc | ||
) | ||
|
||
ign_add_component(usd SOURCES ${sources} GET_TARGET_NAME usd_target) | ||
|
||
target_include_directories(${usd_target} | ||
PUBLIC | ||
${PXR_INCLUDE_DIRS} | ||
) | ||
|
||
target_link_libraries(${usd_target} | ||
PUBLIC | ||
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER} | ||
${PXR_LIBRARIES} | ||
) | ||
|
||
set(gtest_sources | ||
sdf_parser/sdf2usd_TEST.cc | ||
sdf_parser/World_Sdf2Usd_TEST.cc | ||
) | ||
|
||
# Build the unit tests | ||
ign_build_tests( | ||
TYPE UNIT | ||
SOURCES ${gtest_sources} | ||
LIB_DEPS ${usd_target} ignition-cmake${IGN_CMAKE_VER}::utilities | ||
INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/test | ||
) | ||
|
||
add_subdirectory(cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
if(TARGET ${usd_target}) | ||
add_executable(sdf2usd | ||
sdf2usd.cc | ||
) | ||
|
||
target_link_libraries(sdf2usd | ||
PUBLIC | ||
ignition-utils${IGN_UTILS_VER}::ignition-utils${IGN_UTILS_VER} | ||
${usd_target} | ||
) | ||
|
||
install( | ||
TARGETS | ||
sdf2usd | ||
DESTINATION | ||
${BIN_INSTALL_DIR} | ||
) | ||
endif() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like CI has a configuration warning still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configuration warnings should be gone now thanks to gazebo-tooling/release-tools#625, but I realize that until this PR is merged, gazebo-tooling/release-tools#625 will cause CI warnings on other sdformat PRs, as mentioned in gazebo-tooling/release-tools#625 (comment). I'm not sure if we should merge this PR first to take care of CI warnings on other PRs, or revert gazebo-tooling/release-tools#625 until it's time to merge this PR. Does anyone have thoughts on how to handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can merge this today? If so, I think it's fine, but if not, there are at least two PRs waiting to be merged blocked on the CI failure, so I would recommend reverting the release-tools change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this can be merged today if the fix I mentioned in #817 (comment) seems valid. The only lingering question I have is about if we want to structure include guards in a particular way for the SDF -> USD and USD -> SDF converters, which isn't really a blocker: #817 (comment)
If CI is green, everything else has been addressed, so I think we should be good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I addressed the include guard fix, so I'm just waiting on CI to see if it comes back green 🤞