Skip to content

Commit 1902c16

Browse files
authored
USD to SDF: some fixes (#991)
Signed-off-by: ahcorde <ahcorde@gmail.com>
1 parent a593db2 commit 1902c16

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

test/usd/upAxisZ.usda

+15-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def Xform "box" (
102102
double3 xformOp:translate = (0, 0, 0)
103103
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ"]
104104

105-
def Cube "geometry"
105+
def Cube "geometry" (
106+
kind = "model"
107+
)
106108
{
107109
float3[] extent = [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)]
108110
rel material:binding = </Looks/Material_1>
@@ -159,7 +161,9 @@ def Xform "cylinder"
159161
double3 xformOp:translate = (0, 0, 0)
160162
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ"]
161163

162-
def Cylinder "geometry"
164+
def Cylinder "geometry" (
165+
kind = "model"
166+
)
163167
{
164168
float3[] extent = [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)]
165169
double height = 1
@@ -202,7 +206,9 @@ def Xform "sphere"
202206
double3 xformOp:translate = (0, 0, 0)
203207
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ"]
204208

205-
def Sphere "geometry"
209+
def Sphere "geometry" (
210+
kind = "model"
211+
)
206212
{
207213
float3[] extent = [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)]
208214
rel material:binding = </Looks/Material_3>
@@ -243,7 +249,9 @@ def Xform "capsule"
243249
double3 xformOp:translate = (0, 0, 0)
244250
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateZYX"]
245251

246-
def Capsule "geometry"
252+
def Capsule "geometry" (
253+
kind = "model"
254+
)
247255
{
248256
float3[] extent = [(-0.2, -0.2, -0.5), (0.2, 0.2, 0.5)]
249257
double height = 0.6
@@ -286,7 +294,9 @@ def Xform "ellipsoid"
286294
double3 xformOp:translate = (0, 0, 0)
287295
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ"]
288296

289-
def Sphere "geometry"
297+
def Sphere "geometry" (
298+
kind = "model"
299+
)
290300
{
291301
float3[] extent = [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)]
292302
rel material:binding = </Looks/Material_5>

usd/src/usd_parser/USDLinks.cc

+30-10
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ int ParseMeshSubGeom(const pxr::UsdPrim &_prim,
233233

234234
ignition::common::SubMesh subMeshSubset;
235235
subMeshSubset.SetPrimitiveType(ignition::common::SubMesh::TRISTRIPS);
236-
subMeshSubset.SetName("subgeommesh");
236+
subMeshSubset.SetName("subgeommesh_" + std::to_string(numSubMeshes));
237237

238238
if (it != _usdData.Materials().end())
239239
{
@@ -288,12 +288,18 @@ int ParseMeshSubGeom(const pxr::UsdPrim &_prim,
288288
_meshGeom.SetUri(directoryMesh + ".dae");
289289

290290
geomSubset.SetMeshShape(_meshGeom);
291-
visSubset.SetName("mesh_subset");
291+
visSubset.SetName("mesh_subset_" + std::to_string(numSubMeshes));
292292
visSubset.SetGeom(geomSubset);
293293

294294
ignition::math::Pose3d pose;
295295
ignition::math::Vector3d scale(1, 1, 1);
296-
GetTransform(child, _usdData, pose, scale, _link->Name());
296+
std::string linkName = pxr::TfStringify(_prim.GetPath());
297+
auto found = linkName.find(_link->Name());
298+
if (found != std::string::npos)
299+
{
300+
linkName = linkName.substr(0, found + _link->Name().size());
301+
}
302+
GetTransform(child, _usdData, pose, scale, linkName);
297303
_scale *= scale;
298304
visSubset.SetRawPose(pose);
299305
_link->AddVisual(visSubset);
@@ -386,15 +392,21 @@ UsdErrors ParseMesh(
386392

387393
ignition::math::Pose3d pose;
388394
ignition::math::Vector3d scale(1, 1, 1);
389-
std::string linkName = _link->Name();
395+
std::string linkName = pxr::TfStringify(_prim.GetPath());
396+
auto found = linkName.find(_link->Name());
397+
if (found != std::string::npos)
398+
{
399+
linkName = linkName.substr(0, found + _link->Name().size());
400+
}
401+
390402
size_t nSlash = std::count(linkName.begin(), linkName.end(), '/');
391403
if (nSlash == 1)
392404
{
393405
GetTransform(_prim, _usdData, pose, scale, "/");
394406
}
395407
else
396408
{
397-
GetTransform(_prim, _usdData, pose, scale, _link->Name());
409+
GetTransform(_prim, _usdData, pose, scale, linkName);
398410
}
399411

400412
_pose = pose;
@@ -522,7 +534,7 @@ void ParseCylinder(
522534
_geom.SetType(sdf::GeometryType::CYLINDER);
523535

524536
c.SetRadius(radius * _metersPerUnit * _scale.X());
525-
c.SetLength(height * _metersPerUnit * _scale.Y());
537+
c.SetLength(height * _metersPerUnit * _scale.Z());
526538

527539
_geom.SetCylinderShape(c);
528540
}
@@ -632,9 +644,9 @@ UsdErrors ParseUSDLinks(
632644
pxr::UsdModelAPI(parent).GetKind(&kindOfSchema);
633645
}
634646

635-
if (_prim.HasAPI<pxr::UsdPhysicsRigidBodyAPI>()
636-
|| pxr::KindRegistry::IsA(kindOfSchema, pxr::KindTokens->model)
637-
|| !collisionEnabled)
647+
if ((_prim.HasAPI<pxr::UsdPhysicsRigidBodyAPI>()
648+
|| pxr::KindRegistry::IsA(kindOfSchema, pxr::KindTokens->model))
649+
&& (!collisionEnabled || _prim.HasAPI<pxr::UsdPhysicsMassAPI>()))
638650
{
639651
double metersPerUnit = data.second->MetersPerUnit();
640652

@@ -696,7 +708,15 @@ UsdErrors ParseUSDLinks(
696708

697709
ignition::math::Pose3d poseCol;
698710
ignition::math::Vector3d scaleCol(1, 1, 1);
699-
GetTransform(_prim, _usdData, poseCol, scaleCol, _link->Name());
711+
std::string linkName = pxr::TfStringify(_prim.GetPath());
712+
auto found = linkName.find(_link->Name());
713+
if (found != std::string::npos)
714+
{
715+
linkName = linkName.substr(0, found + _link->Name().size());
716+
}
717+
GetTransform(_prim, _usdData, poseCol, scaleCol, linkName);
718+
719+
scaleCol *= _scale;
700720

701721
double metersPerUnit = data.second->MetersPerUnit();
702722

usd/src/usd_parser/USDWorld.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ namespace usd
351351
}
352352

353353
std::optional<sdf::Link> optionalLink;
354-
if (auto linkInserted = modelPtr->LinkByName(linkName))
354+
if (auto linkInserted =
355+
modelPtr->LinkByName(ignition::common::basename(linkName)))
355356
{
356357
optionalLink = *linkInserted;
357358
auto scale = linkScaleMap.find(linkName);
@@ -362,6 +363,8 @@ namespace usd
362363
}
363364
sdf::usd::ParseUSDLinks(
364365
prim, linkName, optionalLink, usdData, scale->second);
366+
*linkInserted = optionalLink.value();
367+
linkScaleMap[linkName] = scale->second;
365368
}
366369
else
367370
{

0 commit comments

Comments
 (0)