From 30bbe6e41b0bd6f16b38903551175d81eb0292af Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 28 Dec 2017 15:43:59 -0800 Subject: [PATCH 01/15] added relayParentJoints property --- libraries/entities/src/EntityItemProperties.cpp | 9 +++++++++ libraries/entities/src/EntityItemProperties.h | 1 + .../entities/src/EntityItemPropertiesDefaults.h | 2 ++ libraries/entities/src/EntityPropertyFlags.h | 1 + libraries/entities/src/ModelEntityItem.cpp | 17 +++++++++++++++++ libraries/entities/src/ModelEntityItem.h | 4 ++++ libraries/networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 1 + 8 files changed, 36 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 13ebd9ef9f..b739726bce 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -507,6 +507,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_JOINT_ROTATIONS, jointRotations); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_JOINT_TRANSLATIONS_SET, jointTranslationsSet); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_JOINT_TRANSLATIONS, jointTranslations); + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_RELAY_PARENT_JOINTS, relayParentJoints); } if (_type == EntityTypes::Model || _type == EntityTypes::Zone || _type == EntityTypes::ParticleEffect) { @@ -732,6 +733,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(radiusSpread, float, setRadiusSpread); COPY_PROPERTY_FROM_QSCRIPTVALUE(radiusStart, float, setRadiusStart); COPY_PROPERTY_FROM_QSCRIPTVALUE(radiusFinish, float, setRadiusFinish); + COPY_PROPERTY_FROM_QSCRIPTVALUE(relayParentJoints, bool, setRelayParentJoints); // Certifiable Properties COPY_PROPERTY_FROM_QSCRIPTVALUE(itemName, QString, setItemName); @@ -1137,6 +1139,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_JOINT_ROTATIONS, JointRotations, jointRotations, QVector); ADD_PROPERTY_TO_MAP(PROP_JOINT_TRANSLATIONS_SET, JointTranslationsSet, jointTranslationsSet, QVector); ADD_PROPERTY_TO_MAP(PROP_JOINT_TRANSLATIONS, JointTranslations, jointTranslations, QVector); + ADD_PROPERTY_TO_MAP(PROP_RELAY_PARENT_JOINTS, RelayParentJoints, relayParentJoints, bool); ADD_PROPERTY_TO_MAP(PROP_SHAPE, Shape, shape, QString); @@ -1364,6 +1367,7 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy APPEND_ENTITY_PROPERTY(PROP_JOINT_ROTATIONS, properties.getJointRotations()); APPEND_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS_SET, properties.getJointTranslationsSet()); APPEND_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS, properties.getJointTranslations()); + APPEND_ENTITY_PROPERTY(PROP_RELAY_PARENT_JOINTS, properties.getRelayParentJoints()); } if (properties.getType() == EntityTypes::Light) { @@ -1721,6 +1725,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_JOINT_ROTATIONS, QVector, setJointRotations); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_JOINT_TRANSLATIONS_SET, QVector, setJointTranslationsSet); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_JOINT_TRANSLATIONS, QVector, setJointTranslations); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_RELAY_PARENT_JOINTS, bool, setRelayParentJoints); } if (properties.getType() == EntityTypes::Light) { @@ -2062,6 +2067,7 @@ void EntityItemProperties::markAllChanged() { _owningAvatarIDChanged = true; _dpiChanged = true; + _relayParentJointsChanged = true; } // The minimum bounding box for the entity. @@ -2420,6 +2426,9 @@ QList EntityItemProperties::listChangedProperties() { if (jointTranslationsChanged()) { out += "jointTranslations"; } + if (relayParentJointsChanged()) { + out += "relayParentJoints"; + } if (queryAACubeChanged()) { out += "queryAACube"; } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 4f7ba1317b..96036c1a2c 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -245,6 +245,7 @@ public: DEFINE_PROPERTY_REF(PROP_LAST_EDITED_BY, LastEditedBy, lastEditedBy, QUuid, ENTITY_ITEM_DEFAULT_LAST_EDITED_BY); DEFINE_PROPERTY_REF(PROP_SERVER_SCRIPTS, ServerScripts, serverScripts, QString, ENTITY_ITEM_DEFAULT_SERVER_SCRIPTS); + DEFINE_PROPERTY(PROP_RELAY_PARENT_JOINTS, RelayParentJoints, relayParentJoints, bool, ENTITY_ITEM_DEFAULT_RELAY_PARENT_JOINTS); static QString getBackgroundModeString(BackgroundMode mode); static QString getHazeModeString(uint32_t mode); diff --git a/libraries/entities/src/EntityItemPropertiesDefaults.h b/libraries/entities/src/EntityItemPropertiesDefaults.h index 49bce37fbd..eb09a64628 100644 --- a/libraries/entities/src/EntityItemPropertiesDefaults.h +++ b/libraries/entities/src/EntityItemPropertiesDefaults.h @@ -92,4 +92,6 @@ const uint16_t ENTITY_ITEM_DEFAULT_DPI = 30; const QUuid ENTITY_ITEM_DEFAULT_LAST_EDITED_BY = QUuid(); +const bool ENTITY_ITEM_DEFAULT_RELAY_PARENT_JOINTS = false; + #endif // hifi_EntityItemPropertiesDefaults_h diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 41c1e77bb8..9ec11fccfc 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -40,6 +40,7 @@ enum EntityPropertyList { PROP_ANIMATION_FRAME_INDEX, PROP_ANIMATION_PLAYING, PROP_ANIMATION_ALLOW_TRANSLATION, + PROP_RELAY_PARENT_JOINTS, // these properties are supported by the EntityItem base class PROP_REGISTRATION_POINT, diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 3a79df34c6..4304f50be0 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -62,6 +62,7 @@ EntityItemProperties ModelEntityItem::getProperties(EntityPropertyFlags desiredP COPY_ENTITY_PROPERTY_TO_PROPERTIES(jointRotations, getJointRotations); COPY_ENTITY_PROPERTY_TO_PROPERTIES(jointTranslationsSet, getJointTranslationsSet); COPY_ENTITY_PROPERTY_TO_PROPERTIES(jointTranslations, getJointTranslations); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(relayParentJoints, getRelayParentJoints); _animationProperties.getProperties(properties); return properties; @@ -80,6 +81,7 @@ bool ModelEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(jointRotations, setJointRotations); SET_ENTITY_PROPERTY_FROM_PROPERTIES(jointTranslationsSet, setJointTranslationsSet); SET_ENTITY_PROPERTY_FROM_PROPERTIES(jointTranslations, setJointTranslations); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(relayParentJoints, setRelayParentJoints); bool somethingChangedInAnimations = _animationProperties.setProperties(properties); @@ -138,6 +140,7 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_JOINT_ROTATIONS, QVector, setJointRotations); READ_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS_SET, QVector, setJointTranslationsSet); READ_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS, QVector, setJointTranslations); + READ_ENTITY_PROPERTY(PROP_RELAY_PARENT_JOINTS, bool, setRelayParentJoints); return bytesRead; } @@ -155,6 +158,7 @@ EntityPropertyFlags ModelEntityItem::getEntityProperties(EncodeBitstreamParams& requestedProperties += PROP_JOINT_ROTATIONS; requestedProperties += PROP_JOINT_TRANSLATIONS_SET; requestedProperties += PROP_JOINT_TRANSLATIONS; + requestedProperties += PROP_RELAY_PARENT_JOINTS; return requestedProperties; } @@ -185,6 +189,7 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit APPEND_ENTITY_PROPERTY(PROP_JOINT_ROTATIONS, getJointRotations()); APPEND_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS_SET, getJointTranslationsSet()); APPEND_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS, getJointTranslations()); + APPEND_ENTITY_PROPERTY(PROP_RELAY_PARENT_JOINTS, getRelayParentJoints()); } @@ -586,6 +591,18 @@ QString ModelEntityItem::getModelURL() const { }); } +void ModelEntityItem::setRelayParentJoints(bool relayJoints) { + withWriteLock([&] { + _relayParentJoints = relayJoints; + }); +} + +bool ModelEntityItem::getRelayParentJoints() const { + return resultWithReadLock([&] { + return _relayParentJoints; + }); +} + QString ModelEntityItem::getCompoundShapeURL() const { return _compoundShapeURL.get(); } diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 7fee022011..6169039f52 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -99,6 +99,9 @@ public: void setAnimationHold(bool hold); bool getAnimationHold() const; + void setRelayParentJoints(bool relayJoints); + bool getRelayParentJoints() const; + void setAnimationFirstFrame(float firstFrame); float getAnimationFirstFrame() const; @@ -157,6 +160,7 @@ protected: rgbColor _color; QString _modelURL; + bool _relayParentJoints; ThreadSafeValueCache _compoundShapeURL; diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 0a75e8c31b..eceef28b0e 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -30,7 +30,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityEdit: case PacketType::EntityData: case PacketType::EntityPhysics: - return static_cast(EntityVersion::OwnershipChallengeFix); + return static_cast(EntityVersion::SoftEntities); case PacketType::EntityQuery: return static_cast(EntityQueryPacketVersion::ConnectionIdentifier); diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 85f321a198..15eb326fe2 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -202,6 +202,7 @@ enum class EntityVersion : PacketVersion { HazeEffect, StaticCertJsonVersionOne, OwnershipChallengeFix, + SoftEntities }; enum class EntityScriptCallMethodVersion : PacketVersion { From 0ebbb76b49b7d16fad3de626d63ca865466488d8 Mon Sep 17 00:00:00 2001 From: druiz17 Date: Fri, 29 Dec 2017 16:12:40 -0800 Subject: [PATCH 02/15] fixed property over written issue and start relaying joints --- .../src/avatars-renderer/Avatar.cpp | 16 ++++++++++++++++ .../src/avatars-renderer/Avatar.h | 1 + .../src/RenderableModelEntityItem.cpp | 2 ++ libraries/entities/src/ModelEntityItem.cpp | 5 ++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index c532e7659f..a26f907c97 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -32,6 +32,7 @@ #include #include #include +#include "ModelEntityItem.h" #include "Logging.h" @@ -347,6 +348,20 @@ void Avatar::updateAvatarEntities() { setAvatarEntityDataChanged(false); } +void Avatar::relayJointDataToChildren() { + forEachChild([&](SpatiallyNestablePointer child) { + if (child->getNestableType() == NestableType::Entity) { + auto entity = std::dynamic_pointer_cast(child); + if (entity) { + auto modelEntity = std::dynamic_pointer_cast(entity); + if (modelEntity) { + qDebug() << "--------> update modelEntityJoints <----------"; + } + } + } + }); +} + void Avatar::simulate(float deltaTime, bool inView) { PROFILE_RANGE(simulation, "simulate"); @@ -379,6 +394,7 @@ void Avatar::simulate(float deltaTime, bool inView) { } head->setScale(getModelScale()); head->simulate(deltaTime); + relayJointDataToChildren(); } else { // a non-full update is still required so that the position, rotation, scale and bounds of the skeletonModel are updated. _skeletonModel->simulate(deltaTime, false); diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index c75b54fdc4..0c845c0a9b 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -329,6 +329,7 @@ protected: // protected methods... bool isLookingAtMe(AvatarSharedPointer avatar) const; + void relayJointDataToChildren(); void fade(render::Transaction& transaction, render::Transition::Type type); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index e40e9a2f0c..930738ea43 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1202,6 +1202,8 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce return; } + if (entity->_relayParentJoints) { + } // Check for addition if (_hasModel && !(bool)_model) { model = std::make_shared(nullptr, entity.get()); diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 4304f50be0..1044700816 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -63,7 +63,6 @@ EntityItemProperties ModelEntityItem::getProperties(EntityPropertyFlags desiredP COPY_ENTITY_PROPERTY_TO_PROPERTIES(jointTranslationsSet, getJointTranslationsSet); COPY_ENTITY_PROPERTY_TO_PROPERTIES(jointTranslations, getJointTranslations); COPY_ENTITY_PROPERTY_TO_PROPERTIES(relayParentJoints, getRelayParentJoints); - _animationProperties.getProperties(properties); return properties; } @@ -117,6 +116,7 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_MODEL_URL, QString, setModelURL); READ_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, QString, setCompoundShapeURL); READ_ENTITY_PROPERTY(PROP_TEXTURES, QString, setTextures); + READ_ENTITY_PROPERTY(PROP_RELAY_PARENT_JOINTS, bool, setRelayParentJoints); int bytesFromAnimation; withWriteLock([&] { @@ -140,7 +140,6 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_JOINT_ROTATIONS, QVector, setJointRotations); READ_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS_SET, QVector, setJointTranslationsSet); READ_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS, QVector, setJointTranslations); - READ_ENTITY_PROPERTY(PROP_RELAY_PARENT_JOINTS, bool, setRelayParentJoints); return bytesRead; } @@ -177,6 +176,7 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit APPEND_ENTITY_PROPERTY(PROP_MODEL_URL, getModelURL()); APPEND_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, getCompoundShapeURL()); APPEND_ENTITY_PROPERTY(PROP_TEXTURES, getTextures()); + APPEND_ENTITY_PROPERTY(PROP_RELAY_PARENT_JOINTS, getRelayParentJoints()); withReadLock([&] { _animationProperties.appendSubclassData(packetData, params, entityTreeElementExtraEncodeData, requestedProperties, @@ -189,7 +189,6 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit APPEND_ENTITY_PROPERTY(PROP_JOINT_ROTATIONS, getJointRotations()); APPEND_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS_SET, getJointTranslationsSet()); APPEND_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS, getJointTranslations()); - APPEND_ENTITY_PROPERTY(PROP_RELAY_PARENT_JOINTS, getRelayParentJoints()); } From 6fa3446c57d15c336c03e4982dbf2be6c00559f7 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Tue, 2 Jan 2018 13:54:13 -0800 Subject: [PATCH 03/15] joints are being relayed to children --- interface/src/avatar/MyAvatar.cpp | 1 + .../src/avatars-renderer/Avatar.cpp | 21 ++++++++++++++++++- .../src/RenderableModelEntityItem.cpp | 6 ++++++ .../entities/src/EntityItemProperties.cpp | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 02a1959a95..24f53aef82 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -536,6 +536,7 @@ void MyAvatar::simulate(float deltaTime) { // we've achived our final adjusted position and rotation for the avatar // and all of its joints, now update our attachements. Avatar::simulateAttachments(deltaTime); + Avatar::relayJointDataToChildren(); if (!_skeletonModel->hasSkeleton()) { // All the simulation that can be done has been done diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index a26f907c97..b5fe2f27b8 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -349,13 +349,32 @@ void Avatar::updateAvatarEntities() { } void Avatar::relayJointDataToChildren() { + int index = 0; forEachChild([&](SpatiallyNestablePointer child) { if (child->getNestableType() == NestableType::Entity) { auto entity = std::dynamic_pointer_cast(child); if (entity) { auto modelEntity = std::dynamic_pointer_cast(entity); if (modelEntity) { - qDebug() << "--------> update modelEntityJoints <----------"; + index++; + if (modelEntity->getRelayParentJoints()) { + QVector jointRotations; + QVector jointRotationsSet; + QStringList modelJointNames = modelEntity->getJointNames(); + QStringList avatarJointNames = getJointNames(); + foreach (const QString& jointName, modelJointNames) { + bool containsJoint = avatarJointNames.contains(jointName); + if (!containsJoint) { + return; + } + int jointIndex = getJointIndex(jointName); + int modelJointIndex = modelEntity->getJointIndex(jointName); + jointRotationsSet.append(true); + jointRotations.append(getJointRotation(jointIndex)); + } + modelEntity->setJointRotationsSet(jointRotationsSet); + modelEntity->setJointRotations(jointRotations); + } } } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 034704a59c..771d0458df 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1203,6 +1203,12 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce } if (entity->_relayParentJoints) { + ModelPointer model = entity->getModel(); + if (model && model->isLoaded()) { + qDebug() << "relaying joints"; + entity->copyAnimationJointDataToModel(); + model->simulate(0.0f); + } } // Check for addition if (_hasModel && !(bool)_model) { diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index e62369f32b..3c3939059d 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -376,6 +376,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_SHAPE, shape); CHECK_PROPERTY_CHANGE(PROP_DPI, dpi); + CHECK_PROPERTY_CHANGE(PROP_RELAY_PARENT_JOINTS, relayParentJoints); changedProperties += _animation.getChangedProperties(); changedProperties += _keyLight.getChangedProperties(); From e1a7f9bfb86f5009e911dd83d3c9e60d38bb72a1 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 3 Jan 2018 08:47:11 -0800 Subject: [PATCH 04/15] working on imporving soft-entities --- .../src/avatars-renderer/Avatar.cpp | 13 +++++++++---- .../src/RenderableModelEntityItem.cpp | 1 - 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index b5fe2f27b8..38f249a075 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -359,21 +359,26 @@ void Avatar::relayJointDataToChildren() { index++; if (modelEntity->getRelayParentJoints()) { QVector jointRotations; - QVector jointRotationsSet; + QVector jointTranslations; + QVector jointSet; QStringList modelJointNames = modelEntity->getJointNames(); QStringList avatarJointNames = getJointNames(); foreach (const QString& jointName, modelJointNames) { bool containsJoint = avatarJointNames.contains(jointName); if (!containsJoint) { - return; + qDebug() << "Warning: Parent does not have joint -" << jointName; + continue; } int jointIndex = getJointIndex(jointName); int modelJointIndex = modelEntity->getJointIndex(jointName); - jointRotationsSet.append(true); + jointSet.append(true); jointRotations.append(getJointRotation(jointIndex)); + jointTranslations.append(getJointTranslation(jointIndex)); } - modelEntity->setJointRotationsSet(jointRotationsSet); + modelEntity->setJointRotationsSet(jointSet); + //modelEntity->setJointTranslationsSet(jointSet); modelEntity->setJointRotations(jointRotations); + //modelEntity->setJointTranslations(jointTranslations); } } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 771d0458df..74e24fd997 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1205,7 +1205,6 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce if (entity->_relayParentJoints) { ModelPointer model = entity->getModel(); if (model && model->isLoaded()) { - qDebug() << "relaying joints"; entity->copyAnimationJointDataToModel(); model->simulate(0.0f); } From 527d00871a8a6d8d7bd5e55095c2e0131f1b6a88 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 4 Jan 2018 11:57:51 -0800 Subject: [PATCH 05/15] making relaying translation work --- .../src/avatars-renderer/Avatar.cpp | 55 ++++++++++--------- .../src/RenderableModelEntityItem.cpp | 16 +++--- .../src/RenderableModelEntityItem.h | 2 +- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 38f249a075..61994db85e 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -33,6 +33,7 @@ #include #include #include "ModelEntityItem.h" +#include "RenderableModelEntityItem.h" #include "Logging.h" @@ -349,37 +350,39 @@ void Avatar::updateAvatarEntities() { } void Avatar::relayJointDataToChildren() { - int index = 0; forEachChild([&](SpatiallyNestablePointer child) { if (child->getNestableType() == NestableType::Entity) { - auto entity = std::dynamic_pointer_cast(child); - if (entity) { - auto modelEntity = std::dynamic_pointer_cast(entity); - if (modelEntity) { - index++; - if (modelEntity->getRelayParentJoints()) { - QVector jointRotations; - QVector jointTranslations; - QVector jointSet; - QStringList modelJointNames = modelEntity->getJointNames(); - QStringList avatarJointNames = getJointNames(); - foreach (const QString& jointName, modelJointNames) { - bool containsJoint = avatarJointNames.contains(jointName); - if (!containsJoint) { - qDebug() << "Warning: Parent does not have joint -" << jointName; - continue; - } + auto modelEntity = std::dynamic_pointer_cast(child); + if (modelEntity) { + if (modelEntity->getRelayParentJoints()) { + QVector jointRotations; + QVector jointTranslations; + QVector jointSet; + QStringList modelJointNames = modelEntity->getJointNames(); + QStringList avatarJointNames = getJointNames(); + foreach (const QString& jointName, modelJointNames) { + bool containsJoint = avatarJointNames.contains(jointName); + glm::quat jointRotation; + glm::vec3 jointTranslation; + if (!containsJoint) { + int jointIndex = modelEntity->getJointIndex(jointName); + jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex); + jointTranslation - modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex); + } else { int jointIndex = getJointIndex(jointName); - int modelJointIndex = modelEntity->getJointIndex(jointName); - jointSet.append(true); - jointRotations.append(getJointRotation(jointIndex)); - jointTranslations.append(getJointTranslation(jointIndex)); + jointRotation = getJointRotation(jointIndex); + jointTranslation = getJointTranslation(jointIndex); } - modelEntity->setJointRotationsSet(jointSet); - //modelEntity->setJointTranslationsSet(jointSet); - modelEntity->setJointRotations(jointRotations); - //modelEntity->setJointTranslations(jointTranslations); + jointSet.append(true); + jointRotations.append(jointRotation); + jointTranslations.append(jointTranslation); } + + modelEntity->setJointRotationsSet(jointSet); + modelEntity->setJointTranslationsSet(jointSet); + modelEntity->setJointRotations(jointRotations); + modelEntity->setJointTranslations(jointTranslations); + modelEntity->simulateRelayedJoints(); } } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 74e24fd997..bccd989ed0 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -929,6 +929,15 @@ bool RenderableModelEntityItem::getMeshes(MeshProxyList& result) { return !result.isEmpty(); } +void RenderableModelEntityItem::simulateRelayedJoints() { + ModelPointer model = getModel(); + if (model && model->isLoaded()) { + copyAnimationJointDataToModel(); + model->simulate(0.0f); + model->updateRenderItems(); + } +} + void RenderableModelEntityItem::copyAnimationJointDataToModel() { auto model = getModel(); if (!model || !model->isLoaded()) { @@ -1202,13 +1211,6 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce return; } - if (entity->_relayParentJoints) { - ModelPointer model = entity->getModel(); - if (model && model->isLoaded()) { - entity->copyAnimationJointDataToModel(); - model->simulate(0.0f); - } - } // Check for addition if (_hasModel && !(bool)_model) { model = std::make_shared(nullptr, entity.get()); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 7af10b09fd..6dbf85061b 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -83,6 +83,7 @@ public: virtual bool contains(const glm::vec3& point) const override; virtual bool shouldBePhysical() const override; + void simulateRelayedJoints(); // these are in the frame of this object (model space) virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override; @@ -90,7 +91,6 @@ public: 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; From a2046855667c59746be50a32085f93c1f57340b6 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 4 Jan 2018 13:44:04 -0800 Subject: [PATCH 06/15] don't do unnecessary work --- .../avatars-renderer/src/avatars-renderer/Avatar.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 61994db85e..b8158338d9 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -367,21 +367,17 @@ void Avatar::relayJointDataToChildren() { if (!containsJoint) { int jointIndex = modelEntity->getJointIndex(jointName); jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex); - jointTranslation - modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex); + jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex); } else { int jointIndex = getJointIndex(jointName); jointRotation = getJointRotation(jointIndex); jointTranslation = getJointTranslation(jointIndex); } jointSet.append(true); - jointRotations.append(jointRotation); - jointTranslations.append(jointTranslation); + int modelJointIndex = modelEntity->getJointIndex(jointName); + modelEntity->setLocalJointRotation(modelJointIndex, jointRotation); + modelEntity->setLocalJointTranslation(modelJointIndex, jointTranslation); } - - modelEntity->setJointRotationsSet(jointSet); - modelEntity->setJointTranslationsSet(jointSet); - modelEntity->setJointRotations(jointRotations); - modelEntity->setJointTranslations(jointTranslations); modelEntity->simulateRelayedJoints(); } } From 597cb6ae9ed6f2d0b62d92348064c3573f7e821b Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 4 Jan 2018 13:57:15 -0800 Subject: [PATCH 07/15] remove unused variables --- libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index b8158338d9..f1e2c5d00d 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -355,9 +355,6 @@ void Avatar::relayJointDataToChildren() { auto modelEntity = std::dynamic_pointer_cast(child); if (modelEntity) { if (modelEntity->getRelayParentJoints()) { - QVector jointRotations; - QVector jointTranslations; - QVector jointSet; QStringList modelJointNames = modelEntity->getJointNames(); QStringList avatarJointNames = getJointNames(); foreach (const QString& jointName, modelJointNames) { @@ -373,7 +370,6 @@ void Avatar::relayJointDataToChildren() { jointRotation = getJointRotation(jointIndex); jointTranslation = getJointTranslation(jointIndex); } - jointSet.append(true); int modelJointIndex = modelEntity->getJointIndex(jointName); modelEntity->setLocalJointRotation(modelJointIndex, jointRotation); modelEntity->setLocalJointTranslation(modelJointIndex, jointTranslation); From 43cd5586f337a3f92cb1f0a37c09aae363a7e59b Mon Sep 17 00:00:00 2001 From: David Back Date: Mon, 8 Jan 2018 17:25:58 -0800 Subject: [PATCH 08/15] nuke AccountScriptingInterface, rename GlobalServicesScriptingInterface to AccountServicesScriptingInterface --- interface/src/Application.cpp | 10 ++-- .../scripting/AccountScriptingInterface.cpp | 36 ----------- .../src/scripting/AccountScriptingInterface.h | 60 ------------------- ... => AccountServicesScriptingInterface.cpp} | 54 ++++++++--------- ....h => AccountServicesScriptingInterface.h} | 16 ++--- interface/src/ui/overlays/Web3DOverlay.cpp | 6 +- 6 files changed, 43 insertions(+), 139 deletions(-) delete mode 100644 interface/src/scripting/AccountScriptingInterface.cpp delete mode 100644 interface/src/scripting/AccountScriptingInterface.h rename interface/src/scripting/{GlobalServicesScriptingInterface.cpp => AccountServicesScriptingInterface.cpp} (71%) rename interface/src/scripting/{GlobalServicesScriptingInterface.h => AccountServicesScriptingInterface.h} (84%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f3c41565f8..cc0ee445fc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -157,7 +157,7 @@ #include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" #include "scripting/DesktopScriptingInterface.h" -#include "scripting/GlobalServicesScriptingInterface.h" +#include "scripting/AccountServicesScriptingInterface.h" #include "scripting/HMDScriptingInterface.h" #include "scripting/MenuScriptingInterface.h" #include "scripting/SettingsScriptingInterface.h" @@ -2373,9 +2373,9 @@ void Application::initializeUi() { surfaceContext->setContextProperty("SoundCache", DependencyManager::get().data()); surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get().data()); - surfaceContext->setContextProperty("Account", GlobalServicesScriptingInterface::getInstance()); + surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); surfaceContext->setContextProperty("DialogsManager", _dialogsManagerScriptingInterface); - surfaceContext->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance()); + surfaceContext->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); surfaceContext->setContextProperty("FaceTracker", DependencyManager::get().data()); surfaceContext->setContextProperty("AvatarManager", DependencyManager::get().data()); surfaceContext->setContextProperty("UndoStack", &_undoStackScriptingInterface); @@ -5744,10 +5744,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("Account", GlobalServicesScriptingInterface::getInstance()); + scriptEngine->registerGlobalObject("Account", AccountServicesScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface); - scriptEngine->registerGlobalObject("GlobalServices", GlobalServicesScriptingInterface::getInstance()); + scriptEngine->registerGlobalObject("GlobalServices", AccountServicesScriptingInterface::getInstance()); qScriptRegisterMetaType(scriptEngine.data(), DownloadInfoResultToScriptValue, DownloadInfoResultFromScriptValue); scriptEngine->registerGlobalObject("FaceTracker", DependencyManager::get().data()); diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp deleted file mode 100644 index fd54198b3c..0000000000 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -// AccountScriptingInterface.cpp -// interface/src/scripting -// -// Created by Stojce Slavkovski on 6/07/14. -// Copyright 2014 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 -// - -#include "AccountManager.h" - -#include "AccountScriptingInterface.h" -#include "GlobalServicesScriptingInterface.h" - -AccountScriptingInterface* AccountScriptingInterface::getInstance() { - static AccountScriptingInterface sharedInstance; - return &sharedInstance; -} - -bool AccountScriptingInterface::isLoggedIn() { - return GlobalServicesScriptingInterface::getInstance()->isLoggedIn(); -} - -void AccountScriptingInterface::logOut() { - GlobalServicesScriptingInterface::getInstance()->logOut(); -} - -bool AccountScriptingInterface::loggedIn() const { - return GlobalServicesScriptingInterface::getInstance()->loggedIn(); -} - -QString AccountScriptingInterface::getUsername() { - return GlobalServicesScriptingInterface::getInstance()->getUsername(); -} diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h deleted file mode 100644 index 10d33ffa36..0000000000 --- a/interface/src/scripting/AccountScriptingInterface.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// AccountScriptingInterface.h -// interface/src/scripting -// -// Created by Stojce Slavkovski on 6/07/14. -// Copyright 2014 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 -// - -#ifndef hifi_AccountScriptingInterface_h -#define hifi_AccountScriptingInterface_h - -#include - -class AccountScriptingInterface : public QObject { - Q_OBJECT - - /**jsdoc - * @namespace Account - * @property username {String} username if user is logged in, otherwise it returns "Unknown user" - */ - Q_PROPERTY(QString username READ getUsername) - Q_PROPERTY(bool loggedIn READ loggedIn) - -signals: - - /**jsdoc - * Triggered when username has changed. - * @function Account.usernameChanged - * @return {Signal} - */ - void usernameChanged(); - void loggedInChanged(bool loggedIn); - -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(); - void logOut(); - -public: - AccountScriptingInterface(QObject* parent = nullptr) {} - bool loggedIn() const; -}; - -#endif // hifi_AccountScriptingInterface_h diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.cpp b/interface/src/scripting/AccountServicesScriptingInterface.cpp similarity index 71% rename from interface/src/scripting/GlobalServicesScriptingInterface.cpp rename to interface/src/scripting/AccountServicesScriptingInterface.cpp index 305bfa3e79..fc293098bb 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.cpp +++ b/interface/src/scripting/AccountServicesScriptingInterface.cpp @@ -1,5 +1,5 @@ // -// GlobalServicesScriptingInterface.cpp +// AccountServicesScriptingInterface.cpp // interface/src/scripting // // Created by Thijs Wenker on 9/10/14. @@ -14,41 +14,41 @@ #include "DiscoverabilityManager.h" #include "ResourceCache.h" -#include "GlobalServicesScriptingInterface.h" +#include "AccountServicesScriptingInterface.h" -GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() { +AccountServicesScriptingInterface::AccountServicesScriptingInterface() { auto accountManager = DependencyManager::get(); - connect(accountManager.data(), &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::onUsernameChanged); - connect(accountManager.data(), &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); - connect(accountManager.data(), &AccountManager::loginComplete, this, &GlobalServicesScriptingInterface::connected); + connect(accountManager.data(), &AccountManager::usernameChanged, this, &AccountServicesScriptingInterface::onUsernameChanged); + connect(accountManager.data(), &AccountManager::logoutComplete, this, &AccountServicesScriptingInterface::loggedOut); + connect(accountManager.data(), &AccountManager::loginComplete, this, &AccountServicesScriptingInterface::connected); _downloading = false; QTimer* checkDownloadTimer = new QTimer(this); - connect(checkDownloadTimer, &QTimer::timeout, this, &GlobalServicesScriptingInterface::checkDownloadInfo); + connect(checkDownloadTimer, &QTimer::timeout, this, &AccountServicesScriptingInterface::checkDownloadInfo); const int CHECK_DOWNLOAD_INTERVAL = MSECS_PER_SECOND / 2; checkDownloadTimer->start(CHECK_DOWNLOAD_INTERVAL); auto discoverabilityManager = DependencyManager::get(); connect(discoverabilityManager.data(), &DiscoverabilityManager::discoverabilityModeChanged, - this, &GlobalServicesScriptingInterface::discoverabilityModeChanged); + this, &AccountServicesScriptingInterface::discoverabilityModeChanged); _loggedIn = isLoggedIn(); emit loggedInChanged(_loggedIn); } -GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() { +AccountServicesScriptingInterface::~AccountServicesScriptingInterface() { auto accountManager = DependencyManager::get(); - disconnect(accountManager.data(), &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::onUsernameChanged); - disconnect(accountManager.data(), &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); - disconnect(accountManager.data(), &AccountManager::loginComplete, this, &GlobalServicesScriptingInterface::connected); + disconnect(accountManager.data(), &AccountManager::usernameChanged, this, &AccountServicesScriptingInterface::onUsernameChanged); + disconnect(accountManager.data(), &AccountManager::logoutComplete, this, &AccountServicesScriptingInterface::loggedOut); + disconnect(accountManager.data(), &AccountManager::loginComplete, this, &AccountServicesScriptingInterface::connected); } -GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() { - static GlobalServicesScriptingInterface sharedInstance; +AccountServicesScriptingInterface* AccountServicesScriptingInterface::getInstance() { + static AccountServicesScriptingInterface sharedInstance; return &sharedInstance; } -const QString GlobalServicesScriptingInterface::getUsername() const { +const QString AccountServicesScriptingInterface::getUsername() const { auto accountManager = DependencyManager::get(); if (accountManager->isLoggedIn()) { return accountManager->getAccountInfo().getUsername(); @@ -57,31 +57,31 @@ const QString GlobalServicesScriptingInterface::getUsername() const { } } -bool GlobalServicesScriptingInterface::isLoggedIn() { +bool AccountServicesScriptingInterface::isLoggedIn() { auto accountManager = DependencyManager::get(); return accountManager->isLoggedIn(); } -bool GlobalServicesScriptingInterface::checkAndSignalForAccessToken() { +bool AccountServicesScriptingInterface::checkAndSignalForAccessToken() { auto accountManager = DependencyManager::get(); return accountManager->checkAndSignalForAccessToken(); } -void GlobalServicesScriptingInterface::logOut() { +void AccountServicesScriptingInterface::logOut() { auto accountManager = DependencyManager::get(); return accountManager->logout(); } -void GlobalServicesScriptingInterface::loggedOut() { - emit GlobalServicesScriptingInterface::disconnected(QString("logout")); +void AccountServicesScriptingInterface::loggedOut() { + emit AccountServicesScriptingInterface::disconnected(QString("logout")); } -QString GlobalServicesScriptingInterface::getFindableBy() const { +QString AccountServicesScriptingInterface::getFindableBy() const { auto discoverabilityManager = DependencyManager::get(); return DiscoverabilityManager::findableByString(discoverabilityManager->getDiscoverabilityMode()); } -void GlobalServicesScriptingInterface::setFindableBy(const QString& discoverabilityMode) { +void AccountServicesScriptingInterface::setFindableBy(const QString& discoverabilityMode) { auto discoverabilityManager = DependencyManager::get(); if (discoverabilityMode.toLower() == "none") { discoverabilityManager->setDiscoverabilityMode(Discoverability::None); @@ -96,11 +96,11 @@ void GlobalServicesScriptingInterface::setFindableBy(const QString& discoverabil } } -void GlobalServicesScriptingInterface::discoverabilityModeChanged(Discoverability::Mode discoverabilityMode) { +void AccountServicesScriptingInterface::discoverabilityModeChanged(Discoverability::Mode discoverabilityMode) { emit findableByChanged(DiscoverabilityManager::findableByString(discoverabilityMode)); } -void GlobalServicesScriptingInterface::onUsernameChanged(const QString& username) { +void AccountServicesScriptingInterface::onUsernameChanged(const QString& username) { _loggedIn = (username != QString()); emit myUsernameChanged(username); emit loggedInChanged(_loggedIn); @@ -135,7 +135,7 @@ void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoR result.pending = object.property("pending").toVariant().toFloat(); } -DownloadInfoResult GlobalServicesScriptingInterface::getDownloadInfo() { +DownloadInfoResult AccountServicesScriptingInterface::getDownloadInfo() { DownloadInfoResult result; foreach(const auto& resource, ResourceCache::getLoadingRequests()) { result.downloading.append(resource->getProgress() * 100.0f); @@ -144,7 +144,7 @@ DownloadInfoResult GlobalServicesScriptingInterface::getDownloadInfo() { return result; } -void GlobalServicesScriptingInterface::checkDownloadInfo() { +void AccountServicesScriptingInterface::checkDownloadInfo() { DownloadInfoResult downloadInfo = getDownloadInfo(); bool downloading = downloadInfo.downloading.count() > 0 || downloadInfo.pending > 0; @@ -155,7 +155,7 @@ void GlobalServicesScriptingInterface::checkDownloadInfo() { } } -void GlobalServicesScriptingInterface::updateDownloadInfo() { +void AccountServicesScriptingInterface::updateDownloadInfo() { emit downloadInfoChanged(getDownloadInfo()); } diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.h b/interface/src/scripting/AccountServicesScriptingInterface.h similarity index 84% rename from interface/src/scripting/GlobalServicesScriptingInterface.h rename to interface/src/scripting/AccountServicesScriptingInterface.h index 93d35e9ce8..012c37305d 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.h +++ b/interface/src/scripting/AccountServicesScriptingInterface.h @@ -1,5 +1,5 @@ // -// GlobalServicesScriptingInterface.h +// AccountServicesScriptingInterface.h // interface/src/scripting // // Created by Thijs Wenker on 9/10/14. @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_GlobalServicesScriptingInterface_h -#define hifi_GlobalServicesScriptingInterface_h +#ifndef hifi_AccountServicesScriptingInterface_h +#define hifi_AccountServicesScriptingInterface_h #include #include @@ -32,7 +32,7 @@ Q_DECLARE_METATYPE(DownloadInfoResult) QScriptValue DownloadInfoResultToScriptValue(QScriptEngine* engine, const DownloadInfoResult& result); void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoResult& result); -class GlobalServicesScriptingInterface : public QObject { +class AccountServicesScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(QString username READ getUsername NOTIFY myUsernameChanged) @@ -41,7 +41,7 @@ class GlobalServicesScriptingInterface : public QObject { Q_PROPERTY(QUrl metaverseServerURL READ getMetaverseServerURL) public: - static GlobalServicesScriptingInterface* getInstance(); + static AccountServicesScriptingInterface* getInstance(); const QString getUsername() const; bool loggedIn() const { return _loggedIn; } @@ -74,11 +74,11 @@ signals: void loggedInChanged(bool loggedIn); private: - GlobalServicesScriptingInterface(); - ~GlobalServicesScriptingInterface(); + AccountServicesScriptingInterface(); + ~AccountServicesScriptingInterface(); bool _downloading; bool _loggedIn{ false }; }; -#endif // hifi_GlobalServicesScriptingInterface_h +#endif // hifi_AccountServicesScriptingInterface_h diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index a5da5e99b6..0850e43590 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -50,7 +50,7 @@ #include "ui/DomainConnectionModel.h" #include "ui/AvatarInputs.h" #include "avatar/AvatarManager.h" -#include "scripting/GlobalServicesScriptingInterface.h" +#include "scripting/AccountServicesScriptingInterface.h" #include #include "ui/Snapshot.h" #include "SoundCache.h" @@ -192,7 +192,7 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("offscreenFlags", flags); _webSurface->getSurfaceContext()->setContextProperty("AddressManager", DependencyManager::get().data()); - _webSurface->getSurfaceContext()->setContextProperty("Account", GlobalServicesScriptingInterface::getInstance()); + _webSurface->getSurfaceContext()->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // in Qt 5.10.0 there is already an "Audio" object in the QML context // though I failed to find it (from QtMultimedia??). So.. let it be "AudioScriptingInterface" @@ -208,7 +208,7 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("OctreeStats", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("DCModel", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("AvatarInputs", AvatarInputs::getInstance()); - _webSurface->getSurfaceContext()->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance()); + _webSurface->getSurfaceContext()->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("AvatarList", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("InputConfiguration", DependencyManager::get().data()); From 13c34b2d3321fcdea7a0f21103cd91258435104f Mon Sep 17 00:00:00 2001 From: David Back Date: Mon, 8 Jan 2018 17:37:48 -0800 Subject: [PATCH 09/15] add AccountServices context --- interface/src/Application.cpp | 11 +++++++---- interface/src/ui/overlays/Web3DOverlay.cpp | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cc0ee445fc..bd5ba93b5f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2373,9 +2373,11 @@ void Application::initializeUi() { surfaceContext->setContextProperty("SoundCache", DependencyManager::get().data()); surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get().data()); - surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); + surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED + surfaceContext->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED + surfaceContext->setContextProperty("AccountServices", AccountServicesScriptingInterface::getInstance()); + surfaceContext->setContextProperty("DialogsManager", _dialogsManagerScriptingInterface); - surfaceContext->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); surfaceContext->setContextProperty("FaceTracker", DependencyManager::get().data()); surfaceContext->setContextProperty("AvatarManager", DependencyManager::get().data()); surfaceContext->setContextProperty("UndoStack", &_undoStackScriptingInterface); @@ -5744,10 +5746,11 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("Account", AccountServicesScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface); - scriptEngine->registerGlobalObject("GlobalServices", AccountServicesScriptingInterface::getInstance()); + scriptEngine->registerGlobalObject("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED + scriptEngine->registerGlobalObject("GlobalServices", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED + scriptEngine->registerGlobalObject("AccountServices", AccountServicesScriptingInterface::getInstance()); qScriptRegisterMetaType(scriptEngine.data(), DownloadInfoResultToScriptValue, DownloadInfoResultFromScriptValue); scriptEngine->registerGlobalObject("FaceTracker", DependencyManager::get().data()); diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 0850e43590..f073cc7413 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -192,7 +192,10 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("offscreenFlags", flags); _webSurface->getSurfaceContext()->setContextProperty("AddressManager", DependencyManager::get().data()); - _webSurface->getSurfaceContext()->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); + + _webSurface->getSurfaceContext()->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED + _webSurface->getSurfaceContext()->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED + _webSurface->getSurfaceContext()->setContextProperty("AccountServices", AccountServicesScriptingInterface::getInstance()); // in Qt 5.10.0 there is already an "Audio" object in the QML context // though I failed to find it (from QtMultimedia??). So.. let it be "AudioScriptingInterface" @@ -208,7 +211,6 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("OctreeStats", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("DCModel", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("AvatarInputs", AvatarInputs::getInstance()); - _webSurface->getSurfaceContext()->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("AvatarList", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("InputConfiguration", DependencyManager::get().data()); From 980807c657479cdd4f05ee21b1ccf05ed7436d5a Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 10 Jan 2018 16:50:41 -0800 Subject: [PATCH 10/15] make changes --- .../src/avatars-renderer/Avatar.cpp | 62 ++++++++++++++----- .../src/RenderableModelEntityItem.cpp | 19 ++++++ .../src/RenderableModelEntityItem.h | 5 ++ 3 files changed, 69 insertions(+), 17 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index f1e2c5d00d..765764da47 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -355,24 +355,52 @@ void Avatar::relayJointDataToChildren() { auto modelEntity = std::dynamic_pointer_cast(child); if (modelEntity) { if (modelEntity->getRelayParentJoints()) { - QStringList modelJointNames = modelEntity->getJointNames(); - QStringList avatarJointNames = getJointNames(); - foreach (const QString& jointName, modelJointNames) { - bool containsJoint = avatarJointNames.contains(jointName); - glm::quat jointRotation; - glm::vec3 jointTranslation; - if (!containsJoint) { - int jointIndex = modelEntity->getJointIndex(jointName); - jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex); - jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex); - } else { - int jointIndex = getJointIndex(jointName); - jointRotation = getJointRotation(jointIndex); - jointTranslation = getJointTranslation(jointIndex); + qDebug() << modelEntity->getJointMapCompleted(); + if (!(modelEntity->getJointMapCompleted())) { + qDebug() << "constructing map"; + QStringList modelJointNames = modelEntity->getJointNames(); + int numJoints = modelJointNames.count(); + std::vector map; + map.reserve(numJoints); + for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) { + QString jointName = modelJointNames.at(jointIndex); + int avatarJointIndex = getJointIndex(jointName); + glm::quat jointRotation; + glm::vec3 jointTranslation; + qDebug() << avatarJointIndex; + if (avatarJointIndex < 0) { + jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex); + jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex); + map.push_back(-1); + } else { + int jointIndex = getJointIndex(jointName); + jointRotation = getJointRotation(jointIndex); + jointTranslation = getJointTranslation(jointIndex); + map.push_back(avatarJointIndex); + } + modelEntity->setLocalJointRotation(jointIndex, jointRotation); + modelEntity->setLocalJointTranslation(jointIndex, jointTranslation); + } + modelEntity->setJointMap(map); + } else { + QStringList modelJointNames = modelEntity->getJointNames(); + int numJoints = modelJointNames.count(); + for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) { + int avatarJointIndex = modelEntity->avatarJointIndex(jointIndex); + int index = modelEntity->getJointIndex(modelJointNames.at(jointIndex)); + //qDebug() << jointIndex << "------" << index; + glm::quat jointRotation; + glm::vec3 jointTranslation; + if (avatarJointIndex >=0) { + jointRotation = getJointRotation(avatarJointIndex); + jointTranslation = getJointTranslation(avatarJointIndex); + } else { + jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex); + jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex); + } + modelEntity->setLocalJointRotation(jointIndex, jointRotation); + modelEntity->setLocalJointTranslation(jointIndex, jointTranslation); } - int modelJointIndex = modelEntity->getJointIndex(jointName); - modelEntity->setLocalJointRotation(modelJointIndex, jointRotation); - modelEntity->setLocalJointTranslation(modelJointIndex, jointTranslation); } modelEntity->simulateRelayedJoints(); } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index d60a82e678..84d19f4fb3 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -708,6 +708,21 @@ void RenderableModelEntityItem::setCollisionShape(const btCollisionShape* shape) } } +void RenderableModelEntityItem::setJointMap(std::vector jointMap) { + _jointMap = jointMap; + _jointMapCompleted = true; +}; + +int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) { + int result = -1; + int mapSize = _jointMap.size(); + if (modelJointIndex >=0 && modelJointIndex < mapSize) { + result = _jointMap[modelJointIndex]; + } + + return result; +} + bool RenderableModelEntityItem::contains(const glm::vec3& point) const { auto model = getModel(); if (EntityItem::contains(point) && model && _compoundShapeResource && _compoundShapeResource->isLoaded()) { @@ -813,6 +828,10 @@ bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int ind return setLocalJointTranslation(index, jointRelativePose.trans()); } +bool RenderableModelEntityItem::getJointMapCompleted() { + return _jointMapCompleted; +} + glm::quat RenderableModelEntityItem::getLocalJointRotation(int index) const { auto model = getModel(); if (model) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index e8244e6f1d..8315a44328 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -84,6 +84,9 @@ public: virtual bool shouldBePhysical() const override; void simulateRelayedJoints(); + bool getJointMapCompleted(); + void setJointMap(std::vector jointMap); + int avatarJointIndex(int modelJointIndex); // these are in the frame of this object (model space) virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override; @@ -119,7 +122,9 @@ private: void getCollisionGeometryResource(); GeometryResource::Pointer _compoundShapeResource; + bool _jointMapCompleted { false }; bool _originalTexturesRead { false }; + std::vector _jointMap; QVariantMap _originalTextures; bool _dimensionsInitialized { true }; bool _needsJointSimulation { false }; From 96a97b5938694c3c5dd256f03e3c8e167cd8d31f Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 11 Jan 2018 16:41:45 -0800 Subject: [PATCH 11/15] added model transform override --- interface/src/avatar/MyAvatar.cpp | 2 +- .../src/avatars-renderer/Avatar.cpp | 5 ++--- .../src/RenderableModelEntityItem.cpp | 21 ++++++++++++++++--- .../src/RenderableModelEntityItem.h | 1 + libraries/render-utils/src/Model.cpp | 14 ++++++++++++- libraries/render-utils/src/Model.h | 8 +++++++ 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 95ccd6c6c4..1cd0c79b32 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -537,7 +537,7 @@ void MyAvatar::simulate(float deltaTime) { // we've achived our final adjusted position and rotation for the avatar // and all of its joints, now update our attachements. Avatar::simulateAttachments(deltaTime); - Avatar::relayJointDataToChildren(); + relayJointDataToChildren(); if (!_skeletonModel->hasSkeleton()) { // All the simulation that can be done has been done diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 765764da47..ebc5ef2f6c 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -355,9 +355,7 @@ void Avatar::relayJointDataToChildren() { auto modelEntity = std::dynamic_pointer_cast(child); if (modelEntity) { if (modelEntity->getRelayParentJoints()) { - qDebug() << modelEntity->getJointMapCompleted(); if (!(modelEntity->getJointMapCompleted())) { - qDebug() << "constructing map"; QStringList modelJointNames = modelEntity->getJointNames(); int numJoints = modelJointNames.count(); std::vector map; @@ -388,7 +386,6 @@ void Avatar::relayJointDataToChildren() { for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) { int avatarJointIndex = modelEntity->avatarJointIndex(jointIndex); int index = modelEntity->getJointIndex(modelJointNames.at(jointIndex)); - //qDebug() << jointIndex << "------" << index; glm::quat jointRotation; glm::vec3 jointTranslation; if (avatarJointIndex >=0) { @@ -402,6 +399,8 @@ void Avatar::relayJointDataToChildren() { modelEntity->setLocalJointTranslation(jointIndex, jointTranslation); } } + + modelEntity->setOverrideTransform(_skeletonModel->getTransform()); modelEntity->simulateRelayedJoints(); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 84d19f4fb3..85dbc2feee 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -209,6 +209,12 @@ void RenderableModelEntityItem::updateModelBounds() { updateRenderItems = true; } + if (getRelayParentJoints()) { + model->setOverrideTransform(true); + } else { + model->setOverrideTransform(false); + } + if (model->getScaleToFitDimensions() != getScaledDimensions() || model->getRegistrationPoint() != getRegistrationPoint()) { // The machinery for updateModelBounds will give existing models the opportunity to fix their @@ -709,13 +715,15 @@ void RenderableModelEntityItem::setCollisionShape(const btCollisionShape* shape) } void RenderableModelEntityItem::setJointMap(std::vector jointMap) { - _jointMap = jointMap; - _jointMapCompleted = true; + if (jointMap.size() > 0) { + _jointMap = jointMap; + _jointMapCompleted = true; + } }; int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) { int result = -1; - int mapSize = _jointMap.size(); + int mapSize = (int) _jointMap.size(); if (modelJointIndex >=0 && modelJointIndex < mapSize) { result = _jointMap[modelJointIndex]; } @@ -854,6 +862,13 @@ glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const { return glm::vec3(); } +void RenderableModelEntityItem::setOverrideTransform(const Transform& transform) { + auto model = getModel(); + if (model) { + model->overrideModelTransform(transform); + } +} + bool RenderableModelEntityItem::setLocalJointRotation(int index, const glm::quat& rotation) { autoResizeJointArrays(); bool result = false; diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 8315a44328..e9e7b9ba67 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -87,6 +87,7 @@ public: bool getJointMapCompleted(); void setJointMap(std::vector jointMap); int avatarJointIndex(int modelJointIndex); + void setOverrideTransform(const Transform& transform); // these are in the frame of this object (model space) virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override; diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 539f0421b0..0c6c2223cd 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -144,7 +144,13 @@ void Model::setTransformNoUpdateRenderItems(const Transform& transform) { } Transform Model::getTransform() const { - if (_spatiallyNestableOverride) { + if (_overrideModelTransform) { + Transform transform; + transform.setTranslation(getOverrideTranslation()); + transform.setRotation(getOverrideRotation()); + transform.setScale(getScale()); + return transform; + } else if (_spatiallyNestableOverride) { bool success; Transform transform = _spatiallyNestableOverride->getTransform(success); if (success) { @@ -1363,6 +1369,12 @@ void Model::deleteGeometry() { _collisionGeometry.reset(); } +void Model::overrideModelTransform(const Transform& transform) { + _overrideTranslation = transform.getTranslation(); + _overrideRotation = transform.getRotation(); + _overrideModelTransform = true; +} + AABox Model::getRenderableMeshBound() const { if (!isLoaded()) { return AABox(); diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 77ed629962..f75e6d9c90 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -208,10 +208,14 @@ public: void setTranslation(const glm::vec3& translation); void setRotation(const glm::quat& rotation); + void overrideModelTransform(const Transform& transform); + void setOverrideTransform(bool override) { _overrideModelTransform = override; }; void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK const glm::vec3& getTranslation() const { return _translation; } const glm::quat& getRotation() const { return _rotation; } + const glm::vec3& getOverrideTranslation() const { return _overrideTranslation; } + const glm::quat& getOverrideRotation() const { return _overrideRotation; } glm::vec3 getNaturalDimensions() const; @@ -302,6 +306,9 @@ protected: glm::quat _rotation; glm::vec3 _scale; + glm::vec3 _overrideTranslation; + glm::quat _overrideRotation; + // For entity models this is the translation for the minimum extent of the model (in original mesh coordinate space) // to the model's registration point. For avatar models this is the translation from the avatar's hips, as determined // by the default pose, to the origin. @@ -362,6 +369,7 @@ protected: QMutex _mutex; + bool _overrideModelTransform { false }; bool _triangleSetsValid { false }; void calculateTriangleSets(); QVector _modelSpaceMeshTriangleSets; // model space triangles for all sub meshes From 088f227df27181d80bd8d1d18ee03855b95fc951 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Fri, 12 Jan 2018 10:26:02 -0800 Subject: [PATCH 12/15] Pass model offset from avatar skeletonModel to attached entity --- .../src/avatars-renderer/Avatar.cpp | 2 +- .../src/RenderableModelEntityItem.cpp | 4 +- .../src/RenderableModelEntityItem.h | 2 +- libraries/networking/src/udt/PacketHeaders.h | 1 + libraries/render-utils/src/Model.cpp | 3 +- libraries/render-utils/src/Model.h | 2 +- .../developer/tests/avatarAttachmentTest.js | 77 +++++++++++++++---- 7 files changed, 69 insertions(+), 22 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index ebc5ef2f6c..2c6cf7d620 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -400,7 +400,7 @@ void Avatar::relayJointDataToChildren() { } } - modelEntity->setOverrideTransform(_skeletonModel->getTransform()); + modelEntity->setOverrideTransform(_skeletonModel->getTransform(), _skeletonModel->getOffset()); modelEntity->simulateRelayedJoints(); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 85dbc2feee..3f5453ff04 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -862,10 +862,10 @@ glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const { return glm::vec3(); } -void RenderableModelEntityItem::setOverrideTransform(const Transform& transform) { +void RenderableModelEntityItem::setOverrideTransform(const Transform& transform, const glm::vec3& offset) { auto model = getModel(); if (model) { - model->overrideModelTransform(transform); + model->overrideModelTransform(transform, offset); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index e9e7b9ba67..1d00767030 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -87,7 +87,7 @@ public: bool getJointMapCompleted(); void setJointMap(std::vector jointMap); int avatarJointIndex(int modelJointIndex); - void setOverrideTransform(const Transform& transform); + void setOverrideTransform(const Transform& transform, const glm::vec3& offset); // these are in the frame of this object (model space) virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override; diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 66ac7ecf6c..8d823049df 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -203,6 +203,7 @@ enum class EntityVersion : PacketVersion { StaticCertJsonVersionOne, OwnershipChallengeFix, ZoneLightInheritModes, + ZoneStageRemoved, SoftEntities }; diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 0c6c2223cd..874fd09a79 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1369,10 +1369,11 @@ void Model::deleteGeometry() { _collisionGeometry.reset(); } -void Model::overrideModelTransform(const Transform& transform) { +void Model::overrideModelTransform(const Transform& transform, const glm::vec3& offset) { _overrideTranslation = transform.getTranslation(); _overrideRotation = transform.getRotation(); _overrideModelTransform = true; + setOffset(offset); } AABox Model::getRenderableMeshBound() const { diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index f75e6d9c90..554d3a4f47 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -208,7 +208,7 @@ public: void setTranslation(const glm::vec3& translation); void setRotation(const glm::quat& rotation); - void overrideModelTransform(const Transform& transform); + void overrideModelTransform(const Transform& transform, const glm::vec3& offset); void setOverrideTransform(bool override) { _overrideModelTransform = override; }; void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK diff --git a/scripts/developer/tests/avatarAttachmentTest.js b/scripts/developer/tests/avatarAttachmentTest.js index c9f2e1615b..ecc8c5a0af 100644 --- a/scripts/developer/tests/avatarAttachmentTest.js +++ b/scripts/developer/tests/avatarAttachmentTest.js @@ -57,7 +57,7 @@ ToggleButtonBuddy.prototype.addToggleHandler = function (callback) { }; ToggleButtonBuddy.prototype.removeToggleHandler = function (callback) { var index = this.callbacks.indexOf(callback); - if (index != -1) { + if (index !== -1) { this.callbacks.splice(index, 1); } }; @@ -86,13 +86,23 @@ var coatButton = new ToggleButtonBuddy(buttonPositionX, buttonPositionY, BUTTON_ down: "https://s3.amazonaws.com/hifi-public/tony/icons/coat-down.svg" }); +buttonPositionY += BUTTON_HEIGHT + BUTTON_PADDING; +var coatButton2 = new ToggleButtonBuddy(buttonPositionX, buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT, { + up: "https://s3.amazonaws.com/hifi-public/tony/icons/coat-up.svg", + down: "https://s3.amazonaws.com/hifi-public/tony/icons/coat-down.svg" +}); + +var AVATAR_ATTACHMENT = 0; +var AVATAR_SOFT_ATTACHMENT = 1; +var ENTITY_ATTACHMENT = 2; + var HAT_ATTACHMENT = { modelURL: "https://s3.amazonaws.com/hifi-public/tony/cowboy-hat.fbx", jointName: "Head", translation: {"x": 0, "y": 0.25, "z": 0.03}, rotation: {"x": 0, "y": 0, "z": 0, "w": 1}, scale: 0.052, - isSoft: false + type: AVATAR_ATTACHMENT }; var COAT_ATTACHMENT = { @@ -101,7 +111,16 @@ var COAT_ATTACHMENT = { translation: {"x": 0, "y": 0, "z": 0}, rotation: {"x": 0, "y": 0, "z": 0, "w": 1}, scale: 1, - isSoft: true + type: AVATAR_SOFT_ATTACHMENT +}; + +var COAT_ENTITY_ATTACHMENT = { + modelURL: "https://hifi-content.s3.amazonaws.com/ozan/dev/clothes/coat/coat_rig.fbx", + jointName: "Hips", + translation: {"x": 0, "y": 0, "z": 0}, + rotation: {"x": 0, "y": 0, "z": 0, "w": 1}, + scale: 1, + type: ENTITY_ATTACHMENT }; hatButton.addToggleHandler(function (isDown) { @@ -120,28 +139,54 @@ coatButton.addToggleHandler(function (isDown) { } }); +coatButton2.addToggleHandler(function (isDown) { + if (isDown) { + wearAttachment(COAT_ENTITY_ATTACHMENT); + } else { + removeAttachment(COAT_ENTITY_ATTACHMENT); + } +}); + function wearAttachment(attachment) { - MyAvatar.attach(attachment.modelURL, - attachment.jointName, - attachment.translation, - attachment.rotation, - attachment.scale, - attachment.isSoft); + if (attachment.type === AVATAR_ATTACHMENT || attachment.type === AVATAR_SOFT_ATTACHMENT) { + MyAvatar.attach(attachment.modelURL, + attachment.jointName, + attachment.translation, + attachment.rotation, + attachment.scale, + (attachment.type === AVATAR_SOFT_ATTACHMENT)); + } else { + attachment.entityID = Entities.addEntity({ + name: "attachment", + type: "Model", + modelURL: attachment.modelURL, + parentID: MyAvatar.sessionUUID, + relayParentJoints: true, + position: attachment.position, + rotation: attachment.rotation, + parentJointIndex: -1 + }); + } } function removeAttachment(attachment) { - var attachments = MyAvatar.attachmentData; - var i, l = attachments.length; - for (i = 0; i < l; i++) { - if (attachments[i].modelURL === attachment.modelURL) { - attachments.splice(i, 1); - MyAvatar.attachmentData = attachments; - break; + if (attachment.type === AVATAR_ATTACHMENT || attachment.type === AVATAR_SOFT_ATTACHMENT) { + var attachments = MyAvatar.attachmentData; + var i, l = attachments.length; + for (i = 0; i < l; i++) { + if (attachments[i].modelURL === attachment.modelURL) { + attachments.splice(i, 1); + MyAvatar.attachmentData = attachments; + break; + } } + } else { + Entities.deleteEntity(attachment.entityID); } } Script.scriptEnding.connect(function() { hatButton.destroy(); coatButton.destroy(); + coatButton2.destroy(); }); From 283b9a8003458af3ef7f00f82760fcdbfb6c7caf Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Fri, 12 Jan 2018 15:31:54 -0800 Subject: [PATCH 13/15] fix softEntity edge cases --- .../src/avatars-renderer/Avatar.cpp | 8 +++---- .../src/avatars-renderer/Avatar.h | 1 + .../src/RenderableModelEntityItem.cpp | 23 +++++++++++++------ .../src/RenderableModelEntityItem.h | 1 + libraries/render-utils/src/Model.cpp | 2 +- libraries/render-utils/src/Model.h | 5 ++-- .../developer/tests/avatarAttachmentTest.js | 2 +- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 2c6cf7d620..fb5ca84ac7 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -352,10 +352,10 @@ void Avatar::updateAvatarEntities() { void Avatar::relayJointDataToChildren() { forEachChild([&](SpatiallyNestablePointer child) { if (child->getNestableType() == NestableType::Entity) { - auto modelEntity = std::dynamic_pointer_cast(child); + auto modelEntity = std::dynamic_pointer_cast(child); if (modelEntity) { if (modelEntity->getRelayParentJoints()) { - if (!(modelEntity->getJointMapCompleted())) { + if (!modelEntity->getJointMapCompleted() || _reconstructSoftEntitiesJointMap) { QStringList modelJointNames = modelEntity->getJointNames(); int numJoints = modelJointNames.count(); std::vector map; @@ -365,7 +365,6 @@ void Avatar::relayJointDataToChildren() { int avatarJointIndex = getJointIndex(jointName); glm::quat jointRotation; glm::vec3 jointTranslation; - qDebug() << avatarJointIndex; if (avatarJointIndex < 0) { jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex); jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex); @@ -385,7 +384,6 @@ void Avatar::relayJointDataToChildren() { int numJoints = modelJointNames.count(); for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) { int avatarJointIndex = modelEntity->avatarJointIndex(jointIndex); - int index = modelEntity->getJointIndex(modelJointNames.at(jointIndex)); glm::quat jointRotation; glm::vec3 jointTranslation; if (avatarJointIndex >=0) { @@ -406,6 +404,7 @@ void Avatar::relayJointDataToChildren() { } } }); + _reconstructSoftEntitiesJointMap = false; } void Avatar::simulate(float deltaTime, bool inView) { @@ -1259,6 +1258,7 @@ void Avatar::setModelURLFinished(bool success) { invalidateJointIndicesCache(); _isAnimatingScale = true; + _reconstructSoftEntitiesJointMap = true; if (!success && _skeletonModelURL != AvatarData::defaultFullAvatarModelUrl()) { const int MAX_SKELETON_DOWNLOAD_ATTEMPTS = 4; // NOTE: we don't want to be as generous as ResourceCache is, we only want 4 attempts diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index e4efb67ebf..3fe14f980f 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -383,6 +383,7 @@ protected: bool _isAnimatingScale { false }; bool _mustFadeIn { false }; bool _isFading { false }; + bool _reconstructSoftEntitiesJointMap { false }; float _modelScale { 1.0f }; static int _jointConesID; diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index d8b1bf1540..5e68ac6a62 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -209,12 +209,6 @@ void RenderableModelEntityItem::updateModelBounds() { updateRenderItems = true; } - if (getRelayParentJoints()) { - model->setOverrideTransform(true); - } else { - model->setOverrideTransform(false); - } - if (model->getScaleToFitDimensions() != getScaledDimensions() || model->getRegistrationPoint() != getRegistrationPoint()) { // The machinery for updateModelBounds will give existing models the opportunity to fix their @@ -718,7 +712,10 @@ void RenderableModelEntityItem::setJointMap(std::vector jointMap) { if (jointMap.size() > 0) { _jointMap = jointMap; _jointMapCompleted = true; + return; } + + _jointMapCompleted = false; }; int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) { @@ -865,7 +862,7 @@ glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const { void RenderableModelEntityItem::setOverrideTransform(const Transform& transform, const glm::vec3& offset) { auto model = getModel(); if (model) { - model->overrideModelTransform(transform, offset); + model->overrideModelTransformAndOffset(transform, offset); } } @@ -972,6 +969,17 @@ void RenderableModelEntityItem::simulateRelayedJoints() { } } +void RenderableModelEntityItem::stopModelOverrideIfNoParent() { + auto model = getModel(); + if (model) { + bool overriding = model->isOverridingModelTransformAndOffset(); + QUuid parentID = getParentID(); + if (overriding && (!_relayParentJoints || parentID.isNull())) { + model->stopTransformAndOffsetOverride(); + } + } +} + void RenderableModelEntityItem::copyAnimationJointDataToModel() { auto model = getModel(); if (!model || !model->isLoaded()) { @@ -1323,6 +1331,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce } entity->updateModelBounds(); + entity->stopModelOverrideIfNoParent(); if (model->isVisible() != _visible) { // FIXME: this seems like it could be optimized if we tracked our last known visible state in diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 1d00767030..b3988e0239 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -81,6 +81,7 @@ public: void setCollisionShape(const btCollisionShape* shape) override; virtual bool contains(const glm::vec3& point) const override; + void stopModelOverrideIfNoParent(); virtual bool shouldBePhysical() const override; void simulateRelayedJoints(); diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 874fd09a79..68d407ac2b 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1369,7 +1369,7 @@ void Model::deleteGeometry() { _collisionGeometry.reset(); } -void Model::overrideModelTransform(const Transform& transform, const glm::vec3& offset) { +void Model::overrideModelTransformAndOffset(const Transform& transform, const glm::vec3& offset) { _overrideTranslation = transform.getTranslation(); _overrideRotation = transform.getRotation(); _overrideModelTransform = true; diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 554d3a4f47..fa773daa6e 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -208,8 +208,9 @@ public: void setTranslation(const glm::vec3& translation); void setRotation(const glm::quat& rotation); - void overrideModelTransform(const Transform& transform, const glm::vec3& offset); - void setOverrideTransform(bool override) { _overrideModelTransform = override; }; + void overrideModelTransformAndOffset(const Transform& transform, const glm::vec3& offset); + bool isOverridingModelTransformAndOffset() { return _overrideModelTransform; }; + void stopTransformAndOffsetOverride() { _overrideModelTransform = false; }; void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK const glm::vec3& getTranslation() const { return _translation; } diff --git a/scripts/developer/tests/avatarAttachmentTest.js b/scripts/developer/tests/avatarAttachmentTest.js index ecc8c5a0af..b9dfcf9596 100644 --- a/scripts/developer/tests/avatarAttachmentTest.js +++ b/scripts/developer/tests/avatarAttachmentTest.js @@ -165,7 +165,7 @@ function wearAttachment(attachment) { position: attachment.position, rotation: attachment.rotation, parentJointIndex: -1 - }); + }, true); } } From c76fdd1f5fe98a6710f36394bb25554330830da3 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 15 Jan 2018 10:43:26 -0800 Subject: [PATCH 14/15] adding scale --- libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 5 +++-- libraries/render-utils/src/Model.cpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index fb5ca84ac7..0f9573bb84 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -397,8 +397,9 @@ void Avatar::relayJointDataToChildren() { modelEntity->setLocalJointTranslation(jointIndex, jointTranslation); } } - - modelEntity->setOverrideTransform(_skeletonModel->getTransform(), _skeletonModel->getOffset()); + Transform avatarTransform = _skeletonModel->getTransform(); + avatarTransform.setScale(_skeletonModel->getScale()); + modelEntity->setOverrideTransform(avatarTransform, _skeletonModel->getOffset()); modelEntity->simulateRelayedJoints(); } } diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 68d407ac2b..3744a0f090 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1373,6 +1373,7 @@ void Model::overrideModelTransformAndOffset(const Transform& transform, const gl _overrideTranslation = transform.getTranslation(); _overrideRotation = transform.getRotation(); _overrideModelTransform = true; + setScale(transform.getScale()); setOffset(offset); } From 6686b328c7a4aed70c2a1595eb10a0df9fec75db Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Tue, 16 Jan 2018 10:47:46 +0100 Subject: [PATCH 15/15] Fixed error in Specular shader which gave low key specular highlights --- libraries/render-utils/src/LightingModel.slh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index d96c565b81..7d08fdabaf 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -133,7 +133,7 @@ SurfaceData initSurfaceData(float roughness, vec3 normal, vec3 eyeDir) { SurfaceData surface; surface.eyeDir = eyeDir; surface.normal = normal; - surface.roughness = mix(0.001, 1.0, roughness); + surface.roughness = mix(0.01, 1.0, roughness); surface.roughness2 = surface.roughness * surface.roughness; surface.roughness4 = surface.roughness2 * surface.roughness2; surface.ndotv = clamp(dot(normal, eyeDir), 0.0, 1.0); @@ -181,7 +181,7 @@ float fresnelSchlickScalar(float fresnelScalar, SurfaceData surface) { float specularDistribution(SurfaceData surface) { // See https://www.khronos.org/assets/uploads/developers/library/2017-web3d/glTF-2.0-Launch_Jun17.pdf // for details of equations, especially page 20 - float denom = (surface.ndoth*surface.ndoth * (surface.roughness2 - 1.0) + 1.0); + float denom = (surface.ndoth*surface.ndoth * (surface.roughness4 - 1.0) + 1.0); denom *= denom; // Add geometric factors G1(n,l) and G1(n,v) float smithInvG1NdotL = evalSmithInvG1(surface.roughness4, surface.ndotl);