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