Skip to content

Commit a0df4a4

Browse files
authored
Merge pull request #81 from KhronosGroup/2.0-fix-ema-simple-skin
Check quaternion decomposition direction for axis angle
2 parents b8cdc07 + 01bd78e commit a0df4a4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

include/COLLADA2GLTFWriter.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace COLLADA2GLTF {
2525
std::map<COLLADAFW::UniqueId, std::map<GLTF::Primitive*, std::vector<int>>> _meshPositionMapping;
2626
std::map<COLLADAFW::UniqueId, GLTF::Skin*> _skinInstances;
2727
std::map<COLLADAFW::UniqueId, GLTF::Node*> _animatedNodes;
28+
std::map<COLLADAFW::UniqueId, float> _originalRotationAngles;
2829
std::map<std::string, std::vector<GLTF::Node*>*> _unboundSkeletonNodes;
2930
std::map<std::string, GLTF::Node*> _nodes;
3031
std::map<COLLADAFW::UniqueId, std::vector<COLLADAFW::UniqueId>> _skinJointNodes;

src/COLLADA2GLTFWriter.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ bool COLLADA2GLTF::Writer::writeNodeToGroup(std::vector<GLTF::Node*>* group, con
184184
node->transform = transform;
185185

186186
_animatedNodes[animationListId] = node;
187+
if (transformation->getTransformationType() == COLLADAFW::Transformation::ROTATE) {
188+
COLLADAFW::Rotate* rotate = (COLLADAFW::Rotate*)transformation;
189+
_originalRotationAngles[animationListId] = rotate->getRotationAngle();
190+
}
187191
isAnimated = true;
188192
}
189193
else {
@@ -1029,7 +1033,14 @@ void interpolateTranslation(float* base, std::vector<float> input, std::vector<f
10291033
*/
10301034
bool COLLADA2GLTF::Writer::writeAnimationList(const COLLADAFW::AnimationList* animationList) {
10311035
const COLLADAFW::AnimationList::AnimationBindings& bindings = animationList->getAnimationBindings();
1036+
COLLADAFW::UniqueId animationListId = animationList->getUniqueId();
10321037
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+
10331044
GLTF::Node::Transform* nodeTransform = node->transform;
10341045
GLTF::Node::TransformTRS* nodeTransformTRS = NULL;
10351046
std::set<float> timeSet = std::set<float>();
@@ -1217,6 +1228,12 @@ bool COLLADA2GLTF::Writer::writeAnimationList(const COLLADAFW::AnimationList* an
12171228
COLLADABU::Math::Vector3 axis;
12181229
COLLADABU::Math::Quaternion quaternion = COLLADABU::Math::Quaternion(nodeRotation[3], nodeRotation[0], nodeRotation[1], nodeRotation[2]);
12191230
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+
}
12201237
angle = COLLADABU::Math::Utils::degToRad(output[index]);
12211238
quaternion.fromAngleAxis(angle, axis);
12221239
rotation[j * 4] = (float)quaternion.x;

0 commit comments

Comments
 (0)