History

more overlay wip

SamGondelman committed 7 years ago

Commit 5ce8f561 parent ca8d64b62 files · +620 −864Browse files

Showing the changes to interface/src/ui/Keyboard.cpp (1 of 62 files). Show all

Unified · Split

interface/src/ui/Keyboard.cpp+239−282
@@ -33,11 +33,6 @@ · 32 unmodified lines
3333 #include <RegisteredMetaTypes.h>
3434 #include <ui/TabletScriptingInterface.h>
3535
36−#include "ui/overlays/Overlays.h"
37−#include "ui/overlays/Overlay.h"
38−#include "ui/overlays/ModelOverlay.h"
39−#include "ui/overlays/Cube3DOverlay.h"
40−#include "ui/overlays/Text3DOverlay.h"
4136 #include "avatar/AvatarManager.h"
4237 #include "avatar/MyAvatar.h"
4338 #include "avatar/AvatarManager.h"
@@ -120,21 +115,21 @@ std::pair<glm::vec3, glm::quat> calculateKeyboardPositionAndOrientation() { · 76 unmodified lines
120115 float sensorToWorldScale = myAvatar->getSensorToWorldScale();
121116 QUuid tabletID = hmd->getCurrentTabletFrameID();
122117 if (!tabletID.isNull() && hmd->getShouldShowTablet()) {
123− Overlays& overlays = qApp->getOverlays();
124− auto tabletOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(tabletID));
125− if (tabletOverlay) {
126− auto tablet = DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system");
127− bool landscapeMode = tablet->getLandscape();
128− glm::vec3 keyboardOffset = landscapeMode ? KEYBOARD_TABLET_LANDSCAPE_OFFSET : KEYBOARD_TABLET_OFFSET;
129− glm::vec3 keyboardDegreesOffset = landscapeMode ? KEYBOARD_TABLET_LANDSCAPE_DEGREES_OFFSET : KEYBOARD_TABLET_DEGREES_OFFSET;
130− glm::vec3 tabletWorldPosition = tabletOverlay->getWorldPosition();
131− glm::quat tabletWorldOrientation = tabletOverlay->getWorldOrientation();
132− glm::vec3 scaledKeyboardTabletOffset = keyboardOffset * sensorToWorldScale;
133−
134− keyboardLocation.first = tabletWorldPosition + (tabletWorldOrientation * scaledKeyboardTabletOffset);
135− keyboardLocation.second = tabletWorldOrientation * glm::quat(glm::radians(keyboardDegreesOffset));
136− }
118+ EntityPropertyFlags desiredProperties;
119+ desiredProperties += PROP_POSITION;
120+ desiredProperties += PROP_ROTATION;
121+ auto properties = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(tabletID, desiredProperties);
137122
123+ auto tablet = DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system");
124+ bool landscapeMode = tablet->getLandscape();
125+ glm::vec3 keyboardOffset = landscapeMode ? KEYBOARD_TABLET_LANDSCAPE_OFFSET : KEYBOARD_TABLET_OFFSET;
126+ glm::vec3 keyboardDegreesOffset = landscapeMode ? KEYBOARD_TABLET_LANDSCAPE_DEGREES_OFFSET : KEYBOARD_TABLET_DEGREES_OFFSET;
127+ glm::vec3 tabletWorldPosition = properties.getPosition();
128+ glm::quat tabletWorldOrientation = properties.getRotation();
129+ glm::vec3 scaledKeyboardTabletOffset = keyboardOffset * sensorToWorldScale;
130+
131+ keyboardLocation.first = tabletWorldPosition + (tabletWorldOrientation * scaledKeyboardTabletOffset);
132+ keyboardLocation.second = tabletWorldOrientation * glm::quat(glm::radians(keyboardDegreesOffset));
138133 } else {
139134 glm::vec3 avatarWorldPosition = myAvatar->getWorldPosition();
140135 glm::quat avatarWorldOrientation = myAvatar->getWorldOrientation();
@@ -148,32 +143,25 @@ std::pair<glm::vec3, glm::quat> calculateKeyboardPositionAndOrientation() { · 7 unmodified lines
148143 }
149144
150145 void Key::saveDimensionsAndLocalPosition() {
151− Overlays& overlays = qApp->getOverlays();
152− auto model3DOverlay = std::dynamic_pointer_cast<ModelOverlay>(overlays.getOverlay(_keyID));
146+ EntityPropertyFlags desiredProperties;
147+ desiredProperties += PROP_LOCAL_POSITION;
148+ desiredProperties += PROP_DIMENSIONS;
149+ auto properties = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(_keyID, desiredProperties);
153150
154− if (model3DOverlay) {
155− _originalLocalPosition = model3DOverlay->getLocalPosition();
156− _originalDimensions = model3DOverlay->getDimensions();
157− _currentLocalPosition = _originalLocalPosition;
158− }
151+ _originalLocalPosition = properties.getLocalPosition();
152+ _originalDimensions = properties.getDimensions();
153+ _currentLocalPosition = _originalLocalPosition;
159154 }
160155
161156 void Key::scaleKey(float sensorToWorldScale) {
162− Overlays& overlays = qApp->getOverlays();
163− auto model3DOverlay = std::dynamic_pointer_cast<ModelOverlay>(overlays.getOverlay(_keyID));
164−
165− if (model3DOverlay) {
166− glm::vec3 scaledLocalPosition = _originalLocalPosition * sensorToWorldScale;
167− glm::vec3 scaledDimensions = _originalDimensions * sensorToWorldScale;
168− _currentLocalPosition = scaledLocalPosition;
157+ glm::vec3 scaledLocalPosition = _originalLocalPosition * sensorToWorldScale;
158+ glm::vec3 scaledDimensions = _originalDimensions * sensorToWorldScale;
159+ _currentLocalPosition = scaledLocalPosition;
169160
170− QVariantMap properties {
171− { "dimensions", vec3toVariant(scaledDimensions) },
172− { "localPosition", vec3toVariant(scaledLocalPosition) }
173− };
174−
175− overlays.editOverlay(_keyID, properties);
176− }
161+ EntityItemProperties properties;
162+ properties.setDimensions(scaledDimensions);
163+ properties.setLocalPosition(scaledLocalPosition);
164+ DependencyManager::get<EntityScriptingInterface>()->editEntity(_keyID, properties);
177165 }
178166
179167 void Key::startTimer(int time) {
@@ -262,21 +250,21 @@ void Keyboard::createKeyboard() { · 82 unmodified lines
262250
263251 QVariantMap leftStylusProperties {
264252 { "hand", LEFT_HAND_CONTROLLER_INDEX },
265− { "filter", PickScriptingInterface::PICK_OVERLAYS() },
253+ { "filter", PickScriptingInterface::PICK_LOCAL_ENTITIES() },
266254 { "model", modelProperties },
267255 { "tipOffset", vec3toVariant(MALLET_TIP_OFFSET) }
268256 };
269257
270258 QVariantMap rightStylusProperties {
271259 { "hand", RIGHT_HAND_CONTROLLER_INDEX },
272− { "filter", PickScriptingInterface::PICK_OVERLAYS() },
260+ { "filter", PickScriptingInterface::PICK_LOCAL_ENTITIES() },
273261 { "model", modelProperties },
274262 { "tipOffset", vec3toVariant(MALLET_TIP_OFFSET) }
275263 };
276264
277− _leftHandStylus = pointerManager->addPointer(std::make_shared<StylusPointer>(leftStylusProperties, StylusPointer::buildStylusOverlay(leftStylusProperties), true, true,
265+ _leftHandStylus = pointerManager->addPointer(std::make_shared<StylusPointer>(leftStylusProperties, StylusPointer::buildStylus(leftStylusProperties), true, true,
278266 MALLET_POSITION_OFFSET, MALLET_ROTATION_OFFSET, MALLET_MODEL_DIMENSIONS));
279− _rightHandStylus = pointerManager->addPointer(std::make_shared<StylusPointer>(rightStylusProperties, StylusPointer::buildStylusOverlay(rightStylusProperties), true, true,
267+ _rightHandStylus = pointerManager->addPointer(std::make_shared<StylusPointer>(rightStylusProperties, StylusPointer::buildStylus(rightStylusProperties), true, true,
280268 MALLET_POSITION_OFFSET, MALLET_ROTATION_OFFSET, MALLET_MODEL_DIMENSIONS));
281269
282270 pointerManager->disablePointer(_rightHandStylus);
@@ -312,93 +300,70 @@ void Keyboard::setRaised(bool raised) { · 29 unmodified lines
312300 }
313301
314302 void Keyboard::updateTextDisplay() {
315− Overlays& overlays = qApp->getOverlays();
316−
317303 auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
304+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
318305 float sensorToWorldScale = myAvatar->getSensorToWorldScale();
319− float textWidth = (float) overlays.textSize(_textDisplay.overlayID, _typedCharacters).width();
306+ float textWidth = (float)entityScriptingInterface->textSize(_textDisplay.entityID, _typedCharacters).width();
320307
321308 glm::vec3 scaledDimensions = _textDisplay.dimensions;
322309 scaledDimensions *= sensorToWorldScale;
323310 float leftMargin = (scaledDimensions.x / 2);
324311 scaledDimensions.x += textWidth;
325312
326−
327− QVariantMap textDisplayProperties {
328− { "dimensions", vec3toVariant(scaledDimensions) },
329− { "leftMargin", leftMargin },
330− { "text", _typedCharacters },
331− { "lineHeight", (_textDisplay.lineHeight * sensorToWorldScale) }
332− };
333−
334− overlays.editOverlay(_textDisplay.overlayID, textDisplayProperties);
313+ EntityItemProperties properties;
314+ properties.setDimensions(scaledDimensions);
315+ properties.setLeftMargin(leftMargin);
316+ properties.setText(_typedCharacters);
317+ properties.setLineHeight(_textDisplay.lineHeight * sensorToWorldScale);
318+ entityScriptingInterface->editEntity(_textDisplay.entityID, properties);
335319 }
336320
337321 void Keyboard::raiseKeyboardAnchor(bool raise) const {
338− Overlays& overlays = qApp->getOverlays();
339− OverlayID anchorOverlayID = _anchor.overlayID;
340− auto anchorOverlay = std::dynamic_pointer_cast<Cube3DOverlay>(overlays.getOverlay(anchorOverlayID));
341− if (anchorOverlay) {
342− std::pair<glm::vec3, glm::quat> keyboardLocation = calculateKeyboardPositionAndOrientation();
343− if (_resetKeyboardPositionOnRaise) {
344− anchorOverlay->setWorldPosition(keyboardLocation.first);
345− anchorOverlay->setWorldOrientation(keyboardLocation.second);
346− }
347− anchorOverlay->setVisible(raise);
348−
349− QVariantMap textDisplayProperties {
350− { "visible", raise }
351− };
322+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
352323
353− overlays.editOverlay(_textDisplay.overlayID, textDisplayProperties);
324+ EntityItemProperties properties;
325+ properties.setVisible(raise);
354326
355− auto backPlateOverlay = std::dynamic_pointer_cast<Cube3DOverlay>(overlays.getOverlay(_backPlate.overlayID));
327+ entityScriptingInterface->editEntity(_textDisplay.entityID, properties);
328+ entityScriptingInterface->editEntity(_backPlate.entityID, properties);
356329
357− if (backPlateOverlay) {
358− backPlateOverlay->setVisible(raise);
359− }
330+ if (_resetKeyboardPositionOnRaise) {
331+ std::pair<glm::vec3, glm::quat> keyboardLocation = calculateKeyboardPositionAndOrientation();
332+ properties.setPosition(keyboardLocation.first);
333+ properties.setRotation(keyboardLocation.second);
360334 }
335+ entityScriptingInterface->editEntity(_anchor.entityID, properties);
361336 }
362337
363338 void Keyboard::scaleKeyboard(float sensorToWorldScale) {
364− Overlays& overlays = qApp->getOverlays();
365−
366− glm::vec3 scaledDimensions = _anchor.originalDimensions * sensorToWorldScale;
367− auto volume3DOverlay = std::dynamic_pointer_cast<Volume3DOverlay>(overlays.getOverlay(_anchor.overlayID));
339+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
368340
369− if (volume3DOverlay) {
370− volume3DOverlay->setDimensions(scaledDimensions);
341+ {
342+ EntityItemProperties properties;
343+ properties.setDimensions(_anchor.originalDimensions * sensorToWorldScale);
344+ entityScriptingInterface->editEntity(_anchor.entityID, properties);
371345 }
372346
373− for (auto& keyboardLayer: _keyboardLayers) {
347+ for (auto& keyboardLayer : _keyboardLayers) {
374348 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {
375349 iter.value().scaleKey(sensorToWorldScale);
376350 }
377351 }
378352
353+ {
354+ EntityItemProperties properties;
355+ properties.setLocalPosition(_textDisplay.localPosition * sensorToWorldScale);
356+ properties.setDimensions(_textDisplay.dimensions * sensorToWorldScale);
357+ properties.setLineHeight(_textDisplay.lineHeight * sensorToWorldScale);
358+ entityScriptingInterface->editEntity(_textDisplay.entityID, properties);
359+ }
379360
380−
381− glm::vec3 scaledLocalPosition = _textDisplay.localPosition * sensorToWorldScale;
382− glm::vec3 textDisplayScaledDimensions = _textDisplay.dimensions * sensorToWorldScale;
383−
384− QVariantMap textDisplayProperties {
385− { "localPosition", vec3toVariant(scaledLocalPosition) },
386− { "dimensions", vec3toVariant(textDisplayScaledDimensions) },
387− { "lineHeight", (_textDisplay.lineHeight * sensorToWorldScale) }
388− };
389−
390− overlays.editOverlay(_textDisplay.overlayID, textDisplayProperties);
391−
392−
393− glm::vec3 backPlateScaledDimensions = _backPlate.dimensions * sensorToWorldScale;
394− glm::vec3 backPlateScaledLocalPosition = _backPlate.localPosition * sensorToWorldScale;
395−
396− QVariantMap backPlateProperties {
397− { "localPosition", vec3toVariant(backPlateScaledLocalPosition) },
398− { "dimensions", vec3toVariant(backPlateScaledDimensions) }
399− };
400−
401− overlays.editOverlay(_backPlate.overlayID, backPlateProperties);
361+ {
362+ EntityItemProperties properties;
363+ properties.setLocalPosition(_backPlate.localPosition * sensorToWorldScale);
364+ properties.setDimensions(_backPlate.dimensions * sensorToWorldScale);
365+ entityScriptingInterface->editEntity(_backPlate.entityID, properties);
366+ }
402367 }
403368
404369 void Keyboard::startLayerSwitchTimer() {
@@ -419,13 +384,12 @@ void Keyboard::raiseKeyboard(bool raise) const { · 14 unmodified lines
419384 if (_keyboardLayers.empty()) {
420385 return;
421386 }
422− Overlays& overlays = qApp->getOverlays();
387+
423388 const auto& keyboardLayer = _keyboardLayers[_layerIndex];
389+ EntityItemProperties properties;
390+ properties.setVisible(raise);
424391 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {
425− auto base3DOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(iter.key()));
426− if (base3DOverlay) {
427− base3DOverlay->setVisible(raise);
428− }
392+ DependencyManager::get<EntityScriptingInterface>()->editEntity(iter.key(), properties);
429393 }
430394 }
431395
@@ -465,19 +429,15 @@ bool Keyboard::getPreferMalletsOverLasers() const { · 33 unmodified lines
465429 }
466430
467431 void Keyboard::switchToLayer(int layerIndex) {
432+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
468433 if (layerIndex >= 0 && layerIndex < (int)_keyboardLayers.size()) {
469− Overlays& overlays = qApp->getOverlays();
470−
471− OverlayID currentAnchorOverlayID = _anchor.overlayID;
472−
473− glm::vec3 currentOverlayPosition;
474− glm::quat currentOverlayOrientation;
434+ EntityPropertyFlags desiredProperties;
435+ desiredProperties += PROP_POSITION;
436+ desiredProperties += PROP_ROTATION;
437+ auto oldProperties = entityScriptingInterface->getEntityProperties(_anchor.entityID, desiredProperties);
475438
476− auto currentAnchorOverlay = std::dynamic_pointer_cast<Cube3DOverlay>(overlays.getOverlay(currentAnchorOverlayID));
477− if (currentAnchorOverlay) {
478− currentOverlayPosition = currentAnchorOverlay->getWorldPosition();
479− currentOverlayOrientation = currentAnchorOverlay->getWorldOrientation();
480− }
439+ glm::vec3 currentPosition = oldProperties.getPosition();
440+ glm::quat currentOrientation = oldProperties.getRotation();
481441
482442 raiseKeyboardAnchor(false);
483443 raiseKeyboard(false);
@@ -487,19 +447,17 @@ void Keyboard::switchToLayer(int layerIndex) { · 3 unmodified lines
487447 raiseKeyboardAnchor(true);
488448 raiseKeyboard(true);
489449
490− OverlayID newAnchorOverlayID = _anchor.overlayID;
491− auto newAnchorOverlay = std::dynamic_pointer_cast<Cube3DOverlay>(overlays.getOverlay(newAnchorOverlayID));
492− if (newAnchorOverlay) {
493− newAnchorOverlay->setWorldPosition(currentOverlayPosition);
494− newAnchorOverlay->setWorldOrientation(currentOverlayOrientation);
495− }
450+ EntityItemProperties properties;
451+ properties.setPosition(currentPosition);
452+ properties.setRotation(currentOrientation);
453+ entityScriptingInterface->editEntity(_anchor.entityID, properties);
496454
497455 startLayerSwitchTimer();
498456 }
499457 }
500458
501−bool Keyboard::shouldProcessOverlayAndPointerEvent(const PointerEvent& event, const OverlayID& overlayID) const {
502− return (shouldProcessPointerEvent(event) && shouldProcessOverlay(overlayID));
459+bool Keyboard::shouldProcessEntityAndPointerEvent(const PointerEvent& event, const QUuid& id) const {
460+ return (shouldProcessPointerEvent(event) && shouldProcessEntity(id));
503461 }
504462
505463 bool Keyboard::shouldProcessPointerEvent(const PointerEvent& event) const {
@@ -510,14 +468,14 @@ bool Keyboard::shouldProcessPointerEvent(const PointerEvent& event) const { · 4 unmodified lines
510468 return ((isStylusEvent && preferMalletsOverLasers) || (isLaserEvent && !preferMalletsOverLasers));
511469 }
512470
513−void Keyboard::handleTriggerBegin(const OverlayID& overlayID, const PointerEvent& event) {
471+void Keyboard::handleTriggerBegin(const QUuid& id, const PointerEvent& event) {
514472 auto buttonType = event.getButton();
515− if (!shouldProcessOverlayAndPointerEvent(event, overlayID) || buttonType != PointerEvent::PrimaryButton) {
473+ if (!shouldProcessEntityAndPointerEvent(event, id) || buttonType != PointerEvent::PrimaryButton) {
516474 return;
517475 }
518476
519477 auto& keyboardLayer = _keyboardLayers[_layerIndex];
520− auto search = keyboardLayer.find(overlayID);
478+ auto search = keyboardLayer.find(id);
521479
522480 if (search == keyboardLayer.end()) {
523481 return;
@@ -533,13 +491,9 @@ void Keyboard::handleTriggerBegin(const OverlayID& overlayID, const PointerEvent · 9 unmodified lines
533491 auto userInputMapper = DependencyManager::get<UserInputMapper>();
534492 userInputMapper->triggerHapticPulse(PULSE_STRENGTH, PULSE_DURATION, handIndex);
535493
536− Overlays& overlays = qApp->getOverlays();
537− auto base3DOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(overlayID));
538−
539− glm::vec3 keyWorldPosition;
540− if (base3DOverlay) {
541− keyWorldPosition = base3DOverlay->getWorldPosition();
542− }
494+ EntityPropertyFlags desiredProperties;
495+ desiredProperties += PROP_POSITION;
496+ glm::vec3 keyWorldPosition = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(id, desiredProperties).getPosition();
543497
544498 AudioInjectorOptions audioOptions;
545499 audioOptions.localOnly = true;
@@ -601,7 +555,7 @@ void Keyboard::handleTriggerBegin(const OverlayID& overlayID, const PointerEvent · 55 unmodified lines
601555 key.startTimer(KEY_PRESS_TIMEOUT_MS);
602556 }
603557 auto selection = DependencyManager::get<SelectionScriptingInterface>();
604− selection->addToSelectedItemsList(KEY_PRESSED_HIGHLIGHT, "overlay", overlayID);
558+ selection->addToSelectedItemsList(KEY_PRESSED_HIGHLIGHT, "entity", id);
605559 }
606560 }
607561
@@ -617,25 +571,23 @@ void Keyboard::setRightHandLaser(unsigned int rightHandLaser) { · 9 unmodified lines
617571 });
618572 }
619573
620−void Keyboard::handleTriggerEnd(const OverlayID& overlayID, const PointerEvent& event) {
621− if (!shouldProcessOverlayAndPointerEvent(event, overlayID)) {
574+void Keyboard::handleTriggerEnd(const QUuid& id, const PointerEvent& event) {
575+ if (!shouldProcessEntityAndPointerEvent(event, id)) {
622576 return;
623577 }
624578
625579 auto& keyboardLayer = _keyboardLayers[_layerIndex];
626− auto search = keyboardLayer.find(overlayID);
580+ auto search = keyboardLayer.find(id);
627581
628582 if (search == keyboardLayer.end()) {
629583 return;
630584 }
631585
632− Key& key = search.value();;
633− Overlays& overlays = qApp->getOverlays();
634− auto base3DOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(overlayID));
586+ Key& key = search.value();
635587
636− if (base3DOverlay) {
637− base3DOverlay->setLocalPosition(key.getCurrentLocalPosition());
638− }
588+ EntityItemProperties properties;
589+ properties.setLocalPosition(key.getCurrentLocalPosition());
590+ DependencyManager::get<EntityScriptingInterface>()->editEntity(id, properties);
639591
640592 key.setIsPressed(false);
641593 if (key.timerFinished() && getPreferMalletsOverLasers()) {
@@ -643,78 +595,79 @@ void Keyboard::handleTriggerEnd(const OverlayID& overlayID, const PointerEvent& · 1 unmodified line
643595 }
644596
645597 auto selection = DependencyManager::get<SelectionScriptingInterface>();
646− selection->removeFromSelectedItemsList(KEY_PRESSED_HIGHLIGHT, "overlay", overlayID);
598+ selection->removeFromSelectedItemsList(KEY_PRESSED_HIGHLIGHT, "entity", id);
647599 }
648600
649−void Keyboard::handleTriggerContinue(const OverlayID& overlayID, const PointerEvent& event) {
650− if (!shouldProcessOverlayAndPointerEvent(event, overlayID)) {
601+void Keyboard::handleTriggerContinue(const QUuid& id, const PointerEvent& event) {
602+ if (!shouldProcessEntityAndPointerEvent(event, id)) {
651603 return;
652604 }
653605
654606 auto& keyboardLayer = _keyboardLayers[_layerIndex];
655− auto search = keyboardLayer.find(overlayID);
607+ auto search = keyboardLayer.find(id);
656608
657609 if (search == keyboardLayer.end()) {
658610 return;
659611 }
660612
661613 Key& key = search.value();
662− Overlays& overlays = qApp->getOverlays();
663−
664614 if (!key.isPressed() && getPreferMalletsOverLasers()) {
665− auto base3DOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(overlayID));
666−
667− if (base3DOverlay) {
668− unsigned int pointerID = event.getID();
669− auto pointerManager = DependencyManager::get<PointerManager>();
670− auto pickResult = pointerManager->getPrevPickResult(pointerID);
671− auto stylusPickResult = std::dynamic_pointer_cast<StylusPickResult>(pickResult);
672− float distance = stylusPickResult->distance;
673−
674− static const float PENATRATION_THRESHOLD = 0.025f;
675− if (distance < PENATRATION_THRESHOLD) {
676− static const float Z_OFFSET = 0.002f;
677− glm::quat overlayOrientation = base3DOverlay->getWorldOrientation();
678− glm::vec3 overlayYAxis = overlayOrientation * Z_AXIS;
679− glm::vec3 overlayYOffset = overlayYAxis * Z_OFFSET;
680− glm::vec3 localPosition = key.getCurrentLocalPosition() - overlayYOffset;
681− base3DOverlay->setLocalPosition(localPosition);
682− key.setIsPressed(true);
683− }
615+ unsigned int pointerID = event.getID();
616+ auto pointerManager = DependencyManager::get<PointerManager>();
617+ auto pickResult = pointerManager->getPrevPickResult(pointerID);
618+ auto stylusPickResult = std::dynamic_pointer_cast<StylusPickResult>(pickResult);
619+ float distance = stylusPickResult->distance;
620+
621+ static const float PENATRATION_THRESHOLD = 0.025f;
622+ if (distance < PENATRATION_THRESHOLD) {
623+ static const float Z_OFFSET = 0.002f;
624+
625+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
626+ EntityPropertyFlags desiredProperties;
627+ desiredProperties += PROP_ROTATION;
628+ glm::quat orientation = entityScriptingInterface->getEntityProperties(id, desiredProperties).getRotation();
629+ glm::vec3 yAxis = orientation * Z_AXIS;
630+ glm::vec3 yOffset = yAxis * Z_OFFSET;
631+ glm::vec3 localPosition = key.getCurrentLocalPosition() - yOffset;
632+
633+ EntityItemProperties properties;
634+ properties.setLocalPosition(localPosition);
635+ entityScriptingInterface->editEntity(id, properties);
636+ key.setIsPressed(true);
684637 }
685638 }
686639 }
687640
688−void Keyboard::handleHoverBegin(const OverlayID& overlayID, const PointerEvent& event) {
689− if (!shouldProcessOverlayAndPointerEvent(event, overlayID)) {
641+void Keyboard::handleHoverBegin(const QUuid& id, const PointerEvent& event) {
642+ if (!shouldProcessEntityAndPointerEvent(event, id)) {
690643 return;
691644 }
692645
693646 auto& keyboardLayer = _keyboardLayers[_layerIndex];
694− auto search = keyboardLayer.find(overlayID);
647+ auto search = keyboardLayer.find(id);
695648
696649 if (search == keyboardLayer.end()) {
697650 return;
698651 }
699652
700653 auto selection = DependencyManager::get<SelectionScriptingInterface>();
701− selection->addToSelectedItemsList(KEY_HOVER_HIGHLIGHT, "overlay", overlayID);
654+ selection->addToSelectedItemsList(KEY_HOVER_HIGHLIGHT, "entity", id);
702655 }
703656
704−void Keyboard::handleHoverEnd(const OverlayID& overlayID, const PointerEvent& event) {
705− if (!shouldProcessOverlayAndPointerEvent(event, overlayID)) {
657+void Keyboard::handleHoverEnd(const QUuid& id, const PointerEvent& event) {
658+ if (!shouldProcessEntityAndPointerEvent(event, id)) {
706659 return;
707660 }
708661
709662 auto& keyboardLayer = _keyboardLayers[_layerIndex];
710− auto search = keyboardLayer.find(overlayID);
663+ auto search = keyboardLayer.find(id);
711664
712665 if (search == keyboardLayer.end()) {
713666 return;
714667 }
715668
716669 auto selection = DependencyManager::get<SelectionScriptingInterface>();
717− selection->removeFromSelectedItemsList(KEY_HOVER_HIGHLIGHT, "overlay", overlayID);
670+ selection->removeFromSelectedItemsList(KEY_HOVER_HIGHLIGHT, "entity", id);
718671 }
719672
720673 void Keyboard::disableStylus() {
@@ -752,7 +705,6 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 31 unmodified lines
752705 }
753706
754707 clearKeyboardKeys();
755− Overlays& overlays = qApp->getOverlays();
756708 auto requestData = request->getData();
757709
758710 QVector<QUuid> includeItems;
@@ -776,54 +728,58 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 17 unmodified lines
776728 return;
777729 }
778730
779− QVariantMap anchorProperties {
780− { "name", "KeyboardAnchor"},
781− { "isSolid", true },
782− { "visible", false },
783− { "grabbable", true },
784− { "ignorePickIntersection", false },
785− { "dimensions", anchorObject["dimensions"].toVariant() },
786− { "position", anchorObject["position"].toVariant() },
787− { "orientation", anchorObject["rotation"].toVariant() }
788− };
789−
790− glm::vec3 dimensions = vec3FromVariant(anchorObject["dimensions"].toVariant());
791−
792− Anchor anchor;
793− anchor.overlayID = overlays.addOverlay("cube", anchorProperties);
794− anchor.originalDimensions = dimensions;
795− _anchor = anchor;
796−
797− QJsonObject backPlateObject = jsonObject["backPlate"].toObject();
798−
799− QVariantMap backPlateProperties {
800− { "name", "backPlate"},
801− { "isSolid", true },
802− { "visible", true },
803− { "grabbable", false },
804− { "alpha", 0.0 },
805− { "ignoreRayIntersection", false},
806− { "dimensions", backPlateObject["dimensions"].toVariant() },
807− { "position", backPlateObject["position"].toVariant() },
808− { "orientation", backPlateObject["rotation"].toVariant() },
809− { "parentID", _anchor.overlayID }
810− };
811−
812− BackPlate backPlate;
813− backPlate.overlayID = overlays.addOverlay("cube", backPlateProperties);
814− backPlate.dimensions = vec3FromVariant(backPlateObject["dimensions"].toVariant());
815− backPlate.localPosition = vec3FromVariant(overlays.getProperty(backPlate.overlayID, "localPosition").value);
816− _backPlate = backPlate;
731+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
732+ {
733+ glm::vec3 dimensions = vec3FromVariant(anchorObject["dimensions"].toVariant());
734+
735+ EntityItemProperties properties;
736+ properties.setType(EntityTypes::Box);
737+ properties.setName("KeyboardAnchor");
738+ properties.setVisible(false);
739+ properties.getGrab().setGrabbable(true);
740+ properties.setIgnorePickIntersection(false);
741+ properties.setDimensions(dimensions);
742+ properties.setPosition(vec3FromVariant(anchorObject["position"].toVariant()));
743+ properties.setRotation(quatFromVariant(anchorObject["rotation"].toVariant()));
744+
745+ Anchor anchor;
746+ anchor.entityID = entityScriptingInterface->addEntity(properties, "local");
747+ anchor.originalDimensions = dimensions;
748+ _anchor = anchor;
749+ }
750+
751+ {
752+ QJsonObject backPlateObject = jsonObject["backPlate"].toObject();
753+ glm::vec3 dimensions = vec3FromVariant(backPlateObject["dimensions"].toVariant());
754+
755+ EntityItemProperties properties;
756+ properties.setType(EntityTypes::Box);
757+ properties.setName("BackPlate");
758+ properties.setVisible(true);
759+ properties.getGrab().setGrabbable(false);
760+ properties.setAlpha(0.0f);
761+ properties.setIgnorePickIntersection(false);
762+ properties.setDimensions(dimensions);
763+ properties.setPosition(vec3FromVariant(backPlateObject["position"].toVariant()));
764+ properties.setRotation(quatFromVariant(backPlateObject["rotation"].toVariant()));
765+ properties.setParentID(_anchor.entityID);
766+
767+ BackPlate backPlate;
768+ backPlate.entityID = entityScriptingInterface->addEntity(properties, "local");
769+ backPlate.dimensions = dimensions;
770+ EntityPropertyFlags desiredProperties;
771+ desiredProperties += PROP_LOCAL_POSITION;
772+ backPlate.localPosition = entityScriptingInterface->getEntityProperties(backPlate.entityID, desiredProperties).getLocalPosition();
773+ _backPlate = backPlate;
774+ }
817775
818776 const QJsonArray& keyboardLayers = jsonObject["layers"].toArray();
819777 int keyboardLayerCount = keyboardLayers.size();
820778 _keyboardLayers.reserve(keyboardLayerCount);
821−
822−
823779 for (int keyboardLayerIndex = 0; keyboardLayerIndex < keyboardLayerCount; keyboardLayerIndex++) {
824780 const QJsonValue& keyboardLayer = keyboardLayers[keyboardLayerIndex].toArray();
825781
826− QHash<OverlayID, Key> keyboardLayerKeys;
782+ QHash<QUuid, Key> keyboardLayerKeys;
827783 foreach (const QJsonValue& keyboardKeyValue, keyboardLayer.toArray()) {
828784
829785 QVariantMap textureMap;
@@ -841,21 +797,6 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 11 unmodified lines
841797 QString modelUrl = keyboardKeyValue["modelURL"].toString();
842798 QString url = (useResourcePath ? (resourcePath + modelUrl) : modelUrl);
843799
844− QVariantMap properties {
845− { "dimensions", keyboardKeyValue["dimensions"].toVariant() },
846− { "position", keyboardKeyValue["position"].toVariant() },
847− { "visible", false },
848− { "isSolid", true },
849− { "emissive", true },
850− { "parentID", _anchor.overlayID },
851− { "url", url },
852− { "textures", textureMap },
853− { "grabbable", false },
854− { "localOrientation", keyboardKeyValue["localOrientation"].toVariant() }
855− };
856−
857− OverlayID overlayID = overlays.addOverlay("model", properties);
858−
859800 QString keyType = keyboardKeyValue["type"].toString();
860801 QString keyString = keyboardKeyValue["key"].toString();
861802
@@ -869,48 +810,65 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 7 unmodified lines
869810 key.setSwitchToLayerIndex(switchToLayer);
870811 }
871812 }
872− key.setID(overlayID);
813+
814+ EntityItemProperties properties;
815+ properties.setType(EntityTypes::Model);
816+ properties.setDimensions(vec3FromVariant(keyboardKeyValue["dimensions"].toVariant()));
817+ properties.setPosition(vec3FromVariant(keyboardKeyValue["position"].toVariant()));
818+ properties.setVisible(false);
819+ properties.setEmissive(true);
820+ properties.setParentID(_anchor.entityID);
821+ properties.setModelURL(url);
822+ properties.setTextures(QVariant(textureMap).toString());
823+ properties.getGrab().setGrabbable(false);
824+ properties.setLocalRotation(quatFromVariant(keyboardKeyValue["localOrientation"].toVariant()));
825+ QUuid id = entityScriptingInterface->addEntity(properties, "local");
826+ key.setID(id);
873827 key.setKeyString(keyString);
874828 key.saveDimensionsAndLocalPosition();
875829
876830 includeItems.append(key.getID());
877831 _itemsToIgnore.append(key.getID());
878− keyboardLayerKeys.insert(overlayID, key);
832+ keyboardLayerKeys.insert(id, key);
879833 }
880834
881835 _keyboardLayers.push_back(keyboardLayerKeys);
882836
883837 }
884838
885− TextDisplay textDisplay;
886− QJsonObject displayTextObject = jsonObject["textDisplay"].toObject();
887−
888− QVariantMap displayTextProperties {
889− { "dimensions", displayTextObject["dimensions"].toVariant() },
890− { "localPosition", displayTextObject["localPosition"].toVariant() },
891− { "localOrientation", displayTextObject["localOrientation"].toVariant() },
892− { "leftMargin", displayTextObject["leftMargin"].toVariant() },
893− { "rightMargin", displayTextObject["rightMargin"].toVariant() },
894− { "topMargin", displayTextObject["topMargin"].toVariant() },
895− { "bottomMargin", displayTextObject["bottomMargin"].toVariant() },
896− { "lineHeight", displayTextObject["lineHeight"].toVariant() },
897− { "visible", false },
898− { "emissive", true },
899− { "grabbable", false },
900− { "text", ""},
901− { "parentID", _anchor.overlayID }
902− };
903−
904− textDisplay.overlayID = overlays.addOverlay("text3d", displayTextProperties);
905− textDisplay.localPosition = vec3FromVariant(displayTextObject["localPosition"].toVariant());
906− textDisplay.dimensions = vec3FromVariant(displayTextObject["dimensions"].toVariant());
907− textDisplay.lineHeight = (float) displayTextObject["lineHeight"].toDouble();
908−
909− _textDisplay = textDisplay;
839+ {
840+ QJsonObject displayTextObject = jsonObject["textDisplay"].toObject();
841+ glm::vec3 dimensions = vec3FromVariant(displayTextObject["dimensions"].toVariant());
842+ glm::vec3 localPosition = vec3FromVariant(displayTextObject["localPosition"].toVariant());
843+ float lineHeight = (float)displayTextObject["lineHeight"].toDouble();
844+
845+ EntityItemProperties properties;
846+ properties.setType(EntityTypes::Text);
847+ properties.setDimensions(dimensions);
848+ properties.setLocalPosition(localPosition);
849+ properties.setLocalRotation(quatFromVariant(displayTextObject["localOrientation"].toVariant()));
850+ properties.setLeftMargin((float)displayTextObject["leftMargin"].toDouble());
851+ properties.setRightMargin((float)displayTextObject["rightMargin"].toDouble());
852+ properties.setTopMargin((float)displayTextObject["topMargin"].toDouble());
853+ properties.setBottomMargin((float)displayTextObject["bottomMargin"].toDouble());
854+ properties.setLineHeight((float)displayTextObject["lineHeight"].toDouble());
855+ properties.setVisible(false);
856+ properties.setEmissive(true);
857+ properties.getGrab().setGrabbable(false);
858+ properties.setText("");
859+ properties.setParentID(_anchor.entityID);
860+
861+ TextDisplay textDisplay;
862+ textDisplay.entityID = entityScriptingInterface->addEntity(properties, "local");
863+ textDisplay.localPosition = localPosition;
864+ textDisplay.dimensions = dimensions;
865+ textDisplay.lineHeight = lineHeight;
866+ _textDisplay = textDisplay;
867+ }
910868
911869 _ignoreItemsLock.withWriteLock([&] {
912− _itemsToIgnore.append(_textDisplay.overlayID);
913− _itemsToIgnore.append(_anchor.overlayID);
870+ _itemsToIgnore.append(_textDisplay.entityID);
871+ _itemsToIgnore.append(_anchor.entityID);
914872 });
915873 _layerIndex = 0;
916874 auto pointerManager = DependencyManager::get<PointerManager>();
@@ -922,34 +880,33 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 5 unmodified lines
922880 }
923881
924882
925−OverlayID Keyboard::getAnchorID() {
926− return _ignoreItemsLock.resultWithReadLock<OverlayID>([&] {
927− return _anchor.overlayID;
883+QUuid Keyboard::getAnchorID() {
884+ return _ignoreItemsLock.resultWithReadLock<QUuid>([&] {
885+ return _anchor.entityID;
928886 });
929887 }
930888
931−bool Keyboard::shouldProcessOverlay(const OverlayID& overlayID) const {
932− return (!_keyboardLayers.empty() && isLayerSwitchTimerFinished() && overlayID != _backPlate.overlayID);
889+bool Keyboard::shouldProcessEntity(const QUuid& id) const {
890+ return (!_keyboardLayers.empty() && isLayerSwitchTimerFinished() && id != _backPlate.entityID);
933891 }
934892
935−QVector<OverlayID> Keyboard::getKeysID() {
936− return _ignoreItemsLock.resultWithReadLock<QVector<OverlayID>>([&] {
893+QVector<QUuid> Keyboard::getKeysID() {
894+ return _ignoreItemsLock.resultWithReadLock<QVector<QUuid>>([&] {
937895 return _itemsToIgnore;
938896 });
939897 }
940898
941899 void Keyboard::clearKeyboardKeys() {
942− Overlays& overlays = qApp->getOverlays();
943−
900+ auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
944901 for (const auto& keyboardLayer: _keyboardLayers) {
945902 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {
946− overlays.deleteOverlay(iter.key());
903+ entityScriptingInterface->deleteEntity(iter.key());
947904 }
948905 }
949906
950− overlays.deleteOverlay(_anchor.overlayID);
951− overlays.deleteOverlay(_textDisplay.overlayID);
952− overlays.deleteOverlay(_backPlate.overlayID);
907+ entityScriptingInterface->deleteEntity(_anchor.entityID);
908+ entityScriptingInterface->deleteEntity(_textDisplay.entityID);
909+ entityScriptingInterface->deleteEntity(_backPlate.entityID);
953910
954911 _keyboardLayers.clear();
955912
@@ -989,8 +946,8 @@ void Keyboard::disableRightMallet() { · 33 unmodified lines
989946 pointerManager->disablePointer(_rightHandStylus);
990947 }
991948
992−bool Keyboard::containsID(OverlayID overlayID) const {
949+bool Keyboard::containsID(const QUuid& id) const {
993950 return resultWithReadLock<bool>([&] {
994− return _itemsToIgnore.contains(overlayID) || _backPlate.overlayID == overlayID;
951+ return _itemsToIgnore.contains(id) || _backPlate.entityID == id;
995952 });
996953 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t