Skip to content

Commit 866ba4f

Browse files
committed
Merge remote-tracking branch 'origin/ahcorde/usd_to_sdf_physics' into ahcorde/usd_to_sdf_transforms
2 parents 576f9bd + 460d693 commit 866ba4f

12 files changed

+122
-53
lines changed

usd/include/sdf/usd/usd_parser/ParseUSD.hh usd/include/sdf/usd/usd_parser/Parser.hh

+10-11
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,31 @@
1515
*
1616
*/
1717

18-
#ifndef SDF_USD_USD_PARSER_PARSE_USD_HH
19-
#define SDF_USD_USD_PARSER_PARSE_USD_HH
18+
#ifndef SDF_USD_USD_PARSER_PARSER_HH
19+
#define SDF_USD_USD_PARSER_PARSER_HH
2020

2121
#include <string>
2222

23-
#include "sdf/sdf_config.h"
24-
#include "sdf/system_util.hh"
23+
#include "sdf/config.hh"
2524
#include "sdf/usd/Export.hh"
2625
#include "sdf/usd/UsdError.hh"
2726

2827
namespace sdf
2928
{
30-
// Inline bracke to help doxygen filtering.
29+
// Inline bracket to help doxygen filtering.
3130
inline namespace SDF_VERSION_NAMESPACE {
3231
//
3332
namespace usd
3433
{
35-
/// \brief It parses a USD file and it converted to SDF
36-
/// \param[in] _inputFilename Path of the USD file to parse
37-
/// \param[in] _outputFilename_sdf Path where the SDF file will be located
34+
/// \brief Parse a USD file and convert it to a SDF file
35+
/// \param[in] _inputFilenameUsd Path of the USD file to parse
36+
/// \param[in] _outputFilenameSdf Path where the SDF file will be located
3837
/// \return UsdErrors, which is a vector of UsdError objects. Each UsdError
3938
/// includes an error code and message. An empty vector indicates no error
40-
/// occurred when parsing to its SDF representation.
39+
/// occurred when parsing the USD file to its SDF representation.
4140
UsdErrors IGNITION_SDFORMAT_USD_VISIBLE parseUSDFile(
42-
const std::string &_inputFilename,
43-
const std::string &_outputFilename_sdf);
41+
const std::string &_inputFilenameUsd,
42+
const std::string &_outputFilenameSdf);
4443
}
4544
}
4645
}

usd/src/CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ set(sources
1010
sdf_parser/Sensor.cc
1111
sdf_parser/Visual.cc
1212
sdf_parser/World.cc
13-
usd_parser/ParseUSD.cc
14-
usd_parser/Physics.cc
15-
usd_parser/USD.cc
13+
usd_parser/Parser.cc
1614
usd_parser/USD2SDF.cc
1715
usd_parser/USDData.cc
1816
usd_parser/USDMaterial.cc
17+
usd_parser/USDPhysics.cc
1918
usd_parser/USDStage.cc
2019
usd_parser/USDTransforms.cc
20+
usd_parser/USDWorld.cc
2121
)
2222

