From 3c37bf8acda8eec6e3cddd103dea7c69abbed44a Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Fri, 17 Nov 2017 20:33:06 +0100 Subject: [PATCH 1/4] parentJointName property experiment --- libraries/avatars/src/AvatarData.h | 3 +-- libraries/entities/src/EntityItem.cpp | 5 +++++ .../entities/src/EntityItemProperties.cpp | 9 ++++++++ libraries/entities/src/EntityItemProperties.h | 2 ++ libraries/entities/src/EntityPropertyFlags.h | 2 ++ .../networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 3 ++- libraries/shared/src/SpatiallyNestable.cpp | 22 ++++++++++++++++++- libraries/shared/src/SpatiallyNestable.h | 9 +++++++- 9 files changed, 51 insertions(+), 6 deletions(-) diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 4dabbb3ff5..1b17f9fc4d 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -522,7 +522,7 @@ public: Q_INVOKABLE virtual void clearJointsData(); /// Returns the index of the joint with the specified name, or -1 if not found/unknown. - Q_INVOKABLE virtual int getJointIndex(const QString& name) const; + Q_INVOKABLE virtual int getJointIndex(const QString& name) const override; Q_INVOKABLE virtual QStringList getJointNames() const; @@ -669,7 +669,6 @@ public slots: emit sessionUUIDChanged(); } } - 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 { return false; } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 3f054e1ccb..f0c88e31c3 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -121,6 +121,7 @@ EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& param requestedProperties += PROP_ACTION_DATA; requestedProperties += PROP_PARENT_ID; requestedProperties += PROP_PARENT_JOINT_INDEX; + requestedProperties += PROP_PARENT_JOINT_NAME; requestedProperties += PROP_QUERY_AA_CUBE; requestedProperties += PROP_CLIENT_ONLY; @@ -287,6 +288,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_PARENT_ID, actualParentID); APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_INDEX, getParentJointIndex()); + APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_NAME, getParentJointName()); APPEND_ENTITY_PROPERTY(PROP_QUERY_AA_CUBE, getQueryAACube()); APPEND_ENTITY_PROPERTY(PROP_LAST_EDITED_BY, getLastEditedBy()); @@ -831,6 +833,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef overwriteLocalData = overwriteLocalData && !weOwnSimulation; READ_ENTITY_PROPERTY(PROP_PARENT_ID, QUuid, updateParentID); READ_ENTITY_PROPERTY(PROP_PARENT_JOINT_INDEX, quint16, setParentJointIndex); + READ_ENTITY_PROPERTY(PROP_PARENT_JOINT_NAME, QString, setParentJointName); overwriteLocalData = oldOverwrite; } @@ -1262,6 +1265,7 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper COPY_ENTITY_PROPERTY_TO_PROPERTIES(actionData, getDynamicData); COPY_ENTITY_PROPERTY_TO_PROPERTIES(parentID, getParentID); COPY_ENTITY_PROPERTY_TO_PROPERTIES(parentJointIndex, getParentJointIndex); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(parentJointName, getParentJointName); COPY_ENTITY_PROPERTY_TO_PROPERTIES(queryAACube, getQueryAACube); COPY_ENTITY_PROPERTY_TO_PROPERTIES(localPosition, getLocalPosition); COPY_ENTITY_PROPERTY_TO_PROPERTIES(localRotation, getLocalOrientation); @@ -1369,6 +1373,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(actionData, setDynamicData); SET_ENTITY_PROPERTY_FROM_PROPERTIES(parentID, updateParentID); SET_ENTITY_PROPERTY_FROM_PROPERTIES(parentJointIndex, setParentJointIndex); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(parentJointName, setParentJointName); SET_ENTITY_PROPERTY_FROM_PROPERTIES(queryAACube, setQueryAACube); SET_ENTITY_PROPERTY_FROM_PROPERTIES(clientOnly, setClientOnly); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 108fc14e30..d2cb894c58 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -359,6 +359,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_Z_P_NEIGHBOR_ID, zPNeighborID); CHECK_PROPERTY_CHANGE(PROP_PARENT_ID, parentID); CHECK_PROPERTY_CHANGE(PROP_PARENT_JOINT_INDEX, parentJointIndex); + CHECK_PROPERTY_CHANGE(PROP_PARENT_JOINT_NAME, parentJointName); CHECK_PROPERTY_CHANGE(PROP_JOINT_ROTATIONS_SET, jointRotationsSet); CHECK_PROPERTY_CHANGE(PROP_JOINT_ROTATIONS, jointRotations); CHECK_PROPERTY_CHANGE(PROP_JOINT_TRANSLATIONS_SET, jointTranslationsSet); @@ -624,6 +625,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_PARENT_ID, parentID); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_PARENT_JOINT_INDEX, parentJointIndex); + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_PARENT_JOINT_NAME, parentJointName); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_QUERY_AA_CUBE, queryAACube); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_POSITION, localPosition); @@ -800,6 +802,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(parentID, QUuid, setParentID); COPY_PROPERTY_FROM_QSCRIPTVALUE(parentJointIndex, quint16, setParentJointIndex); + COPY_PROPERTY_FROM_QSCRIPTVALUE(parentJointName, QString, setParentJointName); COPY_PROPERTY_FROM_QSCRIPTVALUE(queryAACube, AACube, setQueryAACube); COPY_PROPERTY_FROM_QSCRIPTVALUE(localPosition, glmVec3, setLocalPosition); @@ -1126,6 +1129,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_PARENT_ID, ParentID, parentID, QUuid); ADD_PROPERTY_TO_MAP(PROP_PARENT_JOINT_INDEX, ParentJointIndex, parentJointIndex, uint16_t); + ADD_PROPERTY_TO_MAP(PROP_PARENT_JOINT_NAME, ParentJointName, parentJointName, QString); ADD_PROPERTY_TO_MAP(PROP_LOCAL_POSITION, LocalPosition, localPosition, glm::vec3); ADD_PROPERTY_TO_MAP(PROP_LOCAL_ROTATION, LocalRotation, localRotation, glm::quat); @@ -1335,6 +1339,7 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, properties.getDescription()); APPEND_ENTITY_PROPERTY(PROP_PARENT_ID, properties.getParentID()); APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_INDEX, properties.getParentJointIndex()); + APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_NAME, properties.getParentJointName()); APPEND_ENTITY_PROPERTY(PROP_QUERY_AA_CUBE, properties.getQueryAACube()); if (properties.getType() == EntityTypes::Web) { @@ -2042,6 +2047,7 @@ void EntityItemProperties::markAllChanged() { _parentIDChanged = true; _parentJointIndexChanged = true; + _parentJointNameChanged = true; _jointRotationsSetChanged = true; _jointRotationsChanged = true; @@ -2401,6 +2407,9 @@ QList EntityItemProperties::listChangedProperties() { if (parentJointIndexChanged()) { out += "parentJointIndex"; } + if (parentJointNameChanged()) { + out += "parentJointName"; + } if (jointRotationsSetChanged()) { out += "jointRotationsSet"; } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 732dbdf69f..7ad96568fd 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -206,6 +206,7 @@ public: DEFINE_PROPERTY_REF(PROP_Z_P_NEIGHBOR_ID, ZPNeighborID, zPNeighborID, EntityItemID, UNKNOWN_ENTITY_ID); DEFINE_PROPERTY_REF(PROP_PARENT_ID, ParentID, parentID, QUuid, UNKNOWN_ENTITY_ID); DEFINE_PROPERTY_REF(PROP_PARENT_JOINT_INDEX, ParentJointIndex, parentJointIndex, quint16, -1); + DEFINE_PROPERTY_REF(PROP_PARENT_JOINT_NAME, ParentJointName, parentJointName, QString, ""); DEFINE_PROPERTY_REF(PROP_QUERY_AA_CUBE, QueryAACube, queryAACube, AACube, AACube()); DEFINE_PROPERTY_REF(PROP_SHAPE, Shape, shape, QString, "Sphere"); @@ -495,6 +496,7 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParentID, parentID, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParentJointIndex, parentJointIndex, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParentJointName, parentJointName, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, QueryAACube, queryAACube, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, JointRotationsSet, jointRotationsSet, ""); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 35d40b669a..e65cfad2bf 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -219,6 +219,8 @@ enum EntityPropertyList { PROP_HAZE_KEYLIGHT_RANGE, PROP_HAZE_KEYLIGHT_ALTITUDE, + PROP_PARENT_JOINT_NAME, + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties to end of list just ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 9a98393fa1..2fa727accc 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::HazeEffect); + return static_cast(EntityVersion::ParentJointName); case PacketType::EntityQuery: return static_cast(EntityQueryPacketVersion::JSONFilterWithFamilyTree); diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 21b4ae8878..fa72c652ea 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -199,7 +199,8 @@ QDebug operator<<(QDebug debug, const PacketType& type); enum class EntityVersion : PacketVersion { StrokeColorProperty = 77, HasDynamicOwnershipTests, - HazeEffect + HazeEffect, + ParentJointName }; enum class EntityScriptCallMethodVersion : PacketVersion { diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 8dbd2dd5e0..1155763222 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -77,6 +77,18 @@ void SpatiallyNestable::setParentID(const QUuid& parentID) { getParentPointer(success); } +quint16 SpatiallyNestable::getParentJointIndex() const { + if (_parentJointName.isEmpty()) { + return _parentJointIndex; + } + bool success = false; + SpatiallyNestablePointer parent = getParentPointer(success); + if (success && parent) { + return parent->getJointIndex(_parentJointName); + } + return _parentJointIndex; +} + Transform SpatiallyNestable::getParentTransform(bool& success, int depth) const { Transform result; SpatiallyNestablePointer parent = getParentPointer(success); @@ -84,7 +96,7 @@ Transform SpatiallyNestable::getParentTransform(bool& success, int depth) const return result; } if (parent) { - result = parent->getTransform(_parentJointIndex, success, depth + 1); + result = parent->getTransform(getParentJointIndex(), success, depth + 1); } return result; } @@ -163,6 +175,14 @@ void SpatiallyNestable::setParentJointIndex(quint16 parentJointIndex) { _parentJointIndex = parentJointIndex; } +void SpatiallyNestable::setParentJointName(const QString& parentJointName) { + _parentJointName = parentJointName; +} + +QString SpatiallyNestable::getParentJointName() const { + return _parentJointName; +} + glm::vec3 SpatiallyNestable::worldToLocal(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success) { diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 37f6cfdfd9..cb9e3825b0 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -47,9 +47,12 @@ public: virtual const QUuid getParentID() const; virtual void setParentID(const QUuid& parentID); - virtual quint16 getParentJointIndex() const { return _parentJointIndex; } + virtual quint16 getParentJointIndex() const; virtual void setParentJointIndex(quint16 parentJointIndex); + virtual QString getParentJointName() const; + virtual void setParentJointName(const QString& parentJointName); + static glm::vec3 worldToLocal(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success); static glm::quat worldToLocal(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success); static glm::vec3 worldToLocalVelocity(const glm::vec3& velocity, const QUuid& parentID, @@ -162,6 +165,9 @@ public: virtual bool setLocalJointRotation(int index, const glm::quat& rotation) { return false; } virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) { return false; } + virtual int getJointIndex(const QString& jointName) const { return -1; } + virtual QString getJointName(int jointIndex) const { return ""; } + SpatiallyNestablePointer getThisPointer() const; using ChildLambda = std::function; @@ -224,6 +230,7 @@ protected: private: QUuid _parentID; // what is this thing's transform relative to? quint16 _parentJointIndex { INVALID_JOINT_INDEX }; // which joint of the parent is this relative to? + QString _parentJointName; mutable ReadWriteLockable _transformLock; mutable ReadWriteLockable _idLock; From 84ec9890ca8306d23a091f8c5b01d09d6c3badec Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 20 Nov 2017 18:29:33 +0100 Subject: [PATCH 2/4] reverted special property case, parentJointName is now only parsed from the JSON import --- interface/src/Application.cpp | 4 ++++ libraries/avatars/src/AvatarData.h | 3 ++- libraries/entities/src/EntityItem.cpp | 5 ----- .../entities/src/EntityItemProperties.cpp | 9 -------- libraries/entities/src/EntityItemProperties.h | 2 -- libraries/entities/src/EntityPropertyFlags.h | 2 -- libraries/entities/src/EntityTree.cpp | 11 ++++++++++ libraries/entities/src/EntityTree.h | 4 ++++ .../networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 3 +-- libraries/shared/src/SpatiallyNestable.cpp | 22 +------------------ libraries/shared/src/SpatiallyNestable.h | 9 +------- 12 files changed, 25 insertions(+), 51 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c53b2c993c..5c62038ee7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1183,6 +1183,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _entityEditSender.setServerJurisdictions(&_entityServerJurisdictions); _entityEditSender.setMyAvatar(myAvatar.get()); + // The entity octree will have to know about MyAvatar for the parentJointName import + getEntities()->getTree()->setMyAvatar(myAvatar.get()); + _entityClipboard->setMyAvatar(myAvatar.get()); + // For now we're going to set the PPS for outbound packets to be super high, this is // probably not the right long term solution. But for now, we're going to do this to // allow you to move an entity around in your hand diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 1b17f9fc4d..4dabbb3ff5 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -522,7 +522,7 @@ public: Q_INVOKABLE virtual void clearJointsData(); /// Returns the index of the joint with the specified name, or -1 if not found/unknown. - Q_INVOKABLE virtual int getJointIndex(const QString& name) const override; + Q_INVOKABLE virtual int getJointIndex(const QString& name) const; Q_INVOKABLE virtual QStringList getJointNames() const; @@ -669,6 +669,7 @@ public slots: emit sessionUUIDChanged(); } } + 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 { return false; } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index f0c88e31c3..3f054e1ccb 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -121,7 +121,6 @@ EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& param requestedProperties += PROP_ACTION_DATA; requestedProperties += PROP_PARENT_ID; requestedProperties += PROP_PARENT_JOINT_INDEX; - requestedProperties += PROP_PARENT_JOINT_NAME; requestedProperties += PROP_QUERY_AA_CUBE; requestedProperties += PROP_CLIENT_ONLY; @@ -288,7 +287,6 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_PARENT_ID, actualParentID); APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_INDEX, getParentJointIndex()); - APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_NAME, getParentJointName()); APPEND_ENTITY_PROPERTY(PROP_QUERY_AA_CUBE, getQueryAACube()); APPEND_ENTITY_PROPERTY(PROP_LAST_EDITED_BY, getLastEditedBy()); @@ -833,7 +831,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef overwriteLocalData = overwriteLocalData && !weOwnSimulation; READ_ENTITY_PROPERTY(PROP_PARENT_ID, QUuid, updateParentID); READ_ENTITY_PROPERTY(PROP_PARENT_JOINT_INDEX, quint16, setParentJointIndex); - READ_ENTITY_PROPERTY(PROP_PARENT_JOINT_NAME, QString, setParentJointName); overwriteLocalData = oldOverwrite; } @@ -1265,7 +1262,6 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper COPY_ENTITY_PROPERTY_TO_PROPERTIES(actionData, getDynamicData); COPY_ENTITY_PROPERTY_TO_PROPERTIES(parentID, getParentID); COPY_ENTITY_PROPERTY_TO_PROPERTIES(parentJointIndex, getParentJointIndex); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(parentJointName, getParentJointName); COPY_ENTITY_PROPERTY_TO_PROPERTIES(queryAACube, getQueryAACube); COPY_ENTITY_PROPERTY_TO_PROPERTIES(localPosition, getLocalPosition); COPY_ENTITY_PROPERTY_TO_PROPERTIES(localRotation, getLocalOrientation); @@ -1373,7 +1369,6 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(actionData, setDynamicData); SET_ENTITY_PROPERTY_FROM_PROPERTIES(parentID, updateParentID); SET_ENTITY_PROPERTY_FROM_PROPERTIES(parentJointIndex, setParentJointIndex); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(parentJointName, setParentJointName); SET_ENTITY_PROPERTY_FROM_PROPERTIES(queryAACube, setQueryAACube); SET_ENTITY_PROPERTY_FROM_PROPERTIES(clientOnly, setClientOnly); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index d2cb894c58..108fc14e30 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -359,7 +359,6 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_Z_P_NEIGHBOR_ID, zPNeighborID); CHECK_PROPERTY_CHANGE(PROP_PARENT_ID, parentID); CHECK_PROPERTY_CHANGE(PROP_PARENT_JOINT_INDEX, parentJointIndex); - CHECK_PROPERTY_CHANGE(PROP_PARENT_JOINT_NAME, parentJointName); CHECK_PROPERTY_CHANGE(PROP_JOINT_ROTATIONS_SET, jointRotationsSet); CHECK_PROPERTY_CHANGE(PROP_JOINT_ROTATIONS, jointRotations); CHECK_PROPERTY_CHANGE(PROP_JOINT_TRANSLATIONS_SET, jointTranslationsSet); @@ -625,7 +624,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_PARENT_ID, parentID); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_PARENT_JOINT_INDEX, parentJointIndex); - COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_PARENT_JOINT_NAME, parentJointName); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_QUERY_AA_CUBE, queryAACube); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_POSITION, localPosition); @@ -802,7 +800,6 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(parentID, QUuid, setParentID); COPY_PROPERTY_FROM_QSCRIPTVALUE(parentJointIndex, quint16, setParentJointIndex); - COPY_PROPERTY_FROM_QSCRIPTVALUE(parentJointName, QString, setParentJointName); COPY_PROPERTY_FROM_QSCRIPTVALUE(queryAACube, AACube, setQueryAACube); COPY_PROPERTY_FROM_QSCRIPTVALUE(localPosition, glmVec3, setLocalPosition); @@ -1129,7 +1126,6 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_PARENT_ID, ParentID, parentID, QUuid); ADD_PROPERTY_TO_MAP(PROP_PARENT_JOINT_INDEX, ParentJointIndex, parentJointIndex, uint16_t); - ADD_PROPERTY_TO_MAP(PROP_PARENT_JOINT_NAME, ParentJointName, parentJointName, QString); ADD_PROPERTY_TO_MAP(PROP_LOCAL_POSITION, LocalPosition, localPosition, glm::vec3); ADD_PROPERTY_TO_MAP(PROP_LOCAL_ROTATION, LocalRotation, localRotation, glm::quat); @@ -1339,7 +1335,6 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, properties.getDescription()); APPEND_ENTITY_PROPERTY(PROP_PARENT_ID, properties.getParentID()); APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_INDEX, properties.getParentJointIndex()); - APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_NAME, properties.getParentJointName()); APPEND_ENTITY_PROPERTY(PROP_QUERY_AA_CUBE, properties.getQueryAACube()); if (properties.getType() == EntityTypes::Web) { @@ -2047,7 +2042,6 @@ void EntityItemProperties::markAllChanged() { _parentIDChanged = true; _parentJointIndexChanged = true; - _parentJointNameChanged = true; _jointRotationsSetChanged = true; _jointRotationsChanged = true; @@ -2407,9 +2401,6 @@ QList EntityItemProperties::listChangedProperties() { if (parentJointIndexChanged()) { out += "parentJointIndex"; } - if (parentJointNameChanged()) { - out += "parentJointName"; - } if (jointRotationsSetChanged()) { out += "jointRotationsSet"; } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 7ad96568fd..732dbdf69f 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -206,7 +206,6 @@ public: DEFINE_PROPERTY_REF(PROP_Z_P_NEIGHBOR_ID, ZPNeighborID, zPNeighborID, EntityItemID, UNKNOWN_ENTITY_ID); DEFINE_PROPERTY_REF(PROP_PARENT_ID, ParentID, parentID, QUuid, UNKNOWN_ENTITY_ID); DEFINE_PROPERTY_REF(PROP_PARENT_JOINT_INDEX, ParentJointIndex, parentJointIndex, quint16, -1); - DEFINE_PROPERTY_REF(PROP_PARENT_JOINT_NAME, ParentJointName, parentJointName, QString, ""); DEFINE_PROPERTY_REF(PROP_QUERY_AA_CUBE, QueryAACube, queryAACube, AACube, AACube()); DEFINE_PROPERTY_REF(PROP_SHAPE, Shape, shape, QString, "Sphere"); @@ -496,7 +495,6 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParentID, parentID, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParentJointIndex, parentJointIndex, ""); - DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParentJointName, parentJointName, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, QueryAACube, queryAACube, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, JointRotationsSet, jointRotationsSet, ""); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index e65cfad2bf..35d40b669a 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -219,8 +219,6 @@ enum EntityPropertyList { PROP_HAZE_KEYLIGHT_RANGE, PROP_HAZE_KEYLIGHT_ALTITUDE, - PROP_PARENT_JOINT_NAME, - //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties to end of list just ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 333a514377..0957bb8444 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -2276,6 +2276,17 @@ bool EntityTree::readFromMap(QVariantMap& map) { foreach (QVariant entityVariant, entitiesQList) { // QVariantMap --> QScriptValue --> EntityItemProperties --> Entity QVariantMap entityMap = entityVariant.toMap(); + + // handle parentJointName for wearables + if (_myAvatar && entityMap.contains("parentJointName") && entityMap.contains("parentID") && + QUuid(entityMap["parentID"].toString()) == AVATAR_SELF_ID) { + + entityMap["parentJointIndex"] = _myAvatar->getJointIndex(entityMap["parentJointName"].toString()); + + qCDebug(entities) << "Found parentJointName " << entityMap["parentJointName"].toString() << + " mapped it to parentJointIndex " << entityMap["parentJointIndex"].toInt(); + } + QScriptValue entityScriptValue = variantMapToScriptValue(entityMap, scriptEngine); EntityItemProperties properties; EntityItemPropertiesFromScriptValueIgnoreReadOnly(entityScriptValue, properties); diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 86bfe984f6..2dbe05e83b 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -278,6 +278,8 @@ public: QByteArray computeEncryptedNonce(const QString& certID, const QString ownerKey); bool verifyDecryptedNonce(const QString& certID, const QString& decryptedNonce, EntityItemID& id); + void setMyAvatar(AvatarData* myAvatar) { _myAvatar = myAvatar; } + signals: void deletingEntity(const EntityItemID& entityID); void deletingEntityPointer(EntityItem* entityID); @@ -383,6 +385,8 @@ private: void sendChallengeOwnershipPacket(const QString& certID, const QString& ownerKey, const EntityItemID& entityItemID, const SharedNodePointer& senderNode); void sendChallengeOwnershipRequestPacket(const QByteArray& certID, const QByteArray& encryptedText, const QByteArray& nodeToChallenge, const SharedNodePointer& senderNode); void validatePop(const QString& certID, const EntityItemID& entityItemID, const SharedNodePointer& senderNode, bool isRetryingValidation); + + AvatarData* _myAvatar{ nullptr }; }; #endif // hifi_EntityTree_h diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 2fa727accc..9a98393fa1 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::ParentJointName); + return static_cast(EntityVersion::HazeEffect); case PacketType::EntityQuery: return static_cast(EntityQueryPacketVersion::JSONFilterWithFamilyTree); diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index fa72c652ea..21b4ae8878 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -199,8 +199,7 @@ QDebug operator<<(QDebug debug, const PacketType& type); enum class EntityVersion : PacketVersion { StrokeColorProperty = 77, HasDynamicOwnershipTests, - HazeEffect, - ParentJointName + HazeEffect }; enum class EntityScriptCallMethodVersion : PacketVersion { diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 1155763222..8dbd2dd5e0 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -77,18 +77,6 @@ void SpatiallyNestable::setParentID(const QUuid& parentID) { getParentPointer(success); } -quint16 SpatiallyNestable::getParentJointIndex() const { - if (_parentJointName.isEmpty()) { - return _parentJointIndex; - } - bool success = false; - SpatiallyNestablePointer parent = getParentPointer(success); - if (success && parent) { - return parent->getJointIndex(_parentJointName); - } - return _parentJointIndex; -} - Transform SpatiallyNestable::getParentTransform(bool& success, int depth) const { Transform result; SpatiallyNestablePointer parent = getParentPointer(success); @@ -96,7 +84,7 @@ Transform SpatiallyNestable::getParentTransform(bool& success, int depth) const return result; } if (parent) { - result = parent->getTransform(getParentJointIndex(), success, depth + 1); + result = parent->getTransform(_parentJointIndex, success, depth + 1); } return result; } @@ -175,14 +163,6 @@ void SpatiallyNestable::setParentJointIndex(quint16 parentJointIndex) { _parentJointIndex = parentJointIndex; } -void SpatiallyNestable::setParentJointName(const QString& parentJointName) { - _parentJointName = parentJointName; -} - -QString SpatiallyNestable::getParentJointName() const { - return _parentJointName; -} - glm::vec3 SpatiallyNestable::worldToLocal(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success) { diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index cb9e3825b0..37f6cfdfd9 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -47,12 +47,9 @@ public: virtual const QUuid getParentID() const; virtual void setParentID(const QUuid& parentID); - virtual quint16 getParentJointIndex() const; + virtual quint16 getParentJointIndex() const { return _parentJointIndex; } virtual void setParentJointIndex(quint16 parentJointIndex); - virtual QString getParentJointName() const; - virtual void setParentJointName(const QString& parentJointName); - static glm::vec3 worldToLocal(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success); static glm::quat worldToLocal(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success); static glm::vec3 worldToLocalVelocity(const glm::vec3& velocity, const QUuid& parentID, @@ -165,9 +162,6 @@ public: virtual bool setLocalJointRotation(int index, const glm::quat& rotation) { return false; } virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) { return false; } - virtual int getJointIndex(const QString& jointName) const { return -1; } - virtual QString getJointName(int jointIndex) const { return ""; } - SpatiallyNestablePointer getThisPointer() const; using ChildLambda = std::function; @@ -230,7 +224,6 @@ protected: private: QUuid _parentID; // what is this thing's transform relative to? quint16 _parentJointIndex { INVALID_JOINT_INDEX }; // which joint of the parent is this relative to? - QString _parentJointName; mutable ReadWriteLockable _transformLock; mutable ReadWriteLockable _idLock; From c3754d636902cecc55c6f5c6651ec99edca1ca7c Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 20 Nov 2017 23:24:03 +0100 Subject: [PATCH 3/4] smart pointer --- interface/src/Application.cpp | 4 ++-- libraries/entities/src/EntityTree.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0a25a98c43..d22ab8655d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1186,8 +1186,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _entityEditSender.setMyAvatar(myAvatar.get()); // The entity octree will have to know about MyAvatar for the parentJointName import - getEntities()->getTree()->setMyAvatar(myAvatar.get()); - _entityClipboard->setMyAvatar(myAvatar.get()); + getEntities()->getTree()->setMyAvatar(myAvatar); + _entityClipboard->setMyAvatar(myAvatar); // For now we're going to set the PPS for outbound packets to be super high, this is // probably not the right long term solution. But for now, we're going to do this to diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 2dbe05e83b..d8981903d0 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -278,7 +278,7 @@ public: QByteArray computeEncryptedNonce(const QString& certID, const QString ownerKey); bool verifyDecryptedNonce(const QString& certID, const QString& decryptedNonce, EntityItemID& id); - void setMyAvatar(AvatarData* myAvatar) { _myAvatar = myAvatar; } + void setMyAvatar(std::shared_ptr myAvatar) { _myAvatar = myAvatar; } signals: void deletingEntity(const EntityItemID& entityID); @@ -386,7 +386,7 @@ private: void sendChallengeOwnershipRequestPacket(const QByteArray& certID, const QByteArray& encryptedText, const QByteArray& nodeToChallenge, const SharedNodePointer& senderNode); void validatePop(const QString& certID, const EntityItemID& entityItemID, const SharedNodePointer& senderNode, bool isRetryingValidation); - AvatarData* _myAvatar{ nullptr }; + std::shared_ptr _myAvatar{ nullptr }; }; #endif // hifi_EntityTree_h From 627fee80ec5b38f1a11b6ae5d2442890ba2af06d Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 21 Nov 2017 01:49:56 +0100 Subject: [PATCH 4/4] added support for exporting parentJointName --- interface/src/Application.cpp | 1 + libraries/entities/src/EntityTree.cpp | 3 ++- .../src/RecurseOctreeToMapOperator.cpp | 18 ++++++++++++++++-- .../entities/src/RecurseOctreeToMapOperator.h | 3 ++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d22ab8655d..166903c26c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4003,6 +4003,7 @@ bool Application::exportEntities(const QString& filename, auto entityTree = getEntities()->getTree(); auto exportTree = std::make_shared(); + exportTree->setMyAvatar(getMyAvatar()); exportTree->createRootElement(); glm::vec3 root(TREE_SCALE, TREE_SCALE, TREE_SCALE); bool success = true; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 0957bb8444..229269ad21 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -2254,7 +2254,8 @@ bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer entityDescription["Entities"] = QVariantList(); } QScriptEngine scriptEngine; - RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine, skipDefaultValues, skipThoseWithBadParents); + RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine, skipDefaultValues, + skipThoseWithBadParents, _myAvatar); recurseTreeWithOperator(&theOperator); return true; } diff --git a/libraries/entities/src/RecurseOctreeToMapOperator.cpp b/libraries/entities/src/RecurseOctreeToMapOperator.cpp index 217dc0db12..5be921112f 100644 --- a/libraries/entities/src/RecurseOctreeToMapOperator.cpp +++ b/libraries/entities/src/RecurseOctreeToMapOperator.cpp @@ -17,13 +17,15 @@ RecurseOctreeToMapOperator::RecurseOctreeToMapOperator(QVariantMap& map, const OctreeElementPointer& top, QScriptEngine* engine, bool skipDefaultValues, - bool skipThoseWithBadParents) : + bool skipThoseWithBadParents, + std::shared_ptr myAvatar) : RecurseOctreeOperator(), _map(map), _top(top), _engine(engine), _skipDefaultValues(skipDefaultValues), - _skipThoseWithBadParents(skipThoseWithBadParents) + _skipThoseWithBadParents(skipThoseWithBadParents), + _myAvatar(myAvatar) { // if some element "top" was given, only save information for that element and its children. if (_top) { @@ -60,6 +62,18 @@ bool RecurseOctreeToMapOperator::postRecursion(const OctreeElementPointer& eleme } else { qScriptValues = EntityItemPropertiesToScriptValue(_engine, properties); } + + // handle parentJointName for wearables + if (_myAvatar && entityItem->getParentID() == AVATAR_SELF_ID && + entityItem->getParentJointIndex() != INVALID_JOINT_INDEX) { + + auto jointNames = _myAvatar->getJointNames(); + auto parentJointIndex = entityItem->getParentJointIndex(); + if (parentJointIndex < jointNames.count()) { + qScriptValues.setProperty("parentJointName", jointNames.at(parentJointIndex)); + } + } + entitiesQList << qScriptValues.toVariant(); }); diff --git a/libraries/entities/src/RecurseOctreeToMapOperator.h b/libraries/entities/src/RecurseOctreeToMapOperator.h index c661badd88..985ec9de35 100644 --- a/libraries/entities/src/RecurseOctreeToMapOperator.h +++ b/libraries/entities/src/RecurseOctreeToMapOperator.h @@ -14,7 +14,7 @@ class RecurseOctreeToMapOperator : public RecurseOctreeOperator { public: RecurseOctreeToMapOperator(QVariantMap& map, const OctreeElementPointer& top, QScriptEngine* engine, bool skipDefaultValues, - bool skipThoseWithBadParents); + bool skipThoseWithBadParents, std::shared_ptr myAvatar); bool preRecursion(const OctreeElementPointer& element) override; bool postRecursion(const OctreeElementPointer& element) override; private: @@ -24,4 +24,5 @@ public: bool _withinTop; bool _skipDefaultValues; bool _skipThoseWithBadParents; + std::shared_ptr _myAvatar; };