From 03e076046bb08f6fb6a7c9b9ad8b90b9abe5aca1 Mon Sep 17 00:00:00 2001 From: Menithal Date: Mon, 4 Sep 2017 22:16:02 +0300 Subject: [PATCH 1/4] Added Joint Name check for translations This way if there is a mismatch in the skeleton, the translations are applied to the models correctly --- .../src/RenderableModelEntityItem.cpp | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 22b2cffbcb..01885e014e 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -909,8 +909,15 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { QVector jointsData; const QVector& frames = _animation->getFramesReference(); // NOTE: getFrames() is too heavy - auto& fbxJoints = _animation->getGeometry().joints; - auto& originalFbxJoints = _model->getFBXGeometry().joints; + auto& animationGeometry = _animation->getGeometry(); + auto& animationJointNames = animationGeometry.getJointNames(); + auto& fbxJoints = animationGeometry.joints; + auto& _debugFbxJoints = animationGeometry.jointIndices; + + auto& originalFbx = _model->getFBXGeometry(); + auto& originalFbxJoints = originalFbx.joints; + auto& originalFbxIndices = originalFbx.jointIndices; + bool allowTranslation = entity->getAnimationAllowTranslation(); int frameCount = frames.size(); if (frameCount <= 0) { @@ -952,13 +959,22 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { jointsData.resize(_jointMapping.size()); for (int j = 0; j < _jointMapping.size(); j++) { int index = _jointMapping[j]; + if (index >= 0) { glm::mat4 translationMat; - if (!allowTranslation){ - translationMat = glm::translate(originalFbxJoints[index].translation); - } else if (index < translations.size()) { + + if (allowTranslation && index < translations.size()) { translationMat = glm::translate(translations[index]); - } + } else if (!allowTranslation && index < animationJointNames.size()){ + QString jointName = fbxJoints[index].name; // Pushing this here so its not done on every entity, with the exceptions of those allowing for translation + + + if (originalFbxIndices.contains(jointName)) { + // Making sure the joint names exist in the original model the animation is trying to apply onto. If they do, then remap and get it's translation. + int remappedIndex = originalFbxIndices[jointName] - 1; // JointIndeces seem to always start from 1 and the found index is always 1 higher than actual. + translationMat = glm::translate(originalFbxJoints[remappedIndex].translation); + } + } glm::mat4 rotationMat; if (index < rotations.size()) { rotationMat = glm::mat4_cast(fbxJoints[index].preRotation * rotations[index] * fbxJoints[index].postRotation); @@ -975,7 +991,6 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { jointData.rotationSet = true; } } - // Set the data in the entity entity->setAnimationJointsData(jointsData); From 119a2703f79d09aeb1e8c7ccacc1ea500cdbc5b5 Mon Sep 17 00:00:00 2001 From: Menithal Date: Mon, 4 Sep 2017 22:20:00 +0300 Subject: [PATCH 2/4] Removed Debug Joints that wasnt used anylonger --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 01885e014e..a08621f827 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -912,7 +912,6 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { auto& animationGeometry = _animation->getGeometry(); auto& animationJointNames = animationGeometry.getJointNames(); auto& fbxJoints = animationGeometry.joints; - auto& _debugFbxJoints = animationGeometry.jointIndices; auto& originalFbx = _model->getFBXGeometry(); auto& originalFbxJoints = originalFbx.joints; @@ -967,8 +966,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { translationMat = glm::translate(translations[index]); } else if (!allowTranslation && index < animationJointNames.size()){ QString jointName = fbxJoints[index].name; // Pushing this here so its not done on every entity, with the exceptions of those allowing for translation - - + if (originalFbxIndices.contains(jointName)) { // Making sure the joint names exist in the original model the animation is trying to apply onto. If they do, then remap and get it's translation. int remappedIndex = originalFbxIndices[jointName] - 1; // JointIndeces seem to always start from 1 and the found index is always 1 higher than actual. From 856452405e1145847a4dfdd3f23b286288602fe9 Mon Sep 17 00:00:00 2001 From: Menithal Date: Tue, 5 Sep 2017 08:46:37 +0300 Subject: [PATCH 3/4] Made Code abit more concise for better compilation --- .../src/RenderableModelEntityItem.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index a08621f827..cc9dcf8ac5 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -909,13 +909,11 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { QVector jointsData; const QVector& frames = _animation->getFramesReference(); // NOTE: getFrames() is too heavy - auto& animationGeometry = _animation->getGeometry(); - auto& animationJointNames = animationGeometry.getJointNames(); - auto& fbxJoints = animationGeometry.joints; + QStringList animationJointNames = _animation->getGeometry().getJointNames(); + auto& fbxJoints = _animation->getGeometry().joints; - auto& originalFbx = _model->getFBXGeometry(); - auto& originalFbxJoints = originalFbx.joints; - auto& originalFbxIndices = originalFbx.jointIndices; + auto& originalFbxJoints = _model->getFBXGeometry().joints; + auto& originalFbxIndices = _model->getFBXGeometry().jointIndices; bool allowTranslation = entity->getAnimationAllowTranslation(); int frameCount = frames.size(); From 40d339a8318e7b014c60da12a6817aa684d44a9b Mon Sep 17 00:00:00 2001 From: Menithal Date: Mon, 11 Sep 2017 20:33:54 +0300 Subject: [PATCH 4/4] 21484: Updated code to go with PR feedback --- .../src/RenderableModelEntityItem.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index cc9dcf8ac5..c6bad008e4 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -909,13 +909,6 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { QVector jointsData; const QVector& frames = _animation->getFramesReference(); // NOTE: getFrames() is too heavy - QStringList animationJointNames = _animation->getGeometry().getJointNames(); - auto& fbxJoints = _animation->getGeometry().joints; - - auto& originalFbxJoints = _model->getFBXGeometry().joints; - auto& originalFbxIndices = _model->getFBXGeometry().jointIndices; - - bool allowTranslation = entity->getAnimationAllowTranslation(); int frameCount = frames.size(); if (frameCount <= 0) { return; @@ -950,6 +943,14 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { return; } + QStringList animationJointNames = _animation->getGeometry().getJointNames(); + auto& fbxJoints = _animation->getGeometry().joints; + + auto& originalFbxJoints = _model->getFBXGeometry().joints; + auto& originalFbxIndices = _model->getFBXGeometry().jointIndices; + + bool allowTranslation = entity->getAnimationAllowTranslation(); + const QVector& rotations = frames[_lastKnownCurrentFrame].rotations; const QVector& translations = frames[_lastKnownCurrentFrame].translations; @@ -960,9 +961,11 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) { if (index >= 0) { glm::mat4 translationMat; - if (allowTranslation && index < translations.size()) { - translationMat = glm::translate(translations[index]); - } else if (!allowTranslation && index < animationJointNames.size()){ + if (allowTranslation) { + if(index < translations.size()){ + translationMat = glm::translate(translations[index]); + } + } else if (index < animationJointNames.size()){ QString jointName = fbxJoints[index].name; // Pushing this here so its not done on every entity, with the exceptions of those allowing for translation if (originalFbxIndices.contains(jointName)) {