|
| 1 | +<script setup lang="ts"> |
| 2 | +import { TresCanvas } from '@tresjs/core' |
| 3 | +import { Image, OrbitControls } from '@tresjs/cientos' |
| 4 | +import { Color, DoubleSide, FrontSide, NoToneMapping } from 'three' |
| 5 | +import { TresLeches, useControls } from '@tresjs/leches' |
| 6 | +import '@tresjs/leches/styles' |
| 7 | +
|
| 8 | +const URLS = [ |
| 9 | + 'https://upload.wikimedia.org/wikipedia/commons/1/13/20220713-great-tit.jpg', |
| 10 | + 'https://upload.wikimedia.org/wikipedia/commons/0/00/Friendly_Robin.jpg', |
| 11 | +] |
| 12 | +
|
| 13 | +const c = useControls({ |
| 14 | + url: 'https://upload.wikimedia.org/wikipedia/commons/d/d4/Mars_2009_Plouaret.jpg', |
| 15 | + segments: { value: 1, min: 1, max: 10, step: 1 }, |
| 16 | + scaleX: { value: 1, min: 0, max: 3, step: 0.01 }, |
| 17 | + scaleY: { value: 1, min: 0, max: 3, step: 0.01 }, |
| 18 | + isRed: false, |
| 19 | + zoom: { value: 1, min: 0, max: 3, step: 0.01 }, |
| 20 | + radius: { value: 0, min: 0, max: 1, step: 0.01 }, |
| 21 | + grayscale: { value: 0, min: 0, max: 1, step: 0.01 }, |
| 22 | + toneMapped: false, |
| 23 | + transparent: true, |
| 24 | + opacity: { value: 1, min: 0, max: 1, step: 0.01 }, |
| 25 | + isDoubleSided: true, |
| 26 | + enabled: true, |
| 27 | +}) |
| 28 | +
|
| 29 | +const opacity = shallowRef(1) |
| 30 | +const url = shallowRef(URLS[0]) |
| 31 | +const sx = shallowRef(1) |
| 32 | +
|
| 33 | +let elapsed = 0 |
| 34 | +setInterval(() => { |
| 35 | + elapsed += 0.01 |
| 36 | + opacity.value = Math.abs(Math.sin(elapsed)) |
| 37 | + url.value = Math.sin(elapsed) > 0 ? URLS[0] : URLS[1] |
| 38 | + sx.value = (Math.cos(elapsed) * 0.5 + 0.5) |
| 39 | +}, 1000 / 30) |
| 40 | +</script> |
| 41 | + |
| 42 | +<template> |
| 43 | + <TresLeches /> |
| 44 | + <TresCanvas :tone-mapping="NoToneMapping"> |
| 45 | + <TresPerspectiveCamera /> |
| 46 | + <OrbitControls /> |
| 47 | + <Image |
| 48 | + :position-y="2" |
| 49 | + :url="url" |
| 50 | + :radius="opacity" |
| 51 | + :color="new Color('white')" |
| 52 | + > |
| 53 | + <TresBoxGeometry /> |
| 54 | + </Image> |
| 55 | + <Image |
| 56 | + v-if="c.enabled.value.value" |
| 57 | + :url="c.url.value.value" |
| 58 | + :segments="c.segments.value.value" |
| 59 | + :scale="[c.scaleX.value.value, c.scaleY.value.value]" |
| 60 | + :color="c.isRed.value.value ? '#F00' : '#FFF'" |
| 61 | + :zoom="c.zoom.value.value" |
| 62 | + :radius="c.radius.value.value" |
| 63 | + :grayscale="c.grayscale.value.value" |
| 64 | + :tone-mapped="c.toneMapped.value.value" |
| 65 | + :transparent="c.transparent.value.value" |
| 66 | + :opacity="c.opacity.value.value" |
| 67 | + :side="c.isDoubleSided.value.value ? DoubleSide : FrontSide" |
| 68 | + /> |
| 69 | + <Image |
| 70 | + :position-x="2" |
| 71 | + :scale="[sx, 1]" |
| 72 | + :url="url" |
| 73 | + /> |
| 74 | + <Image |
| 75 | + :position-y="-2" |
| 76 | + :scale="sx" |
| 77 | + :url="url" |
| 78 | + > |
| 79 | + <TresCircleGeometry /> |
| 80 | + </Image> |
| 81 | + |
| 82 | + <Image |
| 83 | + :position-x="-2" |
| 84 | + :url="url" |
| 85 | + :radius="opacity" |
| 86 | + :transparent="true" |
| 87 | + /> |
| 88 | + </TresCanvas> |
| 89 | +</template> |
0 commit comments