Class AnimatorControllerBuilder<TStates, TParams>

A fluent builder for creating AnimatorController instances from code.

Use AnimatorControllerBuilder.create or AnimatorController.build to create a new builder.

The builder tracks state names and parameter types through the fluent chain, providing autocomplete for state names in .transition() and type-aware .condition() calls (e.g., trigger parameters don't require a mode argument).

const controller = AnimatorControllerBuilder.create("CharacterController")
.floatParameter("Speed", 0)
.triggerParameter("Jump")
.state("Idle", { clip: idleClip, loop: true })
.state("Walk", { clip: walkClip, loop: true })
.state("Jump", { clip: jumpClip })
.transition("Idle", "Walk", { duration: 0.25 })
.condition("Speed", "greater", 0.1)
.transition("Walk", "Idle", { duration: 0.25 })
.condition("Speed", "less", 0.1)
.transition("*", "Jump", { duration: 0.1 })
.condition("Jump")
.transition("Jump", "Idle", { hasExitTime: true, exitTime: 0.9, duration: 0.25 })
.build();
const controller = AnimatorControllerBuilder.create("Door")
.boolParameter("Open", false)
.state("Closed", { loop: true })
.track(door, "position", { from: [0, 0, 0], to: [0, 0, 0], duration: 1 })
.state("Open", { loop: true })
.track(door, "position", { from: [0, 0, 0], to: [2, 0, 0], duration: 1 })
.track(light, "intensity", { from: 0, to: 5, duration: 1 })
.transition("Closed", "Open", { duration: 0.25 })
.condition("Open", "if")
.transition("Open", "Closed", { duration: 0.25 })
.condition("Open", "ifNot")
.build(room);

Type Parameters

  • TStates extends string = never

    Union of state names added via .state(). Used for autocomplete and validation in .transition() and .defaultState().

  • TParams extends Record<string, "trigger" | "bool" | "float" | "int"> = {}

    Record mapping parameter names to their types ("trigger", "bool", "float", "int"). Used for type-aware .condition() overloads.

Constructors

Methods

  • Adds a condition to the most recently added transition. Multiple conditions on the same transition are AND-ed together.

    The required arguments depend on the parameter type:

    • Trigger: .condition("Jump") — mode defaults to "if", no threshold needed
    • Bool: .condition("Open", "if") or .condition("Open", "ifNot")
    • Float/Int: .condition("Speed", "greater", 0.1)

    Parameters

    • parameter: ParamNamesOfType<TParams, "trigger">

      Name of the parameter to evaluate

    • Optionalmode: "if" | "ifNot"

    Returns AnimatorControllerBuilder<TStates, TParams>

  • Adds a condition to the most recently added transition. Multiple conditions on the same transition are AND-ed together.

    The required arguments depend on the parameter type:

    • Trigger: .condition("Jump") — mode defaults to "if", no threshold needed
    • Bool: .condition("Open", "if") or .condition("Open", "ifNot")
    • Float/Int: .condition("Speed", "greater", 0.1)

    Parameters

    • parameter: ParamNamesOfType<TParams, "bool">

      Name of the parameter to evaluate

    • mode: "if" | "ifNot"

    Returns AnimatorControllerBuilder<TStates, TParams>

  • Adds a condition to the most recently added transition. Multiple conditions on the same transition are AND-ed together.

    The required arguments depend on the parameter type:

    • Trigger: .condition("Jump") — mode defaults to "if", no threshold needed
    • Bool: .condition("Open", "if") or .condition("Open", "ifNot")
    • Float/Int: .condition("Speed", "greater", 0.1)

    Parameters

    • parameter: ParamNamesOfType<TParams, "float" | "int">

      Name of the parameter to evaluate

    • mode: "greater" | "less" | "equals" | "notEqual"
    • Optionalthreshold: number

    Returns AnimatorControllerBuilder<TStates, TParams>

  • Adds a state to the controller. The first state added becomes the default state.

    When options.clip is provided, the state uses that clip directly. When omitted, chain .track() calls to define animation tracks inline:

    .state("Open", { loop: true })
    .track(door, "position", { from: [0,0,0], to: [2,0,0], duration: 1 })
    .track(light, "intensity", { from: 0, to: 5, duration: 1 })

    Type Parameters

    • N extends string

    Parameters

    • name: N

      Unique name for the state

    • Optionaloptions: StateOptions

      State configuration including clip, loop, speed. When omitted, use .track() to add animation data.

    Returns AnimatorControllerBuilder<TStates | N, TParams>

  • Adds an animation track for an Object3D's position or scale to the current state

    Parameters

    • target: Object3D
    • property: "position" | "scale"
    • keyframes: KF<Vec3Value>
    • Optionaloptions: TrackOptions

    Returns this

  • Adds an animation track for an Object3D's quaternion to the current state

    Parameters

    • target: Object3D
    • property: "quaternion"
    • keyframes: KF<QuatValue>
    • Optionaloptions: TrackOptions

    Returns this

  • Adds an animation track for an Object3D's rotation (Euler, converted to quaternion) to the current state

    Parameters

    • target: Object3D
    • property: "rotation"
    • keyframes: KF<EulerValue>
    • Optionaloptions: TrackOptions

    Returns this

  • Adds an animation track for an Object3D's visibility to the current state

    Parameters

    • target: Object3D
    • property: "visible"
    • keyframes: KF<boolean>
    • Optionaloptions: TrackOptions

    Returns this

  • Adds an animation track for a material's numeric property to the current state

    Parameters

    • target: Material
    • property:
          | "opacity"
          | "roughness"
          | "metalness"
          | "alphaTest"
          | "emissiveIntensity"
          | "envMapIntensity"
          | "bumpScale"
          | "displacementScale"
          | "displacementBias"
    • keyframes: KF<number>
    • Optionaloptions: TrackOptions

    Returns this

  • Adds an animation track for a material's color property to the current state

    Parameters

    • target: Material
    • property: "color" | "emissive"
    • keyframes: KF<ColorValue>
    • Optionaloptions: TrackOptions

    Returns this

  • Adds an animation track for a light's numeric property to the current state

    Parameters

    • target: Light
    • property: "intensity" | "distance" | "angle" | "penumbra" | "decay"
    • keyframes: KF<number>
    • Optionaloptions: TrackOptions

    Returns this

  • Adds an animation track for a light's color to the current state

    Parameters

    • target: Light
    • property: "color"
    • keyframes: KF<ColorValue>
    • Optionaloptions: TrackOptions

    Returns this

  • Adds an animation track for a camera's numeric property to the current state

    Parameters

    • target: PerspectiveCamera
    • property: "zoom" | "fov" | "near" | "far"
    • keyframes: KF<number>
    • Optionaloptions: TrackOptions

    Returns this