Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 9 files). Show all
Unified · Split
| @@ -40,8 +40,7 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer r · 39 unmodified lines | ||
| 40 | 40 | _standingFoot(NO_FOOT), |
| 41 | 41 | _standingOffset(0.0f), |
| 42 | 42 | _clampedFootPosition(0.0f), |
| 43 | − _headClipDistance(DEFAULT_NEAR_CLIP), | |
| 44 | − _isFirstPerson(false) | |
| 43 | + _headClipDistance(DEFAULT_NEAR_CLIP) | |
| 45 | 44 | { |
| 46 | 45 | assert(_rig); |
| 47 | 46 | assert(_owningAvatar); |
| @@ -54,7 +53,7 @@ SkeletonModel::~SkeletonModel() { · 6 unmodified lines | ||
| 54 | 53 | void SkeletonModel::initJointStates(QVector<JointState> states) { |
| 55 | 54 | const FBXGeometry& geometry = _geometry->getFBXGeometry(); |
| 56 | 55 | glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset; |
| 57 | − _boundingRadius = _rig->initJointStates(states, parentTransform); | |
| 56 | + _boundingRadius = _rig->initJointStates(states, parentTransform, geometry.neckJointIndex); | |
| 58 | 57 | |
| 59 | 58 | // Determine the default eye position for avatar scale = 1.0 |
| 60 | 59 | int headJointIndex = _geometry->getFBXGeometry().headJointIndex; |
| @@ -98,6 +97,29 @@ void SkeletonModel::initJointStates(QVector<JointState> states) { · 37 unmodified lines | ||
| 98 | 97 | const float PALM_PRIORITY = DEFAULT_PRIORITY; |
| 99 | 98 | const float LEAN_PRIORITY = DEFAULT_PRIORITY; |
| 100 | 99 | |
| 100 | + | |
| 101 | +void SkeletonModel::updateClusterMatrices() { | |
| 102 | + const FBXGeometry& geometry = _geometry->getFBXGeometry(); | |
| 103 | + glm::mat4 modelToWorld = glm::mat4_cast(_rotation); | |
| 104 | + for (int i = 0; i < _meshStates.size(); i++) { | |
| 105 | + MeshState& state = _meshStates[i]; | |
| 106 | + const FBXMesh& mesh = geometry.meshes.at(i); | |
| 107 | + if (_showTrueJointTransforms) { | |
| 108 | + for (int j = 0; j < mesh.clusters.size(); j++) { | |
| 109 | + const FBXCluster& cluster = mesh.clusters.at(j); | |
| 110 | + state.clusterMatrices[j] = | |
| 111 | + modelToWorld * _rig->getJointTransform(cluster.jointIndex) * cluster.inverseBindMatrix; | |
| 112 | + } | |
| 113 | + } else { | |
| 114 | + for (int j = 0; j < mesh.clusters.size(); j++) { | |
| 115 | + const FBXCluster& cluster = mesh.clusters.at(j); | |
| 116 | + state.clusterMatrices[j] = | |
| 117 | + modelToWorld * _rig->getJointVisibleTransform(cluster.jointIndex) * cluster.inverseBindMatrix; | |
| 118 | + } | |
| 119 | + } | |
| 120 | + } | |
| 121 | +} | |
| 122 | + | |
| 101 | 123 | void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { |
| 102 | 124 | setTranslation(_owningAvatar->getSkeletonPosition()); |
| 103 | 125 | static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); |
| @@ -154,8 +176,11 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 50 unmodified lines | ||
| 154 | 176 | } |
| 155 | 177 | } |
| 156 | 178 | |
| 157 | − if (_isFirstPerson) { | |
| 158 | − cauterizeHead(); | |
| 179 | + // if (_isFirstPerson) { | |
| 180 | + // cauterizeHead(); | |
| 181 | + // updateClusterMatrices(); | |
| 182 | + // } | |
| 183 | + if (_rig->getJointsAreDirty()) { | |
| 159 | 184 | updateClusterMatrices(); |
| 160 | 185 | } |
| 161 | 186 | |
| @@ -764,7 +789,7 @@ void SkeletonModel::resetShapePositionsToDefaultPose() { · 602 unmodified lines | ||
| 764 | 789 | // geometry or joints have not yet been created |
| 765 | 790 | return; |
| 766 | 791 | } |
| 767 | − | |
| 792 | + | |
| 768 | 793 | const FBXGeometry& geometry = _geometry->getFBXGeometry(); |
| 769 | 794 | if (geometry.joints.isEmpty()) { |
| 770 | 795 | return; |
| @@ -820,7 +845,7 @@ void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha · 49 unmodified lines | ||
| 820 | 845 | |
| 821 | 846 | // draw a green cylinder between the two points |
| 822 | 847 | glm::vec3 origin(0.0f); |
| 823 | − Avatar::renderJointConnectingCone(batch, origin, axis, _boundingShape.getRadius(), _boundingShape.getRadius(), | |
| 848 | + Avatar::renderJointConnectingCone(batch, origin, axis, _boundingShape.getRadius(), _boundingShape.getRadius(), | |
| 824 | 849 | glm::vec4(0.6f, 0.8f, 0.6f, alpha)); |
| 825 | 850 | } |
| 826 | 851 | |
| @@ -828,56 +853,5 @@ bool SkeletonModel::hasSkeleton() { · 1 unmodified line | ||
| 828 | 853 | return isActive() ? _geometry->getFBXGeometry().rootJointIndex != -1 : false; |
| 829 | 854 | } |
| 830 | 855 | |
| 831 | −void SkeletonModel::initHeadBones() { | |
| 832 | − _headBones.clear(); | |
| 833 | − const FBXGeometry& fbxGeometry = _geometry->getFBXGeometry(); | |
| 834 | − const int neckJointIndex = fbxGeometry.neckJointIndex; | |
| 835 | − std::queue<int> q; | |
| 836 | − q.push(neckJointIndex); | |
| 837 | − _headBones.push_back(neckJointIndex); | |
| 838 | − | |
| 839 | − // fbxJoints only hold links to parents not children, so we have to do a bit of extra work here. | |
| 840 | − while (q.size() > 0) { | |
| 841 | − int jointIndex = q.front(); | |
| 842 | − for (int i = 0; i < fbxGeometry.joints.size(); i++) { | |
| 843 | − const FBXJoint& fbxJoint = fbxGeometry.joints[i]; | |
| 844 | − if (jointIndex == fbxJoint.parentIndex) { | |
| 845 | − _headBones.push_back(i); | |
| 846 | − q.push(i); | |
| 847 | − } | |
| 848 | − } | |
| 849 | − q.pop(); | |
| 850 | − } | |
| 851 | −} | |
| 852 | − | |
| 853 | −void SkeletonModel::invalidateHeadBones() { | |
| 854 | − _headBones.clear(); | |
| 855 | −} | |
| 856 | − | |
| 857 | −void SkeletonModel::cauterizeHead() { | |
| 858 | − if (isActive()) { | |
| 859 | − const FBXGeometry& geometry = _geometry->getFBXGeometry(); | |
| 860 | − const int neckJointIndex = geometry.neckJointIndex; | |
| 861 | − if (neckJointIndex > 0 && neckJointIndex < _rig->getJointStateCount()) { | |
| 862 | − | |
| 863 | − // lazy init of headBones | |
| 864 | − if (_headBones.size() == 0) { | |
| 865 | − initHeadBones(); | |
| 866 | − } | |
| 867 | − | |
| 868 | − // preserve the translation for the neck | |
| 869 | − // glm::vec4 trans = _jointStates[neckJointIndex].getTransform()[3]; | |
| 870 | − glm::vec4 trans = _rig->getJointTransform(neckJointIndex)[3]; | |
| 871 | − glm::vec4 zero(0, 0, 0, 0); | |
| 872 | − for (const int &i : _headBones) { | |
| 873 | − glm::mat4 newXform(zero, zero, zero, trans); | |
| 874 | − _rig->setJointTransform(i, newXform); | |
| 875 | − _rig->setJointVisibleTransform(i, newXform); | |
| 876 | − } | |
| 877 | − } | |
| 878 | − } | |
| 879 | −} | |
| 880 | − | |
| 881 | 856 | void SkeletonModel::onInvalidate() { |
| 882 | − invalidateHeadBones(); | |
| 883 | 857 | } |