diff --git a/interface/src/avatar/MyAvatarHeadTransformNode.cpp b/interface/src/avatar/MyAvatarHeadTransformNode.cpp index 1e83a17dd3..5dfb101c8c 100644 --- a/interface/src/avatar/MyAvatarHeadTransformNode.cpp +++ b/interface/src/avatar/MyAvatarHeadTransformNode.cpp @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/14/2018 +// Created by Sabrina Shanman 2018/08/14 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -21,4 +21,10 @@ Transform MyAvatarHeadTransformNode::getTransform() { glm::quat ori = headOri * glm::angleAxis(-PI / 2.0f, Vectors::RIGHT); return Transform(ori, scale, pos); -} \ No newline at end of file +} + +QVariantMap MyAvatarHeadTransformNode::toVariantMap() const { + QVariantMap map; + map["joint"] = "Avatar"; + return map; +} diff --git a/interface/src/avatar/MyAvatarHeadTransformNode.h b/interface/src/avatar/MyAvatarHeadTransformNode.h index a7d7144521..b1582508bd 100644 --- a/interface/src/avatar/MyAvatarHeadTransformNode.h +++ b/interface/src/avatar/MyAvatarHeadTransformNode.h @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/14/2018 +// Created by Sabrina Shanman 2018/08/14 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -14,6 +14,7 @@ class MyAvatarHeadTransformNode : public TransformNode { public: MyAvatarHeadTransformNode() { } Transform getTransform() override; + QVariantMap toVariantMap() const override; }; -#endif // hifi_MyAvatarHeadTransformNode_h \ No newline at end of file +#endif // hifi_MyAvatarHeadTransformNode_h diff --git a/interface/src/raypick/CollisionPick.cpp b/interface/src/raypick/CollisionPick.cpp index 83ed61030e..2602bdb0a0 100644 --- a/interface/src/raypick/CollisionPick.cpp +++ b/interface/src/raypick/CollisionPick.cpp @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 7/16/2018 +// Created by Sabrina Shanman 2018/07/16 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -460,4 +460,4 @@ Transform CollisionPick::getResultTransform() const { Transform transform; transform.setTranslation(_mathPick.transform.getTranslation()); return transform; -} \ No newline at end of file +} diff --git a/interface/src/raypick/CollisionPick.h b/interface/src/raypick/CollisionPick.h index c742c089b4..24317bf19a 100644 --- a/interface/src/raypick/CollisionPick.h +++ b/interface/src/raypick/CollisionPick.h @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 7/11/2018 +// Created by Sabrina Shanman 2018/07/11 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -49,6 +49,7 @@ class CollisionPick : public Pick { public: CollisionPick(const PickFilter& filter, float maxDistance, bool enabled, bool scaleWithParent, CollisionRegion collisionRegion, PhysicsEnginePointer physicsEngine); + PickType getType() const override { return PickType::Collision; } CollisionRegion getMathematicalPick() const override; PickResultPointer getDefaultResult(const QVariantMap& pickVariant) const override { return std::make_shared(pickVariant, std::vector(), std::vector()); diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 12daae0351..b97c9b89cb 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -27,6 +27,10 @@ LaserPointer::LaserPointer(const QVariant& rayProps, const RenderStateMap& rende { } +PickQuery::PickType LaserPointer::getType() const { + return PickQuery::PickType::Ray; +} + void LaserPointer::editRenderStatePath(const std::string& state, const QVariant& pathProps) { auto renderState = std::static_pointer_cast(_renderStates[state]); if (renderState) { @@ -47,7 +51,7 @@ PickResultPointer LaserPointer::getPickResultCopy(const PickResultPointer& pickR } QVariantMap LaserPointer::toVariantMap() const { - QVariantMap qVariantMap; + QVariantMap qVariantMap = Parent::toVariantMap(); QVariantMap qRenderStates; for (auto iter = _renderStates.cbegin(); iter != _renderStates.cend(); iter++) { diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index 13d108baee..330449a52d 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -42,6 +42,8 @@ public: LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithParent, bool enabled); + PickQuery::PickType getType() const override; + QVariantMap toVariantMap() const override; static std::shared_ptr buildRenderState(const QVariantMap& propMap); diff --git a/interface/src/raypick/LaserPointerScriptingInterface.cpp b/interface/src/raypick/LaserPointerScriptingInterface.cpp index 25720b5f9d..16fe65a989 100644 --- a/interface/src/raypick/LaserPointerScriptingInterface.cpp +++ b/interface/src/raypick/LaserPointerScriptingInterface.cpp @@ -23,7 +23,7 @@ void LaserPointerScriptingInterface::setIncludeItems(unsigned int uid, const QSc } unsigned int LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) const { - return DependencyManager::get()->createLaserPointer(properties); + return DependencyManager::get()->createPointer(PickQuery::PickType::Ray, properties); } void LaserPointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) const { diff --git a/interface/src/raypick/MouseTransformNode.cpp b/interface/src/raypick/MouseTransformNode.cpp index 9caa4865a2..61af0646e1 100644 --- a/interface/src/raypick/MouseTransformNode.cpp +++ b/interface/src/raypick/MouseTransformNode.cpp @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/14/2018 +// Created by Sabrina Shanman 2018/08/14 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -24,4 +24,10 @@ Transform MouseTransformNode::getTransform() { } return Transform(); -} \ No newline at end of file +} + +QVariantMap MouseTransformNode::toVariantMap() const { + QVariantMap map; + map["joint"] = "Mouse"; + return map; +} diff --git a/interface/src/raypick/MouseTransformNode.h b/interface/src/raypick/MouseTransformNode.h index 4f340339e4..37d773e805 100644 --- a/interface/src/raypick/MouseTransformNode.h +++ b/interface/src/raypick/MouseTransformNode.h @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/14/2018 +// Created by Sabrina Shanman 2018/08/14 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -13,6 +13,7 @@ class MouseTransformNode : public TransformNode { public: Transform getTransform() override; + QVariantMap toVariantMap() const override; }; -#endif // hifi_MouseTransformNode_h \ No newline at end of file +#endif // hifi_MouseTransformNode_h diff --git a/interface/src/raypick/ParabolaPick.h b/interface/src/raypick/ParabolaPick.h index 1175b2b246..0d720914cc 100644 --- a/interface/src/raypick/ParabolaPick.h +++ b/interface/src/raypick/ParabolaPick.h @@ -92,6 +92,8 @@ class ParabolaPick : public Pick { public: ParabolaPick(const glm::vec3& position, const glm::vec3& direction, float speed, const glm::vec3& acceleration, bool rotateAccelerationWithAvatar, bool rotateAccelerationWithParent, bool scaleWithParent, const PickFilter& filter, float maxDistance, bool enabled); + PickType getType() const override { return PickType::Parabola; } + PickParabola getMathematicalPick() const override; PickResultPointer getDefaultResult(const QVariantMap& pickVariant) const override { return std::make_shared(pickVariant); } diff --git a/interface/src/raypick/ParabolaPointer.cpp b/interface/src/raypick/ParabolaPointer.cpp index 0589124db8..216248f8b5 100644 --- a/interface/src/raypick/ParabolaPointer.cpp +++ b/interface/src/raypick/ParabolaPointer.cpp @@ -30,6 +30,10 @@ ParabolaPointer::ParabolaPointer(const QVariant& rayProps, const RenderStateMap& { } +PickQuery::PickType ParabolaPointer::getType() const { + return PickQuery::PickType::Parabola; +} + PickResultPointer ParabolaPointer::getPickResultCopy(const PickResultPointer& pickResult) const { auto parabolaPickResult = std::dynamic_pointer_cast(pickResult); if (!parabolaPickResult) { @@ -72,7 +76,7 @@ void ParabolaPointer::editRenderStatePath(const std::string& state, const QVaria } QVariantMap ParabolaPointer::toVariantMap() const { - QVariantMap qVariantMap; + QVariantMap qVariantMap = Parent::toVariantMap(); QVariantMap qRenderStates; for (auto iter = _renderStates.cbegin(); iter != _renderStates.cend(); iter++) { diff --git a/interface/src/raypick/ParabolaPointer.h b/interface/src/raypick/ParabolaPointer.h index 94470971e6..85d09adbdb 100644 --- a/interface/src/raypick/ParabolaPointer.h +++ b/interface/src/raypick/ParabolaPointer.h @@ -101,6 +101,8 @@ public: ParabolaPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled); + PickQuery::PickType getType() const override; + QVariantMap toVariantMap() const override; static std::shared_ptr buildRenderState(const QVariantMap& propMap); diff --git a/interface/src/raypick/PickScriptingInterface.cpp b/interface/src/raypick/PickScriptingInterface.cpp index 12f68c1430..ddc1fe376c 100644 --- a/interface/src/raypick/PickScriptingInterface.cpp +++ b/interface/src/raypick/PickScriptingInterface.cpp @@ -34,18 +34,35 @@ static const float WEB_TOUCH_Y_OFFSET = 0.105f; // how far forward (or back wit static const glm::vec3 TIP_OFFSET = glm::vec3(0.0f, StylusPick::WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, 0.0f); unsigned int PickScriptingInterface::createPick(const PickQuery::PickType type, const QVariant& properties) { + std::shared_ptr pick; + QVariantMap propMap = properties.toMap(); + switch (type) { case PickQuery::PickType::Ray: - return createRayPick(properties); + pick = buildRayPick(propMap); + break; case PickQuery::PickType::Stylus: - return createStylusPick(properties); + pick = buildStylusPick(propMap); + break; case PickQuery::PickType::Parabola: - return createParabolaPick(properties); + pick = buildParabolaPick(propMap); + break; case PickQuery::PickType::Collision: - return createCollisionPick(properties); + pick = buildCollisionPick(propMap); + break; default: - return PickManager::INVALID_PICK_ID; + break; } + + if (!pick) { + return PickManager::INVALID_PICK_ID; + } + + propMap["pickType"] = (int)type; + + pick->setScriptParameters(propMap); + + return DependencyManager::get()->addPick(type, pick); } PickFilter getPickFilter(unsigned int filter) { @@ -82,17 +99,18 @@ PickFilter getPickFilter(unsigned int filter) { * @property {Vec3} [dirOffset] - Synonym for direction. * @property {Quat} [orientation] - Alternative property for specifying direction. The value is applied to the * default direction value. + * @property {PickType} pickType - The type of pick when getting these properties from {@link Picks.getPickProperties} or {@link Picks.getPickScriptParameters}. A ray pick's type is {@link PickType.Ray}. + * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity). + * Its value is the original scale of the parent at the moment the pick was created, and is used to scale the pointer which owns this pick, if any. */ -unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { - QVariantMap propMap = properties.toMap(); - +std::shared_ptr PickScriptingInterface::buildRayPick(const QVariantMap& propMap) { #if defined (Q_OS_ANDROID) QString jointName { "" }; if (propMap["joint"].isValid()) { QString jointName = propMap["joint"].toString(); const QString MOUSE_JOINT = "Mouse"; if (jointName == MOUSE_JOINT) { - return PointerEvent::INVALID_POINTER_ID; + return nullptr; } } #endif @@ -134,7 +152,7 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { auto rayPick = std::make_shared(position, direction, filter, maxDistance, enabled); setParentTransform(rayPick, propMap); - return DependencyManager::get()->addPick(PickQuery::Ray, rayPick); + return rayPick; } /**jsdoc @@ -152,10 +170,9 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { * means no maximum. * @property {Vec3} [tipOffset=0,0.095,0] - The position of the stylus tip relative to the hand position at default avatar * scale. + * @property {PickType} pickType - The type of pick when getting these properties from {@link Picks.getPickProperties} or {@link Picks.getPickScriptParameters}. A stylus pick's type is {@link PickType.Stylus}. */ -unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties) { - QVariantMap propMap = properties.toMap(); - +std::shared_ptr PickScriptingInterface::buildStylusPick(const QVariantMap& propMap) { bilateral::Side side = bilateral::Side::Invalid; { QVariant handVar = propMap["hand"]; @@ -184,7 +201,7 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties tipOffset = vec3FromVariant(propMap["tipOffset"]); } - return DependencyManager::get()->addPick(PickQuery::Stylus, std::make_shared(side, filter, maxDistance, enabled, tipOffset)); + return std::make_shared(side, filter, maxDistance, enabled, tipOffset); } // NOTE: Laser pointer still uses scaleWithAvatar. Until scaleWithAvatar is also deprecated for pointers, scaleWithAvatar should not be removed from the pick API. @@ -228,10 +245,11 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties * with the avatar or other parent. * @property {boolean} [scaleWithAvatar=true] - Synonym for scalewithParent. *

