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

USD to SDF converter #736

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
04ac451
prototype
ahcorde Oct 21, 2021
fec7541
prototype
ahcorde Oct 26, 2021
9ce073f
prototype
ahcorde Oct 27, 2021
787e8f5
User ignition Math, common and sdformat typs
ahcorde Nov 2, 2021
5115f44
using sdf::joint
ahcorde Nov 2, 2021
d4cb4cc
Vehicle joint and some other fixes
ahcorde Nov 3, 2021
9b73015
materials and geometry subsets
ahcorde Nov 5, 2021
a74ee34
Improvements in materials, meshes and joints
ahcorde Nov 10, 2021
fe2ddb0
Improve materials, meshes and others
ahcorde Nov 11, 2021
ce46639
more updates
ahcorde Nov 13, 2021
8fc9666
improvements
ahcorde Nov 16, 2021
ac61126
Added lights, camera sensor and other TF fixes
ahcorde Nov 18, 2021
d127881
Added model vector and other features
ahcorde Nov 19, 2021
163637a
Fix light API and other things
ahcorde Nov 23, 2021
09eea1f
Fixed material and polygon to triangles with CGAL
ahcorde Nov 25, 2021
c344a55
Fixed textures and subgeom pose
ahcorde Nov 25, 2021
5bd5c7b
More changes
ahcorde Nov 29, 2021
0c629c2
Added lidar, collisions and others
ahcorde Dec 1, 2021
58ac549
Add more code
ahcorde Dec 14, 2021
1e9890b
fix USD -> SDF converter build
adlarkin Jan 13, 2022
304d27c
Fixed directory name
ahcorde Jan 13, 2022
e11a18e
Added tutorials
ahcorde Jan 13, 2022
83f86ab
Added missing dependency
ahcorde Jan 13, 2022
aa1333d
USD -> SDF: polygon triangulation (#819)
Jan 18, 2022
f2e88dd
Some more fixes
ahcorde Jan 18, 2022
4deb2bc
cleanup
ahcorde Jan 18, 2022
1c4ba22
Fix
ahcorde Jan 18, 2022
d2fd2a8
USD -> SDF: fix y up (#825)
Jan 20, 2022
d82cf39
cleanup
ahcorde Jan 20, 2022
bfd8d08
some fixes
ahcorde Feb 25, 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
12 changes: 12 additions & 0 deletions cmake/SearchForStuff.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ else()
message(STATUS "Looking for ignition-math${IGN_MATH_VER}-config.cmake - found")
endif()

########################################
# Find ignition common
# Set a variable for generating ProjectConfig.cmake
find_package(ignition-common4 4.0 QUIET)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is ign-common needed for anything other than common::split? I'd avoid adding a dependency if we don't need it. We already have sdf::split that provides the same functionality.

if (NOT ignition-common4_FOUND)
message(STATUS "Looking for ignition-common4-config.cmake - not found")
BUILD_ERROR ("Missing: Ignition math (libignition-common4-dev)")
else()
set(IGN_COMMON_VER ${ignition-common4_VERSION_MAJOR})
message(STATUS "Looking for ignition-common${IGN_COMMON_VER}-config.cmake - found")
endif()

########################################
# Find ignition utils
# Set a variable for generating ProjectConfig.cmake
Expand Down
4 changes: 4 additions & 0 deletions cmake/sdf_config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ find_package(ignition-math@IGN_MATH_VER@)
list(APPEND @PKG_NAME@_INCLUDE_DIRS ${IGNITION-MATH_INCLUDE_DIRS})
list(APPEND @PKG_NAME@_LIBRARY_DIRS ${IGNITION-MATH_LIBRARY_DIRS})

find_package(ignition-commonh@IGN_COMMON_VER@)
list(APPEND @PKG_NAME@_INCLUDE_DIRS ${IGNITION-COMMON_INCLUDE_DIRS})
list(APPEND @PKG_NAME@_LIBRARY_DIRS ${IGNITION-COMMON_LIBRARY_DIRS})

find_package(ignition-utils@IGN_UTILS_VER@)
list(APPEND @PKG_NAME@_INCLUDE_DIRS ${IGNITION-UTILS_INCLUDE_DIRS})
list(APPEND @PKG_NAME@_LIBRARY_DIRS ${IGNITION-UTILS_LIBRARY_DIRS})
Expand Down
61 changes: 42 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ set (sources
Noise.cc
parser.cc
parser_urdf.cc
parser_usd.cc
ParserConfig.cc
Param.cc
ParamPassing.cc
Expand Down Expand Up @@ -93,6 +94,17 @@ else()
include_directories(${URDF_INCLUDE_DIRS})
endif()

find_package(pxr REQUIRED)

include_directories(${PXR_INCLUDE_DIRS})
set(sources ${sources}
usd/usd_parser/parser_usd.cc
usd/usd_parser/physics.cc
usd/usd_parser/joints.cc
usd/usd_parser/links.cc
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/usd)

if (BUILD_SDF_TEST)
set (gtest_sources
Actor_TEST.cc
Expand All @@ -116,7 +128,6 @@ if (BUILD_SDF_TEST)
Gui_TEST.cc
Heightmap_TEST.cc
Imu_TEST.cc
InterfaceElements_TEST.cc
Joint_TEST.cc
JointAxis_TEST.cc
Lidar_TEST.cc
Expand Down Expand Up @@ -191,33 +202,40 @@ if (BUILD_SDF_TEST)
endif()

if (NOT WIN32)
set(SDF_BUILD_TESTS_EXTRA_EXE_SRCS SDFExtension.cc parser_urdf.cc XmlUtils.cc)
set(SDF_BUILD_TESTS_EXTRA_EXE_SRCS SDFExtension.cc parser_urdf.cc parser_usd.cc XmlUtils.cc
usd/usd_parser/parser_usd.cc usd/usd_parser/physics.cc usd/usd_parser/joints.cc usd/usd_parser/links.cc
)
sdf_build_tests(parser_urdf_TEST.cc)
if (NOT USE_INTERNAL_URDF)
target_compile_options(UNIT_parser_urdf_TEST PRIVATE ${URDF_CFLAGS})
if (${CMAKE_VERSION} VERSION_GREATER 3.13)
target_link_options(UNIT_parser_urdf_TEST PRIVATE ${URDF_LDFLAGS})
endif()
target_link_libraries(UNIT_parser_urdf_TEST PRIVATE ${URDF_LIBRARIES})
target_link_libraries(UNIT_parser_urdf_TEST PRIVATE ${URDF_LIBRARIES}
)
endif()
target_link_libraries(UNIT_parser_urdf_TEST PRIVATE
${TinyXML2_LIBRARIES})
endif()

if (NOT WIN32)
set(SDF_BUILD_TESTS_EXTRA_EXE_SRCS ParamPassing.cc XmlUtils.cc parser.cc
parser_urdf.cc FrameSemantics.cc Converter.cc EmbeddedSdf.cc SDFExtension.cc Utils.cc)
sdf_build_tests(ParamPassing_TEST.cc)
if (NOT USE_INTERNAL_URDF)
target_compile_options(UNIT_ParamPassing_TEST PRIVATE ${URDF_CFLAGS})
if (${CMAKE_VERSION} VERSION_GREATER 3.13)
target_link_options(UNIT_ParamPassing_TEST PRIVATE ${URDF_LDFLAGS})
endif()
target_link_libraries(UNIT_ParamPassing_TEST PRIVATE ${URDF_LIBRARIES})
endif()
target_link_libraries(UNIT_ParamPassing_TEST PRIVATE
${TinyXML2_LIBRARIES})
target_link_libraries(UNIT_parser_urdf_TEST PRIVATE
${TinyXML2_LIBRARIES}
${PYTHON_LIBRARY}
${PXR_LIBRARIES}
)
endif()
#
# if (NOT WIN32)
# set(SDF_BUILD_TESTS_EXTRA_EXE_SRCS ParamPassing.cc XmlUtils.cc parser.cc parser_usd.cc
# parser_urdf.cc parser_usd.cc FrameSemantics.cc Converter.cc EmbeddedSdf.cc SDFExtension.cc Utils.cc)
# sdf_build_tests(ParamPassing_TEST.cc)
# if (NOT USE_INTERNAL_URDF)
# target_compile_options(UNIT_ParamPassing_TEST PRIVATE ${URDF_CFLAGS})
# if (${CMAKE_VERSION} VERSION_GREATER 3.13)
# target_link_options(UNIT_ParamPassing_TEST PRIVATE ${URDF_LDFLAGS})
# endif()
# target_link_libraries(UNIT_ParamPassing_TEST PRIVATE ${URDF_LIBRARIES})
# endif()
# target_link_libraries(UNIT_ParamPassing_TEST PRIVATE
# ${TinyXML2_LIBRARIES})
# endif()
endif()

sdf_add_library(${sdf_target} ${sources})
Expand All @@ -226,6 +244,9 @@ target_link_libraries(${sdf_target}
PUBLIC
ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER}
ignition-utils${IGN_UTILS_VER}::ignition-utils${IGN_UTILS_VER}
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER}
${PYTHON_LIBRARY}
${PXR_LIBRARIES}
PRIVATE
${TinyXML2_LIBRARIES})

Expand All @@ -237,6 +258,8 @@ target_include_directories(${sdf_target}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}/..>
${PYTHON_INCLUDE_PATH}
${USD_INCLUDE_DIRECTORY}
)

message (STATUS "URDF_LIBRARY_DIRS=${URDF_LIBRARY_DIRS}")
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,21 @@ file(GENERATE

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

add_executable(sdfconverter
sdfconverter.cpp
)

target_link_libraries(sdfconverter
PUBLIC
ignition-utils${IGN_UTILS_VER}::ignition-utils${IGN_UTILS_VER}
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER}
${sdf_target}
)

install(
TARGETS
${gui_executable}
DESTINATION
${BIN_INSTALL_DIR}
)
92 changes: 92 additions & 0 deletions src/cmd/sdfconverter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2021 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.
*
*/

#include <string.h>

#include <ignition/utils/cli/CLI.hpp>

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

//////////////////////////////////////////////////
/// \brief Enumeration of available commands
enum class Command
{
kNone,
};

//////////////////////////////////////////////////
/// \brief Structure to hold all available topic options
struct Options
{
/// \brief Command to execute
Command command{Command::kNone};

/// \brief input filename
std::string inputFilename{"input.sdf"};

/// \brief output filename
std::string outputFilename{"output.sdf"};
};

void runCommand(const Options &_opt)
{
// Read an SDF file, and store the result in sdf.
auto sdf = sdf::readFile(_opt.inputFilename);

if (sdf)
{
sdf->Write(_opt.outputFilename);
return;
}
std::cerr << "Error sdf was not able to open the file" << '\n';
}

void addFlags(CLI::App &_app)
{
auto opt = std::make_shared<Options>();

_app.add_option("-i,--input",
Copy link

Choose a reason for hiding this comment

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

nit: It will be nice to have the same cli for usd -> sdf and sdf -> usd converter, iirc, the sdf -> usd converter takes the input and output args as positionals.

opt->inputFilename,
"Input filename");

_app.add_option("-o,--output",
opt->outputFilename,
"Output filename");

_app.callback([&_app, opt](){
runCommand(*opt);
});
}

//////////////////////////////////////////////////
int main(int argc, char** argv)
{
CLI::App app{"Sdf format converter"};

app.set_help_all_flag("--help-all", "Show all help");

app.add_flag_callback("--version", [](){
std::cout << strdup(SDF_VERSION_FULL) << std::endl;
throw CLI::Success();
});

addFlags(app);
CLI11_PARSE(app, argc, argv);

return 0;
}
20 changes: 20 additions & 0 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "Utils.hh"
#include "parser_private.hh"
#include "parser_urdf.hh"
#include "parser_usd.hh"

namespace sdf
{
Expand Down Expand Up @@ -713,6 +714,25 @@ bool readFileInternal(const std::string &_filename, const bool _convert,
return false;
}

if (USD2SDF::IsUSD(filename))
Copy link

Choose a reason for hiding this comment

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

Is embedding the usd converter into the sdf parser something we should be doing?

{
USD2SDF usd2g;
auto doc = makeSdfDoc();
usd2g.read(filename, &doc);
sdferr << "here! it's a USD!\n";
if (sdf::readDoc(&doc, _sdf, "usd file", _convert, _config, _errors))
Copy link

Choose a reason for hiding this comment

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

I don't quite understand this, shouldn't the 3rd param be the filename?

{
sdfdbg << "parse from usd file [" << _filename << "].\n";
return true;
}
else
{
sdferr << "parse as old deprecated model file failed.\n";
Copy link

Choose a reason for hiding this comment

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

What is the old deprecated model?

return false;
}
return true;
}

auto error_code = xmlDoc.LoadFile(filename.c_str());
if (error_code)
{
Expand Down
1 change: 1 addition & 0 deletions src/parser_urdf_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "sdf/sdf.hh"
#include "parser_urdf.hh"
#include "./parser_usd.hh"
Copy link

Choose a reason for hiding this comment

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

There is no other changes in this file so this include looks redundant.


/////////////////////////////////////////////////
std::string getMinimalUrdfTxt()
Expand Down
Loading