-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/three-0.x
- Loading branch information
Showing
18 changed files
with
398 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<script lang="ts" setup> | ||
import { Color } from 'three' | ||
import { TresCanvas } from '@tresjs/core' | ||
import { OrbitControls } from '@tresjs/cientos' | ||
import { EffectComposer, Pixelation } from '@tresjs/post-processing' | ||
const boxWidth = 2 | ||
</script> | ||
|
||
<template> | ||
<TresCanvas | ||
clear-color="#121212" | ||
:alpha="false" | ||
:shadows="true" | ||
:disable-render="true" | ||
> | ||
<TresPerspectiveCamera | ||
:position="[3, 2, 4]" | ||
:look-at="[0, 0, 0]" | ||
/> | ||
<OrbitControls /> | ||
<TresMesh | ||
:position="[1, 0.5, 1]" | ||
> | ||
<TresBoxGeometry /> | ||
<TresMeshStandardMaterial | ||
color="hotpink" | ||
/> | ||
</TresMesh> | ||
<TresMesh | ||
:position="[-1.5, 0.75, 0]" | ||
> | ||
<TresConeGeometry :args="[1, 1.5, 4, 1, false, Math.PI * 0.25]" /> | ||
<TresMeshNormalMaterial /> | ||
<TresMeshStandardMaterial | ||
color="aqua" | ||
/> | ||
</TresMesh> | ||
|
||
<TresGridHelper /> | ||
<TresAmbientLight :intensity="0.9" /> | ||
<TresDirectionalLight | ||
:position="[-10, 5, 8]" | ||
:intensity="1" | ||
/> | ||
|
||
<Suspense> | ||
<EffectComposer> | ||
<Pixelation :granularity="8" /> | ||
</EffectComposer> | ||
</Suspense> | ||
</TresCanvas> | ||
</template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Pixelation | ||
|
||
<DocsDemo> | ||
<PixelationDemo /> | ||
</DocsDemo> | ||
|
||
Pixelation is an effect that pixelates the scene. | ||
|
||
## Usage | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
import { EffectComposer, Pixelation } from '@tresjs/post-processing' | ||
</script> | ||
<template> | ||
<EffectComposer> | ||
<Pixelation /> | ||
</EffectComposer> | ||
</template> | ||
``` | ||
|
||
## Props | ||
|
||
| Prop | Description | Default | | ||
| ----------- | ------------------------------ | ------- | | ||
| granularity | The granularity of the pixels. | 30 | | ||
|
||
## Further Reading | ||
see [postprocessing docs](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/PixelationEffect.js~PixelationEffect.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts" setup> | ||
import { computed } from 'vue' | ||
import { TresCanvas } from '@tresjs/core' | ||
import { OrbitControls } from '@tresjs/cientos' | ||
import { EffectComposer, Pixelation } from '@tresjs/post-processing' | ||
import { TresLeches, useControls } from '@tresjs/leches' | ||
import '@tresjs/leches/styles' | ||
useControls('fpsgraph') | ||
const { granularity } = useControls({ | ||
granularity: { | ||
value: 10, | ||
min: 1, | ||
max: 30, | ||
step: 1, | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<TresLeches /> | ||
<TresCanvas> | ||
<TresPerspectiveCamera | ||
:position="[5, 5, 5]" | ||
:look-at="[0, 0, 0]" | ||
/> | ||
<OrbitControls /> | ||
<TresMesh | ||
:position="[-3.5, 1, 0]" | ||
> | ||
<TresConeGeometry :args="[1.25, 2, 4, 1, false, Math.PI * 0.25]" /> | ||
<TresMeshNormalMaterial /> | ||
</TresMesh> | ||
|
||
<TresMesh :position="[0, 1, 0]"> | ||
<TresBoxGeometry :args="[2, 2, 2]" /> | ||
<TresMeshNormalMaterial /> | ||
</TresMesh> | ||
|
||
<TresMesh :position="[3.5, 1, 0]"> | ||
<TresSphereGeometry /> | ||
<TresMeshNormalMaterial /> | ||
</TresMesh> | ||
|
||
<TresGridHelper /> | ||
|
||
<EffectComposer> | ||
<Pixelation :granularity="granularity" /> | ||
</EffectComposer> | ||
</TresCanvas> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { Effect } from 'postprocessing' | ||
import { EffectPass } from 'postprocessing' | ||
import { inject, onUnmounted, shallowRef, watchEffect, defineExpose } from 'vue' | ||
import { useTresContext } from '@tresjs/core' | ||
import { effectComposerInjectionKey } from '../injectionKeys' | ||
|
||
export const useEffect = <T extends Effect>( newEffectFunction: () => T) => { | ||
const composer = inject(effectComposerInjectionKey) | ||
const pass = shallowRef<EffectPass | null>(null) | ||
const effect = shallowRef<T | null>(null) | ||
|
||
const { scene, camera } = useTresContext() | ||
|
||
watchEffect(() => { | ||
if (!camera.value || !effect?.value) return | ||
|
||
effect.value.mainCamera = camera.value | ||
}) | ||
|
||
let unwatch = () => {} // seperate declaration prevents error in HMR | ||
|
||
unwatch = watchEffect(() => { | ||
if (!camera.value || !composer?.value || !scene.value) return | ||
|
||
unwatch() | ||
if (effect.value) return | ||
|
||
effect.value = newEffectFunction() | ||
pass.value = new EffectPass(camera.value, effect.value) | ||
|
||
composer.value.addPass(pass.value) | ||
}) | ||
|
||
onUnmounted(() => { | ||
if (pass.value) composer?.value?.removePass(pass.value) | ||
effect.value?.dispose() | ||
pass.value?.dispose() | ||
}) | ||
|
||
return { | ||
pass, | ||
effect, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.