index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <script setup lang="ts">
  2. import type { Camera } from 'three'
  3. import { TresCanvas } from '@tresjs/core'
  4. import { TresLeches, useControls } from '@tresjs/leches'
  5. import TheCameraOperator from './TheCameraOperator.vue'
  6. import '@tresjs/leches/styles'
  7. useControls('fpsgraph')
  8. const camera1 = shallowRef<Camera>()
  9. const camera2 = shallowRef<Camera>()
  10. const camera3 = shallowRef<Camera>()
  11. const cameraUuidList = computed(() => [
  12. camera1.value?.uuid,
  13. camera2.value?.uuid,
  14. camera3.value?.uuid,
  15. ])
  16. const { cameras: activeCameraIndex } = useControls({
  17. cameras: {
  18. value: 0,
  19. options: [
  20. {
  21. text: 'Camera 1',
  22. value: 0,
  23. },
  24. {
  25. text: 'Camera 2',
  26. value: 1,
  27. },
  28. {
  29. text: 'Camera 3',
  30. value: 2,
  31. },
  32. ],
  33. },
  34. })
  35. const activeCameraUuid = computed(() => cameraUuidList.value[activeCameraIndex.value])
  36. </script>
  37. <template>
  38. <TresLeches>
  39. {{ activeCameraUuid }}
  40. </TresLeches>
  41. <TresCanvas clear-color="#4f4f4f">
  42. <TheCameraOperator :active-camera-uuid="activeCameraUuid">
  43. <TresPerspectiveCamera
  44. ref="camera1"
  45. :position="[5, 5, 5]"
  46. :fov="45"
  47. :near="0.1"
  48. :far="1000"
  49. :look-at="[0, 4, 0]"
  50. />
  51. <TresPerspectiveCamera
  52. ref="camera2"
  53. :position="[15, 5, 5]"
  54. :fov="45"
  55. :near="0.1"
  56. :far="1000"
  57. :look-at="[0, 4, 0]"
  58. />
  59. <TresPerspectiveCamera
  60. ref="camera3"
  61. :position="[-15, 8, 5]"
  62. :fov="25"
  63. :near="0.1"
  64. :far="1000"
  65. :look-at="[0, 4, 0]"
  66. />
  67. </TheCameraOperator>
  68. <TresAmbientLight :intensity="0.5" />
  69. <TresMesh :position="[0, 4, 0]">
  70. <TresBoxGeometry :args="[1, 1, 1]" />
  71. <TresMeshToonMaterial color="cyan" />
  72. </TresMesh>
  73. <Suspense>
  74. <PbrSphere />
  75. </Suspense>
  76. <TresDirectionalLight
  77. :position="[0, 2, 4]"
  78. :intensity="1"
  79. />
  80. </TresCanvas>
  81. </template>