2323
ign_add_component(usd SOURCES ${sources} GET_TARGET_NAME usd_target)
@@ -46,6 +46,7 @@ set(gtest_sources
4646
sdf_parser/Visual_Sdf2Usd_TEST.cc
4747
sdf_parser/World_Sdf2Usd_TEST.cc
4848
usd_parser/USDData_TEST.cc
49+
usd_parser/USDPhysics_TEST.cc
4950
usd_parser/USDStage_TEST.cc
5051
usd_parser/USDTransforms_TEST.cc
5152
Conversions_TEST.cc

usd/src/cmd/usd2sdf.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*
1616
*/
1717

18-
#include <string.h>
18+
#include <string>
1919

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

22-
#include "sdf/usd/usd_parser/ParseUSD.hh"
23-
#include "sdf/sdf.hh"
22+
#include "sdf/usd/usd_parser/Parser.hh"
23+
#include "sdf/config.hh"
2424

2525
//////////////////////////////////////////////////
2626
/// \brief Enumeration of available commands

usd/src/usd_parser/ParseUSD.cc usd/src/usd_parser/Parser.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
#include "sdf/usd/usd_parser/ParseUSD.hh"
18+
#include "sdf/usd/usd_parser/Parser.hh"
1919
#include "USD2SDF.hh"
2020

2121
namespace sdf
@@ -24,18 +24,19 @@ inline namespace SDF_VERSION_NAMESPACE {
2424
namespace usd
2525
{
2626
UsdErrors parseUSDFile(
27-
const std::string &_inputFilename, const std::string &_outputFilename)
27+
const std::string &_inputFilenameUsd,
28+
const std::string &_outputFilenameSdf)
2829
{
2930
UsdErrors errors;
3031
USD2SDF usd2sdf;
3132
auto doc = tinyxml2::XMLDocument(true, tinyxml2::COLLAPSE_WHITESPACE);
32-
auto readErrors = usd2sdf.Read(_inputFilename, &doc);
33+
auto readErrors = usd2sdf.Read(_inputFilenameUsd, &doc);
3334
if (!readErrors.empty())
3435
{
3536
errors.insert(errors.end(), readErrors.begin(), readErrors.end());
3637
return errors;
3738
}
38-
doc.SaveFile(_outputFilename.c_str());
39+
doc.SaveFile(_outputFilenameSdf.c_str());
3940
return errors;
4041
}
4142
}

usd/src/usd_parser/USD2SDF.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
#include "usd_model/WorldInterface.hh"
2121

22-
#include "USD.hh"
22+
#include "USDWorld.hh"
2323

2424
namespace sdf {
25+
inline namespace SDF_VERSION_NAMESPACE {
2526
namespace usd {
2627
/////////////////////////////////////////////////
2728
USD2SDF::USD2SDF()
@@ -59,7 +60,7 @@ UsdErrors USD2SDF::Read(const std::string &_filename,
5960
sdf->SetAttribute("version", "1.7");
6061

6162
world = _sdfXmlOut->NewElement("world");
62-
std::string worldName = worldInterface->_worldName;
63+
std::string worldName = worldInterface->worldName;
6364
if (worldName.empty())
6465
{
6566
worldName = "world_name";
@@ -143,3 +144,4 @@ std::string USD2SDF::Vector32Str(const ignition::math::Vector3d _vector)
143144
}
144145
}
145146
}
147+
}

usd/src/usd_parser/Physics.cc usd/src/usd_parser/USDPhysics.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
#include "Physics.hh"
18+
#include "USDPhysics.hh"
1919

2020
#pragma push_macro ("__DEPRECATED")
2121
#undef __DEPRECATED
@@ -30,7 +30,7 @@ namespace sdf
3030
inline namespace SDF_VERSION_NAMESPACE {
3131
namespace usd
3232
{
33-
void ParsePhysicsScene(
33+
void ParseUSDPhysicsScene(
3434
const pxr::UsdPrim &_prim,
3535
std::shared_ptr<WorldInterface> &_world,
3636
double _metersPerUnit)

usd/src/usd_parser/Physics.hh usd/src/usd_parser/USDPhysics.hh

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#include <pxr/usd/usd/primRange.h>
2626
#pragma pop_macro ("__DEPRECATED")
2727

28-
#include <sdf/sdf_config.h>
28+
#include "sdf/config.hh"
29+
#include "sdf/usd/Export.hh"
2930

3031
namespace sdf
3132
{
@@ -38,7 +39,7 @@ namespace sdf
3839
/// \param[in] _prim Prim to extract the physics attributes
3940
/// \param[out] _world World interface where the data is placed
4041
/// \param[in] _metersPerUnit meter per unit in the USD
41-
void ParsePhysicsScene(
42+
void IGNITION_SDFORMAT_USD_VISIBLE ParseUSDPhysicsScene(
4243
const pxr::UsdPrim &_prim,
4344
std::shared_ptr<WorldInterface> &_world,
4445
double _metersPerUnit);

usd/src/usd_parser/USDPhysics_TEST.cc

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2022 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#include <gtest/gtest.h>
19+
20+
#include <memory>
21+
#include <string>
22+
23+
// TODO(ahcorde):this is to remove deprecated "warnings" in usd, these warnings
24+
// are reported using #pragma message so normal diagnostic flags cannot remove
25+
// them. This workaround requires this block to be used whenever usd is
26+
// included.
27+
#pragma push_macro ("__DEPRECATED")
28+
#undef __DEPRECATED
29+
#include <pxr/usd/usd/prim.h>
30+
#include <pxr/usd/usd/stage.h>
31+
#pragma pop_macro ("__DEPRECATED")
32+
33+
#include "test_config.h"
34+
#include "test_utils.hh"
35+
36+
#include "USDPhysics.hh"
37+
#include "usd_model/WorldInterface.hh"
38+
39+
/////////////////////////////////////////////////
40+
TEST(USDLightsTest, DistanceLight)
41+
{
42+
std::string filename = sdf::testing::TestFile("usd", "upAxisZ.usda");
43+
auto stage = pxr::UsdStage::Open(filename);
44+
ASSERT_TRUE(stage);
45+
46+
pxr::UsdPrim prim = stage->GetPrimAtPath(pxr::SdfPath("/shapes/physics"));
47+
48+
std::shared_ptr<sdf::usd::WorldInterface> worldInterface =
49+
std::make_shared<sdf::usd::WorldInterface>();
50+
51+
double metersPerUnit = 1.0;
52+
53+
sdf::usd::ParseUSDPhysicsScene(
54+
prim, worldInterface, metersPerUnit);
55+
EXPECT_EQ(ignition::math::Vector3d(0, 0, -1), worldInterface->gravity);
56+
EXPECT_NEAR(9.8, worldInterface->magnitude, 0.0001);
57+
}

usd/src/usd_parser/USD.cc usd/src/usd_parser/USDWorld.cc

+23-16
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,60 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
#include "USD.hh"
17+
#include "USDWorld.hh"
1818

19-
#include "sdf/usd/usd_parser/USDData.hh"
20-
#include "sdf/usd/usd_parser/USDStage.hh"
21-
#include "Physics.hh"
19+
#include <string>
2220

2321
#pragma push_macro ("__DEPRECATED")
2422
#undef __DEPRECATED
2523
#include <pxr/usd/usdPhysics/scene.h>
2624
#pragma pop_macro ("__DEPRECATED")
2725

28-
#include <string>
26+
#include "sdf/usd/usd_parser/USDData.hh"
27+
#include "sdf/usd/usd_parser/USDStage.hh"
28+
#include "USDPhysics.hh"
2929

3030
namespace sdf
3131
{
3232
inline namespace SDF_VERSION_NAMESPACE {
3333
namespace usd
3434
{
35-
UsdErrors parseUSDWorld(
36-
const std::string &_inputFilename,
35+
UsdErrors parseUSDWorld(const std::string &_inputFileName,
3736
std::shared_ptr<WorldInterface> &_world)
3837
{
3938
UsdErrors errors;
40-
USDData usdData(_inputFilename);
39+
USDData usdData(_inputFileName);
4140
usdData.Init();
4241
usdData.ParseMaterials();
4342

44-
auto referencee = pxr::UsdStage::Open(_inputFilename);
45-
if (!referencee)
43+
auto reference = pxr::UsdStage::Open(_inputFileName);
44+
if (!reference)
4645
{
4746
errors.emplace_back(UsdError(
4847
UsdErrorCode::INVALID_USD_FILE,
49-
"Unable to open [" + _inputFilename + "]"));
48+
"Unable to open [" + _inputFileName + "]"));
5049
return errors;
5150
}
52-
auto range = pxr::UsdPrimRange::Stage(referencee);
53-
54-
_world->_worldName = referencee->GetDefaultPrim().GetName().GetText();
51+
_world->worldName = reference->GetDefaultPrim().GetName().GetText();
5552

53+
auto range = pxr::UsdPrimRange::Stage(reference);
5654
for (auto const &prim : range)
5755
{
56+
std::string primName = prim.GetName();
57+
5858
if (prim.IsA<pxr::UsdPhysicsScene>())
5959
{
6060
std::pair<std::string, std::shared_ptr<USDStage>> data =
61-
usdData.FindStage(prim.GetPath().GetName());
61+
usdData.FindStage(primName);
62+
if (!data.second)
63+
{
64+
errors.push_back(UsdError(UsdErrorCode::INVALID_PRIM_PATH,
65+
"Unable to retrieve the pxr::UsdPhysicsScene named ["
66+
+ primName + "]"));
67+
return errors;
68+
}
6269

63-
ParsePhysicsScene(prim, _world, data.second->MetersPerUnit());
70+
ParseUSDPhysicsScene(prim, _world, data.second->MetersPerUnit());
6471
continue;
6572
}
6673
}

usd/src/usd_parser/USD.hh usd/src/usd_parser/USDWorld.hh

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*
1616
*/
1717

18-
#ifndef USD_PARSER_USD_HH
19-
#define USD_PARSER_USD_HH
18+
#ifndef USD_PARSER_USDWORLD_HH
19+
#define USD_PARSER_USDWORLD_HH
2020

2121
#include <string>
2222

@@ -27,19 +27,19 @@
2727

2828
namespace sdf
2929
{
30-
// Inline bracke to help doxygen filtering.
30+
// Inline bracket to help doxygen filtering.
3131
inline namespace SDF_VERSION_NAMESPACE {
3232
//
3333
namespace usd
3434
{
35-
/// \brief it parses the USD file
36-
/// \param[in] _inputFilename Path where the USD is located
37-
/// \param[out] _world World interface where all USD data is placed
35+
/// \brief Parse the world information of a USD file
36+
/// \param[in] _inputFileNameUsd Path where the USD is located
37+
/// \param[out] _world World interface where all USD world data is placed
3838
/// \return UsdErrors, which is a vector of UsdError objects. Each UsdError
3939
/// includes an error code and message. An empty vector indicates no error
40-
/// occurred when parsing to its SDF representation.
40+
/// occurred when parsing the world information of _inputFileNameUsd
4141
UsdErrors parseUSDWorld(
42-
const std::string &_inputFilename,
42+
const std::string &_inputFileNameUsd,
4343
std::shared_ptr<WorldInterface> &_world);
4444
}
4545
}

usd/src/usd_parser/usd2sdf_TEST.cc

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <ignition/common/Filesystem.hh>
2222
#include <ignition/common/TempDirectory.hh>
23+
2324
#include <ignition/utilities/ExtraTestMacros.hh>
2425

2526
#include "test_config.h"

usd/src/usd_parser/usd_model/WorldInterface.hh

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace sdf
3838
class WorldInterface {
3939
public:
4040
/// \brief World name
41-
std::string _worldName;
41+
std::string worldName;
4242

4343
/// \brief Magnitude of the gravity
4444
float magnitude;
@@ -49,7 +49,7 @@ namespace sdf
4949
friend std::ostream& operator<<(
5050
std::ostream& os, const WorldInterface& _world)
5151
{
52-
os << "World name: " << _world._worldName;
52+
os << "World name: " << _world.worldName;
5353
os << "Gravity: " << _world.gravity * _world.magnitude << "\n";
5454
return os;
5555
}

0 commit comments

Comments
 (0)