From a905f0c4eb4c156429d48d50c96fe5e1f847359a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Wed, 23 Mar 2022 12:41:55 +0100 Subject: [PATCH 1/2] USD to SDF: Returned errors in USDWorld (#896) Signed-off-by: ahcorde --- usd/src/usd_parser/USDMaterial.cc | 12 ++++++++---- usd/src/usd_parser/USDWorld.cc | 8 ++++++-- usd/src/usd_parser/usd2sdf_TEST.cc | 5 +++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/usd/src/usd_parser/USDMaterial.cc b/usd/src/usd_parser/USDMaterial.cc index 9a63b34f2..3b8933e25 100644 --- a/usd/src/usd_parser/USDMaterial.cc +++ b/usd/src/usd_parser/USDMaterial.cc @@ -144,7 +144,8 @@ namespace sdf assetPath(pxr::TfToken("diffuse_texture"), variantShader); pbrWorkflow.SetAlbedoMap(materialPath.GetAssetPath()); std::string fullAlbedoName = - ignition::common::findFile(materialPath.GetAssetPath()); + ignition::common::findFile(ignition::common::basename( + materialPath.GetAssetPath())); UsdErrors errorCopy = copyFile( fullAlbedoName, materialPath.GetAssetPath()); if (!errorCopy.empty()) @@ -160,7 +161,8 @@ namespace sdf assetPath(pxr::TfToken("normalmap_texture"), variantShader); pbrWorkflow.SetNormalMap(materialPath.GetAssetPath()); std::string fullNormalName = - ignition::common::findFile(materialPath.GetAssetPath()); + ignition::common::findFile(ignition::common::basename( + materialPath.GetAssetPath())); auto errorCopy = copyFile(fullNormalName, materialPath.GetAssetPath()); if (!errorCopy.empty()) @@ -176,7 +178,8 @@ namespace sdf pxr::TfToken("reflectionroughness_texture"), variantShader); pbrWorkflow.SetRoughnessMap(materialPath.GetAssetPath()); std::string fullRoughnessName = - ignition::common::findFile(materialPath.GetAssetPath()); + ignition::common::findFile(ignition::common::basename( + materialPath.GetAssetPath())); auto errorCopy = copyFile( fullRoughnessName, materialPath.GetAssetPath()); if (!errorCopy.empty()) @@ -192,7 +195,8 @@ namespace sdf pxr::TfToken("metallic_texture"), variantShader); pbrWorkflow.SetMetalnessMap(materialPath.GetAssetPath()); std::string fullMetalnessName = - ignition::common::findFile(materialPath.GetAssetPath()); + ignition::common::findFile(ignition::common::basename( + materialPath.GetAssetPath())); auto errorCopy = copyFile( fullMetalnessName, materialPath.GetAssetPath()); if (!errorCopy.empty()) diff --git a/usd/src/usd_parser/USDWorld.cc b/usd/src/usd_parser/USDWorld.cc index 5c1ee6b03..1d3992e8e 100644 --- a/usd/src/usd_parser/USDWorld.cc +++ b/usd/src/usd_parser/USDWorld.cc @@ -42,8 +42,12 @@ namespace usd { UsdErrors errors; USDData usdData(_inputFileName); - usdData.Init(); - usdData.ParseMaterials(); + errors = usdData.Init(); + if (!errors.empty()) + return errors; + errors = usdData.ParseMaterials(); + if (!errors.empty()) + return errors; auto reference = pxr::UsdStage::Open(_inputFileName); if (!reference) diff --git a/usd/src/usd_parser/usd2sdf_TEST.cc b/usd/src/usd_parser/usd2sdf_TEST.cc index fc73df3a1..7339ea238 100644 --- a/usd/src/usd_parser/usd2sdf_TEST.cc +++ b/usd/src/usd_parser/usd2sdf_TEST.cc @@ -20,6 +20,7 @@ #include #include +#include #include @@ -74,6 +75,10 @@ TEST(check_cmd, IGN_UTILS_TEST_DISABLED_ON_WIN32(SDF)) { const auto tmp = ignition::common::createTempDirectory("usd", ignition::common::tempDirectoryPath()); + + auto systemPaths = ignition::common::systemPaths(); + systemPaths->AddFilePaths(ignition::common::joinPaths( + sdf::testing::TestFile("usd"), "materials", "textures")); // Check a good SDF file { const std::string path = sdf::testing::TestFile("usd", "upAxisZ.usda"); From 425985f6d893e20ff1968f3106089ccbd1e09b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Wed, 23 Mar 2022 15:58:21 +0100 Subject: [PATCH 2/2] USD to SDF: Apply rigid body to Model not to Link (#889) Signed-off-by: ahcorde --- usd/src/UsdTestUtils.hh | 1 - usd/src/sdf_parser/Link.cc | 7 ++++--- usd/src/sdf_parser/Link_Sdf2Usd_TEST.cc | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/usd/src/UsdTestUtils.hh b/usd/src/UsdTestUtils.hh index d9156277d..7a8e07af0 100644 --- a/usd/src/UsdTestUtils.hh +++ b/usd/src/UsdTestUtils.hh @@ -224,7 +224,6 @@ void CheckInertial(const pxr::UsdPrim &_usdPrim, } EXPECT_TRUE(checkedCOM); - EXPECT_EQ(_isRigid, _usdPrim.HasAPI()); EXPECT_EQ(_isRigid, _usdPrim.HasAPI()); } } // namespace testing diff --git a/usd/src/sdf_parser/Link.cc b/usd/src/sdf_parser/Link.cc index 973cd5bf1..12e68d7f5 100644 --- a/usd/src/sdf_parser/Link.cc +++ b/usd/src/sdf_parser/Link.cc @@ -85,11 +85,12 @@ namespace usd return errors; } - if (!pxr::UsdPhysicsRigidBodyAPI::Apply(linkPrim)) + if (!pxr::UsdPhysicsRigidBodyAPI::Apply(linkPrim.GetParent())) { errors.push_back(UsdError(sdf::usd::UsdErrorCode::FAILED_PRIM_API_APPLY, - "Internal error: unable to mark link at path [" + _path - + "] as a rigid body, so mass properties won't be attached")); + "Internal error: unable to mark model at path [" + + linkPrim.GetParent().GetPath().GetString() + "] as a rigid body, " + "so mass properties won't be attached")); return errors; } diff --git a/usd/src/sdf_parser/Link_Sdf2Usd_TEST.cc b/usd/src/sdf_parser/Link_Sdf2Usd_TEST.cc index 2d0d995cb..b939553d4 100644 --- a/usd/src/sdf_parser/Link_Sdf2Usd_TEST.cc +++ b/usd/src/sdf_parser/Link_Sdf2Usd_TEST.cc @@ -82,6 +82,7 @@ TEST_F(UsdStageFixture, Link) std::string groundPlanePath = worldPath + "/" + "ground_plane"; auto groundPlane = this->stage->GetPrimAtPath(pxr::SdfPath(groundPlanePath)); ASSERT_TRUE(groundPlane); + EXPECT_FALSE(groundPlane.HasAPI()); sdf::usd::testing::CheckPrimPose(groundPlane, ignition::math::Pose3d( ignition::math::Vector3d(0, 0, -0.125), @@ -98,6 +99,7 @@ TEST_F(UsdStageFixture, Link) std::string boxPath = worldPath + "/" + "box"; auto box = this->stage->GetPrimAtPath(pxr::SdfPath(boxPath)); ASSERT_TRUE(box); + EXPECT_TRUE(box.HasAPI()); sdf::usd::testing::CheckPrimPose(box, ignition::math::Pose3d( ignition::math::Vector3d(0, 0, 2.5), @@ -116,6 +118,7 @@ TEST_F(UsdStageFixture, Link) std::string cylinderPath = worldPath + "/" + "cylinder"; auto cylinder = this->stage->GetPrimAtPath(pxr::SdfPath(cylinderPath)); ASSERT_TRUE(cylinder); + EXPECT_TRUE(cylinder.HasAPI()); sdf::usd::testing::CheckPrimPose(cylinder, ignition::math::Pose3d( ignition::math::Vector3d(2, 0, 2.5), @@ -135,6 +138,7 @@ TEST_F(UsdStageFixture, Link) std::string spherePath = worldPath + "/" + "sphere"; auto sphere = this->stage->GetPrimAtPath(pxr::SdfPath(spherePath)); ASSERT_TRUE(sphere); + EXPECT_TRUE(sphere.HasAPI()); sdf::usd::testing::CheckPrimPose(sphere, ignition::math::Pose3d( ignition::math::Vector3d(4, 0, 2.5), @@ -153,6 +157,7 @@ TEST_F(UsdStageFixture, Link) std::string capsulePath = worldPath + "/" + "capsule"; auto capsule = this->stage->GetPrimAtPath(pxr::SdfPath(capsulePath)); ASSERT_TRUE(capsule); + EXPECT_TRUE(capsule.HasAPI()); sdf::usd::testing::CheckPrimPose(capsule, ignition::math::Pose3d( ignition::math::Vector3d(6, 0, 2.5), @@ -171,6 +176,7 @@ TEST_F(UsdStageFixture, Link) std::string meshPath = worldPath + "/" + "mesh"; auto mesh = this->stage->GetPrimAtPath(pxr::SdfPath(meshPath)); ASSERT_TRUE(mesh); + EXPECT_TRUE(mesh.HasAPI()); sdf::usd::testing::CheckPrimPose(mesh, ignition::math::Pose3d( ignition::math::Vector3d(8, 0, 2.5),