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

sdf -> usd: Added Visual and geometries #829

Merged
merged 21 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9dfc9f2
sdf -> usd Parse links
ahcorde Jan 25, 2022
ffaf2f4
sdf -> usd: Added Visual and geometries
ahcorde Jan 26, 2022
0a5a9a7
Fixed test
ahcorde Jan 26, 2022
89daa0d
review feedback
adlarkin Jan 27, 2022
f48b35b
dont segfault when mesh failed to load
Jan 31, 2022
d932e90
fix error reporting
Jan 31, 2022
54b35e9
Merge branch 'sdf12' into ahcorde/sdf_to_usd_links
ahcorde Feb 1, 2022
f0331ca
Fixed scale and submesh name
ahcorde Feb 10, 2022
e85f60c
Merge remote-tracking branch 'origin/sdf12' into ahcorde/sdf_to_usd_l…
ahcorde Feb 14, 2022
a02a6e1
Use UsdError
ahcorde Feb 14, 2022
f898d26
codecheck, use USD component's visibility macro, properly construct w…
adlarkin Feb 14, 2022
258606c
Merge branch 'ahcorde/sdf_to_usd_links' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 15, 2022
c43ba24
usd UsdErrors and USD component visibility
adlarkin Feb 15, 2022
f816dd4
Merge branch 'sdf12' into ahcorde/sdf_to_usd_links
adlarkin Feb 15, 2022
6f3490e
Merge branch 'ahcorde/sdf_to_usd_links' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 15, 2022
379defd
review feedback
adlarkin Feb 17, 2022
0f4075f
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 18, 2022
a98d481
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 18, 2022
0cb1cc0
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
ahcorde Feb 18, 2022
00a55c5
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
ahcorde Feb 21, 2022
0d483a7
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
ahcorde Feb 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
143 changes: 143 additions & 0 deletions test/sdf/basic_shapes.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?xml version="1.0" ?>
<sdf version="1.8">
<world name="shapes_world">
<model name="ground_plane">
<static>true</static>
<link name="link">
<collision name="collision">
<geometry>
<plane>
<normal>0 0 1</normal>
<size>1.4 6.3</size>
</plane>
</geometry>
</collision>

<visual name="visual">
<geometry>
<plane>
<normal>0 0 1</normal>
<size>2 4</size>
</plane>
</geometry>
</visual>
</link>
</model>

<model name="box">
<pose relative_to="ground_plane">0 0 2.5 0 0 0</pose>
<link name="link">
<collision name="collision">
<geometry>
<box>
<size>1 2 3</size>
</box>
</geometry>
<surface>
<contact>
<collide_bitmask>0xAB</collide_bitmask>
</contact>
</surface>
</collision>

<visual name="box_vis">
<geometry>
<box>
<size>1 2 3</size>
</box>
</geometry>
</visual>
</link>
</model>

<model name="cylinder">
<pose relative_to="box">2 0 0 0 0 0</pose>
<link name="link">
<collision name="collision">
<geometry>
<cylinder>
<radius>0.2</radius>
<length>0.1</length>
</cylinder>
</geometry>
</collision>

<visual name="visual">
<geometry>
<cylinder>
<radius>0.2</radius>
<length>0.1</length>
</cylinder>
</geometry>
</visual>
</link>
</model>

<model name="sphere">
<pose relative_to="cylinder">2 0 0 0 0 0</pose>
<link name="link">
<collision name="collision">
<geometry>
<sphere>
<radius>1.23</radius>
</sphere>
</geometry>
</collision>

<visual name="sphere_vis">
<geometry>
<sphere>
<radius>1.23</radius>
</sphere>
</geometry>
</visual>
</link>
</model>

<model name="capsule">
<pose relative_to="sphere">2 0 0 0 0 0</pose>
<link name="link">
<collision name="collision">
<geometry>
<capsule>
<radius>0.2</radius>
<length>0.1</length>
</capsule>
</geometry>
</collision>

<visual name="visual">
<geometry>
<capsule>
<radius>0.2</radius>
<length>0.1</length>
</capsule>
</geometry>
</visual>
</link>
</model>

<model name="mesh">
<pose relative_to="capsule">2 0 0 0 0 0</pose>
<link name="link">
<collision name="collision">
<geometry>
<mesh>
<uri>file://box.dae</uri>
<scale>0.1 0.2 0.3</scale>
</mesh>
</geometry>
</collision>

<visual name="visual">
<geometry>
<mesh>
<uri>file://box.dae</uri>
<scale>1.2 2.3 3.4</scale>
</mesh>
</geometry>
</visual>
</link>
</model>
</world>
</sdf>
98 changes: 98 additions & 0 deletions test/sdf/box.dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_effects>
<effect id="Material-effect">
<profile_COMMON>
<technique sid="common">
<phong>
<emission>
<color sid="emission">0 0 0 1</color>
</emission>
<ambient>
<color sid="ambient">0 0 0 1</color>
</ambient>
<diffuse>
<color sid="diffuse">0.64 0.64 0.64 1</color>
</diffuse>
<specular>
<color sid="specular">0.5 0.5 0.5 1</color>
</specular>
<shininess>
<float sid="shininess">50</float>
</shininess>
<transparent opaque="A_ONE">
<color>1 1 1 1</color>
</transparent>
<transparency>
<float>1</float>
</transparency>
<index_of_refraction>
<float sid="index_of_refraction">1</float>
</index_of_refraction>
</phong>
</technique>
</profile_COMMON>
</effect>
</library_effects>
<library_materials>
<material id="Material-material" name="Material-material">
<instance_effect url="#Material-effect"/>
</material>
</library_materials>
<library_geometries>
<geometry id="Cube-mesh" name="Cube">
<mesh>
<source id="Cube-mesh-positions">
<float_array id="Cube-mesh-positions-array" count="24">1 1 -1 1 -1 -1 -1 -0.9999998 -1 -0.9999997 1 -1 1 0.9999995 1 0.9999994 -1.000001 1 -1 -0.9999997 1 -1 1 1</float_array>
<technique_common>
<accessor source="#Cube-mesh-positions-array" count="8" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube-mesh-normals">
<float_array id="Cube-mesh-normals-array" count="18">0 0 -1 0 0 1 1 -2.83122e-7 0 -2.83122e-7 -1 0 -1 2.23517e-7 -1.3411e-7 2.38419e-7 1 2.08616e-7</float_array>
<technique_common>
<accessor source="#Cube-mesh-normals-array" count="6" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cube-mesh-vertices">
<input semantic="POSITION" source="#Cube-mesh-positions"/>
</vertices>
<polylist material="Material-material" count="6">
<input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/>
<vcount>4 4 4 4 4 4 </vcount>
<p>0 0 1 0 2 0 3 0 4 1 7 1 6 1 5 1 0 2 4 2 5 2 1 2 1 3 5 3 6 3 2 3 2 4 6 4 7 4 3 4 4 5 0 5 3 5 7 5</p>
</polylist>
</mesh>
<extra><technique profile="MAYA"><double_sided>1</double_sided></technique></extra>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Cube" name="Cube" type="NODE">
<instance_geometry url="#Cube-mesh">
<bind_material>
<technique_common>
<instance_material symbol="Material-material" target="#Material-material"/>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>
9 changes: 9 additions & 0 deletions usd/include/sdf/usd/UsdError.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ namespace sdf

/// \brief A pxr API was not able to be applied to a USD prim.
FAILED_PRIM_API_APPLY,

/// \brief Attempt to define a USD prim or prim schema failed.
FAILED_USD_DEFINITION,

/// \brief Failure to load a mesh and/or submesh
MESH_LOAD_FAILURE,

/// \brief Invalid submesh primitive type
INVALID_SUBMESH_PRIMITIVE_TYPE,
};

