-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathLowPolyPlanet.vue
52 lines (44 loc) · 1.16 KB
/
LowPolyPlanet.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<script setup lang="ts">
import type { TresObject3D } from '@tresjs/core'
import { shallowRef } from 'vue'
const props = defineProps<{
progress: number
}>()
const { progress } = toRefs(props)
const { nodes } = await useGLTF(
'/models/low-poly-planet/low-poly-planet-v3.glb',
)
const planet = nodes['Planet'] as TresObject3D
const planetRef = shallowRef()
const clouds = Object.values(nodes).filter(node => node.name.includes('Cloud'))
const cloudsRef = shallowRef()
const { onLoop } = useRenderLoop()
onLoop(({ delta }) => {
if (!planet) return
planet.rotation.y -= delta * 0.004
planet.rotation.z -= delta * 0.002
planet.rotation.x -= delta * 0.005
planet.updateMatrixWorld()
/* if(cloudsRef.value) {
cloudsRef.value.forEach((cloud: TresObject3D) => {
cloud.rotation.x = -progress.value * 2
})
} */
})
</script>
<template>
<TresGroup :position="[-2, 2, 0]">
<primitive
ref="planetRef"
:object="planet"
/>
<TresGroup :rotation="[0, -progress, 0]">
<primitive
v-for="cloud in clouds"
:key="cloud.id"
ref="cloudsRef"
:object="cloud"
/>
</TresGroup>
</TresGroup>
</template>