@@ -184,6 +184,10 @@ bool COLLADA2GLTF::Writer::writeNodeToGroup(std::vector<GLTF::Node*>* group, con
184
184
node->transform = transform;
185
185
186
186
_animatedNodes[animationListId] = node;
187
+ if (transformation->getTransformationType () == COLLADAFW::Transformation::ROTATE) {
188
+ COLLADAFW::Rotate* rotate = (COLLADAFW::Rotate*)transformation;
189
+ _originalRotationAngles[animationListId] = rotate->getRotationAngle ();
190
+ }
187
191
isAnimated = true ;
188
192
}
189
193
else {
@@ -1029,7 +1033,14 @@ void interpolateTranslation(float* base, std::vector<float> input, std::vector<f
1029
1033
*/
1030
1034
bool COLLADA2GLTF::Writer::writeAnimationList (const COLLADAFW::AnimationList* animationList) {
1031
1035
const COLLADAFW::AnimationList::AnimationBindings& bindings = animationList->getAnimationBindings ();
1036
+ COLLADAFW::UniqueId animationListId = animationList->getUniqueId ();
1032
1037
GLTF::Node* node = _animatedNodes[animationList->getUniqueId ()];
1038
+ float originalRotationAngle = NAN;
1039
+ std::map<COLLADAFW::UniqueId, float >::iterator iter = _originalRotationAngles.find (animationListId);
1040
+ if (iter != _originalRotationAngles.end ()) {
1041
+ originalRotationAngle = iter->second ;
1042
+ }
1043
+
1033
1044
GLTF::Node::Transform* nodeTransform = node->transform ;
1034
1045
GLTF::Node::TransformTRS* nodeTransformTRS = NULL ;
1035
1046
std::set<float > timeSet = std::set<float >();
@@ -1217,6 +1228,12 @@ bool COLLADA2GLTF::Writer::writeAnimationList(const COLLADAFW::AnimationList* an
1217
1228
COLLADABU::Math::Vector3 axis;
1218
1229
COLLADABU::Math::Quaternion quaternion = COLLADABU::Math::Quaternion (nodeRotation[3 ], nodeRotation[0 ], nodeRotation[1 ], nodeRotation[2 ]);
1219
1230
quaternion.toAngleAxis (angle, axis);
1231
+ if (originalRotationAngle != NAN && fabs (COLLADABU::Math::Utils::degToRad (originalRotationAngle) - angle) > 1e-3 ) {
1232
+ // Quaternion -> axis angle can flip chirality; check it against the original rotation angle and correct the axis direction
1233
+ axis.x = -axis.x ;
1234
+ axis.y = -axis.y ;
1235
+ axis.z = -axis.z ;
1236
+ }
1220
1237
angle = COLLADABU::Math::Utils::degToRad (output[index ]);
1221
1238
quaternion.fromAngleAxis (angle, axis);
1222
1239
rotation[j * 4 ] = (float )quaternion.x ;
0 commit comments