History

get rid of _firstPersonSkeletonModel in MyAvatar. add flag in Rig for joints being dirty so Model knows when to recompute meshes

Seth Alves committed 11 years ago

Commit 33c97a11 parent 4566d169 files · +137 −140Browse files

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

Unified · Split

interface/src/avatar/SkeletonModel.cpp+32−58
@@ -40,8 +40,7 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer r · 39 unmodified lines
4040 _standingFoot(NO_FOOT),
4141 _standingOffset(0.0f),
4242 _clampedFootPosition(0.0f),
43− _headClipDistance(DEFAULT_NEAR_CLIP),
44− _isFirstPerson(false)
43+ _headClipDistance(DEFAULT_NEAR_CLIP)
4544 {
4645 assert(_rig);
4746 assert(_owningAvatar);
@@ -54,7 +53,7 @@ SkeletonModel::~SkeletonModel() { · 6 unmodified lines
5453 void SkeletonModel::initJointStates(QVector<JointState> states) {
5554 const FBXGeometry& geometry = _geometry->getFBXGeometry();
5655 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);
5857
5958 // Determine the default eye position for avatar scale = 1.0
6059 int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
@@ -98,6 +97,29 @@ void SkeletonModel::initJointStates(QVector<JointState> states) { · 37 unmodified lines
9897 const float PALM_PRIORITY = DEFAULT_PRIORITY;
9998 const float LEAN_PRIORITY = DEFAULT_PRIORITY;
10099
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+
101123 void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
102124 setTranslation(_owningAvatar->getSkeletonPosition());
103125 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
154176 }
155177 }
156178
157− if (_isFirstPerson) {
158− cauterizeHead();
179+ // if (_isFirstPerson) {
180+ // cauterizeHead();
181+ // updateClusterMatrices();
182+ // }
183+ if (_rig->getJointsAreDirty()) {
159184 updateClusterMatrices();
160185 }
161186
@@ -764,7 +789,7 @@ void SkeletonModel::resetShapePositionsToDefaultPose() { · 602 unmodified lines
764789 // geometry or joints have not yet been created
765790 return;
766791 }
767−
792+
768793 const FBXGeometry& geometry = _geometry->getFBXGeometry();
769794 if (geometry.joints.isEmpty()) {
770795 return;
@@ -820,7 +845,7 @@ void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha · 49 unmodified lines
820845
821846 // draw a green cylinder between the two points
822847 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(),
824849 glm::vec4(0.6f, 0.8f, 0.6f, alpha));
825850 }
826851
@@ -828,56 +853,5 @@ bool SkeletonModel::hasSkeleton() { · 1 unmodified line
828853 return isActive() ? _geometry->getFBXGeometry().rootJointIndex != -1 : false;
829854 }
830855
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−
881856 void SkeletonModel::onInvalidate() {
882− invalidateHeadBones();
883857 }

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