Added materials to SDF to USD converter#770
Conversation
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
d3813d3 to
5e3f5fe
Compare
There was a problem hiding this comment.
When I test this PR on this world, the materials appear to be properly created, bu I don't see any colors on the simple shapes when I run usdview (see image below). Is there something else I need to do to view the materials?
|
I was not able to visualize textures with By the way, |
Signed-off-by: ahcorde <ahcorde@gmail.com>
Is this something that we will need to address later on?
I tried the extinguisher model in isaac sim, and it looks like I can see the materials for simple shapes, but not the mesh: Here's how things look in |
071cef6 to
c291638
Compare
…e/sdf_to_usd/materials
…e/sdf_to_usd/materials
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
… PRs Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
c016c78 to
794309d
Compare
…e/sdf_to_usd/materials
…itionrobotics/sdformat into ahcorde/sdf_to_usd/materials
Signed-off-by: ahcorde <ahcorde@gmail.com>
| return ignition::common::joinPaths( | ||
| "materials", | ||
| "textures", | ||
| ignition::common::basename(_uri)); |
There was a problem hiding this comment.
It looks like the resulting path from this call is being used as a path in the USD file. USD paths use / as the delimiter, so instead of using ignition::common::joinPaths here, I think we should do string concatenation with a / delimiter. The reason why I say this is because if a user called this method on windows, they would have a delimiter of \\ instead of /, which wouldn't be recognized by USD.
There was a problem hiding this comment.
sdf (not sdformat) has a path system as well, maybe we should use SdfPath's concatenation?
| for (unsigned int i = 0; i < ignMesh->SubMeshCount(); ++i) | ||
| { | ||
| auto subMesh = ignMesh->SubMeshByIndex(i).lock(); | ||
| if (!subMesh) | ||
|
|
||
| if (ignMesh->SubMeshCount() != 1) | ||
| { | ||
| std::cerr << "Unable to get a shared pointer to submesh at index [" | ||
| << i << "] of parent mesh [" << ignMesh->Name() << "]\n"; | ||
| return false; | ||
| std::string pathLowerCase = ignition::common::lowercase(_path); | ||
| std::string subMeshLowerCase = ignition::common::lowercase(subMesh->Name()); | ||
|
|
||
| if (pathLowerCase.find(subMeshLowerCase) != std::string::npos) | ||
| { | ||
| isNameInPath = true; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
What is the purpose of the isNameInPath check? I'm having a hard time understanding it.
Also, it looks like the isNameInPath check is occurring for every submesh. So, the result of isNameInPath after the loop says whether the last submesh's name is in the path or not, but says nothing about the previous submeshes. Is this the intended behavior?
| std::string type = ignition::common::lowercase(tokens[3]); | ||
| std::string modelName = ignition::common::lowercase(tokens[4]); | ||
| path = ignition::common::joinPaths( | ||
| home, ".ignition", "fuel", server, owner, type, modelName); |
There was a problem hiding this comment.
Is there a more standard way to get the fuel path that does not require us to hardcode a fixed path?
There was a problem hiding this comment.
humm, we can add a enviroment variable, how does it sound ?
| { | ||
| std::cerr << "Internal error: unable to mark link at path [" | ||
| << _path << "] as a rigid body\n"; | ||
| std::cerr << "Internal error: unable to mark link at path [" << _path |
There was a problem hiding this comment.
Should this, and other std:cerr use ignerr instead?
| if (ignMesh->SubMeshCount() != 1 && isNameInPath) | ||
| { | ||
| std::string pathLowerCase = ignition::common::lowercase(_path); | ||
| std::string subMeshLowerCase = ignition::common::lowercase(subMesh->Name()); | ||
|
|
||
| if (pathLowerCase.find(subMeshLowerCase) == std::string::npos) | ||
| { | ||
| continue; | ||
| } | ||
| } |
There was a problem hiding this comment.
This block is already inside a if (isNameInPath), so the 2nd condition here seems redundant. I'm also having a hard time understanding the purpose of this in combination with the isNameInPath check above.
| } | ||
| else | ||
| { | ||
| auto usdXformMesh = pxr::UsdGeomXform::Define(_stage, pxr::SdfPath(_path)); |
There was a problem hiding this comment.
This block here duplicates many of the code in the if block, I think it should be possible to refactor them to keep things DRY.
| return ignition::common::joinPaths( | ||
| "materials", | ||
| "textures", | ||
| ignition::common::basename(_uri)); |
There was a problem hiding this comment.
sdf (not sdformat) has a path system as well, maybe we should use SdfPath's concatenation?
| if (!_displayName.GetString().empty()) | ||
| { | ||
| attr.SetDisplayName(_displayName); | ||
| } | ||
| if (!_displayGroup.GetString().empty()) | ||
| { | ||
| attr.SetDisplayGroup(_displayGroup); | ||
| } | ||
| if (!_doc.empty()) | ||
| { | ||
| attr.SetDocumentation(_doc); | ||
| } | ||
| if (!_colorSpace.GetString().empty()) |
There was a problem hiding this comment.
These seems to take in a string, why does the function params require these to be TfToken? Also the return value is not checked for errors.
| // with the names of the materials | ||
| static int i = 0; | ||
|
|
||
| const std::string mtl_path = "/Looks/Material_" + std::to_string(i); |
There was a problem hiding this comment.
Is it possible to build the path based on the model/link/visual/material hierarchy?
…e/sdf_to_usd/materials
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
…e/sdf_to_usd/materials
Signed-off-by: ahcorde <ahcorde@gmail.com>



Signed-off-by: ahcorde ahcorde@gmail.com
🎉 New feature
Summary
Added materials to SDF to USD converter. For now I tried this model https://app.ignitionrobotics.org/chapulina/fuel/models/Extinguisher%20PBR
Test it
Checklist
codecheckpassed (See contributing)Note to maintainers: Remember to use Squash-Merge