diff --git a/interface/src/avatar/FaceModel.cpp b/interface/src/avatar/FaceModel.cpp index 90e596bde5..eaa9875641 100644 --- a/interface/src/avatar/FaceModel.cpp +++ b/interface/src/avatar/FaceModel.cpp @@ -69,3 +69,12 @@ void FaceModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJ state.rotation = glm::angleAxis(glm::clamp(glm::angle(between), -MAX_ANGLE, MAX_ANGLE), glm::axis(between)) * joint.rotation; } + +bool FaceModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const { + if (!isActive()) { + return false; + } + const FBXGeometry& geometry = _geometry->getFBXGeometry(); + return getJointPosition(geometry.leftEyeJointIndex, firstEyePosition) && + getJointPosition(geometry.rightEyeJointIndex, secondEyePosition); +} diff --git a/interface/src/avatar/FaceModel.h b/interface/src/avatar/FaceModel.h index 0b7fea8ec4..c3462f42ac 100644 --- a/interface/src/avatar/FaceModel.h +++ b/interface/src/avatar/FaceModel.h @@ -29,6 +29,10 @@ public: virtual void maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); virtual void maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); + /// Retrieve the positions of up to two eye meshes. + /// \return whether or not both eye meshes were found + bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; + private: Head* _owningHead; diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 9fe52f81ce..9867f03f4c 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -198,10 +198,25 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { } void SkeletonModel::updateJointState(int index) { + JointState& state = _jointStates[index]; + const FBXGeometry& geometry = _geometry->getFBXGeometry(); + const FBXJoint& joint = geometry.joints.at(index); + if (joint.parentIndex == -1) { + const JointState& parentState = _jointStates.at(joint.parentIndex); + if (index == geometry.leanJointIndex) { + maybeUpdateLeanRotation(parentState, joint, state); + + } else if (index == geometry.neckJointIndex) { + maybeUpdateNeckRotation(parentState, joint, state); + + } else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) { + maybeUpdateEyeRotation(parentState, joint, state); + } + } + Model::updateJointState(index); if (index == _geometry->getFBXGeometry().rootJointIndex) { - JointState& state = _jointStates[index]; state.transform[3][0] = 0.0f; state.transform[3][1] = 0.0f; state.transform[3][2] = 0.0f; @@ -388,3 +403,31 @@ float SkeletonModel::getRightArmLength() const { return getLimbLength(getRightHandJointIndex()); } +bool SkeletonModel::getHeadPosition(glm::vec3& headPosition) const { + return isActive() && getJointPosition(_geometry->getFBXGeometry().headJointIndex, headPosition); +} + +bool SkeletonModel::getNeckPosition(glm::vec3& neckPosition) const { + return isActive() && getJointPosition(_geometry->getFBXGeometry().neckJointIndex, neckPosition); +} + +bool SkeletonModel::getNeckParentRotation(glm::quat& neckParentRotation) const { + if (!isActive()) { + return false; + } + const FBXGeometry& geometry = _geometry->getFBXGeometry(); + if (geometry.neckJointIndex == -1) { + return false; + } + return getJointRotation(geometry.joints.at(geometry.neckJointIndex).parentIndex, neckParentRotation); +} + +bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const { + if (!isActive()) { + return false; + } + const FBXGeometry& geometry = _geometry->getFBXGeometry(); + return getJointPosition(geometry.leftEyeJointIndex, firstEyePosition) && + getJointPosition(geometry.rightEyeJointIndex, secondEyePosition); +} + diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index 6a46b3b88e..60e925b239 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -80,6 +80,22 @@ public: /// Returns the extended length from the right hand to its first free ancestor. float getRightArmLength() const; + + /// Returns the position of the head joint. + /// \return whether or not the head was found + bool getHeadPosition(glm::vec3& headPosition) const; + + /// Returns the position of the neck joint. + /// \return whether or not the neck was found + bool getNeckPosition(glm::vec3& neckPosition) const; + + /// Returns the rotation of the neck joint's parent. + /// \return whether or not the neck was found + bool getNeckParentRotation(glm::quat& neckRotation) const; + + /// Retrieve the positions of up to two eye meshes. + /// \return whether or not both eye meshes were found + bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; protected: @@ -90,9 +106,9 @@ protected: /// Updates the state of the joint at the specified index. virtual void updateJointState(int index); - virtual void maybeUpdateLeanRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); - virtual void maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); - virtual void maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); + void maybeUpdateLeanRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); + void maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); + void maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); private: diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 192bacdce9..5a93dbcf25 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -613,34 +613,6 @@ int Model::getLastFreeJointIndex(int jointIndex) const { return (isActive() && jointIndex != -1) ? _geometry->getFBXGeometry().joints.at(jointIndex).freeLineage.last() : -1; } -bool Model::getHeadPosition(glm::vec3& headPosition) const { - return isActive() && getJointPosition(_geometry->getFBXGeometry().headJointIndex, headPosition); -} - -bool Model::getNeckPosition(glm::vec3& neckPosition) const { - return isActive() && getJointPosition(_geometry->getFBXGeometry().neckJointIndex, neckPosition); -} - -bool Model::getNeckParentRotation(glm::quat& neckParentRotation) const { - if (!isActive()) { - return false; - } - const FBXGeometry& geometry = _geometry->getFBXGeometry(); - if (geometry.neckJointIndex == -1) { - return false; - } - return getJointRotation(geometry.joints.at(geometry.neckJointIndex).parentIndex, neckParentRotation); -} - -bool Model::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const { - if (!isActive()) { - return false; - } - const FBXGeometry& geometry = _geometry->getFBXGeometry(); - return getJointPosition(geometry.leftEyeJointIndex, firstEyePosition) && - getJointPosition(geometry.rightEyeJointIndex, secondEyePosition); -} - void Model::setURL(const QUrl& url, const QUrl& fallback, bool retainCurrent, bool delayLoad) { // don't recreate the geometry if it's the same URL if (_url == url) { @@ -1166,15 +1138,6 @@ void Model::updateJointState(int index) { state.combinedRotation = _rotation * combinedRotation; } else { const JointState& parentState = _jointStates.at(joint.parentIndex); - if (index == geometry.leanJointIndex) { - maybeUpdateLeanRotation(parentState, joint, state); - - } else if (index == geometry.neckJointIndex) { - maybeUpdateNeckRotation(parentState, joint, state); - - } else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) { - maybeUpdateEyeRotation(parentState, joint, state); - } glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation; state.transform = parentState.transform * glm::translate(state.translation) * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; @@ -1182,18 +1145,6 @@ void Model::updateJointState(int index) { } } -void Model::maybeUpdateLeanRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) { - // nothing by default -} - -void Model::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) { - // nothing by default -} - -void Model::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) { - // nothing by default -} - bool Model::setJointPosition(int jointIndex, const glm::vec3& translation, const glm::quat& rotation, bool useRotation, int lastFreeIndex, bool allIntermediatesFree, const glm::vec3& alignment, float priority) { if (jointIndex == -1 || _jointStates.isEmpty()) { diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 763cbdb577..a4e45287dd 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -121,22 +121,6 @@ public: /// Returns the index of the last free ancestor of the indexed joint, or -1 if not found. int getLastFreeJointIndex(int jointIndex) const; - /// Returns the position of the head joint. - /// \return whether or not the head was found - bool getHeadPosition(glm::vec3& headPosition) const; - - /// Returns the position of the neck joint. - /// \return whether or not the neck was found - bool getNeckPosition(glm::vec3& neckPosition) const; - - /// Returns the rotation of the neck joint's parent. - /// \return whether or not the neck was found - bool getNeckParentRotation(glm::quat& neckRotation) const; - - /// Retrieve the positions of up to two eye meshes. - /// \return whether or not both eye meshes were found - bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; - bool getJointPosition(int jointIndex, glm::vec3& position) const; bool getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind = false) const; @@ -234,10 +218,6 @@ protected: /// Updates the state of the joint at the specified index. virtual void updateJointState(int index); - virtual void maybeUpdateLeanRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); - virtual void maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); - virtual void maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state); - bool setJointPosition(int jointIndex, const glm::vec3& translation, const glm::quat& rotation = glm::quat(), bool useRotation = false, int lastFreeIndex = -1, bool allIntermediatesFree = false, const glm::vec3& alignment = glm::vec3(0.0f, -1.0f, 0.0f), float priority = 1.0f);