TheBasic.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 } 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. const sphereExists = ref(true)
  26. </script>
  27. <template>
  28. <input
  29. v-model="sphereExists"
  30. type="checkbox"
  31. >
  32. <TresCanvas v-bind="state">
  33. <TresPerspectiveCamera
  34. :position="[5, 5, 5]"
  35. :fov="45"
  36. :near="0.1"
  37. :far="1000"
  38. :look-at="[0, 0, 0]"
  39. />
  40. <OrbitControls />
  41. <TresAmbientLight :intensity="0.5" />
  42. <TresGroup>
  43. <TresMesh
  44. ref="sphereRef"
  45. :visible="sphereExists"
  46. :user-data="{ debug: true }"
  47. :position="[0, 4, 0]"
  48. cast-shadow
  49. @pointer-enter="onPointerEnter"
  50. >
  51. <TresSphereGeometry :args="[2, 32, 32]" />
  52. <TresMeshToonMaterial color="teal" />
  53. </TresMesh>
  54. </TresGroup>
  55. <TresDirectionalLight
  56. :position="[0, 8, 4]"
  57. :intensity="0.7"
  58. cast-shadow
  59. />
  60. <TresMesh
  61. :rotation="[-Math.PI / 2, 0, 0]"
  62. receive-shadow
  63. >
  64. <TresPlaneGeometry :args="[10, 10, 10, 10]" />
  65. <TresMeshToonMaterial />
  66. </TresMesh>
  67. <TresDirectionalLight
  68. :position="[0, 2, 4]"
  69. :intensity="1"
  70. cast-shadow
  71. />
  72. </TresCanvas>
  73. </template>