Getting Started

This guide will help you set up and run the VTuber Game Live2D framework on your local machine.

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have the following installed:

Browser Requirements

The application requires a modern browser with:

๐Ÿš€ Quick Setup

1. Clone the Repository

git clone https://github.com/K-Jadeja/vtubergame.git
cd vtubergame

2. Install Dependencies

npm install

The project uses these key dependencies:

3. Start Development Server

npm run dev

This will start the Vite development server, typically at http://localhost:5173.

4. Build for Production

npm run build

The built files will be in the dist/ directory.

๐ŸŽฎ First Run

Once the development server is running:

  1. Open your browser to the development URL
  2. Load a model by clicking either:
    • โ€œLoad Shizuku (Cubism 2.1)โ€ - Classic Live2D model
    • โ€œLoad Haru (Cubism 4)โ€ - Modern Live2D model
  3. Test interactions:
    • Click motion buttons to trigger animations
    • Use expression controls to change facial expressions
    • Try the Text-to-Speech feature with lipsync

๐Ÿ“ Project Structure

vtubergame/
โ”œโ”€โ”€ docs/                     # Documentation (GitHub Pages)
โ”œโ”€โ”€ public/                   # Static assets
โ”‚   โ”œโ”€โ”€ core/                # Live2D runtime files
โ”‚   โ”‚   โ”œโ”€โ”€ live2d.min.js    # Cubism 2.1 runtime
โ”‚   โ”‚   โ””โ”€โ”€ live2dcubismcore.js # Cubism 4 runtime
โ”‚   โ””โ”€โ”€ models/              # Live2D model files
โ”‚       โ”œโ”€โ”€ shizuku/         # Cubism 2.1 sample model
โ”‚       โ””โ”€โ”€ haru/            # Cubism 4 sample model
โ”œโ”€โ”€ src/                     # Source code
โ”‚   โ”œโ”€โ”€ main.js              # Application entry point
โ”‚   โ”œโ”€โ”€ style.css            # Styling
โ”‚   โ””โ”€โ”€ counter.js           # Utility functions
โ”œโ”€โ”€ index.html               # Main HTML file
โ”œโ”€โ”€ package.json             # Dependencies and scripts
โ””โ”€โ”€ vite.config.js           # Build configuration

๐ŸŽฏ Basic Usage

Loading Models

import { Live2DModel } from 'pixi-live2d-display-lipsyncpatch';

// Load a model
const model = await Live2DModel.from('/models/shizuku/shizuku.model.json');
app.stage.addChild(model);

// Position and scale
model.scale.set(0.3);
model.x = app.screen.width / 2;
model.y = app.screen.height * 0.8;
model.anchor.set(0.5, 1.0);

Triggering Animations

// Play a motion
model.motion('idle'); // Motion group name

// Set expression
model.expression(2); // Expression index

// Speak with lipsync
model.speak('/path/to/audio.mp3', {
  volume: 1.0,
  expression: 4,
  resetExpression: true
});

๐Ÿ”ง Configuration

Adding Your Own Models

  1. Place model files in public/models/your-model/
  2. Update model loading in src/main.js:
document.getElementById('load-custom').onclick = () =>
  loadModel('/models/your-model/model.json', 'CustomModel');

Customizing TTS Voices

// In speakText function
const voices = speechSynthesis.getVoices();
const preferredVoice = voices.find(voice => 
  voice.name.includes('your-preferred-voice')
);
if (preferredVoice) {
  utterance.voice = preferredVoice;
}

๐ŸŽจ UI Customization

The interface styling is in src/style.css. Key customizable elements:

๐Ÿ› Common Issues

Models Not Loading

Issue: Model appears in console but not on screen

Solution: Check model positioning and scale:

// Debug model visibility
if (window.model) {
  window.model.visible = true;
  window.model.alpha = 1;
  window.app.render();
}

Audio/Lipsync Problems

Issue: โ€œCORS access restrictionsโ€ error

Solution: Use crossOrigin parameter:

model.speak(audioUrl, {
  crossOrigin: 'anonymous'
});

TTS Not Working

Issue: No speech synthesis

Solution: Check browser support:

if ('speechSynthesis' in window) {
  console.log('TTS supported');
} else {
  console.log('TTS not supported');
}

โšก Performance Tips

  1. Optimize model scale: Use model.scale.set(0.2-0.4) for better performance
  2. Limit FPS: Set app.ticker.maxFPS = 30 if needed
  3. Cleanup models: Always destroy previous models when loading new ones
  4. Use appropriate model sizes: Smaller texture sizes load faster

๐Ÿ”— Next Steps


Need help? Check our Troubleshooting guide or open an issue on GitHub.