Skip to content

Added materials to SDF to USD converter#770

Merged
ahcorde merged 22 commits intoadlarkin/sdf_to_usdfrom
ahcorde/sdf_to_usd/materials
Jan 6, 2022
Merged

Added materials to SDF to USD converter#770
ahcorde merged 22 commits intoadlarkin/sdf_to_usdfrom
ahcorde/sdf_to_usd/materials

Conversation

@ahcorde
Copy link
Copy Markdown
Collaborator

@ahcorde ahcorde commented Dec 2, 2021

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

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde requested a review from adlarkin December 2, 2021 23:32
@ahcorde ahcorde self-assigned this Dec 2, 2021
Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
@adlarkin adlarkin force-pushed the ahcorde/sdf_to_usd/materials branch from d3813d3 to 5e3f5fe Compare December 3, 2021 02:02
Copy link
Copy Markdown
Contributor

@adlarkin adlarkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

no_colors

Comment thread src/usd/sdf_usd_parser/material.cc Outdated
Comment thread src/usd/sdf_usd_parser/material.cc Outdated
Comment thread src/usd/sdf_usd_parser/material.cc Outdated
Comment thread src/usd/sdf_usd_parser/material.cc Outdated
Comment thread src/usd/sdf_usd_parser/material.cc Outdated
Comment thread src/usd/sdf_usd_parser/material.cc
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde
Copy link
Copy Markdown
Collaborator Author

ahcorde commented Dec 3, 2021

I was not able to visualize textures with usdview I tried with IssacSim.

By the way, duck.dae contains the material inside the collada file and this will not generate a material (I believe). Can you try with this other model Extinguisher PBR ?

Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde requested a review from adlarkin December 3, 2021 14:41
@adlarkin
Copy link
Copy Markdown
Contributor

adlarkin commented Dec 3, 2021

By the way, duck.dae contains the material inside the collada file and this will not generate a material (I believe)

Is this something that we will need to address later on?

I tried with IssacSim ... Can you try with this other model Extinguisher PBR ?

I tried the extinguisher model in isaac sim, and it looks like I can see the materials for simple shapes, but not the mesh:

no_mesh_material

Here's how things look in ign-gazebo (I moved the extinguisher to the other side of the simple shapes so that it's easier to see):

mesh_material_gazebo

@adlarkin adlarkin force-pushed the adlarkin/sdf_to_usd branch from 071cef6 to c291638 Compare December 3, 2021 22:31
… PRs

Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
@adlarkin adlarkin force-pushed the ahcorde/sdf_to_usd/materials branch from c016c78 to 794309d Compare December 18, 2021 02:09
@adlarkin
Copy link
Copy Markdown
Contributor

@ahcorde since we are still iterating on materials, I have broken out a few things from this PR in 794309d into separate PRs so that we can get them merged now. Would you mind taking a look at the following PRs?

ahcorde and others added 4 commits December 20, 2021 12:59
Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@adlarkin adlarkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to clean a few things up in f0f0885. @ahcorde, would you mind pulling this commit and testing it to make sure I didn't break anything?

I also have a few more comments/questions for you below

Comment thread src/Conversions.cc Outdated
Comment thread src/usd/sdf_usd_parser/visual.cc Outdated
Comment thread src/cmd/usdConverter.cc Outdated
Comment thread src/cmd/usdConverter.cc
Comment thread src/cmd/usdConverter.cc Outdated
Comment thread src/usd/sdf_usd_parser/material.cc
Comment on lines +57 to +60
return ignition::common::joinPaths(
"materials",
"textures",
ignition::common::basename(_uri));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdf (not sdformat) has a path system as well, maybe we should use SdfPath's concatenation?

Comment thread src/usd/sdf_usd_parser/material.cc Outdated
Comment thread src/usd/sdf_usd_parser/material.cc Outdated
Comment on lines 138 to +152
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;
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@chapulina chapulina added the 🌱 garden Ignition Garden label Dec 30, 2021
Comment thread src/cmd/usdConverter.cc
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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more standard way to get the fuel path that does not require us to hardcode a fixed path?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this, and other std:cerr use ignerr instead?

Comment thread src/usd/sdf_usd_parser/geometry.cc Outdated
Comment on lines +172 to +181
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;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/usd/sdf_usd_parser/geometry.cc Outdated
Comment thread src/usd/sdf_usd_parser/geometry.cc Outdated
}
else
{
auto usdXformMesh = pxr::UsdGeomXform::Define(_stage, pxr::SdfPath(_path));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +57 to +60
return ignition::common::joinPaths(
"materials",
"textures",
ignition::common::basename(_uri));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdf (not sdformat) has a path system as well, maybe we should use SdfPath's concatenation?

Comment thread src/usd/sdf_usd_parser/material.cc
Comment on lines +107 to +119
if (!_displayName.GetString().empty())
{
attr.SetDisplayName(_displayName);
}
if (!_displayGroup.GetString().empty())
{
attr.SetDisplayGroup(_displayGroup);
}
if (!_doc.empty())
{
attr.SetDocumentation(_doc);
}
if (!_colorSpace.GetString().empty())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to build the path based on the model/link/visual/material hierarchy?

Comment thread src/usd/sdf_usd_parser/material.cc Outdated
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde requested review from adlarkin and koonpeng January 4, 2022 18:26
Comment thread src/usd/sdf_usd_parser/geometry.cc
Comment thread src/usd/sdf_usd_parser/sensor.cc
Comment thread src/usd/sdf_usd_parser/light.cc
Comment thread src/usd/sdf_usd_parser/utils.hh
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde merged commit 4e0b9c9 into adlarkin/sdf_to_usd Jan 6, 2022
@ahcorde ahcorde deleted the ahcorde/sdf_to_usd/materials branch January 6, 2022 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌱 garden Ignition Garden

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants