Skip to content

Commit

Permalink
Merge pull request #856 from ignitionrobotics/azeey/12_to_main_20220218
Browse files Browse the repository at this point in the history
12 ➡️ main
  • Loading branch information
scpeters authored Feb 18, 2022
2 parents 54188ff + 2e71959 commit bce7061
Show file tree
Hide file tree
Showing 73 changed files with 4,913 additions and 134 deletions.
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-common5-dev
libignition-math7-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-common5 COMPONENTS graphics REQUIRED_BY usd)
set(IGN_COMMON_VER ${ignition-common5_VERSION_MAJOR})

########################################
# Find PXR
ign_find_package(pxr QUIET REQUIRED_BY usd PKGCONFIG pxr)

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-common5](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.
2 changes: 1 addition & 1 deletion include/sdf/Error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace sdf
VERSION_DEPRECATED,

/// \brief Merge include is unspported for the type of entity being
/// included.
/// included, or the custom parser does not support merge includes.
MERGE_INCLUDE_UNSUPPORTED,
};

Expand Down
11 changes: 11 additions & 0 deletions include/sdf/InterfaceElements.hh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ class SDFORMAT_VISIBLE NestedInclude
/// \param[in] _includeElement The include element
public: void SetIncludeElement(sdf::ElementPtr _includeElement);


/// \brief Set whether the interface model is to be merge-included (i.e
/// set the value of `//include/[@merge]`)
/// \param[in] _isMerge True if the interface model is to be merge included
public: void SetIsMerge(bool _isMerge);

/// \brief Whether the interface model is to be merge-included
/// \return If `//include/[@merge]` is set, this returns the value of the
/// attribute, otherwise, nullopt.
public: const std::optional<bool> &IsMerge() const;

/// \brief Provides the URI as specified in `//include/uri`. This may or may
/// not end with a file extension (it will not end with an extension if it
/// refers to a model package).
Expand Down
14 changes: 12 additions & 2 deletions include/sdf/InterfaceModel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,20 @@ class SDFORMAT_VISIBLE InterfaceModel
/// \brief Gets registered links.
public: const std::vector<sdf::InterfaceLink> &Links() const;

/// \brief Whether the custom parser supports merge-include.
/// \return True if the custom parser supports merge-include
public: bool ParserSupportsMergeInclude() const;

/// \brief Set whether the custom parser supports merge-include.
/// \brief[in] _val True if the custom parser supports merge-include.
public: void SetParserSupportsMergeInclude(bool _val);

/// \brief Recursively invoke the reposture callback if a the callback is set.
/// \param[in] _poseGraph Object used for resolving poses.
private: void InvokeRespostureFunction(
sdf::ScopedGraph<PoseRelativeToGraph> _graph) const;
/// \param[in] _name Override name of graph scope.
private: void InvokeRepostureFunction(
sdf::ScopedGraph<PoseRelativeToGraph> _graph,
const std::optional<std::string> &_name) const;

friend World;
friend Model;
Expand Down
65 changes: 65 additions & 0 deletions include/sdf/Link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ namespace sdf
/// \sa uint64_t VisualCount() const
public: const Visual *VisualByIndex(const uint64_t _index) const;

/// \brief Get a mutable visual based on an index.
/// \param[in] _index Index of the visual. The index should be in the
/// range [0..VisualCount()).
/// \return Pointer to the visual. Nullptr if the index does not exist.
/// \sa uint64_t VisualCount() const
public: Visual *VisualByIndex(uint64_t _index);

/// \brief Get whether a visual name exists.
/// \param[in] _name Name of the visual to check.
/// \return True if there exists a visual with the given name.
Expand All @@ -86,6 +93,11 @@ namespace sdf
/// \return Pointer to the visual. Nullptr if the name does not exist.
public: const Visual *VisualByName(const std::string &_name) const;

/// \brief Get a mutable visual based on a name.
/// \param[in] _name Name of the visual.
/// \return Pointer to the visual. Nullptr if the name does not exist.
public: Visual *VisualByName(const std::string &_name);

/// \brief Get the number of collisions.
/// \return Number of collisions contained in this Link object.
public: uint64_t CollisionCount() const;
Expand All @@ -97,6 +109,13 @@ namespace sdf
/// \sa uint64_t CollisionCount() const
public: const Collision *CollisionByIndex(const uint64_t _index) const;

/// \brief Get a mutable collision based on an index.
/// \param[in] _index Index of the collision. The index should be in the
/// range [0..CollisionCount()).
/// \return Pointer to the collision. Nullptr if the index does not exist.
/// \sa uint64_t CollisionCount() const
public: Collision *CollisionByIndex(uint64_t _index);

