threlte logo
@threlte/extras

<Outlines>

webgl <Outlines> works with WebGL only.

A port of the drei <Outlines> component.

An ornamental component that extracts the geometry from its parent and displays an inverted-hull outline. Supported parents are Mesh, SkinnedMesh and InstancedMesh.

<script lang="ts">
  import { Canvas } from '@threlte/core'
  import Scene from './Scene.svelte'
</script>

<div>
  <Canvas>
    <Scene />
  </Canvas>
</div>

<style>
  div {
    height: 100%;
  }
</style>
<script lang="ts">
  import { T, useTask } from '@threlte/core'
  import { Edges, Outlines, useDraco, useGltf } from '@threlte/extras'
  import { Mesh, MeshStandardMaterial, MathUtils } from 'three'

  let rotation = $state(0)
  useTask((delta) => {
    rotation += delta
  })

  const helmetGltf = useGltf<{
    nodes: {
      'node_damagedHelmet_-6514': Mesh
    }
    materials: {
      Material_MR: MeshStandardMaterial
    }
  }>('/models/helmet/DamagedHelmet.gltf')

  const helmetGeometry = $derived($helmetGltf?.nodes['node_damagedHelmet_-6514'].geometry)

  const dracoLoader = useDraco()
  const suziGltf = useGltf<{
    nodes: {
      Suzanne: Mesh
    }
    materials: {
      Material_MR: MeshStandardMaterial
    }
  }>('/models/Suzanne.glb', { dracoLoader })
</script>

<T.PerspectiveCamera
  makeDefault
  position.z={20}
  fov={20}
/>

<T.DirectionalLight position={[5, 5, 5]} />

<T.Group
  rotation.y={rotation}
  position.x={-3}
>
  <T.Mesh>
    <T.TorusKnotGeometry args={[0.5, 0.15, 128, 64]} />
    <T.MeshToonMaterial color="#ff3e00" />
    <Outlines color="white" />
    <Outlines
      color="hotpink"
      thickness={0.05}
    />
    <Outlines
      color="yellow"
      thickness={0.1}
    />
  </T.Mesh>
</T.Group>

<T.Group rotation.y={rotation}>
  {#if helmetGeometry}
    <T.Mesh
      rotation.x={90 * MathUtils.DEG2RAD}
      geometry={helmetGeometry}
    >
      <T.MeshBasicMaterial
        color="#ff3e00"
        toneMapped={false}
      />
      <Edges
        thresholdAngle={20}
        color="white"
        scale={1.01}
      />
      <Outlines
        color="white"
        thickness={0.04}
      />
    </T.Mesh>
  {/if}
</T.Group>

{#if $suziGltf}
  <T.Group
    rotation.y={rotation}
    position.x={3}
  >
    <T.Mesh geometry={$suziGltf.nodes['Suzanne'].geometry}>
      <T.MeshToonMaterial color="turquoise" />
      <Outlines
        color="white"
        screenspace
        thickness={3}
      />
    </T.Mesh>
  </T.Group>
{/if}

Model: Battle Damaged Sci-fi Helmet by theblueturtle_

Example

<script lang="ts">
  import { BoxGeometry, MeshBasicMaterial } from 'three'
  import { T } from '@threlte/core'
  import { Outlines } from '@threlte/extras'
</script>

<T.Mesh
  geometry={new BoxGeometry()}
  material={new MeshBasicMaterial()}
>
  <Outlines color="black" />
</T.Mesh>

Component Signature

Props

name
type
required
default
description

angle
number
no
Math.PI
The crease angle in radians. Where faces meet at a sharper angle, the outline splits instead of bulging around the corner. The default keeps every corner smooth.

color
ColorRepresentation
no
'black'
The color of the outline.

opacity
number
no
1
The opacity of the outline. Values below 1 need transparent set.

polygonOffset
boolean
no
false
Enables polygon offset on the outline material, which helps against z-fighting with the mesh.

polygonOffsetFactor
number
no
0
The polygon offset factor, when polygonOffset is enabled.

renderOrder
number
no
0
The render order of the outline mesh.

screenspace
boolean
no
false
Keeps the outline the same thickness on screen regardless of distance and zoom.

thickness
number
no
0.05
The thickness of the outline, in world units.

toneMapped
boolean
no
true
Whether the renderer's tone mapping applies to the outline.

transparent
boolean
no
false
Whether the outline material is transparent.