Skip to content
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 29 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
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 Jan 6, 2022
fa4568b
Added ignition-common4 as a dependency
ahcorde Jan 7, 2022
18f3ac1
create world prim and add physics information
adlarkin Jan 10, 2022
3bbd6ea
add unit test for world conversion
adlarkin Jan 11, 2022
16e0789
Added ci to compile with USD
ahcorde Jan 11, 2022
ae3ee43
Added feedback
ahcorde Jan 17, 2022
36d42fc
improved doc
ahcorde Jan 17, 2022
4545723
update CMake code
adlarkin Jan 18, 2022
91629c0
included namespaces
ahcorde Jan 19, 2022
6347953
Added basic test to sdf2usd cmd
ahcorde Jan 19, 2022
bb6ee5a
changes in sdf2usd
ahcorde Jan 19, 2022
d1d7af6
Fixed usd tutorial
ahcorde Jan 19, 2022
bab9e37
Removed unneeded CMakeLists.txt
ahcorde Jan 19, 2022
cbdfa49
Moved CMakeLists.txt
ahcorde Jan 19, 2022
99fb170
update example docs and other nits before merge
adlarkin Jan 19, 2022
819d5f5
Merge branch 'sdf12' into ahcorde/sdf_to_usd_cmake
adlarkin Jan 19, 2022
92eca63
clean CI
ahcorde Jan 19, 2022
0618353
Fixed CMake warning
ahcorde Jan 19, 2022
bcc282b
Fixed cmake
ahcorde Jan 19, 2022
0fd2568
reverted changes in CMakeLists.txt
ahcorde Jan 19, 2022
0195564
Improved test
ahcorde Jan 21, 2022
d91557e
fix search path of sdf2usd executable in UNIT_sdf2usd_TEST
adlarkin Jan 22, 2022
f3922f0
alphabetize packages.apt
adlarkin Jan 22, 2022
4c454a3
cleanup before_cmake.sh
ahcorde Jan 24, 2022
95c07e9
changed file structure
ahcorde Jan 24, 2022
b29b737
Merge branch 'ahcorde/sdf_to_usd_cmake' of https://github.com/ignitio…
ahcorde Jan 24, 2022
c4c189f
File structure
ahcorde Jan 24, 2022
0851949
Added TODO
ahcorde Jan 24, 2022
01aeb57
fix include guard
adlarkin Jan 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/ci/before_cmake.sh
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
2 changes: 2 additions & 0 deletions .github/ci/packages.apt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
libignition-cmake2-dev
libignition-common4-dev
libignition-math6-dev
libignition-tools-dev
libignition-utils1-dev
libignition-utils1-cli-dev
libtinyxml2-dev
liburdfdom-dev
libxml2-utils
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
runs-on: ubuntu-latest
name: Ubuntu Focal CI
steps:
- name: Set env
run: |
echo "PATH=$PATH:/tmp/USD/bin" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp/USD/lib" >> $GITHUB_ENV
echo "CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH:/tmp/USD" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v2
- name: Compile and test
Expand Down
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,18 @@ if (BUILD_SDF)
ign_find_package(ignition-utils1 VERSION REQUIRED)
set(IGN_UTILS_VER ${ignition-utils1_VERSION_MAJOR})

########################################
# Find ignition common
ign_find_package(ignition-common4 COMPONENTS graphics REQUIRED_BY usd)
set(IGN_COMMON_VER ${ignition-common4_VERSION_MAJOR})

########################################
# Find PXR
ign_find_package(pxr QUIET REQUIRED_BY usd PKGCONFIG pxr)
Copy link
Collaborator

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.

Copy link
Contributor

@adlarkin adlarkin Jan 20, 2022

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?

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Contributor

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 🤞


ign_configure_build(HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS
COMPONENTS usd)

ign_configure_build(HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS)
ign_create_packages()

add_subdirectory(sdf)
Expand Down
63 changes: 63 additions & 0 deletions examples/usdConverter/README.md
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.
22 changes: 22 additions & 0 deletions test/test_utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
#define SDF_TEST_UTILS_HH_

#include <ostream>
#include <string>

#include "sdf/Console.hh"
#include "sdf/Root.hh"

namespace sdf
{
Expand Down Expand Up @@ -104,6 +107,25 @@ class RedirectConsoleStream
private: sdf::Console::ConsoleStream oldStream;
};

/// \brief Load an SDF file into a sdf::Root object
/// \param[in] _fileName The name of the file to load
/// \param[in] _root The sdf::Root object to load the file into
/// \return True if a file named _fileName was successfully loaded into
/// _root. False otherwise
bool LoadSdfFile(const std::string &_fileName, sdf::Root &_root)
{
auto errors = _root.Load(_fileName);
if (!errors.empty())
{
std::cerr << "Errors encountered:\n";
for (const auto &e : errors)
std::cerr << e << "\n";
return false;
}

return true;
}

} // namespace testing
} // namespace sdf

Expand Down
1 change: 1 addition & 0 deletions usd/include/sdf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ign_install_all_headers(COMPONENT usd)
57 changes: 57 additions & 0 deletions usd/include/sdf/usd/sdf_parser/World.hh
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
31 changes: 31 additions & 0 deletions usd/src/CMakeLists.txt
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)
18 changes: 18 additions & 0 deletions usd/src/cmd/CMakeLists.txt
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()
Loading