| name | live2d |
|---|---|
| description | Comprehensive Live2D knowledge for Anima project integration using pixi-live2d-display library. Use when working with Live2D models, expressions, lip sync, or debugging Live2D-related issues. Covers model loading, motion/expression control, parameter manipulation, lip sync implementation, and troubleshooting known issues like expression clearing and Idle Motion looping. |
This skill provides comprehensive knowledge about the pixi-live2d-display library and Live2D integration in the Anima project.
npm install pixi-live2d-displayimport { Live2DModel } from 'pixi-live2d-display';
import * as PIXI from 'pixi.js';
// Expose PIXI to window
window.PIXI = PIXI;
// Load model
const model = await Live2DModel.from('shizuku.model.json');
app.stage.addChild(model);// Start a motion
await model.motion('Idle'); // Random Idle motion
await model.motion('TapBody', 0); // Specific motion
// Expression
await model.expression(3); // Expression by index
await model.expression(); // Random expressionmodel.x = 100;
model.y = 100;
model.scale.set(2, 2);
model.rotation = Math.PI;
model.anchor.set(0.5, 0.5);- Frontend Service:
frontend/features/live2d/services/Live2DService.ts - Config:
config/features/live2d.yaml - Hook:
frontend/features/live2d/hooks/useLive2D.ts - Component:
frontend/components/vtuber/live2d-viewer.tsx
-
Live2DService (
frontend/features/live2d/services/Live2DService.ts)- Wraps Live2DModel with additional features
- Manages position, scale, expressions
- Handles lip sync via setMouthOpen()
-
Expression System
- ExpressionTimeline: Time-based expression playback
- Emotion analyzers: Extract emotions from text
- Timeline strategies: Calculate emotion segments
-
Lip Sync
- AudioAnalyzer: Computes volume envelope at 50Hz
- LipSyncEngine: Updates mouth parameters at ~30fps
- Parameters: ParamMouthOpenY (index 19), ParamMouthForm (index 18)
-
Expression cannot be "cleared"
- Live2D API doesn't provide a way to clear expressions
- Setting expression(-1) doesn't exist
- Expressions persist until overridden
-
Idle Motion auto-plays
- MotionManager automatically starts Idle motions when no other motion is playing
- This causes the "looping expressions" effect
- Cannot be disabled without stopping automator
-
Lip sync parameters update but may not be visible
- ParamMouthOpenY updates correctly (values to 1.000)
- Visual effect may not be obvious due to model design
- May need to control additional parameters
Methods:
from(source, options)- Load model from settings filemotion(group, index?, priority?)- Start motionexpression(id?)- Set expressionfocus(x, y, instant?)- Set focus positiontap(x, y)- Tap on model (hit testing)hitTest(x, y)- Get hit areasupdate(dt)- Update model (called by automator)destroy()- Clean up resources
Properties:
internalModel- Core Live2D modeltextures- PIXI texturesautomator- Auto-update manageranchor- Anchor point (0,0 = top-left, 1,1 = bottom-right)
Options:
autoUpdate- Auto-update model (default: true)autoHitTest- Auto hit-test on tap (default: true)autoFocus- Auto focus on pointer move (default: true)ticker- PIXI ticker for updates
Key Methods:
autoUpdate- Get/set auto update stateautoHitTest- Get/set hit testingautoFocus- Get/set focus tracking
Key Behavior:
- Auto-starts Idle motions when no motion is playing
shouldRequestIdleMotion()- Checks if idle motion neededstartRandomMotion(group, priority)- Start random motion from groupstopAllMotions()- Stop all playing motions
Priority Levels:
MotionPriority.IDLE- Lowest priority, can be overriddenMotionPriority.NORMAL- Normal priorityMotionPriority.FORCE- Highest priority, cannot be overridden
Methods:
setExpression(id)- Set expression by index or namesetRandomExpression()- Set random expressionresetExpression()- Reset to default (may be called by motion)restoreExpression()- Restore expression after motion
Cause: Idle Motion is auto-playing (designed behavior) Solution: This is normal. To reduce changes:
- Use models with fewer Idle motions
- Or accept the behavior as "lively" character
Cause: Live2D API doesn't provide clearExpression method Workaround: Set a neutral expression or override with another expression
Possible causes:
- Model design (mouth animation not obvious)
- Need to control more parameters
- Parameter values too small
Debug steps:
- Check parameter values in logs: Look for "嘴部参数更新"
- Verify ParamMouthOpenY index is correct
- Try controlling ParamMouthForm as well
- Check if Expression is overriding parameters
Solutions:
- Use
model.anchor.set(0.5, 0.5)to center anchor - Calculate position as
containerWidth/2 + xOffset - See
Live2DService.autoScaleModel()for implementation
# config/features/live2d.yaml
enabled: true
model:
path: "/live2d/hiyori/Hiyori.model3.json"
scale: 0.5
position:
x: 0
y: 0
emotion_map:
happy: 3
sad: 1
angry: 2
surprised: 4
neutral: 0
thinking: 5
lip_sync:
enabled: true
sensitivity: 2.0
smoothing: 0.15
min_threshold: 0.01
max_value: 1.0
use_mouth_form: true- Add to
emotion_mapin config/features/live2d.yaml - Add to
valid_emotionslist - Rebuild backend
- Check console for "嘴部参数更新" logs
- Look for high values (0.5+)
- If values are high but no visual effect, check model design
// In browser console
const service = window.__live2dService;
const model = service.model;
// Check model state
console.log("Current expression:", service.currentExpression);
console.log("Model position:", { x: model.x, y: model.y });
console.log("Model scale:", model.scale.x);
// Check internal model
console.log("MotionManager:", model.internalModel.motionManager);
console.log("ExpressionManager:", model.internalModel.motionManager.expressionManager);
// Test expression
await model.expression(3); // Happyconst model = await Live2DModel.from(modelPath);
app.stage.addChild(model);
model.anchor.set(0.5, 0.5);const centerX = canvasWidth / 2;
const centerY = canvasHeight / 2;
const yOffset = canvasHeight * (yOffsetPercent / 100);
model.x = centerX + xOffset;
model.y = centerY + yOffset;// By index
await model.expression(3);
// Random
await model.expression();// Update mouth parameter
const coreModel = model.internalModel.coreModel;
const mouthIndex = coreModel.getParameterIndex('ParamMouthOpenY');
coreModel.setParameterValueByIndex(mouthIndex, value);// Stop all motions
model.internalModel.motionManager.stopAllMotions();
// Destroy model
model.destroy({ texture: true });For complete API documentation, see the reference files:
- SUMMARY.md - Complete guide (16KB)
- QUICK_REFERENCE.md - Quick reference card (3.6KB)
- Live2DModel.ts - Main API
- MotionManager.ts - Motion system
- ExpressionManager.ts - Expression system
- Automator.ts - Auto-update system
- InternalModel.ts - Internal model structure
- Always expose
window.PIXI = PIXIbefore using Live2DModel - Expressions and Motions are separate systems
- Idle motions auto-play by design
- Cannot "clear" expressions, only override with new ones
- Automator controls auto-update behavior
- Hit testing requires event mode to be 'static'