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 2 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
1 change: 1 addition & 0 deletions .github/ci/packages.apt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
libignition-common4-dev
libignition-cmake2-dev
libignition-math6-dev
libignition-tools-dev
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ 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 REQUIRED_BY usd PKGCONFIG pxr)

ign_configure_build(HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS)
ign_configure_build(HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS
COMPONENTS usd)
ign_create_packages()

add_subdirectory(sdf)
Expand Down
30 changes: 30 additions & 0 deletions examples/usdConverter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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)

## Setup

Build sdformat, and then run the following commands to build the example (run these commands from this example directory):
```bash
mkdir build
cd build
cmake ..
make
```

You should now have an executable named `sdf2usd`, which can be used to convert a SDF world file to a USD file.
The following command converts the example `shapes.sdf` file to its USD representation, stored in a file called `shapes.usda` (run this command from the `build` directory):
```bash
./sdf2usd ../shapes.sdf shapes.usda
```

You can now view the contents of the generated USD file with `usdview` (this should have been installed when setting up the USD dependency):
```
usdview shapes.usda
```
244 changes: 244 additions & 0 deletions examples/usdConverter/shapes.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
<?xml version="1.0" ?>
<!--

Try moving a model:

ign service -s /world/shapes/set_pose --reqtype ignition.msgs.Pose --reptype ignition.msgs.Boolean --timeout 300 --req 'name: "box", position: {z: 5.0}'

-->
<sdf version="1.6">
<world name="shapes">
<scene>
<ambient>1.0 1.0 1.0</ambient>
<background>0.8 0.8 0.8</background>
</scene>

<light type="directional" name="sun">
<cast_shadows>true</cast_shadows>
<pose>0 0 10 0 0 0</pose>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
<attenuation>
<range>1000</range>
<constant>0.9</constant>
<linear>0.01</linear>
<quadratic>0.001</quadratic>
</attenuation>
<direction>-0.5 0.1 -0.9</direction>
</light>

<model name="ground_plane">
<static>true</static>
<link name="link">
<collision name="collision">
<geometry>
<plane>
<normal>0 0 1</normal>
<size>100 100</size>
</plane>
</geometry>
</collision>
<visual name="visual">
<geometry>
<plane>
<normal>0 0 1</normal>
<size>100 100</size>
</plane>
</geometry>
<material>
<ambient>0.8 0.8 0.8 1</ambient>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.8 0.8 0.8 1</specular>
</material>
</visual>
</link>
</model>

<model name="box">
<pose>0 0 0.5 0 0 0</pose>
<link name="box_link">
<inertial>
<inertia>
<ixx>0.16666</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.16666</iyy>
<iyz>0</iyz>
<izz>0.16666</izz>
</inertia>
<mass>1.0</mass>
</inertial>
<collision name="box_collision">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
</collision>

<visual name="box_visual">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
<material>
<ambient>1 0 0 1</ambient>
<diffuse>1 0 0 1</diffuse>
<specular>1 0 0 1</specular>
</material>
</visual>
</link>
</model>

<model name="cylinder">
<pose>0 -1.5 0.5 0 0 0</pose>
<link name="cylinder_link">
<inertial>
<inertia>
<ixx>0.1458</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.1458</iyy>
<iyz>0</iyz>
<izz>0.125</izz>
</inertia>
<mass>1.0</mass>
</inertial>
<collision name="cylinder_collision">
<geometry>
<cylinder>
<radius>0.5</radius>
<length>1.0</length>
</cylinder>
</geometry>
</collision>

<visual name="cylinder_visual">
<geometry>
<cylinder>
<radius>0.5</radius>
<length>1.0</length>
</cylinder>
</geometry>
<material>
<ambient>0 1 0 1</ambient>
<diffuse>0 1 0 1</diffuse>
<specular>0 1 0 1</specular>
</material>
</visual>
</link>
</model>

<model name="sphere">
<pose>0 1.5 0.5 0 0 0</pose>
<link name="sphere_link">
<inertial>
<inertia>
<ixx>0.1</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.1</iyy>
<iyz>0</iyz>
<izz>0.1</izz>
</inertia>
<mass>1.0</mass>
</inertial>
<collision name="sphere_collision">
<geometry>
<sphere>
<radius>0.5</radius>
</sphere>
</geometry>
</collision>

<visual name="sphere_visual">
<geometry>
<sphere>
<radius>0.5</radius>
</sphere>
</geometry>
<material>
<ambient>0 0 1 1</ambient>
<diffuse>0 0 1 1</diffuse>
<specular>0 0 1 1</specular>
</material>
</visual>
</link>
</model>

<model name="capsule">
<pose>0 -3.0 0.5 0 0 0</pose>
<link name="capsule_link">
<inertial>
<inertia>
<ixx>0.074154</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.074154</iyy>
<iyz>0</iyz>
<izz>0.018769</izz>
</inertia>
<mass>1.0</mass>
</inertial>
<collision name="capsule_collision">
<geometry>
<capsule>
<radius>0.2</radius>
<length>0.6</length>
</capsule>
</geometry>
</collision>
<visual name="capsule_visual">
<geometry>
<capsule>
<radius>0.2</radius>
<length>0.6</length>
</capsule>
</geometry>
<material>
<ambient>1 1 0 1</ambient>
<diffuse>1 1 0 1</diffuse>
<specular>1 1 0 1</specular>
</material>
</visual>
</link>
</model>

<model name="ellipsoid">
<pose>0 3.0 0.5 0 0 0</pose>
<link name="ellipsoid_link">
<inertial>
<inertia>
<ixx>0.068</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>0.058</iyy>
<iyz>0</iyz>
<izz>0.026</izz>
</inertia>
<mass>1.0</mass>
</inertial>
<collision name="ellipsoid_collision">
<geometry>
<ellipsoid>
<radii>0.2 0.3 0.5</radii>
</ellipsoid>
</geometry>
</collision>
<visual name="ellipsoid_visual">
<geometry>
<ellipsoid>
<radii>0.2 0.3 0.5</radii>
</ellipsoid>
</geometry>
<material>
<ambient>1 0 1 1</ambient>
<diffuse>1 0 1 1</diffuse>
<specular>1 0 1 1</specular>
</material>
</visual>
</link>
</model>
</world>
</sdf>
1 change: 1 addition & 0 deletions usd/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ign_install_all_headers(COMPONENT usd)
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)
1 change: 1 addition & 0 deletions usd/include/sdf/usd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ign_install_all_headers(COMPONENT usd)
42 changes: 42 additions & 0 deletions usd/include/sdf/usd/World.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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_WORLD_HH_
#define SDF_USD_WORLD_HH_

#include <string>

#include <pxr/usd/usd/stage.h>

#include "sdf/World.hh"
#include "sdf/sdf_config.h"

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.
/// \param[in] _path The USD path of the parsed world in _stage, which must be
/// a valid USD path.
/// \return True if _world was succesfully parsed into _stage with a path of
/// _path. False otherwise.
bool SDFORMAT_VISIBLE ParseSdfWorld(const sdf::World &_world,
pxr::UsdStageRefPtr &_stage, const std::string &_path);
}

#endif
22 changes: 22 additions & 0 deletions usd/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Collect source files into the "sources" variable and unit test files into the
# "gtest_sources" variable.
ign_get_libsources_and_unittests(sources gtest_sources)

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}
ignition-common${IGN_COMMON_VER}::graphics
${PXR_LIBRARIES}
)

# Build the unit tests
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS ${usd_target})

add_subdirectory(cmd)
Loading