17
17
18
18
#include " sdf/usd/usd_parser/USDTransforms.hh"
19
19
20
+ #include < optional>
21
+ #include < utility>
22
+
20
23
#include < ignition/math/Pose3.hh>
21
24
#include < ignition/math/Vector3.hh>
22
25
@@ -49,16 +52,10 @@ class UDSTransforms::Implementation
49
52
public: ignition::math::Vector3d scale{1 , 1 , 1 };
50
53
51
54
// / \brief Rotation of the schema
52
- public: std::vector <ignition::math::Quaterniond> q;
55
+ public: std::optional <ignition::math::Quaterniond> q = std::nullopt ;
53
56
54
57
// / \brief Translation of the schema
55
58
public: ignition::math::Vector3d translate{0 , 0 , 0 };
56
-
57
- // / \brief True if there is a rotation ZYX defined or false otherwise
58
- public: bool isRotationZYX = false ;
59
-
60
- // / \brief True if there is a rotation XYZ defined or false otherwise
61
- public: bool isRotationXYZ = false ;
62
59
};
63
60
64
61
// ///////////////////////////////////////////////
@@ -80,8 +77,7 @@ const ignition::math::Vector3d UDSTransforms::Scale() const
80
77
}
81
78
82
79
// ////////////////////////////////////////////////
83
- const std::vector<ignition::math::Quaterniond>
84
- UDSTransforms::Rotations () const
80
+ const std::optional<ignition::math::Quaterniond> UDSTransforms::Rotation () const
85
81
{
86
82
return this ->dataPtr ->q ;
87
83
}
@@ -101,44 +97,10 @@ void UDSTransforms::SetScale(
101
97
}
102
98
103
99
// ////////////////////////////////////////////////
104
- void UDSTransforms::AddRotation (
100
+ void UDSTransforms::SetRotation (
105
101
const ignition::math::Quaterniond &_q)
106
102
{
107
- this ->dataPtr ->q .push_back (_q);
108
- }
109
-
110
- // ////////////////////////////////////////////////
111
- bool UDSTransforms::RotationZYX () const
112
- {
113
- return this ->dataPtr ->isRotationZYX ;
114
- }
115
-
116
- // ////////////////////////////////////////////////
117
- bool UDSTransforms::RotationXYZ () const
118
- {
119
- return this ->dataPtr ->isRotationXYZ ;
120
- }
121
-
122
- // ////////////////////////////////////////////////
123
- bool UDSTransforms::Rotation () const
124
- {
125
- return !this ->dataPtr ->q .empty ();
126
- }
127
-
128
- // ////////////////////////////////////////////////
129
- void UDSTransforms::SetRotationZYX (bool _rotationZYX)
130
- {
131
- this ->dataPtr ->isRotationZYX = _rotationZYX;
132
- if (_rotationZYX)
133
- this ->dataPtr ->isRotationXYZ = false ;
134
- }
135
-
136
- // ////////////////////////////////////////////////
137
- void UDSTransforms::SetRotationXYZ (bool _rotationXYZ)
138
- {
139
- this ->dataPtr ->isRotationXYZ = _rotationXYZ;
140
- if (_rotationXYZ)
141
- this ->dataPtr ->isRotationZYX = false ;
103
+ this ->dataPtr ->q = _q;
142
104
}
143
105
144
106
// ////////////////////////////////////////////////
@@ -191,41 +153,11 @@ void GetAllTransforms(
191
153
child.Pos ().Z () * t.Scale ()[2 ]);
192
154
}
193
155
194
- if (!t. RotationZYX () && !t. RotationXYZ ())
156
+ if (t. Rotation ())
195
157
{
196
- if (t.Rotation ())
197
- {
198
- pose.Rot () = t.Rotations ()[0 ];
199
- }
200
- _tfs.push_back (pose);
201
- }
202
- else
203
- {
204
- ignition::math::Pose3d poseZ = ignition::math::Pose3d (
205
- ignition::math::Vector3d (0 , 0 , 0 ), t.Rotations ()[2 ]);
206
- ignition::math::Pose3d poseY = ignition::math::Pose3d (
207
- ignition::math::Vector3d (0 , 0 , 0 ), t.Rotations ()[1 ]);
208
- ignition::math::Pose3d poseX = ignition::math::Pose3d (
209
- ignition::math::Vector3d (0 , 0 , 0 ), t.Rotations ()[0 ]);
210
-
211
- ignition::math::Pose3d poseT = ignition::math::Pose3d (
212
- t.Translation () * metersPerUnit,
213
- ignition::math::Quaterniond (1 , 0 , 0 , 0 ));
214
-
215
- if (t.RotationZYX ())
216
- {
217
- _tfs.push_back (poseZ);
218
- _tfs.push_back (poseY);
219
- _tfs.push_back (poseX);
220
- }
221
- else if (t.RotationXYZ ())
222
- {
223
- _tfs.push_back (poseX);
224
- _tfs.push_back (poseY);
225
- _tfs.push_back (poseZ);
226
- }
227
- _tfs.push_back (poseT);
158
+ pose.Rot () = t.Rotation ().value ();
228
159
}
160
+ _tfs.push_back (pose);
229
161
parent = parent.GetParent ();
230
162
}
231
163
@@ -297,12 +229,10 @@ UDSTransforms ParseUSDTransform(const pxr::UsdPrim &_prim)
297
229
if (op == kXFormOpRotateZYX )
298
230
{
299
231
attribute = _prim.GetAttribute (pxr::TfToken (kXFormOpRotateZYX ));
300
- t.SetRotationZYX (true );
301
232
}
302
233
else
303
234
{
304
235
attribute = _prim.GetAttribute (pxr::TfToken (kXFormOpRotateXYZ ));
305
- t.SetRotationXYZ (true );
306
236
}
307
237
if (attribute.GetTypeName ().GetCPPTypeName () == kGfVec3fString )
308
238
{
@@ -324,9 +254,11 @@ UDSTransforms ParseUSDTransform(const pxr::UsdPrim &_prim)
324
254
qY = ignition::math::Quaterniond (0 , angleY.Normalized ().Radian (), 0 );
325
255
qZ = ignition::math::Quaterniond (0 , 0 , angleZ.Normalized ().Radian ());
326
256
327
- t.AddRotation (qX);
328
- t.AddRotation (qY);
329
- t.AddRotation (qZ);
257
+ if (op == kXFormOpRotateZYX )
258
+ {
259
+ std::swap (angleX, angleZ);
260
+ }
261
+ t.SetRotation ((qX * qY) * qZ);
330
262
}
331
263
else if (op == kXFormOpTranslate )
332
264
{
@@ -370,7 +302,7 @@ UDSTransforms ParseUSDTransform(const pxr::UsdPrim &_prim)
370
302
rotationQuad.GetImaginary ()[0 ],
371
303
rotationQuad.GetImaginary ()[1 ],
372
304
rotationQuad.GetImaginary ()[2 ]);
373
- t.AddRotation (q);
305
+ t.SetRotation (q);
374
306
}
375
307
376
308
if (op == kXFormOpTransform )
@@ -397,7 +329,7 @@ UDSTransforms ParseUSDTransform(const pxr::UsdPrim &_prim)
397
329
rotQuat.GetImaginary ()[1 ],
398
330
rotQuat.GetImaginary ()[2 ]
399
331
);
400
- t.AddRotation (q);
332
+ t.SetRotation (q);
401
333
}
402
334
}
403
335
return t;
0 commit comments