mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 01:16:00 +02:00
set offsets on FBXGeometry
This commit is contained in:
parent
914491ae27
commit
bcde01621d
7 changed files with 40 additions and 44 deletions
|
@ -2062,16 +2062,3 @@ void Rig::computeAvatarBoundingCapsule(
|
|||
glm::vec3 capsuleCenter = transformPoint(_geometryToRigTransform, (0.5f * (totalExtents.maximum + totalExtents.minimum)));
|
||||
localOffsetOut = capsuleCenter - hipsPosition;
|
||||
}
|
||||
|
||||
void Rig::setJointRotationOffsets(const QMap<QString, glm::quat>& offsets) {
|
||||
_jointRotationOffsets.clear();
|
||||
for (auto itr = offsets.begin(); itr != offsets.end(); itr++) {
|
||||
QString jointName = itr.key();
|
||||
glm::quat rotationOffset = itr.value();
|
||||
int jointIndex = indexOfJoint(jointName);
|
||||
if (jointIndex != -1) {
|
||||
_jointRotationOffsets.insert(jointIndex, rotationOffset);
|
||||
}
|
||||
qDebug() << "Joint Rotation Offset added to Rig._jointRotationOffsets : " << " jointName: " << jointName << " jointIndex: " << jointIndex << " rotation offset: " << rotationOffset;
|
||||
}
|
||||
}
|
|
@ -231,8 +231,6 @@ public:
|
|||
const AnimContext::DebugAlphaMap& getDebugAlphaMap() const { return _lastContext.getDebugAlphaMap(); }
|
||||
const AnimVariantMap& getAnimVars() const { return _lastAnimVars; }
|
||||
const AnimContext::DebugStateMachineMap& getStateMachineMap() const { return _lastContext.getStateMachineMap(); }
|
||||
|
||||
void setJointRotationOffsets(const QMap<QString, glm::quat>& offsets);
|
||||
|
||||
signals:
|
||||
void onLoadComplete();
|
||||
|
@ -302,8 +300,6 @@ protected:
|
|||
int _rightElbowJointIndex { -1 };
|
||||
int _rightShoulderJointIndex { -1 };
|
||||
|
||||
QMap<int, glm::quat> _jointRotationOffsets;
|
||||
|
||||
glm::vec3 _lastForward;
|
||||
glm::vec3 _lastPosition;
|
||||
glm::vec3 _lastVelocity;
|
||||
|
|
|
@ -83,7 +83,6 @@ void SkeletonModel::initJointStates() {
|
|||
|
||||
// Skeleton may have already been scaled so unscale it
|
||||
_defaultEyeModelPosition = _defaultEyeModelPosition / _scale;
|
||||
_rig.setJointRotationOffsets(FSTReader::getJointRotationOffsets(getGeometry()->getMapping()));
|
||||
computeBoundingShape();
|
||||
|
||||
Extents meshExtents = getMeshExtents();
|
||||
|
|
|
@ -366,6 +366,8 @@ public:
|
|||
QString getModelNameOfMesh(int meshIndex) const;
|
||||
|
||||
QList<QString> blendshapeChannelNames;
|
||||
|
||||
QMap<int, glm::quat> jointRotationOffsets;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(FBXGeometry)
|
||||
|
|
|
@ -615,6 +615,31 @@ QByteArray fileOnUrl(const QByteArray& filepath, const QString& url) {
|
|||
return filepath.mid(filepath.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
QMap<QString, glm::quat> getJointRotationOffsets(const QVariantHash& mapping) {
|
||||
QMap<QString, glm::quat> jointRotationOffsets;
|
||||
static const QString JOINT_ROTATION_OFFSET_FIELD = "jointRotationOffset";
|
||||
if (!mapping.isEmpty() && mapping.contains(JOINT_ROTATION_OFFSET_FIELD) && mapping[JOINT_ROTATION_OFFSET_FIELD].type() == QVariant::Hash) {
|
||||
auto offsets = mapping[JOINT_ROTATION_OFFSET_FIELD].toHash();
|
||||
for (auto itr = offsets.begin(); itr != offsets.end(); itr++) {
|
||||
QString jointName = itr.key();
|
||||
QString line = itr.value().toString();
|
||||
auto eulerAngles = line.split(',');
|
||||
if (eulerAngles.size() == 3) {
|
||||
float eulerX = eulerAngles[0].mid(1).toFloat();
|
||||
float eulerY = eulerAngles[1].toFloat();
|
||||
float eulerZ = eulerAngles[2].mid(0, eulerAngles[2].size() - 1).toFloat();
|
||||
if (!isNaN(eulerX) && !isNaN(eulerY) && !isNaN(eulerZ)) {
|
||||
glm::quat rotationOffset = (glm::angleAxis(eulerX * RADIANS_PER_DEGREE, Vectors::UNIT_X) *
|
||||
glm::angleAxis(eulerY * RADIANS_PER_DEGREE, Vectors::UNIT_Y) *
|
||||
glm::angleAxis(eulerZ * RADIANS_PER_DEGREE, Vectors::UNIT_Z));
|
||||
jointRotationOffsets.insert(jointName, rotationOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return jointRotationOffsets;
|
||||
}
|
||||
|
||||
FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QString& url) {
|
||||
const FBXNode& node = _rootNode;
|
||||
QMap<QString, ExtractedMesh> meshes;
|
||||
|
@ -1991,6 +2016,19 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto offsets = getJointRotationOffsets(mapping);
|
||||
geometry.jointRotationOffsets.clear();
|
||||
for (auto itr = offsets.begin(); itr != offsets.end(); itr++) {
|
||||
QString jointName = itr.key();
|
||||
glm::quat rotationOffset = itr.value();
|
||||
int jointIndex = geometry.getJointIndex(jointName);
|
||||
if (jointIndex != -1) {
|
||||
geometry.jointRotationOffsets.insert(jointIndex, rotationOffset);
|
||||
}
|
||||
qCDebug(modelformat) << "Joint Rotation Offset added to Rig._jointRotationOffsets : " << " jointName: " << jointName << " jointIndex: " << jointIndex << " rotation offset: " << rotationOffset;
|
||||
}
|
||||
|
||||
return geometryPtr;
|
||||
}
|
||||
|
||||
|
|
|
@ -207,30 +207,6 @@ QVector<QString> FSTReader::getScripts(const QUrl& url, const QVariantHash& mapp
|
|||
return scriptPaths;
|
||||
}
|
||||
|
||||
QMap<QString, glm::quat> FSTReader::getJointRotationOffsets(const QVariantHash& mapping) {
|
||||
QMap<QString, glm::quat> jointRotationOffsets;
|
||||
if (!mapping.isEmpty() && mapping.contains(JOINT_ROTATION_OFFSET_FIELD) && mapping[JOINT_ROTATION_OFFSET_FIELD].type() == QVariant::Hash) {
|
||||
auto offsets = mapping[JOINT_ROTATION_OFFSET_FIELD].toHash();
|
||||
for (auto itr = offsets.begin(); itr != offsets.end(); itr++) {
|
||||
QString jointName = itr.key();
|
||||
QString line = itr.value().toString();
|
||||
auto eulerAngles = line.split(',');
|
||||
if (eulerAngles.size() == 3) {
|
||||
float eulerX = eulerAngles[0].mid(1).toFloat();
|
||||
float eulerY = eulerAngles[1].toFloat();
|
||||
float eulerZ = eulerAngles[2].mid(0, eulerAngles[2].size() - 1).toFloat();
|
||||
if (!isNaN(eulerX) && !isNaN(eulerY) && !isNaN(eulerZ)) {
|
||||
glm::quat rotationOffset = (glm::angleAxis(eulerX * RADIANS_PER_DEGREE, Vectors::UNIT_X) *
|
||||
glm::angleAxis(eulerY * RADIANS_PER_DEGREE, Vectors::UNIT_Y) *
|
||||
glm::angleAxis(eulerZ * RADIANS_PER_DEGREE, Vectors::UNIT_Z));
|
||||
jointRotationOffsets.insert(jointName, rotationOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return jointRotationOffsets;
|
||||
}
|
||||
|
||||
QVariantHash FSTReader::downloadMapping(const QString& url) {
|
||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||
|
|
|
@ -30,7 +30,6 @@ static const QString JOINT_FIELD = "joint";
|
|||
static const QString FREE_JOINT_FIELD = "freeJoint";
|
||||
static const QString BLENDSHAPE_FIELD = "bs";
|
||||
static const QString SCRIPT_FIELD = "script";
|
||||
static const QString JOINT_ROTATION_OFFSET_FIELD = "jointRotationOffset";
|
||||
|
||||
class FSTReader {
|
||||
public:
|
||||
|
@ -53,7 +52,6 @@ public:
|
|||
static ModelType predictModelType(const QVariantHash& mapping);
|
||||
|
||||
static QVector<QString> getScripts(const QUrl& fstUrl, const QVariantHash& mapping = QVariantHash());
|
||||
static QMap<QString, glm::quat> getJointRotationOffsets(const QVariantHash& mapping);
|
||||
|
||||
static QString getNameFromType(ModelType modelType);
|
||||
static FSTReader::ModelType getTypeFromName(const QString& name);
|
||||
|
|
Loading…
Reference in a new issue