diff options
-rw-r--r-- | src/core/transforms/qjoint.cpp | 17 | ||||
-rw-r--r-- | src/core/transforms/qjoint.h | 4 | ||||
-rw-r--r-- | src/core/transforms/qjoint_p.h | 2 | ||||
-rw-r--r-- | src/render/geometry/joint.cpp | 10 | ||||
-rw-r--r-- | src/render/geometry/skeleton.cpp | 14 | ||||
-rw-r--r-- | src/render/geometry/skeleton_p.h | 2 | ||||
-rw-r--r-- | tests/auto/render/skeleton/tst_skeleton.cpp | 18 |
7 files changed, 54 insertions, 13 deletions
diff --git a/src/core/transforms/qjoint.cpp b/src/core/transforms/qjoint.cpp index 57603b54f..84d75d55d 100644 --- a/src/core/transforms/qjoint.cpp +++ b/src/core/transforms/qjoint.cpp @@ -310,6 +310,16 @@ void QJoint::setRotationZ(float rotationZ) blockNotifications(wasBlocked); } +void QJoint::setName(const QString &name) +{ + Q_D(QJoint); + if (d->m_name == name) + return; + + d->m_name = name; + emit nameChanged(name); +} + /*! 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 @@ -366,6 +376,12 @@ QVector<QJoint *> QJoint::childJoints() const return d->m_childJoints; } +QString QJoint::name() const +{ + Q_D(const QJoint); + return d->m_name; +} + /*! \internal */ Qt3DCore::QNodeCreatedChangeBasePtr QJoint::createNodeCreationChange() const { @@ -377,6 +393,7 @@ Qt3DCore::QNodeCreatedChangeBasePtr QJoint::createNodeCreationChange() const data.rotation = d->m_rotation; data.scale = d->m_scale; data.translation = d->m_translation; + data.name = d->m_name; return creationChange; } diff --git a/src/core/transforms/qjoint.h b/src/core/transforms/qjoint.h index 3160d74ab..732cfdddb 100644 --- a/src/core/transforms/qjoint.h +++ b/src/core/transforms/qjoint.h @@ -63,6 +63,7 @@ class QT3DCORESHARED_EXPORT QJoint : public QNode Q_PROPERTY(float rotationX READ rotationX WRITE setRotationX NOTIFY rotationXChanged) Q_PROPERTY(float rotationY READ rotationY WRITE setRotationY NOTIFY rotationYChanged) Q_PROPERTY(float rotationZ READ rotationZ WRITE setRotationZ NOTIFY rotationZChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) public: explicit QJoint(Qt3DCore::QNode *parent = nullptr); @@ -75,6 +76,7 @@ public: float rotationX() const; float rotationY() const; float rotationZ() const; + QString name() const; void addChildJoint(QJoint *joint); void removeChildJoint(QJoint *joint); @@ -88,6 +90,7 @@ public Q_SLOTS: void setRotationX(float rotationX); void setRotationY(float rotationY); void setRotationZ(float rotationZ); + void setName(const QString &name); Q_SIGNALS: void scaleChanged(const QVector3D &scale); @@ -97,6 +100,7 @@ Q_SIGNALS: void rotationXChanged(float rotationX); void rotationYChanged(float rotationY); void rotationZChanged(float rotationZ); + void nameChanged(const QString &name); private: Q_DECLARE_PRIVATE(QJoint) diff --git a/src/core/transforms/qjoint_p.h b/src/core/transforms/qjoint_p.h index f7ab244bd..82439d55a 100644 --- a/src/core/transforms/qjoint_p.h +++ b/src/core/transforms/qjoint_p.h @@ -72,6 +72,7 @@ public: QQuaternion m_rotation; QVector3D m_translation; QVector3D m_scale; + QString m_name; // Not sent to backend. Purely internal convenience QVector3D m_eulerRotationAngles; @@ -84,6 +85,7 @@ struct QJointData QQuaternion rotation; QVector3D translation; QVector3D scale; + QString name; }; } // namespace Qt3DCore diff --git a/src/render/geometry/joint.cpp b/src/render/geometry/joint.cpp index 541ab3302..9c53b8ef8 100644 --- a/src/render/geometry/joint.cpp +++ b/src/render/geometry/joint.cpp @@ -79,10 +79,9 @@ void Joint::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change m_localPose.scale = data.scale; m_localPose.translation = data.translation; m_childJointIds = data.childJointIds; + m_name = data.name; markDirty(AbstractRenderer::JointDirty); m_jointManager->addDirtyJoint(peerId()); - - // TODO: Add name property to QJoint } void Joint::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) @@ -108,8 +107,13 @@ void Joint::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) // the inverse bind matrix. m_inverseBindMatrix = propertyChange->value().value<QMatrix4x4>(); m_skeletonManager->addDirtySkeleton(SkeletonManager::SkeletonDataDirty, m_owningSkeleton); + } else if (propertyChange->propertyName() == QByteArrayLiteral("name")) { + // Joint name doesn't affect anything in the render aspect so no need + // to mark anything as dirty. + m_name = propertyChange->value().toString(); + + // TODO: Notify other aspects (animation) about the name change. } - // TODO: Add name property to QJoint } else if (e->type() == PropertyValueAdded) { const auto addedChange = qSharedPointerCast<QPropertyNodeAddedChange>(e); if (addedChange->propertyName() == QByteArrayLiteral("childJoint")) diff --git a/src/render/geometry/skeleton.cpp b/src/render/geometry/skeleton.cpp index 31bce7eb1..f1761bc18 100644 --- a/src/render/geometry/skeleton.cpp +++ b/src/render/geometry/skeleton.cpp @@ -294,9 +294,13 @@ Qt3DCore::QJoint *Skeleton::createFrontendJoints(const SkeletonData &skeletonDat // Create frontend joints from the joint info objects QVector<QJoint *> frontendJoints; - frontendJoints.reserve(skeletonData.joints.size()); - for (const JointInfo &jointInfo : skeletonData.joints) - frontendJoints.push_back(createFrontendJoint(jointInfo)); + const int jointCount = skeletonData.joints.size(); + frontendJoints.reserve(jointCount); + for (int i = 0; i < jointCount; ++i) { + const JointInfo &jointInfo = skeletonData.joints[i]; + const QString &jointName = skeletonData.jointNames[i]; + frontendJoints.push_back(createFrontendJoint(jointName, jointInfo)); + } // Now go through and resolve the parent for each joint for (int i = 0; i < frontendJoints.size(); ++i) { @@ -313,14 +317,14 @@ Qt3DCore::QJoint *Skeleton::createFrontendJoints(const SkeletonData &skeletonDat return frontendJoints[0]; } -Qt3DCore::QJoint *Skeleton::createFrontendJoint(const JointInfo &jointInfo) const +Qt3DCore::QJoint *Skeleton::createFrontendJoint(const QString &jointName, const JointInfo &jointInfo) const { auto joint = QAbstractNodeFactory::createNode<QJoint>("QJoint"); joint->setTranslation(jointInfo.localPose.translation); joint->setRotation(jointInfo.localPose.rotation); joint->setScale(jointInfo.localPose.scale); joint->setInverseBindMatrix(jointInfo.inverseBindPose); - // TODO: Add name property to joint + joint->setName(jointName); return joint; } diff --git a/src/render/geometry/skeleton_p.h b/src/render/geometry/skeleton_p.h index 2a8ede17e..566304114 100644 --- a/src/render/geometry/skeleton_p.h +++ b/src/render/geometry/skeleton_p.h @@ -123,7 +123,7 @@ private: void loadSkeletonFromUrl(); void loadSkeletonFromData(); Qt3DCore::QJoint *createFrontendJoints(const SkeletonData &skeletonData) const; - Qt3DCore::QJoint *createFrontendJoint(const JointInfo &jointInfo) const; + Qt3DCore::QJoint *createFrontendJoint(const QString &jointName, const JointInfo &jointInfo) const; void processJointHierarchy(Qt3DCore::QNodeId jointId, int parentJointIndex, SkeletonData &skeletonData); void clearData(); diff --git a/tests/auto/render/skeleton/tst_skeleton.cpp b/tests/auto/render/skeleton/tst_skeleton.cpp index 1cfa44e6b..9aafe29b9 100644 --- a/tests/auto/render/skeleton/tst_skeleton.cpp +++ b/tests/auto/render/skeleton/tst_skeleton.cpp @@ -231,9 +231,10 @@ private Q_SLOTS: void checkCreateFrontendJoint_data() { QTest::addColumn<JointInfo>("jointInfo"); + QTest::addColumn<QString>("jointName"); QTest::addColumn<QJoint *>("expectedJoint"); - QTest::newRow("default") << JointInfo() << new QJoint(); + QTest::newRow("default") << JointInfo() << QString() << new QJoint(); const QVector3D t(1.0f, 2.0f, 3.0f); const QQuaternion r = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, 45.0f); @@ -243,24 +244,28 @@ private Q_SLOTS: jointInfo.localPose.rotation = r; jointInfo.localPose.translation = t; + QString name = QLatin1String("Foo"); QJoint *joint = new QJoint(); joint->setTranslation(t); joint->setRotation(r); joint->setScale(s); - QTest::newRow("localPose") << jointInfo << joint; + joint->setName(name); + QTest::newRow("localPose") << jointInfo << name << joint; QMatrix4x4 m; m.rotate(r); m.scale(QVector3D(1.0f, 1.0f, 1.0f) / s); m.translate(-t); jointInfo.inverseBindPose = m; + name = QLatin1String("Bar"); joint = new QJoint(); joint->setTranslation(t); joint->setRotation(r); joint->setScale(s); joint->setInverseBindMatrix(m); - QTest::newRow("inverseBind") << jointInfo << joint; + joint->setName(name); + QTest::newRow("inverseBind") << jointInfo << name << joint; } void checkCreateFrontendJoint() @@ -268,16 +273,18 @@ private Q_SLOTS: // GIVEN Skeleton backendSkeleton; QFETCH(JointInfo, jointInfo); + QFETCH(QString, jointName); QFETCH(QJoint *, expectedJoint); // WHEN - const QJoint *actualJoint = backendSkeleton.createFrontendJoint(jointInfo); + const QJoint *actualJoint = backendSkeleton.createFrontendJoint(jointName, jointInfo); // THEN QCOMPARE(actualJoint->scale(), expectedJoint->scale()); QCOMPARE(actualJoint->rotation(), expectedJoint->rotation()); QCOMPARE(actualJoint->translation(), expectedJoint->translation()); QCOMPARE(actualJoint->inverseBindMatrix(), expectedJoint->inverseBindMatrix()); + QCOMPARE(actualJoint->name(), expectedJoint->name()); // Cleanup delete actualJoint; @@ -294,6 +301,7 @@ private Q_SLOTS: SkeletonData skeletonData; JointInfo rootJointInfo; skeletonData.joints.push_back(rootJointInfo); + skeletonData.jointNames.push_back(QLatin1String("rootJoint")); const int childCount = 10; for (int i = 0; i < childCount; ++i) { JointInfo childJointInfo; @@ -301,6 +309,7 @@ private Q_SLOTS: childJointInfo.localPose.translation = QVector3D(x, x, x); childJointInfo.parentIndex = 0; skeletonData.joints.push_back(childJointInfo); + skeletonData.jointNames.push_back(QString("Child-%1").arg(i)); } QJoint *rootJoint = new QJoint(); @@ -321,6 +330,7 @@ private Q_SLOTS: childJointInfo.localPose.translation = QVector3D(x, x, x); childJointInfo.parentIndex = i; skeletonData.joints.push_back(childJointInfo); + skeletonData.jointNames.push_back(QString("Child-%1").arg(i)); } rootJoint = new QJoint(); |