Skip to content

Make SDF -> USD code a separate component of SDF #816

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

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2349364
add enable_orientation to 1.6 spec (#686)
iche033 Nov 8, 2021
0c6e7ad
Backport cmake/test fixes to sdf6 (#761)
scpeters Nov 29, 2021
3b385c9
Added ToElement conversion for physics and atmosphere (#771)
nkoenig Dec 6, 2021
520b74f
Aded ToElement conversion for shapes (#772)
nkoenig Dec 6, 2021
9ba8ea1
Merge branch 'sdf6' into sdf9
scpeters Dec 6, 2021
3266e33
Merge pull request #774 from scpeters/merge_6_9
scpeters Dec 6, 2021
8de1eb6
Material toelement (#775)
nkoenig Dec 8, 2021
b28967c
Added Geometry ToElement function (#776)
nkoenig Dec 8, 2021
e8a73e4
Added ToElement conversion for Collision, Surface, and Visual (#777)
nkoenig Dec 9, 2021
93c045c
PrintConfig option to preserve includes when converting to string (#749)
jennuine Dec 9, 2021
5b48e41
Added ToElement for ParticleEmitter and Link (#781)
nkoenig Dec 10, 2021
2f21fb2
Model actor toelement functions (#782)
nkoenig Dec 10, 2021
24a2782
Documentation: Clarify behavior of //model/model/static (#713)
FirefoxMetzger Dec 10, 2021
826e7d6
More to element (#783)
nkoenig Dec 11, 2021
4a6b5b6
Support adding and clearing sensors from a joint (#785)
nkoenig Dec 14, 2021
1a88972
Support URI in the Model DOM (#786)
nkoenig Dec 17, 2021
ef48530
Added plugin to SDF DOM (#788)
nkoenig Dec 17, 2021
41ad073
Fix loading nested include with custom attributes (#789)
jennuine Dec 17, 2021
de356cd
Refactor FrameSemantics.cc (#764)
azeey Dec 20, 2021
e5c29da
9 ➡️ 10
chapulina Dec 21, 2021
5e91938
Support printing sdf poses in degrees and allow snapping to commonly …
aaronchongth Dec 21, 2021
6b53f95
9 ➡️ 10 (#795)
chapulina Dec 21, 2021
92d20d2
Replace custom cmake code with ign-cmake2 (#780)
scpeters Dec 22, 2021
1a2c406
Prepare for 10.7.0~pre1 (#799)
scpeters Dec 23, 2021
cf81994
Fix test compilation with USE_INTERNAL_URDF (#800)
scpeters Dec 27, 2021
1741bb0
Prepare for 10.7.0~pre2 (#802)
scpeters Dec 27, 2021
5f326e9
Prepare for 10.7.0, final Dome release (#804)
scpeters Dec 27, 2021
38a69ab
Merge commit '6b53f954b8b74d0bdba33982d59c25da8b280ee4' into merge_9_…
scpeters Dec 29, 2021
bff502f
sdf_custom: fix nested model expectations (#807)
scpeters Dec 29, 2021
5c6e870
Merge pull request #807 from scpeters/merge_9_to_11
scpeters Dec 29, 2021
09c06ea
Merge branch 'sdf10' into merge_10_11
scpeters Dec 29, 2021
f03ec70
Fix compiler warnings (#808)
scpeters Dec 29, 2021
206e698
Merge pull request #808 from scpeters/merge_10_11
scpeters Dec 30, 2021
08eccbf
Merge branch 'sdf11' into merge_11_to_12
scpeters Dec 30, 2021
15e6793
Fix compiler warnings (#810)
scpeters Dec 30, 2021
8785b7a
Merge pull request #810 from scpeters/merge_11_to_12
scpeters Dec 30, 2021
6404afd
Fix parsing 'type' attibutes in plugins (#809)
chapulina Jan 3, 2022
63cc4c0
Merge branch 'sdf12' into adlarkin/sdf_to_usd_cmake
adlarkin Jan 5, 2022
26c1a47
make SDF to USD a separate component of sdformat
adlarkin Jan 6, 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
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})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have a dependency on ign-common in order to parse meshes to/from SDF and USD. I realize that this is a new dependency that we probably don't want to have, but since it's only needed by the usd component, is it okay to have this new dependency?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's ok


########################################
# Find PXR
ign_find_package(pxr REQUIRED_BY usd PKGCONFIG pxr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the PKGCONFIG pxr portion should be here. If I didn't include this, I would see the following warning: https://github.com/ignitionrobotics/ign-cmake/blob/a1eb36a9a6283bb1fe5b4c755a2b3669572e0c08/cmake/IgnUtils.cmake#L378-L391

Can someone confirm if adding PKGCONFIG pxr is correct or not?


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
13 changes: 13 additions & 0 deletions examples/usdConverter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)

project(usdSdfConversions)

set(SDF_VER 12)
find_package(sdformat${SDF_VER} COMPONENTS usd REQUIRED)

add_executable(usdConverter usdConverter.cc)

target_link_libraries(usdConverter
PUBLIC
sdformat${SDF_VER}::usd
)
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 `usdConverter`, 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
./usdConverter ../shapes.sdf shapes.usda
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now, this is not working - whenever I try to run the executable generated by the example, I get the following error:

./usdConverter: error while loading shared libraries: libusd_usdPhysics.so: cannot open shared object file: No such file or directory

This was not happening with this executable before turning all of this code into a separate component, so perhaps the component is not being created correctly at the moment. Does anyone know what's happening here? cc @scpeters

```

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>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <pxr/usd/usd/stage.h>

#include "sdf/sdf.hh"
#include "sdf_usd_parser/world.hh"
#include "sdf/world.hh"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried following the file structure for components in ign-common:

<component name>
    |__include
    |    |__<project name>
    |         |__component header files
    |__src
         |__component source files

This means that for the USD component, header files are in the path usd/include/sdformat, and when it's time to #include them in the component's source files, they have the same prefix as sdformat's header files (sdf/). This doesn't result in naming collisions right now because the component header files are not upper case, but a lot of the USD component header files are essentially just a lower case name of the sdformat header files, which can make this code confusing to read (example: world.hh vs World.hh). Should I change the component header file structure somehow so that the #include path is unique (for example, something like #include "sdf/usd/...")?


int main(int argc, const char* argv[])
{
Expand Down
18 changes: 0 additions & 18 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,3 @@ file(GENERATE

# Install the ruby command line library in an unversioned location.
install(FILES ${cmd_script_generated} DESTINATION lib/ruby/ignition)

#===============================================================================
# SDF -> USD converter
add_executable(usdConverter
usdConverter.cc
)

target_link_libraries(usdConverter
PUBLIC
${sdf_target}
)

install(
TARGETS
usdConverter
DESTINATION
${BIN_INSTALL_DIR}
)
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)
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*
*/

#ifndef SDF_PARSER_GEOMETRY_HH_
#define SDF_PARSER_GEOMETRY_HH_
#ifndef SDF_USD_GEOMETRY_HH_
#define SDF_USD_GEOMETRY_HH_

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions src/usd/sdf_usd_parser/joint.hh → usd/include/sdf/joint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*
*/

#ifndef SDF_PARSER_JOINT_HH_
#define SDF_PARSER_JOINT_HH_
#ifndef SDF_USD_JOINT_HH_
#define SDF_USD_JOINT_HH_

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions src/usd/sdf_usd_parser/light.hh → usd/include/sdf/light.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*
*/

#ifndef SDF_PARSER_LIGHT_HH_
#define SDF_PARSER_LIGHT_HH_
#ifndef SDF_USD_LIGHT_HH_
#define SDF_USD_LIGHT_HH_

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions src/usd/sdf_usd_parser/link.hh → usd/include/sdf/link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*
*/

#ifndef SDF_PARSER_LINK_HH_
#define SDF_PARSER_LINK_HH_
#ifndef SDF_USD_LINK_HH_
#define SDF_USD_LINK_HH_

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions src/usd/sdf_usd_parser/model.hh → usd/include/sdf/model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*
*/

#ifndef SDF_PARSER_MODEL_HH_
#define SDF_PARSER_MODEL_HH_
#ifndef SDF_USD_MODEL_HH_
#define SDF_USD_MODEL_HH_

#include <string>

Expand Down
Loading