diff --git a/src/audio/Audio.ts b/src/audio/Audio.ts index 0b870ab..a161fef 100644 --- a/src/audio/Audio.ts +++ b/src/audio/Audio.ts @@ -1,7 +1,6 @@ import { Audio as StaticAudio, PositionalAudio, AudioLoader } from 'three' -import { defineComponent } from 'vue' +import { defineComponent, watch } from 'vue' import Object3D from '../core/Object3D' -import { bindProp } from '../tools' type ConcreteAudio = StaticAudio | PositionalAudio @@ -14,7 +13,7 @@ export default defineComponent({ extends: Object3D, name: 'Audio', props: { - src: String, + src: { type: String, required: false }, volume: { type: Number, default: 1.0 }, isStreamed: { type: Boolean, default: true } }, @@ -22,18 +21,21 @@ export default defineComponent({ let streamedAudio = new Audio(); return { streamedAudio } }, + watch: { + volume: function(value) { + this.audio?.setVolume(value) + }, + src: function(value) { + this.stop() + this.loadAudioAndPlay() + } + }, methods: { initAudio(audio: ConcreteAudio) { this.audio = audio this.initObject3D(this.audio) - this.bindProps() this.loadAudioAndPlay() }, - bindProps() { - ['volume', 'isStreamed'].forEach(p => { - bindProp(this, p, this.audio) - }) - }, loadAudioAndPlay() { if (!this.src) return undefined diff --git a/src/audio/PositionalAudio.ts b/src/audio/PositionalAudio.ts index c6aae53..b63d0e5 100644 --- a/src/audio/PositionalAudio.ts +++ b/src/audio/PositionalAudio.ts @@ -8,7 +8,9 @@ export default defineComponent({ name: 'PositionalAudio', props: { refDistance: { type: Number, default: 1.0 }, - rolloffFactor: { type: Number, default: 1.0 } + maxDistance: { type: Number, default: 1.0 }, + rolloffFactor: { type: Number, default: 1.0 }, + distanceModel: { type: String, default: 'inverse' }, }, created() { @@ -27,9 +29,10 @@ export default defineComponent({ this.bindProps() }, methods: { - bindProps(audio: PositionalAudio) { - ['refDistance', 'rolloffFactor'].forEach(p => { - bindProp(this.$props, p, this.audio) + bindProps() { + ['refDistance', 'maxDistance', 'rolloffFactor', 'distanceModel'].forEach(p => { + console.log('initialised positionalAudio props') + bindProp(this.$props, p, (this.audio as PositionalAudio).panner) }) }, },