Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 128 files). Show all
Unified · Split
| @@ -21,6 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | #include "Menu.h" |
| 22 | 22 | #include "SkeletonModel.h" |
| 23 | 23 | #include "Util.h" |
| 24 | +#include "InterfaceLogging.h" | |
| 24 | 25 | |
| 25 | 26 | enum StandingFootState { |
| 26 | 27 | LEFT_FOOT, |
| @@ -38,7 +39,8 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) : · 11 unmodified lines | ||
| 38 | 39 | _standingFoot(NO_FOOT), |
| 39 | 40 | _standingOffset(0.0f), |
| 40 | 41 | _clampedFootPosition(0.0f), |
| 41 | − _headClipDistance(DEFAULT_NEAR_CLIP) | |
| 42 | + _headClipDistance(DEFAULT_NEAR_CLIP), | |
| 43 | + _isFirstPerson(false) | |
| 42 | 44 | { |
| 43 | 45 | assert(_owningAvatar); |
| 44 | 46 | _enableShapes = true; |
| @@ -98,7 +100,7 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 53 unmodified lines | ||
| 98 | 100 | setRotation(_owningAvatar->getOrientation() * refOrientation); |
| 99 | 101 | setScale(glm::vec3(1.0f, 1.0f, 1.0f) * _owningAvatar->getScale()); |
| 100 | 102 | setBlendshapeCoefficients(_owningAvatar->getHead()->getBlendshapeCoefficients()); |
| 101 | − | |
| 103 | + | |
| 102 | 104 | Model::simulate(deltaTime, fullUpdate); |
| 103 | 105 | |
| 104 | 106 | if (!isActive() || !_owningAvatar->isMyAvatar()) { |
| @@ -140,6 +142,11 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 35 unmodified lines | ||
| 140 | 142 | applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]); |
| 141 | 143 | } |
| 142 | 144 | |
| 145 | + if (_isFirstPerson) { | |
| 146 | + cauterizeHead(); | |
| 147 | + updateClusterMatrices(); | |
| 148 | + } | |
| 149 | + | |
| 143 | 150 | _boundingShape.setTranslation(_translation + _rotation * _boundingShapeLocalOffset); |
| 144 | 151 | _boundingShape.setRotation(_rotation); |
| 145 | 152 | } |
| @@ -808,3 +815,57 @@ void SkeletonModel::renderBoundingCollisionShapes(float alpha) { · 662 unmodified lines | ||
| 808 | 815 | bool SkeletonModel::hasSkeleton() { |
| 809 | 816 | return isActive() ? _geometry->getFBXGeometry().rootJointIndex != -1 : false; |
| 810 | 817 | } |
| 818 | + | |
| 819 | +void SkeletonModel::initHeadBones() { | |
| 820 | + _headBones.clear(); | |
| 821 | + const FBXGeometry& fbxGeometry = _geometry->getFBXGeometry(); | |
| 822 | + const int neckJointIndex = fbxGeometry.neckJointIndex; | |
| 823 | + std::queue<int> q; | |
| 824 | + q.push(neckJointIndex); | |
| 825 | + _headBones.push_back(neckJointIndex); | |
| 826 | + | |
| 827 | + // fbxJoints only hold links to parents not children, so we have to do a bit of extra work here. | |
| 828 | + while (q.size() > 0) { | |
| 829 | + int jointIndex = q.front(); | |
| 830 | + for (int i = 0; i < fbxGeometry.joints.size(); i++) { | |
| 831 | + const FBXJoint& fbxJoint = fbxGeometry.joints[i]; | |
| 832 | + if (jointIndex == fbxJoint.parentIndex) { | |
| 833 | + _headBones.push_back(i); | |
| 834 | + q.push(i); | |
| 835 | + } | |
| 836 | + } | |
| 837 | + q.pop(); | |
| 838 | + } | |
| 839 | +} | |
| 840 | + | |
| 841 | +void SkeletonModel::invalidateHeadBones() { | |
| 842 | + _headBones.clear(); | |
| 843 | +} | |
| 844 | + | |
| 845 | +void SkeletonModel::cauterizeHead() { | |
| 846 | + if (isActive()) { | |
| 847 | + const FBXGeometry& geometry = _geometry->getFBXGeometry(); | |
| 848 | + const int neckJointIndex = geometry.neckJointIndex; | |
| 849 | + if (neckJointIndex > 0 && neckJointIndex < _jointStates.size()) { | |
| 850 | + | |
| 851 | + // lazy init of headBones | |
| 852 | + if (_headBones.size() == 0) { | |
| 853 | + initHeadBones(); | |
| 854 | + } | |
| 855 | + | |
| 856 | + // preserve the translation for the neck | |
| 857 | + glm::vec4 trans = _jointStates[neckJointIndex].getTransform()[3]; | |
| 858 | + glm::vec4 zero(0, 0, 0, 0); | |
| 859 | + for (const int &i : _headBones) { | |
| 860 | + JointState& joint = _jointStates[i]; | |
| 861 | + glm::mat4 newXform(zero, zero, zero, trans); | |
| 862 | + joint.setTransform(newXform); | |
| 863 | + joint.setVisibleTransform(newXform); | |
| 864 | + } | |
| 865 | + } | |
| 866 | + } | |
| 867 | +} | |
| 868 | + | |
| 869 | +void SkeletonModel::onInvalidate() { | |
| 870 | + invalidateHeadBones(); | |
| 871 | +} | |