pixi-live2d-display-advanced 1.0.1 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,179 +1,233 @@
1
1
  # pixi-live2d-display-advanced
2
2
 
3
3
  ![NPM Version](https://img.shields.io/npm/v/pixi-live2d-display-advanced?style=flat-square&label=version)
4
- ![Cubism version](https://img.shields.io/badge/Cubism-2/3/4-ff69b4?style=flat-square)
4
+ ![Cubism version](https://img.shields.io/badge/Cubism-2/3/4/5-ff69b4?style=flat-square)
5
5
 
6
- A Live2D plugin for [PixiJS](https://github.com/pixijs/pixi.js) v7.
6
+ **English (Current)** | [**简体中文**](README-ZH.md)
7
7
 
8
- This project provides a **unified and simplified API** for controlling Live2D models on the web.
9
- Compared to the official Live2D SDKs, this library is easier to use, more reliable, and more maintainable.
8
+ A Live2D rendering and control plugin designed for **[PixiJS v8](https://pixijs.com/)**.
9
+
10
+ This project aims to provide a **unified, concise, and highly maintainable** API for loading, rendering, and interacting with Live2D models on the Web.
11
+ Compared to the official Live2D SDK, this library significantly reduces usage complexity while preserving full functionality, with additional optimizations for stability and long-term maintainability.
12
+
13
+ This project is based on the
14
+ [pixi-live2d-display-mulmotion](https://github.com/Sekai-World/pixi-live2d-display) branch.
15
+ Starting from **v2.0.0**, it is **fully compatible with PixiJS v8 and Live2D Cubism 5.4 SDK**, and further provides:
16
+
17
+ - Additional practical APIs
18
+ - Stronger TypeScript type safety
19
+ - Optimized internal architecture for extensibility and maintainability
20
+
21
+ > [!IMPORTANT]
22
+ > The project is currently in the testing phase. If you want to try it out, please install it using the following command:
23
+ >
24
+ > If you are using PixiJS v7, please install the v1.x version.
25
+ >
26
+ > ```shell
27
+ > npm install pixi-live2d-display-advanced@prerelease
28
+ > ```
10
29
 
11
- Compared to [pixi-live2d-display-mulmotion](https://www.npmjs.com/package/pixi-live2d-display-mulmotion), this project
12
- additionally supports **playing the last frame of motions**, which is especially useful in
13
- **Project SEKAI-like projects** where animations need to be reapplied frequently, and uses `@pixi/sound` as the audio
14
- backend, fixing many issues such as model update and display anomalies.
15
30
 
16
31
  ---
17
32
 
18
33
  ## Features
19
34
 
20
- - Supports all versions of Live2D models (Cubism 2.1, 3, 4)
35
+ - Supports **all versions** of Live2D models (Cubism 2 / 3 / 4 / 5)
21
36
  - Compatible with `PIXI.RenderTexture` and `PIXI.Filter`
22
- - Familiar Pixi.js style transform API: `position`, `scale`, `rotation`, `skew`, `anchor`
23
- - Automatic interaction: mouse tracking, hit detection on click
24
- - Enhanced motion reservation logic compared to the official framework
25
- - Load models from uploaded files or zip archives (experimental)
26
- - Complete TypeScript type definitions
27
- - Real-time lip sync
28
- - Play multiple motions simultaneously
29
- - Play the last frame of motions
37
+ - Provides a complete **PixiJS-style transform API**
38
+ - `position`
39
+ - `scale`
40
+ - `rotation`
41
+ - `skew`
42
+ - `anchor`
43
+
44
+ - Built-in interaction support
45
+ - Mouse tracking
46
+ - Hit area detection
47
+
48
+ - Improved **motion scheduling and reservation logic** compared to the official SDK
49
+ - Complete and strict **TypeScript type definitions**
50
+ - Real-time lip sync support
51
+ - **Parallel motion playback**
52
+ - Support for **freezing at the last frame of motions**
30
53
 
31
54
  ---
32
55
 
33
56
  ## Requirements
34
57
 
35
- - **PixiJS**: 7.x
36
- - **Cubism Core**: 2.1 or 4
37
- - **Browser**: WebGL, ES6
58
+ - **PixiJS**: `8.x`
59
+ - **Cubism runtime**: `2.1` or `5`
60
+ - **Browser**: Must support `WebGL` and `ES6`
38
61
 
39
62
  ---
40
63
 
41
- ## Examples
64
+ ## Installation
42
65
 
43
- - [Basic Example](#basic-usage)
44
- - [Interaction Example](https://codepen.io/guansss/pen/KKgXBOP/left?editors=0010)
45
- - [Render Texture & Filter Example](https://codepen.io/guansss/pen/qBaMNQV/left?editors=1010)
46
- - [Live2D Viewer Online](https://guansss.github.io/live2d-viewer-web/)
47
- - [Parallel Motions Example](#parallel-motions)
48
- - [Play Motion Last Frame](#play-motion-last-frame)
66
+ ### Using npm / pnpm
49
67
 
50
- Documentation:
68
+ ```bash
69
+ pnpm add pixi-live2d-display-advanced
70
+ # or
71
+ npm install pixi-live2d-display-advanced
72
+ ```
51
73
 
52
- - [User Guide](https://guansss.github.io/pixi-live2d-display)
53
- - [API Reference](https://guansss.github.io/pixi-live2d-display/api/index.html)
74
+ ```ts
75
+ import { Live2DModel } from 'pixi-live2d-display-advanced'
54
76
 
55
- ---
77
+ // Cubism Legacy only (Cubism 2.1)
78
+ import { Live2DModel } from 'pixi-live2d-display-advanced/cubism-legacy'
56
79
 
57
- ## Cubism Runtime
80
+ // Cubism Modern only (Cubism 3 / 4 / 5)
81
+ import { Live2DModel } from 'pixi-live2d-display-advanced/cubism'
82
+ ```
58
83
 
59
- Cubism is the official name of the Live2D SDK.
60
- Currently, there are three versions: **Cubism 2.1**, **Cubism 3**, and **Cubism 4** (Cubism 4 is backward-compatible
61
- with Cubism 3).
84
+ ---
62
85
 
63
- This plugin supports **Cubism 2.1 and Cubism 4**, covering all versions of Live2D models.
86
+ ## Cubism Runtime Overview
64
87
 
65
- ### Load Cubism Core
88
+ This project supports **all versions of Live2D models**, which can be categorized by Cubism architecture:
66
89
 
67
- - **Cubism 4**: `live2dcubismcore.min.js`
90
+ - **Cubism Legacy**: Cubism 2.1
91
+ - **Cubism Modern**: Cubism 3 / 4 / 5
68
92
 
69
- - Download from the [Cubism 4 SDK](https://www.live2d.com/download/cubism-sdk/download-web/)
70
- - Or use this [link](https://cubism.live2d.com/sdk-web/cubismcore/live2dcubismcore.min.js) _(not guaranteed to be
71
- always available, do not use in production)_
93
+ Choose the appropriate runtime entry based on the model you are using.
72
94
 
73
- - **Cubism 2.1**: `live2d.min.js`
95
+ ### Using Cubism Legacy and Cubism Modern Together
74
96
 
75
- - The official site no longer provides it since [September 4, 2019](https://help.live2d.com/en/other/other_20/)
76
- - Available on [GitHub](https://github.com/dylanNew/live2d/tree/master/webgl/Live2D/lib)
77
- - Or via [jsDelivr CDN](https://cdn.jsdelivr.net/gh/dylanNew/live2d/webgl/Live2D/lib/live2d.min.js)
97
+ #### Bundle entry
78
98
 
79
- ### Bundled Files
99
+ ```text
100
+ index.js
101
+ ```
80
102
 
81
- This plugin provides **separate builds** for different Cubism versions:
103
+ > Use this unified entry when your project needs to load both Cubism 2 and Cubism 3+ models.
82
104
 
83
- - `cubism2.js` + `live2d.min.js` → supports Cubism 2.1 models
84
- - `cubism4.js` + `live2dcubismcore.min.js` → supports Cubism 3 & 4 models
85
- - `index.js` + both runtimes → supports all versions
105
+ ---
86
106
 
87
- > [!WARNING]
88
- > Do **not** use `cubism2.js` and `cubism4.js` together. Use `index.js` instead if you need both.
107
+ ### Cubism Legacy Only (Cubism 2.1)
89
108
 
90
- ---
109
+ #### Prerequisites
91
110
 
92
- ## Installation
111
+ You must manually include `live2d.min.js`:
93
112
 
94
- Via npm:
113
+ - Official distribution was discontinued on
114
+ [September 4, 2019](https://help.live2d.com/en/other/other_20/)
115
+ - Available from:
116
+ - GitHub:
117
+ [https://github.com/dylanNew/live2d/tree/master/webgl/Live2D/lib](https://github.com/dylanNew/live2d/tree/master/webgl/Live2D/lib)
118
+ - jsDelivr CDN:
119
+ [https://cdn.jsdelivr.net/gh/dylanNew/live2d/webgl/Live2D/lib/live2d.min.js](https://cdn.jsdelivr.net/gh/dylanNew/live2d/webgl/Live2D/lib/live2d.min.js)
95
120
 
96
- ```sh
97
- npm install pixi-live2d-display-advanced
121
+ #### Bundle entry
122
+
123
+ ```text
124
+ cubism-legacy.js
98
125
  ```
99
126
 
100
- Usage:
127
+ ---
101
128
 
102
- ```ts
103
- import { Live2DModel } from 'pixi-live2d-display-advanced'
129
+ ### Cubism Modern Only (Cubism 3 / 4 / 5)
130
+
131
+ #### Prerequisites
132
+
133
+ You must include `live2dcubismcore.min.js`:
104
134
 
105
- // Only Cubism 2.1
106
- import { Live2DModel } from 'pixi-live2d-display-advanced/cubism2'
135
+ - Downloadable from the official **Cubism 5 SDK**
136
+ [https://www.live2d.com/download/cubism-sdk/download-web/](https://www.live2d.com/download/cubism-sdk/download-web/)
107
137
 
108
- // Only Cubism 4
109
- import { Live2DModel } from 'pixi-live2d-display-advanced/cubism4'
138
+ #### Bundle entry
139
+
140
+ ```text
141
+ cubism.js
110
142
  ```
111
143
 
112
144
  ---
113
145
 
114
- ## Basic Usage
115
-
116
- See example project: [pixi-live2d-display-lipsync](https://github.com/RaSan147/pixi-live2d-display)
146
+ ## Quick Start
117
147
 
118
- When using the Cubism 4 module, you need to call configureCubism4() once before loading models.
119
- This is required to fix potential issues with model updates.
148
+ The following example is based on **PixiJS v8** and supports both Cubism Legacy and Cubism Modern.
120
149
 
121
150
  ```ts
122
- import { Live2DModel, configureCubism4 } from 'pixi-live2d-display-advanced/cubism4'
151
+ import { Application } from 'pixi.js'
152
+ import { configureCubism, Live2DModel } from 'pixi-live2d-display-advanced'
153
+
154
+ const app = new Application({
155
+ resizeTo: window,
156
+ preference: 'webgl'
157
+ })
158
+
159
+ document.body.appendChild(app.view as HTMLCanvasElement)
123
160
 
124
- // Configure Cubism runtime (only needs to be called once)
125
- configureCubism4({
126
- memorySizeMB: 128
161
+ // Configure Cubism Modern work memory (optional, default is 16MB)
162
+ // Increase this value when loading multiple or high-complexity models
163
+ configureCubism({
164
+ memorySizeMB: 32
127
165
  })
128
166
 
129
- // Load a model
130
- const model = await Live2DModel.from('mymodel.model3.json')
167
+ const model = await Live2DModel.from('model/model3.json')
168
+ model.anchor.set(0.5)
169
+ model.position.set(app.screen.width / 2, app.screen.height / 2)
170
+
131
171
  app.stage.addChild(model)
132
172
  ```
133
173
 
134
174
  ---
135
175
 
136
- ## Parallel Motions
176
+ ## Common API Examples
177
+
178
+ ### Play a Motion
137
179
 
138
180
  ```ts
139
- model.parallelMotion([
140
- { group: motion_group1, index: motion_index1, priority: MotionPriority.NORMAL },
141
- { group: motion_group2, index: motion_index2, priority: MotionPriority.NORMAL }
142
- ])
181
+ model.motion('group', index)
143
182
  ```
144
183
 
145
- For syncing motions with expressions/sounds, use `model.motion` or `model.speak` for one motion, and
146
- `model.parallelMotion` for others.
147
- Each item has independent priority control, following the same logic as `model.motion`.
184
+ ### Parallel Motions
148
185
 
149
- ---
186
+ ```ts
187
+ model.parallelMotion([
188
+ { group: group1, index: index1 },
189
+ { group: group2, index: index2 }
190
+ ])
191
+ ```
150
192
 
151
- ## Play Motion Last Frame
193
+ ### Play and Freeze at the Last Frame
152
194
 
153
- Single motion:
195
+ **Single motion:**
154
196
 
155
197
  ```ts
156
- await model.motionLastFrame('w-cute12-tilthead', 0)
198
+ model.motionLastFrame('group', index)
157
199
  ```
158
200
 
159
- Multiple motions:
201
+ **Multiple motions:**
160
202
 
161
203
  ```ts
162
204
  await model.parallelLastFrame([
163
- { group: 'w-cute12-tilthead', index: 0 },
164
- { group: 'face_worry_01', index: 0 }
205
+ { group: group1, index: index1 },
206
+ { group: group2, index: index2 }
165
207
  ])
166
208
  ```
167
209
 
168
- Or with manual parallel motion managers:
210
+ ### Lip Sync
169
211
 
170
212
  ```ts
171
- model.internalModel.extendParallelMotionManager(2)
172
- const manager1 = model.internalModel.parallelMotionManager[0]!
173
- const manager2 = model.internalModel.parallelMotionManager[1]!
213
+ model.speak('audio_file_url')
214
+ ```
174
215
 
175
- manager1.playMotionLastFrame('w-cute12-tilthead', 0)
176
- manager2.playMotionLastFrame('face_worry_01', 0)
216
+ ### Expressions
217
+
218
+ ```ts
219
+ model.expression('id')
177
220
  ```
178
221
 
179
- Both approaches are equivalent — the first is syntactic sugar for the second.
222
+ For more advanced usage, see
223
+ [pixi-live2d-display-lipsync](https://github.com/RaSan147/pixi-live2d-display)
224
+
225
+ ---
226
+
227
+ ## FAQ
228
+
229
+ ### Q: Why do models stop updating when multiple models are loaded?
230
+
231
+ When using the **Cubism Modern** runtime, this issue is usually caused by insufficient work memory configured via `configureCubism`.
232
+
233
+ Try increasing `memorySizeMB` during initialization (minimum: 16MB).