QJsonObject HeadData::toJson() const { QJsonObject headJson; const auto& blendshapeLookupMap = getBlendshapesLookupMap(); QJsonObject blendshapesJson; for (auto name : blendshapeLookupMap.keys()) { auto index = blendshapeLookupMap[name]; if (index >= _blendshapeCoefficients.size()) { continue; } auto value = _blendshapeCoefficients[index]; if (value == 0.0f) { continue; } blendshapesJson[name] = value; } if (!blendshapesJson.isEmpty()) { headJson[JSON_AVATAR_HEAD_BLENDSHAPE_COEFFICIENTS] = blendshapesJson; } if (getRawOrientation() != quat()) { headJson[JSON_AVATAR_HEAD_ROTATION] = toJsonValue(getRawOrientation()); } if (getLeanForward() != 0.0f) { headJson[JSON_AVATAR_HEAD_LEAN_FORWARD] = getLeanForward(); } if (getLeanSideways() != 0.0f) { headJson[JSON_AVATAR_HEAD_LEAN_SIDEWAYS] = getLeanSideways(); } auto lookat = getLookAtPosition(); if (lookat != vec3()) { vec3 relativeLookAt = glm::inverse(_owningAvatar->getOrientation()) * (getLookAtPosition() - _owningAvatar->getPosition()); headJson[JSON_AVATAR_HEAD_LOOKAT] = toJsonValue(relativeLookAt); } return headJson; }
QJsonObject HeadData::toJson() const { QJsonObject headJson; const auto& blendshapeLookupMap = getBlendshapesLookupMap(); QJsonObject blendshapesJson; for (auto name : blendshapeLookupMap.keys()) { auto index = blendshapeLookupMap[name]; float value = 0.0f; if (index < _blendshapeCoefficients.size()) { value += _blendshapeCoefficients[index]; } if (index < _transientBlendshapeCoefficients.size()) { value += _transientBlendshapeCoefficients[index]; } if (value != 0.0f) { blendshapesJson[name] = value; } } if (!blendshapesJson.isEmpty()) { headJson[JSON_AVATAR_HEAD_BLENDSHAPE_COEFFICIENTS] = blendshapesJson; } if (getRawOrientation() != quat()) { headJson[JSON_AVATAR_HEAD_ROTATION] = toJsonValue(getRawOrientation()); } auto lookat = getLookAtPosition(); if (lookat != vec3()) { vec3 relativeLookAt = glm::inverse(_owningAvatar->getOrientation()) * (getLookAtPosition() - _owningAvatar->getPosition()); headJson[JSON_AVATAR_HEAD_LOOKAT] = toJsonValue(relativeLookAt); } return headJson; }
void HeadData::setBlendshape(QString name, float val) { const auto& blendshapeLookupMap = getBlendshapesLookupMap(); //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; } }