Skip to content

Commit

Permalink
Mesh conversion: define intermediate prim as Scope (#32)
Browse files Browse the repository at this point in the history
When converting parsing a mesh from SDFormat, an extra
level of USD hierarchy is added with the mesh name. To
ensure all prims have a type, define the intermediate
prim type as a Scope, as recommended by a USD expert.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
(cherry picked from commit 178e136)
  • Loading branch information
scpeters authored and mergify[bot] committed Oct 3, 2024
1 parent 0cd76ee commit 7fd1a29
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sdf_parser/Geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <pxr/usd/usdGeom/primvarsAPI.h>
#include <pxr/usd/usdGeom/primvar.h>
#include <pxr/usd/usdGeom/mesh.h>
#include <pxr/usd/usdGeom/scope.h>
#include <pxr/usd/usdGeom/sphere.h>
#include <pxr/usd/usdGeom/xform.h>
#include <pxr/usd/usdGeom/xformCommonAPI.h>
Expand Down Expand Up @@ -355,6 +356,19 @@ namespace usd
for (unsigned int n = 0; n < numFaces; ++n)
faceVertexCounts.push_back(verticesPerFace);

// The other geometry types in this file create a prim at _path,
// but in order to store the mesh name in USD, an additional level
// is added to the USD hierarchy with the mesh name.
// To ensure that the prim at _path has a type, define it as a Scope.
auto usdScope = pxr::UsdGeomScope::Define(_stage, pxr::SdfPath(_path));
if (!usdScope)
{
errors.push_back(UsdError(
gz::usd::UsdErrorCode::FAILED_USD_DEFINITION,
"Unable to define a USD geometry scope at path [" + _path + "]"));
return errors;
}

std::string primName;
if (!subMesh->Name().empty())
primName = _path + "/" + subMesh->Name();
Expand Down

0 comments on commit 7fd1a29

Please sign in to comment.