mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:08:47 +02:00
added ability to rotate entity and sound direction
This commit is contained in:
parent
52e418481e
commit
cf3a260646
1 changed files with 13 additions and 4 deletions
|
@ -8,6 +8,9 @@
|
||||||
// userData.range should be an integer for the max distance away from the entity where the sound will be audible.
|
// userData.range should be an integer for the max distance away from the entity where the sound will be audible.
|
||||||
// userData.volume is the max volume at which the clip should play. Defaults to 1.0 full volume)
|
// userData.volume is the max volume at which the clip should play. Defaults to 1.0 full volume)
|
||||||
//
|
//
|
||||||
|
// The rotation of the entity is copied to the ambisonic field, so by rotating the entity you will rotate the
|
||||||
|
// direction in-which a certain sound comes from.
|
||||||
|
//
|
||||||
// Remember that the entity has to be visible to the user for the sound to play at all, so make sure the entity is
|
// Remember that the entity has to be visible to the user for the sound to play at all, so make sure the entity is
|
||||||
// large enough to be loaded at the range you set, particularly for large ranges.
|
// large enough to be loaded at the range you set, particularly for large ranges.
|
||||||
//
|
//
|
||||||
|
@ -27,6 +30,7 @@
|
||||||
var range = DEFAULT_RANGE;
|
var range = DEFAULT_RANGE;
|
||||||
var maxVolume = DEFAULT_VOLUME;
|
var maxVolume = DEFAULT_VOLUME;
|
||||||
var UPDATE_INTERVAL_MSECS = 100;
|
var UPDATE_INTERVAL_MSECS = 100;
|
||||||
|
var rotation;
|
||||||
|
|
||||||
var entity;
|
var entity;
|
||||||
var ambientSound;
|
var ambientSound;
|
||||||
|
@ -92,23 +96,28 @@
|
||||||
this.maybeUpdate = function() {
|
this.maybeUpdate = function() {
|
||||||
// Every UPDATE_INTERVAL_MSECS, update the volume of the ambient sound based on distance from my avatar
|
// Every UPDATE_INTERVAL_MSECS, update the volume of the ambient sound based on distance from my avatar
|
||||||
_this.updateSettings();
|
_this.updateSettings();
|
||||||
var props = Entities.getEntityProperties(entity);
|
|
||||||
var HYSTERESIS_FRACTION = 0.1;
|
var HYSTERESIS_FRACTION = 0.1;
|
||||||
var props = Entities.getEntityProperties(entity, [ "position" ]);
|
var props = Entities.getEntityProperties(entity, [ "position", "rotation" ]);
|
||||||
center = props.position;
|
center = props.position;
|
||||||
|
rotation = props.rotation;
|
||||||
var distance = Vec3.length(Vec3.subtract(MyAvatar.position, center));
|
var distance = Vec3.length(Vec3.subtract(MyAvatar.position, center));
|
||||||
if (distance <= range) {
|
if (distance <= range) {
|
||||||
var volume = (1.0 - distance / range) * maxVolume;
|
var volume = (1.0 - distance / range) * maxVolume;
|
||||||
if (!soundPlaying && ambientSound.downloaded) {
|
if (!soundPlaying && ambientSound.downloaded) {
|
||||||
soundPlaying = Audio.playSound(ambientSound, { loop: true, localOnly: true, volume: volume });
|
soundPlaying = Audio.playSound(ambientSound, { loop: true,
|
||||||
|
localOnly: true,
|
||||||
|
rotation: rotation,
|
||||||
|
volume: volume });
|
||||||
debugPrint("Starting ambient sound, volume: " + volume);
|
debugPrint("Starting ambient sound, volume: " + volume);
|
||||||
if (WANT_COLOR_CHANGE) {
|
if (WANT_COLOR_CHANGE) {
|
||||||
Entities.editEntity(entity, { color: COLOR_ON });
|
Entities.editEntity(entity, { color: COLOR_ON });
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (soundPlaying && soundPlaying.playing) {
|
} else if (soundPlaying && soundPlaying.playing) {
|
||||||
soundPlaying.setOptions( { volume: volume } );
|
debugPrint("Setting volume and rotation: " + Quat.safeEulerAngles(rotation).y);
|
||||||
|
soundPlaying.setOptions( { volume: volume, orientation: rotation } );
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (soundPlaying && soundPlaying.playing && (distance > range * HYSTERESIS_FRACTION)) {
|
} else if (soundPlaying && soundPlaying.playing && (distance > range * HYSTERESIS_FRACTION)) {
|
||||||
soundPlaying.stop();
|
soundPlaying.stop();
|
||||||
soundPlaying = false;
|
soundPlaying = false;
|
||||||
|
|
Loading…
Reference in a new issue