From 4f34d89c4a014939e0f18ea9377417648ed27238 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 28 Oct 2013 14:38:09 -0700 Subject: [PATCH] Added left hand/hand rotation setters in preparation for Leap integration. --- interface/src/renderer/FBXReader.cpp | 6 ++++++ interface/src/renderer/FBXReader.h | 1 + interface/src/renderer/Model.cpp | 22 ++++++++++++++++++++++ interface/src/renderer/Model.h | 13 +++++++++++++ 4 files changed, 42 insertions(+) diff --git a/interface/src/renderer/FBXReader.cpp b/interface/src/renderer/FBXReader.cpp index 977368061f..9fae95bf53 100644 --- a/interface/src/renderer/FBXReader.cpp +++ b/interface/src/renderer/FBXReader.cpp @@ -696,6 +696,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) QString jointRootName = processID(joints.value("jointRoot", "jointRoot").toString()); QString jointLeanName = processID(joints.value("jointLean", "jointLean").toString()); QString jointHeadName = processID(joints.value("jointHead", "jointHead").toString()); + QString jointLeftHandName = processID(joints.value("jointLeftHand", "jointLeftHand").toString()); QString jointRightHandName = processID(joints.value("jointRightHand", "jointRightHand").toString()); QString jointEyeLeftID; QString jointEyeRightID; @@ -703,6 +704,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) QString jointRootID; QString jointLeanID; QString jointHeadID; + QString jointLeftHandID; QString jointRightHandID; QVariantHash blendshapeMappings = mapping.value("bs").toHash(); @@ -778,6 +780,9 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) } else if (name == jointHeadName) { jointHeadID = getID(object.properties); + } else if (name == jointLeftHandName) { + jointLeftHandID = getID(object.properties); + } else if (name == jointRightHandName) { jointRightHandID = getID(object.properties); } @@ -1028,6 +1033,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) geometry.rootJointIndex = modelIDs.indexOf(jointRootID); geometry.leanJointIndex = modelIDs.indexOf(jointLeanID); geometry.headJointIndex = modelIDs.indexOf(jointHeadID); + geometry.leftHandJointIndex = modelIDs.indexOf(jointLeftHandID); geometry.rightHandJointIndex = modelIDs.indexOf(jointRightHandID); // extract the translation component of the neck transform diff --git a/interface/src/renderer/FBXReader.h b/interface/src/renderer/FBXReader.h index c607e1ad49..c48da019ae 100644 --- a/interface/src/renderer/FBXReader.h +++ b/interface/src/renderer/FBXReader.h @@ -130,6 +130,7 @@ public: int rootJointIndex; int leanJointIndex; int headJointIndex; + int leftHandJointIndex; int rightHandJointIndex; glm::vec3 neckPivot; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 9aee34db7f..7ba8d24104 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -413,10 +413,22 @@ bool Model::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePos getJointPosition(geometry.rightEyeJointIndex, secondEyePosition); } +bool Model::setLeftHandPosition(const glm::vec3& position) { + return isActive() && setJointPosition(_geometry->getFBXGeometry().leftHandJointIndex, position); +} + +bool Model::setLeftHandRotation(const glm::quat& rotation) { + return isActive() && setJointRotation(_geometry->getFBXGeometry().leftHandJointIndex, rotation); +} + bool Model::setRightHandPosition(const glm::vec3& position) { return isActive() && setJointPosition(_geometry->getFBXGeometry().rightHandJointIndex, position); } +bool Model::setRightHandRotation(const glm::quat& rotation) { + return isActive() && setJointRotation(_geometry->getFBXGeometry().rightHandJointIndex, rotation); +} + void Model::setURL(const QUrl& url) { // don't recreate the geometry if it's the same URL if (_url == url) { @@ -535,6 +547,16 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position) { return true; } +bool Model::setJointRotation(int jointIndex, const glm::quat& rotation) { + if (jointIndex == -1 || _jointStates.isEmpty()) { + return false; + } + JointState& state = _jointStates[jointIndex]; + state.rotation = state.rotation * glm::inverse(state.combinedRotation) * rotation * + glm::inverse(_geometry->getFBXGeometry().joints.at(jointIndex).inverseBindRotation); + return true; +} + void Model::deleteGeometry() { foreach (Model* attachment, _attachments) { delete attachment; diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index eb6c59e773..4b54fcaaf4 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -70,10 +70,22 @@ public: /// \return whether or not both eye meshes were found bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; + /// Sets the position of the left hand using inverse kinematics. + /// \return whether or not the left hand joint was found + bool setLeftHandPosition(const glm::vec3& position); + + /// Sets the rotation of the left hand. + /// \return whether or not the left hand joint was found + bool setLeftHandRotation(const glm::quat& rotation); + /// Sets the position of the right hand using inverse kinematics. /// \return whether or not the right hand joint was found bool setRightHandPosition(const glm::vec3& position); + /// Sets the rotation of the right hand. + /// \return whether or not the right hand joint was found + bool setRightHandRotation(const glm::quat& rotation); + /// Returns the average color of all meshes in the geometry. glm::vec4 computeAverageColor() const; @@ -106,6 +118,7 @@ protected: bool getJointRotation(int jointIndex, glm::quat& rotation) const; bool setJointPosition(int jointIndex, const glm::vec3& position); + bool setJointRotation(int jointIndex, const glm::quat& rotation); private: