mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 18:55:01 +02:00
Andrejz Faceshift modif merge
This commit is contained in:
parent
7a2a79f6f5
commit
d6981bfa20
3 changed files with 67 additions and 34 deletions
|
@ -150,8 +150,9 @@ void Head::simulate(float deltaTime, bool isMine, float gyroCameraSensitivity) {
|
|||
// Update audio trailing average for rendering facial animations
|
||||
Faceshift* faceshift = Application::getInstance()->getFaceshift();
|
||||
if (isMine && faceshift->isActive()) {
|
||||
_leftEyeBlink = faceshift->getLeftBlink();
|
||||
_rightEyeBlink = faceshift->getRightBlink();
|
||||
const float EYE_OPEN_SCALE = 0.5f;
|
||||
_leftEyeBlink = faceshift->getLeftBlink() - EYE_OPEN_SCALE * faceshift->getLeftEyeOpen();
|
||||
_rightEyeBlink = faceshift->getRightBlink() - EYE_OPEN_SCALE * faceshift->getRightEyeOpen();
|
||||
|
||||
// set these values based on how they'll be used. if we use faceshift in the long term, we'll want a complete
|
||||
// mapping between their blendshape coefficients and our avatar features
|
||||
|
@ -730,7 +731,7 @@ void Head::renderEyeBalls() {
|
|||
float angle = -67.5f - 50.0f * _leftEyeBlink;
|
||||
glRotatef(angle, 1, 0, 0);
|
||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||
glRotatef(glm::mix(-angle, 180.0f, _leftEyeBlink), 1, 0, 0);
|
||||
glRotatef(glm::mix(-angle, 180.0f, max(0.0f, _leftEyeBlink)), 1, 0, 0);
|
||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||
}
|
||||
glPopMatrix();
|
||||
|
@ -744,7 +745,7 @@ void Head::renderEyeBalls() {
|
|||
float angle = -67.5f - 50.0f * _rightEyeBlink;
|
||||
glRotatef(angle, 1, 0, 0);
|
||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||
glRotatef(glm::mix(-angle, 180.0f, _rightEyeBlink), 1, 0, 0);
|
||||
glRotatef(glm::mix(-angle, 180.0f, max(0.0f, _rightEyeBlink)), 1, 0, 0);
|
||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||
}
|
||||
glPopMatrix();
|
||||
|
|
|
@ -8,13 +8,18 @@
|
|||
|
||||
#include <QTimer>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Faceshift.h"
|
||||
|
||||
using namespace fs;
|
||||
using namespace std;
|
||||
|
||||
const quint16 FACESHIFT_PORT = 33433;
|
||||
|
||||
Faceshift::Faceshift() :
|
||||
_enabled(false),
|
||||
_tcpEnabled(false),
|
||||
_lastMessageReceived(0),
|
||||
_eyeGazeLeftPitch(0.0f),
|
||||
_eyeGazeLeftYaw(0.0f),
|
||||
_eyeGazeRightPitch(0.0f),
|
||||
|
@ -23,10 +28,6 @@ Faceshift::Faceshift() :
|
|||
_rightBlink(0.0f),
|
||||
_leftEyeOpen(0.0f),
|
||||
_rightEyeOpen(0.0f),
|
||||
_leftBlinkIndex(-1),
|
||||
_rightBlinkIndex(-1),
|
||||
_leftEyeOpenIndex(-1),
|
||||
_rightEyeOpenIndex(-1),
|
||||
_browDownLeft(0.0f),
|
||||
_browDownRight(0.0f),
|
||||
_browUpCenter(0.0f),
|
||||
|
@ -34,7 +35,6 @@ Faceshift::Faceshift() :
|
|||
_browUpRight(0.0f),
|
||||
_browDownLeftIndex(-1),
|
||||
_browDownRightIndex(-1),
|
||||
_browUpCenterIndex(-1),
|
||||
_browUpLeftIndex(-1),
|
||||
_browUpRightIndex(-1),
|
||||
_mouthSize(0.0f),
|
||||
|
@ -42,15 +42,30 @@ Faceshift::Faceshift() :
|
|||
_mouthSmileRight(0),
|
||||
_mouthSmileLeftIndex(-1),
|
||||
_mouthSmileRightIndex(0),
|
||||
_jawOpenIndex(-1),
|
||||
_leftBlinkIndex(0), // see http://support.faceshift.com/support/articles/35129-export-of-blendshapes
|
||||
_rightBlinkIndex(1),
|
||||
_leftEyeOpenIndex(8),
|
||||
_rightEyeOpenIndex(9),
|
||||
_browUpCenterIndex(16),
|
||||
_jawOpenIndex(21),
|
||||
_longTermAverageEyePitch(0.0f),
|
||||
_longTermAverageEyeYaw(0.0f),
|
||||
_estimatedEyePitch(0.0f),
|
||||
_estimatedEyeYaw(0.0f)
|
||||
{
|
||||
connect(&_socket, SIGNAL(connected()), SLOT(noteConnected()));
|
||||
connect(&_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(noteError(QAbstractSocket::SocketError)));
|
||||
connect(&_socket, SIGNAL(readyRead()), SLOT(readFromSocket()));
|
||||
connect(&_tcpSocket, SIGNAL(connected()), SLOT(noteConnected()));
|
||||
connect(&_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(noteError(QAbstractSocket::SocketError)));
|
||||
connect(&_tcpSocket, SIGNAL(readyRead()), SLOT(readFromSocket()));
|
||||
|
||||
connect(&_udpSocket, SIGNAL(readyRead()), SLOT(readPendingDatagrams()));
|
||||
|
||||
_udpSocket.bind(FACESHIFT_PORT);
|
||||
}
|
||||
|
||||
bool Faceshift::isActive() const {
|
||||
const uint64_t ACTIVE_TIMEOUT_USECS = 1000000;
|
||||
return (_tcpSocket.state() == QAbstractSocket::ConnectedState ||
|
||||
(usecTimestampNow() - _lastMessageReceived) < ACTIVE_TIMEOUT_USECS) && _tracking;
|
||||
}
|
||||
|
||||
void Faceshift::update() {
|
||||
|
@ -67,28 +82,27 @@ void Faceshift::update() {
|
|||
}
|
||||
|
||||
void Faceshift::reset() {
|
||||
if (isActive()) {
|
||||
if (_tcpSocket.state() == QAbstractSocket::ConnectedState) {
|
||||
string message;
|
||||
fsBinaryStream::encode_message(message, fsMsgCalibrateNeutral());
|
||||
send(message);
|
||||
}
|
||||
}
|
||||
|
||||
void Faceshift::setEnabled(bool enabled) {
|
||||
if ((_enabled = enabled)) {
|
||||
void Faceshift::setTCPEnabled(bool enabled) {
|
||||
if ((_tcpEnabled = enabled)) {
|
||||
connectSocket();
|
||||
|
||||
} else {
|
||||
_socket.disconnectFromHost();
|
||||
_tcpSocket.disconnectFromHost();
|
||||
}
|
||||
}
|
||||
|
||||
void Faceshift::connectSocket() {
|
||||
if (_enabled) {
|
||||
if (_tcpEnabled) {
|
||||
qDebug("Faceshift: Connecting...\n");
|
||||
|
||||
const quint16 FACESHIFT_PORT = 33433;
|
||||
_socket.connectToHost("localhost", FACESHIFT_PORT);
|
||||
_tcpSocket.connectToHost("localhost", FACESHIFT_PORT);
|
||||
_tracking = false;
|
||||
}
|
||||
}
|
||||
|
@ -103,16 +117,32 @@ void Faceshift::noteConnected() {
|
|||
}
|
||||
|
||||
void Faceshift::noteError(QAbstractSocket::SocketError error) {
|
||||
qDebug() << "Faceshift: " << _socket.errorString() << "\n";
|
||||
qDebug() << "Faceshift: " << _tcpSocket.errorString() << "\n";
|
||||
|
||||
// reconnect after a delay
|
||||
if (_enabled) {
|
||||
if (_tcpEnabled) {
|
||||
QTimer::singleShot(1000, this, SLOT(connectSocket()));
|
||||
}
|
||||
}
|
||||
|
||||
void Faceshift::readPendingDatagrams() {
|
||||
QByteArray buffer;
|
||||
while (_udpSocket.hasPendingDatagrams()) {
|
||||
buffer.resize(_udpSocket.pendingDatagramSize());
|
||||
_udpSocket.readDatagram(buffer.data(), buffer.size());
|
||||
receive(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void Faceshift::readFromSocket() {
|
||||
QByteArray buffer = _socket.readAll();
|
||||
receive(_tcpSocket.readAll());
|
||||
}
|
||||
|
||||
void Faceshift::send(const std::string& message) {
|
||||
_tcpSocket.write(message.data(), message.size());
|
||||
}
|
||||
|
||||
void Faceshift::receive(const QByteArray& buffer) {
|
||||
_stream.received(buffer.size(), buffer.constData());
|
||||
fsMsgPtr msg;
|
||||
for (fsMsgPtr msg; (msg = _stream.get_message()); ) {
|
||||
|
@ -129,7 +159,7 @@ void Faceshift::readFromSocket() {
|
|||
_eyeGazeLeftYaw = data.m_eyeGazeLeftYaw;
|
||||
_eyeGazeRightPitch = -data.m_eyeGazeRightPitch;
|
||||
_eyeGazeRightYaw = data.m_eyeGazeRightYaw;
|
||||
|
||||
|
||||
if (_leftBlinkIndex != -1) {
|
||||
_leftBlink = data.m_coeffs[_leftBlinkIndex];
|
||||
}
|
||||
|
@ -216,8 +246,5 @@ void Faceshift::readFromSocket() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Faceshift::send(const std::string& message) {
|
||||
_socket.write(message.data(), message.size());
|
||||
_lastMessageReceived = usecTimestampNow();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define __interface__Faceshift__
|
||||
|
||||
#include <QTcpSocket>
|
||||
#include <QUdpSocket>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
@ -24,7 +25,7 @@ public:
|
|||
|
||||
Faceshift();
|
||||
|
||||
bool isActive() const { return _socket.state() == QAbstractSocket::ConnectedState && _tracking; }
|
||||
bool isActive() const;
|
||||
|
||||
const glm::quat& getHeadRotation() const { return _headRotation; }
|
||||
const glm::vec3& getHeadTranslation() const { return _headTranslation; }
|
||||
|
@ -58,23 +59,27 @@ public:
|
|||
|
||||
public slots:
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
void setTCPEnabled(bool enabled);
|
||||
|
||||
private slots:
|
||||
|
||||
void connectSocket();
|
||||
void noteConnected();
|
||||
void noteError(QAbstractSocket::SocketError error);
|
||||
void readPendingDatagrams();
|
||||
void readFromSocket();
|
||||
|
||||
private:
|
||||
|
||||
void send(const std::string& message);
|
||||
void receive(const QByteArray& buffer);
|
||||
|
||||
QTcpSocket _socket;
|
||||
QTcpSocket _tcpSocket;
|
||||
QUdpSocket _udpSocket;
|
||||
fs::fsBinaryStream _stream;
|
||||
bool _enabled;
|
||||
bool _tcpEnabled;
|
||||
bool _tracking;
|
||||
uint64_t _lastMessageReceived;
|
||||
|
||||
glm::quat _headRotation;
|
||||
glm::vec3 _headTranslation;
|
||||
|
@ -94,7 +99,6 @@ private:
|
|||
int _rightBlinkIndex;
|
||||
int _leftEyeOpenIndex;
|
||||
int _rightEyeOpenIndex;
|
||||
|
||||
|
||||
// Brows
|
||||
float _browDownLeft;
|
||||
|
@ -105,6 +109,7 @@ private:
|
|||
|
||||
int _browDownLeftIndex;
|
||||
int _browDownRightIndex;
|
||||
|
||||
int _browUpCenterIndex;
|
||||
int _browUpLeftIndex;
|
||||
int _browUpRightIndex;
|
||||
|
|
Loading…
Reference in a new issue