Live2D
Render 2D animated avatars using Live2D Cubism models with switchable WebGL / WebGPU backends.
The Live2DRenderer renders a Live2D Cubism model in the browser using @live2d-loader/core with pluggable rendering backends. It supports automatic blink, pointer tracking, expression presets, both RMS-based and viseme-based lip-sync, and switchable WebGL / WebGPU rendering.
Usage
import { Live2DRenderer } from "avatarlayer/renderers";
const renderer = new Live2DRenderer({
modelUrl: "/models/avatar/model.model3.json", // Cubism 5
frameMode: "upperBodyFocus",
autoBlink: true,
renderer: "webgpu", // use WebGPU for Cubism 3/4/5 models
});Constructor options
| Option | Type | Default | Description |
|---|---|---|---|
modelUrl | string | required | URL to a Live2D model descriptor (.model.json for Cubism 2, .model3.json for Cubism 3/4/5) |
frameMode | Live2DFrameMode | "upperBodyFocus" | Camera framing mode |
autoBlink | boolean | true | Enable automatic blinking |
autoTrackPointer | boolean | false | Track mouse/touch pointer with eye gaze |
visemeLipSync | boolean | false | Enable viseme-based lip-sync instead of RMS amplitude |
renderer | 'webgl' | 'webgpu' | 'webgl' | Rendering backend for Cubism 3/4/5 models. Falls back to WebGL automatically when WebGPU is unavailable. |
Frame modes
| Mode | Description |
|---|---|
"upperBodyFocus" | Camera frames the upper body and face |
"fullBody" | Full-body view with automatic foot-snap alignment |
WebGL / WebGPU backends
The renderer automatically selects the appropriate backend based on the model type and renderer setting:
| Model format | renderer: 'webgl' | renderer: 'webgpu' |
|---|---|---|
.model.json (Cubism 2) | WebGL | WebGL (always — Cubism 2 SDK requires direct GL access) |
.model3.json (Cubism 3/4/5) | WebGL | WebGPU (with automatic WebGL fallback) |
How it works
When mounted, the renderer:
- Detects the Cubism version from the model URL extension
- Loads the appropriate Cubism adapter (
Cubism2AdapterorCubism5Adapter) - Creates the rendering backend (WebGL or WebGPU) based on the model type and preference
- Loads the model via
@live2d-loader/core - Starts automatic blink and idle motion loops
- Begins a render loop at screen refresh rate
Peer dependencies
The Live2D renderer requires these packages to be installed:
@live2d-loader/core@live2d-loader/renderer-webgl@live2d-loader/adapter-cubism2(for Cubism 2 models)@live2d-loader/adapter-cubism5(for Cubism 3/4/5 models)
When speak(audio) is called:
- The audio blob is played through an
<audio>element - Audio is analyzed in realtime for lip-sync — either via RMS amplitude or viseme weights
- The mouth parameters on the Live2D model are updated each frame
- The promise resolves when the audio ends
Avatar control
The Live2D renderer responds to update() calls for expression and emotion control:
session.updateControl({
avatar: {
emotion: {
label: "happy",
intensity: 0.8,
valence: 0.7,
arousal: 0.5,
},
},
});Supported expressions are mapped automatically: happy, sad, angry, surprised, relaxed, neutral. The renderer matches available model expressions to the requested emotion.
Cubism version parameter mapping
The renderer automatically uses the correct parameter IDs for each Cubism version:
| Feature | Cubism 2 ID | Cubism 5 ID |
|---|---|---|
| Head yaw | PARAM_ANGLE_X | ParamAngleX |
| Head pitch | PARAM_ANGLE_Y | ParamAngleY |
| Head roll | PARAM_ANGLE_Z | ParamAngleZ |
| Left eye | PARAM_EYE_L_OPEN | ParamEyeLOpen |
| Right eye | PARAM_EYE_R_OPEN | ParamEyeROpen |
| Eye ball X | PARAM_EYE_BALL_X | ParamEyeBallX |
| Eye ball Y | PARAM_EYE_BALL_Y | ParamEyeBallY |
| Mouth open | PARAM_MOUTH_OPEN_Y | ParamMouthOpenY |
| Mouth form | PARAM_MOUTH_FORM | ParamMouthForm |