From 844cc03dcbbc7a8764f20cabbab13f4ce9736734 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 2 Nov 2016 10:24:01 -0700 Subject: [PATCH 1/5] fix names of model-entity joint setters --- .../src/RenderableModelEntityItem.cpp | 52 +++++++++---------- .../src/RenderableModelEntityItem.h | 4 +- libraries/entities/src/EntityItem.h | 5 +- .../entities/src/EntityScriptingInterface.cpp | 30 +++++------ .../entities/src/EntityScriptingInterface.h | 16 +++--- libraries/entities/src/ModelEntityItem.cpp | 38 +++++++------- libraries/entities/src/ModelEntityItem.h | 14 ++--- libraries/shared/src/SpatiallyNestable.h | 3 ++ 8 files changed, 80 insertions(+), 82 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 95d28f74f3..fe61b0e703 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -307,14 +307,14 @@ bool RenderableModelEntityItem::getAnimationFrame() { } glm::mat4 finalMat = (translationMat * fbxJoints[index].preTransform * rotationMat * fbxJoints[index].postTransform); - _absoluteJointTranslationsInObjectFrame[j] = extractTranslation(finalMat); - _absoluteJointTranslationsInObjectFrameSet[j] = true; - _absoluteJointTranslationsInObjectFrameDirty[j] = true; + _localJointTranslations[j] = extractTranslation(finalMat); + _localJointTranslationsSet[j] = true; + _localJointTranslationsDirty[j] = true; - _absoluteJointRotationsInObjectFrame[j] = glmExtractRotation(finalMat); + _localJointRotations[j] = glmExtractRotation(finalMat); - _absoluteJointRotationsInObjectFrameSet[j] = true; - _absoluteJointRotationsInObjectFrameDirty[j] = true; + _localJointRotationsSet[j] = true; + _localJointRotationsDirty[j] = true; } } } @@ -387,18 +387,18 @@ void RenderableModelEntityItem::render(RenderArgs* args) { getAnimationFrame(); // relay any inbound joint changes from scripts/animation/network to the model/rig - for (int index = 0; index < _absoluteJointRotationsInObjectFrame.size(); index++) { - if (_absoluteJointRotationsInObjectFrameDirty[index]) { - glm::quat rotation = _absoluteJointRotationsInObjectFrame[index]; + for (int index = 0; index < _localJointRotations.size(); index++) { + if (_localJointRotationsDirty[index]) { + glm::quat rotation = _localJointRotations[index]; _model->setJointRotation(index, true, rotation, 1.0f); - _absoluteJointRotationsInObjectFrameDirty[index] = false; + _localJointRotationsDirty[index] = false; } } - for (int index = 0; index < _absoluteJointTranslationsInObjectFrame.size(); index++) { - if (_absoluteJointTranslationsInObjectFrameDirty[index]) { - glm::vec3 translation = _absoluteJointTranslationsInObjectFrame[index]; + for (int index = 0; index < _localJointTranslations.size(); index++) { + if (_localJointTranslationsDirty[index]) { + glm::vec3 translation = _localJointTranslations[index]; _model->setJointTranslation(index, true, translation, 1.0f); - _absoluteJointTranslationsInObjectFrameDirty[index] = false; + _localJointTranslationsDirty[index] = false; } } }); @@ -1017,16 +1017,16 @@ glm::vec3 RenderableModelEntityItem::getAbsoluteJointTranslationInObjectFrame(in return glm::vec3(0.0f); } -bool RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) { +bool RenderableModelEntityItem::setLocalJointRotation(int index, const glm::quat& rotation) { bool result = false; _jointDataLock.withWriteLock([&] { _jointRotationsExplicitlySet = true; resizeJointArrays(); - if (index >= 0 && index < _absoluteJointRotationsInObjectFrame.size() && - _absoluteJointRotationsInObjectFrame[index] != rotation) { - _absoluteJointRotationsInObjectFrame[index] = rotation; - _absoluteJointRotationsInObjectFrameSet[index] = true; - _absoluteJointRotationsInObjectFrameDirty[index] = true; + if (index >= 0 && index < _localJointRotations.size() && + _localJointRotations[index] != rotation) { + _localJointRotations[index] = rotation; + _localJointRotationsSet[index] = true; + _localJointRotationsDirty[index] = true; result = true; _needsJointSimulation = true; } @@ -1034,16 +1034,16 @@ bool RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame(int index, return result; } -bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) { +bool RenderableModelEntityItem::setLocalJointTranslation(int index, const glm::vec3& translation) { bool result = false; _jointDataLock.withWriteLock([&] { _jointTranslationsExplicitlySet = true; resizeJointArrays(); - if (index >= 0 && index < _absoluteJointTranslationsInObjectFrame.size() && - _absoluteJointTranslationsInObjectFrame[index] != translation) { - _absoluteJointTranslationsInObjectFrame[index] = translation; - _absoluteJointTranslationsInObjectFrameSet[index] = true; - _absoluteJointTranslationsInObjectFrameDirty[index] = true; + if (index >= 0 && index < _localJointTranslations.size() && + _localJointTranslations[index] != translation) { + _localJointTranslations[index] = translation; + _localJointTranslationsSet[index] = true; + _localJointTranslationsDirty[index] = true; result = true; _needsJointSimulation = true; } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index a52b0b0041..8ae7a5c873 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -71,8 +71,8 @@ public: // these are in the frame of this object (model space) virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override; virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const override; - virtual bool setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) override; - virtual bool setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) override; + virtual bool setLocalJointRotation(int index, const glm::quat& rotation) override; + virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) override; virtual void setJointRotations(const QVector& rotations) override; virtual void setJointRotationsSet(const QVector& rotationsSet) override; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index a751d76b2a..d3c4cbfdfc 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -411,8 +411,9 @@ public: // these are in the frame of this object virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override { return glm::quat(); } virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const override { return glm::vec3(0.0f); } - virtual bool setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) override { return false; } - virtual bool setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) override { return false; } + + virtual bool setLocalJointRotation(int index, const glm::quat& rotation) override { return false; } + virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) override { return false; } virtual int getJointIndex(const QString& name) const { return -1; } virtual QStringList getJointNames() const { return QStringList(); } diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 306477b10c..8a2bb5731a 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -1110,12 +1110,11 @@ glm::quat EntityScriptingInterface::getAbsoluteJointRotationInObjectFrame(const } } -bool EntityScriptingInterface::setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, - int jointIndex, glm::vec3 translation) { +bool EntityScriptingInterface::setLocalJointTranslation(const QUuid& entityID, int jointIndex, glm::vec3 translation) { if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { auto now = usecTimestampNow(); auto modelEntity = std::dynamic_pointer_cast(entity); - bool result = modelEntity->setAbsoluteJointTranslationInObjectFrame(jointIndex, translation); + bool result = modelEntity->setLocalJointTranslation(jointIndex, translation); if (result) { EntityItemProperties properties; _entityTree->withWriteLock([&] { @@ -1132,12 +1131,11 @@ bool EntityScriptingInterface::setAbsoluteJointTranslationInObjectFrame(const QU return false; } -bool EntityScriptingInterface::setAbsoluteJointRotationInObjectFrame(const QUuid& entityID, - int jointIndex, glm::quat rotation) { +bool EntityScriptingInterface::setLocalJointRotation(const QUuid& entityID, int jointIndex, glm::quat rotation) { if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { auto now = usecTimestampNow(); auto modelEntity = std::dynamic_pointer_cast(entity); - bool result = modelEntity->setAbsoluteJointRotationInObjectFrame(jointIndex, rotation); + bool result = modelEntity->setLocalJointRotation(jointIndex, rotation); if (result) { EntityItemProperties properties; _entityTree->withWriteLock([&] { @@ -1156,15 +1154,14 @@ bool EntityScriptingInterface::setAbsoluteJointRotationInObjectFrame(const QUuid -bool EntityScriptingInterface::setAbsoluteJointRotationsInObjectFrame(const QUuid& entityID, - const QVector& rotations) { +bool EntityScriptingInterface::setLocalJointRotations(const QUuid& entityID, const QVector& rotations) { if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { auto now = usecTimestampNow(); auto modelEntity = std::dynamic_pointer_cast(entity); bool result = false; for (int index = 0; index < rotations.size(); index++) { - result |= modelEntity->setAbsoluteJointRotationInObjectFrame(index, rotations[index]); + result |= modelEntity->setLocalJointRotation(index, rotations[index]); } if (result) { EntityItemProperties properties; @@ -1184,15 +1181,14 @@ bool EntityScriptingInterface::setAbsoluteJointRotationsInObjectFrame(const QUui } -bool EntityScriptingInterface::setAbsoluteJointTranslationsInObjectFrame(const QUuid& entityID, - const QVector& translations) { +bool EntityScriptingInterface::setLocalJointTranslations(const QUuid& entityID, const QVector& translations) { if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { auto now = usecTimestampNow(); auto modelEntity = std::dynamic_pointer_cast(entity); bool result = false; for (int index = 0; index < translations.size(); index++) { - result |= modelEntity->setAbsoluteJointTranslationInObjectFrame(index, translations[index]); + result |= modelEntity->setLocalJointTranslation(index, translations[index]); } if (result) { EntityItemProperties properties; @@ -1211,12 +1207,12 @@ bool EntityScriptingInterface::setAbsoluteJointTranslationsInObjectFrame(const Q return false; } -bool EntityScriptingInterface::setAbsoluteJointsDataInObjectFrame(const QUuid& entityID, - const QVector& rotations, - const QVector& translations) { +bool EntityScriptingInterface::setLocalJointsData(const QUuid& entityID, + const QVector& rotations, + const QVector& translations) { // for a model with 80 joints, sending both these in one edit packet causes the packet to be too large. - return setAbsoluteJointRotationsInObjectFrame(entityID, rotations) || - setAbsoluteJointTranslationsInObjectFrame(entityID, translations); + return setLocalJointRotations(entityID, rotations) || + setLocalJointTranslations(entityID, translations); } int EntityScriptingInterface::getJointIndex(const QUuid& entityID, const QString& name) { diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 3a24ff59fd..eaa328e74d 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -184,15 +184,13 @@ public slots: Q_INVOKABLE glm::vec3 getAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex); Q_INVOKABLE glm::quat getAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex); - Q_INVOKABLE bool setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex, glm::vec3 translation); - Q_INVOKABLE bool setAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex, glm::quat rotation); - Q_INVOKABLE bool setAbsoluteJointRotationsInObjectFrame(const QUuid& entityID, - const QVector& rotations); - Q_INVOKABLE bool setAbsoluteJointTranslationsInObjectFrame(const QUuid& entityID, - const QVector& translations); - Q_INVOKABLE bool setAbsoluteJointsDataInObjectFrame(const QUuid& entityID, - const QVector& rotations, - const QVector& translations); + Q_INVOKABLE bool setLocalJointTranslation(const QUuid& entityID, int jointIndex, glm::vec3 translation); + Q_INVOKABLE bool setLocalJointRotation(const QUuid& entityID, int jointIndex, glm::quat rotation); + Q_INVOKABLE bool setLocalJointRotations(const QUuid& entityID, const QVector& rotations); + Q_INVOKABLE bool setLocalJointTranslations(const QUuid& entityID, const QVector& translations); + Q_INVOKABLE bool setLocalJointsData(const QUuid& entityID, + const QVector& rotations, + const QVector& translations); Q_INVOKABLE int getJointIndex(const QUuid& entityID, const QString& name); Q_INVOKABLE QStringList getJointNames(const QUuid& entityID); diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index b098247524..df568817ac 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -389,13 +389,13 @@ bool ModelEntityItem::shouldBePhysical() const { } void ModelEntityItem::resizeJointArrays(int newSize) { - if (newSize >= 0 && newSize > _absoluteJointRotationsInObjectFrame.size()) { - _absoluteJointRotationsInObjectFrame.resize(newSize); - _absoluteJointRotationsInObjectFrameSet.resize(newSize); - _absoluteJointRotationsInObjectFrameDirty.resize(newSize); - _absoluteJointTranslationsInObjectFrame.resize(newSize); - _absoluteJointTranslationsInObjectFrameSet.resize(newSize); - _absoluteJointTranslationsInObjectFrameDirty.resize(newSize); + if (newSize >= 0 && newSize > _localJointRotations.size()) { + _localJointRotations.resize(newSize); + _localJointRotationsSet.resize(newSize); + _localJointRotationsDirty.resize(newSize); + _localJointTranslations.resize(newSize); + _localJointTranslationsSet.resize(newSize); + _localJointTranslationsDirty.resize(newSize); } } @@ -404,9 +404,9 @@ void ModelEntityItem::setJointRotations(const QVector& rotations) { _jointRotationsExplicitlySet = rotations.size() > 0; resizeJointArrays(rotations.size()); for (int index = 0; index < rotations.size(); index++) { - if (_absoluteJointRotationsInObjectFrameSet[index]) { - _absoluteJointRotationsInObjectFrame[index] = rotations[index]; - _absoluteJointRotationsInObjectFrameDirty[index] = true; + if (_localJointRotationsSet[index]) { + _localJointRotations[index] = rotations[index]; + _localJointRotationsDirty[index] = true; } } }); @@ -417,7 +417,7 @@ void ModelEntityItem::setJointRotationsSet(const QVector& rotationsSet) { _jointRotationsExplicitlySet = rotationsSet.size() > 0; resizeJointArrays(rotationsSet.size()); for (int index = 0; index < rotationsSet.size(); index++) { - _absoluteJointRotationsInObjectFrameSet[index] = rotationsSet[index]; + _localJointRotationsSet[index] = rotationsSet[index]; } }); } @@ -427,9 +427,9 @@ void ModelEntityItem::setJointTranslations(const QVector& translation _jointTranslationsExplicitlySet = translations.size() > 0; resizeJointArrays(translations.size()); for (int index = 0; index < translations.size(); index++) { - if (_absoluteJointTranslationsInObjectFrameSet[index]) { - _absoluteJointTranslationsInObjectFrame[index] = translations[index]; - _absoluteJointTranslationsInObjectFrameSet[index] = true; + if (_localJointTranslationsSet[index]) { + _localJointTranslations[index] = translations[index]; + _localJointTranslationsSet[index] = true; } } }); @@ -440,7 +440,7 @@ void ModelEntityItem::setJointTranslationsSet(const QVector& translationsS _jointTranslationsExplicitlySet = translationsSet.size() > 0; resizeJointArrays(translationsSet.size()); for (int index = 0; index < translationsSet.size(); index++) { - _absoluteJointTranslationsInObjectFrameSet[index] = translationsSet[index]; + _localJointTranslationsSet[index] = translationsSet[index]; } }); } @@ -449,7 +449,7 @@ QVector ModelEntityItem::getJointRotations() const { QVector result; _jointDataLock.withReadLock([&] { if (_jointRotationsExplicitlySet) { - result = _absoluteJointRotationsInObjectFrame; + result = _localJointRotations; } }); return result; @@ -459,7 +459,7 @@ QVector ModelEntityItem::getJointRotationsSet() const { QVector result; _jointDataLock.withReadLock([&] { if (_jointRotationsExplicitlySet) { - result = _absoluteJointRotationsInObjectFrameSet; + result = _localJointRotationsSet; } }); @@ -470,7 +470,7 @@ QVector ModelEntityItem::getJointTranslations() const { QVector result; _jointDataLock.withReadLock([&] { if (_jointTranslationsExplicitlySet) { - result = _absoluteJointTranslationsInObjectFrame; + result = _localJointTranslations; } }); return result; @@ -480,7 +480,7 @@ QVector ModelEntityItem::getJointTranslationsSet() const { QVector result; _jointDataLock.withReadLock([&] { if (_jointTranslationsExplicitlySet) { - result = _absoluteJointTranslationsInObjectFrameSet; + result = _localJointTranslationsSet; } }); return result; diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 6f2a0e1b31..c9f278bb3b 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -143,14 +143,14 @@ protected: ReadWriteLockable _jointDataLock; bool _jointRotationsExplicitlySet { false }; // were the joints set as a property or just side effect of animations - QVector _absoluteJointRotationsInObjectFrame; - QVector _absoluteJointRotationsInObjectFrameSet; // ever set? - QVector _absoluteJointRotationsInObjectFrameDirty; // needs a relay to model/rig? - + QVector _localJointRotations; + QVector _localJointRotationsSet; // ever set? + QVector _localJointRotationsDirty; // needs a relay to model/rig? + bool _jointTranslationsExplicitlySet { false }; // were the joints set as a property or just side effect of animations - QVector _absoluteJointTranslationsInObjectFrame; - QVector _absoluteJointTranslationsInObjectFrameSet; // ever set? - QVector _absoluteJointTranslationsInObjectFrameDirty; // needs a relay to model/rig? + QVector _localJointTranslations; + QVector _localJointTranslationsSet; // ever set? + QVector _localJointTranslationsDirty; // needs a relay to model/rig? int _lastKnownCurrentFrame; virtual void resizeJointArrays(int newSize = -1); diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 5605cc0031..ece10617cb 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -144,6 +144,9 @@ public: virtual bool setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) { return false; } virtual bool setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) {return false; } + virtual bool setLocalJointRotation(int index, const glm::quat& rotation) { return false; } + virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) { return false; } + SpatiallyNestablePointer getThisPointer() const; void markAncestorMissing(bool value) { _missingAncestor = value; } From 339d6a55cfec28d12dfd1fbbd75fb298455e2ba2 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 3 Nov 2016 10:06:07 -0700 Subject: [PATCH 2/5] getLocalJointRotation getLocalJointTranslation, started on getLocalJointTranslation getLocalJointRotation --- .../src/RenderableModelEntityItem.cpp | 34 ++++++++++ .../src/RenderableModelEntityItem.h | 6 ++ .../entities/src/EntityScriptingInterface.cpp | 62 +++++++++++++++++++ .../entities/src/EntityScriptingInterface.h | 6 ++ libraries/entities/src/ModelEntityItem.h | 4 +- libraries/shared/src/SpatiallyNestable.h | 2 + 6 files changed, 112 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index fe61b0e703..976819a8f5 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1017,6 +1017,40 @@ glm::vec3 RenderableModelEntityItem::getAbsoluteJointTranslationInObjectFrame(in return glm::vec3(0.0f); } +bool RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) { + // TODO -- write this + assert(false); + abort(); + return false; +} + +bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) { + // TODO -- write this + assert(false); + abort(); + return false; +} + +glm::quat RenderableModelEntityItem::getLocalJointRotation(int index) const { + if (_model) { + glm::quat result; + if (_model->getJointRotation(index, result)) { + return result; + } + } + return glm::quat(); +} + +glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const { + if (_model) { + glm::vec3 result; + if (_model->getJointTranslation(index, result)) { + return result; + } + } + return glm::vec3(); +} + bool RenderableModelEntityItem::setLocalJointRotation(int index, const glm::quat& rotation) { bool result = false; _jointDataLock.withWriteLock([&] { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 8ae7a5c873..93d48c6085 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -71,6 +71,12 @@ public: // these are in the frame of this object (model space) virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override; virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const override; + virtual bool setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) override; + virtual bool setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) override; + + + virtual glm::quat getLocalJointRotation(int index) const override; + virtual glm::vec3 getLocalJointTranslation(int index) const override; virtual bool setLocalJointRotation(int index, const glm::quat& rotation) override; virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) override; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 8a2bb5731a..ee4db74c64 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -1110,6 +1110,68 @@ glm::quat EntityScriptingInterface::getAbsoluteJointRotationInObjectFrame(const } } +bool EntityScriptingInterface::setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, + int jointIndex, glm::vec3 translation) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { + auto now = usecTimestampNow(); + auto modelEntity = std::dynamic_pointer_cast(entity); + bool result = modelEntity->setAbsoluteJointTranslationInObjectFrame(jointIndex, translation); + if (result) { + EntityItemProperties properties; + _entityTree->withWriteLock([&] { + properties = entity->getProperties(); + entity->setLastBroadcast(now); + }); + + properties.setJointTranslationsDirty(); + properties.setLastEdited(now); + queueEntityMessage(PacketType::EntityEdit, entityID, properties); + return true; + } + } + return false; +} + +bool EntityScriptingInterface::setAbsoluteJointRotationInObjectFrame(const QUuid& entityID, + int jointIndex, glm::quat rotation) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { + auto now = usecTimestampNow(); + auto modelEntity = std::dynamic_pointer_cast(entity); + bool result = modelEntity->setAbsoluteJointRotationInObjectFrame(jointIndex, rotation); + if (result) { + EntityItemProperties properties; + _entityTree->withWriteLock([&] { + properties = entity->getProperties(); + entity->setLastBroadcast(now); + }); + + properties.setJointRotationsDirty(); + properties.setLastEdited(now); + queueEntityMessage(PacketType::EntityEdit, entityID, properties); + return true; + } + } + return false; +} + +glm::vec3 EntityScriptingInterface::getLocalJointTranslation(const QUuid& entityID, int jointIndex) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { + auto modelEntity = std::dynamic_pointer_cast(entity); + return modelEntity->getLocalJointTranslation(jointIndex); + } else { + return glm::vec3(0.0f); + } +} + +glm::quat EntityScriptingInterface::getLocalJointRotation(const QUuid& entityID, int jointIndex) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { + auto modelEntity = std::dynamic_pointer_cast(entity); + return modelEntity->getLocalJointRotation(jointIndex); + } else { + return glm::quat(); + } +} + bool EntityScriptingInterface::setLocalJointTranslation(const QUuid& entityID, int jointIndex, glm::vec3 translation) { if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { auto now = usecTimestampNow(); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index eaa328e74d..3d46113611 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -184,8 +184,14 @@ public slots: Q_INVOKABLE glm::vec3 getAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex); Q_INVOKABLE glm::quat getAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex); + Q_INVOKABLE bool setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex, glm::vec3 translation); + Q_INVOKABLE bool setAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex, glm::quat rotation); + + Q_INVOKABLE glm::vec3 getLocalJointTranslation(const QUuid& entityID, int jointIndex); + Q_INVOKABLE glm::quat getLocalJointRotation(const QUuid& entityID, int jointIndex); Q_INVOKABLE bool setLocalJointTranslation(const QUuid& entityID, int jointIndex, glm::vec3 translation); Q_INVOKABLE bool setLocalJointRotation(const QUuid& entityID, int jointIndex, glm::quat rotation); + Q_INVOKABLE bool setLocalJointRotations(const QUuid& entityID, const QVector& rotations); Q_INVOKABLE bool setLocalJointTranslations(const QUuid& entityID, const QVector& translations); Q_INVOKABLE bool setLocalJointsData(const QUuid& entityID, diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index c9f278bb3b..797474f784 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -117,8 +117,8 @@ public: virtual bool shouldBePhysical() const override; - virtual glm::vec3 getJointPosition(int jointIndex) const { return glm::vec3(); } - virtual glm::quat getJointRotation(int jointIndex) const { return glm::quat(); } + // virtual glm::vec3 getJointPosition(int jointIndex) const { return glm::vec3(); } + // virtual glm::quat getJointRotation(int jointIndex) const { return glm::quat(); } virtual void setJointRotations(const QVector& rotations); virtual void setJointRotationsSet(const QVector& rotationsSet); diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index ece10617cb..f58e2c906c 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -144,6 +144,8 @@ public: virtual bool setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) { return false; } virtual bool setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) {return false; } + virtual glm::quat getLocalJointRotation(int index) const {return glm::quat(); } + virtual glm::vec3 getLocalJointTranslation(int index) const {return glm::vec3(); } virtual bool setLocalJointRotation(int index, const glm::quat& rotation) { return false; } virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) { return false; } From e41fa94958279ef74098afe78ffe5e8197f5e13c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 4 Nov 2016 11:42:31 -0700 Subject: [PATCH 3/5] implement RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame and RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame --- libraries/animation/src/Rig.cpp | 17 +++++ libraries/animation/src/Rig.h | 3 + .../src/RenderableModelEntityItem.cpp | 62 ++++++++++++++++--- 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 877c6c3e91..722fcc92aa 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -308,6 +308,13 @@ void Rig::clearIKJointLimitHistory() { } } +int Rig::getJointParentIndex(int childIndex) { + if (_animSkeleton && isIndexValid(childIndex)) { + return _animSkeleton->getParentIndex(childIndex); + } + return -1; +} + void Rig::setJointTranslation(int index, bool valid, const glm::vec3& translation, float priority) { if (isIndexValid(index)) { if (valid) { @@ -414,6 +421,16 @@ bool Rig::getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& trans } } +bool Rig::getAbsoluteJointPoseInRigFrame(int jointIndex, AnimPose& returnPose) const { + QReadLocker readLock(&_externalPoseSetLock); + if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._absolutePoses.size()) { + returnPose = _externalPoseSet._absolutePoses[jointIndex]; + return true; + } else { + return false; + } +} + bool Rig::getJointCombinedRotation(int jointIndex, glm::quat& result, const glm::quat& rotation) const { // AJT: TODO: used by attachments ASSERT(false); diff --git a/libraries/animation/src/Rig.h b/libraries/animation/src/Rig.h index 86b8dadd85..cc4992cb31 100644 --- a/libraries/animation/src/Rig.h +++ b/libraries/animation/src/Rig.h @@ -105,6 +105,8 @@ public: void clearIKJointLimitHistory(); + int getJointParentIndex(int childIndex); + // geometry space void setJointState(int index, bool valid, const glm::quat& rotation, const glm::vec3& translation, float priority); @@ -133,6 +135,7 @@ public: // rig space (thread-safe) bool getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation) const; bool getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation) const; + bool getAbsoluteJointPoseInRigFrame(int jointIndex, AnimPose& returnPose) const; // legacy bool getJointCombinedRotation(int jointIndex, glm::quat& result, const glm::quat& rotation) const; diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index a6b3cb1d92..e58212e676 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1028,17 +1028,63 @@ glm::vec3 RenderableModelEntityItem::getAbsoluteJointTranslationInObjectFrame(in } bool RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) { - // TODO -- write this - assert(false); - abort(); - return false; + if (!_model) { + return false; + } + RigPointer rig = _model->getRig(); + if (!rig) { + return false; + } + + int jointParentIndex = rig->getJointParentIndex(index); + + bool success; + AnimPose jointParentPose; + success = rig->getAbsoluteJointPoseInRigFrame(jointParentIndex, jointParentPose); + if (!success) { + return false; + } + AnimPose jointParentInversePose = jointParentPose.inverse(); + + AnimPose jointAbsolutePose; // in rig frame + success = rig->getAbsoluteJointPoseInRigFrame(index, jointAbsolutePose); + if (!success) { + return false; + } + jointAbsolutePose.rot = rotation; + + AnimPose jointRelativePose = jointParentInversePose * jointAbsolutePose; + return setLocalJointRotation(index, jointRelativePose.rot); } bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) { - // TODO -- write this - assert(false); - abort(); - return false; + if (!_model) { + return false; + } + RigPointer rig = _model->getRig(); + if (!rig) { + return false; + } + + int jointParentIndex = rig->getJointParentIndex(index); + + bool success; + AnimPose jointParentPose; + success = rig->getAbsoluteJointPoseInRigFrame(jointParentIndex, jointParentPose); + if (!success) { + return false; + } + AnimPose jointParentInversePose = jointParentPose.inverse(); + + AnimPose jointAbsolutePose; // in rig frame + success = rig->getAbsoluteJointPoseInRigFrame(index, jointAbsolutePose); + if (!success) { + return false; + } + jointAbsolutePose.trans = translation; + + AnimPose jointRelativePose = jointParentInversePose * jointAbsolutePose; + return setLocalJointRotation(index, jointRelativePose.trans); } glm::quat RenderableModelEntityItem::getLocalJointRotation(int index) const { From 689fdfb35ff1242c6891bdc0b387b0755519c024 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 4 Nov 2016 11:44:42 -0700 Subject: [PATCH 4/5] implement RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame and RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index e58212e676..dc5b6cd8d3 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1037,6 +1037,9 @@ bool RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame(int index, } int jointParentIndex = rig->getJointParentIndex(index); + if (jointParentIndex == -1) { + return setLocalJointRotation(index, rotation); + } bool success; AnimPose jointParentPose; @@ -1067,6 +1070,9 @@ bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int ind } int jointParentIndex = rig->getJointParentIndex(index); + if (jointParentIndex == -1) { + return setLocalJointTranslation(index, translation); + } bool success; AnimPose jointParentPose; @@ -1084,7 +1090,7 @@ bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int ind jointAbsolutePose.trans = translation; AnimPose jointRelativePose = jointParentInversePose * jointAbsolutePose; - return setLocalJointRotation(index, jointRelativePose.trans); + return setLocalJointTranslation(index, jointRelativePose.trans); } glm::quat RenderableModelEntityItem::getLocalJointRotation(int index) const { From 51f6b5af78222d8d2632da7f4fb00370a09353ea Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 5 Nov 2016 10:35:21 -0700 Subject: [PATCH 5/5] code review --- libraries/animation/src/Rig.cpp | 2 +- libraries/animation/src/Rig.h | 2 +- libraries/entities/src/ModelEntityItem.h | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 722fcc92aa..45790524d1 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -308,7 +308,7 @@ void Rig::clearIKJointLimitHistory() { } } -int Rig::getJointParentIndex(int childIndex) { +int Rig::getJointParentIndex(int childIndex) const { if (_animSkeleton && isIndexValid(childIndex)) { return _animSkeleton->getParentIndex(childIndex); } diff --git a/libraries/animation/src/Rig.h b/libraries/animation/src/Rig.h index cc4992cb31..151a7ae8e9 100644 --- a/libraries/animation/src/Rig.h +++ b/libraries/animation/src/Rig.h @@ -105,7 +105,7 @@ public: void clearIKJointLimitHistory(); - int getJointParentIndex(int childIndex); + int getJointParentIndex(int childIndex) const; // geometry space void setJointState(int index, bool valid, const glm::quat& rotation, const glm::vec3& translation, float priority); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 797474f784..58766906bb 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -117,9 +117,6 @@ public: virtual bool shouldBePhysical() const override; - // virtual glm::vec3 getJointPosition(int jointIndex) const { return glm::vec3(); } - // virtual glm::quat getJointRotation(int jointIndex) const { return glm::quat(); } - virtual void setJointRotations(const QVector& rotations); virtual void setJointRotationsSet(const QVector& rotationsSet); virtual void setJointTranslations(const QVector& translations);