/// \brief Get whether a collision name exists.
/// \param[in] _name Name of the collision to check.
/// \return True if there exists a collision with the given name.
Expand All @@ -107,6 +126,11 @@ namespace sdf
/// \return Pointer to the collision. Nullptr if the name does not exist.
public: const Collision *CollisionByName(const std::string &_name) const;

/// \brief Get a mutable collision based on a name.
/// \param[in] _name Name of the collision.
/// \return Pointer to the collision. Nullptr if the name does not exist.
public: Collision *CollisionByName(const std::string &_name);

/// \brief Get the number of lights.
/// \return Number of lights contained in this Link object.
public: uint64_t LightCount() const;
Expand All @@ -118,6 +142,13 @@ namespace sdf
/// \sa uint64_t LightCount() const
public: const Light *LightByIndex(const uint64_t _index) const;

/// \brief Get a mutable light based on an index.
/// \param[in] _index Index of the light. The index should be in the
/// range [0..LightCount()).
/// \return Pointer to the light. Nullptr if the index does not exist.
/// \sa uint64_t LightCount() const
public: Light *LightByIndex(uint64_t _index);

/// \brief Get whether a light name exists.
/// \param[in] _name Name of the light to check.
/// \return True if there exists a light with the given name.
Expand All @@ -128,6 +159,11 @@ namespace sdf
/// \return Pointer to the light. Nullptr if the name does not exist.
public: const Light *LightByName(const std::string &_name) const;

/// \brief Get a mutable light based on a name.
/// \param[in] _name Name of the light.
/// \return Pointer to the light. Nullptr if the name does not exist.
public: Light *LightByName(const std::string &_name);

/// \brief Get the number of sensors.
/// \return Number of sensors contained in this Link object.
public: uint64_t SensorCount() const;
Expand All @@ -139,6 +175,13 @@ namespace sdf
/// \sa uint64_t SensorCount() const
public: const Sensor *SensorByIndex(const uint64_t _index) const;

/// \brief Get a mutable sensor based on an index.
/// \param[in] _index Index of the sensor. The index should be in the
/// range [0..SensorCount()).
/// \return Pointer to the sensor. Nullptr if the index does not exist.
/// \sa uint64_t SensorCount() const
public: Sensor *SensorByIndex(uint64_t _index);

/// \brief Get whether a sensor name exists.
/// \param[in] _name Name of the sensor to check.
/// \return True if there exists a sensor with the given name.
Expand All @@ -151,6 +194,13 @@ namespace sdf
/// \sa bool SensorNameExists(const std::string &_name) const
public: const Sensor *SensorByName(const std::string &_name) const;

/// \brief Get a mutable sensor based on a name.
/// \param[in] _name Name of the sensor.
/// \return Pointer to the sensor. Nullptr if a sensor with the given name
/// does not exist.
/// \sa bool SensorNameExists(const std::string &_name) const
public: Sensor *SensorByName(const std::string &_name);

/// \brief Get the number of particle emitters.
/// \return Number of particle emitters contained in this Link object.
public: uint64_t ParticleEmitterCount() const;
Expand All @@ -164,6 +214,14 @@ namespace sdf
public: const ParticleEmitter *ParticleEmitterByIndex(
const uint64_t _index) const;

/// \brief Get a mutable particle emitter based on an index.
/// \param[in] _index Index of the particle emitter.
/// The index should be in the range [0..ParticleEmitterCount()).
/// \return Pointer to the particle emitter. Nullptr if the index does
/// not exist.
/// \sa uint64_t ParticleEmitterCount() const
public: ParticleEmitter *ParticleEmitterByIndex(uint64_t _index);

/// \brief Get whether a particle emitter name exists.
/// \param[in] _name Name of the particle emitter to check.
/// \return True if there exists a particle emitter with the given name.
Expand All @@ -177,6 +235,13 @@ namespace sdf
public: const ParticleEmitter *ParticleEmitterByName(
const std::string &_name) const;

/// \brief Get a mutable particle emitter based on a name.
/// \param[in] _name Name of the particle emitter.
/// \return Pointer to the particle emitter. Nullptr if a particle emitter
/// with the given name does not exist.
/// \sa bool ParticleEmitterNameExists(const std::string &_name) const
public: ParticleEmitter *ParticleEmitterByName(const std::string &_name);

/// \brief Get the inertial value for this link. The inertial object
/// consists of the link's mass, a 3x3 rotational inertia matrix, and
/// a pose for the inertial reference frame. The units for mass is
Expand Down
Loading

0 comments on commit bce7061

Please sign in to comment.