Deprecated: This property is deprecated and will be removed.

+ * @property {PickType} pickType - The type of pick when getting these properties from {@link Picks.getPickProperties} or {@link Picks.getPickScriptParameters}. A parabola pick's type is {@link PickType.Parabola}. + * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity). + * Its value is the original scale of the parent at the moment the pick was created, and is used to rescale the pick, and/or the pointer which owns this pick, if any. */ -unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properties) { - QVariantMap propMap = properties.toMap(); - +std::shared_ptr PickScriptingInterface::buildParabolaPick(const QVariantMap& propMap) { bool enabled = false; if (propMap["enabled"].isValid()) { enabled = propMap["enabled"].toBool(); @@ -292,7 +310,7 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti auto parabolaPick = std::make_shared(position, direction, speed, accelerationAxis, rotateAccelerationWithAvatar, rotateAccelerationWithParent, scaleWithParent, filter, maxDistance, enabled); setParentTransform(parabolaPick, propMap); - return DependencyManager::get()->addPick(PickQuery::Parabola, parabolaPick); + return parabolaPick; } @@ -326,10 +344,11 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti * the collision region. The depth is in world coordinates but scales with the parent if defined. * @property {CollisionMask} [collisionGroup=8] - The type of objects the collision region collides as. Objects whose collision * masks overlap with the region's collision group are considered to be colliding with the region. + * @property {PickType} pickType - The type of pick when getting these properties from {@link Picks.getPickProperties} or {@link Picks.getPickScriptParameters}. A collision pick's type is {@link PickType.Collision}. + * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity). + * Its value is the original scale of the parent at the moment the pick was created, and is used to rescale the pick, and/or the pointer which owns this pick, if any. */ -unsigned int PickScriptingInterface::createCollisionPick(const QVariant& properties) { - QVariantMap propMap = properties.toMap(); - +std::shared_ptr PickScriptingInterface::buildCollisionPick(const QVariantMap& propMap) { bool enabled = false; if (propMap["enabled"].isValid()) { enabled = propMap["enabled"].toBool(); @@ -354,7 +373,7 @@ unsigned int PickScriptingInterface::createCollisionPick(const QVariant& propert auto collisionPick = std::make_shared(filter, maxDistance, enabled, scaleWithParent, collisionRegion, qApp->getPhysicsEngine()); setParentTransform(collisionPick, propMap); - return DependencyManager::get()->addPick(PickQuery::Collision, collisionPick); + return collisionPick; } void PickScriptingInterface::enablePick(unsigned int uid) { @@ -365,10 +384,26 @@ void PickScriptingInterface::disablePick(unsigned int uid) { DependencyManager::get()->disablePick(uid); } +bool PickScriptingInterface::isPickEnabled(unsigned int uid) const { + return DependencyManager::get()->isPickEnabled(uid); +} + void PickScriptingInterface::removePick(unsigned int uid) { DependencyManager::get()->removePick(uid); } +QVariantMap PickScriptingInterface::getPickProperties(unsigned int uid) const { + return DependencyManager::get()->getPickProperties(uid); +} + +QVariantMap PickScriptingInterface::getPickScriptParameters(unsigned int uid) const { + return DependencyManager::get()->getPickScriptParameters(uid); +} + +QVector PickScriptingInterface::getPicks() const { + return DependencyManager::get()->getPicks(); +} + QVariantMap PickScriptingInterface::getPrevPickResult(unsigned int uid) { QVariantMap result; auto pickResult = DependencyManager::get()->getPrevPickResult(uid); diff --git a/interface/src/raypick/PickScriptingInterface.h b/interface/src/raypick/PickScriptingInterface.h index 473413ca58..72b28bbc47 100644 --- a/interface/src/raypick/PickScriptingInterface.h +++ b/interface/src/raypick/PickScriptingInterface.h @@ -10,7 +10,6 @@ #include -#include #include #include #include @@ -98,11 +97,6 @@ class PickScriptingInterface : public QObject, public Dependency { SINGLETON_DEPENDENCY public: - unsigned int createRayPick(const QVariant& properties); - unsigned int createStylusPick(const QVariant& properties); - unsigned int createCollisionPick(const QVariant& properties); - unsigned int createParabolaPick(const QVariant& properties); - void registerMetaTypes(QScriptEngine* engine); /**jsdoc @@ -134,6 +128,14 @@ public: */ Q_INVOKABLE void disablePick(unsigned int uid); + /**jsdoc + * Get the enabled status of a pick. Enabled picks update their pick results. + * @function Picks.isPickEnabled + * @param {number} id - The ID of the pick. + * @returns {boolean} enabled - Whether or not the pick is enabled. + */ + Q_INVOKABLE bool isPickEnabled(unsigned int uid) const; + /**jsdoc * Removes (deletes) a pick. * @function Picks.removePick @@ -141,6 +143,32 @@ public: */ Q_INVOKABLE void removePick(unsigned int uid); + /**jsdoc + * Gets the current properties of the pick. + * @function Picks.getPickProperties + * @param {number} id - The ID of the pick. + * @returns {Picks.RayPickProperties|Picks.ParabolaPickProperties|Picks.StylusPickProperties|Picks.CollisionPickProperties} Properties of the pick, per the pick type. + */ + Q_INVOKABLE QVariantMap getPickProperties(unsigned int uid) const; + + /**jsdoc + * Gets the parameters that were passed in to {@link Picks.createPick} to create the pick, + * if the pick was created through a script. + * Note that these properties do not reflect the current state of the pick. + * See {@link Picks.getPickProperties}. + * @function Picks.getPickScriptParameters + * @param {number} id - The ID of the pick. + * @returns {Picks.RayPickProperties|Picks.ParabolaPickProperties|Picks.StylusPickProperties|Picks.CollisionPickProperties} User-provided properties, per the pick type. + */ + Q_INVOKABLE QVariantMap getPickScriptParameters(unsigned int uid) const; + + /**jsdoc + * Gets all picks which currently exist, including disabled picks. + * @function Picks.getPicks + * @returns {number[]} picks - The IDs of the picks. + */ + Q_INVOKABLE QVector getPicks() const; + /**jsdoc * Gets the most recent result from a pick. A pick continues to be updated ready to return a result, as long as it is * enabled. @@ -419,6 +447,11 @@ public slots: static constexpr unsigned int INTERSECTED_HUD() { return IntersectionType::HUD; } protected: + static std::shared_ptr buildRayPick(const QVariantMap& properties); + static std::shared_ptr buildStylusPick(const QVariantMap& properties); + static std::shared_ptr buildCollisionPick(const QVariantMap& properties); + static std::shared_ptr buildParabolaPick(const QVariantMap& properties); + static void setParentTransform(std::shared_ptr pick, const QVariantMap& propMap); }; diff --git a/interface/src/raypick/PointerScriptingInterface.cpp b/interface/src/raypick/PointerScriptingInterface.cpp index f1dcf7bd5d..3520aacbd0 100644 --- a/interface/src/raypick/PointerScriptingInterface.cpp +++ b/interface/src/raypick/PointerScriptingInterface.cpp @@ -13,6 +13,7 @@ #include #include "Application.h" +#include "PickManager.h" #include "LaserPointer.h" #include "StylusPointer.h" #include "ParabolaPointer.h" @@ -38,16 +39,48 @@ unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& return result; } + QVariantMap propertyMap = properties.toMap(); + + std::shared_ptr pointer; switch (type) { case PickQuery::PickType::Ray: - return createLaserPointer(properties); + pointer = buildLaserPointer(propertyMap); + break; case PickQuery::PickType::Stylus: - return createStylus(properties); + pointer = buildStylus(propertyMap); + break; case PickQuery::PickType::Parabola: - return createParabolaPointer(properties); + pointer = buildParabolaPointer(propertyMap); + break; default: - return PointerEvent::INVALID_POINTER_ID; + break; } + + if (!pointer) { + return PointerEvent::INVALID_POINTER_ID; + } + + propertyMap["pointerType"] = (int)type; + + pointer->setScriptParameters(propertyMap); + + return DependencyManager::get()->addPointer(pointer); +} + +bool PointerScriptingInterface::isPointerEnabled(unsigned int uid) const { + return DependencyManager::get()->isPointerEnabled(uid); +} + +QVector PointerScriptingInterface::getPointers() const { + return DependencyManager::get()->getPointers(); +} + +QVariantMap PointerScriptingInterface::getPointerProperties(unsigned int uid) const { + return DependencyManager::get()->getPointerProperties(uid); +} + +QVariantMap PointerScriptingInterface::getPointerScriptParameters(unsigned int uid) const { + return DependencyManager::get()->getPointerScriptParameters(uid); } /**jsdoc @@ -56,6 +89,8 @@ unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& * @property {Pointers.StylusPointerModel} [model] - Override some or all of the default stylus model properties. * @property {boolean} [hover=false] - true if the pointer generates {@link Entities} hover events, * false if it doesn't. + * @property {PickType} pointerType - The type of pointer when getting these properties from {@link Pointers.getPointerProperties} or {@link Pointers.getPointerScriptParameters}. A stylus pointer's type is {@link PickType.Stylus}. + * @property {number} [pickID] - Returned from {@link Pointers.getPointerProperties}. The ID of the pick created alongside this pointer. * @see {@link Picks.StylusPickProperties} for additional properties from the underlying stylus pick. */ /**jsdoc @@ -67,7 +102,7 @@ unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& * offset. * @property {Quat} [rotationOffset] - The rotation offset of the model from the hand, to override the default rotation offset. */ -unsigned int PointerScriptingInterface::createStylus(const QVariant& properties) const { +std::shared_ptr PointerScriptingInterface::buildStylus(const QVariant& properties) { QVariantMap propertyMap = properties.toMap(); bool hover = false; @@ -100,8 +135,7 @@ unsigned int PointerScriptingInterface::createStylus(const QVariant& properties) } } - return DependencyManager::get()->addPointer(std::make_shared(properties, StylusPointer::buildStylus(propertyMap), hover, enabled, modelPositionOffset, - modelRotationOffset, modelDimensions)); + return std::make_shared(properties, StylusPointer::buildStylus(propertyMap), hover, enabled, modelPositionOffset, modelRotationOffset, modelDimensions); } /**jsdoc @@ -174,9 +208,11 @@ unsigned int PointerScriptingInterface::createStylus(const QVariant& properties) * false if it doesn't. * @property {Pointers.Trigger[]} [triggers=[]] - A list of ways that a {@link Controller} action or function should trigger * events on the entity or overlay currently intersected. + * @property {PickType} pointerType - The type of pointer when getting these properties from {@link Pointers.getPointerProperties} or {@link Pointers.getPointerScriptParameters}. A laser pointer's type is {@link PickType.Ray}. + * @property {number} [pickID] - Returned from {@link Pointers.getPointerProperties}. The ID of the pick created alongside this pointer. * @see {@link Picks.RayPickProperties} for additional properties from the underlying ray pick. */ -unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& properties) const { +std::shared_ptr PointerScriptingInterface::buildLaserPointer(const QVariant& properties) { QVariantMap propertyMap = properties.toMap(); #if defined (Q_OS_ANDROID) @@ -185,7 +221,7 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope QString jointName = propertyMap["joint"].toString(); const QString MOUSE_JOINT = "Mouse"; if (jointName == MOUSE_JOINT) { - return PointerEvent::INVALID_POINTER_ID; + return nullptr; } } #endif @@ -283,9 +319,9 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope } } - return DependencyManager::get()->addPointer(std::make_shared(properties, renderStates, defaultRenderStates, hover, triggers, - faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, - distanceScaleEnd, scaleWithParent, enabled)); + return std::make_shared(properties, renderStates, defaultRenderStates, hover, triggers, + faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, + distanceScaleEnd, scaleWithParent, enabled); } /**jsdoc @@ -365,9 +401,11 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope * false if it doesn't. * @property {Pointers.Trigger[]} [triggers=[]] - A list of ways that a {@link Controller} action or function should trigger * events on the entity or overlay currently intersected. + * @property {PickType} pointerType - The type of pointer when getting these properties from {@link Pointers.getPointerProperties} or {@link Pointers.getPointerScriptParameters}. A parabola pointer's type is {@link PickType.Parabola}. + * @property {number} [pickID] - Returned from {@link Pointers.getPointerProperties}. The ID of the pick created alongside this pointer. * @see {@link Picks.ParabolaPickProperties} for additional properties from the underlying parabola pick. */ -unsigned int PointerScriptingInterface::createParabolaPointer(const QVariant& properties) const { +std::shared_ptr PointerScriptingInterface::buildParabolaPointer(const QVariant& properties) { QVariantMap propertyMap = properties.toMap(); bool faceAvatar = false; @@ -463,9 +501,9 @@ unsigned int PointerScriptingInterface::createParabolaPointer(const QVariant& pr } } - return DependencyManager::get()->addPointer(std::make_shared(properties, renderStates, defaultRenderStates, hover, triggers, - faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, distanceScaleEnd, - scaleWithParent, enabled)); + return std::make_shared(properties, renderStates, defaultRenderStates, hover, triggers, + faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, distanceScaleEnd, + scaleWithParent, enabled); } void PointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) const { @@ -497,7 +535,3 @@ QVariantMap PointerScriptingInterface::getPrevPickResult(unsigned int uid) const } return result; } - -QVariantMap PointerScriptingInterface::getPointerProperties(unsigned int uid) const { - return DependencyManager::get()->getPointerProperties(uid); -} diff --git a/interface/src/raypick/PointerScriptingInterface.h b/interface/src/raypick/PointerScriptingInterface.h index e6efaae09f..0eed8b4741 100644 --- a/interface/src/raypick/PointerScriptingInterface.h +++ b/interface/src/raypick/PointerScriptingInterface.h @@ -11,6 +11,7 @@ #include #include "DependencyManager.h" +#include "RegisteredMetaTypes.h" #include #include @@ -31,9 +32,6 @@ class PointerScriptingInterface : public QObject, public Dependency { SINGLETON_DEPENDENCY public: - unsigned int createLaserPointer(const QVariant& properties) const; - unsigned int createStylus(const QVariant& properties) const; - unsigned int createParabolaPointer(const QVariant& properties) const; /**jsdoc * Specifies that a {@link Controller} action or function should trigger events on the entity or overlay currently @@ -147,6 +145,14 @@ public: */ Q_INVOKABLE void disablePointer(unsigned int uid) const { DependencyManager::get()->disablePointer(uid); } + /**jsdoc + * Gets the enabled status of a pointer. Enabled pointers update their pick results and generate events. + * @function Pointers.isPointerEnabled + * @param {number} id - The ID of the pointer. + * @returns {boolean} enabled - Whether or not the pointer is enabled. + */ + Q_INVOKABLE bool isPointerEnabled(unsigned int uid) const; + /**jsdoc * Removes (deletes) a pointer. * @function Pointers.removePointer @@ -154,6 +160,24 @@ public: */ Q_INVOKABLE void removePointer(unsigned int uid) const { DependencyManager::get()->removePointer(uid); } + /**jsdoc + * Gets the parameters that were passed in to {@link Pointers.createPointer} to create the pointer, + * if the pointer was created through a script. + * Note that these properties do not reflect the current state of the pointer. + * See {@link Pointers.getPointerProperties}. + * @function Pointers.getPointerScriptParameters + * @param {number} id - The ID of the pointer. + * @returns {Pointers.RayPointerProperties|Picks.ParabolaPointerProperties|Picks.StylusPointerProperties} User-provided properties, per the pointer type. + */ + Q_INVOKABLE QVariantMap getPointerScriptParameters(unsigned int uid) const; + + /**jsdoc + * Gets all pointers which currently exist, including disabled pointers. + * @function Pointers.getPointers + * @returns {number[]} pointers - The IDs of the pointers. + */ + Q_INVOKABLE QVector getPointers() const; + /**jsdoc * Edits a render state of a {@link Pointers.RayPointerProperties|ray} or * {@link Pointers.ParabolaPointerProperties|parabola} pointer, to change its visual appearance for the state when the @@ -448,6 +472,11 @@ public: * }); */ Q_INVOKABLE QVariantMap getPointerProperties(unsigned int uid) const; + +protected: + static std::shared_ptr buildLaserPointer(const QVariant& properties); + static std::shared_ptr buildStylus(const QVariant& properties); + static std::shared_ptr buildParabolaPointer(const QVariant& properties); }; #endif // hifi_PointerScriptingInterface_h diff --git a/interface/src/raypick/RayPick.h b/interface/src/raypick/RayPick.h index 170a0489da..3bd82f4194 100644 --- a/interface/src/raypick/RayPick.h +++ b/interface/src/raypick/RayPick.h @@ -88,6 +88,8 @@ public: Pick(PickRay(position, direction), filter, maxDistance, enabled) { } + PickType getType() const override { return PickType::Ray; } + PickRay getMathematicalPick() const override; PickResultPointer getDefaultResult(const QVariantMap& pickVariant) const override { return std::make_shared(pickVariant); } diff --git a/interface/src/raypick/RayPickScriptingInterface.cpp b/interface/src/raypick/RayPickScriptingInterface.cpp index 247368df51..a837121e6a 100644 --- a/interface/src/raypick/RayPickScriptingInterface.cpp +++ b/interface/src/raypick/RayPickScriptingInterface.cpp @@ -17,7 +17,7 @@ #include unsigned int RayPickScriptingInterface::createRayPick(const QVariant& properties) { - return DependencyManager::get()->createRayPick(properties); + return DependencyManager::get()->createPick(PickQuery::PickType::Ray, properties); } void RayPickScriptingInterface::enableRayPick(unsigned int uid) { diff --git a/interface/src/raypick/StylusPick.h b/interface/src/raypick/StylusPick.h index e443fb1c6d..27514efefa 100644 --- a/interface/src/raypick/StylusPick.h +++ b/interface/src/raypick/StylusPick.h @@ -72,6 +72,7 @@ class StylusPick : public Pick { public: StylusPick(Side side, const PickFilter& filter, float maxDistance, bool enabled, const glm::vec3& tipOffset); + PickType getType() const override { return PickType::Stylus; } StylusTip getMathematicalPick() const override; PickResultPointer getDefaultResult(const QVariantMap& pickVariant) const override; PickResultPointer getEntityIntersection(const StylusTip& pick) override; diff --git a/interface/src/raypick/StylusPointer.cpp b/interface/src/raypick/StylusPointer.cpp index 3cdcb9c3a5..48b61e9a2a 100644 --- a/interface/src/raypick/StylusPointer.cpp +++ b/interface/src/raypick/StylusPointer.cpp @@ -29,7 +29,7 @@ static const QString DEFAULT_STYLUS_MODEL_URL = PathUtils::resourcesUrl() + "/me StylusPointer::StylusPointer(const QVariant& props, const QUuid& stylus, bool hover, bool enabled, const glm::vec3& modelPositionOffset, const glm::quat& modelRotationOffset, const glm::vec3& modelDimensions) : - Pointer(DependencyManager::get()->createStylusPick(props), enabled, hover), + Pointer(DependencyManager::get()->createPick(PickQuery::PickType::Stylus, props), enabled, hover), _stylus(stylus), _modelPositionOffset(modelPositionOffset), _modelDimensions(modelDimensions), @@ -43,6 +43,10 @@ StylusPointer::~StylusPointer() { } } +PickQuery::PickType StylusPointer::getType() const { + return PickQuery::PickType::Stylus; +} + QUuid StylusPointer::buildStylus(const QVariantMap& properties) { // FIXME: we have to keep using the Overlays interface here, because existing scripts use overlay properties to define pointers QVariantMap propertiesMap; @@ -229,7 +233,7 @@ void StylusPointer::setRenderState(const std::string& state) { } QVariantMap StylusPointer::toVariantMap() const { - return QVariantMap(); + return Parent::toVariantMap(); } glm::vec3 StylusPointer::findIntersection(const PickedObject& pickedObject, const glm::vec3& origin, const glm::vec3& direction) { diff --git a/interface/src/raypick/StylusPointer.h b/interface/src/raypick/StylusPointer.h index 7d43df2379..41ac17e598 100644 --- a/interface/src/raypick/StylusPointer.h +++ b/interface/src/raypick/StylusPointer.h @@ -23,6 +23,8 @@ public: const glm::vec3& modelPositionOffset, const glm::quat& modelRotationOffset, const glm::vec3& modelDimensions); ~StylusPointer(); + PickQuery::PickType getType() const override; + void updateVisuals(const PickResultPointer& pickResult) override; // Styluses have three render states: diff --git a/libraries/avatars-renderer/src/avatars-renderer/AvatarTransformNode.cpp b/libraries/avatars-renderer/src/avatars-renderer/AvatarTransformNode.cpp index ca3d4a6062..5770e85e8d 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/AvatarTransformNode.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/AvatarTransformNode.cpp @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 9/5/2018 +// Created by Sabrina Shanman 2018/09/05 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -10,4 +10,4 @@ template<> glm::vec3 BaseNestableTransformNode::getActualScale(const std::shared_ptr& nestablePointer) const { return nestablePointer->scaleForChildren(); -} \ No newline at end of file +} diff --git a/libraries/avatars-renderer/src/avatars-renderer/AvatarTransformNode.h b/libraries/avatars-renderer/src/avatars-renderer/AvatarTransformNode.h index 183e4ab05c..fcbe63d5ca 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/AvatarTransformNode.h +++ b/libraries/avatars-renderer/src/avatars-renderer/AvatarTransformNode.h @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 9/5/2018 +// Created by Sabrina Shanman 2018/09/05 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -17,4 +17,4 @@ public: AvatarTransformNode(std::weak_ptr spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {}; }; -#endif // hifi_AvatarTransformNode_h \ No newline at end of file +#endif // hifi_AvatarTransformNode_h diff --git a/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp b/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp index 404e2d3ac6..45f8461a1a 100644 --- a/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp +++ b/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp @@ -297,10 +297,6 @@ MeshPointer GraphicsScriptingInterface::getMeshPointer(scriptable::ScriptableMes namespace { QVector metaTypeIds{ - qRegisterMetaType("uint32"), - qRegisterMetaType("glm::uint32"), - qRegisterMetaType>(), - qRegisterMetaType>("QVector"), qRegisterMetaType(), qRegisterMetaType("ScriptableMeshes"), qRegisterMetaType("scriptable::ScriptableMeshes"), @@ -532,7 +528,6 @@ namespace scriptable { } void GraphicsScriptingInterface::registerMetaTypes(QScriptEngine* engine) { - qScriptRegisterSequenceMetaType>(engine); qScriptRegisterSequenceMetaType>(engine); scriptable::registerQPointerMetaType(engine); diff --git a/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.h b/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.h index 267ba01041..808d3f221f 100644 --- a/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.h +++ b/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.h @@ -19,6 +19,7 @@ #include "ScriptableMesh.h" #include +#include "RegisteredMetaTypes.h" /**jsdoc @@ -107,8 +108,6 @@ namespace scriptable { QScriptValue scriptableMaterialToScriptValue(QScriptEngine* engine, const scriptable::ScriptableMaterial &material); }; -Q_DECLARE_METATYPE(glm::uint32) -Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(NestableType) #endif // hifi_GraphicsScriptingInterface_h diff --git a/libraries/pointers/src/Pick.cpp b/libraries/pointers/src/Pick.cpp index e95721c04b..f6877d40ef 100644 --- a/libraries/pointers/src/Pick.cpp +++ b/libraries/pointers/src/Pick.cpp @@ -56,6 +56,14 @@ QVector PickQuery::getIgnoreItems() const { }); } +void PickQuery::setScriptParameters(const QVariantMap& parameters) { + _scriptParameters = parameters; +} + +QVariantMap PickQuery::getScriptParameters() const { + return _scriptParameters; +} + QVector PickQuery::getIncludeItems() const { return resultWithReadLock>([&] { return _includeItems; diff --git a/libraries/pointers/src/Pick.h b/libraries/pointers/src/Pick.h index 4adb571a5a..e4257140fd 100644 --- a/libraries/pointers/src/Pick.h +++ b/libraries/pointers/src/Pick.h @@ -117,7 +117,8 @@ public: Stylus, Parabola, Collision, - NUM_PICK_TYPES + NUM_PICK_TYPES, + INVALID_PICK_TYPE = -1 }; Q_ENUM(PickType) @@ -134,6 +135,7 @@ public: PickFilter getFilter() const; float getMaxDistance() const; bool isEnabled() const; + virtual PickType getType() const = 0; void setPrecisionPicking(bool precisionPicking); @@ -168,6 +170,27 @@ public: void setIgnoreItems(const QVector& items); void setIncludeItems(const QVector& items); + virtual QVariantMap toVariantMap() const { + QVariantMap properties; + + properties["pickType"] = (int)getType(); + properties["enabled"] = isEnabled(); + properties["filter"] = (unsigned int)getFilter()._flags.to_ulong(); + properties["maxDistance"] = getMaxDistance(); + + if (parentTransform) { + auto transformNodeProperties = parentTransform->toVariantMap(); + for (auto it = transformNodeProperties.cbegin(); it != transformNodeProperties.cend(); ++it) { + properties[it.key()] = it.value(); + } + } + + return properties; + } + + void setScriptParameters(const QVariantMap& parameters); + QVariantMap getScriptParameters() const; + virtual bool isLeftHand() const { return _jointState == JOINT_STATE_LEFT_HAND; } virtual bool isRightHand() const { return _jointState == JOINT_STATE_RIGHT_HAND; } virtual bool isMouse() const { return _jointState == JOINT_STATE_MOUSE; } @@ -187,6 +210,9 @@ private: QVector _ignoreItems; QVector _includeItems; + // The parameters used to create this pick when created through a script + QVariantMap _scriptParameters; + JointState _jointState { JOINT_STATE_NONE }; }; Q_DECLARE_METATYPE(PickQuery::PickType) @@ -202,6 +228,17 @@ public: virtual PickResultPointer getAvatarIntersection(const T& pick) = 0; virtual PickResultPointer getHUDIntersection(const T& pick) = 0; + QVariantMap toVariantMap() const override { + QVariantMap properties = PickQuery::toVariantMap(); + + const QVariantMap mathPickProperties = _mathPick.toVariantMap(); + for (auto it = mathPickProperties.cbegin(); it != mathPickProperties.cend(); ++it) { + properties[it.key()] = it.value(); + } + + return properties; + } + protected: T _mathPick; }; diff --git a/libraries/pointers/src/PickManager.cpp b/libraries/pointers/src/PickManager.cpp index aadfbc41a0..cad44b1864 100644 --- a/libraries/pointers/src/PickManager.cpp +++ b/libraries/pointers/src/PickManager.cpp @@ -49,6 +49,35 @@ void PickManager::removePick(unsigned int uid) { }); } +QVariantMap PickManager::getPickProperties(unsigned int uid) const { + auto pick = findPick(uid); + if (pick) { + return pick->toVariantMap(); + } + return QVariantMap(); +} + +QVariantMap PickManager::getPickScriptParameters(unsigned int uid) const { + auto pick = findPick(uid); + if (pick) { + return pick->getScriptParameters(); + } + return QVariantMap(); +} + +QVector PickManager::getPicks() const { + QVector picks; + withReadLock([&] { + for (auto typeIt = _picks.cbegin(); typeIt != _picks.cend(); ++typeIt) { + auto& picksForType = typeIt->second; + for (auto pickIt = picksForType.cbegin(); pickIt != picksForType.cend(); ++pickIt) { + picks.push_back(pickIt->first); + } + } + }); + return picks; +} + PickResultPointer PickManager::getPrevPickResult(unsigned int uid) const { auto pick = findPick(uid); if (pick) { @@ -71,6 +100,14 @@ void PickManager::disablePick(unsigned int uid) const { } } +bool PickManager::isPickEnabled(unsigned int uid) const { + auto pick = findPick(uid); + if (pick) { + return pick->isEnabled(); + } + return false; +} + void PickManager::setPrecisionPicking(unsigned int uid, bool precisionPicking) const { auto pick = findPick(uid); if (pick) { diff --git a/libraries/pointers/src/PickManager.h b/libraries/pointers/src/PickManager.h index 8f5aa5caf8..79ab6ca2c8 100644 --- a/libraries/pointers/src/PickManager.h +++ b/libraries/pointers/src/PickManager.h @@ -31,8 +31,14 @@ public: void removePick(unsigned int uid); void enablePick(unsigned int uid) const; void disablePick(unsigned int uid) const; + bool isPickEnabled(unsigned int uid) const; + QVector getPicks() const; PickResultPointer getPrevPickResult(unsigned int uid) const; + // The actual current properties of the pick + QVariantMap getPickProperties(unsigned int uid) const; + // The properties that were passed in to create the pick (may be empty if the pick was created by invoking the constructor) + QVariantMap getPickScriptParameters(unsigned int uid) const; template std::shared_ptr getPrevPickResultTyped(unsigned int uid) const { diff --git a/libraries/pointers/src/PickTransformNode.cpp b/libraries/pointers/src/PickTransformNode.cpp index fe011b7fcd..badc9dccec 100644 --- a/libraries/pointers/src/PickTransformNode.cpp +++ b/libraries/pointers/src/PickTransformNode.cpp @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/22/2018 +// Created by Sabrina Shanman 2018/08/22 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -23,4 +23,10 @@ Transform PickTransformNode::getTransform() { } return pickManager->getResultTransform(_uid); -} \ No newline at end of file +} + +QVariantMap PickTransformNode::toVariantMap() const { + QVariantMap map; + map["parentID"] = _uid; + return map; +} diff --git a/libraries/pointers/src/PickTransformNode.h b/libraries/pointers/src/PickTransformNode.h index b4c92f3ba7..fb8161757b 100644 --- a/libraries/pointers/src/PickTransformNode.h +++ b/libraries/pointers/src/PickTransformNode.h @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/22/2018 +// Created by Sabrina Shanman 2018/08/22 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -15,9 +15,10 @@ class PickTransformNode : public TransformNode { public: PickTransformNode(unsigned int uid); Transform getTransform() override; + QVariantMap toVariantMap() const override; protected: unsigned int _uid; }; -#endif // hifi_PickTransformNode_h \ No newline at end of file +#endif // hifi_PickTransformNode_h diff --git a/libraries/pointers/src/Pointer.cpp b/libraries/pointers/src/Pointer.cpp index c08a3c2be6..f435482865 100644 --- a/libraries/pointers/src/Pointer.cpp +++ b/libraries/pointers/src/Pointer.cpp @@ -36,10 +36,32 @@ void Pointer::disable() { DependencyManager::get()->disablePick(_pickUID); } +bool Pointer::isEnabled() { + return _enabled; +} + PickResultPointer Pointer::getPrevPickResult() { return DependencyManager::get()->getPrevPickResult(_pickUID); } +QVariantMap Pointer::toVariantMap() const { + QVariantMap qVariantMap = DependencyManager::get()->getPickProperties(_pickUID); + + qVariantMap["pointerType"] = getType(); + qVariantMap["pickID"] = _pickUID; + qVariantMap["hover"] = _hover; + + return qVariantMap; +} + +void Pointer::setScriptParameters(const QVariantMap& scriptParameters) { + _scriptParameters = scriptParameters; +} + +QVariantMap Pointer::getScriptParameters() const { + return _scriptParameters; +} + void Pointer::setPrecisionPicking(bool precisionPicking) { DependencyManager::get()->setPrecisionPicking(_pickUID, precisionPicking); } diff --git a/libraries/pointers/src/Pointer.h b/libraries/pointers/src/Pointer.h index 28d7e42e8f..7a7c51477a 100644 --- a/libraries/pointers/src/Pointer.h +++ b/libraries/pointers/src/Pointer.h @@ -45,12 +45,16 @@ public: virtual void enable(); virtual void disable(); + virtual bool isEnabled(); + virtual PickQuery::PickType getType() const = 0; virtual PickResultPointer getPrevPickResult(); virtual void setRenderState(const std::string& state) = 0; virtual void editRenderState(const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) = 0; - virtual QVariantMap toVariantMap() const = 0; + virtual QVariantMap toVariantMap() const; + virtual void setScriptParameters(const QVariantMap& scriptParameters); + virtual QVariantMap getScriptParameters() const; virtual void setPrecisionPicking(bool precisionPicking); virtual void setIgnoreItems(const QVector& ignoreItems) const; @@ -84,6 +88,9 @@ protected: bool _enabled; bool _hover; + // The parameters used to create this pointer when created through a script + QVariantMap _scriptParameters; + virtual PointerEvent buildPointerEvent(const PickedObject& target, const PickResultPointer& pickResult, const std::string& button = "", bool hover = true) = 0; virtual PickedObject getHoveredObject(const PickResultPointer& pickResult) = 0; diff --git a/libraries/pointers/src/PointerManager.cpp b/libraries/pointers/src/PointerManager.cpp index ca8dfb3f26..de403a46e8 100644 --- a/libraries/pointers/src/PointerManager.cpp +++ b/libraries/pointers/src/PointerManager.cpp @@ -54,6 +54,24 @@ void PointerManager::disablePointer(unsigned int uid) const { } } +bool PointerManager::isPointerEnabled(unsigned int uid) const { + auto pointer = find(uid); + if (pointer) { + return pointer->isEnabled(); + } + return false; +} + +QVector PointerManager::getPointers() const { + QVector pointers; + withReadLock([&] { + for (auto it = _pointers.cbegin(); it != _pointers.cend(); ++it) { + pointers.push_back(it->first); + } + }); + return pointers; +} + void PointerManager::setRenderState(unsigned int uid, const std::string& renderState) const { auto pointer = find(uid); if (pointer) { @@ -86,6 +104,14 @@ QVariantMap PointerManager::getPointerProperties(unsigned int uid) const { } } +QVariantMap PointerManager::getPointerScriptParameters(unsigned int uid) const { + auto pointer = find(uid); + if (pointer) { + return pointer->getScriptParameters(); + } + return QVariantMap(); +} + void PointerManager::update() { auto cachedPointers = resultWithReadLock>>([&] { return _pointers; diff --git a/libraries/pointers/src/PointerManager.h b/libraries/pointers/src/PointerManager.h index 6c1581b09b..609f944101 100644 --- a/libraries/pointers/src/PointerManager.h +++ b/libraries/pointers/src/PointerManager.h @@ -27,10 +27,17 @@ public: void removePointer(unsigned int uid); void enablePointer(unsigned int uid) const; void disablePointer(unsigned int uid) const; + bool isPointerEnabled(unsigned int uid) const; + QVector getPointers() const; + void setRenderState(unsigned int uid, const std::string& renderState) const; void editRenderState(unsigned int uid, const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) const; + PickResultPointer getPrevPickResult(unsigned int uid) const; + // The actual current properties of the pointer QVariantMap getPointerProperties(unsigned int uid) const; + // The properties that were passed in to create the pointer (may be empty if the pointer was created by invoking the constructor) + QVariantMap getPointerScriptParameters(unsigned int uid) const; void setPrecisionPicking(unsigned int uid, bool precisionPicking) const; void setIgnoreItems(unsigned int uid, const QVector& ignoreEntities) const; diff --git a/libraries/shared/src/NestableTransformNode.cpp b/libraries/shared/src/NestableTransformNode.cpp index 9723f388f6..464037dbe5 100644 --- a/libraries/shared/src/NestableTransformNode.cpp +++ b/libraries/shared/src/NestableTransformNode.cpp @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/14/2018 +// Created by Sabrina Shanman 2018/08/14 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -11,4 +11,4 @@ template<> glm::vec3 BaseNestableTransformNode::getActualScale(const std::shared_ptr& nestablePointer) const { return nestablePointer->getAbsoluteJointScaleInObjectFrame(_jointIndex); -} \ No newline at end of file +} diff --git a/libraries/shared/src/NestableTransformNode.h b/libraries/shared/src/NestableTransformNode.h index f70d158c91..4267ca5541 100644 --- a/libraries/shared/src/NestableTransformNode.h +++ b/libraries/shared/src/NestableTransformNode.h @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/14/2018 +// Created by Sabrina Shanman 2018/08/14 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -12,6 +12,8 @@ #include "SpatiallyNestable.h" +#include "RegisteredMetaTypes.h" + template class BaseNestableTransformNode : public TransformNode { public: @@ -45,6 +47,19 @@ public: return jointWorldTransform; } + QVariantMap toVariantMap() const override { + QVariantMap map; + + auto nestable = _spatiallyNestable.lock(); + if (nestable) { + map["parentID"] = nestable->getID(); + map["parentJointIndex"] = _jointIndex; + map["baseParentScale"] = vec3toVariant(_baseScale); + } + + return map; + } + glm::vec3 getActualScale(const std::shared_ptr& nestablePointer) const; protected: diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index d6ce2f11b1..87cd269c97 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -26,6 +26,8 @@ #include #include +int uint32MetaTypeId = qRegisterMetaType("uint32"); +int glmUint32MetaTypeId = qRegisterMetaType("glm::uint32"); int vec2MetaTypeId = qRegisterMetaType(); int u8vec3MetaTypeId = qRegisterMetaType(); int vec3MetaTypeId = qRegisterMetaType(); @@ -33,6 +35,7 @@ int vec4MetaTypeId = qRegisterMetaType(); int qVectorVec3MetaTypeId = qRegisterMetaType>(); int qVectorQuatMetaTypeId = qRegisterMetaType>(); int qVectorBoolMetaTypeId = qRegisterMetaType>(); +int qVectorGLMUint32MetaTypeId = qRegisterMetaType>("QVector"); int quatMetaTypeId = qRegisterMetaType(); int pickRayMetaTypeId = qRegisterMetaType(); int collisionMetaTypeId = qRegisterMetaType(); @@ -67,6 +70,8 @@ void registerMetaTypes(QScriptEngine* engine) { qScriptRegisterMetaType(engine, aaCubeToScriptValue, aaCubeFromScriptValue); qScriptRegisterMetaType(engine, stencilMaskModeToScriptValue, stencilMaskModeFromScriptValue); + + qScriptRegisterSequenceMetaType>(engine); } QScriptValue vec2ToScriptValue(QScriptEngine* engine, const glm::vec2& vec2) { diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index 5b8aa34fd9..3b47bb70c6 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -37,6 +37,8 @@ Q_DECLARE_METATYPE(glm::vec4) Q_DECLARE_METATYPE(glm::quat) Q_DECLARE_METATYPE(glm::mat4) Q_DECLARE_METATYPE(QVector) +Q_DECLARE_METATYPE(unsigned int) +Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(AACube) Q_DECLARE_METATYPE(std::function); Q_DECLARE_METATYPE(std::function); diff --git a/libraries/shared/src/TransformNode.h b/libraries/shared/src/TransformNode.h index c9340bddf0..530218db98 100644 --- a/libraries/shared/src/TransformNode.h +++ b/libraries/shared/src/TransformNode.h @@ -1,5 +1,5 @@ // -// Created by Sabrina Shanman 8/14/2018 +// Created by Sabrina Shanman 2018/08/14 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -8,6 +8,8 @@ #ifndef hifi_TransformNode_h #define hifi_TransformNode_h +#include + #include "Transform.h" class TransformNode { @@ -15,6 +17,7 @@ public: virtual ~TransformNode() = default; virtual Transform getTransform() = 0; + virtual QVariantMap toVariantMap() const = 0; }; #endif // hifi_TransformNode_h