Skip to content

Commit 46f6680

Browse files
authored
Merge pull request #25 from Arkueid/v2-rewrite-in-python
rewrite v2 in python
2 parents 2ccb56f + 94e9e00 commit 46f6680

File tree

389 files changed

+79066
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

389 files changed

+79066
-255
lines changed

Diff for: .gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ test
2828

2929
**.db
3030

31-
Resources/v2
32-
3331
!package/audio1.wav
3432

3533
!package/audio2.wav

Diff for: CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ message("${CMAKE_BUILD_TYPE}")
1414

1515
set(LIB_NAME LAppModelWrapper)
1616
set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
17-
set(RES_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Resources)
1817

1918
# prevent python root dir being shadowed by registry
2019
set(Python3_FIND_REGISTRY "NEVER")
@@ -25,7 +24,7 @@ if(DEFINED PYTHON_INSTALLATION_PATH)
2524
else()
2625
# 寻找Python
2726
message("Not found PYTHON_INSTALLATION_PATH in environment variables. \nUse default path.")
28-
set(CMAKE_PREFIX_PATH D:/Python/x86/3.12.0)
27+
set(CMAKE_PREFIX_PATH D:/Python/x64/3.12)
2928
endif()
3029

3130
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")

Diff for: LAppModelWrapper.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -775,19 +775,6 @@ static PyObject* live2d_glew_init()
775775
Py_RETURN_NONE;
776776
}
777777

