Class MotionManager<Motion, MotionSpec>Abstract

Handles the motion playback.

Emits

MotionManagerEvents

Type Parameters

  • Motion = any

  • MotionSpec = any

Hierarchy

Constructors

Properties

currentAudio?: HTMLAudioElement

Audio element of the current motion if a sound file is defined with it.

definitions: Partial<Record<string, MotionSpec[]>>

Motion definitions copied from ModelSettings.

destroyed: boolean = false

Flags the instances has been destroyed.

expressionManager?: ExpressionManager<any, any>

Can be undefined if the settings defines no expression.

groups: { idle: string }

Motion groups with particular internal usages. Currently there's only the idle field, which specifies the actual name of the idle motion group, so the idle motions can be correctly found from the settings JSON of various Cubism versions.

Type declaration

  • idle: string
motionDataType: "arraybuffer" | "json"

Indicates the content type of the motion files, varies in different Cubism versions. This will be used as xhr.responseType.

motionGroups: Partial<Record<string, (undefined | null | Motion)[]>> = {}

The Motions. The structure is the same as definitions, initially each group contains an empty array, which means all motions will be undefined. When a Motion has been loaded, it'll fill the place in which it should be; when it fails to load, the place will be filled with null.

playing: boolean = false

Flags there's a motion playing.

settings: ModelSettings

The ModelSettings reference.

state: MotionState = ...

Maintains the state of this MotionManager.

tag: string

Tag for logging.

prefixed: string | boolean

Methods

  • Starts the Motion.

    Parameters

    • motion: Motion
    • Optional onFinish: ((motion: Motion) => void)
        • (motion: Motion): void
        • Parameters

          • motion: Motion

          Returns void

    Returns number

  • Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns MotionManager<Motion, MotionSpec>

  • Creates a Motion from the data.

    Returns

    The created Motion.

    Parameters

    • data: object | ArrayBuffer

      Content of the motion file. The format must be consistent with motionDataType.

    • group: string

      The motion group.

    • definition: MotionSpec

      The motion definition.

    Returns Motion

  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

  • Return an array listing the events for which the emitter has registered listeners.

    Returns (string | symbol)[]

  • Retrieves the motion's file path by its definition.

    Returns

    The file path extracted from given definition. Not resolved.

    Parameters

    • definition: MotionSpec

    Returns string

  • Retrieves the motion's name by its definition.

    Returns

    The motion's name.

    Parameters

    • definition: MotionSpec

    Returns string

  • Retrieves the motion's sound file by its definition.

    Returns

    The motion's sound file, can be undefined.

    Parameters

    • definition: MotionSpec

    Returns undefined | string

  • Return the number of listeners listening to a given event.

    Parameters

    • event: string | symbol

    Returns number

  • Return the listeners registered for a given event.

    Parameters

    • event: string | symbol

    Returns ListenerFn[]

  • Loads a Motion in a motion group. Errors in this method will not be thrown, but be emitted with a "motionLoadError" event.

    Returns

    Promise that resolves with the Motion, or with undefined if it can't be loaded.

    Emits

    motionLoaded

    Emits

    motionLoadError

    Parameters

    • group: string

      The motion group.

    • index: number

      Index in the motion group.

    Returns Promise<undefined | Motion>

  • Parameters

    • event: string | symbol
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns MotionManager<Motion, MotionSpec>

  • Add a listener for a given event.

    Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns MotionManager<Motion, MotionSpec>

  • Add a one-time listener for a given event.

    Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns MotionManager<Motion, MotionSpec>

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: string | symbol

    Returns MotionManager<Motion, MotionSpec>

  • Remove the listeners of a given event.

    Parameters

    • event: string | symbol
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns MotionManager<Motion, MotionSpec>

  • Starts a motion as given priority.

    Returns

    Promise that resolves with true if the motion is successfully started, with false otherwise.

    Parameters

    • group: string

      The motion group.

    • index: number

      Index in the motion group.

    • priority: MotionPriority = MotionPriority.NORMAL

      The priority to be applied.

    Returns Promise<boolean>

  • Starts a random Motion as given priority.

    Returns

    Promise that resolves with true if the motion is successfully started, with false otherwise.

    Parameters

    • group: string

      The motion group.

    • Optional priority: MotionPriority

      The priority to be applied.

    Returns Promise<boolean>

  • Updates parameters of the core model.

    Returns

    True if the parameters have been actually updated.

    Parameters

    • model: object

      The core model.

    • now: number

      Current time in milliseconds.

    Returns boolean

  • Updates parameters of the core model.

    Returns

    True if the parameters have been actually updated.

    Parameters

    • model: object

      The core model.

    • now: number

      Current time in milliseconds.

    Returns boolean

Generated using TypeDoc