From 0860c50a49f50c9a6afa8e660a3d6b444d33da90 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Fri, 6 Jan 2017 14:01:13 -0800 Subject: [PATCH] Allow Hifi.SoundEffect to be used in all qml Including webEntities, webOverlays and the system tablet. We might want to add this to enable spatial sound effects for the web keyboard. --- .../resources/qml/hifi/tablet/TabletRoot.qml | 2 +- interface/src/ui/overlays/Web3DOverlay.cpp | 12 ++++-------- .../src/RenderableWebEntityItem.cpp | 7 +++++++ .../src/TabletScriptingInterface.cpp | 9 +++------ .../script-engine/src/TabletScriptingInterface.h | 15 +-------------- scripts/system/tablet-ui/tabletUI.js | 3 --- 6 files changed, 16 insertions(+), 32 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/TabletRoot.qml b/interface/resources/qml/hifi/tablet/TabletRoot.qml index e05f867919..f5f3b84cfc 100644 --- a/interface/resources/qml/hifi/tablet/TabletRoot.qml +++ b/interface/resources/qml/hifi/tablet/TabletRoot.qml @@ -20,7 +20,7 @@ Item { } function playButtonClickSound() { - buttonClickSound.play(); + buttonClickSound.play(globalPosition); } Loader { diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index fe48b05f5e..486452ea5b 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -107,15 +107,10 @@ Web3DOverlay::~Web3DOverlay() { } void Web3DOverlay::update(float deltatime) { - // FIXME: applyTransformTo causes tablet overlay to detach from tablet entity. - // Perhaps rather than deleting the following code it should be run only if isFacingAvatar() is true? - /* - if (usecTimestampNow() > _transformExpiry) { - Transform transform = getTransform(); - applyTransformTo(transform); - setTransform(transform); + if (_webSurface) { + // update globalPosition + _webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition())); } - */ } void Web3DOverlay::loadSourceURL() { @@ -141,6 +136,7 @@ void Web3DOverlay::loadSourceURL() { tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data()); } } + _webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition())); } void Web3DOverlay::render(RenderArgs* args) { diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index df28769964..bceaa8b608 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -271,6 +271,7 @@ void RenderableWebEntityItem::loadSourceURL() { tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data()); } } + _webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition())); } @@ -403,6 +404,12 @@ void RenderableWebEntityItem::destroyWebSurface() { } void RenderableWebEntityItem::update(const quint64& now) { + + if (_webSurface) { + // update globalPosition + _webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition())); + } + auto interval = now - _lastRenderTime; if (interval > MAX_NO_RENDER_INTERVAL) { destroyWebSurface(); diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index 0f2d382525..056d946482 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -12,6 +12,7 @@ #include #include +#include #include "ScriptEngineLogging.h" TabletScriptingInterface::TabletScriptingInterface() { @@ -165,10 +166,6 @@ void TabletProxy::updateAudioBar(const double micLevel) { } } -void TabletProxy::updateTabletPosition(glm::vec3 tabletPosition) { - _position.set(tabletPosition); -} - void TabletProxy::emitScriptEvent(QVariant msg) { if (_qmlOffscreenSurface) { QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg)); @@ -269,13 +266,13 @@ void SoundEffect::setSource(QUrl url) { _sound = DependencyManager::get()->getSound(_url); } -void SoundEffect::play() { +void SoundEffect::play(QVariant position) { auto tsi = DependencyManager::get(); if (tsi) { TabletProxy* tablet = qobject_cast(tsi->getTablet("com.highfidelity.interface.tablet.system")); if (tablet) { AudioInjectorOptions options; - options.position = tablet->getPosition(); + options.position = vec3FromVariant(position); options.localOnly = true; if (_injector) { _injector->setOptions(options); diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index 61e3205dc3..43750e2519 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -24,7 +24,6 @@ #include #include -#include class TabletProxy; class TabletButtonProxy; @@ -101,17 +100,6 @@ public: */ Q_INVOKABLE void updateAudioBar(const double micLevel); - - /**jsdoc - * Updates the tablet's position in world space. This is necessary for the tablet - * to emit audio with the correct spatialization. - * @function TabletProxy#updateTabletPosition - * @param position {vec3} tablet position in world space. - */ - Q_INVOKABLE void updateTabletPosition(glm::vec3 tabletPosition); - - glm::vec3 getPosition() const { return _position.get(); } - QString getName() const { return _name; } /**jsdoc @@ -141,7 +129,6 @@ protected: std::vector> _tabletButtonProxies; QQuickItem* _qmlTabletRoot { nullptr }; QObject* _qmlOffscreenSurface { nullptr }; - ThreadSafeValueCache _position; }; /**jsdoc @@ -202,7 +189,7 @@ public: QUrl getSource() const; void setSource(QUrl url); - Q_INVOKABLE void play(); + Q_INVOKABLE void play(QVariant position); protected: QUrl _url; SharedSoundPointer _sound; diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 50985a7f1a..14fe4d649f 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -50,9 +50,6 @@ var currentMicLevel = getMicLevel(); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); tablet.updateAudioBar(currentMicLevel); - if (UIWebTablet) { - tablet.updateTabletPosition(UIWebTablet.getPosition()); - } } if (HMD.showTablet && !tabletShown) {