49
49
#include < ignition/math/Inertial.hh>
50
50
51
51
#include " sdf/Box.hh"
52
+ #include " sdf/Collision.hh"
52
53
#include " sdf/Cylinder.hh"
53
54
#include " sdf/Geometry.hh"
54
55
#include " sdf/Link.hh"
@@ -309,6 +310,7 @@ int ParseMeshSubGeom(const pxr::UsdPrim &_prim,
309
310
// / \param[in] _geom sdf geom
310
311
// / \param[in] _scale scale mesh
311
312
// / \param[in] _usdData metadata of the USD file
313
+ // / \param[out] _pose The pose of the parsed mesh
312
314
// / \return UsdErrors, which is a list of UsdError objects. An empty list means
313
315
// / that no errors occurred when parsing the USD mesh
314
316
UsdErrors ParseMesh (
@@ -317,7 +319,8 @@ UsdErrors ParseMesh(
317
319
sdf::Visual &_vis,
318
320
sdf::Geometry &_geom,
319
321
ignition::math::Vector3d &_scale,
320
- const USDData &_usdData)
322
+ const USDData &_usdData,
323
+ ignition::math::Pose3d &_pose)
321
324
{
322
325
UsdErrors errors;
323
326
@@ -393,6 +396,9 @@ UsdErrors ParseMesh(
393
396
{
394
397
GetTransform (_prim, _usdData, pose, scale, _link->Name ());
395
398
}
399
+
400
+ _pose = pose;
401
+
396
402
meshGeom.SetScale (scale * _scale);
397
403
398
404
std::string primName = pxr::TfStringify (_prim.GetPath ());
@@ -633,39 +639,119 @@ UsdErrors ParseUSDLinks(
633
639
double metersPerUnit = data.second ->MetersPerUnit ();
634
640
635
641
if (_prim.IsA <pxr::UsdGeomSphere>())
642
+ {
643
+ ParseSphere (_prim, geom, _scale, metersPerUnit);
644
+ vis.SetName (" visual_sphere" );
645
+ vis.SetGeom (geom);
646
+ _link->AddVisual (vis);
647
+ }
648
+ else if (_prim.IsA <pxr::UsdGeomCylinder>())
649
+ {
650
+ ParseCylinder (_prim, geom, _scale, metersPerUnit);
651
+ vis.SetName (" visual_cylinder" );
652
+ vis.SetGeom (geom);
653
+ _link->AddVisual (vis);
654
+ }
655
+ else if (_prim.IsA <pxr::UsdGeomCube>())
656
+ {
657
+ ParseCube (_prim, geom, _scale, metersPerUnit);
658
+ vis.SetName (" visual_box" );
659
+ vis.SetGeom (geom);
660
+ _link->AddVisual (vis);
661
+ }
662
+ else if (_prim.IsA <pxr::UsdGeomMesh>())
663
+ {
664
+ ignition::math::Pose3d poseTmp;
665
+ errors = ParseMesh (
666
+ _prim, &_link.value (), vis, geom, _scale, _usdData, poseTmp);
667
+ if (!errors.empty ())
636
668
{
637
- ParseSphere (_prim, geom, _scale, metersPerUnit);
638
- vis.SetName (" visual_sphere" );
639
- vis.SetGeom (geom);
640
- _link->AddVisual (vis);
641
- }
642
- else if (_prim.IsA <pxr::UsdGeomCylinder>())
643
- {
644
- ParseCylinder (_prim, geom, _scale, metersPerUnit);
645
- vis.SetName (" visual_cylinder" );
646
- vis.SetGeom (geom);
647
- _link->AddVisual (vis);
648
- }
649
- else if (_prim.IsA <pxr::UsdGeomCube>())
650
- {
651
- ParseCube (_prim, geom, _scale, metersPerUnit);
652
- vis.SetName (" visual_box" );
653
- vis.SetGeom (geom);
654
- _link->AddVisual (vis);
669
+ errors.emplace_back (UsdError (
670
+ sdf::usd::UsdErrorCode::SDF_TO_USD_PARSING_ERROR,
671
+ " Error parsing mesh" ));
672
+ return errors;
655
673
}
656
- else if (_prim.IsA <pxr::UsdGeomMesh>())
674
+ }
675
+ }
676
+
677
+ pxr::TfTokenVector schemasCollision = _prim.GetAppliedSchemas ();
678
+ bool physxCollisionAPIenable = false ;
679
+ for (const auto & token : schemasCollision)
680
+ {
681
+ if (std::string (token.GetText ()) == " PhysxCollisionAPI" )
682
+ {
683
+ physxCollisionAPIenable = true ;
684
+ break ;
685
+ }
686
+ }
687
+
688
+ if (collisionEnabled || physxCollisionAPIenable)
689
+ {
690
+ sdf::Collision col;
691
+
692
+ // add _collision extension
693
+ std::string collisionName = _prim.GetPath ().GetName () + " _collision" ;
694
+ col.SetName (collisionName);
695
+ sdf::Geometry colGeom;
696
+
697
+ ignition::math::Pose3d poseCol;
698
+ ignition::math::Vector3d scaleCol (1 , 1 , 1 );
699
+ GetTransform (_prim, _usdData, poseCol, scaleCol, _link->Name ());
700
+
701
+ double metersPerUnit = data.second ->MetersPerUnit ();
702
+
703
+ if (_prim.IsA <pxr::UsdGeomSphere>())
704
+ {
705
+ ParseSphere (_prim, colGeom, scaleCol, metersPerUnit);
706
+ col.SetGeom (colGeom);
707
+ col.SetRawPose (poseCol);
708
+ }
709
+ else if (_prim.IsA <pxr::UsdGeomCylinder>())
710
+ {
711
+ ParseCylinder (_prim, colGeom, scaleCol, metersPerUnit);
712
+ col.SetGeom (colGeom);
713
+ col.SetRawPose (poseCol);
714
+ }
715
+ else if (_prim.IsA <pxr::UsdGeomCube>())
716
+ {
717
+ ParseCube (_prim, colGeom, scaleCol, metersPerUnit);
718
+ col.SetGeom (colGeom);
719
+ col.SetRawPose (poseCol);
720
+ }
721
+ else if (_prim.IsA <pxr::UsdGeomMesh>())
722
+ {
723
+ sdf::Visual visTmp;
724
+ ignition::math::Pose3d poseTmp;
725
+ errors = ParseMesh (
726
+ _prim, &_link.value (), visTmp, colGeom, scaleCol, _usdData, poseTmp);
727
+ if (!errors.empty ())
657
728
{
658
- errors = ParseMesh (
659
- _prim, &_link.value (), vis, geom, _scale, _usdData);
660
- if (!errors.empty ())
661
- {
662
- errors.emplace_back (UsdError (
663
- sdf::usd::UsdErrorCode::SDF_TO_USD_PARSING_ERROR,
664
- " Error parsing mesh" ));
665
- return errors;
666
- }
729
+ errors.emplace_back (UsdError (
730
+ sdf::usd::UsdErrorCode::SDF_TO_USD_PARSING_ERROR,
731
+ " Error parsing mesh" ));
732
+ return errors;
667
733
}
734
+ col.SetRawPose (poseTmp);
735
+ col.SetGeom (colGeom);
736
+ }
737
+ else if (primType == " Plane" )
738
+ {
739
+ sdf::Plane plane;
740
+ colGeom.SetType (sdf::GeometryType::PLANE);
741
+ plane.SetSize (ignition::math::Vector2d (100 , 100 ));
742
+ colGeom.SetPlaneShape (plane);
743
+
744
+ ignition::math::Pose3d pose;
745
+ ignition::math::Vector3d scale (1 , 1 , 1 );
746
+ GetTransform (
747
+ _prim, _usdData, pose, scale, pxr::TfStringify (_prim.GetPath ()));
748
+ col.SetRawPose (pose);
749
+ col.SetGeom (colGeom);
750
+ }
751
+
752
+ _link->AddCollision (col);
668
753
}
754
+
669
755
}
670
756
return errors;
671
757
}
0 commit comments