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 19 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 REQUIRED graphics)
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
1 change: 1 addition & 0 deletions include/sdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set (headers
Capsule.hh
Collision.hh
Console.hh
Conversions.hh
Cylinder.hh
Element.hh
Ellipsoid.hh
Expand Down
49 changes: 49 additions & 0 deletions include/sdf/Conversions.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 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.
*
*/


#ifndef SDF_CONVERSIONS_HH_
#define SDF_CONVERSIONS_HH_

#include <memory>

#include <ignition/common/Material.hh>
#include <sdf/Material.hh>
#include "sdf/sdf_config.h"

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//
/// \brief Specialized conversion from an SDF material to a Ignition Common
/// material.
/// \param[in] _in Ignition Common Material.
/// \return Geometry material.
SDFORMAT_VISIBLE
sdf::Material convert(const ignition::common::Material &_in);

/// \brief Specialized conversion from an Ignition Common Material
/// to a SDF material
/// \param[in] _in SDF material.
/// \return Ignition Common Material.
SDFORMAT_VISIBLE
std::shared_ptr<ignition::common::Material> convertMaterial(sdf::Material &_in);
}
}

#endif
80 changes: 61 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set (sources
Capsule.cc
Collision.cc
Console.cc
Conversions.cc
Converter.cc
Cylinder.cc
Element.cc
Expand Down Expand Up @@ -53,6 +54,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 +95,24 @@ else()
include_directories(${URDF_INCLUDE_DIRS})
endif()

find_package(pxr REQUIRED)
find_package(CGAL)

include_directories(${PXR_INCLUDE_DIRS})
set(sources ${sources}
usd/usd/USDStage.cc
usd/usd/USDData.cc
usd/usd_parser/parser_usd.cc
usd/usd_parser/polygon_helper.cc
usd/usd_parser/physics.cc
usd/usd_parser/joints.cc
usd/usd_parser/lights.cc
usd/usd_parser/links.cc
usd/usd_parser/sensors.cc
usd/usd_parser/utils.cc
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/usd)

if (BUILD_SDF_TEST)
set (gtest_sources
Actor_TEST.cc
Expand All @@ -104,6 +124,7 @@ if (BUILD_SDF_TEST)
Capsule_TEST.cc
Collision_TEST.cc
Console_TEST.cc
Conversions_TEST.cc
Cylinder_TEST.cc
Element_TEST.cc
Ellipsoid_TEST.cc
Expand All @@ -116,7 +137,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 @@ -166,6 +186,14 @@ if (BUILD_SDF_TEST)
)
endif()

if (TARGET UNIT_Conversions_TEST)
# Link the libraries that we always need.
target_link_libraries("UNIT_Conversions_TEST"
PUBLIC
ignition-common${IGN_COMMON_VER}::graphics
)
endif()

if (NOT WIN32)
set(SDF_BUILD_TESTS_EXTRA_EXE_SRCS Utils.cc)
sdf_build_tests(Utils_TEST.cc)
Expand All @@ -191,33 +219,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 +261,11 @@ 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}
ignition-common${IGN_COMMON_VER}::graphics
${PYTHON_LIBRARY}
${PXR_LIBRARIES}
CGAL::CGAL
PRIVATE
${TinyXML2_LIBRARIES})

Expand All @@ -237,6 +277,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
145 changes: 145 additions & 0 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright 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 "sdf/Conversions.hh"

#include <ignition/common/Pbr.hh>
#include <sdf/Pbr.hh>

