Showing the changes to interface/src/avatar/MySkeletonModel.cpp (1 of 888 files). Show all
Unified · Split
| @@ -36,9 +36,6 @@ Rig::CharacterControllerState convertCharacterControllerState(CharacterControlle · 35 unmodified lines | ||
| 36 | 36 | static AnimPose computeHipsInSensorFrame(MyAvatar* myAvatar, bool isFlying) { |
| 37 | 37 | glm::mat4 worldToSensorMat = glm::inverse(myAvatar->getSensorToWorldMatrix()); |
| 38 | 38 | |
| 39 | − //experiment to fix crazy legs. | |
| 40 | − glm::vec3 floorPosition = transformPoint(myAvatar->getSensorToWorldMatrix(), glm::vec3(0.0f, 0.0f, 0.0f)); | |
| 41 | − | |
| 42 | 39 | // check for pinned hips. |
| 43 | 40 | auto hipsIndex = myAvatar->getJointIndex("Hips"); |
| 44 | 41 | if (myAvatar->isJointPinned(hipsIndex)) { |
| @@ -59,14 +56,6 @@ static AnimPose computeHipsInSensorFrame(MyAvatar* myAvatar, bool isFlying) { · 14 unmodified lines | ||
| 59 | 56 | glm::vec3 hipsPos = extractTranslation(hipsMat); |
| 60 | 57 | glm::quat hipsRot = glmExtractRotation(hipsMat); |
| 61 | 58 | |
| 62 | − // if we are less the floor with the hips then lock them to the floor. | |
| 63 | − // if, if that is, we are using cg or hmd lean is off. | |
| 64 | − if (myAvatar->getCenterOfGravityModelEnabled() || !myAvatar->getHMDLeanRecenterEnabled()) { | |
| 65 | − if (hipsPos.y < 0.02f) { | |
| 66 | − hipsPos.y = 0.02f; | |
| 67 | − } | |
| 68 | − } | |
| 69 | − | |
| 70 | 59 | |
| 71 | 60 | glm::mat4 avatarToWorldMat = myAvatar->getTransform().getMatrix(); |
| 72 | 61 | glm::mat4 avatarToSensorMat = worldToSensorMat * avatarToWorldMat; |
| @@ -101,7 +90,7 @@ static AnimPose computeHipsInSensorFrame(MyAvatar* myAvatar, bool isFlying) { · 28 unmodified lines | ||
| 101 | 90 | |
| 102 | 91 | // Called within Model::simulate call, below. |
| 103 | 92 | void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { |
| 104 | − const FBXGeometry& geometry = getFBXGeometry(); | |
| 93 | + const HFMModel& hfmModel = getHFMModel(); | |
| 105 | 94 | |
| 106 | 95 | Head* head = _owningAvatar->getHead(); |
| 107 | 96 | |
| @@ -211,49 +200,38 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { · 103 unmodified lines | ||
| 211 | 200 | if (avatarHeadPose.isValid() && !(params.primaryControllerFlags[Rig::PrimaryControllerType_Hips] & (uint8_t)Rig::ControllerFlags::Enabled)) { |
| 212 | 201 | bool isFlying = (myAvatar->getCharacterController()->getState() == CharacterController::State::Hover || myAvatar->getCharacterController()->computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS); |
| 213 | 202 | |
| 214 | − if (!_prevHipsValid) { | |
| 215 | − AnimPose hips = computeHipsInSensorFrame(myAvatar, isFlying); | |
| 216 | − _prevHips = hips; | |
| 217 | − } | |
| 218 | − | |
| 219 | − AnimPose hips = computeHipsInSensorFrame(myAvatar, isFlying); | |
| 220 | − | |
| 221 | 203 | // timescale in seconds |
| 222 | 204 | const float TRANS_HORIZ_TIMESCALE = 0.15f; |
| 223 | 205 | const float TRANS_VERT_TIMESCALE = 0.01f; // We want the vertical component of the hips to follow quickly to prevent spine squash/stretch. |
| 224 | 206 | const float ROT_TIMESCALE = 0.15f; |
| 225 | 207 | const float FLY_IDLE_TRANSITION_TIMESCALE = 0.25f; |
| 226 | 208 | |
| 227 | − float transHorizAlpha, transVertAlpha, rotAlpha; | |
| 228 | 209 | if (_flyIdleTimer < 0.0f) { |
| 229 | − transHorizAlpha = glm::min(deltaTime / TRANS_HORIZ_TIMESCALE, 1.0f); | |
| 230 | − transVertAlpha = glm::min(deltaTime / TRANS_VERT_TIMESCALE, 1.0f); | |
| 231 | − rotAlpha = glm::min(deltaTime / ROT_TIMESCALE, 1.0f); | |
| 210 | + _smoothHipsHelper.setHorizontalTranslationTimescale(TRANS_HORIZ_TIMESCALE); | |
| 211 | + _smoothHipsHelper.setVerticalTranslationTimescale(TRANS_VERT_TIMESCALE); | |
| 212 | + _smoothHipsHelper.setRotationTimescale(ROT_TIMESCALE); | |
| 232 | 213 | } else { |
| 233 | − transHorizAlpha = glm::min(deltaTime / FLY_IDLE_TRANSITION_TIMESCALE, 1.0f); | |
| 234 | − transVertAlpha = glm::min(deltaTime / FLY_IDLE_TRANSITION_TIMESCALE, 1.0f); | |
| 235 | − rotAlpha = glm::min(deltaTime / FLY_IDLE_TRANSITION_TIMESCALE, 1.0f); | |
| 214 | + _smoothHipsHelper.setHorizontalTranslationTimescale(FLY_IDLE_TRANSITION_TIMESCALE); | |
| 215 | + _smoothHipsHelper.setVerticalTranslationTimescale(FLY_IDLE_TRANSITION_TIMESCALE); | |
| 216 | + _smoothHipsHelper.setRotationTimescale(FLY_IDLE_TRANSITION_TIMESCALE); | |
| 236 | 217 | } |
| 237 | 218 | |
| 238 | − // smootly lerp hips, in sensorframe, with different coeff for horiz and vertical translation. | |
| 239 | − float hipsY = hips.trans().y; | |
| 240 | − hips.trans() = lerp(_prevHips.trans(), hips.trans(), transHorizAlpha); | |
| 241 | − hips.trans().y = lerp(_prevHips.trans().y, hipsY, transVertAlpha); | |
| 242 | − hips.rot() = safeLerp(_prevHips.rot(), hips.rot(), rotAlpha); | |
| 243 | − | |
| 244 | − _prevHips = hips; | |
| 245 | − _prevHipsValid = true; | |
| 219 | + AnimPose sensorHips = computeHipsInSensorFrame(myAvatar, isFlying); | |
| 220 | + if (!_prevIsEstimatingHips) { | |
| 221 | + _smoothHipsHelper.teleport(sensorHips); | |
| 222 | + } | |
| 223 | + sensorHips = _smoothHipsHelper.update(sensorHips, deltaTime); | |
| 246 | 224 | |
| 247 | 225 | glm::mat4 invRigMat = glm::inverse(myAvatar->getTransform().getMatrix() * Matrices::Y_180); |
| 248 | 226 | AnimPose sensorToRigPose(invRigMat * myAvatar->getSensorToWorldMatrix()); |
| 249 | 227 | |
| 250 | − params.primaryControllerPoses[Rig::PrimaryControllerType_Hips] = sensorToRigPose * hips; | |
| 228 | + params.primaryControllerPoses[Rig::PrimaryControllerType_Hips] = sensorToRigPose * sensorHips; | |
| 251 | 229 | params.primaryControllerFlags[Rig::PrimaryControllerType_Hips] = (uint8_t)Rig::ControllerFlags::Enabled | (uint8_t)Rig::ControllerFlags::Estimated; |
| 252 | 230 | |
| 253 | 231 | // set spine2 if we have hand controllers |
| 254 | 232 | if (myAvatar->getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).isValid() && |
| 255 | − myAvatar->getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).isValid() && | |
| 256 | − !(params.primaryControllerFlags[Rig::PrimaryControllerType_Spine2] & (uint8_t)Rig::ControllerFlags::Enabled)) { | |
| 233 | + myAvatar->getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).isValid() && | |
| 234 | + !(params.primaryControllerFlags[Rig::PrimaryControllerType_Spine2] & (uint8_t)Rig::ControllerFlags::Enabled)) { | |
| 257 | 235 | |
| 258 | 236 | AnimPose currentSpine2Pose; |
| 259 | 237 | AnimPose currentHeadPose; |
| @@ -280,8 +258,9 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { · 20 unmodified lines | ||
| 280 | 258 | } |
| 281 | 259 | } |
| 282 | 260 | |
| 261 | + _prevIsEstimatingHips = true; | |
| 283 | 262 | } else { |
| 284 | − _prevHipsValid = false; | |
| 263 | + _prevIsEstimatingHips = false; | |
| 285 | 264 | } |
| 286 | 265 | |
| 287 | 266 | params.isTalking = head->getTimeWithoutTalking() <= 1.5f; |
| @@ -289,19 +268,19 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { · 1 unmodified line | ||
| 289 | 268 | // pass detailed torso k-dops to rig. |
| 290 | 269 | int hipsJoint = _rig.indexOfJoint("Hips"); |
| 291 | 270 | if (hipsJoint >= 0) { |
| 292 | − params.hipsShapeInfo = geometry.joints[hipsJoint].shapeInfo; | |
| 271 | + params.hipsShapeInfo = hfmModel.joints[hipsJoint].shapeInfo; | |
| 293 | 272 | } |
| 294 | 273 | int spineJoint = _rig.indexOfJoint("Spine"); |
| 295 | 274 | if (spineJoint >= 0) { |
| 296 | − params.spineShapeInfo = geometry.joints[spineJoint].shapeInfo; | |
| 275 | + params.spineShapeInfo = hfmModel.joints[spineJoint].shapeInfo; | |
| 297 | 276 | } |
| 298 | 277 | int spine1Joint = _rig.indexOfJoint("Spine1"); |
| 299 | 278 | if (spine1Joint >= 0) { |
| 300 | − params.spine1ShapeInfo = geometry.joints[spine1Joint].shapeInfo; | |
| 279 | + params.spine1ShapeInfo = hfmModel.joints[spine1Joint].shapeInfo; | |
| 301 | 280 | } |
| 302 | 281 | int spine2Joint = _rig.indexOfJoint("Spine2"); |
| 303 | 282 | if (spine2Joint >= 0) { |
| 304 | − params.spine2ShapeInfo = geometry.joints[spine2Joint].shapeInfo; | |
| 283 | + params.spine2ShapeInfo = hfmModel.joints[spine2Joint].shapeInfo; | |
| 305 | 284 | } |
| 306 | 285 | |
| 307 | 286 | _rig.updateFromControllerParameters(params, deltaTime); |
| @@ -311,7 +290,7 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { · 3 unmodified lines | ||
| 311 | 290 | auto velocity = myAvatar->getLocalVelocity() / myAvatar->getSensorToWorldScale(); |
| 312 | 291 | auto position = myAvatar->getLocalPosition(); |
| 313 | 292 | auto orientation = myAvatar->getLocalOrientation(); |
| 314 | − _rig.computeMotionAnimationState(deltaTime, position, velocity, orientation, ccState); | |
| 293 | + _rig.computeMotionAnimationState(deltaTime, position, velocity, orientation, ccState, myAvatar->getSensorToWorldScale()); | |
| 315 | 294 | |
| 316 | 295 | // evaluate AnimGraph animation and update jointStates. |
| 317 | 296 | Model::updateRig(deltaTime, parentTransform); |
| @@ -321,8 +300,8 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { · 3 unmodified lines | ||
| 321 | 300 | eyeParams.eyeSaccade = head->getSaccade(); |
| 322 | 301 | eyeParams.modelRotation = getRotation(); |
| 323 | 302 | eyeParams.modelTranslation = getTranslation(); |
| 324 | − eyeParams.leftEyeJointIndex = geometry.leftEyeJointIndex; | |
| 325 | − eyeParams.rightEyeJointIndex = geometry.rightEyeJointIndex; | |
| 303 | + eyeParams.leftEyeJointIndex = hfmModel.leftEyeJointIndex; | |
| 304 | + eyeParams.rightEyeJointIndex = hfmModel.rightEyeJointIndex; | |
| 326 | 305 | |
| 327 | 306 | _rig.updateFromEyeParameters(eyeParams); |
| 328 | 307 | |