Events.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <script setup lang="ts">
  2. import { BasicShadowMap, NoToneMapping, sRGBEncoding } from 'three'
  3. import { reactive } from 'vue'
  4. import { OrbitControls } from '@tresjs/cientos'
  5. const state = reactive({
  6. clearColor: '#201919',
  7. shadows: true,
  8. alpha: false,
  9. shadowMapType: BasicShadowMap,
  10. outputEncoding: sRGBEncoding,
  11. toneMapping: NoToneMapping,
  12. })
  13. function onClick(ev) {
  14. if (ev) {
  15. ev.object.material.color.set('#008080')
  16. }
  17. }
  18. function onPointerEnter(ev) {
  19. console.log(ev)
  20. if (ev) {
  21. ev.object.material.color.set('#CCFF03')
  22. }
  23. }
  24. function onPointerLeave(ev) {
  25. if (ev) {
  26. /* ev.object.material.color.set('#efefef') */
  27. }
  28. }
  29. </script>
  30. <template>
  31. <TresCanvas v-bind="state">
  32. <TresPerspectiveCamera :position="[11, 11, 11]" :fov="45" :near="0.1" :far="1000" :look-at="[-8, 3, -3]" />
  33. <OrbitControls />
  34. <TresScene>
  35. <TresDirectionalLight :position="[0, 8, 4]" :intensity="0.2" cast-shadow />
  36. <template v-for="x in [-2.5, 0, 2.5]">
  37. <template v-for="y in [-2.5, 0, 2.5]">
  38. <TresMesh
  39. v-for="z in [-2.5, 0, 2.5]"
  40. :key="[x, y, z]"
  41. :position="[x, y, z]"
  42. @click="onClick"
  43. @pointer-enter="onPointerEnter"
  44. @pointer-leave="onPointerLeave"
  45. >
  46. <TresBoxGeometry :args="[1, 1, 1]" />
  47. <TresMeshToonMaterial color="#efefef" />
  48. </TresMesh>
  49. </template>
  50. </template>
  51. <TresAmbientLight :intensity="0.5" />
  52. </TresScene>
  53. </TresCanvas>
  54. </template>