index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <script setup lang="ts">
  2. import { TresCanvas } from '@tresjs/core'
  3. import { BasicShadowMap, NoToneMapping, SRGBColorSpace } from 'three'
  4. import { Perf, TresLeches, useControls } from '@tresjs/leches'
  5. import '@tresjs/leches/styles'
  6. import { OrbitControls } from '@tresjs/cientos'
  7. import AsyncComponent from './AsyncComponent.vue'
  8. const gl = {
  9. clearColor: '#82DBC5',
  10. shadows: true,
  11. alpha: false,
  12. shadowMapType: BasicShadowMap,
  13. outputColorSpace: SRGBColorSpace,
  14. toneMapping: NoToneMapping,
  15. }
  16. const { show } = useControls({
  17. show: true,
  18. })
  19. const ctx = ref(null)
  20. watchEffect(() => {
  21. if (!ctx.value) {
  22. return
  23. }
  24. // eslint-disable-next-line no-console
  25. console.log('ctx', ctx.value)
  26. })
  27. useControls({
  28. button: {
  29. label: 'Render dispose',
  30. type: 'button',
  31. onClick() {
  32. ctx?.value?.dispose()
  33. },
  34. },
  35. })
  36. </script>
  37. <template>
  38. <TresLeches />
  39. <TresCanvas v-bind="gl" ref="ctx">
  40. <Perf />
  41. <TresPerspectiveCamera :position="[3, 3, 3]" />
  42. <OrbitControls />
  43. <Suspense>
  44. <AsyncComponent v-if="show" />
  45. </Suspense>
  46. <TresAmbientLight :intensity="1" />
  47. </TresCanvas>
  48. <OverlayInfo>
  49. <h1>Suspense</h1>
  50. <p>
  51. Because the model in this page is loaded asynchronously behind the scenes
  52. with <code>useGLTF</code>, it must be wrapped in a Suspense component.
  53. </p>
  54. </OverlayInfo>
  55. </template>