class IGNITION_SDFORMAT_USD_VISIBLE UsdError
Expand Down
59 changes: 59 additions & 0 deletions usd/include/sdf/usd/sdf_parser/Geometry.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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_SDF_PARSER_GEOMETRY_HH_
#define SDF_USD_SDF_PARSER_GEOMETRY_HH_

#include <string>

// TODO(adlarkin) this is to remove deprecated "warnings" in usd, these warnings
// are reported using #pragma message so normal diagnostic flags cannot remove
// them. This workaround requires this block to be used whenever usd is
// included.
#pragma push_macro ("__DEPRECATED")
#undef __DEPRECATED
#include <pxr/usd/usd/stage.h>
#pragma pop_macro ("__DEPRECATED")

#include "sdf/Geometry.hh"
#include "sdf/config.hh"
#include "sdf/usd/Export.hh"
#include "sdf/usd/UsdError.hh"

namespace sdf
{
// Inline bracke to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//
namespace usd
{
/// \brief Parse an SDF geometry into a USD stage.
/// \param[in] _geometry The SDF geometry to parse.
/// \param[in] _stage The stage that should contain the USD representation
/// of _geometry.
/// \param[in] _path The USD path of the parsed geometry in _stage, which
/// must be a valid USD path.
/// \return UsdErrors, which is a vector of UsdError objects. Each UsdError
/// includes an error code and message. An empty vector indicates no error.
UsdErrors IGNITION_SDFORMAT_USD_VISIBLE ParseSdfGeometry(
const sdf::Geometry &_geometry, pxr::UsdStageRefPtr &_stage,
const std::string &_path);
}
}
}

#endif
2 changes: 1 addition & 1 deletion usd/include/sdf/usd/sdf_parser/Light.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace sdf
/// of _light.
/// \param[in] _path The USD path of the parsed light in _stage, which must
/// be a valid USD path.
/// \return UsdErrors, which is a vector of Error objects. Each Error
/// \return UsdErrors, which is a vector of UsdError objects. Each UsdError
/// includes an error code and message. An empty vector indicates no error.
UsdErrors IGNITION_SDFORMAT_USD_VISIBLE ParseSdfLight(
const sdf::Light &_light,
Expand Down
62 changes: 62 additions & 0 deletions usd/include/sdf/usd/sdf_parser/Link.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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_SDF_PARSER_LINK_HH_
#define SDF_USD_SDF_PARSER_LINK_HH_

#include <string>

// TODO(ahcorde) this is to remove deprecated "warnings" in usd, these warnings
// are reported using #pragma message so normal diagnostic flags cannot remove
// them. This workaround requires this block to be used whenever usd is
// included.
#pragma push_macro ("__DEPRECATED")
#undef __DEPRECATED
#include <pxr/usd/usd/stage.h>
#pragma pop_macro ("__DEPRECATED")

#include "sdf/Link.hh"
#include "sdf/usd/Export.hh"
#include "sdf/usd/UsdError.hh"
#include "sdf/sdf_config.h"

namespace sdf
{
// Inline bracke to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//
namespace usd
{
/// \brief Parse an SDF link into a USD stage.
/// \param[in] _link The SDF link to parse.
/// \param[in] _stage The stage that should contain the USD representation
/// of _link. This must be a valid, initialized stage.
/// \param[in] _path The USD path of the parsed link in _stage, which must
/// be a valid USD path.
/// \param[in] _rigidBody Whether the link is a rigid body (i.e.,
/// non-static) or not. True for rigid body, false otherwise
/// \return UsdErrors, which is a vector of UsdError objects. Each UsdError
/// includes an error code and message. An empty vector indicates no errors
/// occurred when parsing _link to its USD representation.
UsdErrors IGNITION_SDFORMAT_USD_VISIBLE ParseSdfLink(const sdf::Link &_link,
pxr::UsdStageRefPtr &_stage, const std::string &_path,
bool _rigidBody);
}
}
}

#endif
Loading