summaryrefslogtreecommitdiffstats
path: root/src/core/transforms
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-08-06 19:35:10 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-08-10 10:41:44 +0000
commit02d7a145af1e64b4606fdddb07f2555a8b2652a8 (patch)
treee22687a679d41127e049aeae36afdd4a98b9d728 /src/core/transforms
parent490fc79f93afa30fc2a6f38b0c3f605b317ae359 (diff)
Add inverseBindMatrix property to QJoint
Needed to compute skinning palette of matrices. Change-Id: Ifec41c2bb18855bbb2c332cf80d37642d34f75cf Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/transforms')
-rw-r--r--src/core/transforms/qjoint.cpp35
-rw-r--r--src/core/transforms/qjoint.h5
-rw-r--r--src/core/transforms/qjoint_p.h3
3 files changed, 43 insertions, 0 deletions
diff --git a/src/core/transforms/qjoint.cpp b/src/core/transforms/qjoint.cpp
index ca5f6dff0..c83b1e530 100644
--- a/src/core/transforms/qjoint.cpp
+++ b/src/core/transforms/qjoint.cpp
@@ -51,6 +51,7 @@ namespace Qt3DCore {
QJointPrivate::QJointPrivate()
: QNodePrivate()
+ , m_inverseBindMatrix()
, m_rotation()
, m_translation()
, m_scale(1.0f, 1.0f, 1.0f)
@@ -90,6 +91,15 @@ QJointPrivate::QJointPrivate()
*/
/*!
+ \qmlproperty matrix4x4 inverseBindMatrix
+
+ Holds the inverse bind matrix of the joint. This is used to transform
+ vertices from model space into the space of this joint so they can
+ subsequently be multiplied by the joint's global transform to perform
+ the skinning operation.
+*/
+
+/*!
\class Qt3DCore::QJoint
\inmodule Qt3DCore
\inherits Qt3DCore::QNode
@@ -148,6 +158,20 @@ QVector3D QJoint::translation() const
return d->m_translation;
}
+/*!
+ \property Qt3DCore::QJoint::inverseBindMatrix
+
+ Holds the inverse bind matrix of the joint. This is used to transform
+ vertices from model space into the space of this joint so they can
+ subsequently be multiplied by the joint's global transform to perform
+ the skinning operation.
+*/
+QMatrix4x4 QJoint::inverseBindMatrix() const
+{
+ Q_D(const QJoint);
+ return d->m_inverseBindMatrix;
+}
+
void QJoint::setScale(const QVector3D &scale)
{
Q_D(QJoint);
@@ -178,6 +202,16 @@ void QJoint::setTranslation(const QVector3D &translation)
emit translationChanged(translation);
}
+void QJoint::setInverseBindMatrix(const QMatrix4x4 &inverseBindMatrix)
+{
+ Q_D(QJoint);
+ if (d->m_inverseBindMatrix == inverseBindMatrix)
+ return;
+
+ d->m_inverseBindMatrix = inverseBindMatrix;
+ emit inverseBindMatrixChanged(inverseBindMatrix);
+}
+
/*!
Adds \a joint as a child of this joint. If \a joint has no parent, then
this joint takes ownership of it. Child joints are in the coordinate system
@@ -240,6 +274,7 @@ Qt3DCore::QNodeCreatedChangeBasePtr QJoint::createNodeCreationChange() const
auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QJointData>::create(this);
auto &data = creationChange->data;
Q_D(const QJoint);
+ data.inverseBindMatrix = d->m_inverseBindMatrix;
data.childJointIds = qIdsForNodes(d->m_childJoints);
data.rotation = d->m_rotation;
data.scale = d->m_scale;
diff --git a/src/core/transforms/qjoint.h b/src/core/transforms/qjoint.h
index 35b559f59..024c83ec7 100644
--- a/src/core/transforms/qjoint.h
+++ b/src/core/transforms/qjoint.h
@@ -43,6 +43,7 @@
#include <Qt3DCore/qnode.h>
#include <Qt3DCore/qt3dcore_global.h>
+#include <QtGui/qmatrix4x4.h>
#include <QtGui/qquaternion.h>
#include <QtGui/qvector3d.h>
@@ -58,6 +59,7 @@ class QT3DCORESHARED_EXPORT QJoint : public QNode
Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
Q_PROPERTY(QVector3D translation READ translation WRITE setTranslation NOTIFY translationChanged)
+ Q_PROPERTY(QMatrix4x4 inverseBindMatrix READ inverseBindMatrix WRITE setInverseBindMatrix NOTIFY inverseBindMatrixChanged)
public:
explicit QJoint(Qt3DCore::QNode *parent = nullptr);
@@ -66,6 +68,7 @@ public:
QVector3D scale() const;
QQuaternion rotation() const;
QVector3D translation() const;
+ QMatrix4x4 inverseBindMatrix() const;
void addChildJoint(QJoint *joint);
void removeChildJoint(QJoint *joint);
@@ -75,11 +78,13 @@ public Q_SLOTS:
void setScale(const QVector3D &scale);
void setRotation(const QQuaternion &rotation);
void setTranslation(const QVector3D &translation);
+ void setInverseBindMatrix(const QMatrix4x4 &inverseBindMatrix);
Q_SIGNALS:
void scaleChanged(const QVector3D &scale);
void rotationChanged(const QQuaternion &rotation);
void translationChanged(const QVector3D &translation);
+ void inverseBindMatrixChanged(const QMatrix4x4 &inverseBindMatrix);
private:
Q_DECLARE_PRIVATE(QJoint)
diff --git a/src/core/transforms/qjoint_p.h b/src/core/transforms/qjoint_p.h
index 35915a7dd..a0d59eac4 100644
--- a/src/core/transforms/qjoint_p.h
+++ b/src/core/transforms/qjoint_p.h
@@ -52,6 +52,7 @@
//
#include <Qt3DCore/private/qnode_p.h>
+#include <Qt3DCore/qjoint.h>
QT_BEGIN_NAMESPACE
@@ -66,6 +67,7 @@ public:
Q_DECLARE_PUBLIC(QJoint)
+ QMatrix4x4 m_inverseBindMatrix;
QVector<QJoint *> m_childJoints;
QQuaternion m_rotation;
QVector3D m_translation;
@@ -74,6 +76,7 @@ public:
struct QJointData
{
+ QMatrix4x4 inverseBindMatrix;
QNodeIdVector childJointIds;
QQuaternion rotation;
QVector3D translation;