mirror of
https://github.com/lubosz/overte.git
synced 2025-04-14 06:46:19 +02:00
Added support for setting Variants in the json file.
For example: the avatar.json file was updated to use the "sine" Variant to drive the Overlay alpha parameter.
This commit is contained in:
parent
4abf0cbd63
commit
0c02a338f2
6 changed files with 63 additions and 13 deletions
|
@ -1232,7 +1232,8 @@ void MyAvatar::setupNewAnimationSystem() {
|
|||
//AnimDebugDraw::getInstance().addSkeleton("my-avatar", _animSkeleton, xform);
|
||||
|
||||
// load the anim graph
|
||||
auto graphUrl = QUrl("https://gist.githubusercontent.com/hyperlogic/7d6a0892a7319c69e2b9/raw/a939eadee4f36248776913d42891954a8d009158/avatar.json");
|
||||
// https://gist.github.com/hyperlogic/7d6a0892a7319c69e2b9
|
||||
auto graphUrl = QUrl("https://gist.githubusercontent.com/hyperlogic/7d6a0892a7319c69e2b9/raw/c4a9223e97b1d00b423b87542a2a57895ca72d21/avatar.json");
|
||||
_animLoader.reset(new AnimNodeLoader(graphUrl));
|
||||
connect(_animLoader.get(), &AnimNodeLoader::success, [this](AnimNode::Pointer nodeIn) {
|
||||
_animNode = nodeIn;
|
||||
|
|
|
@ -31,9 +31,9 @@ public:
|
|||
|
||||
virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, float dt) override;
|
||||
|
||||
protected:
|
||||
void setAlphaVar(const std::string& alphaVar) { _alphaVar = alphaVar; }
|
||||
|
||||
protected:
|
||||
// for AnimDebugDraw rendering
|
||||
virtual const AnimPoseVec& getPosesInternal() const override;
|
||||
|
||||
|
|
|
@ -29,15 +29,15 @@ public:
|
|||
|
||||
virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, float dt) override;
|
||||
|
||||
protected:
|
||||
void loadURL(const std::string& url);
|
||||
|
||||
void setStartFrameVar(const std::string& startFrameVar) { _startFrameVar = startFrameVar; }
|
||||
void setEndFrameVar(const std::string& endFrameVar) { _endFrameVar = endFrameVar; }
|
||||
void setTimeScaleVar(const std::string& timeScaleVar) { _timeScaleVar = timeScaleVar; }
|
||||
void setLoopFlagVar(const std::string& loopFlagVar) { _loopFlagVar = loopFlagVar; }
|
||||
void setFrameVar(const std::string& frameVar) { _frameVar = frameVar; }
|
||||
|
||||
protected:
|
||||
void loadURL(const std::string& url);
|
||||
|
||||
virtual void setCurrentFrameInternal(float frame) override;
|
||||
|
||||
float accumulateTime(float frame, float dt) const;
|
||||
|
|
|
@ -54,6 +54,13 @@ static NodeLoaderFunc nodeLoaderFuncs[AnimNode::NumTypes] = {
|
|||
} \
|
||||
QString NAME = NAME##_VAL.toString()
|
||||
|
||||
#define READ_OPTIONAL_STRING(NAME, JSON_OBJ) \
|
||||
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
||||
QString NAME; \
|
||||
if (NAME##_VAL.isString()) { \
|
||||
NAME = NAME##_VAL.toString(); \
|
||||
}
|
||||
|
||||
#define READ_BOOL(NAME, JSON_OBJ, ID, URL) \
|
||||
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
||||
if (!NAME##_VAL.isBool()) { \
|
||||
|
@ -137,14 +144,42 @@ static AnimNode::Pointer loadClipNode(const QJsonObject& jsonObj, const QString&
|
|||
READ_FLOAT(timeScale, jsonObj, id, jsonUrl);
|
||||
READ_BOOL(loopFlag, jsonObj, id, jsonUrl);
|
||||
|
||||
return std::make_shared<AnimClip>(id.toStdString(), url.toStdString(), startFrame, endFrame, timeScale, loopFlag);
|
||||
READ_OPTIONAL_STRING(startFrameVar, jsonObj);
|
||||
READ_OPTIONAL_STRING(endFrameVar, jsonObj);
|
||||
READ_OPTIONAL_STRING(timeScaleVar, jsonObj);
|
||||
READ_OPTIONAL_STRING(loopFlagVar, jsonObj);
|
||||
|
||||
auto node = std::make_shared<AnimClip>(id.toStdString(), url.toStdString(), startFrame, endFrame, timeScale, loopFlag);
|
||||
|
||||
if (!startFrameVar.isEmpty()) {
|
||||
node->setStartFrameVar(startFrameVar.toStdString());
|
||||
}
|
||||
if (!endFrameVar.isEmpty()) {
|
||||
node->setEndFrameVar(endFrameVar.toStdString());
|
||||
}
|
||||
if (!timeScaleVar.isEmpty()) {
|
||||
node->setTimeScaleVar(timeScaleVar.toStdString());
|
||||
}
|
||||
if (!loopFlagVar.isEmpty()) {
|
||||
node->setLoopFlagVar(loopFlagVar.toStdString());
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static AnimNode::Pointer loadBlendLinearNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||
|
||||
READ_FLOAT(alpha, jsonObj, id, jsonUrl);
|
||||
|
||||
return std::make_shared<AnimBlendLinear>(id.toStdString(), alpha);
|
||||
READ_OPTIONAL_STRING(alphaVar, jsonObj);
|
||||
|
||||
auto node = std::make_shared<AnimBlendLinear>(id.toStdString(), alpha);
|
||||
|
||||
if (!alphaVar.isEmpty()) {
|
||||
node->setAlphaVar(alphaVar.toStdString());
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static const char* boneSetStrings[AnimOverlay::NumBoneSets] = {
|
||||
|
@ -172,6 +207,7 @@ static AnimOverlay::BoneSet stringToBoneSetEnum(const QString& str) {
|
|||
static AnimNode::Pointer loadOverlayNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||
|
||||
READ_STRING(boneSet, jsonObj, id, jsonUrl);
|
||||
READ_FLOAT(alpha, jsonObj, id, jsonUrl);
|
||||
|
||||
auto boneSetEnum = stringToBoneSetEnum(boneSet);
|
||||
if (boneSetEnum == AnimOverlay::NumBoneSets) {
|
||||
|
@ -179,7 +215,19 @@ static AnimNode::Pointer loadOverlayNode(const QJsonObject& jsonObj, const QStri
|
|||
boneSetEnum = AnimOverlay::FullBodyBoneSet;
|
||||
}
|
||||
|
||||
return std::make_shared<AnimBlendLinear>(id.toStdString(), boneSetEnum);
|
||||
READ_OPTIONAL_STRING(boneSetVar, jsonObj);
|
||||
READ_OPTIONAL_STRING(alphaVar, jsonObj);
|
||||
|
||||
auto node = std::make_shared<AnimOverlay>(id.toStdString(), boneSetEnum, alpha);
|
||||
|
||||
if (!boneSetVar.isEmpty()) {
|
||||
node->setBoneSetVar(boneSetVar.toStdString());
|
||||
}
|
||||
if (!alphaVar.isEmpty()) {
|
||||
node->setAlphaVar(alphaVar.toStdString());
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
AnimNodeLoader::AnimNodeLoader(const QUrl& url) :
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
class AnimOverlay : public AnimNode {
|
||||
public:
|
||||
friend class AnimDebugDraw;
|
||||
friend class AnimTests;
|
||||
|
||||
enum BoneSet {
|
||||
FullBodyBoneSet = 0,
|
||||
|
@ -42,12 +42,12 @@ public:
|
|||
|
||||
virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, float dt) override;
|
||||
|
||||
protected:
|
||||
void buildBoneSet(BoneSet boneSet);
|
||||
|
||||
void setBoneSetVar(const std::string& boneSetVar) { _boneSetVar = boneSetVar; }
|
||||
void setAlphaVar(const std::string& alphaVar) { _alphaVar = alphaVar; }
|
||||
|
||||
protected:
|
||||
void buildBoneSet(BoneSet boneSet);
|
||||
|
||||
// for AnimDebugDraw rendering
|
||||
virtual const AnimPoseVec& getPosesInternal() const override;
|
||||
virtual void setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) override;
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"type": "overlay",
|
||||
"data": {
|
||||
"boneSet": "upperBody",
|
||||
"alpha": 1.0
|
||||
"alpha": 1.0,
|
||||
"alphaVar": "sine"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue