History

Work on porting laser pointers to local entities, removal of LaserPointer JS API

ksuprynowicz committed 3 years ago

Commit 2a2cf381 parent 4d0303313 files · +311 −385Browse files

Showing the changes to interface/src/raypick/PointerScriptingInterface.cpp (1 of 13 files). Show all

Unified · Split

interface/src/raypick/PointerScriptingInterface.cpp+82−19
@@ -22,6 +22,13 @@ · 21 unmodified lines
2222 #include "StylusPointer.h"
2323 #include "ParabolaPointer.h"
2424 #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+}));
2532
2633 static const glm::quat X_ROT_NEG_90{ 0.70710678f, -0.70710678f, 0.0f, 0.0f };
2734 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
3542 DependencyManager::get<PointerManager>()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems));
3643 }
3744
38−unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& type, const QVariant& properties) {
45+unsigned int PointerScriptingInterface::createPointerInternal(const PickQuery::PickType& type, const PointerProperties& properties) {
3946 // Interaction with managers should always happen on the main thread
4047 if (QThread::currentThread() != qApp->thread()) {
4148 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));
4350 return result;
4451 }
4552
46− QVariantMap propertyMap = properties.toMap();
53+ QVariantMap propertyMap = properties.properties;
4754
4855 std::shared_ptr<Pointer> pointer;
4956 switch (type) {
5057 case PickQuery::PickType::Ray:
51− pointer = buildLaserPointer(propertyMap);
58+ pointer = buildLaserPointer(properties);
5259 break;
5360 case PickQuery::PickType::Stylus:
54− pointer = buildStylus(propertyMap);
61+ pointer = buildStylus(properties);
5562 break;
5663 case PickQuery::PickType::Parabola:
57− pointer = buildParabolaPointer(propertyMap);
64+ pointer = buildParabolaPointer(properties);
5865 break;
5966 default:
6067 break;
@@ -71,6 +78,10 @@ unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& · 10 unmodified lines
7178 return DependencyManager::get<PointerManager>()->addPointer(pointer);
7279 }
7380
81+unsigned int PointerScriptingInterface::createRayPointer(RayPointerProperties properties) {
82+ return createPointerInternal(PickQuery::PickType::Ray, properties);
83+}
84+
7485 bool PointerScriptingInterface::isPointerEnabled(unsigned int uid) const {
7586 return DependencyManager::get<PointerManager>()->isPointerEnabled(uid);
7687 }
@@ -109,8 +120,8 @@ QVariantMap PointerScriptingInterface::getPointerScriptParameters(unsigned int u · 32 unmodified lines
109120 * offset.
110121 * @property {Quat} [rotationOffset] - The rotation offset of the model from the hand, to override the default rotation offset.
111122 */
112−std::shared_ptr<Pointer> PointerScriptingInterface::buildStylus(const QVariant& properties) {
113− QVariantMap propertyMap = properties.toMap();
123+std::shared_ptr<Pointer> PointerScriptingInterface::buildStylus(const PointerProperties& properties) {
124+ QVariantMap propertyMap = properties.properties;
114125
115126 bool hover = false;
116127 if (propertyMap["hover"].isValid()) {
@@ -142,7 +153,7 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildStylus(const QVariant& · 25 unmodified lines
142153 }
143154 }
144155
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);
146157 }
147158
148159 /*@jsdoc
@@ -221,8 +232,8 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildStylus(const QVariant& · 72 unmodified lines
221232 * {@link Pointers.getPointerProperties}.
222233 * @see {@link Picks.RayPickProperties} for additional properties from the underlying ray pick.
223234 */
224−std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVariant& properties) {
225− QVariantMap propertyMap = properties.toMap();
235+std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const PointerProperties& properties) {
236+ QVariantMap propertyMap = properties.properties;
226237
227238 #if defined (Q_OS_ANDROID)
228239 QString jointName { "" };
@@ -284,7 +295,7 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVar · 55 unmodified lines
284295 QVariantMap renderStateMap = renderStateVariant.toMap();
285296 if (renderStateMap["name"].isValid()) {
286297 std::string name = renderStateMap["name"].toString().toStdString();
287− renderStates[name] = LaserPointer::buildRenderState(renderStateMap);
298+ renderStates[name] = LaserPointer::buildRenderState(renderStateMap, properties.entityProperties);
288299 }
289300 }
290301 }
@@ -299,7 +310,8 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVar · 8 unmodified lines
299310 if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) {
300311 std::string name = renderStateMap["name"].toString().toStdString();
301312 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));
303315 }
304316 }
305317 }
@@ -328,7 +340,7 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVar · 22 unmodified lines
328340 }
329341 }
330342
331− return std::make_shared<LaserPointer>(properties, renderStates, defaultRenderStates, hover, triggers,
343+ return std::make_shared<LaserPointer>(properties.properties, renderStates, defaultRenderStates, hover, triggers,
332344 faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd,
333345 distanceScaleEnd, scaleWithParent, enabled);
334346 }
@@ -416,8 +428,8 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildLaserPointer(const QVar · 81 unmodified lines
416428 * {@link Pointers.getPointerProperties}.
417429 * @see {@link Picks.ParabolaPickProperties} for additional properties from the underlying parabola pick.
418430 */
419−std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const QVariant& properties) {
420− QVariantMap propertyMap = properties.toMap();
431+std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const PointerProperties& properties) {
432+ QVariantMap propertyMap = properties.properties;
421433
422434 bool faceAvatar = false;
423435 if (propertyMap["faceAvatar"].isValid()) {
@@ -468,7 +480,7 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const Q · 44 unmodified lines
468480 QVariantMap renderStateMap = renderStateVariant.toMap();
469481 if (renderStateMap["name"].isValid()) {
470482 std::string name = renderStateMap["name"].toString().toStdString();
471− renderStates[name] = ParabolaPointer::buildRenderState(renderStateMap);
483+ renderStates[name] = ParabolaPointer::buildRenderState(renderStateMap, properties.entityProperties);
472484 }
473485 }
474486 }
@@ -483,7 +495,8 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const Q · 8 unmodified lines
483495 if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) {
484496 std::string name = renderStateMap["name"].toString().toStdString();
485497 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));
487500 }
488501 }
489502 }
@@ -512,12 +525,13 @@ std::shared_ptr<Pointer> PointerScriptingInterface::buildParabolaPointer(const Q · 22 unmodified lines
512525 }
513526 }
514527
515− return std::make_shared<ParabolaPointer>(properties, renderStates, defaultRenderStates, hover, triggers,
528+ return std::make_shared<ParabolaPointer>(properties.properties, renderStates, defaultRenderStates, hover, triggers,
516529 faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, distanceScaleEnd,
517530 scaleWithParent, enabled);
518531 }
519532
520533 void PointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) const {
534+ //V8TODO: this won't work for now
521535 QVariantMap propMap = properties.toMap();
522536
523537 QVariant startProps;
@@ -546,3 +560,52 @@ QVariantMap PointerScriptingInterface::getPrevPickResult(unsigned int uid) const · 22 unmodified lines
546560 }
547561 return result;
548562 }
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+}