Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check quaternion decomposition direction for axis angle #81

Merged
merged 1 commit into from
Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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