778-
static PyObject* live2d_set_gl_properties()
779-
{
780-
// テクスチャサンプリング設定
781-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
782-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
783-
784-
// 透過設定
785-
glEnable(GL_BLEND);
786-
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
787-
788-
Py_RETURN_NONE;
789-
}
790-
791778
static PyObject* live2d_clear_buffer(PyObject* self, PyObject* args)
792779
{
793780
// 默认为黑色
@@ -833,7 +820,6 @@ static PyMethodDef live2d_methods[] = {
833820
{"init", (PyCFunction)live2d_init, METH_VARARGS, ""},
834821
{"dispose", (PyCFunction)live2d_dispose, METH_VARARGS, ""},
835822
{"glewInit", (PyCFunction)live2d_glew_init, METH_VARARGS, ""},
836-
{"setGLProperties", (PyCFunction)live2d_set_gl_properties, METH_VARARGS, ""},
837823
{"clearBuffer", (PyCFunction)live2d_clear_buffer, METH_VARARGS, ""},
838824
{"setLogEnable", (PyCFunction)live2d_set_log_enable, METH_VARARGS, ""},
839825
{"logEnable", (PyCFunction)live2d_log_enable, METH_VARARGS, ""},

Diff for: Main/live2d/MatrixManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Csm::CubismMatrix44 &MatrixManager::GetProjection(LAppModel *model)
4646
{
4747
_projection.LoadIdentity();
4848

49-
if (model->GetModel()->GetCanvasWidth() > 1.0f && _ww < _ww)
49+
if (model->GetModel()->GetCanvasWidth() > 1.0f && _ww < _wh)
5050
{
5151
// 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する
5252
model->GetModelMatrix()->SetWidth(2.0f);

Diff for: README.md

+25-14
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,62 @@
1111

1212
使用 Python 直接加载和操作 Live2D 模型,不通过 Web Engine 等间接手段进行渲染。
1313

14-
基于 Python C++ API 对 Live2D Native SDK (C++) 进行了封装。理论上,只要配置好 OpenGL 上下文,可在 Python 中将 live2d 绘制在任何基于 OpenGL 的窗口。
14+
基于 Python C++ API 对 Live2D Native SDK (C++) 进行了封装。理论上,只要配置好 OpenGL 上下文,可在 Python 中将 live2d
15+
绘制在任何基于 OpenGL 的窗口。
1516

1617
代码使用示例:[package](./package/)
1718

1819
详细使用文档:https://arkueid.github.io/live2d-py-docs/
1920

20-
加载 Cubism 2.1 及以下版本的 Live2D 模型使用 [v2](https://github.com/Arkueid/live2d-py/tree/v2) 分支
21-
2221
## 兼容UI库
22+
2323
理论上兼容所有能使用 OpenGL 进行绘制的UI库: Pygame / PyQt5 / PySide2 / PySide6 / GLFW / FreeGlut / Qfluentwidgets ...
2424

2525
## 支持功能
26-
* 加载模型
26+
27+
* 加载模型:**Cubism 2.1****Cubism 3.0** 及以上版本
2728
* 视线跟踪
2829
* 点击交互
2930
* 动作播放回调
3031
* 口型同步
3132
* 模型各部分参数控制
3233
* 各部件透明度控制
34+
* 精确到部件的点击检测
3335

3436
## 平台支持
3537

36-
| `live2d-py` | 支持的live2d模型 | 支持的Python版本 | 支持平台 |
37-
|-------------|------------------------|----------------------------------------------------------------|---------------|
38-
| `live2d.v2` | Cubism 2.1 以及更早的版本 | 仅 32 位,支持`Python 3.0` 及以上版本,但除 `Python 3.10.11` 外需要自行编译 | Windows |
39-
| `live2d.v3` | Cubism 3.0 及以上版本 | 支持 `32` / `64` 位,支持`Python 3.0` 及以上版本,但除 `Python 3.12` 外需要自行编译 | Windows、Linux |
38+
| `live2d-py` | 支持的live2d模型 | 实现 | 支持的Python版本 | 支持平台 |
39+
|-------------|--------------------|-------------------|---------------------------------------|--------------------------|
40+
| `live2d.v2` | Cubism 2.1 以及更早的版本 | 纯 Python 实现 | 支持 `32` / `64` 位,支持`Python 3.0` 及以上版本 | Winodws、Linux、MacOS(理论上) | |
41+
| `live2d.v3` | Cubism 3.0 及以上版本 | Python C++ API 封装 | 支持 `32` / `64` 位,支持`Python 3.0` 及以上版本 | Windows、Linux |
4042

4143
注:
44+
45+
* `live2d.v2` 由 Cubism Web SDK 转写为纯 Python,尚未使用 numpy 等优化的库,性能有待提升。
4246
* Cubism 2.X 导出的模型:文件名格式常为 `XXX.moc``XXX.model.json``XXX.mtn`
43-
* Cubism 3.0 及以上导出的模型:文件名格式常为 `XXX.moc3``XXX.model3.json`, `XXX.motion3.json`
44-
* 对于 Cubism 2.0 模型,网络上能找到的现存 live2d opengl 静态库只有 32 位,因此只能使用 32 位 Python 解释器加载。
47+
* Cubism 3.0 及以上导出的模型:文件名格式常为 `XXX.moc3``XXX.model3.json`, `XXX.motion3.json`
4548

4649
## 安装方式
4750

4851
1. 通过 [PyPI](https://pypi.org/project/live2d-py/) 安装
52+
4953
```shell
5054
pip install live2d-py
5155
```
5256

5357
2.[Release](https://github.com/Arkueid/live2d-py/releases/latest) 中下载对应版本的 `whl` 文件并安装(推荐)
58+
5459
```shell
5560
pip install live2d_py-0.X.X-cpXXX-cpXXX-win32.whl
5661
```
5762

58-
3. 从源码构建,参考 [安装#源码构建](https://arkueid.github.io/live2d-py-docs/%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/%E5%AE%89%E8%A3%85.html#%E6%BA%90%E7%A0%81%E6%9E%84%E5%BB%BA)
63+
3.
5964

65+
从源码构建,参考 [安装#源码构建](https://arkueid.github.io/live2d-py-docs/%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/%E5%AE%89%E8%A3%85.html#%E6%BA%90%E7%A0%81%E6%9E%84%E5%BB%BA)
6066

6167
## 简易面部动捕示例
62-
源码见 [main_facial_bind_mediapipe.py](./package/main_facial_bind_mediapipe.py)
68+
69+
源码见 [main_facial_bind_mediapipe.py](./package/main_facial_bind_mediapipe.py)
6370

6471
![面捕-期末周破防](./docs/video_test.gif)
6572

@@ -71,8 +78,12 @@ pip install live2d_py-0.X.X-cpXXX-cpXXX-win32.whl
7178

7279
## 贡献
7380

74-
特别感谢 [@96bearli][@Ovizro], [@AnyaCoder] 为本项目提供的帮助和支持。
81+
特别感谢 [@96bearli][@Ovizro], [@AnyaCoder], [@jahtim] 为本项目提供的帮助和支持。
7582

7683
[@96bearli]: https://github.com/96bearli
84+
7785
[@Ovizro]: https://github.com/Ovizro
78-
[@AnyaCoder]: https://github.com/AnyaCoder
86+
87+
[@AnyaCoder]: https://github.com/AnyaCoder
88+
89+
[@jahtim]: https://github.com/jahtim

Diff for: Resources/v2/Epsilon/Epsilon.1024/texture_00.png

786 KB
Loading

Diff for: Resources/v2/Epsilon/Epsilon.1024/texture_01.png

664 KB
Loading

Diff for: Resources/v2/Epsilon/Epsilon.1024/texture_02.png

805 KB
Loading

Diff for: Resources/v2/Epsilon/Epsilon.moc

170 KB
Binary file not shown.

Diff for: Resources/v2/Epsilon/Epsilon.model.json

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"version":"Sample 1.0.0",
3+
"model":"Epsilon.moc",
4+
"textures":[
5+
"Epsilon.1024/texture_00.png",
6+
"Epsilon.1024/texture_01.png",
7+
"Epsilon.1024/texture_02.png"
8+
],
9+
"motions":{
10+
"idle":[
11+
{
12+
"file":"motions/Epsilon_idle_01.mtn"
13+
}
14+
],
15+
"null":[
16+
{
17+
"file":"motions/Epsilon_m_01.mtn"
18+
},
19+
{
20+
"file":"motions/Epsilon_m_02.mtn"
21+
},
22+
{
23+
"file":"motions/Epsilon_m_03.mtn"
24+
},
25+
{
26+
"file":"motions/Epsilon_m_04.mtn"
27+
},
28+
{
29+
"file":"motions/Epsilon_m_05.mtn"
30+
},
31+
{
32+
"file":"motions/Epsilon_m_06.mtn"
33+
},
34+
{
35+
"file":"motions/Epsilon_m_07.mtn"
36+
},
37+
{
38+
"file":"motions/Epsilon_m_08.mtn"
39+
},
40+
{
41+
"file":"motions/Epsilon_m_sp_01.mtn"
42+
},
43+
{
44+
"file":"motions/Epsilon_m_sp_02.mtn"
45+
},
46+
{
47+
"file":"motions/Epsilon_m_sp_03.mtn"
48+
},
49+
{
50+
"file":"motions/Epsilon_m_sp_04.mtn"
51+
},
52+
{
53+
"file":"motions/Epsilon_m_sp_05.mtn"
54+
},
55+
{
56+
"file":"motions/Epsilon_shake_01.mtn"
57+
}
58+
]
59+
},
60+
"expressions":[
61+
{"name":"f01.exp.json","file":"expressions/f01.exp.json"},
62+
{"name":"f02.exp.json","file":"expressions/f02.exp.json"},
63+
{"name":"f03.exp.json","file":"expressions/f03.exp.json"},
64+
{"name":"f04.exp.json","file":"expressions/f04.exp.json"},
65+
{"name":"f05.exp.json","file":"expressions/f05.exp.json"},
66+
{"name":"f06.exp.json","file":"expressions/f06.exp.json"},
67+
{"name":"f07.exp.json","file":"expressions/f07.exp.json"},
68+
{"name":"f08.exp.json","file":"expressions/f08.exp.json"}
69+
],
70+
"physics":"Epsilon.physics.json"
71+
}

Diff for: Resources/v2/Epsilon/Epsilon.physics.json

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"type":"Live2D Physics",
3+
"physics_hair":[
4+
{
5+
"lebel":"BACK",
6+
"setup":{
7+
"length":0.24,
8+
"regist":0.5,
9+
"mass":0.18
10+
},
11+
"src":[
12+
{
13+
"id":"PARAM_ANGLE_X",
14+
"ptype":"x",
15+
"scale":0.005,
16+
"weight":1
17+
},
18+
{
19+
"id":"PARAM_ANGLE_Z",
20+
"ptype":"angle",
21+
"scale":0.8,
22+
"weight":1
23+
}
24+
],
25+
"targets":[
26+
{
27+
"id":"PARAM_HAIR_BACK_L",
28+
"ptype":"angle",
29+
"scale":0.005,
30+
"weight":1
31+
},
32+
{
33+
"id":"PARAM_HAIR_BACK_R",
34+
"ptype":"angle",
35+
"scale":0.005,
36+
"weight":1
37+
}
38+
]
39+
},
40+
{
41+
"lebel":"SIDE",
42+
"setup":{
43+
"length":0.2,
44+
"regist":0.5,
45+
"mass":0.14
46+
},
47+
"src":[
48+
{
49+
"id":"PARAM_ANGLE_X",
50+
"ptype":"x",
51+
"scale":0.004,
52+
"weight":1
53+
},
54+
{
55+
"id":"PARAM_ANGLE_Z",
56+
"ptype":"angle",
57+
"scale":0.8,
58+
"weight":1
59+
}
60+
],
61+
"targets":[
62+
{
63+
"id":"PARAM_HAIR_SIDE_L",
64+
"ptype":"angle",
65+
"scale":0.01,
66+
"weight":1
67+
},
68+
{
69+
"id":"PARAM_HAIR_SIDE_R",
70+
"ptype":"angle",
71+
"scale":0.01,
72+
"weight":1
73+
}
74+
]
75+
}
76+
]
77+
}

Diff for: Resources/v2/Epsilon/expressions/f01.exp.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type":"Live2D Expression",
3+
"fade_in":500,
4+
"fade_out":500
5+
}

Diff for: Resources/v2/Epsilon/expressions/f02.exp.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type":"Live2D Expression",
3+
"fade_in":500,
4+
"fade_out":500,
5+
"params":[
6+
{"id":"PARAM_EYE_L_OPEN","val":0,"calc":"mult"},
7+
{"id":"PARAM_EYE_L_SMILE","val":1},
8+
{"id":"PARAM_EYE_R_OPEN","val":0,"calc":"mult"},
9+
{"id":"PARAM_EYE_R_SMILE","val":1},
10+
{"id":"PARAM_BROW_L_ANGLE","val":0.48},
11+
{"id":"PARAM_BROW_R_ANGLE","val":0.46}
12+
]
13+
}

Diff for: Resources/v2/Epsilon/expressions/f03.exp.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"type":"Live2D Expression",
3+
"fade_in":500,
4+
"fade_out":500,
5+
"params":[
6+
{"id":"PARAM_EYE_L_OPEN","val":0.87,"calc":"mult"},
7+
{"id":"PARAM_EYE_L_SMILE","val":1},
8+
{"id":"PARAM_EYE_R_OPEN","val":0.87,"calc":"mult"},
9+
{"id":"PARAM_BROW_L_Y","val":-1},
10+
{"id":"PARAM_BROW_R_Y","val":-1},
11+
{"id":"PARAM_BROW_L_ANGLE","val":1},
12+
{"id":"PARAM_BROW_R_ANGLE","val":1},
13+
{"id":"PARAM_BROW_L_FORM","val":-0.51},
14+
{"id":"PARAM_BROW_R_FORM","val":-0.51},
15+
{"id":"PARAM_MOUTH_FORM","val":-1,"def":1}
16+
]
17+
}

Diff for: Resources/v2/Epsilon/expressions/f04.exp.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"type":"Live2D Expression",
3+
"fade_in":500,
4+
"fade_out":500,
5+
"params":[
6+
{"id":"PARAM_BROW_L_Y","val":-0.59},
7+
{"id":"PARAM_BROW_R_Y","val":-0.59},
8+
{"id":"PARAM_BROW_L_X","val":-1},
9+
{"id":"PARAM_BROW_R_X","val":-1},
10+
{"id":"PARAM_BROW_L_ANGLE","val":-1},
11+
{"id":"PARAM_BROW_R_ANGLE","val":-1},
12+
{"id":"PARAM_BROW_L_FORM","val":-1},
13+
{"id":"PARAM_BROW_R_FORM","val":-1},
14+
{"id":"PARAM_MOUTH_FORM","val":-1,"def":1}
15+
]
16+
}

Diff for: Resources/v2/Epsilon/expressions/f05.exp.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type":"Live2D Expression",
3+
"fade_in":500,
4+
"fade_out":500,
5+
"params":[
6+
{"id":"PARAM_BROW_L_Y","val":-0.42},
7+
{"id":"PARAM_BROW_R_Y","val":-0.44},
8+
{"id":"PARAM_BROW_L_X","val":-0.07},
9+
{"id":"PARAM_BROW_L_ANGLE","val":1},
10+
{"id":"PARAM_BROW_R_ANGLE","val":1},
11+
{"id":"PARAM_TERE","val":1}
12+
]
13+
}

Diff for: Resources/v2/Epsilon/expressions/f06.exp.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type":"Live2D Expression",
3+
"fade_in":500,
4+
"fade_out":500,
5+
"params":[
6+
{"id":"PARAM_BROW_L_Y","val":-1},
7+
{"id":"PARAM_BROW_R_Y","val":-1},
8+
{"id":"PARAM_BROW_L_X","val":-0.07},
9+
{"id":"PARAM_BROW_L_ANGLE","val":0.73},
10+
{"id":"PARAM_BROW_R_ANGLE","val":0.71},
11+
{"id":"PARAM_BROW_L_FORM","val":-0.81},
12+
{"id":"PARAM_BROW_R_FORM","val":-0.81},
13+
{"id":"PARAM_MOUTH_FORM","val":-1,"def":1}
14+
]
15+
}

0 commit comments

Comments
 (0)