Skip to content
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

Add sdf -> usd light functionality to usd component #818

Merged
merged 30 commits into from
Jan 25, 2022

Conversation

adlarkin
Copy link
Contributor

@adlarkin adlarkin commented Jan 8, 2022

Signed-off-by: Ashton Larkin [email protected]

🎉 New feature

Summary

This builds on top of #817 to add light converting functionality from SDF to USD.

There are a few things that may need to be addressed, but they aren't blocking the core functionality (I left some TODO notes in the code to highlight things we might want to address). I think we can start to review this PR now, and then re-visit the TODOs later when time permits to add enhanced functionality. Perhaps we should create an issue that lists what enhanced functionality is missing from the USD -> SDF creator?

I also think we can close #796 because the only test in that PR is for lights, which has been moved to this PR (we will need to address #796 (review), which is also a potential issue with the tests that are written in #817).

Test it

You can run the unit test that has been added in this PR (Light_Sdf2Usd_TEST), or you can try converting https://github.com/ignitionrobotics/ign-gazebo/blob/ign-gazebo6/examples/worlds/lights.sdf to a USD file with the sdf2usd executable that's generated in #817 (this assumes you have PXR installed and have built the usd component of sdformat).

If you want to see how the light intensities look in isaac sim, you'll need to add an object to the lights.sdf file above in order to have the lights reflect off of something. You can add the following code to usd/src/World.cc, which adds a ground plane to the world:

diff --git a/usd/src/World.cc b/usd/src/World.cc
index a3aaa138..90bb81f7 100644
--- a/usd/src/World.cc
+++ b/usd/src/World.cc
@@ -30,6 +30,16 @@
 #include "sdf/World.hh"
 #include "sdf/usd/Light.hh"
 
+// includes needed for creating a plane
+#include <pxr/usd/usdGeom/xform.h>
+#include <ignition/math/Vector3.hh>
+#include <ignition/math/Pose3.hh>
+#include <pxr/usd/usdGeom/cube.h>
+#include <pxr/base/gf/vec3f.h>
+#include <pxr/base/vt/array.h>
+#include <pxr/usd/usdGeom/xformCommonAPI.h>
+#include "sdf/usd/Utils.hh"
+
 namespace usd
 {
   bool ParseSdfWorld(const sdf::World &_world, pxr::UsdStageRefPtr &_stage,
@@ -69,6 +79,23 @@ namespace usd
               << "the moment. Models that are children of the world "
               << "are currently being ignored.\n";
 
+    // temporarily adding ground plane in order to test light intensities
+    const pxr::SdfPath sdfModelPath(_path + "/plane");
+    auto usdModelXform = pxr::UsdGeomXform::Define(_stage, sdfModelPath);
+    ignition::math::Vector3d planePosition(0, 0, -0.25);
+    usd::SetPose(ignition::math::Pose3d(planePosition,
+          ignition::math::Quaterniond::Identity), _stage, sdfModelPath);
+    const pxr::SdfPath geomPath(_path + "/plane/geom");
+    auto usdCube = pxr::UsdGeomCube::Define(_stage, pxr::SdfPath(geomPath));
+    usdCube.CreateSizeAttr().Set(1.0);
+    pxr::GfVec3f endPoint(0.5);
+    pxr::VtArray<pxr::GfVec3f> extentBounds;
+    extentBounds.push_back(-1.0 * endPoint);
+    extentBounds.push_back(endPoint);
+    usdCube.CreateExtentAttr().Set(extentBounds);
+    pxr::UsdGeomXformCommonAPI cubeXformAPI(usdCube);
+    cubeXformAPI.SetScale(pxr::GfVec3f(10, 10, 0.5));
+
     return true;
   }
 }

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 and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2022

Codecov Report

Merging #818 (8073b07) into sdf12 (3151bd8) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##            sdf12     #818   +/-   ##
=======================================
  Coverage   90.70%   90.70%           
=======================================
  Files          78       78           
  Lines       12438    12438           
=======================================
  Hits        11282    11282           
  Misses       1156     1156           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3151bd8...8073b07. Read the comment docs.

@adlarkin adlarkin marked this pull request as ready for review January 12, 2022 01:53
Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

LGTM, I'm not going to merge this PR yet, I'm waiting to get a review in the targeted branch

Copy link

@koonpeng koonpeng left a comment

Choose a reason for hiding this comment

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

LGTM, just some minor comments.

usd/src/Light.cc Outdated Show resolved Hide resolved
usd/src/UsdTestUtils.hh Outdated Show resolved Hide resolved
Base automatically changed from ahcorde/sdf_to_usd_cmake to sdf12 January 24, 2022 21:29
@adlarkin adlarkin force-pushed the adlarkin/add_lights_to_usd_cmake branch from cea02cc to d14dc37 Compare January 24, 2022 23:21
@adlarkin
Copy link
Contributor Author

I've updated this PR to match the USD component files that currently exist in the sdf12 branch (from #817). If CI comes back green, I believe that this is ready to be merged.

@ahcorde ahcorde merged commit 57edaf7 into sdf12 Jan 25, 2022
@ahcorde ahcorde deleted the adlarkin/add_lights_to_usd_cmake branch January 25, 2022 09:08
@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/new-ignition-releases-2022-04-13-fortress-edifice/1367/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants