Skip to content

Commit

Permalink
Merge pull request #81 from KhronosGroup/2.0-fix-ema-simple-skin
Browse files Browse the repository at this point in the history
Check quaternion decomposition direction for axis angle
  • Loading branch information
lasalvavida authored Aug 27, 2017
2 parents b8cdc07 + 01bd78e commit a0df4a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/COLLADA2GLTFWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace COLLADA2GLTF {
std::map<COLLADAFW::UniqueId, std::map<GLTF::Primitive*, std::vector<int>>> _meshPositionMapping;
std::map<COLLADAFW::UniqueId, GLTF::Skin*> _skinInstances;
std::map<COLLADAFW::UniqueId, GLTF::Node*> _animatedNodes;
std::map<COLLADAFW::UniqueId, float> _originalRotationAngles;
std::map<std::string, std::vector<GLTF::Node*>*> _unboundSkeletonNodes;
std::map<std::string, GLTF::Node*> _nodes;
std::map<COLLADAFW::UniqueId, std::vector<COLLADAFW::UniqueId>> _skinJointNodes;
Expand Down
17 changes: 17 additions & 0 deletions src/COLLADA2GLTFWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ bool COLLADA2GLTF::Writer::writeNodeToGroup(std::vector<GLTF::Node*>* group, con
node->transform = transform;

_animatedNodes[animationListId] = node;
if (transformation->getTransformationType() == COLLADAFW::Transformation::ROTATE) {
COLLADAFW::Rotate* rotate = (COLLADAFW::Rotate*)transformation;
_originalRotationAngles[animationListId] = rotate->getRotationAngle();
}
isAnimated = true;
}
else {
Expand Down Expand Up @@ -1029,7 +1033,14 @@ void interpolateTranslation(float* base, std::vector<float> input, std::vector<f
*/
bool COLLADA2GLTF::Writer::writeAnimationList(const COLLADAFW::AnimationList* animationList) {
const COLLADAFW::AnimationList::AnimationBindings& bindings = animationList->getAnimationBindings();
COLLADAFW::UniqueId animationListId = animationList->getUniqueId();
GLTF::Node* node = _animatedNodes[animationList->getUniqueId()];
float originalRotationAngle = NAN;
std::map<COLLADAFW::UniqueId, float>::iterator iter = _originalRotationAngles.find(animationListId);
if (iter != _originalRotationAngles.end()) {
originalRotationAngle = iter->second;
}

GLTF::Node::Transform* nodeTransform = node->transform;
GLTF::Node::TransformTRS* nodeTransformTRS = NULL;
std::set<float> timeSet = std::set<float>();
Expand Down Expand Up @@ -1217,6 +1228,12 @@ bool COLLADA2GLTF::Writer::writeAnimationList(const COLLADAFW::AnimationList* an
COLLADABU::Math::Vector3 axis;
COLLADABU::Math::Quaternion quaternion = COLLADABU::Math::Quaternion(nodeRotation[3], nodeRotation[0], nodeRotation[1], nodeRotation[2]);
quaternion.toAngleAxis(angle, axis);
if (originalRotationAngle != NAN && fabs(COLLADABU::Math::Utils::degToRad(originalRotationAngle) - angle) > 1e-3) {
// Quaternion -> axis angle can flip chirality; check it against the original rotation angle and correct the axis direction
axis.x = -axis.x;
axis.y = -axis.y;
axis.z = -axis.z;
}
angle = COLLADABU::Math::Utils::degToRad(output[index]);
quaternion.fromAngleAxis(angle, axis);
rotation[j * 4] = (float)quaternion.x;
Expand Down

0 comments on commit a0df4a4

Please sign in to comment.