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
40 _standingFoot(NO_FOOT),40 _standingFoot(NO_FOOT),
41 _standingOffset(0.0f),41 _standingOffset(0.0f),
42 _clampedFootPosition(0.0f),42 _clampedFootPosition(0.0f),
43 _headClipDistance(DEFAULT_NEAR_CLIP),43 _headClipDistance(DEFAULT_NEAR_CLIP)
44 _isFirstPerson(false)
45{44{
46 assert(_rig);45 assert(_rig);
47 assert(_owningAvatar);46 assert(_owningAvatar);
@@ -54,7 +53,7 @@ SkeletonModel::~SkeletonModel() { · 6 unmodified lines
54void SkeletonModel::initJointStates(QVector<JointState> states) {53void SkeletonModel::initJointStates(QVector<JointState> states) {
55 const FBXGeometry& geometry = _geometry->getFBXGeometry();54 const FBXGeometry& geometry = _geometry->getFBXGeometry();
56 glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;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 // Determine the default eye position for avatar scale = 1.058 // Determine the default eye position for avatar scale = 1.0
60 int headJointIndex = _geometry->getFBXGeometry().headJointIndex;59 int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
@@ -98,6 +97,29 @@ void SkeletonModel::initJointStates(QVector<JointState> states) { · 37 unmodified lines
98const float PALM_PRIORITY = DEFAULT_PRIORITY;97const float PALM_PRIORITY = DEFAULT_PRIORITY;
99const float LEAN_PRIORITY = DEFAULT_PRIORITY;98const float LEAN_PRIORITY = DEFAULT_PRIORITY;
100 99
100
101void 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
101void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {123void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
102 setTranslation(_owningAvatar->getSkeletonPosition());124 setTranslation(_owningAvatar->getSkeletonPosition());
103 static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));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) {179 // if (_isFirstPerson) {
158 cauterizeHead();180 // cauterizeHead();
181 // updateClusterMatrices();
182 // }
183 if (_rig->getJointsAreDirty()) {
159 updateClusterMatrices();184 updateClusterMatrices();
160 }185 }
161 186
@@ -764,7 +789,7 @@ void SkeletonModel::resetShapePositionsToDefaultPose() { · 602 unmodified lines
764 // geometry or joints have not yet been created789 // geometry or joints have not yet been created
765 return;790 return;
766 }791 }
767 792
768 const FBXGeometry& geometry = _geometry->getFBXGeometry();793 const FBXGeometry& geometry = _geometry->getFBXGeometry();
769 if (geometry.joints.isEmpty()) {794 if (geometry.joints.isEmpty()) {
770 return;795 return;
@@ -820,7 +845,7 @@ void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha · 49 unmodified lines
820 845
821 // draw a green cylinder between the two points846 // draw a green cylinder between the two points
822 glm::vec3 origin(0.0f);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 glm::vec4(0.6f, 0.8f, 0.6f, alpha));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 return isActive() ? _geometry->getFBXGeometry().rootJointIndex != -1 : false;853 return isActive() ? _geometry->getFBXGeometry().rootJointIndex != -1 : false;
829}854}
830 855
831void 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
853void SkeletonModel::invalidateHeadBones() {
854 _headBones.clear();
855}
856
857void 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
881void SkeletonModel::onInvalidate() {856void SkeletonModel::onInvalidate() {
882 invalidateHeadBones();
883}857}

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