From 844cc03dcbbc7a8764f20cabbab13f4ce9736734 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 2 Nov 2016 10:24:01 -0700 Subject: [PATCH 01/22] 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 02/22] 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 03/22] 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 04/22] 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 05/22] 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); From 86a569651c501da4f4f3e7d70e809b8023b67135 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 7 Nov 2016 14:45:26 -0800 Subject: [PATCH 06/22] Add more precuation when extracting the opengl version in the openGLVersionChecker to avoid crashing --- libraries/gl/src/gl/OpenGLVersionChecker.cpp | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/libraries/gl/src/gl/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp index 6473b6bf2b..9a41ebfdca 100644 --- a/libraries/gl/src/gl/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -75,15 +75,26 @@ QJsonObject OpenGLVersionChecker::checkVersion(bool& valid, bool& override) { // - major_number.minor_number // - major_number.minor_number.release_number // Reference: https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glGetString.xml - const QString version { "version" }; - QString glVersion = glData[version].toString(); - QStringList versionParts = glVersion.split(QRegularExpression("[\\.\\s]")); - int majorNumber = versionParts[0].toInt(); - int minorNumber = versionParts[1].toInt(); + int minimumMajorNumber = (MINIMUM_GL_VERSION >> 16); int minimumMinorNumber = (MINIMUM_GL_VERSION & 0xFF); - valid = (majorNumber > minimumMajorNumber - || (majorNumber == minimumMajorNumber && minorNumber >= minimumMinorNumber)); + int majorNumber = 0; + int minorNumber = 0; + const QString version { "version" }; + if (version.contains(version)) { + QString glVersion = glData[version].toString(); + QStringList versionParts = glVersion.split(QRegularExpression("[\\.\\s]")); + if (versionParts.size() >= 2) { + majorNumber = versionParts[0].toInt(); + minorNumber = versionParts[1].toInt(); + valid = (majorNumber > minimumMajorNumber + || (majorNumber == minimumMajorNumber && minorNumber >= minimumMinorNumber)); + } else { + valid = false; + } + } else { + valid = false; + } // Prompt user if below minimum if (!valid) { From 284b458148dd9e0a1f32700bab7ee211d16301f6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 8 Nov 2016 09:46:47 -0800 Subject: [PATCH 07/22] Increase margin at bottom of users.js --- scripts/system/users.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/system/users.js b/scripts/system/users.js index 1e4cf042f3..68501721b3 100644 --- a/scripts/system/users.js +++ b/scripts/system/users.js @@ -228,7 +228,7 @@ var usersWindow = (function () { var WINDOW_WIDTH = 260, WINDOW_MARGIN = 12, - WINDOW_BASE_MARGIN = 6, // A little less is needed in order look correct + WINDOW_BASE_MARGIN = 24, // A little less is needed in order look correct WINDOW_FONT = { size: 12 }, @@ -254,10 +254,11 @@ var usersWindow = (function () { windowHeading, // Window border is similar to that of edit.js. - WINDOW_BORDER_WIDTH = WINDOW_WIDTH + 2 * WINDOW_BASE_MARGIN, - WINDOW_BORDER_TOP_MARGIN = 2 * WINDOW_BASE_MARGIN, - WINDOW_BORDER_BOTTOM_MARGIN = WINDOW_BASE_MARGIN, - WINDOW_BORDER_LEFT_MARGIN = WINDOW_BASE_MARGIN, + WINDOW_MARGIN_HALF = WINDOW_MARGIN / 2, + WINDOW_BORDER_WIDTH = WINDOW_WIDTH + 2 * WINDOW_MARGIN_HALF, + WINDOW_BORDER_TOP_MARGIN = 2 * WINDOW_MARGIN_HALF, + WINDOW_BORDER_BOTTOM_MARGIN = WINDOW_MARGIN_HALF, + WINDOW_BORDER_LEFT_MARGIN = WINDOW_MARGIN_HALF, WINDOW_BORDER_RADIUS = 4, WINDOW_BORDER_COLOR = { red: 255, green: 255, blue: 255 }, WINDOW_BORDER_ALPHA = 0.5, From 5dab2ac2a7b492b46d741f818bfdb3ccd4aaf412 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 8 Nov 2016 09:47:09 -0800 Subject: [PATCH 08/22] Add margin to left and right side of users.js --- scripts/system/users.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/system/users.js b/scripts/system/users.js index 68501721b3..d03a5bb846 100644 --- a/scripts/system/users.js +++ b/scripts/system/users.js @@ -253,6 +253,11 @@ var usersWindow = (function () { windowPane, windowHeading, + // Margin on the left and right side of the window to keep + // it from getting too close to the edge of the screen which + // is unclickable. + WINDOW_MARGIN_X = 20, + // Window border is similar to that of edit.js. WINDOW_MARGIN_HALF = WINDOW_MARGIN / 2, WINDOW_BORDER_WIDTH = WINDOW_WIDTH + 2 * WINDOW_MARGIN_HALF, @@ -446,7 +451,7 @@ var usersWindow = (function () { } function saturateWindowPosition() { - windowPosition.x = Math.max(0, Math.min(viewport.x - WINDOW_WIDTH, windowPosition.x)); + windowPosition.x = Math.max(WINDOW_MARGIN_X, Math.min(viewport.x - WINDOW_WIDTH - WINDOW_MARGIN_X, windowPosition.x)); windowPosition.y = Math.max(windowMinimumHeight, Math.min(viewport.y, windowPosition.y)); } From a4e75b4dcf334bcbf9980d187a2cfabbaa730970 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 8 Nov 2016 14:51:48 -0800 Subject: [PATCH 09/22] FIx an obvious mistake, good catch MR Zappoman --- libraries/gl/src/gl/OpenGLVersionChecker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/gl/src/gl/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp index 9a41ebfdca..24b61e5128 100644 --- a/libraries/gl/src/gl/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -81,7 +81,7 @@ QJsonObject OpenGLVersionChecker::checkVersion(bool& valid, bool& override) { int majorNumber = 0; int minorNumber = 0; const QString version { "version" }; - if (version.contains(version)) { + if (glData.contains(version)) { QString glVersion = glData[version].toString(); QStringList versionParts = glVersion.split(QRegularExpression("[\\.\\s]")); if (versionParts.size() >= 2) { From 35f857ef9d751a46a13523c0f778deab0c7edfa6 Mon Sep 17 00:00:00 2001 From: humbletim Date: Wed, 9 Nov 2016 13:21:24 -0500 Subject: [PATCH 10/22] inhibit user interactions when window is disabled --- scripts/system/users.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/system/users.js b/scripts/system/users.js index 1e4cf042f3..a81903b07a 100644 --- a/scripts/system/users.js +++ b/scripts/system/users.js @@ -371,7 +371,8 @@ var usersWindow = (function () { MENU_NAME = "View", MENU_ITEM = "Users Online", - MENU_ITEM_AFTER = "Overlays", + MENU_ITEM_OVERLAYS = "Overlays", + MENU_ITEM_AFTER = MENU_ITEM_OVERLAYS, SETTING_USERS_SHOW_ME = "UsersWindow.ShowMe", SETTING_USERS_VISIBLE_TO = "UsersWindow.VisibleTo", @@ -399,6 +400,10 @@ var usersWindow = (function () { scrollbarBarClickedAt, // 0.0 .. 1.0 scrollbarValue = 0.0; // 0.0 .. 1.0 + function isWindowDisabled() { + return !Menu.isOptionChecked(MENU_ITEM) || !Menu.isOptionChecked(MENU_ITEM_OVERLAYS); + } + function isValueTrue(value) { // Work around Boolean Settings values being read as string when Interface starts up but as Booleans when re-read after // Being written if refresh script. @@ -744,7 +749,7 @@ var usersWindow = (function () { userClicked, delta; - if (!isVisible) { + if (!isVisible || isWindowDisabled()) { return; } @@ -856,7 +861,7 @@ var usersWindow = (function () { function onMouseMoveEvent(event) { var isVisible; - if (!isLoggedIn) { + if (!isLoggedIn || isWindowDisabled()) { return; } @@ -914,6 +919,10 @@ var usersWindow = (function () { function onMouseReleaseEvent() { var offset = {}; + if (isWindowDisabled()) { + return; + } + if (isMovingScrollbar) { Overlays.editOverlay(scrollbarBar, { backgroundAlpha: SCROLLBAR_BAR_ALPHA @@ -939,6 +948,10 @@ var usersWindow = (function () { MIRROR_MENU_ITEM = "Mirror", FULLSCREEN_MIRROR_MENU_ITEM = "Fullscreen Mirror"; + if (isWindowDisabled()) { + return; + } + viewport = Controller.getViewportDimensions(); isMirrorDisplay = Menu.isOptionChecked(MIRROR_MENU_ITEM); isFullscreenMirror = Menu.isOptionChecked(FULLSCREEN_MIRROR_MENU_ITEM); From b7381c30cb605ed7e23aa3f7c8d0d773905c5f25 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 9 Nov 2016 10:38:44 -0800 Subject: [PATCH 11/22] Including the fix for the bad Major Version number from David K --- libraries/gl/src/gl/OpenGLVersionChecker.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/gl/src/gl/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp index 24b61e5128..428bf86c6f 100644 --- a/libraries/gl/src/gl/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -21,6 +21,7 @@ #include "GLHelpers.h" +// Minimum gl version required is 4.1 #define MINIMUM_GL_VERSION 0x0401 OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : @@ -76,7 +77,7 @@ QJsonObject OpenGLVersionChecker::checkVersion(bool& valid, bool& override) { // - major_number.minor_number.release_number // Reference: https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glGetString.xml - int minimumMajorNumber = (MINIMUM_GL_VERSION >> 16); + int minimumMajorNumber = (MINIMUM_GL_VERSION >> 8) & 0xFF; int minimumMinorNumber = (MINIMUM_GL_VERSION & 0xFF); int majorNumber = 0; int minorNumber = 0; From 941e5a57b18c532b683ccd66d729727688d63290 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 9 Nov 2016 17:25:46 -0800 Subject: [PATCH 12/22] trying a test with 4.4 as the minimum gl context to be able to break on Intel integrated --- libraries/gl/src/gl/Context.cpp | 6 ++++-- libraries/gl/src/gl/OpenGLVersionChecker.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/gl/src/gl/Context.cpp b/libraries/gl/src/gl/Context.cpp index ec1c284e99..fe48968981 100644 --- a/libraries/gl/src/gl/Context.cpp +++ b/libraries/gl/src/gl/Context.cpp @@ -217,8 +217,10 @@ void Context::create() { glewInit(); if (glewIsSupported("GL_VERSION_4_5")) { _version = 0x0405; - } else if (glewIsSupported("GL_VERSION_4_3")) { - _version = 0x0403; + // } else if (glewIsSupported("GL_VERSION_4_3")) { + } else if (glewIsSupported("GL_VERSION_4_4")) { +///_version = 0x0403; + _version = 0x0404; } glGetError(); wglMakeCurrent(0, 0); diff --git a/libraries/gl/src/gl/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp index 428bf86c6f..273251581a 100644 --- a/libraries/gl/src/gl/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -22,7 +22,8 @@ #include "GLHelpers.h" // Minimum gl version required is 4.1 -#define MINIMUM_GL_VERSION 0x0401 +//#define MINIMUM_GL_VERSION 0x0401 +#define MINIMUM_GL_VERSION 0x0404 OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : QApplication(argc, argv) From 5b244357e0542122a2eea6fc51c09920d307e188 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Nov 2016 18:03:42 -0800 Subject: [PATCH 13/22] Add jsdoc readme and plugin --- scripts/jsdoc/.gitignore | 1 + scripts/jsdoc/README.md | 13 ++++++++++++ scripts/jsdoc/config.json | 8 +++++++ scripts/jsdoc/plugins/hifi.js | 40 +++++++++++++++++++++++++++++++++++ scripts/jsdoc/root.js | 11 ++++++++++ 5 files changed, 73 insertions(+) create mode 100644 scripts/jsdoc/.gitignore create mode 100644 scripts/jsdoc/README.md create mode 100644 scripts/jsdoc/config.json create mode 100644 scripts/jsdoc/plugins/hifi.js create mode 100644 scripts/jsdoc/root.js diff --git a/scripts/jsdoc/.gitignore b/scripts/jsdoc/.gitignore new file mode 100644 index 0000000000..c585e19389 --- /dev/null +++ b/scripts/jsdoc/.gitignore @@ -0,0 +1 @@ +out \ No newline at end of file diff --git a/scripts/jsdoc/README.md b/scripts/jsdoc/README.md new file mode 100644 index 0000000000..c43f95cabe --- /dev/null +++ b/scripts/jsdoc/README.md @@ -0,0 +1,13 @@ +#JavaScript Documentation Generation + +##Prerequisites + +* Install node.js +* Install jsdoc via npm. `npm install jsdoc -g` + +To generate html documentation for the High Fidelity JavaScript API + +`cd scripts/jsdoc` +`jsdoc . -c config.json` + +The out folder should contain index.html diff --git a/scripts/jsdoc/config.json b/scripts/jsdoc/config.json new file mode 100644 index 0000000000..0fb833d015 --- /dev/null +++ b/scripts/jsdoc/config.json @@ -0,0 +1,8 @@ +{ + "templates": { + "default": { + "outputSourceFiles": false + } + }, + "plugins": ["plugins/hifi"] +} diff --git a/scripts/jsdoc/plugins/hifi.js b/scripts/jsdoc/plugins/hifi.js new file mode 100644 index 0000000000..fde4183db8 --- /dev/null +++ b/scripts/jsdoc/plugins/hifi.js @@ -0,0 +1,40 @@ +function endsWith(path, exts) { + var result = false; + exts.forEach(function(ext) { + if (path.endsWith(ext)) { + result = true; + } + }); + return result; +} + +exports.handlers = { + beforeParse: function(e) { + console.log("Scanning hifi source for jsdoc comments..."); + + // directories to scan for jsdoc comments + var dirList = [ + '../../interface/src', + '../../libraries/script-engine/src', + '../../libraries/networking/src', + '../../libraries/animation/src' + ]; + var exts = ['.h', '.cpp']; + + const fs = require('fs'); + dirList.forEach(function (dir) { + var files = fs.readdirSync(dir) + files.forEach(function (file) { + var path = dir + "/" + file; + if (fs.lstatSync(path).isFile() && endsWith(path, exts)) { + var data = fs.readFileSync(path, "utf8"); + var reg = /(\/\*\*jsdoc(.|[\r\n])*?\*\/)/gm; + var matches = data.match(reg); + if (matches) { + e.source += matches.map(function (s) { return s.replace('/**jsdoc', '/**'); }).join('\n'); + } + } + }); + }); + } +}; diff --git a/scripts/jsdoc/root.js b/scripts/jsdoc/root.js new file mode 100644 index 0000000000..097403f723 --- /dev/null +++ b/scripts/jsdoc/root.js @@ -0,0 +1,11 @@ +// +// root.js +// +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +// Root of High Fidelity generated java script documentation +// + From 839b1a3c5e872c806a809c2b61676b0f3c731be0 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Nov 2016 18:09:10 -0800 Subject: [PATCH 14/22] Added some jsdoc comments to the C++ source --- .../src/scripting/AccountScriptingInterface.h | 23 +++++ libraries/animation/src/AnimationCache.h | 12 +++ libraries/networking/src/ResourceCache.h | 86 ++++++++++++++++++- .../src/AssetScriptingInterface.h | 47 ++++++++++ 4 files changed, 167 insertions(+), 1 deletion(-) diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 0f958f2286..748f110356 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -19,12 +19,35 @@ class AccountScriptingInterface : public QObject { Q_PROPERTY(QString username READ getUsername NOTIFY usernameChanged) + /**jsdoc + * @namespace Account + * @property username {String} username if user is logged in, otherwise it returns "Unknown user" + */ + signals: + + /**jsdoc + * Triggered when username has changed. + * @function Account.usernameChanged + * @return {Signal} + */ void usernameChanged(); public slots: static AccountScriptingInterface* getInstance(); + + /**jsdoc + * Returns the username for the currently logged in High Fidelity metaverse account. + * @function Account.getUsername + * @return {string} username if user is logged in, otherwise it returns "Unknown user" + */ QString getUsername(); + + /**jsdoc + * Determine if the user is logged into the High Fidleity metaverse. + * @function Account.isLoggedIn + * @return {bool} true when user is logged into the High Fidelity metaverse. + */ bool isLoggedIn(); bool checkAndSignalForAccessToken(); }; diff --git a/libraries/animation/src/AnimationCache.h b/libraries/animation/src/AnimationCache.h index a7d8700fed..59e3de9bcb 100644 --- a/libraries/animation/src/AnimationCache.h +++ b/libraries/animation/src/AnimationCache.h @@ -29,7 +29,19 @@ class AnimationCache : public ResourceCache, public Dependency { Q_OBJECT SINGLETON_DEPENDENCY + /**jsdoc + * @namespace AnimationCache + * @augments ResourceCache + */ + public: + + /**jsdoc + * Returns animation resource for particular animation + * @function AnimationCache.getAnimation + * @param url {string} url to load + * @return {Resource} animation + */ Q_INVOKABLE AnimationPointer getAnimation(const QString& url) { return getAnimation(QUrl(url)); } Q_INVOKABLE AnimationPointer getAnimation(const QUrl& url); diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index eba84dddd4..48b21a1e98 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -88,7 +88,24 @@ class ScriptableResource : public QObject { Q_PROPERTY(QUrl url READ getUrl) Q_PROPERTY(int state READ getState NOTIFY stateChanged) + /**jsdoc + * @constructor Resource + * @property url {string} url of this resource + * @property state {Resource.State} current loading state + */ + public: + + /**jsdoc + * @name Resource.State + * @static + * @property QUEUED {int} The resource is queued up, waiting to be loaded. + * @property LOADING {int} The resource is downloading + * @property LOADED {int} The resource has finished downloaded by is not complete + * @property FINISHED {int} The resource has completly finished loading and is ready. + * @property FAILED {int} Downloading the resource has failed. + */ + enum State { QUEUED, LOADING, @@ -101,6 +118,10 @@ public: ScriptableResource(const QUrl& url); virtual ~ScriptableResource() = default; + /**jsdoc + * Release this resource + * @function Resource#release + */ Q_INVOKABLE void release(); const QUrl& getUrl() const { return _url; } @@ -111,7 +132,22 @@ public: void setInScript(bool isInScript); signals: + + /**jsdoc + * Signaled when download progress for this resource has changed + * @function Resource#progressChanged + * @param bytesReceived {int} bytes downloaded so far + * @param bytesTotal {int} total number of bytes in the resource + * @returns {Signal} + */ void progressChanged(uint64_t bytesReceived, uint64_t bytesTotal); + + /**jsdoc + * Signaled when resource loading state has changed + * @function Resource#stateChanged + * @param bytesReceived {Resource.State} new state + * @returns {Signal} + */ void stateChanged(int state); protected: @@ -148,14 +184,49 @@ class ResourceCache : public QObject { Q_PROPERTY(size_t numCached READ getNumCachedResources NOTIFY dirty) Q_PROPERTY(size_t sizeTotal READ getSizeTotalResources NOTIFY dirty) Q_PROPERTY(size_t sizeCached READ getSizeCachedResources NOTIFY dirty) - + + /**jsdoc + * @namespace ResourceCache + * @property numTotal {number} total number of total resources + * @property numCached {number} total number of cached resource + * @property sizeTotal {number} size in bytes of all resources + * @property sizeCached {number} size in bytes of all cached resources + */ + public: + /**jsdoc + * Returns the total number of resources + * @function ResourceCache.getNumTotalResources + * @return {number} + */ size_t getNumTotalResources() const { return _numTotalResources; } + + /**jsdoc + * Returns the total size in bytes of all resources + * @function ResourceCache.getSizeTotalResources + * @return {number} + */ size_t getSizeTotalResources() const { return _totalResourcesSize; } + /**jsdoc + * Returns the total number of cached resources + * @function ResourceCache.getNumCachedResources + * @return {number} + */ size_t getNumCachedResources() const { return _numUnusedResources; } + + /**jsdoc + * Returns the total size in bytes of cached resources + * @function ResourceCache.getSizeCachedResources + * @return {number} + */ size_t getSizeCachedResources() const { return _unusedResourcesSize; } + /**jsdoc + * Returns list of all resource urls + * @function ResourceCache.getResourceList + * @return {string[]} + */ Q_INVOKABLE QVariantList getResourceList(); static void setRequestLimit(int limit); @@ -192,6 +263,13 @@ protected slots: /// returns an empty smart pointer and loads its asynchronously. /// \param fallback a fallback URL to load if the desired one is unavailable /// \param extra extra data to pass to the creator, if appropriate + /**jsdoc + * Asynchronously loads a resource from the spedified URL and returns it. + * @param url {string} url of resource to load + * @param fallback {string} fallback URL if load of the desired url fails + * @function ResourceCache.getResource + * @return {Resource} + */ QSharedPointer getResource(const QUrl& url, const QUrl& fallback = QUrl(), void* extra = NULL); @@ -203,6 +281,12 @@ protected: // Pointers created through this method should be owned by the caller, // which should be a QScriptEngine with ScriptableResource registered, so that // the QScriptEngine will delete the pointer when it is garbage collected. + /**jsdoc + * Prefetches a resource. + * @param url {string} url of resource to load + * @function ResourceCache.prefetch + * @return {Resource} + */ Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url) { return prefetch(url, nullptr); } /// Creates a new resource. diff --git a/libraries/script-engine/src/AssetScriptingInterface.h b/libraries/script-engine/src/AssetScriptingInterface.h index 82d220ab34..d8bc319256 100644 --- a/libraries/script-engine/src/AssetScriptingInterface.h +++ b/libraries/script-engine/src/AssetScriptingInterface.h @@ -19,13 +19,60 @@ #include +/**jsdoc + * @namespace Assets + */ class AssetScriptingInterface : public QObject { Q_OBJECT public: AssetScriptingInterface(QScriptEngine* engine); + /**jsdoc + * Upload content to the connected domain's asset server. + * @function Assets.uploadData + * @static + * @param data {string} content to upload + * @param callback {Assets~uploadDataCallback} called when upload is complete + */ + + /**jsdoc + * Called when uploadData is complete + * @callback Assets~uploadDataCallback + * @param {string} url + * @param {string} hash + */ + Q_INVOKABLE void uploadData(QString data, QScriptValue callback); + + /**jsdoc + * Download data from the connected domain's asset server. + * @function Assets.downloadData + * @static + * @param url {string} url of asset to download, must be atp scheme url. + * @param callback {Assets~downloadDataCallback} + */ + + /**jsdoc + * Called when downloadData is complete + * @callback Assets~downloadDataCallback + * @param data {string} content that was downloaded + */ + Q_INVOKABLE void downloadData(QString url, QScriptValue downloadComplete); + + /**jsdoc + * Sets up a path to hash mapping within the connected domain's asset server + * @function Assets.setMapping + * @static + * @param path {string} + * @param hash {string} + * @param callback {Assets~setMappingCallback} + */ + + /**jsdoc + * Called when setMapping is complete + * @callback Assets~setMappingCallback + */ Q_INVOKABLE void setMapping(QString path, QString hash, QScriptValue callback); #if (PR_BUILD || DEV_BUILD) From 940edd4a6d2c2b3f8682c0d09d2836e45abc8e0d Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Nov 2016 18:09:42 -0800 Subject: [PATCH 15/22] Added interface/src/scripting dir to doc search path --- scripts/jsdoc/plugins/hifi.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/jsdoc/plugins/hifi.js b/scripts/jsdoc/plugins/hifi.js index fde4183db8..8016aa2ae5 100644 --- a/scripts/jsdoc/plugins/hifi.js +++ b/scripts/jsdoc/plugins/hifi.js @@ -15,9 +15,10 @@ exports.handlers = { // directories to scan for jsdoc comments var dirList = [ '../../interface/src', + '../../interface/src/scripting', '../../libraries/script-engine/src', '../../libraries/networking/src', - '../../libraries/animation/src' + '../../libraries/animation/src', ]; var exts = ['.h', '.cpp']; From c01b39b54bdd0fe83fdfb8690a640ae98f1d2cef Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 9 Nov 2016 18:16:51 -0800 Subject: [PATCH 16/22] And test that again --- libraries/gl/src/gl/Context.cpp | 6 +++--- libraries/gl/src/gl/OpenGLVersionChecker.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/gl/src/gl/Context.cpp b/libraries/gl/src/gl/Context.cpp index fe48968981..221223d584 100644 --- a/libraries/gl/src/gl/Context.cpp +++ b/libraries/gl/src/gl/Context.cpp @@ -215,10 +215,10 @@ void Context::create() { } glewExperimental = true; glewInit(); - if (glewIsSupported("GL_VERSION_4_5")) { - _version = 0x0405; + // if (glewIsSupported("GL_VERSION_4_5")) { + // _version = 0x0405; // } else if (glewIsSupported("GL_VERSION_4_3")) { - } else if (glewIsSupported("GL_VERSION_4_4")) { + /* } else*/ if (glewIsSupported("GL_VERSION_4_8")) { ///_version = 0x0403; _version = 0x0404; } diff --git a/libraries/gl/src/gl/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp index 273251581a..322a7bc484 100644 --- a/libraries/gl/src/gl/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -23,7 +23,7 @@ // Minimum gl version required is 4.1 //#define MINIMUM_GL_VERSION 0x0401 -#define MINIMUM_GL_VERSION 0x0404 +#define MINIMUM_GL_VERSION 0x0408 OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : QApplication(argc, argv) From 0ab4a781f59513f598de3e4eaafb38a5a1e1c412 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 9 Nov 2016 18:25:37 -0800 Subject: [PATCH 17/22] Back to the correct code --- libraries/gl/src/gl/Context.cpp | 10 ++++------ libraries/gl/src/gl/OpenGLVersionChecker.cpp | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libraries/gl/src/gl/Context.cpp b/libraries/gl/src/gl/Context.cpp index 221223d584..ec1c284e99 100644 --- a/libraries/gl/src/gl/Context.cpp +++ b/libraries/gl/src/gl/Context.cpp @@ -215,12 +215,10 @@ void Context::create() { } glewExperimental = true; glewInit(); - // if (glewIsSupported("GL_VERSION_4_5")) { - // _version = 0x0405; - // } else if (glewIsSupported("GL_VERSION_4_3")) { - /* } else*/ if (glewIsSupported("GL_VERSION_4_8")) { -///_version = 0x0403; - _version = 0x0404; + if (glewIsSupported("GL_VERSION_4_5")) { + _version = 0x0405; + } else if (glewIsSupported("GL_VERSION_4_3")) { + _version = 0x0403; } glGetError(); wglMakeCurrent(0, 0); diff --git a/libraries/gl/src/gl/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp index 322a7bc484..428bf86c6f 100644 --- a/libraries/gl/src/gl/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -22,8 +22,7 @@ #include "GLHelpers.h" // Minimum gl version required is 4.1 -//#define MINIMUM_GL_VERSION 0x0401 -#define MINIMUM_GL_VERSION 0x0408 +#define MINIMUM_GL_VERSION 0x0401 OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : QApplication(argc, argv) From db98a742b60f5075ec848c206a4e4dc00ae7b26b Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 9 Nov 2016 12:22:57 -0800 Subject: [PATCH 18/22] Remove incremental transfers --- interface/src/Menu.cpp | 9 --- interface/src/Menu.h | 1 - libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 8 ++- .../src/gpu/gl45/GL45BackendTexture.cpp | 67 +++++++++++-------- libraries/gpu/src/gpu/Texture.cpp | 23 +------ libraries/gpu/src/gpu/Texture.h | 7 +- 6 files changed, 51 insertions(+), 64 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6207ecdb3c..dfa1a2f8b9 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -396,15 +396,6 @@ Menu::Menu() { }); } - // Developer > Render > Enable Incremental Texture Transfer - { - auto action = addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::IncrementalTextureTransfer, 0, gpu::Texture::getEnableIncrementalTextureTransfers()); - connect(action, &QAction::triggered, [&](bool checked) { - qDebug() << "[TEXTURE TRANSFER SUPPORT] --- Enable Incremental Texture Transfer menu option:" << checked; - gpu::Texture::setEnableIncrementalTextureTransfers(checked); - }); - } - #else qDebug() << "[TEXTURE TRANSFER SUPPORT] Incremental Texture Transfer and Dynamic Texture Management not supported on this platform."; #endif diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 87e0e678f1..e339da4d25 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -112,7 +112,6 @@ namespace MenuOption { const QString FrameTimer = "Show Timer"; const QString FullscreenMirror = "Mirror"; const QString Help = "Help..."; - const QString IncrementalTextureTransfer = "Enable Incremental Texture Transfer"; const QString IncreaseAvatarSize = "Increase Avatar Size"; const QString IndependentMode = "Independent Mode"; const QString ActionMotorControl = "Enable Default Motor Control"; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index 438b1e9454..291888e81b 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -14,6 +14,8 @@ #include "../gl/GLBackend.h" #include "../gl/GLTexture.h" +#define INCREMENTAL_TRANSFER 0 + namespace gpu { namespace gl45 { using namespace gpu::gl; @@ -56,6 +58,7 @@ public: GLint pageDimensionsIndex { 0 }; }; +#if INCREMENTAL_TRANSFER struct TransferState { TransferState(GL45Texture& texture); uvec3 currentPageSize() const; @@ -74,6 +77,10 @@ public: uvec3 mipOffset; const uint8_t* srcPointer { nullptr }; }; + protected: + TransferState _transferState; +#endif + protected: void updateMips() override; void stripToMip(uint16_t newMinMip); @@ -91,7 +98,6 @@ public: void derez(); SparseInfo _sparseInfo; - TransferState _transferState; uint32_t _allocatedPages { 0 }; uint32_t _lastMipAllocatedPages { 0 }; uint16_t _mipOffset { 0 }; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index f97364f5c5..fca809186f 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -162,6 +162,8 @@ void GL45Backend::initTextureManagementStage() { } } +#if INCREMENTAL_TRANSFER + using TransferState = GL45Backend::GL45Texture::TransferState; TransferState::TransferState(GL45Texture& texture) : texture(texture) { @@ -246,6 +248,7 @@ void TransferState::populatePage(std::vector& buffer) { uvec3 TransferState::currentPageSize() const { return glm::clamp(mipDimensions - mipOffset, uvec3(1), texture._sparseInfo.pageDimensions); } +#endif GLuint GL45Texture::allocate(const Texture& texture) { GLuint result; @@ -258,11 +261,19 @@ GLuint GL45Backend::getTextureID(const TexturePointer& texture, bool transfer) { } GL45Texture::GL45Texture(const std::weak_ptr& backend, const Texture& texture, GLuint externalId) - : GLTexture(backend, texture, externalId), _sparseInfo(*this), _transferState(*this) { + : GLTexture(backend, texture, externalId), _sparseInfo(*this) +#if INCREMENTAL_TRANSFER +, _transferState(*this) +#endif +{ } GL45Texture::GL45Texture(const std::weak_ptr& backend, const Texture& texture, bool transferrable) - : GLTexture(backend, texture, allocate(texture), transferrable), _sparseInfo(*this), _transferState(*this) { + : GLTexture(backend, texture, allocate(texture), transferrable), _sparseInfo(*this) +#if INCREMENTAL_TRANSFER +, _transferState(*this) +#endif + { auto theBackend = _backend.lock(); if (_transferrable && theBackend && theBackend->isTextureManagementSparseEnabled()) { @@ -375,39 +386,40 @@ void GL45Texture::updateSize() const { void GL45Texture::startTransfer() { Parent::startTransfer(); _sparseInfo.update(); +#if INCREMENTAL_TRANSFER _transferState.updateMip(); +#endif } bool GL45Texture::continueTransfer() { - if (!Texture::getEnableIncrementalTextureTransfers()) { - size_t maxFace = GL_TEXTURE_CUBE_MAP == _target ? CUBE_NUM_FACES : 1; - for (uint8_t face = 0; face < maxFace; ++face) { - for (uint16_t mipLevel = _minMip; mipLevel <= _maxMip; ++mipLevel) { - auto size = _gpuObject.evalMipDimensions(mipLevel); - if (_sparseInfo.sparse && mipLevel <= _sparseInfo.maxSparseLevel) { - glTexturePageCommitmentEXT(_id, mipLevel, 0, 0, face, size.x, size.y, 1, GL_TRUE); - _allocatedPages += _sparseInfo.getPageCount(size); - } - if (_gpuObject.isStoredMipFaceAvailable(mipLevel, face)) { - auto mip = _gpuObject.accessStoredMipFace(mipLevel, face); - GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat(), mip->getFormat()); - if (GL_TEXTURE_2D == _target) { - glTextureSubImage2D(_id, mipLevel, 0, 0, size.x, size.y, texelFormat.format, texelFormat.type, mip->readData()); - } else if (GL_TEXTURE_CUBE_MAP == _target) { - // DSA ARB does not work on AMD, so use EXT - // glTextureSubImage3D(_id, mipLevel, 0, 0, face, size.x, size.y, 1, texelFormat.format, texelFormat.type, mip->readData()); - auto target = CUBE_FACE_LAYOUT[face]; - glTextureSubImage2DEXT(_id, target, mipLevel, 0, 0, size.x, size.y, texelFormat.format, texelFormat.type, mip->readData()); - } else { - Q_ASSERT(false); - } - (void)CHECK_GL_ERROR(); +#if !INCREMENTAL_TRANSFER + size_t maxFace = GL_TEXTURE_CUBE_MAP == _target ? CUBE_NUM_FACES : 1; + for (uint8_t face = 0; face < maxFace; ++face) { + for (uint16_t mipLevel = _minMip; mipLevel <= _maxMip; ++mipLevel) { + auto size = _gpuObject.evalMipDimensions(mipLevel); + if (_sparseInfo.sparse && mipLevel <= _sparseInfo.maxSparseLevel) { + glTexturePageCommitmentEXT(_id, mipLevel, 0, 0, face, size.x, size.y, 1, GL_TRUE); + _allocatedPages += _sparseInfo.getPageCount(size); + } + if (_gpuObject.isStoredMipFaceAvailable(mipLevel, face)) { + auto mip = _gpuObject.accessStoredMipFace(mipLevel, face); + GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat(), mip->getFormat()); + if (GL_TEXTURE_2D == _target) { + glTextureSubImage2D(_id, mipLevel, 0, 0, size.x, size.y, texelFormat.format, texelFormat.type, mip->readData()); + } else if (GL_TEXTURE_CUBE_MAP == _target) { + // DSA ARB does not work on AMD, so use EXT + // glTextureSubImage3D(_id, mipLevel, 0, 0, face, size.x, size.y, 1, texelFormat.format, texelFormat.type, mip->readData()); + auto target = CUBE_FACE_LAYOUT[face]; + glTextureSubImage2DEXT(_id, target, mipLevel, 0, 0, size.x, size.y, texelFormat.format, texelFormat.type, mip->readData()); + } else { + Q_ASSERT(false); } + (void)CHECK_GL_ERROR(); } } - return false; } - + return false; +#else static std::vector buffer; if (buffer.empty()) { buffer.resize(DEFAULT_PAGE_BUFFER_SIZE); @@ -458,6 +470,7 @@ bool GL45Texture::continueTransfer() { _lastMipAllocatedPages = _allocatedPages; } return result; +#endif } void GL45Texture::finishTransfer() { diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 33786155db..45aff54b8f 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -35,18 +35,15 @@ std::atomic Texture::_allowedCPUMemoryUsage { 0 }; #define MIN_CORES_FOR_INCREMENTAL_TEXTURES 5 -bool recommendedIncrementalTransfers = (QThread::idealThreadCount() >= MIN_CORES_FOR_INCREMENTAL_TEXTURES); -bool recommendedSparseTextures = recommendedIncrementalTransfers; +bool recommendedSparseTextures = (QThread::idealThreadCount() >= MIN_CORES_FOR_INCREMENTAL_TEXTURES); -std::atomic Texture::_enableSparseTextures { recommendedIncrementalTransfers }; -std::atomic Texture::_enableIncrementalTextureTransfers { recommendedSparseTextures }; +std::atomic Texture::_enableSparseTextures { recommendedSparseTextures }; struct ReportTextureState { ReportTextureState() { qDebug() << "[TEXTURE TRANSFER SUPPORT]" << "\n\tidealThreadCount:" << QThread::idealThreadCount() - << "\n\tRECOMMENDED enableSparseTextures:" << recommendedSparseTextures - << "\n\tRECOMMENDED enableIncrementalTextures:" << recommendedIncrementalTransfers; + << "\n\tRECOMMENDED enableSparseTextures:" << recommendedSparseTextures; } } report; @@ -59,16 +56,6 @@ void Texture::setEnableSparseTextures(bool enabled) { #endif } -void Texture::setEnableIncrementalTextureTransfers(bool enabled) { -#ifdef Q_OS_WIN - qDebug() << "[TEXTURE TRANSFER SUPPORT] SETTING - Enable Incremental Texture Transfer:" << enabled; - _enableIncrementalTextureTransfers = enabled; -#else - qDebug() << "[TEXTURE TRANSFER SUPPORT] Incremental Texture Transfer not supported on this platform."; -#endif -} - - void Texture::updateTextureCPUMemoryUsage(Size prevObjectSize, Size newObjectSize) { if (prevObjectSize == newObjectSize) { return; @@ -84,10 +71,6 @@ bool Texture::getEnableSparseTextures() { return _enableSparseTextures.load(); } -bool Texture::getEnableIncrementalTextureTransfers() { - return _enableIncrementalTextureTransfers.load(); -} - uint32_t Texture::getTextureCPUCount() { return _textureCPUCount.load(); } diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 2a93ec3066..856bd4983d 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -143,10 +143,8 @@ class Texture : public Resource { static std::atomic _textureCPUCount; static std::atomic _textureCPUMemoryUsage; static std::atomic _allowedCPUMemoryUsage; - static void updateTextureCPUMemoryUsage(Size prevObjectSize, Size newObjectSize); - static std::atomic _enableSparseTextures; - static std::atomic _enableIncrementalTextureTransfers; + static void updateTextureCPUMemoryUsage(Size prevObjectSize, Size newObjectSize); public: static uint32_t getTextureCPUCount(); @@ -162,10 +160,7 @@ public: static void setAllowedGPUMemoryUsage(Size size); static bool getEnableSparseTextures(); - static bool getEnableIncrementalTextureTransfers(); - static void setEnableSparseTextures(bool enabled); - static void setEnableIncrementalTextureTransfers(bool enabled); using ExternalRecycler = std::function; using ExternalIdAndFence = std::pair; From f56a5d1d989abd7a3846af44408e0c6abb49314c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Nov 2016 09:23:01 -0800 Subject: [PATCH 19/22] elevate permissions required for mute environment --- assignment-client/src/audio/AudioMixer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index d785579c38..f8077303d2 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -489,7 +489,7 @@ void AudioMixer::handleNodeAudioPacket(QSharedPointer message, void AudioMixer::handleMuteEnvironmentPacket(QSharedPointer message, SharedNodePointer sendingNode) { auto nodeList = DependencyManager::get(); - if (sendingNode->isAllowedEditor()) { + if (sendingNode->getCanKick()) { glm::vec3 position; float radius; From d111f7c4099528e8d7a6a5dc748626d129cf7844 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 10 Nov 2016 09:33:56 -0800 Subject: [PATCH 20/22] Moved jsdoc folder from scripts to tools directory --- {scripts => tools}/jsdoc/.gitignore | 0 {scripts => tools}/jsdoc/README.md | 0 {scripts => tools}/jsdoc/config.json | 0 {scripts => tools}/jsdoc/plugins/hifi.js | 0 {scripts => tools}/jsdoc/root.js | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {scripts => tools}/jsdoc/.gitignore (100%) rename {scripts => tools}/jsdoc/README.md (100%) rename {scripts => tools}/jsdoc/config.json (100%) rename {scripts => tools}/jsdoc/plugins/hifi.js (100%) rename {scripts => tools}/jsdoc/root.js (100%) diff --git a/scripts/jsdoc/.gitignore b/tools/jsdoc/.gitignore similarity index 100% rename from scripts/jsdoc/.gitignore rename to tools/jsdoc/.gitignore diff --git a/scripts/jsdoc/README.md b/tools/jsdoc/README.md similarity index 100% rename from scripts/jsdoc/README.md rename to tools/jsdoc/README.md diff --git a/scripts/jsdoc/config.json b/tools/jsdoc/config.json similarity index 100% rename from scripts/jsdoc/config.json rename to tools/jsdoc/config.json diff --git a/scripts/jsdoc/plugins/hifi.js b/tools/jsdoc/plugins/hifi.js similarity index 100% rename from scripts/jsdoc/plugins/hifi.js rename to tools/jsdoc/plugins/hifi.js diff --git a/scripts/jsdoc/root.js b/tools/jsdoc/root.js similarity index 100% rename from scripts/jsdoc/root.js rename to tools/jsdoc/root.js From 4d18a3cc3d5a7b52930cfb904676b78688703c83 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 10 Nov 2016 15:01:06 -0800 Subject: [PATCH 21/22] expose menu enablement to javascript --- .../src/scripting/MenuScriptingInterface.cpp | 17 +++++++++++++++++ .../src/scripting/MenuScriptingInterface.h | 3 +++ libraries/ui/src/ui/Menu.cpp | 19 +++++++++++++++++++ libraries/ui/src/ui/Menu.h | 3 +++ 4 files changed, 42 insertions(+) diff --git a/interface/src/scripting/MenuScriptingInterface.cpp b/interface/src/scripting/MenuScriptingInterface.cpp index 2fa7470561..df75d331d6 100644 --- a/interface/src/scripting/MenuScriptingInterface.cpp +++ b/interface/src/scripting/MenuScriptingInterface.cpp @@ -126,6 +126,23 @@ void MenuScriptingInterface::setIsOptionChecked(const QString& menuOption, bool Q_ARG(bool, isChecked)); } +bool MenuScriptingInterface::isMenuEnabled(const QString& menuOption) { + if (QThread::currentThread() == qApp->thread()) { + return Menu::getInstance()->isOptionChecked(menuOption); + } + bool result; + QMetaObject::invokeMethod(Menu::getInstance(), "isMenuEnabled", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(bool, result), + Q_ARG(const QString&, menuOption)); + return result; +} + +void MenuScriptingInterface::setMenuEnabled(const QString& menuOption, bool isChecked) { + QMetaObject::invokeMethod(Menu::getInstance(), "setMenuEnabled", + Q_ARG(const QString&, menuOption), + Q_ARG(bool, isChecked)); +} + void MenuScriptingInterface::triggerOption(const QString& menuOption) { QMetaObject::invokeMethod(Menu::getInstance(), "triggerOption", Q_ARG(const QString&, menuOption)); } diff --git a/interface/src/scripting/MenuScriptingInterface.h b/interface/src/scripting/MenuScriptingInterface.h index 5b8a437529..855b1af13b 100644 --- a/interface/src/scripting/MenuScriptingInterface.h +++ b/interface/src/scripting/MenuScriptingInterface.h @@ -50,6 +50,9 @@ public slots: void setIsOptionChecked(const QString& menuOption, bool isChecked); void triggerOption(const QString& menuOption); + + bool isMenuEnabled(const QString& menuName); + void setMenuEnabled(const QString& menuName, bool isEnabled); signals: void menuItemEvent(const QString& menuItem); diff --git a/libraries/ui/src/ui/Menu.cpp b/libraries/ui/src/ui/Menu.cpp index aee8b40832..ba24adfc3f 100644 --- a/libraries/ui/src/ui/Menu.cpp +++ b/libraries/ui/src/ui/Menu.cpp @@ -428,6 +428,25 @@ bool Menu::menuExists(const QString& menuName) { return false; } +bool Menu::isMenuEnabled(const QString& menuName) { + QAction* action = getMenuAction(menuName); + + // only proceed if the menu actually exists + if (action) { + return action->isEnabled(); + } + return false; +} + +void Menu::setMenuEnabled(const QString& menuName, bool isEnabled) { + QAction* action = getMenuAction(menuName); + + // only proceed if the menu actually exists + if (action) { + action->setEnabled(isEnabled); + } +} + void Menu::addSeparator(const QString& menuName, const QString& separatorName, const QString& grouping) { MenuWrapper* menuObj = getMenu(menuName); if (menuObj) { diff --git a/libraries/ui/src/ui/Menu.h b/libraries/ui/src/ui/Menu.h index ee60a031c3..2711fc5921 100644 --- a/libraries/ui/src/ui/Menu.h +++ b/libraries/ui/src/ui/Menu.h @@ -106,6 +106,9 @@ public slots: bool isOptionChecked(const QString& menuOption) const; void setIsOptionChecked(const QString& menuOption, bool isChecked); + bool isMenuEnabled(const QString& menuName); + void setMenuEnabled(const QString& menuName, bool isEnabled); + bool getGroupingIsVisible(const QString& grouping); void setGroupingIsVisible(const QString& grouping, bool isVisible); /// NOTE: the "" grouping is always visible From 8299e23cc3e084f2be5823491963bf5606c4028c Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 10 Nov 2016 15:15:11 -0800 Subject: [PATCH 22/22] diable some viewpoint menu options when in hmd. --- scripts/system/hmd.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/system/hmd.js b/scripts/system/hmd.js index 84ff6b3c89..e1c846806f 100644 --- a/scripts/system/hmd.js +++ b/scripts/system/hmd.js @@ -24,10 +24,16 @@ var desktopMenuItemName = "Desktop"; var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); var button; +// Independent and Entity mode make people sick. Third Person and Mirror have traps that we need to work through. +// Disable them in hmd. +var desktopOnlyViews = ['Third Person', 'Mirror', 'Independent Mode', 'Entity Mode']; function onHmdChanged(isHmd) { button.writeProperty('buttonState', isHmd ? 0 : 1); button.writeProperty('defaultState', isHmd ? 0 : 1); button.writeProperty('hoverState', isHmd ? 2 : 3); + desktopOnlyViews.forEach(function (view) { + Menu.setMenuEnabled("View>" + view, !isHmd); + }); } function onClicked(){ var isDesktop = Menu.isOptionChecked(desktopMenuItemName);