Finite State Machine#

FSM is the brain of the 3DAC system, governing the entire chat lifecycle and ensuring consistent behavior across all system states. It defines a series of states and makes state transitions throughout the system. The FSM uses a condition-based event queue to process external signals such as user interactions, network events, which consists of 2 stages:

  • System Startup: Ensures that all static and runtime assets are available before entering the chat, including environment model, character mesh, local animations(e.g., audio/motion/face for apologize behavior). It also generates an opening remark as the avatar’s first sentence.

  • Interactive Conversation: Triggered when the user enters the chat, the system orchestrates stream lifecycle management, synchronizes animation playback with the runtime pipeline, and applies robust error handling and recovery to deliver a seamless chat experience.

The following figure illustrates the overall workflow of FSM:

FSM

States#

INIT#

WAITING_FOR_FRONTEND_READY#

  • Wait for Babylon scene to be ready.

  • Transit to:

SPAWN_ENVIRONMENT#

  • Load HDR environment and ground model using user settings.

  • Transit to:

SPAWN_CHARACTER#

  • Loads character configuration and assets.

  • Transit to:

WAITING_FOR_ALGORITHM_READY_ON_START#

CHECK_AND_UPDATE_ASSETS#

  • Sync character local motion/audio/face into runtime and generate opening remark.

  • Transit to:

WAITING_FOR_USER_START_GAME#

  • Wait for user to start chat and accumulate opening remark stream.

  • Transit to:

IDLE#

WAITING_FOR_USER_STOP_RECORDING#

WAITING_FOR_LOCAL_ANIMATION_INTERRUPTED#

WAITING_FOR_ACTOR_RESPOND_GENERATION_FINISHED#

ACTOR_ANIMATION_STREAMING#

WAITING_FOR_STREAMED_ANIMATION_INTERRUPTED#

  • Interrupt streamed animation, return to listen state and restart audio recording.

  • Transit to:

WAITING_FOR_ACTOR_ANIMATION_FINISHED#

  • Wait for character animation to complete and check for relationship and emotion updates.

  • Transit to:

WAITING_FOR_ACTOR_LEAVING_FINISHED#

  • Wait for leaving animation to complete.

  • Transit to:

    • EXIT when received ANIMATION_FINISHED signal.

ALGORITHM_GENERATION_FAILED#

WAITING_FOR_ACTOR_APOLOGIZE_FINISHED#

  • Wait for apology animation to complete.

  • Transit to:

    • IDLE when received ANIMATION_FINISHED signal.

EXIT#

  • Terminate state machine and notify user.

  • Transit to:

    • (terminal state)