mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:08:47 +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
|
// Update audio trailing average for rendering facial animations
|
||||||
Faceshift* faceshift = Application::getInstance()->getFaceshift();
|
Faceshift* faceshift = Application::getInstance()->getFaceshift();
|
||||||
if (isMine && faceshift->isActive()) {
|
if (isMine && faceshift->isActive()) {
|
||||||
_leftEyeBlink = faceshift->getLeftBlink();
|
const float EYE_OPEN_SCALE = 0.5f;
|
||||||
_rightEyeBlink = faceshift->getRightBlink();
|
_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
|
// 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
|
// mapping between their blendshape coefficients and our avatar features
|
||||||
|
@ -730,7 +731,7 @@ void Head::renderEyeBalls() {
|
||||||
float angle = -67.5f - 50.0f * _leftEyeBlink;
|
float angle = -67.5f - 50.0f * _leftEyeBlink;
|
||||||
glRotatef(angle, 1, 0, 0);
|
glRotatef(angle, 1, 0, 0);
|
||||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
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);
|
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
@ -744,7 +745,7 @@ void Head::renderEyeBalls() {
|
||||||
float angle = -67.5f - 50.0f * _rightEyeBlink;
|
float angle = -67.5f - 50.0f * _rightEyeBlink;
|
||||||
glRotatef(angle, 1, 0, 0);
|
glRotatef(angle, 1, 0, 0);
|
||||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
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);
|
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
|
@ -8,13 +8,18 @@
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
#include "Faceshift.h"
|
#include "Faceshift.h"
|
||||||
|
|
||||||
using namespace fs;
|
using namespace fs;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
const quint16 FACESHIFT_PORT = 33433;
|
||||||
|
|
||||||
Faceshift::Faceshift() :
|
Faceshift::Faceshift() :
|
||||||
_enabled(false),
|
_tcpEnabled(false),
|
||||||
|
_lastMessageReceived(0),
|
||||||
_eyeGazeLeftPitch(0.0f),
|
_eyeGazeLeftPitch(0.0f),
|
||||||
_eyeGazeLeftYaw(0.0f),
|
_eyeGazeLeftYaw(0.0f),
|
||||||
_eyeGazeRightPitch(0.0f),
|
_eyeGazeRightPitch(0.0f),
|
||||||
|
@ -23,10 +28,6 @@ Faceshift::Faceshift() :
|
||||||
_rightBlink(0.0f),
|
_rightBlink(0.0f),
|
||||||
_leftEyeOpen(0.0f),
|
_leftEyeOpen(0.0f),
|
||||||
_rightEyeOpen(0.0f),
|
_rightEyeOpen(0.0f),
|
||||||
_leftBlinkIndex(-1),
|
|
||||||
_rightBlinkIndex(-1),
|
|
||||||
_leftEyeOpenIndex(-1),
|
|
||||||
_rightEyeOpenIndex(-1),
|
|
||||||
_browDownLeft(0.0f),
|
_browDownLeft(0.0f),
|
||||||
_browDownRight(0.0f),
|
_browDownRight(0.0f),
|
||||||
_browUpCenter(0.0f),
|
_browUpCenter(0.0f),
|
||||||
|
@ -34,7 +35,6 @@ Faceshift::Faceshift() :
|
||||||
_browUpRight(0.0f),
|
_browUpRight(0.0f),
|
||||||
_browDownLeftIndex(-1),
|
_browDownLeftIndex(-1),
|
||||||
_browDownRightIndex(-1),
|
_browDownRightIndex(-1),
|
||||||
_browUpCenterIndex(-1),
|
|
||||||
_browUpLeftIndex(-1),
|
_browUpLeftIndex(-1),
|
||||||
_browUpRightIndex(-1),
|
_browUpRightIndex(-1),
|
||||||
_mouthSize(0.0f),
|
_mouthSize(0.0f),
|
||||||
|
@ -42,15 +42,30 @@ Faceshift::Faceshift() :
|
||||||
_mouthSmileRight(0),
|
_mouthSmileRight(0),
|
||||||
_mouthSmileLeftIndex(-1),
|
_mouthSmileLeftIndex(-1),
|
||||||
_mouthSmileRightIndex(0),
|
_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),
|
_longTermAverageEyePitch(0.0f),
|
||||||
_longTermAverageEyeYaw(0.0f),
|
_longTermAverageEyeYaw(0.0f),
|
||||||
_estimatedEyePitch(0.0f),
|
_estimatedEyePitch(0.0f),
|
||||||
_estimatedEyeYaw(0.0f)
|
_estimatedEyeYaw(0.0f)
|
||||||
{
|
{
|
||||||
connect(&_socket, SIGNAL(connected()), SLOT(noteConnected()));
|
connect(&_tcpSocket, SIGNAL(connected()), SLOT(noteConnected()));
|
||||||
connect(&_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(noteError(QAbstractSocket::SocketError)));
|
connect(&_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(noteError(QAbstractSocket::SocketError)));
|
||||||
connect(&_socket, SIGNAL(readyRead()), SLOT(readFromSocket()));
|
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() {
|
void Faceshift::update() {
|
||||||
|
@ -67,28 +82,27 @@ void Faceshift::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faceshift::reset() {
|
void Faceshift::reset() {
|
||||||
if (isActive()) {
|
if (_tcpSocket.state() == QAbstractSocket::ConnectedState) {
|
||||||
string message;
|
string message;
|
||||||
fsBinaryStream::encode_message(message, fsMsgCalibrateNeutral());
|
fsBinaryStream::encode_message(message, fsMsgCalibrateNeutral());
|
||||||
send(message);
|
send(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faceshift::setEnabled(bool enabled) {
|
void Faceshift::setTCPEnabled(bool enabled) {
|
||||||
if ((_enabled = enabled)) {
|
if ((_tcpEnabled = enabled)) {
|
||||||
connectSocket();
|
connectSocket();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_socket.disconnectFromHost();
|
_tcpSocket.disconnectFromHost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faceshift::connectSocket() {
|
void Faceshift::connectSocket() {
|
||||||
if (_enabled) {
|
if (_tcpEnabled) {
|
||||||
qDebug("Faceshift: Connecting...\n");
|
qDebug("Faceshift: Connecting...\n");
|
||||||
|
|
||||||
const quint16 FACESHIFT_PORT = 33433;
|
_tcpSocket.connectToHost("localhost", FACESHIFT_PORT);
|
||||||
_socket.connectToHost("localhost", FACESHIFT_PORT);
|
|
||||||
_tracking = false;
|
_tracking = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,16 +117,32 @@ void Faceshift::noteConnected() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faceshift::noteError(QAbstractSocket::SocketError error) {
|
void Faceshift::noteError(QAbstractSocket::SocketError error) {
|
||||||
qDebug() << "Faceshift: " << _socket.errorString() << "\n";
|
qDebug() << "Faceshift: " << _tcpSocket.errorString() << "\n";
|
||||||
|
|
||||||
// reconnect after a delay
|
// reconnect after a delay
|
||||||
if (_enabled) {
|
if (_tcpEnabled) {
|
||||||
QTimer::singleShot(1000, this, SLOT(connectSocket()));
|
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() {
|
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());
|
_stream.received(buffer.size(), buffer.constData());
|
||||||
fsMsgPtr msg;
|
fsMsgPtr msg;
|
||||||
for (fsMsgPtr msg; (msg = _stream.get_message()); ) {
|
for (fsMsgPtr msg; (msg = _stream.get_message()); ) {
|
||||||
|
@ -129,7 +159,7 @@ void Faceshift::readFromSocket() {
|
||||||
_eyeGazeLeftYaw = data.m_eyeGazeLeftYaw;
|
_eyeGazeLeftYaw = data.m_eyeGazeLeftYaw;
|
||||||
_eyeGazeRightPitch = -data.m_eyeGazeRightPitch;
|
_eyeGazeRightPitch = -data.m_eyeGazeRightPitch;
|
||||||
_eyeGazeRightYaw = data.m_eyeGazeRightYaw;
|
_eyeGazeRightYaw = data.m_eyeGazeRightYaw;
|
||||||
|
|
||||||
if (_leftBlinkIndex != -1) {
|
if (_leftBlinkIndex != -1) {
|
||||||
_leftBlink = data.m_coeffs[_leftBlinkIndex];
|
_leftBlink = data.m_coeffs[_leftBlinkIndex];
|
||||||
}
|
}
|
||||||
|
@ -216,8 +246,5 @@ void Faceshift::readFromSocket() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
_lastMessageReceived = usecTimestampNow();
|
||||||
|
|
||||||
void Faceshift::send(const std::string& message) {
|
|
||||||
_socket.write(message.data(), message.size());
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define __interface__Faceshift__
|
#define __interface__Faceshift__
|
||||||
|
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
|
#include <QUdpSocket>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
@ -24,7 +25,7 @@ public:
|
||||||
|
|
||||||
Faceshift();
|
Faceshift();
|
||||||
|
|
||||||
bool isActive() const { return _socket.state() == QAbstractSocket::ConnectedState && _tracking; }
|
bool isActive() const;
|
||||||
|
|
||||||
const glm::quat& getHeadRotation() const { return _headRotation; }
|
const glm::quat& getHeadRotation() const { return _headRotation; }
|
||||||
const glm::vec3& getHeadTranslation() const { return _headTranslation; }
|
const glm::vec3& getHeadTranslation() const { return _headTranslation; }
|
||||||
|
@ -58,23 +59,27 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void setEnabled(bool enabled);
|
void setTCPEnabled(bool enabled);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void connectSocket();
|
void connectSocket();
|
||||||
void noteConnected();
|
void noteConnected();
|
||||||
void noteError(QAbstractSocket::SocketError error);
|
void noteError(QAbstractSocket::SocketError error);
|
||||||
|
void readPendingDatagrams();
|
||||||
void readFromSocket();
|
void readFromSocket();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void send(const std::string& message);
|
void send(const std::string& message);
|
||||||
|
void receive(const QByteArray& buffer);
|
||||||
|
|
||||||
QTcpSocket _socket;
|
QTcpSocket _tcpSocket;
|
||||||
|
QUdpSocket _udpSocket;
|
||||||
fs::fsBinaryStream _stream;
|
fs::fsBinaryStream _stream;
|
||||||
bool _enabled;
|
bool _tcpEnabled;
|
||||||
bool _tracking;
|
bool _tracking;
|
||||||
|
uint64_t _lastMessageReceived;
|
||||||
|
|
||||||
glm::quat _headRotation;
|
glm::quat _headRotation;
|
||||||
glm::vec3 _headTranslation;
|
glm::vec3 _headTranslation;
|
||||||
|
@ -94,7 +99,6 @@ private:
|
||||||
int _rightBlinkIndex;
|
int _rightBlinkIndex;
|
||||||
int _leftEyeOpenIndex;
|
int _leftEyeOpenIndex;
|
||||||
int _rightEyeOpenIndex;
|
int _rightEyeOpenIndex;
|
||||||
|
|
||||||
|
|
||||||
// Brows
|
// Brows
|
||||||
float _browDownLeft;
|
float _browDownLeft;
|
||||||
|
@ -105,6 +109,7 @@ private:
|
||||||
|
|
||||||
int _browDownLeftIndex;
|
int _browDownLeftIndex;
|
||||||
int _browDownRightIndex;
|
int _browDownRightIndex;
|
||||||
|
|
||||||
int _browUpCenterIndex;
|
int _browUpCenterIndex;
|
||||||
int _browUpLeftIndex;
|
int _browUpLeftIndex;
|
||||||
int _browUpRightIndex;
|
int _browUpRightIndex;
|
||||||
|
|
Loading…
Reference in a new issue