History

Merge remote-tracking branch 'upstream/master' into plugins

Brad Davis committed 11 years ago

Commit 4417c002 parents a5428ae 8a6ab68128 files · +3167 −2493Browse files

Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 128 files). Show all

Unified · Split

interface/src/avatar/SkeletonModel.cpp+63−2
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include "Menu.h"
2222 #include "SkeletonModel.h"
2323 #include "Util.h"
24+#include "InterfaceLogging.h"
2425
2526 enum StandingFootState {
2627 LEFT_FOOT,
@@ -38,7 +39,8 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) : · 11 unmodified lines
3839 _standingFoot(NO_FOOT),
3940 _standingOffset(0.0f),
4041 _clampedFootPosition(0.0f),
41− _headClipDistance(DEFAULT_NEAR_CLIP)
42+ _headClipDistance(DEFAULT_NEAR_CLIP),
43+ _isFirstPerson(false)
4244 {
4345 assert(_owningAvatar);
4446 _enableShapes = true;
@@ -98,7 +100,7 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 53 unmodified lines
98100 setRotation(_owningAvatar->getOrientation() * refOrientation);
99101 setScale(glm::vec3(1.0f, 1.0f, 1.0f) * _owningAvatar->getScale());
100102 setBlendshapeCoefficients(_owningAvatar->getHead()->getBlendshapeCoefficients());
101−
103+
102104 Model::simulate(deltaTime, fullUpdate);
103105
104106 if (!isActive() || !_owningAvatar->isMyAvatar()) {
@@ -140,6 +142,11 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 35 unmodified lines
140142 applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]);
141143 }
142144
145+ if (_isFirstPerson) {
146+ cauterizeHead();
147+ updateClusterMatrices();
148+ }
149+
143150 _boundingShape.setTranslation(_translation + _rotation * _boundingShapeLocalOffset);
144151 _boundingShape.setRotation(_rotation);
145152 }
@@ -808,3 +815,57 @@ void SkeletonModel::renderBoundingCollisionShapes(float alpha) { · 662 unmodified lines
808815 bool SkeletonModel::hasSkeleton() {
809816 return isActive() ? _geometry->getFBXGeometry().rootJointIndex != -1 : false;
810817 }
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+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t