Showing the changes to interface/src/raypick/PickScriptingInterface.cpp (1 of 35 files). Show all
Unified · Split
| @@ -34,18 +34,35 @@ static const float WEB_TOUCH_Y_OFFSET = 0.105f; // how far forward (or back wit · 33 unmodified lines | ||
| 34 | 34 | static const glm::vec3 TIP_OFFSET = glm::vec3(0.0f, StylusPick::WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, 0.0f); |
| 35 | 35 | |
| 36 | 36 | unsigned int PickScriptingInterface::createPick(const PickQuery::PickType type, const QVariant& properties) { |
| 37 | + std::shared_ptr<PickQuery> pick; | |
| 38 | + QVariantMap propMap = properties.toMap(); | |
| 39 | + | |
| 37 | 40 | switch (type) { |
| 38 | 41 | case PickQuery::PickType::Ray: |
| 39 | − return createRayPick(properties); | |
| 42 | + pick = buildRayPick(propMap); | |
| 43 | + break; | |
| 40 | 44 | case PickQuery::PickType::Stylus: |
| 41 | − return createStylusPick(properties); | |
| 45 | + pick = buildStylusPick(propMap); | |
| 46 | + break; | |
| 42 | 47 | case PickQuery::PickType::Parabola: |
| 43 | − return createParabolaPick(properties); | |
| 48 | + pick = buildParabolaPick(propMap); | |
| 49 | + break; | |
| 44 | 50 | case PickQuery::PickType::Collision: |
| 45 | − return createCollisionPick(properties); | |
| 51 | + pick = buildCollisionPick(propMap); | |
| 52 | + break; | |
| 46 | 53 | default: |
| 47 | − return PickManager::INVALID_PICK_ID; | |
| 54 | + break; | |
| 55 | + } | |
| 56 | + | |
| 57 | + if (!pick) { | |
| 58 | + return PickManager::INVALID_PICK_ID; | |
| 48 | 59 | } |
| 60 | + | |
| 61 | + propMap["type"] = (int)type; | |
| 62 | + | |
| 63 | + pick->setScriptParameters(propMap); | |
| 64 | + | |
| 65 | + return DependencyManager::get<PickManager>()->addPick(type, pick); | |
| 49 | 66 | } |
| 50 | 67 | |
| 51 | 68 | PickFilter getPickFilter(unsigned int filter) { |
| @@ -82,17 +99,18 @@ PickFilter getPickFilter(unsigned int filter) { · 30 unmodified lines | ||
| 82 | 99 | * @property {Vec3} [dirOffset] - Synonym for <code>direction</code>. |
| 83 | 100 | * @property {Quat} [orientation] - Alternative property for specifying <code>direction</code>. The value is applied to the |
| 84 | 101 | * default <code>direction</code> value. |
| 102 | + * @property {PickType} type - The type of pick when getting these properties from {@link Picks.getPickProperties}. A ray pick's type is {@link PickType.Ray}. | |
| 103 | + * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity). | |
| 104 | + * 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. | |
| 85 | 105 | */ |
| 86 | −unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { | |
| 87 | − QVariantMap propMap = properties.toMap(); | |
| 88 | − | |
| 106 | +std::shared_ptr<PickQuery> PickScriptingInterface::buildRayPick(const QVariantMap& propMap) { | |
| 89 | 107 | #if defined (Q_OS_ANDROID) |
| 90 | 108 | QString jointName { "" }; |
| 91 | 109 | if (propMap["joint"].isValid()) { |
| 92 | 110 | QString jointName = propMap["joint"].toString(); |
| 93 | 111 | const QString MOUSE_JOINT = "Mouse"; |
| 94 | 112 | if (jointName == MOUSE_JOINT) { |
| 95 | − return PointerEvent::INVALID_POINTER_ID; | |
| 113 | + return nullptr; | |
| 96 | 114 | } |
| 97 | 115 | } |
| 98 | 116 | #endif |
| @@ -134,7 +152,7 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { · 35 unmodified lines | ||
| 134 | 152 | auto rayPick = std::make_shared<RayPick>(position, direction, filter, maxDistance, enabled); |
| 135 | 153 | setParentTransform(rayPick, propMap); |
| 136 | 154 | |
| 137 | − return DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, rayPick); | |
| 155 | + return rayPick; | |
| 138 | 156 | } |
| 139 | 157 | |
| 140 | 158 | /**jsdoc |
| @@ -152,10 +170,9 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { · 11 unmodified lines | ||
| 152 | 170 | * means no maximum. |
| 153 | 171 | * @property {Vec3} [tipOffset=0,0.095,0] - The position of the stylus tip relative to the hand position at default avatar |
| 154 | 172 | * scale. |
| 173 | + * @property {PickType} type - The type of pick when getting these properties from {@link Picks.getPickProperties}. A stylus pick's type is {@link PickType.Stylus}. | |
| 155 | 174 | */ |
| 156 | −unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties) { | |
| 157 | − QVariantMap propMap = properties.toMap(); | |
| 158 | − | |
| 175 | +std::shared_ptr<PickQuery> PickScriptingInterface::buildStylusPick(const QVariantMap& propMap) { | |
| 159 | 176 | bilateral::Side side = bilateral::Side::Invalid; |
| 160 | 177 | { |
| 161 | 178 | QVariant handVar = propMap["hand"]; |
| @@ -184,7 +201,7 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties · 22 unmodified lines | ||
| 184 | 201 | tipOffset = vec3FromVariant(propMap["tipOffset"]); |
| 185 | 202 | } |
| 186 | 203 | |
| 187 | − return DependencyManager::get<PickManager>()->addPick(PickQuery::Stylus, std::make_shared<StylusPick>(side, filter, maxDistance, enabled, tipOffset)); | |
| 204 | + return std::make_shared<StylusPick>(side, filter, maxDistance, enabled, tipOffset); | |
| 188 | 205 | } |
| 189 | 206 | |
| 190 | 207 | // 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 · 37 unmodified lines | ||
| 228 | 245 | * with the avatar or other parent. |
| 229 | 246 | * @property {boolean} [scaleWithAvatar=true] - Synonym for <code>scalewithParent</code>. |
| 230 | 247 | * <p class="important">Deprecated: This property is deprecated and will be removed.</p> |
| 248 | + * @property {PickType} type - The type of pick when getting these properties from {@link Picks.getPickProperties}. A parabola pick's type is {@link PickType.Parabola}. | |
| 249 | + * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity). | |
| 250 | + * 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. | |
| 231 | 251 | */ |
| 232 | −unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properties) { | |
| 233 | − QVariantMap propMap = properties.toMap(); | |
| 234 | − | |
| 252 | +std::shared_ptr<PickQuery> PickScriptingInterface::buildParabolaPick(const QVariantMap& propMap) { | |
| 235 | 253 | bool enabled = false; |
| 236 | 254 | if (propMap["enabled"].isValid()) { |
| 237 | 255 | enabled = propMap["enabled"].toBool(); |
| @@ -292,7 +310,7 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti · 54 unmodified lines | ||
| 292 | 310 | auto parabolaPick = std::make_shared<ParabolaPick>(position, direction, speed, accelerationAxis, |
| 293 | 311 | rotateAccelerationWithAvatar, rotateAccelerationWithParent, scaleWithParent, filter, maxDistance, enabled); |
| 294 | 312 | setParentTransform(parabolaPick, propMap); |
| 295 | − return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, parabolaPick); | |
| 313 | + return parabolaPick; | |
| 296 | 314 | } |
| 297 | 315 | |
| 298 | 316 | |
| @@ -326,10 +344,11 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti · 27 unmodified lines | ||
| 326 | 344 | * the collision region. The depth is in world coordinates but scales with the parent if defined. |
| 327 | 345 | * @property {CollisionMask} [collisionGroup=8] - The type of objects the collision region collides as. Objects whose collision |
| 328 | 346 | * masks overlap with the region's collision group are considered to be colliding with the region. |
| 347 | + * @property {PickType} type - The type of pick when getting these properties from {@link Picks.getPickProperties}. A collision pick's type is {@link PickType.Collision}. | |
| 348 | + * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity). | |
| 349 | + * 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. | |
| 329 | 350 | */ |
| 330 | −unsigned int PickScriptingInterface::createCollisionPick(const QVariant& properties) { | |
| 331 | − QVariantMap propMap = properties.toMap(); | |
| 332 | − | |
| 351 | +std::shared_ptr<PickQuery> PickScriptingInterface::buildCollisionPick(const QVariantMap& propMap) { | |
| 333 | 352 | bool enabled = false; |
| 334 | 353 | if (propMap["enabled"].isValid()) { |
| 335 | 354 | enabled = propMap["enabled"].toBool(); |
| @@ -354,7 +373,7 @@ unsigned int PickScriptingInterface::createCollisionPick(const QVariant& propert · 18 unmodified lines | ||
| 354 | 373 | auto collisionPick = std::make_shared<CollisionPick>(filter, maxDistance, enabled, scaleWithParent, collisionRegion, qApp->getPhysicsEngine()); |
| 355 | 374 | setParentTransform(collisionPick, propMap); |
| 356 | 375 | |
| 357 | − return DependencyManager::get<PickManager>()->addPick(PickQuery::Collision, collisionPick); | |
| 376 | + return collisionPick; | |
| 358 | 377 | } |
| 359 | 378 | |
| 360 | 379 | void PickScriptingInterface::enablePick(unsigned int uid) { |
| @@ -365,10 +384,26 @@ void PickScriptingInterface::disablePick(unsigned int uid) { · 4 unmodified lines | ||
| 365 | 384 | DependencyManager::get<PickManager>()->disablePick(uid); |
| 366 | 385 | } |
| 367 | 386 | |
| 387 | +bool PickScriptingInterface::isPickEnabled(unsigned int uid) const { | |
| 388 | + return DependencyManager::get<PickManager>()->isPickEnabled(uid); | |
| 389 | +} | |
| 390 | + | |
| 368 | 391 | void PickScriptingInterface::removePick(unsigned int uid) { |
| 369 | 392 | DependencyManager::get<PickManager>()->removePick(uid); |
| 370 | 393 | } |
| 371 | 394 | |
| 395 | +QVariantMap PickScriptingInterface::getPickProperties(unsigned int uid) const { | |
| 396 | + return DependencyManager::get<PickManager>()->getPickProperties(uid); | |
| 397 | +} | |
| 398 | + | |
| 399 | +QVariantMap PickScriptingInterface::getPickScriptParameters(unsigned int uid) const { | |
| 400 | + return DependencyManager::get<PickManager>()->getPickScriptParameters(uid); | |
| 401 | +} | |
| 402 | + | |
| 403 | +QVector<unsigned int> PickScriptingInterface::getCreatedPicks() const { | |
| 404 | + return DependencyManager::get<PickManager>()->getCreatedPicks(); | |
| 405 | +} | |
| 406 | + | |
| 372 | 407 | QVariantMap PickScriptingInterface::getPrevPickResult(unsigned int uid) { |
| 373 | 408 | QVariantMap result; |
| 374 | 409 | auto pickResult = DependencyManager::get<PickManager>()->getPrevPickResult(uid); |