-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f1eae4
commit 776c67a
Showing
644 changed files
with
12,842 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 FGHRSH | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# Live2D API | ||
|
||
Live2D 看板娘插件 (https://www.fghrsh.net/post/123.html) 上使用的后端 API | ||
|
||
### 特性 | ||
|
||
- 原生 PHP 开发,无需伪静态,开箱即用 | ||
- 支持 模型、皮肤 的 顺序切换 和 随机切换 | ||
- 支持 单模型 单皮肤 切换、多组皮肤 递归穷举 | ||
- 支持 同分组 多个模型 或 多个路径 的 加载切换 | ||
|
||
## 使用 | ||
|
||
### 环境要求 | ||
- PHP 版本 >= 5.2 | ||
- 依赖 PHP 扩展:json | ||
|
||
### 目录结构 | ||
|
||
```shell | ||
│ model_list.json // 模型列表 | ||
│ | ||
├─model // 模型路径 | ||
│ └─GroupName // 模组分组 | ||
│ └─ModelName // 模型名称 | ||
│ | ||
├─add // 更新皮肤列表 | ||
├─get // 获取模型配置 | ||
├─rand // 随机切换模型 | ||
├─rand_textures // 随机切换皮肤 | ||
├─switch // 顺序切换模型 | ||
├─switch_textures // 顺序切换皮肤 | ||
└─tools | ||
modelList.php // 列出模型列表 | ||
modelTextures.php // 列出皮肤列表 | ||
name-to-lower.php // 文件名格式化 | ||
``` | ||
|
||
### 添加模型 | ||
|
||
- 单模型 单皮肤 切换 | ||
- 单次加载只输出一个皮肤 | ||
- 皮肤放在 `textures` 文件夹,自动识别 | ||
|
||
```shell | ||
│ index.json | ||
│ model.moc | ||
│ textures.cache // 皮肤列表缓存,自动生成 | ||
│ | ||
├─motions | ||
│ idle_01.mtn | ||
│ idle_02.mtn | ||
│ idle_03.mtn | ||
│ | ||
└─textures | ||
default-costume.png | ||
school-costume.png | ||
winter-costume.png | ||
``` | ||
|
||
- 单模型 多组皮肤 递归穷举 | ||
- 多组皮肤 组合模型、穷举组合 | ||
- 皮肤文件夹按 `texture_XX` 命名 | ||
- 添加 `textures_order.json` 列出组合 | ||
```shell | ||
│ index.json | ||
│ model.moc | ||
│ textures.cache | ||
│ textures_order.json | ||
│ | ||
├─motions | ||
│ idle_01.mtn | ||
│ idle_02.mtn | ||
│ idle_03.mtn | ||
│ | ||
├─texture_00 | ||
│ 00.png | ||
│ | ||
├─texture_01 | ||
│ 00.png | ||
│ 01.png | ||
│ 02.png | ||
│ | ||
├─texture_02 | ||
│ 00.png | ||
│ 01.png | ||
│ 02.png | ||
│ | ||
└─texture_03 | ||
00.png | ||
01.png | ||
``` | ||
|
||
textures_order.json | ||
|
||
```json | ||
[ | ||
["texture_00"], | ||
["texture_01","texture_02"], | ||
["texture_03"] | ||
] | ||
``` | ||
|
||
textures.cache | ||
|
||
```json | ||
[ | ||
["texture_00/00.png","texture_01/00.png","texture_02/00.png","texture_03/00.png"], | ||
["texture_00/00.png","texture_01/00.png","texture_02/00.png","texture_03/01.png"], | ||
["texture_00/00.png","texture_01/01.png","texture_02/01.png","texture_03/00.png"], | ||
["texture_00/00.png","texture_01/01.png","texture_02/01.png","texture_03/01.png"], | ||
["texture_00/00.png","texture_01/02.png","texture_02/02.png","texture_03/00.png"], | ||
["texture_00/00.png","texture_01/02.png","texture_02/02.png","texture_03/01.png"] | ||
] | ||
``` | ||
|
||
- 同分组 多个模型 或 多个路径 切换 | ||
- 修改 `model_list.json` 添加多个模型 | ||
|
||
```shell | ||
│ | ||
├─model | ||
│ ├─Group1 | ||
│ │ ├─Model1 | ||
│ │ │ index.json | ||
│ │ │ | ||
│ │ └─Model2 | ||
│ │ index.json | ||
│ │ | ||
│ ├─Group2 | ||
│ │ └─Model1 | ||
│ │ index.json | ||
│ │ | ||
│ └─GroupName | ||
│ └─ModelName | ||
│ │ index.json | ||
│ │ model.moc | ||
│ │ | ||
│ ├─motions | ||
│ └─textures | ||
│ | ||
``` | ||
|
||
model_list.json | ||
```json | ||
{ | ||
"models": [ | ||
"GroupName/ModelName", | ||
[ | ||
"Group1/Model1", | ||
"Group1/Model2", | ||
"Group2/Model1" | ||
] | ||
], | ||
"messages": [ | ||
"Example 1", | ||
"Example 2" | ||
] | ||
} | ||
``` | ||
|
||
### 接口用法 | ||
- `/add/` - 检测 新增皮肤 并更新 缓存列表 | ||
- `/get/?id=1-23` 获取 分组 1 的 第 23 号 皮肤 | ||
- `/rand/?id=1` 根据 上一分组 随机切换 | ||
- `/switch/?id=1` 根据 上一分组 顺序切换 | ||
- `/rand_textures/?id=1-23` 根据 上一皮肤 随机切换 同分组其他皮肤 | ||
- `/switch_textures/?id=1-23` 根据 上一皮肤 顺序切换 同分组其他皮肤 | ||
|
||
## 版权声明 | ||
|
||
> (>▽<) 都看到这了,点个 Star 吧 ~ | ||
**API 内所有模型 版权均属于原作者,仅供研究学习,不得用于商业用途** | ||
|
||
MIT © FGHRSH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
require '../tools/modelList.php'; | ||
require '../tools/modelTextures.php'; | ||
|
||
$modelList = new modelList(); | ||
$modelTextures = new modelTextures(); | ||
|
||
$modelList = $modelList->get_list(); | ||
$modelList = $modelList['models']; | ||
|
||
foreach ($modelList as $modelName) { | ||
if (!is_array($modelName) && file_exists('../model/'.$modelName.'/textures.cache')) { | ||
|
||
$textures = $texturesNew = array(); | ||
$modelTexturesList = $modelTextures->get_list($modelName); | ||
$modelNameTextures = $modelTextures->get_textures($modelName); | ||
if (is_array($modelTexturesList)) foreach ($modelTexturesList['textures'] as $v) $textures[] = str_replace('\/', '/', json_encode($v)); | ||
if (is_array($modelNameTextures)) foreach ($modelNameTextures as $v) $texturesNew[] = str_replace('\/', '/', json_encode($v)); | ||
|
||
$texturesDiff = array_diff($texturesNew, $textures); | ||
if (empty($textures)) continue; elseif (empty($texturesDiff)) { | ||
echo '<p>'.$modelName.' / textures.cache / No Update.</p>'; | ||
} else { | ||
foreach (array_values(array_unique(array_merge($textures, $texturesNew))) as $v) $texturesMerge[] = json_decode($v, 1); | ||
file_put_contents('../model/'.$modelName.'/textures.cache', str_replace('\/', '/', json_encode($texturesMerge))); | ||
echo '<p>'.$modelName.' / textures.cache / Updated.</p>'; | ||
} | ||
|
||
} | ||
elseif (is_array($modelName)) continue; | ||
elseif ($modelTextures->get_list($modelName)) echo '<p>'.$modelName.' / textures.cache / Created.</p>'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
isset($_GET['id']) ? $id = $_GET['id'] : exit('error'); | ||
|
||
require '../tools/modelList.php'; | ||
require '../tools/modelTextures.php'; | ||
require '../tools/jsonCompatible.php'; | ||
|
||
$modelList = new modelList(); | ||
$modelTextures = new modelTextures(); | ||
$jsonCompatible = new jsonCompatible(); | ||
|
||
$id = explode('-', $id); | ||
$modelId = (int)$id[0]; | ||
$modelTexturesId = isset($id[1]) ? (int)$id[1] : 0; | ||
|
||
$modelName = $modelList->id_to_name($modelId); | ||
|
||
if (is_array($modelName)) { | ||
$modelName = $modelTexturesId > 0 ? $modelName[$modelTexturesId-1] : $modelName[0]; | ||
$json = json_decode(file_get_contents('../model/'.$modelName.'/index.json'), 1); | ||
} else { | ||
$json = json_decode(file_get_contents('../model/'.$modelName.'/index.json'), 1); | ||
if ($modelTexturesId > 0) { | ||
$modelTexturesName = $modelTextures->get_name($modelName, $modelTexturesId); | ||
if (isset($modelTexturesName)) $json['textures'] = is_array($modelTexturesName) ? $modelTexturesName : array($modelTexturesName); | ||
} | ||
} | ||
|
||
foreach ($json['textures'] as $k => $texture) | ||
$json['textures'][$k] = '../model/' . $modelName . '/' . $texture; | ||
|
||
$json['model'] = '../model/'.$modelName.'/'.$json['model']; | ||
if (isset($json['pose'])) $json['pose'] = '../model/'.$modelName.'/'.$json['pose']; | ||
if (isset($json['physics'])) $json['physics'] = '../model/'.$modelName.'/'.$json['physics']; | ||
|
||
if (isset($json['motions'])) | ||
foreach ($json['motions'] as $k => $v) foreach($v as $k2 => $v2) foreach ($v2 as $k3 => $motion) | ||
if ($k3 == 'file' || $k3 == 'sound') $json['motions'][$k][$k2][$k3] = '../model/' . $modelName . '/' . $motion; | ||
|
||
if (isset($json['expressions'])) | ||
foreach ($json['expressions'] as $k => $v) foreach($v as $k2 => $expression) | ||
if ($k2 == 'file') $json['expressions'][$k][$k2] = '../model/' . $modelName . '/' . $expression; | ||
|
||
header("Content-type: application/json"); | ||
echo $jsonCompatible->json_encode($json); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"version":"Sample 1.0.0", | ||
"model": "model.moc", | ||
"textures": [ | ||
"textures.1024/00.png", | ||
"textures.1024/01.png", | ||
"textures.1024/02.png", | ||
"textures.1024/03.png" | ||
], | ||
"pose": "../general/pose.json", | ||
"physics": "physics.json", | ||
"layout": { | ||
"center_x": 0, | ||
"center_y": -0.6, | ||
"width": 3 | ||
}, | ||
"hit_areas_custom":{ | ||
"head_x":[-0.35, 0.6], | ||
"head_y":[0.19, -0.2], | ||
"body_x":[-0.3, -0.25], | ||
"body_y":[0.3, -0.9] | ||
}, | ||
"motions": { | ||
"idle": [ | ||
{"file": "motions/../../general/mtn/idle_00.mtn", "fade_in": 2000, "fade_out": 2000}, | ||
{"file": "motions/../../general/mtn/idle_01.mtn", "fade_in": 2000, "fade_out": 2000}, | ||
{"file": "motions/../../general/mtn/idle_02.mtn", "fade_in": 2000, "fade_out": 2000} | ||
] | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.