void PreferencesDialog::loadPreferences() { MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); Menu* menuInstance = Menu::getInstance(); _displayNameString = myAvatar->getDisplayName(); ui.displayNameEdit->setText(_displayNameString); ui.collisionSoundURLEdit->setText(myAvatar->getCollisionSoundURL()); ui.sendDataCheckBox->setChecked(!menuInstance->isOptionChecked(MenuOption::DisableActivityLogger)); ui.snapshotLocationEdit->setText(Snapshot::snapshotsLocation.get()); ui.scriptsLocationEdit->setText(qApp->getScriptsLocation()); ui.pupilDilationSlider->setValue(myAvatar->getHead()->getPupilDilation() * ui.pupilDilationSlider->maximum()); auto dde = DependencyManager::get<DdeFaceTracker>(); ui.ddeEyeClosingThresholdSlider->setValue(dde->getEyeClosingThreshold() * ui.ddeEyeClosingThresholdSlider->maximum()); ui.faceTrackerEyeDeflectionSider->setValue(FaceTracker::getEyeDeflection() * ui.faceTrackerEyeDeflectionSider->maximum()); auto faceshift = DependencyManager::get<Faceshift>(); ui.faceshiftHostnameEdit->setText(faceshift->getHostname()); auto audio = DependencyManager::get<AudioClient>(); MixedProcessedAudioStream& stream = audio->getReceivedAudioStream(); ui.dynamicJitterBuffersCheckBox->setChecked(stream.getDynamicJitterBuffers()); ui.staticDesiredJitterBufferFramesSpin->setValue(stream.getDesiredJitterBufferFrames()); ui.maxFramesOverDesiredSpin->setValue(stream.getMaxFramesOverDesired()); ui.useStdevForJitterCalcCheckBox->setChecked(stream.getUseStDevForJitterCalc()); ui.windowStarveThresholdSpin->setValue(stream.getWindowStarveThreshold()); ui.windowSecondsForDesiredCalcOnTooManyStarvesSpin->setValue( stream.getWindowSecondsForDesiredCalcOnTooManyStarves()); ui.windowSecondsForDesiredReductionSpin->setValue(stream.getWindowSecondsForDesiredReduction()); ui.repetitionWithFadeCheckBox->setChecked(stream.getRepetitionWithFade()); ui.outputBufferSizeSpinner->setValue(audio->getOutputBufferSize()); ui.outputStarveDetectionCheckBox->setChecked(audio->getOutputStarveDetectionEnabled()); ui.outputStarveDetectionThresholdSpinner->setValue(audio->getOutputStarveDetectionThreshold()); ui.outputStarveDetectionPeriodSpinner->setValue(audio->getOutputStarveDetectionPeriod()); ui.realWorldFieldOfViewSpin->setValue(DependencyManager::get<AvatarManager>()->getMyAvatar()->getRealWorldFieldOfView()); ui.fieldOfViewSpin->setValue(qApp->getFieldOfView()); ui.leanScaleSpin->setValue(myAvatar->getLeanScale()); ui.avatarScaleSpin->setValue(myAvatar->getScale()); ui.maxOctreePPSSpin->setValue(qApp->getMaxOctreePacketsPerSecond()); ui.oculusUIAngularSizeSpin->setValue(qApp->getApplicationCompositor().getHmdUIAngularSize()); SixenseManager& sixense = SixenseManager::getInstance(); ui.sixenseReticleMoveSpeedSpin->setValue(sixense.getReticleMoveSpeed()); ui.invertSixenseButtonsCheckBox->setChecked(sixense.getInvertButtons()); // LOD items auto lodManager = DependencyManager::get<LODManager>(); ui.desktopMinimumFPSSpin->setValue(lodManager->getDesktopLODDecreaseFPS()); ui.hmdMinimumFPSSpin->setValue(lodManager->getHMDLODDecreaseFPS()); }
void DdeFaceTracker::decodePacket(const QByteArray& buffer) { _lastReceiveTimestamp = usecTimestampNow(); if (buffer.size() > MIN_PACKET_SIZE) { bool isFiltering = Menu::getInstance()->isOptionChecked(MenuOption::VelocityFilter); Packet packet; int bytesToCopy = glm::min((int)sizeof(packet), buffer.size()); memset(&packet.name, '\n', MAX_NAME_SIZE + 1); memcpy(&packet, buffer.data(), bytesToCopy); glm::vec3 translation; memcpy(&translation, packet.translation, sizeof(packet.translation)); glm::quat rotation; memcpy(&rotation, &packet.rotation, sizeof(packet.rotation)); if (_reset || (_lastMessageReceived == 0)) { memcpy(&_referenceTranslation, &translation, sizeof(glm::vec3)); memcpy(&_referenceRotation, &rotation, sizeof(glm::quat)); _reset = false; } // Compute relative translation float LEAN_DAMPING_FACTOR = 75.0f; translation -= _referenceTranslation; translation /= LEAN_DAMPING_FACTOR; translation.x *= -1; if (isFiltering) { glm::vec3 linearVelocity = (translation - _lastHeadTranslation) / _averageMessageTime; const float LINEAR_VELOCITY_FILTER_STRENGTH = 0.3f; float velocityFilter = glm::clamp(1.0f - glm::length(linearVelocity) * LINEAR_VELOCITY_FILTER_STRENGTH, 0.0f, 1.0f); _filteredHeadTranslation = velocityFilter * _filteredHeadTranslation + (1.0f - velocityFilter) * translation; _lastHeadTranslation = translation; _headTranslation = _filteredHeadTranslation; } else { _headTranslation = translation; } // Compute relative rotation rotation = glm::inverse(_referenceRotation) * rotation; if (isFiltering) { glm::quat r = rotation * glm::inverse(_headRotation); float theta = 2 * acos(r.w); glm::vec3 angularVelocity; if (theta > EPSILON) { float rMag = glm::length(glm::vec3(r.x, r.y, r.z)); angularVelocity = theta / _averageMessageTime * glm::vec3(r.x, r.y, r.z) / rMag; } else { angularVelocity = glm::vec3(0, 0, 0); } const float ANGULAR_VELOCITY_FILTER_STRENGTH = 0.3f; _headRotation = safeMix(_headRotation, rotation, glm::clamp(glm::length(angularVelocity) * ANGULAR_VELOCITY_FILTER_STRENGTH, 0.0f, 1.0f)); } else { _headRotation = rotation; } // Translate DDE coefficients to Faceshift compatible coefficients for (int i = 0; i < NUM_EXPRESSIONS; i++) { _coefficients[DDE_TO_FACESHIFT_MAPPING[i]] = packet.expressions[i]; } // Calibration if (_isCalibrating) { addCalibrationDatum(); } for (int i = 0; i < NUM_FACESHIFT_BLENDSHAPES; i++) { _coefficients[i] -= _coefficientAverages[i]; } // Use BrowsU_C to control both brows' up and down float browUp = _coefficients[_browUpCenterIndex]; if (isFiltering) { const float BROW_VELOCITY_FILTER_STRENGTH = 0.5f; float velocity = fabs(browUp - _lastBrowUp) / _averageMessageTime; float velocityFilter = glm::clamp(velocity * BROW_VELOCITY_FILTER_STRENGTH, 0.0f, 1.0f); _filteredBrowUp = velocityFilter * browUp + (1.0f - velocityFilter) * _filteredBrowUp; _lastBrowUp = browUp; browUp = _filteredBrowUp; _coefficients[_browUpCenterIndex] = browUp; } _coefficients[_browUpLeftIndex] = browUp; _coefficients[_browUpRightIndex] = browUp; _coefficients[_browDownLeftIndex] = -browUp; _coefficients[_browDownRightIndex] = -browUp; // Offset jaw open coefficient static const float JAW_OPEN_THRESHOLD = 0.1f; _coefficients[_jawOpenIndex] = _coefficients[_jawOpenIndex] - JAW_OPEN_THRESHOLD; // Offset smile coefficients static const float SMILE_THRESHOLD = 0.5f; _coefficients[_mouthSmileLeftIndex] = _coefficients[_mouthSmileLeftIndex] - SMILE_THRESHOLD; _coefficients[_mouthSmileRightIndex] = _coefficients[_mouthSmileRightIndex] - SMILE_THRESHOLD; // Velocity filter EyeBlink values const float DDE_EYEBLINK_SCALE = 3.0f; float eyeBlinks[] = { DDE_EYEBLINK_SCALE * _coefficients[_leftBlinkIndex], DDE_EYEBLINK_SCALE * _coefficients[_rightBlinkIndex] }; if (isFiltering) { const float BLINK_VELOCITY_FILTER_STRENGTH = 0.3f; for (int i = 0; i < 2; i++) { float velocity = fabs(eyeBlinks[i] - _lastEyeBlinks[i]) / _averageMessageTime; float velocityFilter = glm::clamp(velocity * BLINK_VELOCITY_FILTER_STRENGTH, 0.0f, 1.0f); _filteredEyeBlinks[i] = velocityFilter * eyeBlinks[i] + (1.0f - velocityFilter) * _filteredEyeBlinks[i]; _lastEyeBlinks[i] = eyeBlinks[i]; } } // Finesse EyeBlink values float eyeCoefficients[2]; if (Menu::getInstance()->isOptionChecked(MenuOption::BinaryEyelidControl)) { if (_eyeStates[0] == EYE_UNCONTROLLED) { _eyeStates[0] = EYE_OPEN; _eyeStates[1] = EYE_OPEN; } for (int i = 0; i < 2; i++) { // Scale EyeBlink values so that they can be used to control both EyeBlink and EyeOpen // -ve values control EyeOpen; +ve values control EyeBlink static const float EYE_CONTROL_THRESHOLD = 0.5f; // Resting eye value eyeCoefficients[i] = (_filteredEyeBlinks[i] - EYE_CONTROL_THRESHOLD) / (1.0f - EYE_CONTROL_THRESHOLD); // Change to closing or opening states const float EYE_CONTROL_HYSTERISIS = 0.25f; float eyeClosingThreshold = getEyeClosingThreshold(); float eyeOpeningThreshold = eyeClosingThreshold - EYE_CONTROL_HYSTERISIS; if ((_eyeStates[i] == EYE_OPEN || _eyeStates[i] == EYE_OPENING) && eyeCoefficients[i] > eyeClosingThreshold) { _eyeStates[i] = EYE_CLOSING; } else if ((_eyeStates[i] == EYE_CLOSED || _eyeStates[i] == EYE_CLOSING) && eyeCoefficients[i] < eyeOpeningThreshold) { _eyeStates[i] = EYE_OPENING; } const float EYELID_MOVEMENT_RATE = 10.0f; // units/second const float EYE_OPEN_SCALE = 0.2f; if (_eyeStates[i] == EYE_CLOSING) { // Close eyelid until it's fully closed float closingValue = _lastEyeCoefficients[i] + EYELID_MOVEMENT_RATE * _averageMessageTime; if (closingValue >= 1.0) { _eyeStates[i] = EYE_CLOSED; eyeCoefficients[i] = 1.0; } else { eyeCoefficients[i] = closingValue; } } else if (_eyeStates[i] == EYE_OPENING) { // Open eyelid until it meets the current adjusted value float openingValue = _lastEyeCoefficients[i] - EYELID_MOVEMENT_RATE * _averageMessageTime; if (openingValue < eyeCoefficients[i] * EYE_OPEN_SCALE) { _eyeStates[i] = EYE_OPEN; eyeCoefficients[i] = eyeCoefficients[i] * EYE_OPEN_SCALE; } else { eyeCoefficients[i] = openingValue; } } else if (_eyeStates[i] == EYE_OPEN) { // Reduce eyelid movement eyeCoefficients[i] = eyeCoefficients[i] * EYE_OPEN_SCALE; } else if (_eyeStates[i] == EYE_CLOSED) { // Keep eyelid fully closed eyeCoefficients[i] = 1.0; } } if (_eyeStates[0] == EYE_OPEN && _eyeStates[1] == EYE_OPEN) { // Couple eyelids eyeCoefficients[0] = eyeCoefficients[1] = (eyeCoefficients[0] + eyeCoefficients[0]) / 2.0f; } _lastEyeCoefficients[0] = eyeCoefficients[0]; _lastEyeCoefficients[1] = eyeCoefficients[1]; } else { _eyeStates[0] = EYE_UNCONTROLLED; _eyeStates[1] = EYE_UNCONTROLLED; eyeCoefficients[0] = _filteredEyeBlinks[0]; eyeCoefficients[1] = _filteredEyeBlinks[1]; } // Use EyeBlink values to control both EyeBlink and EyeOpen if (eyeCoefficients[0] > 0) { _coefficients[_leftBlinkIndex] = eyeCoefficients[0]; _coefficients[_leftEyeOpenIndex] = 0.0f; } else { _coefficients[_leftBlinkIndex] = 0.0f; _coefficients[_leftEyeOpenIndex] = -eyeCoefficients[0]; } if (eyeCoefficients[1] > 0) { _coefficients[_rightBlinkIndex] = eyeCoefficients[1]; _coefficients[_rightEyeOpenIndex] = 0.0f; } else { _coefficients[_rightBlinkIndex] = 0.0f; _coefficients[_rightEyeOpenIndex] = -eyeCoefficients[1]; } // Scale all coefficients for (int i = 0; i < NUM_EXPRESSIONS; i++) { _blendshapeCoefficients[i] = glm::clamp(DDE_COEFFICIENT_SCALES[i] * _coefficients[i], 0.0f, 1.0f); } // Calculate average frame time const float FRAME_AVERAGING_FACTOR = 0.99f; quint64 usecsNow = usecTimestampNow(); if (_lastMessageReceived != 0) { _averageMessageTime = FRAME_AVERAGING_FACTOR * _averageMessageTime + (1.0f - FRAME_AVERAGING_FACTOR) * (float)(usecsNow - _lastMessageReceived) / 1000000.0f; } _lastMessageReceived = usecsNow; FaceTracker::countFrame(); } else { qCWarning(interfaceapp) << "DDE Face Tracker: Decode error"; } if (_isCalibrating && _calibrationCount > CALIBRATION_SAMPLES) { finishCalibration(); } }