diff --git a/indra/newview/fsposeranimator.cpp b/indra/newview/fsposeranimator.cpp index b539966198..6f12b1c84e 100644 --- a/indra/newview/fsposeranimator.cpp +++ b/indra/newview/fsposeranimator.cpp @@ -226,7 +226,7 @@ void FSPoserAnimator::resetJointScale(LLVOAvatar* avatar, FSPoserJoint joint, E_ if (!jointPose) return; - jointPose->revertJointScale(); + jointPose->setTargetScale(jointPose->getBeginningScale()); if (style == NONE) return; @@ -235,7 +235,7 @@ void FSPoserAnimator::resetJointScale(LLVOAvatar* avatar, FSPoserJoint joint, E_ if (!oppositeJointPose) return; - oppositeJointPose->revertJointScale(); + oppositeJointPose->setTargetScale(oppositeJointPose->getBeginningScale()); } bool FSPoserAnimator::canRedoJointRotation(LLVOAvatar* avatar, FSPoserJoint joint) @@ -664,7 +664,7 @@ LLVector3 FSPoserAnimator::getJointScale(LLVOAvatar *avatar, FSPoserJoint joint) if (!jointPose) return scale; - scale = jointPose->getJointScale(); + scale = jointPose->getTargetScale(); return scale; } @@ -688,7 +688,7 @@ void FSPoserAnimator::setJointScale(LLVOAvatar *avatar, const FSPoserJoint *join if (!jointPose) return; - jointPose->setJointScale(scale); + jointPose->setTargetScale(scale); if (style == NONE) return; @@ -697,7 +697,7 @@ void FSPoserAnimator::setJointScale(LLVOAvatar *avatar, const FSPoserJoint *join if (!oppositeJointPose) return; - oppositeJointPose->setJointScale(scale); + oppositeJointPose->setTargetScale(scale); } const FSPoserAnimator::FSPoserJoint* FSPoserAnimator::getPoserJointByName(std::string jointName) @@ -728,8 +728,6 @@ bool FSPoserAnimator::tryPosingAvatar(LLVOAvatar *avatar) avatar->startDefaultMotions(); avatar->startMotion(posingMotion->motionId()); - // TODO: scrape motion state prior to edit, facilitating reset - return true; } diff --git a/indra/newview/fsposingmotion.cpp b/indra/newview/fsposingmotion.cpp index bbb9c54bac..4b9e266700 100644 --- a/indra/newview/fsposingmotion.cpp +++ b/indra/newview/fsposingmotion.cpp @@ -74,6 +74,8 @@ bool FSPosingMotion::onUpdate(F32 time, U8* joint_mask) LLQuaternion currentRotation; LLVector3 currentPosition; LLVector3 targetPosition; + LLVector3 currentScale; + LLVector3 targetScale; for (FSJointPose jointPose : _jointPoses) { @@ -83,8 +85,10 @@ bool FSPosingMotion::onUpdate(F32 time, U8* joint_mask) currentRotation = joint->getRotation(); currentPosition = joint->getPosition(); + currentScale = joint->getScale(); targetRotation = jointPose.getTargetRotation(); targetPosition = jointPose.getTargetPosition(); + targetScale = jointPose.getTargetScale(); if (currentPosition != targetPosition) { @@ -97,6 +101,12 @@ bool FSPosingMotion::onUpdate(F32 time, U8* joint_mask) currentRotation = slerp(_interpolationTime, currentRotation, targetRotation); jointPose.getJointState()->setRotation(currentRotation); } + + if (currentScale != targetScale) + { + currentScale = lerp(currentScale, targetScale, _interpolationTime); + jointPose.getJointState()->setScale(currentScale); + } } return true; diff --git a/indra/newview/fsposingmotion.h b/indra/newview/fsposingmotion.h index ecbc183d2a..cdfaa3f7ff 100644 --- a/indra/newview/fsposingmotion.h +++ b/indra/newview/fsposingmotion.h @@ -145,15 +145,6 @@ public: _lastSetScales.pop_back(); } - void setScale(LLVector3 scale) - { - LLJoint* joint = _jointState->getJoint(); - if (!joint) - return; - - joint->setScale(scale); - } - public: /// /// Gets the name of the joint. @@ -218,6 +209,29 @@ public: _targetRotation.set(rot); } + /// + /// Gets the scale the animator wishes the joint to have. + /// + LLVector3 getTargetScale() const { return _targetScale; } + + /// + /// Gets the scale the joint had when the animation was initialized. + /// + LLVector3 getBeginningScale() const { return _beginningScale; } + + /// + /// Sets the scale the animator wishes the joint to have. + /// + void setTargetScale(LLVector3 scale) + { + auto timeIntervalSinceLastScaleChange = std::chrono::system_clock::now() - _timeLastUpdatedScale; + if (timeIntervalSinceLastScaleChange > _undoUpdateInterval) + addLastScaleToUndo(); + + _timeLastUpdatedScale = std::chrono::system_clock::now(); + _targetScale.set(scale); + } + /// /// Undoes the last position set, if any. /// @@ -285,6 +299,56 @@ public: _lastSetRotations.pop_front(); } + void undoLastScaleSet() + { + if (_lastSetScales.empty()) + return; + + if (_undoneScaleIndex == 0) + addLastScaleToUndo(); + + _undoneScaleIndex++; + _undoneScaleIndex = llclamp(_undoneScaleIndex, 0, _lastSetScales.size() - 1); + _targetScale.set(_lastSetScales[_undoneScaleIndex]); + } + + void redoLastScaleSet() + { + if (_lastSetScales.empty()) + return; + + _undoneScaleIndex--; + _undoneScaleIndex = llclamp(_undoneScaleIndex, 0, _lastSetScales.size() - 1); + + _targetScale.set(_lastSetScales[_undoneScaleIndex]); + if (_undoneScaleIndex == 0) + _lastSetScales.pop_front(); + } + + /// + /// Restores the joint represented by this to the scale it had when this motion started. + /// + void revertJointScale() + { + LLJoint* joint = _jointState->getJoint(); + if (!joint) + return; + + joint->setScale(_beginningScale); + } + + /// + /// Restores the joint represented by this to the position it had when this motion started. + /// + void revertJointPosition() + { + LLJoint* joint = _jointState->getJoint(); + if (!joint) + return; + + joint->setPosition(_beginningPosition); + } + /// /// Collision Volumes do not 'reset' their position/rotation when the animation stops. /// This requires special treatment to revert changes we've made this animation session. @@ -303,70 +367,6 @@ public: joint->setScale(_beginningScale); } - LLVector3 getJointScale() const { return _targetScale; } - void setJointScale(LLVector3 scale) - { - auto timeIntervalSinceLastScaleChange = std::chrono::system_clock::now() - _timeLastUpdatedScale; - if (timeIntervalSinceLastScaleChange > _undoUpdateInterval) - addLastScaleToUndo(); - - _timeLastUpdatedScale = std::chrono::system_clock::now(); - - _targetScale.set(scale); - setScale(_targetScale); - } - - void undoLastScaleSet() - { - if (_lastSetScales.empty()) - return; - - if (_undoneScaleIndex == 0) // at the top of the queue add the current - addLastScaleToUndo(); - - _undoneScaleIndex++; - _undoneScaleIndex = llclamp(_undoneScaleIndex, 0, _lastSetScales.size() - 1); - _targetScale.set(_lastSetScales[_undoneScaleIndex]); - - setScale(_targetScale); - } - - void redoLastScaleSet() - { - if (_lastSetScales.empty()) - return; - - _undoneScaleIndex--; - _undoneScaleIndex = llclamp(_undoneScaleIndex, 0, _lastSetScales.size() - 1); - - _targetScale.set(_lastSetScales[_undoneScaleIndex]); - if (_undoneScaleIndex == 0) - _lastSetScales.pop_front(); - - setScale(_targetScale); - } - - /// - /// Restores the joint represented by this to the scale it had when this motion started. - /// - void revertJointScale() - { - _targetScale.set(_beginningScale); - setScale(_beginningScale); - } - - /// - /// Restores the joint represented by this to the position it had when this motion started. - /// - void revertJointPosition() - { - LLJoint* joint = _jointState->getJoint(); - if (!joint) - return; - - joint->setPosition(_beginningPosition); - } - /// /// Gets the pointer to the jointstate for the joint this represents. /// @@ -461,7 +461,7 @@ private: /// /// The kind of joint state this animation is concerned with changing. /// - static const U32 POSER_JOINT_STATE = LLJointState::POS | LLJointState::ROT /* | LLJointState::SCALE*/; + static const U32 POSER_JOINT_STATE = LLJointState::POS | LLJointState::ROT | LLJointState::SCALE; LLAssetID _motionID; ///