namespace sdf
{
inline namespace SDF_VERSION_NAMESPACE {

sdf::Material convert(const ignition::common::Material &_in)
{
sdf::Material out;
out.SetEmissive(_in.Emissive());
out.SetDiffuse(_in.Diffuse());
out.SetSpecular(_in.Specular());
out.SetAmbient(_in.Ambient());
out.SetRenderOrder(_in.RenderOrder());
out.SetLighting(_in.Lighting());
out.SetDoubleSided(_in.TwoSidedEnabled());
ignition::common::Pbr * pbr = _in.PbrMaterial();
if (pbr != nullptr)
{
out.SetNormalMap(pbr->NormalMap());
sdf::Pbr pbrOut;
sdf::PbrWorkflow pbrWorkflow;
pbrWorkflow.SetAlbedoMap(pbr->AlbedoMap());
pbrWorkflow.SetMetalnessMap(pbr->MetalnessMap());
pbrWorkflow.SetEmissiveMap(pbr->EmissiveMap());
pbrWorkflow.SetRoughnessMap(pbr->RoughnessMap());

pbrWorkflow.SetEnvironmentMap(pbr->EnvironmentMap());
pbrWorkflow.SetAmbientOcclusionMap(pbr->AmbientOcclusionMap());
pbrWorkflow.SetLightMap(pbr->LightMap());

if (pbr->NormalMapType() == ignition::common::NormalMapSpace::TANGENT)
{
pbrWorkflow.SetNormalMap(
pbr->NormalMap(), sdf::NormalMapSpace::TANGENT);
}
else
{
pbrWorkflow.SetNormalMap(
pbr->NormalMap(), sdf::NormalMapSpace::OBJECT);
}

pbrWorkflow.SetRoughness(pbr->Roughness());
pbrWorkflow.SetGlossiness(pbr->Glossiness());
pbrWorkflow.SetMetalness(pbr->Metalness());

if (pbr->Type() == ignition::common::PbrType::METAL)
{
pbrOut.SetWorkflow(sdf::PbrWorkflowType::METAL, pbrWorkflow);
}
else if (pbr->Type() == ignition::common::PbrType::SPECULAR)
{
pbrOut.SetWorkflow(sdf::PbrWorkflowType::SPECULAR, pbrWorkflow);
}
out.SetPbrMaterial(pbrOut);
}

return out;
}

std::shared_ptr<ignition::common::Material> convertMaterial(sdf::Material &_in)
{
std::shared_ptr<ignition::common::Material> out =
std::make_shared<ignition::common::Material>();
out->SetEmissive(_in.Emissive());
out->SetEmissive(_in.Emissive());
out->SetDiffuse(_in.Diffuse());
out->SetSpecular(_in.Specular());
out->SetAmbient(_in.Ambient());
out->SetRenderOrder(_in.RenderOrder());
out->SetLighting(_in.Lighting());
// TODO(ahcorde): Review this
// out->SetTwoSidedEnabled(_in.DoubleSided());

const sdf::Pbr * pbr = _in.PbrMaterial();
if (pbr != nullptr)
{
ignition::common::Pbr pbrOut;

const sdf::PbrWorkflow * pbrWorkflow =
pbr->Workflow(sdf::PbrWorkflowType::METAL);
if (pbrWorkflow)
{
pbrOut.SetType(ignition::common::PbrType::METAL);
}
else
{
pbrWorkflow = pbr->Workflow(sdf::PbrWorkflowType::SPECULAR);
if (pbrWorkflow)
{
pbrOut.SetType(ignition::common::PbrType::SPECULAR);
}
}
if (pbrWorkflow != nullptr)
{
pbrOut.SetAlbedoMap(pbrWorkflow->AlbedoMap());
pbrOut.SetMetalnessMap(pbrWorkflow->MetalnessMap());
pbrOut.SetEmissiveMap(pbrWorkflow->EmissiveMap());
pbrOut.SetRoughnessMap(pbrWorkflow->RoughnessMap());
pbrOut.SetEnvironmentMap(pbrWorkflow->EnvironmentMap());
pbrOut.SetAmbientOcclusionMap(pbrWorkflow->AmbientOcclusionMap());
pbrOut.SetLightMap(pbrWorkflow->LightMap());
pbrOut.SetRoughness(pbrWorkflow->Roughness());
pbrOut.SetGlossiness(pbrWorkflow->Glossiness());
pbrOut.SetMetalness(pbrWorkflow->Metalness());

if (pbrWorkflow->NormalMapType() == sdf::NormalMapSpace::TANGENT)
{
pbrOut.SetNormalMap(
pbrWorkflow->NormalMap(),
ignition::common::NormalMapSpace::TANGENT);
}
else if(pbrWorkflow->NormalMapType() == sdf::NormalMapSpace::OBJECT)
{
pbrOut.SetNormalMap(
pbrWorkflow->NormalMap(),
ignition::common::NormalMapSpace::OBJECT);
}
}
out->SetPbrMaterial(pbrOut);
}
return out;
}
}
}
Loading