Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Commit 2a05cbc

Browse files
committed
refactor(PositionalAudio.vue): streamline audio buffer handling
- Replaced the direct use of `shallowRef` for the audio buffer with a destructured state from `useLoader`, enhancing clarity and maintainability. - This change simplifies the audio loading process and aligns with best practices for reactive state management in Vue components.
1 parent d09a4c7 commit 2a05cbc

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/core/abstractions/PositionalAudio.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useLoader, useTresContext } from '@tresjs/core'
33
import { AudioListener, AudioLoader, Box3 } from 'three'
44
import { PositionalAudioHelper } from 'three-stdlib'
55
import { onBeforeUnmount, onMounted, shallowReactive, shallowRef, toRefs, watch } from 'vue'
6-
import type { LoaderProto } from '@tresjs/core'
76
import type { Material, Object3D, PositionalAudio } from 'three'
87
98
// TODO: Add & Dynamize : setRolloffFactor 'FLOAT' from https://threejs.org/docs/index.html?q=posi#api/en/audio/PositionalAudio.setRolloffFactor
@@ -41,7 +40,7 @@ const { camera } = useTresContext()
4140
4241
const positionalAudioRef = shallowRef<PositionalAudio | null>(null)
4342
const positionalAudioHelperRef = shallowRef<PositionalAudioHelper | null>(null)
44-
const buffer = shallowRef<AudioBuffer | null>(null)
43+
4544
const listener = shallowReactive<AudioListener>(new AudioListener())
4645
4746
const playAudio = () => {
@@ -133,7 +132,7 @@ defineExpose({
133132
dispose,
134133
})
135134
136-
buffer.value = await useLoader<AudioBuffer | AudioBuffer[]>(AudioLoader as LoaderProto<AudioBuffer | AudioBuffer[]>, url.value) as AudioBuffer
135+
const { state: buffer } = useLoader<AudioBuffer | AudioBuffer[]>(AudioLoader, url.value)
137136
138137
watch(positionalAudioRef, () => {
139138
if (!positionalAudioRef?.value) { return }

0 commit comments

Comments
 (0)