threlte logo
@threlte/extras

<Billboard>

This component is a port of drei’s <Billboard> component which rotates its contents to always face the camera.

<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 } from '@threlte/core'
  import { OrbitControls, Grid, Billboard } from '@threlte/extras'
</script>

<Billboard>
  <T.Mesh position={[3, 1, 0]}>
    <T.MeshBasicMaterial color="red" />
    <T.PlaneGeometry args={[2, 3]} />
  </T.Mesh>

  <T.Mesh position={[-4, 3, 0]}>
    <T.MeshBasicMaterial color="green" />
    <T.PlaneGeometry args={[3, 2]} />
  </T.Mesh>

  <T.Mesh position={[-1, 5, 2]}>
    <T.MeshBasicMaterial color="blue" />
    <T.PlaneGeometry args={[2, 2]} />
  </T.Mesh>
</Billboard>

<T.PerspectiveCamera
  makeDefault
  position.y={8}
  position.z={8}
  fov={90}
  on:create={({ ref }) => {
    ref.lookAt(0, 0, 0)
  }}
>
  <OrbitControls
    enableDamping
    enablePan={false}
    enableZoom={false}
  />
</T.PerspectiveCamera>

<Grid
  position.y={0}
  sectionThickness={1}
  infiniteGrid
  cellColor="#dddddd"
  sectionColor="#ffffff"
  sectionSize={10}
  cellSize={2}
/>

Examples

Basic Example

Billboard.svelte
<script lang="ts">
  import { T } from '@threlte/core'
  import { Billboard } from '@threlte/extras'
</script>

<Billboard>
  <T.Mesh>
    <T.MeshStandardMaterial />
    <T.PlaneGeometry args={[2, 2]} />
  </T.Mesh>
</Billboard>

To disable the billboard from rotating its contents to face the camera, you can optionally pass in a follow prop set to false.

You can also optionally pass in a lockX, lockY, or lockZ prop to lock the rotation of the billboard on a specific axis.

BillboardLocked.svelte
<script lang="ts">
  import { T } from '@threlte/core'
  import { Billboard } from '@threlte/extras'
</script>

<Billboard lockX>
  <T.Mesh>
    <T.MeshStandardMaterial />
    <T.PlaneGeometry args={[2, 2]} />
  </T.Mesh>
</Billboard>

Component Signature

<Billboard> extends <T.Group> and supports all its props, slot props, bindings and events.

Props

name
type
required
default

follow
boolean
no
true

lockX
boolean
no
false

lockY
boolean
no
false

lockZ
boolean
no
false