Showing the changes to interface/src/raypick/PointerScriptingInterface.cpp (1 of 10 files). Show all
Unified · Split
| @@ -28,6 +28,8 @@ STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){ · 27 unmodified lines | |||
| 28 | qDebug() << "STATIC_SCRIPT_TYPES_INITIALIZER PointerScriptingInterface"; | 28 | qDebug() << "STATIC_SCRIPT_TYPES_INITIALIZER PointerScriptingInterface"; |
| 29 | auto scriptEngine = manager->engine().get(); | 29 | auto scriptEngine = manager->engine().get(); |
| 30 | scriptRegisterMetaType<RayPointerProperties, rayPointerPropertiesToScriptValue, rayPointerPropertiesFromScriptValue>(scriptEngine); | 30 | scriptRegisterMetaType<RayPointerProperties, rayPointerPropertiesToScriptValue, rayPointerPropertiesFromScriptValue>(scriptEngine); |
| 31 | scriptRegisterMetaType<StylusPointerProperties, stylusPointerPropertiesToScriptValue, stylusPointerPropertiesFromScriptValue>(scriptEngine); | ||
| 32 | scriptRegisterMetaType<ParabolaPointerProperties, parabolaPointerPropertiesToScriptValue, parabolaPointerPropertiesFromScriptValue>(scriptEngine); | ||
| 31 | })); | 33 | })); |
| 32 | 34 | ||
| 33 | static const glm::quat X_ROT_NEG_90{ 0.70710678f, -0.70710678f, 0.0f, 0.0f }; | 35 | static const glm::quat X_ROT_NEG_90{ 0.70710678f, -0.70710678f, 0.0f, 0.0f }; |
| @@ -82,6 +84,15 @@ unsigned int PointerScriptingInterface::createRayPointer(RayPointerProperties pr · 48 unmodified lines | |||
| 82 | return createPointerInternal(PickQuery::PickType::Ray, properties); | 84 | return createPointerInternal(PickQuery::PickType::Ray, properties); |
| 83 | } | 85 | } |
| 84 | 86 | ||
| 87 | unsigned int PointerScriptingInterface::createStylusPointer(StylusPointerProperties properties) { | ||
| 88 | return createPointerInternal(PickQuery::PickType::Stylus, properties); | ||
| 89 | } | ||
| 90 | |||
| 91 | unsigned int PointerScriptingInterface::createParabolaPointer(ParabolaPointerProperties properties) { | ||
| 92 | return createPointerInternal(PickQuery::PickType::Parabola, properties); | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 85 | bool PointerScriptingInterface::isPointerEnabled(unsigned int uid) const { | 96 | bool PointerScriptingInterface::isPointerEnabled(unsigned int uid) const { |
| 86 | return DependencyManager::get<PointerManager>()->isPointerEnabled(uid); | 97 | return DependencyManager::get<PointerManager>()->isPointerEnabled(uid); |
| 87 | } | 98 | } |
| @@ -614,3 +625,113 @@ bool rayPointerPropertiesFromScriptValue(const ScriptValue& value, RayPointerPro · 526 unmodified lines | |||
| 614 | qDebug() << "rayPointerPropertiesFromScriptValue" << out.properties; | 625 | qDebug() << "rayPointerPropertiesFromScriptValue" << out.properties; |
| 615 | return true; | 626 | return true; |
| 616 | } | 627 | } |
| 628 | |||
| 629 | ScriptValue stylusPointerPropertiesToScriptValue(ScriptEngine* engine, const StylusPointerProperties& in) { | ||
| 630 | return engine->newVariant(QVariant(in.properties)); | ||
| 631 | } | ||
| 632 | |||
| 633 | //V8TODO: adapt render states to what parabola expects | ||
| 634 | bool stylusPointerPropertiesFromScriptValue(const ScriptValue& value, StylusPointerProperties& out) { | ||
| 635 | // This copies properties from script value, but also converts entity properties of entities used in render states | ||
| 636 | // from JS objects into EntityItemProperties | ||
| 637 | out.properties = value.engine()->fromScriptValue<QVariantMap>(value); | ||
| 638 | QList<QString> renderStatesNames; | ||
| 639 | renderStatesNames.append("renderStates"); | ||
| 640 | renderStatesNames.append("defaultRenderStates"); | ||
| 641 | for (auto renderStatesName = renderStatesNames.cbegin(); renderStatesName!=renderStatesNames.cend(); renderStatesName++) { | ||
| 642 | if (out.properties[*renderStatesName].canConvert<QVariantList>()) { | ||
| 643 | QVariantList renderStates = out.properties[*renderStatesName].value<QVariantList>(); | ||
| 644 | for (int i = 0; i < renderStates.length(); i++) { | ||
| 645 | if (renderStates[i].canConvert<QVariantMap>()) { | ||
| 646 | QVariantMap stateMap = renderStates[i].value<QVariantMap>(); | ||
| 647 | if (stateMap["name"].canConvert<QString>()) { | ||
| 648 | stateMap["name"].value<QString>(); | ||
| 649 | } | ||
| 650 | if (stateMap["start"].isValid()) { | ||
| 651 | ScriptValue start = value.property(*renderStatesName).property(i).property("start"); | ||
| 652 | EntityItemProperties startProperties; | ||
| 653 | startProperties.copyFromScriptValue(start, false); | ||
| 654 | stateMap.insert("startPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 655 | out.entityProperties.append(startProperties); | ||
| 656 | } | ||
| 657 | |||
| 658 | if (stateMap["path"].isValid()) { | ||
| 659 | ScriptValue path = value.property(*renderStatesName).property(i).property("path"); | ||
| 660 | EntityItemProperties pathProperties; | ||
| 661 | pathProperties.copyFromScriptValue(path, false); | ||
| 662 | stateMap.insert("pathPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 663 | out.entityProperties.append(pathProperties); | ||
| 664 | } | ||
| 665 | |||
| 666 | if (stateMap["end"].isValid()) { | ||
| 667 | ScriptValue end = value.property(*renderStatesName).property(i).property("end"); | ||
| 668 | EntityItemProperties endProperties; | ||
| 669 | endProperties.copyFromScriptValue(end, false); | ||
| 670 | stateMap.insert("endPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 671 | out.entityProperties.append(endProperties); | ||
| 672 | } | ||
| 673 | // V8TODO: Check if path is a polyline and if values are valid | ||
| 674 | renderStates[i].setValue(stateMap); | ||
| 675 | } | ||
| 676 | } | ||
| 677 | out.properties[*renderStatesName].setValue(renderStates); | ||
| 678 | } | ||
| 679 | } | ||
| 680 | qDebug() << "rayPointerPropertiesFromScriptValue" << out.properties; | ||
| 681 | return true; | ||
| 682 | } | ||
| 683 | |||
| 684 | ScriptValue parabolaPointerPropertiesToScriptValue(ScriptEngine* engine, const ParabolaPointerProperties& in) { | ||
| 685 | return engine->newVariant(QVariant(in.properties)); | ||
| 686 | } | ||
| 687 | |||
| 688 | //V8TODO: adapt render states to what parabola expects | ||
| 689 | bool parabolaPointerPropertiesFromScriptValue(const ScriptValue& value, ParabolaPointerProperties& out) { | ||
| 690 | // This copies properties from script value, but also converts entity properties of entities used in render states | ||
| 691 | // from JS objects into EntityItemProperties | ||
| 692 | out.properties = value.engine()->fromScriptValue<QVariantMap>(value); | ||
| 693 | QList<QString> renderStatesNames; | ||
| 694 | renderStatesNames.append("renderStates"); | ||
| 695 | renderStatesNames.append("defaultRenderStates"); | ||
| 696 | for (auto renderStatesName = renderStatesNames.cbegin(); renderStatesName!=renderStatesNames.cend(); renderStatesName++) { | ||
| 697 | if (out.properties[*renderStatesName].canConvert<QVariantList>()) { | ||
| 698 | QVariantList renderStates = out.properties[*renderStatesName].value<QVariantList>(); | ||
| 699 | for (int i = 0; i < renderStates.length(); i++) { | ||
| 700 | if (renderStates[i].canConvert<QVariantMap>()) { | ||
| 701 | QVariantMap stateMap = renderStates[i].value<QVariantMap>(); | ||
| 702 | if (stateMap["name"].canConvert<QString>()) { | ||
| 703 | stateMap["name"].value<QString>(); | ||
| 704 | } | ||
| 705 | if (stateMap["start"].isValid()) { | ||
| 706 | ScriptValue start = value.property(*renderStatesName).property(i).property("start"); | ||
| 707 | EntityItemProperties startProperties; | ||
| 708 | startProperties.copyFromScriptValue(start, false); | ||
| 709 | stateMap.insert("startPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 710 | out.entityProperties.append(startProperties); | ||
| 711 | } | ||
| 712 | |||
| 713 | if (stateMap["path"].isValid()) { | ||
| 714 | ScriptValue path = value.property(*renderStatesName).property(i).property("path"); | ||
| 715 | EntityItemProperties pathProperties; | ||
| 716 | pathProperties.copyFromScriptValue(path, false); | ||
| 717 | stateMap.insert("pathPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 718 | out.entityProperties.append(pathProperties); | ||
| 719 | } | ||
| 720 | |||
| 721 | if (stateMap["end"].isValid()) { | ||
| 722 | ScriptValue end = value.property(*renderStatesName).property(i).property("end"); | ||
| 723 | EntityItemProperties endProperties; | ||
| 724 | endProperties.copyFromScriptValue(end, false); | ||
| 725 | stateMap.insert("endPropertyIndex", QVariant(out.entityProperties.length())); | ||
| 726 | out.entityProperties.append(endProperties); | ||
| 727 | } | ||
| 728 | // V8TODO: Check if path is a polyline and if values are valid | ||
| 729 | renderStates[i].setValue(stateMap); | ||
| 730 | } | ||
| 731 | } | ||
| 732 | out.properties[*renderStatesName].setValue(renderStates); | ||
| 733 | } | ||
| 734 | } | ||
| 735 | qDebug() << "rayPointerPropertiesFromScriptValue" << out.properties; | ||
| 736 | return true; | ||
| 737 | } | ||