Skip to content

Commit

Permalink
fixed types and restructured composable a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinoooo committed Nov 17, 2023
1 parent e9930f7 commit 7a8fe67
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 52 deletions.
4 changes: 1 addition & 3 deletions docs/.vitepress/theme/components/BloomDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Color } from 'three'
import { reactive, ref } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { BlendFunction } from 'postprocessing'
import type { EffectComposer as EffectComposerImpl } from 'postprocessing'
import { EffectComposer, Bloom } from '@tresjs/post-processing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
Expand All @@ -25,8 +24,7 @@ const bloomParams = reactive({
})
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const effectComposer = ref<EffectComposerImpl | null>(null)
useRouteDisposal(effectComposer)
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand Down
38 changes: 8 additions & 30 deletions docs/.vitepress/theme/components/DepthOfFieldDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ref } from 'vue'
import { gsap } from 'gsap'
import { TresCanvas } from '@tresjs/core'
import { EffectComposer, DepthOfField } from '@tresjs/post-processing'
import type { EffectComposer as EffectComposerImpl } from 'postprocessing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
Expand All @@ -18,13 +17,11 @@ const toggleFocusDistance = () => {
}
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const effectComposer = ref<EffectComposerImpl | null>(null)
useRouteDisposal(effectComposer)
const { effectComposer } = useRouteDisposal()
</script>

<template>
<button
class="
<button class="

Check warning on line 24 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

Expected a linebreak before this attribute
absolute
rounded
px-2 py-1
Expand All @@ -39,42 +36,23 @@ useRouteDisposal(effectComposer)
active:bg-gray-400/50
font-semibold
transition-colors
"
@click="toggleFocusDistance"
>
" @click="toggleFocusDistance">

Check failure on line 39 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

'@click' should be on a new line

Check warning on line 39 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

Expected 1 line break before closing bracket, but no line breaks found
toggle focus
</button>
<TresCanvas>
<TresPerspectiveCamera
:rotation="[-0.89, 1.28, 0.87]"
:position="[5.55, 1.57, 1.02]"
/>
<TresPerspectiveCamera :rotation="[-0.89, 1.28, 0.87]" :position="[5.55, 1.57, 1.02]" />

Check failure on line 43 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':position' should be on a new line
<TresMesh :position="[-2, 1, 0]">
<TresBoxGeometry
:width="3"
:height="3"
:depth="3"
/>
<TresBoxGeometry :width="3" :height="3" :depth="3" />

Check failure on line 45 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':height' should be on a new line

Check failure on line 45 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':depth' should be on a new line
<TresMeshNormalMaterial />
</TresMesh>
<TresMesh :position="[3, 1, 0]">
<TresBoxGeometry
:width="3"
:height="3"
:depth="3"
/>
<TresBoxGeometry :width="3" :height="3" :depth="3" />

Check failure on line 49 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':height' should be on a new line

Check failure on line 49 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':depth' should be on a new line
<TresMeshNormalMaterial />
</TresMesh>
<TresGridHelper />
<EffectComposer ref="effectComposer">
<DepthOfField
ref="dofEffect"
:focus-distance="0.0012"
:world-focus-distance="2"
:world-focus-range="1"
:bokeh-scale="8"
:focus-range="0.005"
/>
<DepthOfField ref="dofEffect" :focus-distance="0.0012" :world-focus-distance="2" :world-focus-range="1"

Check warning on line 54 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

Expected a linebreak before this attribute

Check failure on line 54 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':focus-distance' should be on a new line

Check failure on line 54 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':world-focus-distance' should be on a new line

Check failure on line 54 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':world-focus-range' should be on a new line
:bokeh-scale="8" :focus-range="0.005" />

Check warning on line 55 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

Expected indentation of 20 spaces but found 8 spaces

Check failure on line 55 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

':focus-range' should be on a new line

Check warning on line 55 in docs/.vitepress/theme/components/DepthOfFieldDemo.vue

View workflow job for this annotation

GitHub Actions / Lint (16)

Expected 1 line break before closing bracket, but no line breaks found
</EffectComposer>
</TresCanvas>
</template>
5 changes: 1 addition & 4 deletions docs/.vitepress/theme/components/GlitchDemo.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<script setup lang="ts">
import { ref } from 'vue'
import { Color } from 'three'
import { TresCanvas } from '@tresjs/core'
import { Text3D } from '@tresjs/cientos'
import { EffectComposer, Glitch } from '@tresjs/post-processing'
import type { EffectComposer as EffectComposerImpl } from 'postprocessing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
Expand All @@ -17,8 +15,7 @@ const gl = {
}
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const effectComposer = ref<EffectComposerImpl | null>(null)
useRouteDisposal(effectComposer)
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand Down
5 changes: 1 addition & 4 deletions docs/.vitepress/theme/components/NoiseDemo.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<script setup lang="ts">
import { ref } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three'
import { EffectComposer, Noise } from '@tresjs/post-processing'
import { OrbitControls } from '@tresjs/cientos'
import { BlendFunction } from 'postprocessing'
import type { EffectComposer as EffectComposerImpl } from 'postprocessing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
Expand All @@ -19,8 +17,7 @@ const gl = {
}
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const effectComposer = ref<EffectComposerImpl | null>(null)
useRouteDisposal(effectComposer)
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand Down
3 changes: 1 addition & 2 deletions docs/.vitepress/theme/components/OutlineDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { NoToneMapping } from 'three'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { Outline, EffectComposer } from '@tresjs/post-processing'
import type { EffectComposer as EffectComposerImpl } from 'postprocessing'
import { KernelSize } from 'postprocessing'
import { TresLeches, useControls } from '@tresjs/leches'
Expand All @@ -19,7 +18,7 @@ const gl = {
disableRender: true,
}
const effectComposer = ref<EffectComposerImpl | null>(null)
const { effectComposer } = useRouteDisposal()
const outlinedObjects = ref<Object3D[]>([])
Expand Down
4 changes: 1 addition & 3 deletions docs/.vitepress/theme/components/PixelationDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { EffectComposer, Pixelation } from '@tresjs/post-processing'
import type { EffectComposer as EffectComposerImpl } from 'postprocessing'
import { ref } from 'vue'
import { useRouteDisposal } from '../composables/useRouteDisposal'
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const effectComposer = ref<EffectComposerImpl | null>(null)
useRouteDisposal(effectComposer)
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand Down
5 changes: 1 addition & 4 deletions docs/.vitepress/theme/components/VignetteDemo.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<script setup lang="ts">
import { ref } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three'
import { OrbitControls } from '@tresjs/cientos'
import { EffectComposer, Vignette, DepthOfField } from '@tresjs/post-processing'
import type { EffectComposer as EffectComposerImpl } from 'postprocessing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
Expand All @@ -20,8 +18,7 @@ const gl = {
}
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const effectComposer = ref<EffectComposerImpl | null>(null)
useRouteDisposal(effectComposer)
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand Down
12 changes: 10 additions & 2 deletions docs/.vitepress/theme/composables/useRouteDisposal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { useRouter } from 'vitepress'
import { ref } from 'vue'
import { watch } from 'vue'
import { useRouter } from 'vitepress'
import type { EffectComposer } from '@tresjs/post-processing'

export function useRouteDisposal(effectComposer) {
export function useRouteDisposal() {
const router = useRouter()

const effectComposer = ref<InstanceType<typeof EffectComposer> | null>(null)

watch(() => router.route.data.relativePath, () => {
effectComposer.value?.composer.dispose()
})

return {
effectComposer
}
}

0 comments on commit 7a8fe67

Please sign in to comment.