Skip to content

Commit da83120

Browse files
committed
refactor: update texture loading in Ocean and Precipitation components
- Replaced the use of destructured state from `useTexture` with direct texture loading using `TextureLoader` in the `Ocean.vue` component for improved clarity and performance. - Updated the `watchEffect` in `Precipitation.vue` to use a more descriptive variable name for the texture state, enhancing code readability. - Ensured that texture loading logic is consistent across components, aligning with best practices for resource management.
1 parent 3badacd commit da83120

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/core/staging/Ocean.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
import { useLoop, useTresContext } from '@tresjs/core'
33
import { useTexture } from '../loaders/useTexture'
4-
import { FrontSide, RepeatWrapping, Vector3 } from 'three'
4+
import { FrontSide, RepeatWrapping, TextureLoader, Vector3 } from 'three'
55
import { Water } from 'three-stdlib'
66
import { nextTick, onMounted, shallowRef, toRefs } from 'vue'
77
import type { TresColor, TresVector3 } from '@tresjs/core'
@@ -147,16 +147,18 @@ onMounted(async () => {
147147
}
148148
})
149149
150-
const { state: normalMap } = useTexture(waterNormals.value)
150+
const normalMap = new TextureLoader().load(waterNormals.value)
151151
152152
normalMap.wrapS = normalMap.wrapT = RepeatWrapping
153153
154154
const { onBeforeRender } = useLoop()
155155
156156
onBeforeRender(({ delta /* invalidate */ }) => {
157-
waterRef.value.material.uniforms.time.value += delta
158-
// TODO: comment this until invalidate is back in the loop callback on v5
159-
// invalidate()
157+
if (waterRef.value) {
158+
waterRef.value.material.uniforms.time.value += delta
159+
// TODO: comment this until invalidate is back in the loop callback on v5
160+
// invalidate()
161+
}
160162
})
161163
</script>
162164

src/core/staging/Precipitation.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,16 @@ const mapTexture = shallowRef<Texture | null>(null)
179179
180180
watchEffect(async () => {
181181
if (typeof alphaMapUrl.value === 'string') {
182-
const { state: resolvedTexture } = useTexture({ alphaMap: alphaMapUrl.value })
183-
alphaMapTexture.value = resolvedTexture.value
182+
const { state: alphaMap } = useTexture(alphaMapUrl.value)
183+
alphaMapTexture.value = alphaMap.value
184184
}
185185
else {
186186
alphaMapTexture.value = alphaMapUrl.value ?? null
187187
}
188188
189189
if (typeof mapUrl.value === 'string') {
190-
const { state: resolvedTexture } = useTexture({ map: mapUrl.value })
191-
mapTexture.value = resolvedTexture.value
190+
const { state: map } = useTexture(mapUrl.value)
191+
mapTexture.value = map.value
192192
}
193193
else {
194194
mapTexture.value = mapUrl.value ?? null

0 commit comments

Comments
 (0)