feat(models): 模型一律转 VRM(契约 0.5.0)+ 可用性门槛 + 管理端版本号展示
按《DSH 开发文档 v1.6》4.9 与第十一章实现,Web 端第一步:
1. 契约先行(先改 contracts/ 再同步三端):
* model-formats.md -> 0.5.0:模型主力格式改为 VRM,所有上传模型一律转 VRM
(.pmx/.fbx: assimp -> GLB -> VRM;glb/gltf: 包装为 VRM);
新增 humanoid 硬门槛与"不达标回退 GLB + usable=false"的交付表;
* data-models.md -> 0.5.0:Model 新增 usable / unusableReason,明确
usable=false 不进入 catalog/export;format 说明改为主力 vrm;
* VERSION 与 contract-versions.ts 同步(三端契约文件逐字节一致)。
2. 实现:
* MODEL_CONVERT_FORMAT 默认改为 vrm(deploy/.env.example 同步);
* 新增 isUsableModel()/unusableReason():usable 等价于"已产出 VRM",
原因从 stats 里带出 humanoid 覆盖度;
* catalog/export 与 catalog/version 指纹都只统计 format=vrm 的已发布模型,
resolveDefaultModelId 同样只在可用模型中选;
* 管理端:模型列表与审核面板显示「不可用」及原因;
* 管理端左下角展示当前版本号(构建期从 web-server/package.json 注入
__APP_VERSION__,与 GET /health 同源),并去掉写死的"契约 rest-api 0.1.0"。
3. 测试:新增 test/model-usability.spec.ts 5 项;规模 16 文件 / 225 项。
4. 版本 0.3.0。
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ModelFormat, PublishStatus, SourceType } from '../common/enums';
|
||||
import type { ModelStats } from './model-inspector';
|
||||
import { CharacterModel } from '../entities/model.entity';
|
||||
|
||||
/** 契约 data-models.md §4 的对外表示 */
|
||||
@@ -7,6 +8,13 @@ export interface ModelDto {
|
||||
name: string;
|
||||
format: ModelFormat;
|
||||
vrmVersion: string | null;
|
||||
/**
|
||||
* 是否可被客户端使用(v0.5.0):等价于"已产出 VRM"。
|
||||
* `false` 的模型**不进入 `catalog/export`**,但仍可入库与审核。
|
||||
*/
|
||||
usable: boolean;
|
||||
/** `usable=false` 时的原因(中文,供审核面板直接展示) */
|
||||
unusableReason: string | null;
|
||||
isPrimary: boolean;
|
||||
fileUrl: string | null;
|
||||
fileSize: number | null;
|
||||
@@ -37,12 +45,35 @@ export interface ModelUrlLookup {
|
||||
sourceSha256?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模型是否可用于客户端(v0.5.0 门槛):**必须已产出 VRM**。
|
||||
*
|
||||
* 依据 `contracts/model-formats.md` 1.1:所有上传模型一律转 VRM;
|
||||
* humanoid 不达标时管线回退交付 GLB,此时模型可入库、可审核,但**不可用**、
|
||||
* 不进入 `catalog/export` —— 待按 skeleton-topology 标准重绑定骨骼后重新转换即转为可用。
|
||||
*/
|
||||
export function isUsableModel(model: CharacterModel): boolean {
|
||||
return model.format === ModelFormat.Vrm;
|
||||
}
|
||||
|
||||
/** 不可用的原因(可用时返回 null);从 stats 取 humanoid 覆盖度,便于人工定位 */
|
||||
export function unusableReason(model: CharacterModel): string | null {
|
||||
if (isUsableModel(model)) return null;
|
||||
const stats = (model.stats ?? null) as Partial<ModelStats> | null;
|
||||
if (stats && typeof stats.humanoidMapped === 'number' && typeof stats.humanoidTotal === 'number') {
|
||||
return `humanoid 不达标(${stats.humanoidMapped}/${stats.humanoidTotal}),未产出 VRM`;
|
||||
}
|
||||
return '未产出 VRM(格式为 GLB),不可用于客户端';
|
||||
}
|
||||
|
||||
export function toModelDto(model: CharacterModel, urls: ModelUrlLookup): ModelDto {
|
||||
return {
|
||||
id: model.id,
|
||||
name: model.name,
|
||||
format: model.format,
|
||||
vrmVersion: model.vrmVersion,
|
||||
usable: isUsableModel(model),
|
||||
unusableReason: unusableReason(model),
|
||||
isPrimary: model.isPrimary,
|
||||
fileUrl: urls.fileUrl,
|
||||
fileSize: urls.fileSize ?? null,
|
||||
|
||||
@@ -451,8 +451,9 @@ export class ModelsService {
|
||||
* 4. id 最小的已发布模型
|
||||
*/
|
||||
async resolveDefaultModelId(): Promise<number | null> {
|
||||
// v0.5.0:默认模型必须来自**可用**模型(已产出 VRM);未产出 VRM 的不进客户端目录
|
||||
const published = await this.models.find({
|
||||
where: { status: PublishStatus.Published },
|
||||
where: { status: PublishStatus.Published, format: ModelFormat.Vrm },
|
||||
order: { id: 'ASC' },
|
||||
});
|
||||
if (published.length === 0) return null;
|
||||
|
||||
Reference in New Issue
Block a user