From 164192fb508bb356b13928a4a76b941cf5e0175f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 30 May 2014 11:03:46 -0700 Subject: [PATCH] If the skeleton doesn't have eye joints (as with the Fuse models), make up some positions based on the head and neck joints. --- interface/src/avatar/SkeletonModel.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 3586e525ae..ef5fc3d34b 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -427,7 +427,25 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco return false; } const FBXGeometry& geometry = _geometry->getFBXGeometry(); - return getJointPosition(geometry.leftEyeJointIndex, firstEyePosition) && - getJointPosition(geometry.rightEyeJointIndex, secondEyePosition); + if (getJointPosition(geometry.leftEyeJointIndex, firstEyePosition) && + getJointPosition(geometry.rightEyeJointIndex, secondEyePosition)) { + return true; + } + // no eye joints; try to estimate based on head/neck joints + glm::vec3 neckPosition, headPosition; + if (getJointPosition(geometry.neckJointIndex, neckPosition) && + getJointPosition(geometry.headJointIndex, headPosition)) { + const float EYE_PROPORTION = 0.6f; + glm::vec3 baseEyePosition = glm::mix(neckPosition, headPosition, EYE_PROPORTION); + glm::quat headRotation; + getJointRotation(geometry.headJointIndex, headRotation); + const float EYES_FORWARD = 0.25f; + const float EYE_SEPARATION = 0.1f; + float headHeight = glm::distance(neckPosition, headPosition); + firstEyePosition = baseEyePosition + headRotation * glm::vec3(EYE_SEPARATION, 0.0f, EYES_FORWARD) * headHeight; + secondEyePosition = baseEyePosition + headRotation * glm::vec3(-EYE_SEPARATION, 0.0f, EYES_FORWARD) * headHeight; + return true; + } + return false; }