live2d_api/get/index.php

66 lines
2.1 KiB
PHP
Raw Normal View History

2018-03-03 01:39:22 +08:00
<?php
isset($_GET['id']) ? $id = $_GET['id'] : exit('error');
require '../tools/modelList.php';
require '../tools/modelTextures.php';
2019-02-09 15:17:15 +08:00
require '../tools/jsonCompatible.php';
2018-03-03 01:39:22 +08:00
$modelList = new modelList();
$modelTextures = new modelTextures();
2019-02-09 15:17:15 +08:00
$jsonCompatible = new jsonCompatible();
2018-03-03 01:39:22 +08:00
$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);
}
}
$textures = $json['textures'];
foreach ($textures as $key => $texture){
$textures[$key] = '../model/' . $modelName . '/' . $texture;
}
2018-03-03 01:39:22 +08:00
$json['textures'] = $textures;
$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'])) {
$motions = $json['motions'];
foreach ($motions as $key1 => $motion){
foreach($motion as $key2 => $resource){
foreach ($resource as $key3 => $value)
if($key3 == 'file'){
$motions[$key1][$key2][$key3] = '../model/' . $modelName . '/' . $value;
}
}
}
2020-03-09 02:55:29 +08:00
$json['motions'] = $motions;
2018-03-03 01:39:22 +08:00
}
if (isset($json['expressions'])) {
$expressions = $json['expressions'];
foreach ($expressions as $key1 => $expression){
foreach($expression as $key2 => $value){
if($key2 == 'file'){
$expressions[$key1][$key2] = '../model/' . $modelName . '/' . $value;
}
}
}
2018-03-03 01:39:22 +08:00
$json['expressions'] = $expressions;
}
header("Content-type: application/json");
2019-02-09 15:17:15 +08:00
echo $jsonCompatible->json_encode($json);