Outlines
Implements the Outline postprocessing pass. Vanilla threejs example here
An outlined cube loops through a maze, with a different outline color when the object is hidden.
<script lang="ts">
import { Canvas } from '@threlte/core'
import Scene from './Scene.svelte'
</script>
<div>
<Canvas>
<Scene />
</Canvas>
</div>
<style>
div {
height: 100%;
}
</style>
How it works
- In
Scene.svelte
- Bind the mesh we want to outline, and pass it as prop
selectedMesh
toCustomRenderer
component
- Bind the mesh we want to outline, and pass it as prop
- Postprocessing is performed within
CustomRenderer
component- We use the ‘postprocessing’ library
- Create a new
EffectComposer
with Threlte’srenderer
- Then run our own render loop with this new render function, using
useTask
from threlte, make sure to setautoRender
tofalse
- Our function
setupEffectComposer
adds the requiredRenderPass
, andOutlinePass
to theEffectComposer
, specifically to ourMesh
object - This function will re-run if
selectedMesh
changes
- Animation of the cube is done with
svelte/motion
inScene.svelte