-
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
Conversation
Signed-off-by: Alejandro Hernández <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Of all the parts of cc @azeey |
cmake/SearchForStuff.cmake
Outdated
######################################## | ||
# Find ignition common | ||
# Set a variable for generating ProjectConfig.cmake | ||
find_package(ignition-common4 4.0 QUIET) |
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 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.
I agree with @scpeters about |
Another possibility is keeping USD support in a separate component within this codebase. The advantage would be giving it more visibility, tighter maintenance, and maybe setting the standard for adding other converters in the future. My concern with a separate repository is that unless we make it a first-class Ignition library, it may just go unmaintained very quickly (similar to ign-rndf). |
sdformat doesn't use |
If this is something that we think would be valuable, it would be a good excuse to update SDFormat to use |
I'm very new to the ignition build system so I might be totally off, does a separate component means declaring it with |
I've taken an initial step towards this in gazebosim/gz-cmake#190, which is awaiting review |
There is an aspect that is more significant than whether the code produces a library or executable, which is to define a cmake component for packaging purposes. See for instance the discussion of the |
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
It looks like Is this a mistake, or does |
On a somewhat related note, it looks like Do we need to wait until the next |
libsdformat depends on ignition-cmake2 but isn't an ignition-cmake project that uses the cmake macros like ign_configure_project and ign_configure_build. Until recently, it only depended on ignition-cmake2 indirectly via ignition-math6, although it now uses |
that comment is wrong; this code is still needed. |
I made a PR that removes this comment in #740
Before we go ahead and make changes to |
If we want to perpetually support conversion between SDFormat and USD, I think there are advantages to keeping this code in the same repository. Since it requires additional dependencies, I think adding it in a separate component would be appropriate. If we wanted to put this code in a separate repository, I think that would be a valid choice as well; it would just take a bit more effort to keep the code synchronized and manage version differences. It would also make it easier to limit our commitment to support of the USD format, for better or worse. |
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
src/usd/usd_parser/polygon_helper.cc
Outdated
fit != triangulation.finite_facets_end(); ++fit) | ||
{ | ||
auto &face = fit; | ||
if (face->first->vertex(0)->info() > maxIndex || |
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.
maxIndex
is not defined.
|
||
///////////////////////////////////////////////// | ||
/// Main | ||
int main(int argc, char **argv) |
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.
This shouldn't be needed if you link to gtest_main
.
{ | ||
auto opt = std::make_shared<Options>(); | ||
|
||
_app.add_option("-i,--input", |
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.
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.
@@ -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 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?
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 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?
{ | ||
std::cerr << "UsdPhysicsMassAPI " << pxr::TfStringify(_prim.GetPath()) << '\n'; | ||
if (pxr::UsdAttribute massAttribute = | ||
_prim.GetAttribute(pxr::TfToken("physics:mass"))) |
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.
Could we use pxr::UsdPhysicsMassApi
to avoid hard coded tokens?
if (mass < 0.0001) | ||
{ | ||
mass = 0.1; | ||
} |
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.
whats the reason for having a minimal mass?
_world->gravity[0] = gravity[0]; | ||
_world->gravity[1] = gravity[1]; | ||
_world->gravity[2] = gravity[2]; |
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.
Do we need to account for up axis?
sdf::Camera camera; | ||
|
||
auto variantCamera = pxr::UsdGeomCamera(_prim); | ||
float horizontalAperture = 20.955; |
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.
What is this value based off from?
{ | ||
pxr::SdfAssetPath materialPath; | ||
pxr::UsdShadeInput diffuseTextureShaderInput = | ||
variantshader.GetInput(pxr::TfToken("diffuse_texture")); |
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 there a doc explaining the available tokens?
TODO
|
Signed-off-by: Ashton Larkin <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
I've added the |
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.
This PR is really large and doesn't have documentation, so it's hard to review all at once. Once #817 is merged, would you mind refactoring this PR to match the component structure? Then, we can break it up into smaller PRs and review the smaller PRs, like what we're doing for SDF -> USD conversion.
if (tokens.size() > 1) | ||
{ | ||
bool shortName = false; | ||
if (tokens.size() == 2) | ||
{ | ||
if (prim.IsA<pxr::UsdGeomGprim>() || | ||
(std::string(prim.GetPrimTypeInfo().GetTypeName().GetText()) == "Plane")) | ||
{ | ||
if (prim.GetPath().GetName() != "imu") | ||
{ | ||
baseLink = "/" + tokens[0]; | ||
shortName = true; | ||
// exit(-1); | ||
} | ||
} | ||
} | ||
if(!shortName) | ||
{ | ||
baseLink = "/" + tokens[0] + "/" + tokens[1]; | ||
} | ||
} |
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.
it looks like this code block can be deleted, because tokens.size() > 1
is already being checked in the above if
statement: https://github.com/ignitionrobotics/sdformat/blob/58ac549f454601bcf1f58917965c64d93617f527/src/usd/usd_parser/parser_usd.cc#L183
if (pxr::TfStringify(parent.GetPath()) == _name) | ||
{ | ||
return; | ||
} |
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.
This check can be removed, because it's comparing the prim's path (which has a /
) with the prim's name (which does not have a /
).
* polygon triangulation using the fan-triangulation algorithm Signed-off-by: Teo Koon Peng <[email protected]> * remove cgal dep Signed-off-by: Teo Koon Peng <[email protected]> * add todo Signed-off-by: Teo Koon Peng <[email protected]> * fix xformOp:transform parsing (#822) Signed-off-by: Teo Koon Peng <[email protected]> Co-authored-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
* fix y up Signed-off-by: Teo Koon Peng <[email protected]> * cleanup Signed-off-by: Teo Koon Peng <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Closing this PR in favour of this metaticket #866 |
🎉 New feature
Summary
FYI @adlarkin @koonpeng . Feel free to push code, cleanups or suggestions
This draft PR creates a prototype to convert USD files into SDF files.
For now I already tested with
simple_articulated.usd
andur10.usd
.Regarding joints there are two fields
physics:body0
andphysics:body1
that indicate the parent and child of the joint, but in usd format there is no distinction between them. We need to rework this part a little bit more. I have to modifyur10.usda
to set parent asbody1
and child asbody0
. No changes are required in thesimple_articulated.usd
file.The current implementation supports:
Code need a huge refactor. We can probably use some ignition library such as ignition-common or ignition-math in the
usd_parser
folders because I copy-paste the code from urdf. There are object likeSphere
, poses, Vectors quaternions, links and many other that I'm pretty sure that we can use something from these libraries.Test it
-DPXR_ENABLE_PYTHON_SUPPORT=0
usdcat
: It allows to convertusd
(binary format) intousda
(human redeable format). `usdcat binary.usa > output.usdausdview
. It allows to visualizeusd
filessdfconverter
which allows to convert aurdf
orusd
files in tosdf
. it's simple to use:sdfconverter -i <input> -o <ouput>
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge