@doki-land/live2d 0.0.7 → 0.0.9
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/dist/l2d.umd.js +47 -47
- package/dist/l2d.umd.js.map +1 -1
- package/package.json +10 -6
- package/readme.md +50 -9
- package/src/helper/index.ts +25 -0
- package/src/index.ts +3 -7
- package/src/types/Resolve.ts +16 -0
- package/src/types/index.ts +2 -1
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doki-land/live2d",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"live2d",
|
|
6
6
|
"pixi",
|
|
7
7
|
"typescript"
|
|
8
8
|
],
|
|
9
|
-
"description": "Live2D TypeScript runtime based on pixi
|
|
9
|
+
"description": "Live2D TypeScript runtime based on pixi",
|
|
10
10
|
"author": "Aster <192608617@qq.com>",
|
|
11
11
|
"license": "LGPL-3.0-or-later",
|
|
12
12
|
"type": "module",
|
|
@@ -16,13 +16,17 @@
|
|
|
16
16
|
"require": "./dist/l2d.umd.js",
|
|
17
17
|
"import": "./src/index.ts"
|
|
18
18
|
},
|
|
19
|
-
"./fs": {
|
|
20
|
-
"types": "./src/fs/index.ts",
|
|
21
|
-
"import": "./src/fs/index.ts"
|
|
22
|
-
},
|
|
23
19
|
"./types": {
|
|
24
20
|
"types": "./src/types/index.ts",
|
|
25
21
|
"import": "./src/types/index.ts"
|
|
22
|
+
},
|
|
23
|
+
"./helper": {
|
|
24
|
+
"types": "./src/helper/index.ts",
|
|
25
|
+
"import": "./src/helper/index.ts"
|
|
26
|
+
},
|
|
27
|
+
"./fs": {
|
|
28
|
+
"types": "./src/fs/index.ts",
|
|
29
|
+
"import": "./src/fs/index.ts"
|
|
26
30
|
}
|
|
27
31
|
},
|
|
28
32
|
"files": [
|
package/readme.md
CHANGED
|
@@ -1,19 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
# Live2D Core Adapter (Unofficial)
|
|
2
2
|
|
|
3
|
+
## Usage
|
|
3
4
|
|
|
5
|
+
This is the core library for rendering Live2D models in web applications.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
It provides essential functionalities to load and display Live2D models with interactive capabilities.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### In HTML via Module
|
|
6
12
|
|
|
7
13
|
```html
|
|
14
|
+
<script src="https://cdn.jsdelivr.net/npm/@doki-land/live2d@latest/dist/l2d.umd.js">
|
|
8
15
|
<script type="module">
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
initializeLive2D();
|
|
12
|
-
await createLive2dModel({
|
|
16
|
+
l2d.initializeLive2D();
|
|
17
|
+
l2d.createLive2D({
|
|
13
18
|
element_id: 'live2d-canvas',
|
|
14
19
|
models: [
|
|
15
|
-
|
|
20
|
+
{}
|
|
16
21
|
]
|
|
17
|
-
|
|
22
|
+
})
|
|
18
23
|
</script>
|
|
19
|
-
```
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### In Node via npm
|
|
28
|
+
|
|
29
|
+
- installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @doki-land/live2d-core
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- usage
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### In Other Frameworks
|
|
46
|
+
|
|
47
|
+
- [VitePress]()
|
|
48
|
+
- [VuePress]()
|
|
49
|
+
- [Hexo]()
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- Render Live2D Cubism™ v1, v2 (`*.model.json`).
|
|
54
|
+
- Render Live2D Cubism™ v3, v4, v5 (`*.model3.json`).
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### API Documentation
|
|
59
|
+
- `initializeLive2D()`: Initializes the Live2D environment
|
|
60
|
+
- `createLive2dModel(options)`: Creates and renders a Live2D model with specified options
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {findAllModels, mergeModels} from "@/fs/index.js";
|
|
2
|
+
import {ResolveCdn, ResolveElementId, ResolveModels} from "@/types/index.js";
|
|
3
|
+
|
|
4
|
+
export function generateModelList(options: ResolveModels) {
|
|
5
|
+
const models = mergeModels(options.domain || 'https://localhost:8080', findAllModels(options.models_folder || 'public/live2d'), options.models || []);
|
|
6
|
+
if (models.length == 0) {
|
|
7
|
+
throw new Error('At least one live2d model is required');
|
|
8
|
+
}
|
|
9
|
+
delete options.domain;
|
|
10
|
+
delete options.models;
|
|
11
|
+
delete options.models_folder;
|
|
12
|
+
return models;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function generateElementId(options: ResolveElementId) {
|
|
16
|
+
const element_id = options.element_id || 'live2d-canvas';
|
|
17
|
+
delete options.element_id;
|
|
18
|
+
return element_id
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function generateCdn(options: ResolveCdn) {
|
|
22
|
+
const cdn = options.cdn || 'https://cdn.jsdelivr.net/npm/@doki-land/live2d@latest/dist/l2d.umd.js';
|
|
23
|
+
delete options.cdn;
|
|
24
|
+
return cdn
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -50,8 +50,9 @@ export async function createLive2D(options: Live2dOptions): Promise<Live2DModel>
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
// 加载模型
|
|
53
|
-
const model = await Live2DModel.from(models[0].model_url
|
|
54
|
-
|
|
53
|
+
const model = await Live2DModel.from(models[0].model_url, {
|
|
54
|
+
ticker: Ticker.system,
|
|
55
|
+
});
|
|
55
56
|
// 添加模型到舞台
|
|
56
57
|
app.stage.addChild(model);
|
|
57
58
|
|
|
@@ -194,11 +195,6 @@ export async function initializeLive2D() {
|
|
|
194
195
|
// @ts-ignore
|
|
195
196
|
// window.Live2DCubismCore = cubism5 || Cubism5().Live2DCubismCore;
|
|
196
197
|
|
|
197
|
-
// 最后初始化 PIXI 相关功能
|
|
198
|
-
// 为 Live2DModel 注册 Ticker
|
|
199
|
-
Live2DModel.registerTicker(Ticker);
|
|
200
|
-
// 为 Application 注册 Ticker
|
|
201
|
-
PIXI.extensions.add(TickerPlugin);
|
|
202
198
|
// 注册 InteractionManager 以支持 Live2D 模型的自动交互
|
|
203
199
|
// PIXI.extensions.add(InteractionManager);
|
|
204
200
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {ModelOptions} from "@/types/ModelOptions.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export type ResolveModels = {
|
|
5
|
+
domain?: string,
|
|
6
|
+
models?: ModelOptions[]
|
|
7
|
+
models_folder?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type ResolveElementId = {
|
|
11
|
+
element_id?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ResolveCdn = {
|
|
15
|
+
cdn?: string
|
|
16
|
+
}
|
package/src/types/index.ts
CHANGED