Showing the changes to interface/src/raypick/PointerScriptingInterface.cpp (1 of 13 files). Show all
Unified · Split
| @@ -22,6 +22,13 @@ · 21 unmodified lines | |||
| 22 | #include "StylusPointer.h" | 22 | #include "StylusPointer.h" |
| 23 | #include "ParabolaPointer.h" | 23 | #include "ParabolaPointer.h" |
| 24 | #include "StylusPick.h" | 24 | #include "StylusPick.h" |
| 25 | #include <ScriptManager.h> | ||
| 26 | |||
| 27 | STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){ | ||
| 28 | qDebug() << "STATIC_SCRIPT_TYPES_INITIALIZER PointerScriptingInterface"; | ||
| 29 | auto scriptEngine = manager->engine().get(); | ||
| 30 | scriptRegisterMetaType<RayPointerProperties, rayPointerPropertiesToScriptValue, rayPointerPropertiesFromScriptValue>(scriptEngine); | ||
| 31 | })); | ||
| 25 | 32 | ||
| 26 | static const glm::quat X_ROT_NEG_90{ 0.70710678f, -0.70710678f, 0.0f, 0.0f }; | 33 | static const glm::quat X_ROT_NEG_90{ 0.70710678f, -0.70710678f, 0.0f, 0.0f }; |
| 27 | static const glm::vec3 DEFAULT_POSITION_OFFSET{0.0f, 0.0f, -StylusPick::WEB_STYLUS_LENGTH / 2.0f}; | 34 | static const glm::vec3 DEFAULT_POSITION_OFFSET{0.0f, 0.0f, -StylusPick::WEB_STYLUS_LENGTH / 2.0f}; |
| @@ -35,26 +42,26 @@ void PointerScriptingInterface::setIncludeItems(unsigned int uid, const ScriptVa · 7 unmodified lines | |||
| 35 | DependencyManager::get<PointerManager>()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems)); | 42 | DependencyManager::get<PointerManager>()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems)); |
| 36 | } | 43 | } |
| 37 | 44 | ||
| 38 | unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& type, const QVariant& properties) { | 45 | unsigned int PointerScriptingInterface::createPointerInternal(const PickQuery::PickType& type, const PointerProperties& properties) { |
| 39 | // Interaction with managers should always happen on the main thread | 46 | // Interaction with managers should always happen on the main thread |
| 40 | if (QThread::currentThread() != qApp->thread()) { | 47 | if (QThread::currentThread() != qApp->thread()) { |
| 41 | unsigned int result; | 48 | unsigned int result; |
| 42 | BLOCKING_INVOKE_METHOD(this, "createPointer", Q_RETURN_ARG(unsigned int, result), Q_ARG(PickQuery::PickType, type), Q_ARG(QVariant, properties)); | 49 | BLOCKING_INVOKE_METHOD(this, "createPointerInternal", Q_RETURN_ARG(unsigned int, result), Q_ARG(PickQuery::PickType, type), Q_ARG(PointerProperties, properties)); |
| 43 | return result; | 50 | return result; |
| 44 | } | 51 | } |
| 45 | 52 | ||
| 46 | QVariantMap propertyMap = properties.toMap(); | 53 | QVariantMap propertyMap = properties.properties; |
| 47 | 54 | ||
| 48 | std::shared_ptr<Pointer> pointer; | 55 | std::shared_ptr<Pointer> pointer; |
| 49 | switch (type) { | 56 | switch (type) { |
| 50 | case PickQuery::PickType::Ray: | 57 | case PickQuery::PickType::Ray: |
| 51 | pointer = buildLaserPointer(propertyMap); | 58 | pointer = buildLaserPointer(properties); |
| 52 | break; | 59 | break; |
| 53 | case PickQuery::PickType::Stylus: | 60 | case PickQuery::PickType::Stylus: |
| 54 | pointer = buildStylus(propertyMap); | 61 | pointer = buildStylus(properties); |
| 55 | break; | 62 | break; |
| 56 | case PickQuery::PickType::Parabola: | 63 | case PickQuery::PickType::Parabola: |
| 57 | pointer = buildParabolaPointer(propertyMap); | 64 | pointer = buildParabolaPointer(properties); |
| 58 | break; | 65 | break; |
| 59 | default: | 66 | default: |
| 60 | break; | 67 | break; |
| @@ -71,6 +78,10 @@ unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& · 10 unmodified lines | |||
| 71 | return DependencyManager::get<PointerManager>()->addPointer(pointer); | 78 | return DependencyManager::get<PointerManager>()->addPointer(pointer); |
| 72 | } | 79 | } |
| 73 | 80 | ||
| 81 | unsigned int PointerScriptingInterface::createRayPointer(RayPointerProperties properties) { | ||
| 82 | return createPointerInternal(PickQuery::PickType::Ray, properties); | ||
| 83 | } | ||
| 84 | |||
| 74 | bool PointerScriptingInterface::isPointerEnabled(unsigned int uid) const { | 85 | bool PointerScriptingInterface::isPointerEnabled(unsigned int uid) const { |
| 75 | return DependencyManager::get<PointerManager>()->isPointerEnabled(uid); | 86 | return DependencyManager::get<PointerManager>()->isPointerEnabled(uid); |
| 76 | } | 87 | } |
| @@ -109,8 +120,8 @@ QVariantMap PointerScriptingInterface::getPointerScriptParameters(unsigned int u · 32 unmodified lines | |||
| 109 | * offset. | 120 | * offset. |
| 110 | * @property {Quat} [rotationOffset] - The rotation offset of the model from the hand, to override the default rotation offset. | 121 | * @property {Quat} [rotationOffset] - The rotation offset of the model from the hand, to override the default rotation offset. |
| 111 | */ | 122 | */ |
| 112 | std::shared_ptr<Pointer> PointerScriptingInterface::buildStylus(const QVariant& properties) { | 123 | std::shared_ptr<Pointer> PointerScriptingInterface::buildStylus(const PointerProperties& properties) { |
| 113 | QVariantMap propertyMap = properties.toMap(); | 124 | QVariantMap propertyMap = properties.properties; |
| 114 | 125 | ||
| 115 | bool hover = false; | 126 | bool hover = false; |
| 116 | if (propertyMap["hover"].isValid()) { | 127 | if (propertyMap["hover"].isValid()) { |
| @@ -142,7 +153,7 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildStylus(const QVariant& · 25 unmodified lines | |||
| 142 | } | 153 | } |
| 143 | } | 154 | } |
| 144 | 155 | ||
| 145 | return std::make_shared<StylusPointer>(properties, StylusPointer::buildStylus(propertyMap), hover, enabled, modelPositionOffset, modelRotationOffset, modelDimensions); | 156 | return std::make_shared<StylusPointer>(properties.properties, StylusPointer::buildStylus(propertyMap), hover, enabled, modelPositionOffset, modelRotationOffset, modelDimensions); |
| 146 | } | 157 | } |
| 147 | 158 | ||
| 148 | /*@jsdoc | 159 | /*@jsdoc |
| @@ -221,8 +232,8 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildStylus(const QVariant& · 72 unmodified lines | |||
| 221 | * {@link Pointers.getPointerProperties}. | 232 | * {@link Pointers.getPointerProperties}. |
| 222 | * @see {@link Picks.RayPickProperties} for additional properties from the underlying ray pick. | 233 | * @see {@link Picks.RayPickProperties} for additional properties from the underlying ray pick. |
| 223 | */ | 234 | */ |
| 224 | std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVariant& properties) { | 235 | std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const PointerProperties& properties) { |
| 225 | QVariantMap propertyMap = properties.toMap(); | 236 | QVariantMap propertyMap = properties.properties; |
| 226 | 237 | ||
| 227 | #if defined (Q_OS_ANDROID) | 238 | #if defined (Q_OS_ANDROID) |
| 228 | QString jointName { "" }; | 239 | QString jointName { "" }; |
| @@ -284,7 +295,7 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVar · 55 unmodified lines | |||
| 284 | QVariantMap renderStateMap = renderStateVariant.toMap(); | 295 | QVariantMap renderStateMap = renderStateVariant.toMap(); |
| 285 | if (renderStateMap["name"].isValid()) { | 296 | if (renderStateMap["name"].isValid()) { |
| 286 | std::string name = renderStateMap["name"].toString().toStdString(); | 297 | std::string name = renderStateMap["name"].toString().toStdString(); |
| 287 | renderStates[name] = LaserPointer::buildRenderState(renderStateMap); | 298 | renderStates[name] = LaserPointer::buildRenderState(renderStateMap, properties.entityProperties); |
| 288 | } | 299 | } |
| 289 | } | 300 | } |
| 290 | } | 301 | } |
| @@ -299,7 +310,8 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVar · 8 unmodified lines | |||
| 299 | if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) { | 310 | if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) { |
| 300 | std::string name = renderStateMap["name"].toString().toStdString(); | 311 | std::string name = renderStateMap["name"].toString().toStdString(); |
| 301 | float distance = renderStateMap["distance"].toFloat(); | 312 | float distance = renderStateMap["distance"].toFloat(); |
| 302 | defaultRenderStates[name] = std::pair<float, std::shared_ptr<StartEndRenderState>>(distance, LaserPointer::buildRenderState(renderStateMap)); | 313 | defaultRenderStates[name] = std::pair<float, std::shared_ptr<StartEndRenderState>>(distance, |
| 314 | LaserPointer::buildRenderState(renderStateMap, properties.entityProperties)); | ||
| 303 | } | 315 | } |
| 304 | } | 316 | } |
| 305 | } | 317 | } |
| @@ -328,7 +340,7 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVar · 22 unmodified lines | |||
| 328 | } | 340 | } |
| 329 | } | 341 | } |
| 330 | 342 | ||
| 331 | return std::make_shared<LaserPointer>(properties, renderStates, defaultRenderStates, hover, triggers, | 343 | return std::make_shared<LaserPointer>(properties.properties, renderStates, defaultRenderStates, hover, triggers, |
| 332 | faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, | 344 | faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, |
| 333 | distanceScaleEnd, scaleWithParent, enabled); | 345 | distanceScaleEnd, scaleWithParent, enabled); |
| 334 | } | 346 | } |
| @@ -416,8 +428,8 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVar · 81 unmodified lines | |||
| 416 | * {@link Pointers.getPointerProperties}. | 428 | * {@link Pointers.getPointerProperties}. |
| 417 | * @see {@link Picks.ParabolaPickProperties} for additional properties from the underlying parabola pick. | 429 | * @see {@link Picks.ParabolaPickProperties} for additional properties from the underlying parabola pick. |
| 418 | */ | 430 | */ |
| 419 | std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const QVariant& properties) { | 431 | std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const PointerProperties& properties) { |
| 420 | QVariantMap propertyMap = properties.toMap(); | 432 | QVariantMap propertyMap = properties.properties; |
| 421 | 433 | ||
| 422 | bool faceAvatar = false; | 434 | bool faceAvatar = false; |
| 423 | if (propertyMap["faceAvatar"].isValid()) { | 435 | if (propertyMap["faceAvatar"].isValid()) { |
| @@ -468,7 +480,7 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const Q · 44 unmodified lines | |||
| 468 | QVariantMap renderStateMap = renderStateVariant.toMap(); | 480 | QVariantMap renderStateMap = renderStateVariant.toMap(); |
| 469 | if (renderStateMap["name"].isValid()) { | 481 | if (renderStateMap["name"].isValid()) { |
| 470 | std::string name = renderStateMap["name"].toString().toStdString(); | 482 | std::string name = renderStateMap["name"].toString().toStdString(); |
| 471 | renderStates[name] = ParabolaPointer::buildRenderState(renderStateMap); | 483 | renderStates[name] = ParabolaPointer::buildRenderState(renderStateMap, properties.entityProperties); |
| 472 | } | 484 | } |
| 473 | } | 485 | } |
| 474 | } | 486 | } |
| @@ -483,7 +495,8 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const Q · 8 unmodified lines | |||
| 483 | if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) { | 495 | if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) { |
| 484 | std::string name = renderStateMap["name"].toString().toStdString(); | 496 | std::string name = renderStateMap["name"].toString().toStdString(); |
| 485 | float distance = renderStateMap["distance"].toFloat(); | 497 | float distance = renderStateMap["distance"].toFloat(); |
| 486 | defaultRenderStates[name] = std::pair<float, std::shared_ptr<StartEndRenderState>>(distance, ParabolaPointer::buildRenderState(renderStateMap)); | 498 | defaultRenderStates[name] = std::pair<float, std::shared_ptr<StartEndRenderState>>(distance, |
| 499 | ParabolaPointer::buildRenderState(renderStateMap, properties.entityProperties)); | ||
| 487 | } | 500 | } |
| 488 | } | 501 | } |
| 489 | } | 502 | } |
| @@ -512,12 +525,13 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const Q · 22 unmodified lines | |||
| 512 | } | 525 | } |
| 513 | } | 526 | } |
| 514 | 527 | ||
| 515 | return std::make_shared<ParabolaPointer>(properties, renderStates, defaultRenderStates, hover, triggers, | 528 | return std::make_shared<ParabolaPointer>(properties.properties, renderStates, defaultRenderStates, hover, triggers, |
| 516 | faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, distanceScaleEnd, | 529 | faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, distanceScaleEnd, |
| 517 | scaleWithParent, enabled); | 530 | scaleWithParent, enabled); |
| 518 | } | 531 | } |
| 519 | 532 | ||
| 520 | void PointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) const { | 533 | void PointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) const { |
| 534 | //V8TODO: this won't work for now | ||
| 521 | QVariantMap propMap = properties.toMap(); | 535 | QVariantMap propMap = properties.toMap(); |
| 522 | 536 | ||
| 523 | QVariant startProps; | 537 | QVariant startProps; |
| @@ -546,3 +560,52 @@ QVariantMap PointerScriptingInterface::getPrevPickResult(unsigned int uid) const · 22 unmodified lines | |||
| 546 | } | 560 | } |
| 547 | return result; | 561 | return result; |
| 548 | } | 562 | } |
| 563 | |||
| 564 | ScriptValue rayPointerPropertiesToScriptValue(ScriptEngine* engine, const RayPointerProperties& in) { | ||
| 565 | return engine->newVariant(QVariant(in.properties)); | ||
| 566 | } | ||
| 567 | |||
| 568 | bool rayPointerPropertiesFromScriptValue(const ScriptValue& value, RayPointerProperties& out) { | ||
| 569 | // This copies properties from script value, but also converts entity properties of entities used in render states | ||
| 570 | // from JS objects into EntityItemProperties | ||
| 571 | out.properties = value.engine()->fromScriptValue<QVariantMap>(value); | ||
| 572 | if (out.properties["renderStates"].canConvert<QVariantList>()) { | ||
| 573 | QVariantList renderStates = out.properties["renderStates"].value<QVariantList>(); | ||
| 574 | for( int i = 0; i < renderStates.length(); i++) { | ||
| 575 | if (renderStates[i].canConvert<QVariantMap>()) { | ||
| 576 | QVariantMap stateMap = renderStates[i].value<QVariantMap>(); | ||
| 577 | if (stateMap["name"].canConvert<QString>()) { | ||
| 578 | stateMap["name"].value<QString>(); | ||
| 579 | } | ||
| 580 | if (stateMap["start"].isValid()) { | ||
| 581 | ScriptValue start = value.property("renderStates").property(i).property("start"); | ||
| 582 | EntityItemProperties startProperties; | ||
| 583 | startProperties.copyFromScriptValue(start, false); | ||
| 584 | stateMap.insert("startPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 585 | out.entityProperties.append(startProperties); | ||
| 586 | } | ||
| 587 | |||
| 588 | if (stateMap["path"].isValid()) { | ||
| 589 | ScriptValue path = value.property("renderStates").property(i).property("path"); | ||
| 590 | EntityItemProperties pathProperties; | ||
| 591 | pathProperties.copyFromScriptValue(path, false); | ||
| 592 | stateMap.insert("pathPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 593 | out.entityProperties.append(pathProperties); | ||
| 594 | } | ||
| 595 | |||
| 596 | if (stateMap["end"].isValid()) { | ||
| 597 | ScriptValue end = value.property("renderStates").property(i).property("end"); | ||
| 598 | EntityItemProperties endProperties; | ||
| 599 | endProperties.copyFromScriptValue(end, false); | ||
| 600 | stateMap.insert("endPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 601 | out.entityProperties.append(endProperties); | ||
| 602 | } | ||
| 603 | // V8TODO: Check if path is a polyline and if values are valid | ||
| 604 | renderStates[i].setValue(stateMap); | ||
| 605 | } | ||
| 606 | } | ||
| 607 | out.properties["renderStates"].setValue(renderStates); | ||
| 608 | } | ||
| 609 | qDebug() << "rayPointerPropertiesFromScriptValue" << out.properties; | ||
| 610 | return true; | ||
| 611 | } | ||