Experience.vue 947 B

123456789101112131415161718192021222324252627282930313233343536
  1. <script setup lang="ts">
  2. import { ref } from 'vue'
  3. import { useLoop } from '@tresjs/core'
  4. import type { Mesh } from 'three'
  5. const cubeRef = ref<Mesh | null>(null)
  6. const { onBeforeRender } = useLoop()
  7. let lastTime = 0
  8. const targetFPS = 60
  9. const frameInterval = 1000 / targetFPS
  10. onBeforeRender(({ elapsed }) => {
  11. const currentTime = elapsed * 1000
  12. if (currentTime - lastTime >= frameInterval) {
  13. if (cubeRef.value) {
  14. // Fixed rotation per frame (not time-based) - 60 FPS
  15. cubeRef.value.rotation.x += 0.02
  16. cubeRef.value.rotation.y += 0.02
  17. }
  18. lastTime = currentTime
  19. }
  20. })
  21. </script>
  22. <template>
  23. <TresPerspectiveCamera :position="[0, 1, 5]" />
  24. <TresAmbientLight :intensity="0.5" />
  25. <TresDirectionalLight :position="[0, 2, 4]" :intensity="1" />
  26. <TresMesh ref="cubeRef" :position="[0, 1, 0]">
  27. <TresBoxGeometry :args="[1, 1, 1]" />
  28. <TresMeshStandardMaterial color="#ff6b6b" />
  29. </TresMesh>
  30. </template>