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
33#include <RegisteredMetaTypes.h>33#include <RegisteredMetaTypes.h>
34#include <ui/TabletScriptingInterface.h>34#include <ui/TabletScriptingInterface.h>
35 35
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"
41#include "avatar/AvatarManager.h"36#include "avatar/AvatarManager.h"
42#include "avatar/MyAvatar.h"37#include "avatar/MyAvatar.h"
43#include "avatar/AvatarManager.h"38#include "avatar/AvatarManager.h"
@@ -120,21 +115,21 @@ std::pair<glm::vec3, glm::quat> calculateKeyboardPositionAndOrientation() { · 76 unmodified lines
120 float sensorToWorldScale = myAvatar->getSensorToWorldScale();115 float sensorToWorldScale = myAvatar->getSensorToWorldScale();
121 QUuid tabletID = hmd->getCurrentTabletFrameID();116 QUuid tabletID = hmd->getCurrentTabletFrameID();
122 if (!tabletID.isNull() && hmd->getShouldShowTablet()) {117 if (!tabletID.isNull() && hmd->getShouldShowTablet()) {
123 Overlays& overlays = qApp->getOverlays();118 EntityPropertyFlags desiredProperties;
124 auto tabletOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(tabletID));119 desiredProperties += PROP_POSITION;
125 if (tabletOverlay) {120 desiredProperties += PROP_ROTATION;
126 auto tablet = DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system");121 auto properties = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(tabletID, desiredProperties);
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 }
137 122
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));
138 } else {133 } else {
139 glm::vec3 avatarWorldPosition = myAvatar->getWorldPosition();134 glm::vec3 avatarWorldPosition = myAvatar->getWorldPosition();
140 glm::quat avatarWorldOrientation = myAvatar->getWorldOrientation();135 glm::quat avatarWorldOrientation = myAvatar->getWorldOrientation();
@@ -148,32 +143,25 @@ std::pair<glm::vec3, glm::quat> calculateKeyboardPositionAndOrientation() { · 7 unmodified lines
148}143}
149 144
150void Key::saveDimensionsAndLocalPosition() {145void Key::saveDimensionsAndLocalPosition() {
151 Overlays& overlays = qApp->getOverlays();146 EntityPropertyFlags desiredProperties;
152 auto model3DOverlay = std::dynamic_pointer_cast<ModelOverlay>(overlays.getOverlay(_keyID));147 desiredProperties += PROP_LOCAL_POSITION;
148 desiredProperties += PROP_DIMENSIONS;
149 auto properties = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(_keyID, desiredProperties);
153 150
154 if (model3DOverlay) {151 _originalLocalPosition = properties.getLocalPosition();
155 _originalLocalPosition = model3DOverlay->getLocalPosition();152 _originalDimensions = properties.getDimensions();
156 _originalDimensions = model3DOverlay->getDimensions();153 _currentLocalPosition = _originalLocalPosition;
157 _currentLocalPosition = _originalLocalPosition;
158 }
159}154}
160 155
161void Key::scaleKey(float sensorToWorldScale) {156void Key::scaleKey(float sensorToWorldScale) {
162 Overlays& overlays = qApp->getOverlays();157 glm::vec3 scaledLocalPosition = _originalLocalPosition * sensorToWorldScale;
163 auto model3DOverlay = std::dynamic_pointer_cast<ModelOverlay>(overlays.getOverlay(_keyID));158 glm::vec3 scaledDimensions = _originalDimensions * sensorToWorldScale;
164 159 _currentLocalPosition = scaledLocalPosition;
165 if (model3DOverlay) {
166 glm::vec3 scaledLocalPosition = _originalLocalPosition * sensorToWorldScale;
167 glm::vec3 scaledDimensions = _originalDimensions * sensorToWorldScale;
168 _currentLocalPosition = scaledLocalPosition;
169 160
170 QVariantMap properties {161 EntityItemProperties properties;
171 { "dimensions", vec3toVariant(scaledDimensions) },162 properties.setDimensions(scaledDimensions);
172 { "localPosition", vec3toVariant(scaledLocalPosition) }163 properties.setLocalPosition(scaledLocalPosition);
173 };164 DependencyManager::get<EntityScriptingInterface>()->editEntity(_keyID, properties);
174
175 overlays.editOverlay(_keyID, properties);
176 }
177}165}
178 166
179void Key::startTimer(int time) {167void Key::startTimer(int time) {
@@ -262,21 +250,21 @@ void Keyboard::createKeyboard() { · 82 unmodified lines
262 250
263 QVariantMap leftStylusProperties {251 QVariantMap leftStylusProperties {
264 { "hand", LEFT_HAND_CONTROLLER_INDEX },252 { "hand", LEFT_HAND_CONTROLLER_INDEX },
265 { "filter", PickScriptingInterface::PICK_OVERLAYS() },253 { "filter", PickScriptingInterface::PICK_LOCAL_ENTITIES() },
266 { "model", modelProperties },254 { "model", modelProperties },
267 { "tipOffset", vec3toVariant(MALLET_TIP_OFFSET) }255 { "tipOffset", vec3toVariant(MALLET_TIP_OFFSET) }
268 };256 };
269 257
270 QVariantMap rightStylusProperties {258 QVariantMap rightStylusProperties {
271 { "hand", RIGHT_HAND_CONTROLLER_INDEX },259 { "hand", RIGHT_HAND_CONTROLLER_INDEX },
272 { "filter", PickScriptingInterface::PICK_OVERLAYS() },260 { "filter", PickScriptingInterface::PICK_LOCAL_ENTITIES() },
273 { "model", modelProperties },261 { "model", modelProperties },
274 { "tipOffset", vec3toVariant(MALLET_TIP_OFFSET) }262 { "tipOffset", vec3toVariant(MALLET_TIP_OFFSET) }
275 };263 };
276 264
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,
278 MALLET_POSITION_OFFSET, MALLET_ROTATION_OFFSET, MALLET_MODEL_DIMENSIONS));266 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,
280 MALLET_POSITION_OFFSET, MALLET_ROTATION_OFFSET, MALLET_MODEL_DIMENSIONS));268 MALLET_POSITION_OFFSET, MALLET_ROTATION_OFFSET, MALLET_MODEL_DIMENSIONS));
281 269
282 pointerManager->disablePointer(_rightHandStylus);270 pointerManager->disablePointer(_rightHandStylus);
@@ -312,93 +300,70 @@ void Keyboard::setRaised(bool raised) { · 29 unmodified lines
312}300}
313 301
314void Keyboard::updateTextDisplay() {302void Keyboard::updateTextDisplay() {
315 Overlays& overlays = qApp->getOverlays();
316
317 auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();303 auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
304 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
318 float sensorToWorldScale = myAvatar->getSensorToWorldScale();305 float sensorToWorldScale = myAvatar->getSensorToWorldScale();
319 float textWidth = (float) overlays.textSize(_textDisplay.overlayID, _typedCharacters).width();306 float textWidth = (float)entityScriptingInterface->textSize(_textDisplay.entityID, _typedCharacters).width();
320 307
321 glm::vec3 scaledDimensions = _textDisplay.dimensions;308 glm::vec3 scaledDimensions = _textDisplay.dimensions;
322 scaledDimensions *= sensorToWorldScale;309 scaledDimensions *= sensorToWorldScale;
323 float leftMargin = (scaledDimensions.x / 2);310 float leftMargin = (scaledDimensions.x / 2);
324 scaledDimensions.x += textWidth;311 scaledDimensions.x += textWidth;
325 312
326 313 EntityItemProperties properties;
327 QVariantMap textDisplayProperties {314 properties.setDimensions(scaledDimensions);
328 { "dimensions", vec3toVariant(scaledDimensions) },315 properties.setLeftMargin(leftMargin);
329 { "leftMargin", leftMargin },316 properties.setText(_typedCharacters);
330 { "text", _typedCharacters },317 properties.setLineHeight(_textDisplay.lineHeight * sensorToWorldScale);
331 { "lineHeight", (_textDisplay.lineHeight * sensorToWorldScale) }318 entityScriptingInterface->editEntity(_textDisplay.entityID, properties);
332 };
333
334 overlays.editOverlay(_textDisplay.overlayID, textDisplayProperties);
335}319}
336 320
337void Keyboard::raiseKeyboardAnchor(bool raise) const {321void Keyboard::raiseKeyboardAnchor(bool raise) const {
338 Overlays& overlays = qApp->getOverlays();322 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
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 };
352 323
353 overlays.editOverlay(_textDisplay.overlayID, textDisplayProperties);324 EntityItemProperties properties;
325 properties.setVisible(raise);
354 326
355 auto backPlateOverlay = std::dynamic_pointer_cast<Cube3DOverlay>(overlays.getOverlay(_backPlate.overlayID));327 entityScriptingInterface->editEntity(_textDisplay.entityID, properties);
328 entityScriptingInterface->editEntity(_backPlate.entityID, properties);
356 329
357 if (backPlateOverlay) {330 if (_resetKeyboardPositionOnRaise) {
358 backPlateOverlay->setVisible(raise);331 std::pair<glm::vec3, glm::quat> keyboardLocation = calculateKeyboardPositionAndOrientation();
359 }332 properties.setPosition(keyboardLocation.first);
333 properties.setRotation(keyboardLocation.second);
360 }334 }
335 entityScriptingInterface->editEntity(_anchor.entityID, properties);
361}336}
362 337
363void Keyboard::scaleKeyboard(float sensorToWorldScale) {338void Keyboard::scaleKeyboard(float sensorToWorldScale) {
364 Overlays& overlays = qApp->getOverlays();339 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
365
366 glm::vec3 scaledDimensions = _anchor.originalDimensions * sensorToWorldScale;
367 auto volume3DOverlay = std::dynamic_pointer_cast<Volume3DOverlay>(overlays.getOverlay(_anchor.overlayID));
368 340
369 if (volume3DOverlay) {341 {
370 volume3DOverlay->setDimensions(scaledDimensions);342 EntityItemProperties properties;
343 properties.setDimensions(_anchor.originalDimensions * sensorToWorldScale);
344 entityScriptingInterface->editEntity(_anchor.entityID, properties);
371 }345 }
372 346
373 for (auto& keyboardLayer: _keyboardLayers) {347 for (auto& keyboardLayer : _keyboardLayers) {
374 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {348 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {
375 iter.value().scaleKey(sensorToWorldScale);349 iter.value().scaleKey(sensorToWorldScale);
376 }350 }
377 }351 }
378 352
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 }
379 360
380 361 {
381 glm::vec3 scaledLocalPosition = _textDisplay.localPosition * sensorToWorldScale;362 EntityItemProperties properties;
382 glm::vec3 textDisplayScaledDimensions = _textDisplay.dimensions * sensorToWorldScale;363 properties.setLocalPosition(_backPlate.localPosition * sensorToWorldScale);
383 364 properties.setDimensions(_backPlate.dimensions * sensorToWorldScale);
384 QVariantMap textDisplayProperties {365 entityScriptingInterface->editEntity(_backPlate.entityID, properties);
385 { "localPosition", vec3toVariant(scaledLocalPosition) },366 }
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);
402}367}
403 368
404void Keyboard::startLayerSwitchTimer() {369void Keyboard::startLayerSwitchTimer() {
@@ -419,13 +384,12 @@ void Keyboard::raiseKeyboard(bool raise) const { · 14 unmodified lines
419 if (_keyboardLayers.empty()) {384 if (_keyboardLayers.empty()) {
420 return;385 return;
421 }386 }
422 Overlays& overlays = qApp->getOverlays();387
423 const auto& keyboardLayer = _keyboardLayers[_layerIndex];388 const auto& keyboardLayer = _keyboardLayers[_layerIndex];
389 EntityItemProperties properties;
390 properties.setVisible(raise);
424 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {391 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {
425 auto base3DOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(iter.key()));392 DependencyManager::get<EntityScriptingInterface>()->editEntity(iter.key(), properties);
426 if (base3DOverlay) {
427 base3DOverlay->setVisible(raise);
428 }
429 }393 }
430}394}
431 395
@@ -465,19 +429,15 @@ bool Keyboard::getPreferMalletsOverLasers() const { · 33 unmodified lines
465}429}
466 430
467void Keyboard::switchToLayer(int layerIndex) {431void Keyboard::switchToLayer(int layerIndex) {
432 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
468 if (layerIndex >= 0 && layerIndex < (int)_keyboardLayers.size()) {433 if (layerIndex >= 0 && layerIndex < (int)_keyboardLayers.size()) {
469 Overlays& overlays = qApp->getOverlays();434 EntityPropertyFlags desiredProperties;
470 435 desiredProperties += PROP_POSITION;
471 OverlayID currentAnchorOverlayID = _anchor.overlayID;436 desiredProperties += PROP_ROTATION;
472 437 auto oldProperties = entityScriptingInterface->getEntityProperties(_anchor.entityID, desiredProperties);
473 glm::vec3 currentOverlayPosition;
474 glm::quat currentOverlayOrientation;
475 438
476 auto currentAnchorOverlay = std::dynamic_pointer_cast<Cube3DOverlay>(overlays.getOverlay(currentAnchorOverlayID));439 glm::vec3 currentPosition = oldProperties.getPosition();
477 if (currentAnchorOverlay) {440 glm::quat currentOrientation = oldProperties.getRotation();
478 currentOverlayPosition = currentAnchorOverlay->getWorldPosition();
479 currentOverlayOrientation = currentAnchorOverlay->getWorldOrientation();
480 }
481 441
482 raiseKeyboardAnchor(false);442 raiseKeyboardAnchor(false);
483 raiseKeyboard(false);443 raiseKeyboard(false);
@@ -487,19 +447,17 @@ void Keyboard::switchToLayer(int layerIndex) { · 3 unmodified lines
487 raiseKeyboardAnchor(true);447 raiseKeyboardAnchor(true);
488 raiseKeyboard(true);448 raiseKeyboard(true);
489 449
490 OverlayID newAnchorOverlayID = _anchor.overlayID;450 EntityItemProperties properties;
491 auto newAnchorOverlay = std::dynamic_pointer_cast<Cube3DOverlay>(overlays.getOverlay(newAnchorOverlayID));451 properties.setPosition(currentPosition);
492 if (newAnchorOverlay) {452 properties.setRotation(currentOrientation);
493 newAnchorOverlay->setWorldPosition(currentOverlayPosition);453 entityScriptingInterface->editEntity(_anchor.entityID, properties);
494 newAnchorOverlay->setWorldOrientation(currentOverlayOrientation);
495 }
496 454
497 startLayerSwitchTimer();455 startLayerSwitchTimer();
498 }456 }
499}457}
500 458
501bool Keyboard::shouldProcessOverlayAndPointerEvent(const PointerEvent& event, const OverlayID& overlayID) const {459bool Keyboard::shouldProcessEntityAndPointerEvent(const PointerEvent& event, const QUuid& id) const {
502 return (shouldProcessPointerEvent(event) && shouldProcessOverlay(overlayID));460 return (shouldProcessPointerEvent(event) && shouldProcessEntity(id));
503}461}
504 462
505bool Keyboard::shouldProcessPointerEvent(const PointerEvent& event) const {463bool Keyboard::shouldProcessPointerEvent(const PointerEvent& event) const {
@@ -510,14 +468,14 @@ bool Keyboard::shouldProcessPointerEvent(const PointerEvent& event) const { · 4 unmodified lines
510 return ((isStylusEvent && preferMalletsOverLasers) || (isLaserEvent && !preferMalletsOverLasers));468 return ((isStylusEvent && preferMalletsOverLasers) || (isLaserEvent && !preferMalletsOverLasers));
511}469}
512 470
513void Keyboard::handleTriggerBegin(const OverlayID& overlayID, const PointerEvent& event) {471void Keyboard::handleTriggerBegin(const QUuid& id, const PointerEvent& event) {
514 auto buttonType = event.getButton();472 auto buttonType = event.getButton();
515 if (!shouldProcessOverlayAndPointerEvent(event, overlayID) || buttonType != PointerEvent::PrimaryButton) {473 if (!shouldProcessEntityAndPointerEvent(event, id) || buttonType != PointerEvent::PrimaryButton) {
516 return;474 return;
517 }475 }
518 476
519 auto& keyboardLayer = _keyboardLayers[_layerIndex];477 auto& keyboardLayer = _keyboardLayers[_layerIndex];
520 auto search = keyboardLayer.find(overlayID);478 auto search = keyboardLayer.find(id);
521 479
522 if (search == keyboardLayer.end()) {480 if (search == keyboardLayer.end()) {
523 return;481 return;
@@ -533,13 +491,9 @@ void Keyboard::handleTriggerBegin(const OverlayID& overlayID, const PointerEvent · 9 unmodified lines
533 auto userInputMapper = DependencyManager::get<UserInputMapper>();491 auto userInputMapper = DependencyManager::get<UserInputMapper>();
534 userInputMapper->triggerHapticPulse(PULSE_STRENGTH, PULSE_DURATION, handIndex);492 userInputMapper->triggerHapticPulse(PULSE_STRENGTH, PULSE_DURATION, handIndex);
535 493
536 Overlays& overlays = qApp->getOverlays();494 EntityPropertyFlags desiredProperties;
537 auto base3DOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(overlayID));495 desiredProperties += PROP_POSITION;
538 496 glm::vec3 keyWorldPosition = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(id, desiredProperties).getPosition();
539 glm::vec3 keyWorldPosition;
540 if (base3DOverlay) {
541 keyWorldPosition = base3DOverlay->getWorldPosition();
542 }
543 497
544 AudioInjectorOptions audioOptions;498 AudioInjectorOptions audioOptions;
545 audioOptions.localOnly = true;499 audioOptions.localOnly = true;
@@ -601,7 +555,7 @@ void Keyboard::handleTriggerBegin(const OverlayID& overlayID, const PointerEvent · 55 unmodified lines
601 key.startTimer(KEY_PRESS_TIMEOUT_MS);555 key.startTimer(KEY_PRESS_TIMEOUT_MS);
602 }556 }
603 auto selection = DependencyManager::get<SelectionScriptingInterface>();557 auto selection = DependencyManager::get<SelectionScriptingInterface>();
604 selection->addToSelectedItemsList(KEY_PRESSED_HIGHLIGHT, "overlay", overlayID);558 selection->addToSelectedItemsList(KEY_PRESSED_HIGHLIGHT, "entity", id);
605 }559 }
606}560}
607 561
@@ -617,25 +571,23 @@ void Keyboard::setRightHandLaser(unsigned int rightHandLaser) { · 9 unmodified lines
617 });571 });
618}572}
619 573
620void Keyboard::handleTriggerEnd(const OverlayID& overlayID, const PointerEvent& event) {574void Keyboard::handleTriggerEnd(const QUuid& id, const PointerEvent& event) {
621 if (!shouldProcessOverlayAndPointerEvent(event, overlayID)) {575 if (!shouldProcessEntityAndPointerEvent(event, id)) {
622 return;576 return;
623 }577 }
624 578
625 auto& keyboardLayer = _keyboardLayers[_layerIndex];579 auto& keyboardLayer = _keyboardLayers[_layerIndex];
626 auto search = keyboardLayer.find(overlayID);580 auto search = keyboardLayer.find(id);
627 581
628 if (search == keyboardLayer.end()) {582 if (search == keyboardLayer.end()) {
629 return;583 return;
630 }584 }
631 585
632 Key& key = search.value();;586 Key& key = search.value();
633 Overlays& overlays = qApp->getOverlays();
634 auto base3DOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(overlayID));
635 587
636 if (base3DOverlay) {588 EntityItemProperties properties;
637 base3DOverlay->setLocalPosition(key.getCurrentLocalPosition());589 properties.setLocalPosition(key.getCurrentLocalPosition());
638 }590 DependencyManager::get<EntityScriptingInterface>()->editEntity(id, properties);
639 591
640 key.setIsPressed(false);592 key.setIsPressed(false);
641 if (key.timerFinished() && getPreferMalletsOverLasers()) {593 if (key.timerFinished() && getPreferMalletsOverLasers()) {
@@ -643,78 +595,79 @@ void Keyboard::handleTriggerEnd(const OverlayID& overlayID, const PointerEvent& · 1 unmodified line
643 }595 }
644 596
645 auto selection = DependencyManager::get<SelectionScriptingInterface>();597 auto selection = DependencyManager::get<SelectionScriptingInterface>();
646 selection->removeFromSelectedItemsList(KEY_PRESSED_HIGHLIGHT, "overlay", overlayID);598 selection->removeFromSelectedItemsList(KEY_PRESSED_HIGHLIGHT, "entity", id);
647}599}
648 600
649void Keyboard::handleTriggerContinue(const OverlayID& overlayID, const PointerEvent& event) {601void Keyboard::handleTriggerContinue(const QUuid& id, const PointerEvent& event) {
650 if (!shouldProcessOverlayAndPointerEvent(event, overlayID)) {602 if (!shouldProcessEntityAndPointerEvent(event, id)) {
651 return;603 return;
652 }604 }
653 605
654 auto& keyboardLayer = _keyboardLayers[_layerIndex];606 auto& keyboardLayer = _keyboardLayers[_layerIndex];
655 auto search = keyboardLayer.find(overlayID);607 auto search = keyboardLayer.find(id);
656 608
657 if (search == keyboardLayer.end()) {609 if (search == keyboardLayer.end()) {
658 return;610 return;
659 }611 }
660 612
661 Key& key = search.value();613 Key& key = search.value();
662 Overlays& overlays = qApp->getOverlays();
663
664 if (!key.isPressed() && getPreferMalletsOverLasers()) {614 if (!key.isPressed() && getPreferMalletsOverLasers()) {
665 auto base3DOverlay = std::dynamic_pointer_cast<Base3DOverlay>(overlays.getOverlay(overlayID));615 unsigned int pointerID = event.getID();
666 616 auto pointerManager = DependencyManager::get<PointerManager>();
667 if (base3DOverlay) {617 auto pickResult = pointerManager->getPrevPickResult(pointerID);
668 unsigned int pointerID = event.getID();618 auto stylusPickResult = std::dynamic_pointer_cast<StylusPickResult>(pickResult);
669 auto pointerManager = DependencyManager::get<PointerManager>();619 float distance = stylusPickResult->distance;
670 auto pickResult = pointerManager->getPrevPickResult(pointerID);620
671 auto stylusPickResult = std::dynamic_pointer_cast<StylusPickResult>(pickResult);621 static const float PENATRATION_THRESHOLD = 0.025f;
672 float distance = stylusPickResult->distance;622 if (distance < PENATRATION_THRESHOLD) {
673 623 static const float Z_OFFSET = 0.002f;
674 static const float PENATRATION_THRESHOLD = 0.025f;624
675 if (distance < PENATRATION_THRESHOLD) {625 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
676 static const float Z_OFFSET = 0.002f;626 EntityPropertyFlags desiredProperties;
677 glm::quat overlayOrientation = base3DOverlay->getWorldOrientation();627 desiredProperties += PROP_ROTATION;
678 glm::vec3 overlayYAxis = overlayOrientation * Z_AXIS;628 glm::quat orientation = entityScriptingInterface->getEntityProperties(id, desiredProperties).getRotation();
679 glm::vec3 overlayYOffset = overlayYAxis * Z_OFFSET;629 glm::vec3 yAxis = orientation * Z_AXIS;
680 glm::vec3 localPosition = key.getCurrentLocalPosition() - overlayYOffset;630 glm::vec3 yOffset = yAxis * Z_OFFSET;
681 base3DOverlay->setLocalPosition(localPosition);631 glm::vec3 localPosition = key.getCurrentLocalPosition() - yOffset;
682 key.setIsPressed(true);632
683 }633 EntityItemProperties properties;
634 properties.setLocalPosition(localPosition);
635 entityScriptingInterface->editEntity(id, properties);
636 key.setIsPressed(true);
684 }637 }
685 }638 }
686}639}
687 640
688void Keyboard::handleHoverBegin(const OverlayID& overlayID, const PointerEvent& event) {641void Keyboard::handleHoverBegin(const QUuid& id, const PointerEvent& event) {
689 if (!shouldProcessOverlayAndPointerEvent(event, overlayID)) {642 if (!shouldProcessEntityAndPointerEvent(event, id)) {
690 return;643 return;
691 }644 }
692 645
693 auto& keyboardLayer = _keyboardLayers[_layerIndex];646 auto& keyboardLayer = _keyboardLayers[_layerIndex];
694 auto search = keyboardLayer.find(overlayID);647 auto search = keyboardLayer.find(id);
695 648
696 if (search == keyboardLayer.end()) {649 if (search == keyboardLayer.end()) {
697 return;650 return;
698 }651 }
699 652
700 auto selection = DependencyManager::get<SelectionScriptingInterface>();653 auto selection = DependencyManager::get<SelectionScriptingInterface>();
701 selection->addToSelectedItemsList(KEY_HOVER_HIGHLIGHT, "overlay", overlayID);654 selection->addToSelectedItemsList(KEY_HOVER_HIGHLIGHT, "entity", id);
702}655}
703 656
704void Keyboard::handleHoverEnd(const OverlayID& overlayID, const PointerEvent& event) {657void Keyboard::handleHoverEnd(const QUuid& id, const PointerEvent& event) {
705 if (!shouldProcessOverlayAndPointerEvent(event, overlayID)) {658 if (!shouldProcessEntityAndPointerEvent(event, id)) {
706 return;659 return;
707 }660 }
708 661
709 auto& keyboardLayer = _keyboardLayers[_layerIndex];662 auto& keyboardLayer = _keyboardLayers[_layerIndex];
710 auto search = keyboardLayer.find(overlayID);663 auto search = keyboardLayer.find(id);
711 664
712 if (search == keyboardLayer.end()) {665 if (search == keyboardLayer.end()) {
713 return;666 return;
714 }667 }
715 668
716 auto selection = DependencyManager::get<SelectionScriptingInterface>();669 auto selection = DependencyManager::get<SelectionScriptingInterface>();
717 selection->removeFromSelectedItemsList(KEY_HOVER_HIGHLIGHT, "overlay", overlayID);670 selection->removeFromSelectedItemsList(KEY_HOVER_HIGHLIGHT, "entity", id);
718}671}
719 672
720void Keyboard::disableStylus() {673void Keyboard::disableStylus() {
@@ -752,7 +705,6 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 31 unmodified lines
752 }705 }
753 706
754 clearKeyboardKeys();707 clearKeyboardKeys();
755 Overlays& overlays = qApp->getOverlays();
756 auto requestData = request->getData();708 auto requestData = request->getData();
757 709
758 QVector<QUuid> includeItems;710 QVector<QUuid> includeItems;
@@ -776,54 +728,58 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 17 unmodified lines
776 return;728 return;
777 }729 }
778 730
779 QVariantMap anchorProperties {731 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
780 { "name", "KeyboardAnchor"},732 {
781 { "isSolid", true },733 glm::vec3 dimensions = vec3FromVariant(anchorObject["dimensions"].toVariant());
782 { "visible", false },734
783 { "grabbable", true },735 EntityItemProperties properties;
784 { "ignorePickIntersection", false },736 properties.setType(EntityTypes::Box);
785 { "dimensions", anchorObject["dimensions"].toVariant() },737 properties.setName("KeyboardAnchor");
786 { "position", anchorObject["position"].toVariant() },738 properties.setVisible(false);
787 { "orientation", anchorObject["rotation"].toVariant() }739 properties.getGrab().setGrabbable(true);
788 };740 properties.setIgnorePickIntersection(false);
789 741 properties.setDimensions(dimensions);
790 glm::vec3 dimensions = vec3FromVariant(anchorObject["dimensions"].toVariant());742 properties.setPosition(vec3FromVariant(anchorObject["position"].toVariant()));
791 743 properties.setRotation(quatFromVariant(anchorObject["rotation"].toVariant()));
792 Anchor anchor;744
793 anchor.overlayID = overlays.addOverlay("cube", anchorProperties);745 Anchor anchor;
794 anchor.originalDimensions = dimensions;746 anchor.entityID = entityScriptingInterface->addEntity(properties, "local");
795 _anchor = anchor;747 anchor.originalDimensions = dimensions;
796 748 _anchor = anchor;
797 QJsonObject backPlateObject = jsonObject["backPlate"].toObject();749 }
798 750
799 QVariantMap backPlateProperties {751 {
800 { "name", "backPlate"},752 QJsonObject backPlateObject = jsonObject["backPlate"].toObject();
801 { "isSolid", true },753 glm::vec3 dimensions = vec3FromVariant(backPlateObject["dimensions"].toVariant());
802 { "visible", true },754
803 { "grabbable", false },755 EntityItemProperties properties;
804 { "alpha", 0.0 },756 properties.setType(EntityTypes::Box);
805 { "ignoreRayIntersection", false},757 properties.setName("BackPlate");
806 { "dimensions", backPlateObject["dimensions"].toVariant() },758 properties.setVisible(true);
807 { "position", backPlateObject["position"].toVariant() },759 properties.getGrab().setGrabbable(false);
808 { "orientation", backPlateObject["rotation"].toVariant() },760 properties.setAlpha(0.0f);
809 { "parentID", _anchor.overlayID }761 properties.setIgnorePickIntersection(false);
810 };762 properties.setDimensions(dimensions);
811 763 properties.setPosition(vec3FromVariant(backPlateObject["position"].toVariant()));
812 BackPlate backPlate;764 properties.setRotation(quatFromVariant(backPlateObject["rotation"].toVariant()));
813 backPlate.overlayID = overlays.addOverlay("cube", backPlateProperties);765 properties.setParentID(_anchor.entityID);
814 backPlate.dimensions = vec3FromVariant(backPlateObject["dimensions"].toVariant());766
815 backPlate.localPosition = vec3FromVariant(overlays.getProperty(backPlate.overlayID, "localPosition").value);767 BackPlate backPlate;
816 _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 }
817 775
818 const QJsonArray& keyboardLayers = jsonObject["layers"].toArray();776 const QJsonArray& keyboardLayers = jsonObject["layers"].toArray();
819 int keyboardLayerCount = keyboardLayers.size();777 int keyboardLayerCount = keyboardLayers.size();
820 _keyboardLayers.reserve(keyboardLayerCount);778 _keyboardLayers.reserve(keyboardLayerCount);
821
822
823 for (int keyboardLayerIndex = 0; keyboardLayerIndex < keyboardLayerCount; keyboardLayerIndex++) {779 for (int keyboardLayerIndex = 0; keyboardLayerIndex < keyboardLayerCount; keyboardLayerIndex++) {
824 const QJsonValue& keyboardLayer = keyboardLayers[keyboardLayerIndex].toArray();780 const QJsonValue& keyboardLayer = keyboardLayers[keyboardLayerIndex].toArray();
825 781
826 QHash<OverlayID, Key> keyboardLayerKeys;782 QHash<QUuid, Key> keyboardLayerKeys;
827 foreach (const QJsonValue& keyboardKeyValue, keyboardLayer.toArray()) {783 foreach (const QJsonValue& keyboardKeyValue, keyboardLayer.toArray()) {
828 784
829 QVariantMap textureMap;785 QVariantMap textureMap;
@@ -841,21 +797,6 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 11 unmodified lines
841 QString modelUrl = keyboardKeyValue["modelURL"].toString();797 QString modelUrl = keyboardKeyValue["modelURL"].toString();
842 QString url = (useResourcePath ? (resourcePath + modelUrl) : modelUrl);798 QString url = (useResourcePath ? (resourcePath + modelUrl) : modelUrl);
843 799
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
859 QString keyType = keyboardKeyValue["type"].toString();800 QString keyType = keyboardKeyValue["type"].toString();
860 QString keyString = keyboardKeyValue["key"].toString();801 QString keyString = keyboardKeyValue["key"].toString();
861 802
@@ -869,48 +810,65 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 7 unmodified lines
869 key.setSwitchToLayerIndex(switchToLayer);810 key.setSwitchToLayerIndex(switchToLayer);
870 }811 }
871 }812 }
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);
873 key.setKeyString(keyString);827 key.setKeyString(keyString);
874 key.saveDimensionsAndLocalPosition();828 key.saveDimensionsAndLocalPosition();
875 829
876 includeItems.append(key.getID());830 includeItems.append(key.getID());
877 _itemsToIgnore.append(key.getID());831 _itemsToIgnore.append(key.getID());
878 keyboardLayerKeys.insert(overlayID, key);832 keyboardLayerKeys.insert(id, key);
879 }833 }
880 834
881 _keyboardLayers.push_back(keyboardLayerKeys);835 _keyboardLayers.push_back(keyboardLayerKeys);
882 836
883 }837 }
884 838
885 TextDisplay textDisplay;839 {
886 QJsonObject displayTextObject = jsonObject["textDisplay"].toObject();840 QJsonObject displayTextObject = jsonObject["textDisplay"].toObject();
887 841 glm::vec3 dimensions = vec3FromVariant(displayTextObject["dimensions"].toVariant());
888 QVariantMap displayTextProperties {842 glm::vec3 localPosition = vec3FromVariant(displayTextObject["localPosition"].toVariant());
889 { "dimensions", displayTextObject["dimensions"].toVariant() },843 float lineHeight = (float)displayTextObject["lineHeight"].toDouble();
890 { "localPosition", displayTextObject["localPosition"].toVariant() },844
891 { "localOrientation", displayTextObject["localOrientation"].toVariant() },845 EntityItemProperties properties;
892 { "leftMargin", displayTextObject["leftMargin"].toVariant() },846 properties.setType(EntityTypes::Text);
893 { "rightMargin", displayTextObject["rightMargin"].toVariant() },847 properties.setDimensions(dimensions);
894 { "topMargin", displayTextObject["topMargin"].toVariant() },848 properties.setLocalPosition(localPosition);
895 { "bottomMargin", displayTextObject["bottomMargin"].toVariant() },849 properties.setLocalRotation(quatFromVariant(displayTextObject["localOrientation"].toVariant()));
896 { "lineHeight", displayTextObject["lineHeight"].toVariant() },850 properties.setLeftMargin((float)displayTextObject["leftMargin"].toDouble());
897 { "visible", false },851 properties.setRightMargin((float)displayTextObject["rightMargin"].toDouble());
898 { "emissive", true },852 properties.setTopMargin((float)displayTextObject["topMargin"].toDouble());
899 { "grabbable", false },853 properties.setBottomMargin((float)displayTextObject["bottomMargin"].toDouble());
900 { "text", ""},854 properties.setLineHeight((float)displayTextObject["lineHeight"].toDouble());
901 { "parentID", _anchor.overlayID }855 properties.setVisible(false);
902 };856 properties.setEmissive(true);
903 857 properties.getGrab().setGrabbable(false);
904 textDisplay.overlayID = overlays.addOverlay("text3d", displayTextProperties);858 properties.setText("");
905 textDisplay.localPosition = vec3FromVariant(displayTextObject["localPosition"].toVariant());859 properties.setParentID(_anchor.entityID);
906 textDisplay.dimensions = vec3FromVariant(displayTextObject["dimensions"].toVariant());860
907 textDisplay.lineHeight = (float) displayTextObject["lineHeight"].toDouble();861 TextDisplay textDisplay;
908 862 textDisplay.entityID = entityScriptingInterface->addEntity(properties, "local");
909 _textDisplay = textDisplay;863 textDisplay.localPosition = localPosition;
864 textDisplay.dimensions = dimensions;
865 textDisplay.lineHeight = lineHeight;
866 _textDisplay = textDisplay;
867 }
910 868
911 _ignoreItemsLock.withWriteLock([&] {869 _ignoreItemsLock.withWriteLock([&] {
912 _itemsToIgnore.append(_textDisplay.overlayID);870 _itemsToIgnore.append(_textDisplay.entityID);
913 _itemsToIgnore.append(_anchor.overlayID);871 _itemsToIgnore.append(_anchor.entityID);
914 });872 });
915 _layerIndex = 0;873 _layerIndex = 0;
916 auto pointerManager = DependencyManager::get<PointerManager>();874 auto pointerManager = DependencyManager::get<PointerManager>();
@@ -922,34 +880,33 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { · 5 unmodified lines
922}880}
923 881
924 882
925OverlayID Keyboard::getAnchorID() {883QUuid Keyboard::getAnchorID() {
926 return _ignoreItemsLock.resultWithReadLock<OverlayID>([&] {884 return _ignoreItemsLock.resultWithReadLock<QUuid>([&] {
927 return _anchor.overlayID;885 return _anchor.entityID;
928 });886 });
929}887}
930 888
931bool Keyboard::shouldProcessOverlay(const OverlayID& overlayID) const {889bool Keyboard::shouldProcessEntity(const QUuid& id) const {
932 return (!_keyboardLayers.empty() && isLayerSwitchTimerFinished() && overlayID != _backPlate.overlayID);890 return (!_keyboardLayers.empty() && isLayerSwitchTimerFinished() && id != _backPlate.entityID);
933}891}
934 892
935QVector<OverlayID> Keyboard::getKeysID() {893QVector<QUuid> Keyboard::getKeysID() {
936 return _ignoreItemsLock.resultWithReadLock<QVector<OverlayID>>([&] {894 return _ignoreItemsLock.resultWithReadLock<QVector<QUuid>>([&] {
937 return _itemsToIgnore;895 return _itemsToIgnore;
938 });896 });
939}897}
940 898
941void Keyboard::clearKeyboardKeys() {899void Keyboard::clearKeyboardKeys() {
942 Overlays& overlays = qApp->getOverlays();900 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
943
944 for (const auto& keyboardLayer: _keyboardLayers) {901 for (const auto& keyboardLayer: _keyboardLayers) {
945 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {902 for (auto iter = keyboardLayer.begin(); iter != keyboardLayer.end(); iter++) {
946 overlays.deleteOverlay(iter.key());903 entityScriptingInterface->deleteEntity(iter.key());
947 }904 }
948 }905 }
949 906
950 overlays.deleteOverlay(_anchor.overlayID);907 entityScriptingInterface->deleteEntity(_anchor.entityID);
951 overlays.deleteOverlay(_textDisplay.overlayID);908 entityScriptingInterface->deleteEntity(_textDisplay.entityID);
952 overlays.deleteOverlay(_backPlate.overlayID);909 entityScriptingInterface->deleteEntity(_backPlate.entityID);
953 910
954 _keyboardLayers.clear();911 _keyboardLayers.clear();
955 912
@@ -989,8 +946,8 @@ void Keyboard::disableRightMallet() { · 33 unmodified lines
989 pointerManager->disablePointer(_rightHandStylus);946 pointerManager->disablePointer(_rightHandStylus);
990}947}
991 948
992bool Keyboard::containsID(OverlayID overlayID) const {949bool Keyboard::containsID(const QUuid& id) const {
993 return resultWithReadLock<bool>([&] {950 return resultWithReadLock<bool>([&] {
994 return _itemsToIgnore.contains(overlayID) || _backPlate.overlayID == overlayID;951 return _itemsToIgnore.contains(id) || _backPlate.entityID == id;
995 });952 });
996}953}

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