@threlte/theatre

<Sequence>

Sequences are the heart of the Theatre.js animation system. The sequence represents the animation timeline and provides an API for controlling its playback. In Threlte 7, you can reactively control animations through the <Sequence> component, which you place inside a <Sheet>.

Currently, you can only have one sequence in each sheet. Future versions of Theatre.js are expected to support multisequence sheets.

Theatre.js Docs

   
SequenceSequence ManualSequence API Reference

Usage

The following example shows how <Sequence> can be used to build a simple playback controller.

Lifecycle

Threlte provides lifecycle props to allow you to configure how the sequence playback is connected to the Svelte component lifecycle. See the autoplay, autoreset and autopause props below.

Note that the underlying Theatre.js sheets are persisted even when unmounting a <Sheet> component. That’s why the sequence doesn’t reset automatically when unmounting a <Sheet>, and why the autoreset options is required.

Audio

The audio options allow you to attach a soundtrack to your animation sequence. Theatre.js achieves this using the Web Audio API. For more details, see audio manual and attach audio API reference

Snippet Prop

When using the sequence in a child component, a snippet prop can come in handy.

<script lang="ts">
  import { T } from '@threlte/core'
  import { Sheet, Sequence, SheetObject } from '@threlte/theatre'
</script>

<Sheet>
  <Sequence>
    {#snippet children({ play })}
      <SheetObject key="Cube">
        {#snippet children({ Transform })}
          <Transform>
            <T.Mesh onclick={play}>
              <T.BoxGeometry />
              <T.MeshStandardMaterial />
            </T.Mesh>
          </Transform>
        {/snippet}
      </SheetObject>
    {/snippet}
  </Sequence>
</Sheet>

Component Signature

Props

name
type
required
default
description

audio
{source: AudioBuffer; audioContext: AudioContext; destinationNode: AudioContext['destination'];}
no
{}
Syncronize an audio track to the sequence; see the audio section below (Theatre.js)

autopause
boolean
no
false
Whether to pause playback when the component is unmounted (Threlte)

autoplay
boolean
no
false
Choose whether to automatically play the animation when the component is mounted (Threlte)

autoreset
"always" | "onMount" | "onDestroy" | undefined
no
undefined
Reset the playhead when the component is mounted, unmounted**, both or neither (Threlte)

delay
number
no
0
When using autoplay, how many milliseconds to wait before starting playback (Threlte)

direction
"normal" | "reverse" | "alternate" | "alternateReverse"
no
normal
Choose the direction of animation playback (Theatre.js)

iterationCount
number
no
1
Control how often the animation is played. Set Infinity to keep looping (Theatre.js)

range
[number, number] | undefined
no
[0, length]
Choose what part of the animation is played (Theatre.js)

rate
number
no
1
Set the speed of playback (Theatre.js)

Bindings

name
type

position
number | undefined

play
(opts?) => Promise<boolean> (see Theatre.js Sequence API docs for options)

pause
() => void

sequence
ISequence

sheet
ISheet