-
Notifications
You must be signed in to change notification settings - Fork 100
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
USD to SDF converter #736
Changes from 3 commits
04ac451
fec7541
9ce073f
787e8f5
5115f44
d4cb4cc
9b73015
a74ee34
fe2ddb0
ce46639
8fc9666
ac61126
d127881
163637a
09eea1f
c344a55
5bd5c7b
0c629c2
58ac549
1e9890b
304d27c
e11a18e
83f86ab
aa1333d
f2e88dd
4deb2bc
1c4ba22
d2fd2a8
d82cf39
bfd8d08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
#include "Utils.hh" | ||
#include "parser_private.hh" | ||
#include "parser_urdf.hh" | ||
#include "parser_usd.hh" | ||
|
||
namespace sdf | ||
{ | ||
|
@@ -713,6 +714,25 @@ bool readFileInternal(const std::string &_filename, const bool _convert, | |
return false; | ||
} | ||
|
||
if (USD2SDF::IsUSD(filename)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
#include "sdf/sdf.hh" | ||
#include "parser_urdf.hh" | ||
#include "./parser_usd.hh" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
There was a problem hiding this comment.
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 thancommon::split
? I'd avoid adding a dependency if we don't need it. We already havesdf::split
that provides the same functionality.