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
selectedMeshtoCustomRenderercomponent
- Bind the mesh we want to outline, and pass it as prop
- Postprocessing is performed within
CustomRenderercomponent- We use the ‘postprocessing’ library
- Create a new
EffectComposerwith Threlte’srenderer - Then run our own render loop with this new render function, using
useTaskfrom threlte, make sure to setautoRendertofalse - Our function
setupEffectComposeradds the requiredRenderPass, andOutlinePassto theEffectComposer, specifically to ourMeshobject - This function will re-run if
selectedMeshchanges
- Animation of the cube is done with
svelte/motioninScene.svelte