|
20 | 20 | #include <gtest/gtest.h>
|
21 | 21 | #include <ignition/math/Angle.hh>
|
22 | 22 | #include <ignition/math/Pose3.hh>
|
| 23 | + |
| 24 | +// TODO(ahcorde):this is to remove deprecated "warnings" in usd, these warnings |
| 25 | +// are reported using #pragma message so normal diagnostic flags cannot remove |
| 26 | +// them. This workaround requires this block to be used whenever usd is |
| 27 | +// included. |
| 28 | +#pragma push_macro ("__DEPRECATED") |
| 29 | +#undef __DEPRECATED |
| 30 | +#include <pxr/base/gf/quatf.h> |
23 | 31 | #include <pxr/base/gf/vec3d.h>
|
24 | 32 | #include <pxr/base/gf/vec3f.h>
|
25 | 33 | #include <pxr/base/tf/token.h>
|
26 | 34 | #include <pxr/usd/usd/attribute.h>
|
27 | 35 | #include <pxr/usd/usd/prim.h>
|
| 36 | +#include <pxr/usd/usdPhysics/massAPI.h> |
| 37 | +#include <pxr/usd/usdPhysics/rigidBodyAPI.h> |
| 38 | +#pragma pop_macro ("__DEPRECATED") |
28 | 39 |
|
29 | 40 | #include "sdf/system_util.hh"
|
30 | 41 |
|
@@ -95,6 +106,76 @@ void CheckPrimPose(const pxr::UsdPrim &_usdPrim,
|
95 | 106 | EXPECT_TRUE(checkedOpOrder);
|
96 | 107 | }
|
97 | 108 |
|
| 109 | +/// \brief Compare the Inertial of a USD prim to the desired values |
| 110 | +/// \param[in] _usdPrim The USD prim |
| 111 | +/// \param[in] _targetMass Mass of the link that _usdPrim should have |
| 112 | +/// \param[in] _targetDiagonalInertia Diagonal Inertia that _usdPrim should have |
| 113 | +/// \param[in] _targetPrincipalAxes The principal axes that _usdPrim should have |
| 114 | +/// \param[in] _targetCenterOfMass Center of mass that _usdPrim should have |
| 115 | +/// \param[in] _isRigid True if _usdPrim should be a rigid body, False otherwise |
| 116 | +void CheckInertial(const pxr::UsdPrim &_usdPrim, |
| 117 | + float _targetMass, |
| 118 | + const pxr::GfVec3f &_targetDiagonalInertia, |
| 119 | + const pxr::GfQuatf &_targetPrincipalAxes, |
| 120 | + const pxr::GfVec3f &_targetCenterOfMass, |
| 121 | + bool _isRigid) |
| 122 | +{ |
| 123 | + bool checkedMass = false; |
| 124 | + if (auto massAttr = |
| 125 | + _usdPrim.GetAttribute(pxr::TfToken("physics:mass"))) |
| 126 | + { |
| 127 | + float massUSD; |
| 128 | + massAttr.Get(&massUSD); |
| 129 | + EXPECT_FLOAT_EQ(_targetMass, massUSD); |
| 130 | + checkedMass = true; |
| 131 | + } |
| 132 | + EXPECT_TRUE(checkedMass); |
| 133 | + |
| 134 | + bool checkedDiagInertia = false; |
| 135 | + if (auto diagInertiaAttr = |
| 136 | + _usdPrim.GetAttribute(pxr::TfToken("physics:diagonalInertia"))) |
| 137 | + { |
| 138 | + pxr::GfVec3f diagonalInertiaUSD; |
| 139 | + diagInertiaAttr.Get(&diagonalInertiaUSD); |
| 140 | + EXPECT_FLOAT_EQ(_targetDiagonalInertia[0], diagonalInertiaUSD[0]); |
| 141 | + EXPECT_FLOAT_EQ(_targetDiagonalInertia[1], diagonalInertiaUSD[1]); |
| 142 | + EXPECT_FLOAT_EQ(_targetDiagonalInertia[2], diagonalInertiaUSD[2]); |
| 143 | + checkedDiagInertia = true; |
| 144 | + } |
| 145 | + EXPECT_TRUE(checkedDiagInertia); |
| 146 | + |
| 147 | + bool checkedPrincipalAxes = false; |
| 148 | + if (auto principalAxesAttr = |
| 149 | + _usdPrim.GetAttribute(pxr::TfToken("physics:principalAxes"))) |
| 150 | + { |
| 151 | + pxr::GfQuatf principalAxesUSD; |
| 152 | + principalAxesAttr.Get(&principalAxesUSD); |
| 153 | + EXPECT_FLOAT_EQ(principalAxesUSD.GetReal(), _targetPrincipalAxes.GetReal()); |
| 154 | + const auto &usdImaginary = principalAxesUSD.GetImaginary(); |
| 155 | + const auto &targetImaginary = _targetPrincipalAxes.GetImaginary(); |
| 156 | + EXPECT_FLOAT_EQ(usdImaginary[0], targetImaginary[0]); |
| 157 | + EXPECT_FLOAT_EQ(usdImaginary[1], targetImaginary[1]); |
| 158 | + EXPECT_FLOAT_EQ(usdImaginary[2], targetImaginary[2]); |
| 159 | + checkedPrincipalAxes = true; |
| 160 | + } |
| 161 | + EXPECT_TRUE(checkedPrincipalAxes); |
| 162 | + |
| 163 | + bool checkedCOM = false; |
| 164 | + if (auto comAttr = |
| 165 | + _usdPrim.GetAttribute(pxr::TfToken("physics:centerOfMass"))) |
| 166 | + { |
| 167 | + pxr::GfVec3f centerOfMassUSD; |
| 168 | + comAttr.Get(¢erOfMassUSD); |
| 169 | + EXPECT_FLOAT_EQ(_targetCenterOfMass[0], centerOfMassUSD[0]); |
| 170 | + EXPECT_FLOAT_EQ(_targetCenterOfMass[1], centerOfMassUSD[1]); |
| 171 | + EXPECT_FLOAT_EQ(_targetCenterOfMass[2], centerOfMassUSD[2]); |
| 172 | + checkedCOM = true; |
| 173 | + } |
| 174 | + EXPECT_TRUE(checkedCOM); |
| 175 | + |
| 176 | + EXPECT_EQ(_isRigid, _usdPrim.HasAPI<pxr::UsdPhysicsRigidBodyAPI>()); |
| 177 | + EXPECT_EQ(_isRigid, _usdPrim.HasAPI<pxr::UsdPhysicsMassAPI>()); |
| 178 | +} |
98 | 179 | } // namespace testing
|
99 | 180 | } // namespace usd
|
100 | 181 | }
|
|
0 commit comments