Clean up code and refactor avatar-animation.json

This commit is contained in:
luiscuenca 2019-09-19 10:45:20 -07:00
parent fc223e4cb6
commit 6d98537a20
No known key found for this signature in database
GPG key ID: 2387ECD129A6961D
7 changed files with 724 additions and 758 deletions
interface
libraries/animation/src

File diff suppressed because it is too large Load diff

View file

@ -3604,7 +3604,8 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
// Always use the default eye position, not the actual head eye position.
// Using the latter will cause the camera to wobble with idle animations,
// or with changes from the face tracker
if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
CameraMode mode = _myCamera.getMode();
if (mode == CAMERA_MODE_FIRST_PERSON) {
_thirdPersonHMDCameraBoomValid= false;
if (isHMDMode()) {
mat4 camMat = myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix();
@ -3615,11 +3616,8 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
_myCamera.setPosition(myAvatar->getDefaultEyePosition());
_myCamera.setOrientation(myAvatar->getMyHead()->getHeadOrientation());
}
} else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON ||
_myCamera.getMode() == CAMERA_MODE_LOOK_AT ||
_myCamera.getMode() == CAMERA_MODE_SELFIE) {
} else if (mode == CAMERA_MODE_THIRD_PERSON || mode == CAMERA_MODE_LOOK_AT || mode == CAMERA_MODE_SELFIE) {
if (isHMDMode()) {
if (!_thirdPersonHMDCameraBoomValid) {
const glm::vec3 CAMERA_OFFSET = glm::vec3(0.0f, 0.0f, 0.7f);
_thirdPersonHMDCameraBoom = cancelOutRollAndPitch(myAvatar->getHMDSensorOrientation()) * CAMERA_OFFSET;
@ -3636,7 +3634,7 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
_myCamera.setPosition(extractTranslation(worldCameraMat));
} else {
_thirdPersonHMDCameraBoomValid = false;
if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
if (mode == CAMERA_MODE_THIRD_PERSON) {
_myCamera.setOrientation(myAvatar->getHead()->getOrientation());
if (isOptionChecked(MenuOption::CenterPlayerInView)) {
_myCamera.setPosition(myAvatar->getDefaultEyePosition()
@ -3647,7 +3645,7 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
}
} else {
glm::quat lookAtOffset = myAvatar->getLookAtOffset();
if (_myCamera.getMode() == CAMERA_MODE_SELFIE) {
if (mode == CAMERA_MODE_SELFIE) {
lookAtOffset = lookAtOffset * glm::angleAxis(PI, myAvatar->getWorldOrientation() * Vectors::UP);
}
_myCamera.setPosition(myAvatar->getDefaultEyePosition()
@ -3655,7 +3653,7 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
_myCamera.lookAt(myAvatar->getDefaultEyePosition());
}
}
} else if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
} else if (mode == CAMERA_MODE_MIRROR) {
_thirdPersonHMDCameraBoomValid= false;
if (isHMDMode()) {
@ -3693,7 +3691,7 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
glm::vec3(0.0f, 0.0f, -1.0f) * myAvatar->getBoomLength() * _scaleMirror);
}
renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
} else if (_myCamera.getMode() == CAMERA_MODE_ENTITY) {
} else if (mode == CAMERA_MODE_ENTITY) {
_thirdPersonHMDCameraBoomValid= false;
EntityItemPointer cameraEntity = _myCamera.getCameraEntityPointer();
if (cameraEntity != nullptr) {
@ -4410,12 +4408,12 @@ void Application::keyPressEvent(QKeyEvent* event) {
}
case Qt::Key_2: {
Menu* menu = Menu::getInstance();
menu->triggerOption(MenuOption::SelfieScreen);
menu->triggerOption(MenuOption::SelfieCamera);
break;
}
case Qt::Key_3: {
Menu* menu = Menu::getInstance();
menu->triggerOption(MenuOption::LookAtScreen);
menu->triggerOption(MenuOption::LookAtCamera);
break;
}
case Qt::Key_4:
@ -5977,16 +5975,16 @@ void Application::cycleCamera() {
} else if (menu->isOptionChecked(MenuOption::FirstPerson)) {
menu->setIsOptionChecked(MenuOption::FirstPerson, false);
menu->setIsOptionChecked(MenuOption::LookAtScreen, true);
menu->setIsOptionChecked(MenuOption::LookAtCamera, true);
} else if (menu->isOptionChecked(MenuOption::LookAtScreen)) {
} else if (menu->isOptionChecked(MenuOption::LookAtCamera)) {
menu->setIsOptionChecked(MenuOption::LookAtScreen, false);
menu->setIsOptionChecked(MenuOption::SelfieScreen, true);
menu->setIsOptionChecked(MenuOption::LookAtCamera, false);
menu->setIsOptionChecked(MenuOption::SelfieCamera, true);
} else if (menu->isOptionChecked(MenuOption::SelfieScreen)) {
} else if (menu->isOptionChecked(MenuOption::SelfieCamera)) {
menu->setIsOptionChecked(MenuOption::SelfieScreen, false);
menu->setIsOptionChecked(MenuOption::SelfieCamera, false);
menu->setIsOptionChecked(MenuOption::FullscreenMirror, true);
}
@ -5999,10 +5997,10 @@ void Application::cameraModeChanged() {
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, true);
break;
case CAMERA_MODE_LOOK_AT:
Menu::getInstance()->setIsOptionChecked(MenuOption::LookAtScreen, true);
Menu::getInstance()->setIsOptionChecked(MenuOption::LookAtCamera, true);
break;
case CAMERA_MODE_SELFIE:
Menu::getInstance()->setIsOptionChecked(MenuOption::SelfieScreen, true);
Menu::getInstance()->setIsOptionChecked(MenuOption::SelfieCamera, true);
break;
default:
// we don't have menu items for the others, so just leave it alone.
@ -6018,11 +6016,11 @@ void Application::changeViewAsNeeded(float boomLength) {
if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON && boomLengthGreaterThanMinimum) {
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, false);
Menu::getInstance()->setIsOptionChecked(MenuOption::LookAtScreen, true);
Menu::getInstance()->setIsOptionChecked(MenuOption::LookAtCamera, true);
cameraMenuChanged();
} else if (_myCamera.getMode() == CAMERA_MODE_LOOK_AT && !boomLengthGreaterThanMinimum) {
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, true);
Menu::getInstance()->setIsOptionChecked(MenuOption::LookAtScreen, false);
Menu::getInstance()->setIsOptionChecked(MenuOption::LookAtCamera, false);
cameraMenuChanged();
}
}
@ -6034,14 +6032,14 @@ void Application::cameraMenuChanged() {
_myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
getMyAvatar()->setBoomLength(MyAvatar::ZOOM_MIN);
}
} else if (menu->isOptionChecked(MenuOption::LookAtScreen)) {
} else if (menu->isOptionChecked(MenuOption::LookAtCamera)) {
if (_myCamera.getMode() != CAMERA_MODE_LOOK_AT) {
_myCamera.setMode(CAMERA_MODE_LOOK_AT);
if (getMyAvatar()->getBoomLength() == MyAvatar::ZOOM_MIN) {
getMyAvatar()->setBoomLength(MyAvatar::ZOOM_DEFAULT);
}
}
} else if (menu->isOptionChecked(MenuOption::SelfieScreen)) {
} else if (menu->isOptionChecked(MenuOption::SelfieCamera)) {
if (_myCamera.getMode() != CAMERA_MODE_SELFIE) {
_myCamera.setMode(CAMERA_MODE_SELFIE);
if (getMyAvatar()->getBoomLength() == MyAvatar::ZOOM_MIN) {
@ -9132,7 +9130,7 @@ void Application::setDisplayPlugin(DisplayPluginPointer newDisplayPlugin) {
}
// Remove the selfie camera options from menu if in HMD mode
auto selfieAction = menu->getActionForOption(MenuOption::SelfieScreen);
auto selfieAction = menu->getActionForOption(MenuOption::SelfieCamera);
selfieAction->setVisible(!isHmd);
}

View file

@ -179,14 +179,14 @@ Menu::Menu() {
// View > Look At
auto lookAtAction = cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(
viewMenu, MenuOption::LookAtScreen, 0,
viewMenu, MenuOption::LookAtCamera, 0,
false, qApp, SLOT(cameraMenuChanged())));
lookAtAction->setProperty(EXCLUSION_GROUP_KEY, QVariant::fromValue(cameraModeGroup));
// View > Selfie
auto selfieAction = cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(
viewMenu, MenuOption::SelfieScreen, 0,
viewMenu, MenuOption::SelfieCamera, 0,
false, qApp, SLOT(cameraMenuChanged())));
selfieAction->setProperty(EXCLUSION_GROUP_KEY, QVariant::fromValue(cameraModeGroup));

View file

@ -129,7 +129,7 @@ namespace MenuOption {
const QString Login = "Login/Sign Up";
const QString Log = "Log";
const QString LogExtraTimings = "Log Extra Timing Details";
const QString LookAtScreen = "Third Person";
const QString LookAtCamera = "Third Person";
const QString LowVelocityFilter = "Low Velocity Filter";
const QString MeshVisible = "Draw Mesh";
const QString MuteEnvironment = "Mute Environment";
@ -182,7 +182,7 @@ namespace MenuOption {
const QString RunTimingTests = "Run Timing Tests";
const QString ScriptedMotorControl = "Enable Scripted Motor Control";
const QString ShowTrackedObjects = "Show Tracked Objects";
const QString SelfieScreen = "Selfie";
const QString SelfieCamera = "Selfie";
const QString SendWrongDSConnectVersion = "Send wrong DS connect version";
const QString SendWrongProtocolVersion = "Send wrong protocol version";
const QString SetHomeLocation = "Set Home Location";

View file

@ -940,7 +940,8 @@ void MyAvatar::simulate(float deltaTime, bool inView) {
head->setPosition(headPosition);
head->setScale(getModelScale());
head->simulate(deltaTime);
if (_scriptControlsHeadLookAt || qApp->getCamera().getMode() == CAMERA_MODE_LOOK_AT || qApp->getCamera().getMode() == CAMERA_MODE_SELFIE) {
CameraMode mode = qApp->getCamera().getMode();
if (_scriptControlsHeadLookAt || mode == CAMERA_MODE_LOOK_AT || mode == CAMERA_MODE_SELFIE) {
updateHeadLookAt(deltaTime);
} else if (_headLookAtActive){
resetHeadLookAt();
@ -3333,8 +3334,8 @@ void MyAvatar::setRotationThreshold(float angleRadians) {
void MyAvatar::updateOrientation(float deltaTime) {
// Smoothly rotate body with arrow keys
float targetSpeed = getDriveKey(YAW) * _yawSpeed;
bool computeLookAt = (qApp->getCamera().getMode() == CAMERA_MODE_LOOK_AT ||
qApp->getCamera().getMode() == CAMERA_MODE_SELFIE) && isReadyForPhysics();
CameraMode mode = qApp->getCamera().getMode();
bool computeLookAt = (mode == CAMERA_MODE_LOOK_AT || mode == CAMERA_MODE_SELFIE) && isReadyForPhysics() && !qApp->isHMDMode();
if (computeLookAt) {
// For "Look At" and "Selfie" camera modes we also smooth the yaw rotation from right-click mouse movement.
float speedFromDeltaYaw = deltaTime > FLT_EPSILON ? getDriveKey(DELTA_YAW) / deltaTime : 0.0f;
@ -3425,9 +3426,8 @@ void MyAvatar::updateOrientation(float deltaTime) {
if (totalBodyYaw != 0.0f) {
_lookAtOffsetYaw = _lookAtOffsetYaw * glm::quat(glm::radians(glm::vec3(0.0f, totalBodyYaw, 0.0f)));
}
float deltalPitchSign = 1.0f;// qApp->getCamera().getMode() == CAMERA_MODE_SELFIE ? -1.0f : 1.0f;
float pitchIncrement = getDriveKey(PITCH) * _pitchSpeed * deltaTime
+ deltalPitchSign * getDriveKey(DELTA_PITCH) * _pitchSpeed / PITCH_SPEED_DEFAULT;
+ getDriveKey(DELTA_PITCH) * _pitchSpeed / PITCH_SPEED_DEFAULT;
if (pitchIncrement != 0.0f) {
glm::quat _previousLookAtOffsetPitch = _lookAtOffsetPitch;
_lookAtOffsetPitch = _lookAtOffsetPitch * glm::quat(glm::radians(glm::vec3(pitchIncrement, 0.0f, 0.0f)));
@ -3535,14 +3535,13 @@ void MyAvatar::updateOrientation(float deltaTime) {
cameraVector = glm::mix(cameraVector, ajustedYawVector, 1.0f - lookAttenuation);
// Calculate the camera target point.
const float TARGET_DISTANCE_FROM_EYES = 20.0f;
glm::vec3 targetPoint = eyesPosition + TARGET_DISTANCE_FROM_EYES * glm::normalize(cameraVector);
glm::vec3 targetPoint = eyesPosition + glm::normalize(cameraVector);
// const float LOOKAT_MIX_ALPHA = 0.25f;
const float LOOKAT_MIX_ALPHA = 0.25f;
if (getDriveKey(TRANSLATE_Y) == 0.0f) {
// Approximate the head's look at vector to the camera look at vector with some delay.
float mixAlpha = (frontBackDot > 0.0f ? _backLookAtSpeed : _frontLookAtSpeed) * timeScale;
float mixAlpha = LOOKAT_MIX_ALPHA * timeScale;
if (mixAlpha > 1.0f) {
mixAlpha = 1.0f;
}
@ -5276,7 +5275,7 @@ glm::quat MyAvatar::getOrientationForAudio() {
switch (_audioListenerMode) {
case AudioListenerMode::FROM_HEAD: {
// Compute the head orientation if we are using the look at blending
// Using the camera's orientation instead, when the current mode is controlling the avatar's head.
CameraMode mode = qApp->getCamera().getMode();
bool headFollowsCamera = mode == CAMERA_MODE_LOOK_AT || mode == CAMERA_MODE_SELFIE;
result = headFollowsCamera ? qApp->getCamera().getOrientation() : getHead()->getFinalOrientationInWorldFrame();
@ -6311,36 +6310,6 @@ QVariantMap MyAvatar::getFlowData() {
return result;
}
QVariantMap MyAvatar::getLookAtCameraData() {
QVariantMap result;
if (QThread::currentThread() != thread()) {
BLOCKING_INVOKE_METHOD(this, "getLookAtCameraData",
Q_RETURN_ARG(QVariantMap, result));
return result;
}
result.insert("selfieTriggerAngle", _selfieTriggerAngle);
result.insert("backLookAtSpeed", glm::pow(_backLookAtSpeed, 0.25f));
result.insert("frontLookAtSpeed", glm::pow(_frontLookAtSpeed, 0.25f));
return result;
}
Q_INVOKABLE void MyAvatar::setLookAtCameraData(const QVariantMap& data) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "setLookAtCameraData",
Q_ARG(const QVariantMap&, data));
return;
}
if (data.contains("selfieTriggerAngle")) {
_selfieTriggerAngle = data["selfieTriggerAngle"].toFloat();
}
if (data.contains("backLookAtSpeed")) {
_backLookAtSpeed = glm::pow(data["backLookAtSpeed"].toFloat(), 4.0f);
}
if (data.contains("frontLookAtSpeed")) {
_frontLookAtSpeed = glm::pow(data["frontLookAtSpeed"].toFloat(), 4.0f);
}
}
QVariantList MyAvatar::getCollidingFlowJoints() {
QVariantList result;
if (QThread::currentThread() != thread()) {

View file

@ -1852,8 +1852,6 @@ public:
* @returns {MyAvatar.FlowData}
*/
Q_INVOKABLE QVariantMap getFlowData();
Q_INVOKABLE QVariantMap getLookAtCameraData();
Q_INVOKABLE void setLookAtCameraData(const QVariantMap& data);
/**jsdoc
* Gets the indexes of currently colliding flow joints.

View file

@ -1644,7 +1644,7 @@ void Rig::updateHead(bool headEnabled, bool hipsEnabled, const AnimPose& headPos
_animVars.set("splineIKEnabled", false);
_animVars.unset("headPosition");
_animVars.set("headRotation", headPose.rot());
_animVars.set("headType", (int)IKTarget::Type::RotationOnly);
_animVars.set("headType", (int)IKTarget::Type::Unknown);
}
}
}