History

merge from upstream

Seth Alves committed 10 years ago

Commit b7ebe5b2 parents 3402585 6f50d9172 files · +2573 −4128Browse files

Showing the changes to libraries/render-utils/src/Model.cpp (1 of 72 files). Show all

Unified · Split

libraries/render-utils/src/Model.cpp+16−69
@@ -22,7 +22,6 @@ · 21 unmodified lines
2222 #include <ViewFrustum.h>
2323
2424 #include "AbstractViewStateInterface.h"
25−#include "AnimationHandle.h"
2625 #include "Model.h"
2726 #include "MeshPartPayload.h"
2827
@@ -91,6 +90,8 @@ void Model::setScale(const glm::vec3& scale) { · 62 unmodified lines
9190 _scaledToFit = false;
9291 }
9392
93+const float METERS_PER_MILLIMETER = 0.01f;
94+
9495 void Model::setScaleInternal(const glm::vec3& scale) {
9596 if (glm::distance(_scale, scale) > METERS_PER_MILLIMETER) {
9697 _scale = scale;
@@ -120,24 +121,12 @@ void Model::enqueueLocationChange() { · 23 unmodified lines
120121 scene->enqueuePendingChanges(pendingChanges);
121122 }
122123
123−QVector<JointState> Model::createJointStates(const FBXGeometry& geometry) {
124− QVector<JointState> jointStates;
125− for (int i = 0; i < geometry.joints.size(); ++i) {
126− const FBXJoint& joint = geometry.joints[i];
127− // store a pointer to the FBXJoint in the JointState
128− JointState state(joint);
129− jointStates.append(state);
130− }
131− return jointStates;
132−};
133−
134124 void Model::initJointTransforms() {
135125 if (!_geometry || !_geometry->isLoaded()) {
136126 return;
137127 }
138− const FBXGeometry& geometry = _geometry->getFBXGeometry();
139− glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
140− _rig->initJointTransforms(parentTransform);
128+ glm::mat4 modelOffset = glm::scale(_scale) * glm::translate(_offset);
129+ _rig->setModelOffset(modelOffset);
141130 }
142131
143132 void Model::init() {
@@ -146,14 +135,13 @@ void Model::init() { · 2 unmodified lines
146135 void Model::reset() {
147136 if (_geometry && _geometry->isLoaded()) {
148137 const FBXGeometry& geometry = _geometry->getFBXGeometry();
149− _rig->reset(geometry.joints);
138+ _rig->reset(geometry);
150139 }
151140 }
152141
153142 bool Model::updateGeometry() {
154143 PROFILE_RANGE(__FUNCTION__);
155144 bool needFullUpdate = false;
156− bool needToRebuild = false;
157145
158146 if (!_geometry || !_geometry->isLoaded()) {
159147 // geometry is not ready
@@ -162,17 +150,10 @@ bool Model::updateGeometry() { · 2 unmodified lines
162150
163151 _needsReload = false;
164152
165− QSharedPointer<NetworkGeometry> geometry = _geometry;
166− if (_rig->jointStatesEmpty()) {
167− const FBXGeometry& fbxGeometry = geometry->getFBXGeometry();
168− if (fbxGeometry.joints.size() > 0) {
169− initJointStates(createJointStates(fbxGeometry));
170− needToRebuild = true;
171− }
172− }
153+ if (_rig->jointStatesEmpty() && _geometry->getFBXGeometry().joints.size() > 0) {
154+ initJointStates();
173155
174− if (needToRebuild) {
175− const FBXGeometry& fbxGeometry = geometry->getFBXGeometry();
156+ const FBXGeometry& fbxGeometry = _geometry->getFBXGeometry();
176157 foreach (const FBXMesh& mesh, fbxGeometry.meshes) {
177158 MeshState state;
178159 state.clusterMatrices.resize(mesh.clusters.size());
@@ -195,26 +176,11 @@ bool Model::updateGeometry() { · 16 unmodified lines
195176 }
196177
197178 // virtual
198−void Model::initJointStates(QVector<JointState> states) {
179+void Model::initJointStates() {
199180 const FBXGeometry& geometry = _geometry->getFBXGeometry();
200− glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
201−
202− int rootJointIndex = geometry.rootJointIndex;
203− int leftHandJointIndex = geometry.leftHandJointIndex;
204− int leftElbowJointIndex = leftHandJointIndex >= 0 ? geometry.joints.at(leftHandJointIndex).parentIndex : -1;
205− int leftShoulderJointIndex = leftElbowJointIndex >= 0 ? geometry.joints.at(leftElbowJointIndex).parentIndex : -1;
206− int rightHandJointIndex = geometry.rightHandJointIndex;
207− int rightElbowJointIndex = rightHandJointIndex >= 0 ? geometry.joints.at(rightHandJointIndex).parentIndex : -1;
208− int rightShoulderJointIndex = rightElbowJointIndex >= 0 ? geometry.joints.at(rightElbowJointIndex).parentIndex : -1;
209−
210− _rig->initJointStates(states, parentTransform,
211− rootJointIndex,
212− leftHandJointIndex,
213− leftElbowJointIndex,
214− leftShoulderJointIndex,
215− rightHandJointIndex,
216− rightElbowJointIndex,
217− rightShoulderJointIndex);
181+ glm::mat4 modelOffset = glm::scale(_scale) * glm::translate(_offset);
182+
183+ _rig->initJointStates(geometry, modelOffset);
218184 }
219185
220186 bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance,
@@ -856,6 +822,7 @@ void Blender::run() { · 635 unmodified lines
856822 const float NORMAL_COEFFICIENT_SCALE = 0.01f;
857823 for (int i = 0, n = qMin(_blendshapeCoefficients.size(), mesh.blendshapes.size()); i < n; i++) {
858824 float vertexCoefficient = _blendshapeCoefficients.at(i);
825+ const float EPSILON = 0.0001f;
859826 if (vertexCoefficient < EPSILON) {
860827 continue;
861828 }
@@ -983,9 +950,7 @@ void Model::updateRig(float deltaTime, glm::mat4 parentTransform) { · 121 unmodified lines
983950 }
984951 void Model::simulateInternal(float deltaTime) {
985952 // update the world space transforms for all joints
986−
987− const FBXGeometry& geometry = _geometry->getFBXGeometry();
988− glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
953+ glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset);
989954 updateRig(deltaTime, parentTransform);
990955 }
991956 void Model::updateClusterMatrices(glm::vec3 modelPosition, glm::quat modelOrientation) {
@@ -1051,22 +1016,10 @@ void Model::updateClusterMatrices(glm::vec3 modelPosition, glm::quat modelOrient · 59 unmodified lines
10511016 }
10521017 }
10531018
1054−bool Model::setJointPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation, bool useRotation,
1055− int lastFreeIndex, bool allIntermediatesFree, const glm::vec3& alignment, float priority) {
1056− const FBXGeometry& geometry = _geometry->getFBXGeometry();
1057− const QVector<int>& freeLineage = geometry.joints.at(jointIndex).freeLineage;
1058− glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
1059− if (_rig->setJointPosition(jointIndex, position, rotation, useRotation,
1060− lastFreeIndex, allIntermediatesFree, alignment, priority, freeLineage, parentTransform)) {
1061− return true;
1062− }
1063− return false;
1064−}
1065−
10661019 void Model::inverseKinematics(int endIndex, glm::vec3 targetPosition, const glm::quat& targetRotation, float priority) {
10671020 const FBXGeometry& geometry = _geometry->getFBXGeometry();
10681021 const QVector<int>& freeLineage = geometry.joints.at(endIndex).freeLineage;
1069− glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
1022+ glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset);
10701023 _rig->inverseKinematics(endIndex, targetPosition, targetRotation, priority, freeLineage, parentTransform);
10711024 }
10721025
@@ -1125,11 +1078,7 @@ void Model::setGeometry(const QSharedPointer<NetworkGeometry>& newGeometry) { · 52 unmodified lines
11251078 void Model::deleteGeometry() {
11261079 _blendedVertexBuffers.clear();
11271080 _meshStates.clear();
1128− if (_rig) {
1129− _rig->clearJointStates();
1130− _rig->deleteAnimations();
1131− _rig->destroyAnimGraph();
1132− }
1081+ _rig->destroyAnimGraph();
11331082 _blendedBlendshapeCoefficients.clear();
11341083 }
11351084
@@ -1177,8 +1126,6 @@ void Model::segregateMeshGroups() { · 41 unmodified lines
11771126 const FBXGeometry& geometry = networkGeometry->getFBXGeometry();
11781127 const std::vector<std::unique_ptr<NetworkMesh>>& networkMeshes = networkGeometry->getMeshes();
11791128
1180− _rig->makeAnimSkeleton(geometry);
1181−
11821129 // all of our mesh vectors must match in size
11831130 if ((int)networkMeshes.size() != geometry.meshes.size() ||
11841131 geometry.meshes.size() != _meshStates.size()) {