feat(scenes): 场景管理后端 + 契约 0.5.0/0.7.0/0.4.0(T-WEB-015)
契约先行(三端逐字节一致,已同步 windows/android):
- rest-api -> 0.5.0:新增 GET/POST /api/scenes、GET/PATCH/DELETE /api/scenes/{id}
- data-models -> 0.7.0:新增 §7 Scene 与 7.1 SceneConfig(物理/环境/出生点/相机)
- database -> 0.4.0:新增 scenes 表(config/stats 用 MEDIUMTEXT,迁移可逆)
后端:
- entities/scene.entity.ts + 迁移 AddScenes1789650000000(scenes 表)
- scenes/scene-config.ts:SceneConfig 定义 + 默认值 + **边界收敛**(越界夹紧、
非法枚举回退),保证客户端拿到的参数一定可解释;服务端只存参数不跑物理
- scenes/scenes.service.ts:上传(.glb/.gltf 直接导入;.zip/.pmx/.fbx 转 GLB,
场景不做 humanoid 重绑定、不转 VRM)、列表/详情/更新/软删除、缩略图复用模型
光栅化器、分析复用模型检查器、config 同时接受 JSON 字符串与平铺字段
- scenes/scenes.controller.ts + scenes.module.ts(app.module 注册)
- 审核复用 /api/reviews/:type/:id:TargetType.Scene 接入待审列表与状态流转
- catalog/export 增 scenes[],目录指纹纳入场景变更
- 枚举:TargetType.Scene、AssetKind.Scene / SceneThumbnail
测试:新增 test/scene-config.spec.ts 6 项(默认值/夹紧/枚举回退/出生点上限/颜色/
序列化);规模 19 文件 / 243 项;check-routes 35 条一致。版本 0.6.0。
注:管理端场景页(GLB 预览 + 物理参数可视化)与 Windows 场景选择留待下一轮。
This commit is contained in:
@@ -12,6 +12,8 @@ import { ModelsService } from '../models/models.service';
|
||||
import { MotionDto } from '../motions/motion.serializer';
|
||||
import { MotionsService } from '../motions/motions.service';
|
||||
import { SongDto } from '../songs/song.serializer';
|
||||
import { ScenesService } from '../scenes/scenes.service';
|
||||
import type { SceneDto } from '../scenes/scene.serializer';
|
||||
import { SongsService } from '../songs/songs.service';
|
||||
|
||||
export interface CatalogBundle {
|
||||
@@ -20,6 +22,8 @@ export interface CatalogBundle {
|
||||
songs: SongDto[];
|
||||
motions: MotionDto[];
|
||||
models: ModelDto[];
|
||||
/** 已发布场景(含物理参数);契约 data-models 0.7.0 */
|
||||
scenes: SceneDto[];
|
||||
defaultModelId: number | null;
|
||||
}
|
||||
|
||||
@@ -36,6 +40,7 @@ export class CatalogService {
|
||||
private readonly songsService: SongsService,
|
||||
private readonly motionsService: MotionsService,
|
||||
private readonly modelsService: ModelsService,
|
||||
private readonly scenesService: ScenesService,
|
||||
private readonly config: AppConfig,
|
||||
) {}
|
||||
|
||||
@@ -50,10 +55,11 @@ export class CatalogService {
|
||||
}),
|
||||
]);
|
||||
|
||||
const [songDtos, motionDtos, modelDtos, defaultModelId] = await Promise.all([
|
||||
const [songDtos, motionDtos, modelDtos, sceneDtos, defaultModelId] = await Promise.all([
|
||||
this.songsService.toDtos(songs),
|
||||
this.motionsService.toDtos(motions),
|
||||
this.modelsService.toDtos(models),
|
||||
this.scenesService.published(),
|
||||
this.modelsService.resolveDefaultModelId(),
|
||||
]);
|
||||
|
||||
@@ -63,6 +69,7 @@ export class CatalogService {
|
||||
songs: songDtos,
|
||||
motions: motionDtos,
|
||||
models: modelDtos,
|
||||
scenes: sceneDtos,
|
||||
defaultModelId,
|
||||
};
|
||||
}
|
||||
@@ -72,7 +79,7 @@ export class CatalogService {
|
||||
* 指纹只覆盖影响客户端行为的字段。
|
||||
*/
|
||||
async version(): Promise<{ contractVersion: Record<string, string>; revision: string; generatedAt: string }> {
|
||||
const [songs, motions, models] = await Promise.all([
|
||||
const [songs, motions, models, scenes] = await Promise.all([
|
||||
this.songs.find({ where: { status: PublishStatus.Published }, order: { id: 'ASC' } }),
|
||||
this.motions.find({ where: { status: PublishStatus.Published }, order: { id: 'ASC' } }),
|
||||
// v0.5.0:只交付**已产出 VRM** 的模型(usable),未产出 VRM 的不进入客户端目录
|
||||
@@ -80,6 +87,7 @@ export class CatalogService {
|
||||
where: { status: PublishStatus.Published, format: ModelFormat.Vrm },
|
||||
order: { id: 'ASC' },
|
||||
}),
|
||||
this.scenesService.published(),
|
||||
]);
|
||||
|
||||
const fingerprint = JSON.stringify({
|
||||
@@ -94,6 +102,7 @@ export class CatalogService {
|
||||
m.preprocessState,
|
||||
]),
|
||||
models: models.map((m) => [m.id, m.name, m.format, m.isPrimary, m.updatedAt.toISOString(), m.fileAssetId]),
|
||||
scenes: scenes.map((s) => [s.id, s.name, s.updatedAt, s.glbUrl, s.status]),
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user