stopgap with MyAvatar.qmlPosition

This commit is contained in:
Zach Pomerantz 2017-06-14 16:11:32 -04:00
parent d3d36324c0
commit a7e1b75909
4 changed files with 20 additions and 2 deletions

View file

@ -27,7 +27,9 @@ RowLayout {
sample = null;
}
function playSound() {
sample = Audio.playSound(sound, { position: MyAvatar.position, loop: false, localOnly: true });
// FIXME: MyAvatar is not properly exposed to QML; MyAvatar.qmlPosition is a stopgap
// FIXME: Audio.playSystemSound should not require position
sample = Audio.playSystemSound(sound, MyAvatar.qmlPosition);
isPlaying = true;
sample.finished.connect(function() { isPlaying = false; sample = null; });
}

View file

@ -56,6 +56,7 @@ class MyAvatar : public Avatar {
*
* @namespace MyAvatar
* @augments Avatar
* @property qmlPosition {Vec3} Used as a polyfill for position access by QML
* @property shouldRenderLocally {bool} Set it to true if you would like to see MyAvatar in your local interface,
* and false if you would not like to see MyAvatar in your local interface.
* @property motorVelocity {Vec3} Can be used to move the avatar with this velocity.
@ -101,6 +102,10 @@ class MyAvatar : public Avatar {
* "scripts/system/controllers/toggleAdvancedMovementForHandControllers.js".
*/
// FIXME: `glm::vec3 position` is not accessible from QML, so this exposes position in a QML-native type
Q_PROPERTY(QVector3D qmlPosition READ getQmlPosition)
QVector3D getQmlPosition() { auto p = getPosition(); return QVector3D(p.x, p.y, p.z); }
Q_PROPERTY(bool shouldRenderLocally READ getShouldRenderLocally WRITE setShouldRenderLocally)
Q_PROPERTY(glm::vec3 motorVelocity READ getScriptedMotorVelocity WRITE setScriptedMotorVelocity)
Q_PROPERTY(float motorTimescale READ getScriptedMotorTimescale WRITE setScriptedMotorTimescale)

View file

@ -11,6 +11,8 @@
#include "AudioScriptingInterface.h"
#include <QVector3D>
#include "ScriptAudioInjector.h"
#include "ScriptEngineLogging.h"
@ -19,6 +21,13 @@ void registerAudioMetaTypes(QScriptEngine* engine) {
qScriptRegisterMetaType(engine, soundSharedPointerToScriptValue, soundSharedPointerFromScriptValue);
}
ScriptAudioInjector* AudioScriptingInterface::playSystemSound(SharedSoundPointer sound, const QVector3D& position) {
AudioInjectorOptions options;
options.position = glm::vec3(position.x(), position.y(), position.z());
options.localOnly = true;
return playSound(sound, options);
}
ScriptAudioInjector* AudioScriptingInterface::playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions) {
if (QThread::currentThread() != thread()) {
ScriptAudioInjector* injector = NULL;

View file

@ -30,8 +30,10 @@ public:
protected:
AudioScriptingInterface() {}
// this method is protected to stop C++ callers from calling, but invokable from script
// these methods are protected to stop C++ callers from calling, but invokable from script
Q_INVOKABLE ScriptAudioInjector* playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions = AudioInjectorOptions());
// FIXME: there is no way to play a positionless sound
Q_INVOKABLE ScriptAudioInjector* playSystemSound(SharedSoundPointer sound, const QVector3D& position);
Q_INVOKABLE void setStereoInput(bool stereo);