Add VRM import map and assets endpoint.

This commit is contained in:
Tony Ribeiro 2024-01-05 07:00:23 +01:00
parent 99dc3fb6fe
commit 72d78fbe96
2 changed files with 41 additions and 1 deletions

View File

@ -22,6 +22,19 @@
<link rel="apple-touch-icon" sizes="72x72" href="img/apple-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="img/apple-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="img/apple-icon-144x144.png" />
<!-- VRM DEBUG -->
<script type="importmap">
{
"imports": {
"three": "./scripts/extensions/third-party/Extension-VRM/lib/three.module.js",
"three/addons/": "./scripts/extensions/third-party/Extension-VRM/lib/jsm/",
"@pixiv/three-vrm": "./scripts/extensions/third-party/Extension-VRM/lib/three-vrm.module.js"
}
}
</script>
<!-- VRM DEBUG -->
<script src="lib/object-hasown.js"></script>
<script src="lib/jquery-3.5.1.min.js"></script>
<script src="lib/jquery-ui.min.js"></script>

View File

@ -8,7 +8,7 @@ const { DIRECTORIES, UNSAFE_EXTENSIONS } = require('../constants');
const { jsonParser } = require('../express-common');
const { clientRelativePath } = require('../util');
const VALID_CATEGORIES = ['bgm', 'ambient', 'blip', 'live2d'];
const VALID_CATEGORIES = ['bgm', 'ambient', 'blip', 'live2d', 'vrm'];
/**
* Validates the input filename for the asset.
@ -106,6 +106,33 @@ router.post('/get', jsonParser, async (_, response) => {
continue;
}
// VRM assets
if (folder == 'vrm') {
output[folder] = {'model':[], 'animation':[]};
// Extract models
const vrm_model_folder = path.normalize(path.join(folderPath, 'vrm', 'model'));
let files = getFiles(vrm_model_folder);
//console.debug("FILE FOUND:",files)
for (let file of files) {
if (!file.endsWith('.placeholder')) {
//console.debug("Asset VRM model found:",file)
output['vrm']['model'].push(clientRelativePath(file));
}
}
// Extract models
const vrm_animation_folder = path.normalize(path.join(folderPath, 'vrm', 'animation'));
files = getFiles(vrm_animation_folder);
//console.debug("FILE FOUND:",files)
for (let file of files) {
if (!file.endsWith('.placeholder')) {
//console.debug("Asset VRM animation found:",file)
output['vrm']['animation'].push(clientRelativePath(file));
}
}
continue;
}
// Other assets (bgm/ambient/blip)
const files = fs.readdirSync(path.join(folderPath, folder))
.filter(filename => {