From a12b90c65becd64ca9d78cf75ac123b6c49abf5b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 17 Apr 2014 13:34:37 -0700 Subject: [PATCH 1/3] Add head translation to Faceplus. Closes #2684. --- interface/src/Application.cpp | 1 + interface/src/devices/Faceplus.cpp | 44 ++++++++++++++++++++++++------ interface/src/devices/Faceplus.h | 14 +++++++--- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bd7a82b439..978e457ae9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3020,6 +3020,7 @@ void Application::resetSensors() { _mouseX = _glWidget->width() / 2; _mouseY = _glWidget->height() / 2; + _faceplus.reset(); _faceshift.reset(); _visage.reset(); diff --git a/interface/src/devices/Faceplus.cpp b/interface/src/devices/Faceplus.cpp index f7f2f1f1bd..f06433b663 100644 --- a/interface/src/devices/Faceplus.cpp +++ b/interface/src/devices/Faceplus.cpp @@ -40,9 +40,16 @@ void Faceplus::init() { updateEnabled(); } -void Faceplus::setState(const glm::quat& headRotation, float estimatedEyePitch, float estimatedEyeYaw, - const QVector& blendshapeCoefficients) { - _headRotation = headRotation; +void Faceplus::reset() { + if (_enabled) { + QMetaObject::invokeMethod(_reader, "reset"); + } +} + +void Faceplus::setState(const glm::vec3& headTranslation, const glm::quat& headRotation, + float estimatedEyePitch, float estimatedEyeYaw, const QVector& blendshapeCoefficients) { + _headTranslation = headTranslation; + _headRotation = headRotation; _estimatedEyePitch = estimatedEyePitch; _estimatedEyeYaw = estimatedEyeYaw; _blendshapeCoefficients = blendshapeCoefficients; @@ -149,7 +156,7 @@ FaceplusReader::~FaceplusReader() { void FaceplusReader::init() { #ifdef HAVE_FACEPLUS - if (!faceplus_init("VGA")) { + if (!faceplus_init("hHD")) { qDebug() << "Failed to initialized Faceplus."; return; } @@ -190,7 +197,8 @@ void FaceplusReader::init() { } } _blendshapeCoefficients.resize(maxIndex + 1); - + _referenceInitialized = false; + QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection); #endif } @@ -202,10 +210,24 @@ void FaceplusReader::shutdown() { void FaceplusReader::update() { #ifdef HAVE_FACEPLUS - if (!(faceplus_synchronous_track() && faceplus_current_output_vector(_outputVector.data()))) { + float x, y, rotation, scale; + if (!(faceplus_synchronous_track() && faceplus_current_face_location(&x, &y, &rotation, &scale) && !glm::isnan(x) && + faceplus_current_output_vector(_outputVector.data()))) { QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection); return; } + if (!_referenceInitialized) { + _referenceX = x; + _referenceY = y; + _referenceScale = scale; + _referenceInitialized = true; + } + const float TRANSLATION_SCALE = 10.0f; + const float REFERENCE_DISTANCE = 10.0f; + float depthScale = _referenceScale / scale; + float z = REFERENCE_DISTANCE * (depthScale - 1.0f); + glm::vec3 headTranslation((x - _referenceX) * depthScale * TRANSLATION_SCALE, + (y - _referenceY) * depthScale * TRANSLATION_SCALE, z); glm::quat headRotation(glm::radians(glm::vec3(-_outputVector.at(_headRotationIndices[0]), _outputVector.at(_headRotationIndices[1]), -_outputVector.at(_headRotationIndices[2])))); float estimatedEyePitch = (_outputVector.at(_leftEyeRotationIndices[0]) + @@ -221,10 +243,16 @@ void FaceplusReader::update() { } } - QMetaObject::invokeMethod(Application::getInstance()->getFaceplus(), "setState", Q_ARG(const glm::quat&, headRotation), - Q_ARG(float, estimatedEyePitch), Q_ARG(float, estimatedEyeYaw), Q_ARG(const QVector&, _blendshapeCoefficients)); + QMetaObject::invokeMethod(Application::getInstance()->getFaceplus(), "setState", Q_ARG(const glm::vec3&, headTranslation), + Q_ARG(const glm::quat&, headRotation), Q_ARG(float, estimatedEyePitch), Q_ARG(float, estimatedEyeYaw), + Q_ARG(const QVector&, _blendshapeCoefficients)); QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection); #endif } +void FaceplusReader::reset() { +#ifdef HAVE_FACEPLUS + _referenceInitialized = false; +#endif +} diff --git a/interface/src/devices/Faceplus.h b/interface/src/devices/Faceplus.h index 2b9219f3fd..f819dadca3 100644 --- a/interface/src/devices/Faceplus.h +++ b/interface/src/devices/Faceplus.h @@ -30,11 +30,12 @@ public: virtual ~Faceplus(); void init(); - + void reset(); + bool isActive() const { return _active; } - Q_INVOKABLE void setState(const glm::quat& headRotation, float estimatedEyePitch, float estimatedEyeYaw, - const QVector& blendshapeCoefficients); + Q_INVOKABLE void setState(const glm::vec3& headTranslation, const glm::quat& headRotation, + float estimatedEyePitch, float estimatedEyeYaw, const QVector& blendshapeCoefficients); public slots: @@ -63,6 +64,7 @@ public: Q_INVOKABLE void init(); Q_INVOKABLE void shutdown(); Q_INVOKABLE void update(); + Q_INVOKABLE void reset(); private: @@ -72,7 +74,11 @@ private: int _headRotationIndices[3]; int _leftEyeRotationIndices[2]; int _rightEyeRotationIndices[2]; - QVector _blendshapeCoefficients; + float _referenceX; + float _referenceY; + float _referenceScale; + bool _referenceInitialized; + QVector _blendshapeCoefficients; #endif }; From 0a2670ea23b60de1749d94f7715a84c4867a70a5 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 17 Apr 2014 13:42:29 -0700 Subject: [PATCH 2/3] Detabbed. --- interface/src/Application.cpp | 2 +- interface/src/devices/Faceplus.cpp | 44 +++++++++++++++--------------- interface/src/devices/Faceplus.h | 12 ++++---- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 978e457ae9..119fd72f17 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3020,7 +3020,7 @@ void Application::resetSensors() { _mouseX = _glWidget->width() / 2; _mouseY = _glWidget->height() / 2; - _faceplus.reset(); + _faceplus.reset(); _faceshift.reset(); _visage.reset(); diff --git a/interface/src/devices/Faceplus.cpp b/interface/src/devices/Faceplus.cpp index f06433b663..a5601932b6 100644 --- a/interface/src/devices/Faceplus.cpp +++ b/interface/src/devices/Faceplus.cpp @@ -41,15 +41,15 @@ void Faceplus::init() { } void Faceplus::reset() { - if (_enabled) { - QMetaObject::invokeMethod(_reader, "reset"); - } + if (_enabled) { + QMetaObject::invokeMethod(_reader, "reset"); + } } void Faceplus::setState(const glm::vec3& headTranslation, const glm::quat& headRotation, - float estimatedEyePitch, float estimatedEyeYaw, const QVector& blendshapeCoefficients) { + float estimatedEyePitch, float estimatedEyeYaw, const QVector& blendshapeCoefficients) { _headTranslation = headTranslation; - _headRotation = headRotation; + _headRotation = headRotation; _estimatedEyePitch = estimatedEyePitch; _estimatedEyeYaw = estimatedEyeYaw; _blendshapeCoefficients = blendshapeCoefficients; @@ -211,23 +211,23 @@ void FaceplusReader::shutdown() { void FaceplusReader::update() { #ifdef HAVE_FACEPLUS float x, y, rotation, scale; - if (!(faceplus_synchronous_track() && faceplus_current_face_location(&x, &y, &rotation, &scale) && !glm::isnan(x) && - faceplus_current_output_vector(_outputVector.data()))) { + if (!(faceplus_synchronous_track() && faceplus_current_face_location(&x, &y, &rotation, &scale) && !glm::isnan(x) && + faceplus_current_output_vector(_outputVector.data()))) { QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection); return; } - if (!_referenceInitialized) { - _referenceX = x; - _referenceY = y; - _referenceScale = scale; - _referenceInitialized = true; - } - const float TRANSLATION_SCALE = 10.0f; - const float REFERENCE_DISTANCE = 10.0f; - float depthScale = _referenceScale / scale; - float z = REFERENCE_DISTANCE * (depthScale - 1.0f); - glm::vec3 headTranslation((x - _referenceX) * depthScale * TRANSLATION_SCALE, - (y - _referenceY) * depthScale * TRANSLATION_SCALE, z); + if (!_referenceInitialized) { + _referenceX = x; + _referenceY = y; + _referenceScale = scale; + _referenceInitialized = true; + } + const float TRANSLATION_SCALE = 10.0f; + const float REFERENCE_DISTANCE = 10.0f; + float depthScale = _referenceScale / scale; + float z = REFERENCE_DISTANCE * (depthScale - 1.0f); + glm::vec3 headTranslation((x - _referenceX) * depthScale * TRANSLATION_SCALE, + (y - _referenceY) * depthScale * TRANSLATION_SCALE, z); glm::quat headRotation(glm::radians(glm::vec3(-_outputVector.at(_headRotationIndices[0]), _outputVector.at(_headRotationIndices[1]), -_outputVector.at(_headRotationIndices[2])))); float estimatedEyePitch = (_outputVector.at(_leftEyeRotationIndices[0]) + @@ -244,8 +244,8 @@ void FaceplusReader::update() { } QMetaObject::invokeMethod(Application::getInstance()->getFaceplus(), "setState", Q_ARG(const glm::vec3&, headTranslation), - Q_ARG(const glm::quat&, headRotation), Q_ARG(float, estimatedEyePitch), Q_ARG(float, estimatedEyeYaw), - Q_ARG(const QVector&, _blendshapeCoefficients)); + Q_ARG(const glm::quat&, headRotation), Q_ARG(float, estimatedEyePitch), Q_ARG(float, estimatedEyeYaw), + Q_ARG(const QVector&, _blendshapeCoefficients)); QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection); #endif @@ -253,6 +253,6 @@ void FaceplusReader::update() { void FaceplusReader::reset() { #ifdef HAVE_FACEPLUS - _referenceInitialized = false; + _referenceInitialized = false; #endif } diff --git a/interface/src/devices/Faceplus.h b/interface/src/devices/Faceplus.h index f819dadca3..f3c680c2d6 100644 --- a/interface/src/devices/Faceplus.h +++ b/interface/src/devices/Faceplus.h @@ -35,7 +35,7 @@ public: bool isActive() const { return _active; } Q_INVOKABLE void setState(const glm::vec3& headTranslation, const glm::quat& headRotation, - float estimatedEyePitch, float estimatedEyeYaw, const QVector& blendshapeCoefficients); + float estimatedEyePitch, float estimatedEyeYaw, const QVector& blendshapeCoefficients); public slots: @@ -64,7 +64,7 @@ public: Q_INVOKABLE void init(); Q_INVOKABLE void shutdown(); Q_INVOKABLE void update(); - Q_INVOKABLE void reset(); + Q_INVOKABLE void reset(); private: @@ -75,10 +75,10 @@ private: int _leftEyeRotationIndices[2]; int _rightEyeRotationIndices[2]; float _referenceX; - float _referenceY; - float _referenceScale; - bool _referenceInitialized; - QVector _blendshapeCoefficients; + float _referenceY; + float _referenceScale; + bool _referenceInitialized; + QVector _blendshapeCoefficients; #endif }; From 828bedc3e80088777000bf73af7c89fa10c652bb Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 17 Apr 2014 17:07:02 -0700 Subject: [PATCH 3/3] Slight fix for dancing bot script. --- examples/dancing_bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dancing_bot.js b/examples/dancing_bot.js index 3572cc5a11..2c0a35adb7 100644 --- a/examples/dancing_bot.js +++ b/examples/dancing_bot.js @@ -27,7 +27,7 @@ Script.update.connect(function(deltaTime) { if (!jointMapping) { var avatarJointNames = Avatar.jointNames; var animationJointNames = animation.jointNames; - if (avatarJointNames === 0 || animationJointNames.length === 0) { + if (avatarJointNames.length === 0 || animationJointNames.length === 0) { return; } jointMapping = new Array(avatarJointNames.length);