11<script lang="ts" setup>
2- import { ref , shallowRef } from ' vue'
3- import { watchOnce } from ' @vueuse/core'
2+ import { ref } from ' vue'
3+ import type { Intersection , Object3D } from ' three'
4+ import { NoToneMapping } from ' three'
45import { TresCanvas } from ' @tresjs/core'
6+ import { OrbitControls } from ' @tresjs/cientos'
7+ import { Outline , EffectComposer } from ' @tresjs/post-processing'
58import { KernelSize } from ' postprocessing'
6- import { EffectComposer , Outline } from ' @tresjs/post-processing'
7- import type { Intersection , Object3D } from ' three'
8- import { Color } from ' three'
99
10- const boxWidth = 2
10+ import { TresLeches , useControls } from ' @tresjs/leches'
11+ import ' @tresjs/leches/styles'
12+
13+ import { useRouteDisposal } from ' ../composables/useRouteDisposal'
14+
15+ const gl = {
16+ clearColor: ' #121212' ,
17+ toneMapping: NoToneMapping ,
18+ disableRender: true ,
19+ }
20+
21+ const { effectComposer } = useRouteDisposal ()
22+
1123const outlinedObjects = ref <Object3D []>([])
1224
1325const toggleMeshSelectionState = ({ object }: Intersection ) => {
@@ -16,55 +28,71 @@ const toggleMeshSelectionState = ({ object }: Intersection) => {
1628 else outlinedObjects .value = [... outlinedObjects .value , object ]
1729}
1830
19- const meshes = shallowRef <Object3D [] | null >(null )
20-
21- watchOnce (meshes , () => {
22- if (meshes .value ?.[0 ]) outlinedObjects .value .push (meshes .value [0 ])
23- if (meshes .value ?.[2 ]) outlinedObjects .value .push (meshes .value [2 ])
31+ const { edgeStrength, pulseSpeed, visibleEdgeColor, blur, kernelSize } = useControls ({
32+ edgeStrength: {
33+ value: 8000 ,
34+ min: 0 ,
35+ max: 8000 ,
36+ step: 10 ,
37+ },
38+ pulseSpeed: {
39+ value: 0 ,
40+ min: 0 ,
41+ max: 2 ,
42+ step: 0.01 ,
43+ },
44+ visibleEdgeColor: ' #ffffff' ,
45+ blur: false ,
46+ kernelSize: {
47+ value: 0 ,
48+ min: KernelSize .VERY_SMALL ,
49+ max: KernelSize .VERY_LARGE ,
50+ step: 1 ,
51+ },
2452})
53+
54+ // Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
55+ useRouteDisposal (effectComposer )
2556 </script >
2657
2758<template >
59+ <TresLeches />
2860 <TresCanvas
29- clear-color =" #121212"
30- :alpha =" false"
31- :shadows =" true"
61+ v-bind =" gl"
3262 :disable-render =" true"
3363 >
3464 <TresPerspectiveCamera
35- :position =" [3 , 3, 4 ]"
36- :look-at =" [0, 0, 0 ]"
65+ :position =" [1 , 3, 3 ]"
66+ :look-at =" [2, 2, 2 ]"
3767 />
38- <TresMesh
39- v-for =" i in 3"
40- ref =" meshes"
41- :key =" i.toString()"
42- :position =" [(i - 2) * boxWidth, 0.5, 1]"
43- @click =" toggleMeshSelectionState"
68+ <OrbitControls />
69+ <template
70+ v-for =" i in 5 "
71+ :key =" i "
4472 >
45- <TresBoxGeometry />
46- <TresMeshStandardMaterial
47- color =" hotpink"
48- :emissive =" new Color('hotpink')"
49- :emissive-intensity =" 1"
50- />
51- </TresMesh >
73+ <TresMesh
74+ :position =" [i * 1.1 - 2.8, 1, 0]"
75+ @click =" toggleMeshSelectionState"
76+ >
77+ <TresBoxGeometry
78+ :width =" 4"
79+ :height =" 4"
80+ :depth =" 4"
81+ />
82+ <TresMeshStandardMaterial color =" hotpink" />
83+ </TresMesh >
84+ </template >
5285 <TresGridHelper />
5386 <TresAmbientLight :intensity =" 2" />
54- <TresDirectionalLight
55- :position =" [-4, 4, 3]"
56- :intensity =" 2"
57- />
58-
5987 <Suspense >
60- <EffectComposer >
88+ <EffectComposer ref = " effectComposer " >
6189 <Outline
62- blur
63- :edge-glow =" 3"
64- :kernel-size =" KernelSize.LARGE"
65- :edge-strength =" 20"
6690 :outlined-objects =" outlinedObjects"
67- visible-edge-color =" #82DBC5"
91+ :blur =" blur.value"
92+ :edge-strength =" edgeStrength.value"
93+ :pulse-speed =" pulseSpeed.value"
94+ :visible-edge-color =" visibleEdgeColor.value"
95+ :kernel-size =" kernelSize.value"
6896 />
6997 </EffectComposer >
7098 </Suspense >
0 commit comments