also consider distance from plane in AudioArea volume
This commit is contained in:
parent
97b4aae360
commit
eac0c6d8c7
1 changed files with 7 additions and 1 deletions
|
@ -22,6 +22,11 @@ export default defineComponent({
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const audio = ref<HTMLAudioElement | null>(null);
|
const audio = ref<HTMLAudioElement | null>(null);
|
||||||
|
|
||||||
|
const MIN_SCALE = 0.02;
|
||||||
|
const MIN_VOLUME_MULTIPLIER = 0.25;
|
||||||
|
const vol_x = (1 - MIN_VOLUME_MULTIPLIER) / (1 - MIN_SCALE);
|
||||||
|
const vol_b = 1 - vol_x;
|
||||||
|
|
||||||
const onBBoxChange = () => {
|
const onBBoxChange = () => {
|
||||||
const x = props.bbox.x + props.bbox.w / 2;
|
const x = props.bbox.x + props.bbox.w / 2;
|
||||||
const y = props.bbox.y + props.bbox.h / 2;
|
const y = props.bbox.y + props.bbox.h / 2;
|
||||||
|
@ -29,7 +34,8 @@ export default defineComponent({
|
||||||
|
|
||||||
if (distance < props.definition.radius) {
|
if (distance < props.definition.radius) {
|
||||||
audio.value!.play();
|
audio.value!.play();
|
||||||
audio.value!.volume = (props.definition.radius - distance) / props.definition.radius;
|
const volume = (props.definition.radius - distance) / props.definition.radius;
|
||||||
|
audio.value!.volume = volume * (props.bbox.z < 1 ? (props.bbox.z * vol_x + vol_b) : 1);
|
||||||
} else {
|
} else {
|
||||||
audio.value!.pause();
|
audio.value!.pause();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue