mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 11:04:00 +02:00
Proper blendshape JS api.
This commit is contained in:
parent
ba9d896856
commit
aba031a125
7 changed files with 38 additions and 2 deletions
|
@ -229,7 +229,8 @@ void Agent::run() {
|
||||||
|
|
||||||
// setup an Avatar for the script to use
|
// setup an Avatar for the script to use
|
||||||
AvatarData scriptedAvatar;
|
AvatarData scriptedAvatar;
|
||||||
|
scriptedAvatar.setForceFaceshiftConnected(true);
|
||||||
|
|
||||||
// call model URL setters with empty URLs so our avatar, if user, will have the default models
|
// call model URL setters with empty URLs so our avatar, if user, will have the default models
|
||||||
scriptedAvatar.setFaceModelURL(QUrl());
|
scriptedAvatar.setFaceModelURL(QUrl());
|
||||||
scriptedAvatar.setSkeletonModelURL(QUrl());
|
scriptedAvatar.setSkeletonModelURL(QUrl());
|
||||||
|
|
|
@ -43,6 +43,7 @@ AvatarData::AvatarData() :
|
||||||
_handState(0),
|
_handState(0),
|
||||||
_keyState(NO_KEY_DOWN),
|
_keyState(NO_KEY_DOWN),
|
||||||
_isChatCirclingEnabled(false),
|
_isChatCirclingEnabled(false),
|
||||||
|
_forceFaceshiftConnected(false),
|
||||||
_hasNewJointRotations(true),
|
_hasNewJointRotations(true),
|
||||||
_headData(NULL),
|
_headData(NULL),
|
||||||
_handData(NULL),
|
_handData(NULL),
|
||||||
|
@ -80,6 +81,9 @@ QByteArray AvatarData::toByteArray() {
|
||||||
// lazily allocate memory for HeadData in case we're not an Avatar instance
|
// lazily allocate memory for HeadData in case we're not an Avatar instance
|
||||||
if (!_headData) {
|
if (!_headData) {
|
||||||
_headData = new HeadData(this);
|
_headData = new HeadData(this);
|
||||||
|
if (_forceFaceshiftConnected) {
|
||||||
|
_headData->_isFaceshiftConnected = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray avatarDataByteArray;
|
QByteArray avatarDataByteArray;
|
||||||
|
|
|
@ -206,6 +206,10 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE virtual QStringList getJointNames() const { return _jointNames; }
|
Q_INVOKABLE virtual QStringList getJointNames() const { return _jointNames; }
|
||||||
|
|
||||||
|
Q_INVOKABLE void setBlendshape(QString name, float val) { _headData->setBlendshape(name, val); }
|
||||||
|
|
||||||
|
void setForceFaceshiftConnected(bool connected) { _forceFaceshiftConnected = connected; }
|
||||||
|
|
||||||
// key state
|
// key state
|
||||||
void setKeyState(KeyState s) { _keyState = s; }
|
void setKeyState(KeyState s) { _keyState = s; }
|
||||||
KeyState keyState() const { return _keyState; }
|
KeyState keyState() const { return _keyState; }
|
||||||
|
@ -300,7 +304,7 @@ protected:
|
||||||
std::string _chatMessage;
|
std::string _chatMessage;
|
||||||
|
|
||||||
bool _isChatCirclingEnabled;
|
bool _isChatCirclingEnabled;
|
||||||
|
bool _forceFaceshiftConnected;
|
||||||
bool _hasNewJointRotations; // set in AvatarData, cleared in Avatar
|
bool _hasNewJointRotations; // set in AvatarData, cleared in Avatar
|
||||||
|
|
||||||
HeadData* _headData;
|
HeadData* _headData;
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include "AvatarData.h"
|
#include "AvatarData.h"
|
||||||
#include "HeadData.h"
|
#include "HeadData.h"
|
||||||
|
|
||||||
|
#include "../fbx/src/FBXReader.h"
|
||||||
|
|
||||||
HeadData::HeadData(AvatarData* owningAvatar) :
|
HeadData::HeadData(AvatarData* owningAvatar) :
|
||||||
_baseYaw(0.0f),
|
_baseYaw(0.0f),
|
||||||
_basePitch(0.0f),
|
_basePitch(0.0f),
|
||||||
|
@ -52,6 +54,26 @@ void HeadData::setOrientation(const glm::quat& orientation) {
|
||||||
_baseRoll = eulers.z;
|
_baseRoll = eulers.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HeadData::setBlendshape(QString name, float val) {
|
||||||
|
static bool hasInitializedLookupMap = false;
|
||||||
|
static QMap<QString, int> blendshapeLookupMap;
|
||||||
|
//Lazily construct a lookup map from the blendshapes
|
||||||
|
if (!hasInitializedLookupMap) {
|
||||||
|
for (int i = 0; i < NUM_FACESHIFT_BLENDSHAPES; i++) {
|
||||||
|
blendshapeLookupMap[FACESHIFT_BLENDSHAPES[i]] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check to see if the named blendshape exists, and then set its value if it does
|
||||||
|
auto it = blendshapeLookupMap.find(name);
|
||||||
|
if (it != blendshapeLookupMap.end()) {
|
||||||
|
if (_blendshapeCoefficients.size() <= it.value()) {
|
||||||
|
_blendshapeCoefficients.resize(it.value() + 1);
|
||||||
|
}
|
||||||
|
_blendshapeCoefficients[it.value()] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HeadData::addYaw(float yaw) {
|
void HeadData::addYaw(float yaw) {
|
||||||
setBaseYaw(_baseYaw + yaw);
|
setBaseYaw(_baseYaw + yaw);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
float getAudioAverageLoudness() const { return _audioAverageLoudness; }
|
float getAudioAverageLoudness() const { return _audioAverageLoudness; }
|
||||||
void setAudioAverageLoudness(float audioAverageLoudness) { _audioAverageLoudness = audioAverageLoudness; }
|
void setAudioAverageLoudness(float audioAverageLoudness) { _audioAverageLoudness = audioAverageLoudness; }
|
||||||
|
|
||||||
|
void setBlendshape(QString name, float val);
|
||||||
const QVector<float>& getBlendshapeCoefficients() const { return _blendshapeCoefficients; }
|
const QVector<float>& getBlendshapeCoefficients() const { return _blendshapeCoefficients; }
|
||||||
|
|
||||||
float getPupilDilation() const { return _pupilDilation; }
|
float getPupilDilation() const { return _pupilDilation; }
|
||||||
|
|
|
@ -577,6 +577,8 @@ const char* FACESHIFT_BLENDSHAPES[] = {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const int NUM_FACESHIFT_BLENDSHAPES = sizeof(FACESHIFT_BLENDSHAPES) / sizeof(char*);
|
||||||
|
|
||||||
const char* HUMANIK_JOINTS[] = {
|
const char* HUMANIK_JOINTS[] = {
|
||||||
"RightHand",
|
"RightHand",
|
||||||
"RightForeArm",
|
"RightForeArm",
|
||||||
|
|
|
@ -29,6 +29,8 @@ typedef QList<FBXNode> FBXNodeList;
|
||||||
|
|
||||||
/// The names of the blendshapes expected by Faceshift, terminated with an empty string.
|
/// The names of the blendshapes expected by Faceshift, terminated with an empty string.
|
||||||
extern const char* FACESHIFT_BLENDSHAPES[];
|
extern const char* FACESHIFT_BLENDSHAPES[];
|
||||||
|
/// The size of FACESHIFT_BLENDSHAPES
|
||||||
|
extern const int NUM_FACESHIFT_BLENDSHAPES;
|
||||||
|
|
||||||
/// The names of the joints in the Maya HumanIK rig, terminated with an empty string.
|
/// The names of the joints in the Maya HumanIK rig, terminated with an empty string.
|
||||||
extern const char* HUMANIK_JOINTS[];
|
extern const char* HUMANIK_JOINTS[];
|
||||||
|
|
Loading…
Reference in a new issue