TheBasic.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <script setup lang="ts">
  2. import { SRGBColorSpace, BasicShadowMap, NoToneMapping } from 'three'
  3. import { reactive, ref } from 'vue'
  4. import { TresCanvas, useRenderLoop } from '@tresjs/core'
  5. import { OrbitControls, TransformControls } from '@tresjs/cientos'
  6. const state = reactive({
  7. clearColor: '#201919',
  8. shadows: true,
  9. alpha: false,
  10. shadowMapType: BasicShadowMap,
  11. outputColorSpace: SRGBColorSpace,
  12. toneMapping: NoToneMapping,
  13. })
  14. const sphereRef = ref()
  15. const { onLoop } = useRenderLoop()
  16. onLoop(({ elapsed }) => {
  17. if (!sphereRef.value) return
  18. sphereRef.value.position.y += Math.sin(elapsed) * 0.01
  19. })
  20. function onPointerEnter(ev) {
  21. if (ev) {
  22. ev.object.material.color.set('#DFFF45')
  23. }
  24. }
  25. </script>
  26. <template>
  27. <TresCanvas v-bind="state">
  28. <TresPerspectiveCamera :position="[5, 5, 5]" :fov="45" :near="0.1" :far="1000" :look-at="[0, 0, 0]" />
  29. <OrbitControls />
  30. <TresAmbientLight :intensity="0.5" />
  31. <TresMesh ref="sphereRef" :position="[0, 4, 0]" cast-shadow @pointer-enter="onPointerEnter">
  32. <TresSphereGeometry :args="[2, 32, 32]" />
  33. <TresMeshToonMaterial color="cyan" />
  34. </TresMesh>
  35. <TresDirectionalLight :position="[0, 8, 4]" :intensity="0.7" cast-shadow />
  36. <TresMesh :rotation="[-Math.PI / 2, 0, 0]" receive-shadow>
  37. <TresPlaneGeometry :args="[10, 10, 10, 10]" />
  38. <TresMeshToonMaterial />
  39. </TresMesh>
  40. <TresDirectionalLight :position="[0, 2, 4]" :intensity="1" cast-shadow />
  41. <TransformControls :object="sphereRef" />
  42. </TresCanvas>
  43. </template>