|
| 1 | +<!-- eslint-disable ts/no-use-before-define --> |
| 2 | + |
| 3 | +<script setup lang="ts"> |
| 4 | +import { gsap } from 'gsap' |
| 5 | +import { Environment, OrbitControls, Precipitation, RoundedBox } from '@tresjs/cientos' |
| 6 | +import { TresCanvas } from '@tresjs/core' |
| 7 | +import { TresLeches, useControls } from '@tresjs/leches' |
| 8 | +import { EffectComposerPmndrs, FishEyePmndrs } from '@tresjs/post-processing' |
| 9 | +import { BackSide, NoToneMapping } from 'three' |
| 10 | +import { ref, watch } from 'vue' |
| 11 | +import { BlendFunction } from 'postprocessing' |
| 12 | +
|
| 13 | +import '@tresjs/leches/styles' |
| 14 | +
|
| 15 | +const gl = { |
| 16 | + clearColor: '#ffffff', |
| 17 | + toneMapping: NoToneMapping, |
| 18 | + multisampling: 8, |
| 19 | +} |
| 20 | +
|
| 21 | +const lensParams = [ |
| 22 | + { lensSX: 1.0, lensSY: 1.0, lensFX: 0.0, lensFY: 1.0 }, |
| 23 | + { lensSX: 0.5, lensSY: 1.0, lensFX: -0.25, lensFY: 0.75 }, |
| 24 | + { lensSX: 1.0, lensSY: 1.0, lensFX: -1.0, lensFY: 1.0 }, |
| 25 | + { lensSX: 0.8, lensSY: 0.8, lensFX: -0.5, lensFY: 0.5 }, |
| 26 | + { lensSX: 1, lensSY: 1, lensFX: 0, lensFY: 2 }, |
| 27 | + { lensSX: -0.7, lensSY: 0.7, lensFX: 0.5, lensFY: -0.5 }, |
| 28 | + { lensSX: -1.2, lensSY: 1.2, lensFX: 1.0, lensFY: -1.0 }, |
| 29 | + { lensSX: 1, lensSY: 1, lensFX: 0, lensFY: 0 }, |
| 30 | + { lensSX: 0.9, lensSY: 0.9, lensFX: 1.5, lensFY: -1.5 }, |
| 31 | + { lensSX: 1.3, lensSY: 1.3, lensFX: 1.5, lensFY: -1.0 }, |
| 32 | +] |
| 33 | +
|
| 34 | +const tweenParams = { |
| 35 | + duration: 2, |
| 36 | + ease: 'elastic.out(0.85,0.3)', |
| 37 | +} |
| 38 | +
|
| 39 | +const localBlendFunction = ref(BlendFunction.NORMAL) |
| 40 | +
|
| 41 | +const currentIndex = ref(0) |
| 42 | +
|
| 43 | +const onSwitch = () => { |
| 44 | + currentIndex.value = (currentIndex.value + 1) % lensParams.length |
| 45 | +
|
| 46 | + gsap.to(lensSX, { value: lensParams[currentIndex.value].lensSX, ...tweenParams }) |
| 47 | + gsap.to(lensSY, { value: lensParams[currentIndex.value].lensSY, ...tweenParams }) |
| 48 | + gsap.to(lensFX, { value: lensParams[currentIndex.value].lensFX, ...tweenParams }) |
| 49 | + gsap.to(lensFY, { value: lensParams[currentIndex.value].lensFY, ...tweenParams }) |
| 50 | +} |
| 51 | +
|
| 52 | +const { enabled, lensSX, lensSY, lensFX, lensFY, scale } = useControls({ |
| 53 | + acceptBtn: { |
| 54 | + label: 'Switch Lens', |
| 55 | + type: 'button', |
| 56 | + onClick: onSwitch, |
| 57 | + size: 'md', |
| 58 | + }, |
| 59 | + lensSX: { value: lensParams[0].lensSX, step: 0.01, min: -2, max: 2 }, |
| 60 | + lensSY: { value: lensParams[0].lensFY, step: 0.01, min: -2, max: 2 }, |
| 61 | + lensFX: { value: lensParams[0].lensFX, step: 0.01, min: -2, max: 2 }, |
| 62 | + lensFY: { value: lensParams[0].lensFY, step: 0.01, min: -2, max: 2 }, |
| 63 | + scale: { value: 1.0, step: 0.01, min: 0.1, max: 2 }, |
| 64 | + enabled: true, |
| 65 | +}) |
| 66 | +
|
| 67 | +watch(enabled, () => { |
| 68 | + localBlendFunction.value = enabled.value ? BlendFunction.NORMAL : BlendFunction.SKIP |
| 69 | +}) |
| 70 | +</script> |
| 71 | + |
| 72 | +<template> |
| 73 | + <div class="aspect-16/9"> |
| 74 | + <TresCanvas |
| 75 | + v-bind="gl" |
| 76 | + > |
| 77 | + <TresPerspectiveCamera |
| 78 | + :position="[5, 5, 5]" |
| 79 | + /> |
| 80 | + <OrbitControls :target="[0, .5, 0]" auto-rotate :maxPolarAngle="Math.PI / 2" /> |
| 81 | + |
| 82 | + <Suspense> |
| 83 | + <Environment preset="snow" /> |
| 84 | + </Suspense> |
| 85 | + |
| 86 | + <TresAmbientLight :intensity=".5" /> |
| 87 | + |
| 88 | + <TresMesh :rotation-x="-Math.PI / 2"> |
| 89 | + <TresPlaneGeometry :args="[15, 15]" /> |
| 90 | + <TresMeshPhysicalMaterial |
| 91 | + :metalness=".5" |
| 92 | + :roughness=".85" |
| 93 | + /> |
| 94 | + </TresMesh> |
| 95 | + |
| 96 | + <TresMesh> |
| 97 | + <TresSphereGeometry :args="[7.5, 32, 32]" /> |
| 98 | + <TresMeshPhysicalMaterial |
| 99 | + :metalness=".5" |
| 100 | + :roughness=".25" |
| 101 | + :side="BackSide" |
| 102 | + /> |
| 103 | + </TresMesh> |
| 104 | + |
| 105 | + <RoundedBox |
| 106 | + v-for="(positionX, index) in [-1.75, 1.75]" |
| 107 | + :key="index" |
| 108 | + :position="positionX" |
| 109 | + :position-y="1.05" |
| 110 | + :args="[2, 2, 2, 2, 0.25]" |
| 111 | + > |
| 112 | + <TresMeshPhysicalMaterial |
| 113 | + :metalness="0.5" |
| 114 | + :roughness=".3" |
| 115 | + /> |
| 116 | + </RoundedBox> |
| 117 | + |
| 118 | + <Precipitation |
| 119 | + :randomness="3" |
| 120 | + :speed="1" |
| 121 | + :count="2500" |
| 122 | + /> |
| 123 | + |
| 124 | + <Suspense> |
| 125 | + <EffectComposerPmndrs> |
| 126 | + <FishEyePmndrs |
| 127 | + :blendFunction="localBlendFunction" |
| 128 | + :lensS="[lensSX, lensSY]" |
| 129 | + :lensF="[lensFX, lensFY]" |
| 130 | + :scale="scale" |
| 131 | + /> |
| 132 | + </EffectComposerPmndrs> |
| 133 | + </Suspense> |
| 134 | + </TresCanvas> |
| 135 | + </div> |
| 136 | + <TresLeches :float="false" /> |
| 137 | +</template> |
0 commit comments