mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:41:10 +02:00
Merge pull request #6528 from hyperlogic/tony/non-uniform-scale-model-entity-fix
Fix for model entities with non-uniform scaled mesh
This commit is contained in:
commit
144983d345
3 changed files with 8 additions and 10 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include "AnimPose.h"
|
#include "AnimPose.h"
|
||||||
#include <GLMHelpers.h>
|
#include <GLMHelpers.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
const AnimPose AnimPose::identity = AnimPose(glm::vec3(1.0f),
|
const AnimPose AnimPose::identity = AnimPose(glm::vec3(1.0f),
|
||||||
glm::quat(),
|
glm::quat(),
|
||||||
|
@ -18,7 +19,9 @@ const AnimPose AnimPose::identity = AnimPose(glm::vec3(1.0f),
|
||||||
|
|
||||||
AnimPose::AnimPose(const glm::mat4& mat) {
|
AnimPose::AnimPose(const glm::mat4& mat) {
|
||||||
scale = extractScale(mat);
|
scale = extractScale(mat);
|
||||||
rot = glmExtractRotation(mat);
|
// quat_cast doesn't work so well with scaled matrices, so cancel it out.
|
||||||
|
glm::mat4 tmp = glm::scale(mat, 1.0f / scale);
|
||||||
|
rot = glm::normalize(glm::quat_cast(tmp));
|
||||||
trans = extractTranslation(mat);
|
trans = extractTranslation(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -928,7 +928,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|
||||||
//virtual
|
//virtual
|
||||||
void Model::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
void Model::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
||||||
_needsUpdateClusterMatrices = true;
|
_needsUpdateClusterMatrices = true;
|
||||||
_rig->updateAnimations(deltaTime, parentTransform);
|
_rig->updateAnimations(deltaTime, parentTransform);
|
||||||
}
|
}
|
||||||
void Model::simulateInternal(float deltaTime) {
|
void Model::simulateInternal(float deltaTime) {
|
||||||
// update the world space transforms for all joints
|
// update the world space transforms for all joints
|
||||||
|
|
|
@ -279,14 +279,9 @@ glm::quat extractRotation(const glm::mat4& matrix, bool assumeOrthogonal) {
|
||||||
|
|
||||||
glm::quat glmExtractRotation(const glm::mat4& matrix) {
|
glm::quat glmExtractRotation(const glm::mat4& matrix) {
|
||||||
glm::vec3 scale = extractScale(matrix);
|
glm::vec3 scale = extractScale(matrix);
|
||||||
float maxScale = std::max(std::max(scale.x, scale.y), scale.z);
|
// quat_cast doesn't work so well with scaled matrices, so cancel it out.
|
||||||
if (maxScale > 1.01f || maxScale <= 0.99f) {
|
glm::mat4 tmp = glm::scale(matrix, 1.0f / scale);
|
||||||
// quat_cast doesn't work so well with scaled matrices, so cancel it out.
|
return glm::normalize(glm::quat_cast(tmp));
|
||||||
glm::mat4 tmp = glm::scale(matrix, 1.0f / scale);
|
|
||||||
return glm::normalize(glm::quat_cast(tmp));
|
|
||||||
} else {
|
|
||||||
return glm::normalize(glm::quat_cast(matrix));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 extractScale(const glm::mat4& matrix) {
|
glm::vec3 extractScale(const glm::mat4& matrix) {
|
||||||
|
|
Loading…
Reference in a new issue