modelstage 0.0.0-stage → 0.5.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +274 -2
- package/THIRD_PARTY_NOTICES.md +90 -0
- package/bin/modelstage.mjs +137 -0
- package/config/diag-upload.example.json +7 -0
- package/config/models/live2d.assetbundls.json +1 -0
- package/config/models/live2d.azurlane.json +1 -0
- package/config/models/live2d.azurlane_bundle.json +1 -0
- package/config/models/live2d.azurlane_spine.json +1 -0
- package/config/models/live2d.bd2.json +1 -0
- package/config/models/live2d.bluearchive.json +1 -0
- package/config/models/live2d.live2d.json +1 -0
- package/config/models/live2d.nikke.json +1 -0
- package/config/models/live2d.nikke_2.json +1 -0
- package/config/models/live2d.npc.json +1 -0
- package/config/models/spine.assetbundls.json +1 -0
- package/config/models/spine.azurlane.json +1 -0
- package/config/models/spine.azurlane_bundle.json +1 -0
- package/config/models/spine.azurlane_spine.json +1 -0
- package/config/models/spine.bd2.json +1 -0
- package/config/models/spine.bluearchive.json +1 -0
- package/config/models/spine.live2d.json +1 -0
- package/config/models/spine.nikke.json +1 -0
- package/config/models/spine.nikke_2.json +1 -0
- package/config/models/spine.npc.json +1 -0
- package/config/names/NIKKE.json +1058 -0
- package/config/names/README.md +47 -0
- package/config/names//345/244/251/345/221/275/344/271/213/345/255/220.json +42897 -0
- package/config/names//346/243/225/350/211/262/345/260/230/345/237/2032.json +4016 -0
- package/config/names//347/242/247/350/223/235/350/210/252/347/272/277.json +38342 -0
- package/config/plugins.json +13 -0
- package/config/resources.example.json +40 -0
- package/package.json +63 -4
- package/plugins/unity-live2d-bundle/README.md +98 -0
- package/plugins/unity-live2d-bundle/index.js +891 -0
- package/plugins/unity-live2d-bundle/lib/anim-to-motion.js +402 -0
- package/plugins/unity-live2d-bundle/lib/bundle-probe.js +244 -0
- package/plugins/unity-live2d-bundle/lib/bytes.js +189 -0
- package/plugins/unity-live2d-bundle/lib/common-strings.js +46 -0
- package/plugins/unity-live2d-bundle/lib/dxt.js +197 -0
- package/plugins/unity-live2d-bundle/lib/errors.js +71 -0
- package/plugins/unity-live2d-bundle/lib/etc2.js +371 -0
- package/plugins/unity-live2d-bundle/lib/extract.js +242 -0
- package/plugins/unity-live2d-bundle/lib/lzma-d-min.LICENSE.txt +21 -0
- package/plugins/unity-live2d-bundle/lib/lzma-d-min.js +34 -0
- package/plugins/unity-live2d-bundle/lib/model3.js +137 -0
- package/plugins/unity-live2d-bundle/lib/png.js +424 -0
- package/plugins/unity-live2d-bundle/lib/serialized.js +233 -0
- package/plugins/unity-live2d-bundle/lib/texdecode.js +190 -0
- package/plugins/unity-live2d-bundle/lib/typetree.js +215 -0
- package/plugins/unity-live2d-bundle/lib/unityfs.js +396 -0
- package/plugins/unity-live2d-bundle/plugin.json +81 -0
- package/plugins/unity-live2d-bundle/profiles/unityfs-live2d.json +26 -0
- package/plugins/unity-spine-bundle/index.js +535 -0
- package/plugins/unity-spine-bundle/lib/bytes.js +189 -0
- package/plugins/unity-spine-bundle/lib/common-strings.js +46 -0
- package/plugins/unity-spine-bundle/lib/dxt.js +197 -0
- package/plugins/unity-spine-bundle/lib/errors.js +79 -0
- package/plugins/unity-spine-bundle/lib/etc2.js +371 -0
- package/plugins/unity-spine-bundle/lib/extract.js +242 -0
- package/plugins/unity-spine-bundle/lib/lzma-d-min.LICENSE.txt +21 -0
- package/plugins/unity-spine-bundle/lib/lzma-d-min.js +34 -0
- package/plugins/unity-spine-bundle/lib/png.js +424 -0
- package/plugins/unity-spine-bundle/lib/serialized.js +233 -0
- package/plugins/unity-spine-bundle/lib/texdecode.js +190 -0
- package/plugins/unity-spine-bundle/lib/typetree.js +215 -0
- package/plugins/unity-spine-bundle/lib/unityfs.js +396 -0
- package/plugins/unity-spine-bundle/plugin.json +75 -0
- package/src/server/README.md +69 -0
- package/src/server/assets/browse.mjs +56 -0
- package/src/server/assets/bundle-probe.mjs +94 -0
- package/src/server/assets/probe.mjs +184 -0
- package/src/server/core/config.mjs +173 -0
- package/src/server/core/env-num.mjs +60 -0
- package/src/server/core/env.mjs +49 -0
- package/src/server/core/fs-portable.mjs +37 -0
- package/src/server/core/log.mjs +107 -0
- package/src/server/core/paths.mjs +44 -0
- package/src/server/data/catalog.mjs +1091 -0
- package/src/server/data/entry-states.mjs +499 -0
- package/src/server/data/live2d.mjs +272 -0
- package/src/server/data/manifest-cache.mjs +58 -0
- package/src/server/data/manifest-stamp.mjs +135 -0
- package/src/server/data/model-meta.mjs +114 -0
- package/src/server/data/names.mjs +106 -0
- package/src/server/data/shape-probe-worker.mjs +33 -0
- package/src/server/data/shape-probe.mjs +626 -0
- package/src/server/data/spine.mjs +336 -0
- package/src/server/data/tree.mjs +126 -0
- package/src/server/http/atomic-json.mjs +145 -0
- package/src/server/http/background-solids.mjs +270 -0
- package/src/server/http/backgrounds.mjs +388 -0
- package/src/server/http/diag-upload.mjs +264 -0
- package/src/server/http/diag.mjs +173 -0
- package/src/server/http/ready.mjs +167 -0
- package/src/server/http/static.mjs +312 -0
- package/src/server/http/write.mjs +654 -0
- package/src/server/index.mjs +114 -0
- package/src/server/plugins/builtin-providers.json +30 -0
- package/src/server/plugins/registry.mjs +650 -0
- package/src/server/plugins/slot-catalog.mjs +286 -0
- package/src/server/routes/background-solids.mjs +56 -0
- package/src/server/routes/backgrounds.mjs +77 -0
- package/src/server/routes/config.mjs +38 -0
- package/src/server/routes/data.mjs +313 -0
- package/src/server/routes/diag.mjs +37 -0
- package/src/server/routes/entries.mjs +170 -0
- package/src/server/routes/ready.mjs +122 -0
- package/src/server/serve.mjs +396 -0
- package/src/server/unpack/capacity.mjs +217 -0
- package/src/server/unpack/mem-probe.mjs +27 -0
- package/src/server/unpack/plugin-runner.mjs +529 -0
- package/src/server/unpack/plugin-store.mjs +736 -0
- package/src/server/unpack/probe-store.mjs +73 -0
- package/src/server/unpack/routes.mjs +359 -0
- package/src/server/unpack/runtime/exec.mjs +558 -0
- package/src/server/unpack/runtime/index.mjs +141 -0
- package/src/server/unpack/runtime/node-vm.mjs +111 -0
- package/src/server/unpack/unpack-worker.mjs +105 -0
- package/src/server/unpack/worker-client.mjs +184 -0
- package/src/server/unpack/write-result.mjs +84 -0
- package/src/shared/bundle-shape.mjs +83 -0
- package/src/shared/entry-reasons.mjs +119 -0
- package/src/shared/names.mjs +45 -0
- package/src/shared/type-labels.mjs +31 -0
- package/src/web/README.md +193 -0
- package/src/web/app/anim-list.js +222 -0
- package/src/web/app/background-solids.js +150 -0
- package/src/web/app/backgrounds.js +152 -0
- package/src/web/app/camera-log.js +28 -0
- package/src/web/app/context.js +72 -0
- package/src/web/app/dir-picker.js +242 -0
- package/src/web/app/entry-report.js +71 -0
- package/src/web/app/memory-bars.js +91 -0
- package/src/web/app/memory-budget.js +228 -0
- package/src/web/app/memory-guard.js +204 -0
- package/src/web/app/model-actions.js +682 -0
- package/src/web/app/renderer-setting.js +70 -0
- package/src/web/app/root-manager.js +254 -0
- package/src/web/app/status.js +138 -0
- package/src/web/app/topbar-actions.js +357 -0
- package/src/web/app/transport-actions.js +297 -0
- package/src/web/app/ui-state.js +559 -0
- package/src/web/app/url-params.js +171 -0
- package/src/web/app/view-settings.js +186 -0
- package/src/web/components.css +524 -0
- package/src/web/debug/diag-hud.js +95 -0
- package/src/web/debug/drag.js +369 -0
- package/src/web/debug/log.js +320 -0
- package/src/web/debug/model-cmp.js +292 -0
- package/src/web/debug/panel.css +474 -0
- package/src/web/debug/panel.js +712 -0
- package/src/web/debug/race-probe.js +82 -0
- package/src/web/debug/upload.js +130 -0
- package/src/web/engine/adapters/atlas.js +47 -0
- package/src/web/engine/adapters/index.js +22 -0
- package/src/web/engine/adapters/renderer.js +223 -0
- package/src/web/engine/adapters/skeleton.js +105 -0
- package/src/web/engine/adapters/texture.js +64 -0
- package/src/web/engine/animation.js +181 -0
- package/src/web/engine/appearance.js +136 -0
- package/src/web/engine/camera-adapter.js +212 -0
- package/src/web/engine/effect-chain.js +138 -0
- package/src/web/engine/engine-state.js +120 -0
- package/src/web/engine/filters.js +224 -0
- package/src/web/engine/fit.js +197 -0
- package/src/web/engine/frame-gate.js +33 -0
- package/src/web/engine/gl-driver.js +56 -0
- package/src/web/engine/gl.js +77 -0
- package/src/web/engine/index.js +20 -0
- package/src/web/engine/loader.js +55 -0
- package/src/web/engine/model-info.js +26 -0
- package/src/web/engine/pipeline.js +200 -0
- package/src/web/engine/player.js +427 -0
- package/src/web/engine/pma/blend.js +76 -0
- package/src/web/engine/pma/detect.js +118 -0
- package/src/web/engine/pma/index.js +8 -0
- package/src/web/engine/pma/resolve.js +112 -0
- package/src/web/engine/pma/upload.js +127 -0
- package/src/web/engine/pma.js +5 -0
- package/src/web/engine/render-frame.js +93 -0
- package/src/web/engine/runtime-capabilities.js +209 -0
- package/src/web/engine/runtime.js +37 -0
- package/src/web/engine/skins.js +165 -0
- package/src/web/engine/textures.js +174 -0
- package/src/web/index.html +117 -0
- package/src/web/infra/api.js +531 -0
- package/src/web/infra/diag.js +509 -0
- package/src/web/infra/document.js +269 -0
- package/src/web/infra/dom.js +31 -0
- package/src/web/infra/events.mjs +27 -0
- package/src/web/infra/log.js +153 -0
- package/src/web/infra/mem-stats.js +112 -0
- package/src/web/infra/plugin-host-registration.mjs +285 -0
- package/src/web/infra/plugin-host-report.mjs +32 -0
- package/src/web/infra/plugin-host-unload.mjs +79 -0
- package/src/web/infra/plugin-host-unpack.mjs +899 -0
- package/src/web/infra/plugin-host-warmup.mjs +180 -0
- package/src/web/infra/plugin-host.js +628 -0
- package/src/web/infra/ready.js +461 -0
- package/src/web/infra/schedule.js +51 -0
- package/src/web/infra/shortcuts.js +129 -0
- package/src/web/infra/slot-registry.js +402 -0
- package/src/web/infra/vfs.js +247 -0
- package/src/web/live2d/bridge.js +400 -0
- package/src/web/live2d/model.js +321 -0
- package/src/web/live2d/overlay.js +142 -0
- package/src/web/live2d/pixi-app.js +111 -0
- package/src/web/live2d/playback-probe.js +92 -0
- package/src/web/live2d/probe-geometry.js +329 -0
- package/src/web/live2d/probe.js +119 -0
- package/src/web/live2d/release.js +66 -0
- package/src/web/live2d/runtime-adapter.js +289 -0
- package/src/web/live2d/stage-ctx.js +152 -0
- package/src/web/live2d/stage.js +204 -0
- package/src/web/live2d/vfs-settings.js +174 -0
- package/src/web/live2d/view.js +89 -0
- package/src/web/main.js +629 -0
- package/src/web/panel/background-list.js +373 -0
- package/src/web/panel/bg-source.js +291 -0
- package/src/web/panel/color-picker.css +199 -0
- package/src/web/panel/color-picker.js +278 -0
- package/src/web/panel/dialog.css +116 -0
- package/src/web/panel/dialog.js +173 -0
- package/src/web/panel/dom.js +35 -0
- package/src/web/panel/icons.js +58 -0
- package/src/web/panel/memory-bar.js +195 -0
- package/src/web/panel/panel-settings.js +1263 -0
- package/src/web/panel/panel.css +1304 -0
- package/src/web/panel/render-choice.js +104 -0
- package/src/web/panel/schema.js +784 -0
- package/src/web/panel/settings-io.js +291 -0
- package/src/web/panel/shell-controls.js +274 -0
- package/src/web/panel/slider.js +210 -0
- package/src/web/panel/toolbar-schema.js +111 -0
- package/src/web/panel/toolbar.js +195 -0
- package/src/web/panel/transport-picker.js +375 -0
- package/src/web/panel/transport.js +321 -0
- package/src/web/panel/view.js +553 -0
- package/src/web/plugin/unpack-worker.js +185 -0
- package/src/web/render/camera/constants.js +60 -0
- package/src/web/render/camera/index.js +123 -0
- package/src/web/render/camera/spine.js +124 -0
- package/src/web/render/capture.js +30 -0
- package/src/web/render/interaction.js +527 -0
- package/src/web/render/live2d.js +627 -0
- package/src/web/render/playback.js +47 -0
- package/src/web/render/reset-view.js +29 -0
- package/src/web/render/spine.js +386 -0
- package/src/web/render/surface-switch.js +176 -0
- package/src/web/render/surface.js +571 -0
- package/src/web/render/surfaces.js +70 -0
- package/src/web/roster/filter.js +31 -0
- package/src/web/roster/list.js +276 -0
- package/src/web/roster/persist.js +92 -0
- package/src/web/roster/reveal.js +77 -0
- package/src/web/roster/rows.js +248 -0
- package/src/web/roster/snapshot.js +39 -0
- package/src/web/roster/type-filter.js +97 -0
- package/src/web/roster/view.js +761 -0
- package/src/web/spine/canvas-api-groups.js +267 -0
- package/src/web/spine/canvas-api.js +97 -0
- package/src/web/spine/canvas-document.js +80 -0
- package/src/web/spine/canvas-engine.js +193 -0
- package/src/web/spine/canvas-entry.js +28 -0
- package/src/web/spine/canvas-pixels.js +36 -0
- package/src/web/spine/canvas-runtime.js +127 -0
- package/src/web/spine/canvas-view.js +108 -0
- package/src/web/spine/canvas.js +7 -0
- package/src/web/spine/runtime-hint.js +73 -0
- package/src/web/spine/runtimes.js +212 -0
- package/src/web/style.css +493 -0
- package/tool/lib/bundle-probe-node.mjs +121 -0
- package/tool/lib/paths.mjs +20 -0
- package/tool/lib/runtime-guides.mjs +65 -0
- package/tool/lib/runtime-package.mjs +403 -0
- package/tool/lib/spine-meta.mjs +227 -0
- package/tool/lib/spine-motions.mjs +104 -0
- package/tool/parse-jsonc.mjs +86 -0
- package/tool/resolve-live2d-runtimes.mjs +276 -0
- package/tool/spine-motion-rules.json +101 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
// 展示类型插件开关(JSONC,可写注释)。
|
|
3
|
+
// id 的取值:plugins/ 下的目录名,或平铺单 js 的文件名去扩展名(与 /api/plugins 列出的 id 一致)。
|
|
4
|
+
//
|
|
5
|
+
// 禁用一个插件的完整效果(缺省 = 全部启用):
|
|
6
|
+
// ① /api/plugins 不再列出它 → 前端插件宿主不注入它的 js → 能力整体消失;
|
|
7
|
+
// ② 它声明的 fileKinds(如 bundle 资源包)对应的条目**不再出现在角色库**——
|
|
8
|
+
// 条目本身是插件能力的一部分,插件没启用就不显示;
|
|
9
|
+
// ③ /api/tree 对这类资源根返回空文件列表,并在响应里带 note 说明原因(可探测,不静默)。
|
|
10
|
+
//
|
|
11
|
+
// 用途:排查「某能力是否影响了别的东西」时,用配置关掉它做排除法,不需要改文件名或代码。
|
|
12
|
+
"disabled": []
|
|
13
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// 本地资源根配置示例 —— 复制为 config/resources.json 后再改成你的路径
|
|
2
|
+
// 文件格式:JSONC(标准 JSON + // 注释);注释由 tool/parse-jsonc.mjs 剥离
|
|
3
|
+
//
|
|
4
|
+
// 必填字段:id(唯一标识,会出现在索引文件名 config/models/<类型>.<id>.json 里)
|
|
5
|
+
// path(本机的资源目录绝对路径)
|
|
6
|
+
// 可选字段:name(界面显示名,缺省用目录名)
|
|
7
|
+
// enabled(缺省 true;false = 停用但保留在配置里,随时可再启用)
|
|
8
|
+
// names(指向 config/names/<names>.json 的角色名表,用于显示角色名)
|
|
9
|
+
// icons(角色头像目录,可外置:{ "dir": "绝对路径" })
|
|
10
|
+
// 头像文件名记在名表的 characters[id].icon;名表没记时回退模型目录自带 icon.png
|
|
11
|
+
//
|
|
12
|
+
// 三点需要知道:
|
|
13
|
+
// · 不声明"这个根是什么类型":每个根都会被 Spine 与 Live2D 两个扫描器各扫一遍,
|
|
14
|
+
// 目录里有什么内容就进什么清单(config/models/ 下两份索引互不干扰,各自可重建)
|
|
15
|
+
// · 同级根用同一个 name 会被界面合并成一个游戏节点(同一角色的两种画风自动聚合)
|
|
16
|
+
// · 界面「选择目录」会重写本文件(只保留文件头部注释),手写内容会被一并覆盖
|
|
17
|
+
//
|
|
18
|
+
// 下面两个根只示范字段写法,值全是占位符:
|
|
19
|
+
// ① 把所有可选字段都填上(名表 + 外置头像 + 启用)
|
|
20
|
+
// ② 只写必填字段,并演示停用(enabled:false)
|
|
21
|
+
{
|
|
22
|
+
"roots": [
|
|
23
|
+
{
|
|
24
|
+
"id": "example_spine",
|
|
25
|
+
"name": "示例游戏 A",
|
|
26
|
+
"path": "/path/to/your/spine/assets",
|
|
27
|
+
"names": "example_a",
|
|
28
|
+
"icons": {
|
|
29
|
+
"dir": "/path/to/your/char_icons"
|
|
30
|
+
},
|
|
31
|
+
"enabled": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "example_live2d",
|
|
35
|
+
"name": "示例游戏 B",
|
|
36
|
+
"path": "/path/to/your/live2d/assets",
|
|
37
|
+
"enabled": false
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modelstage",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.28",
|
|
4
|
+
"description": "Spine / Live2D 模型查看器:三级名册、两套渲染面共享相机与面板、UnityFS 资源包解包",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"modelstage": "bin/modelstage.mjs"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=20"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"start": "node bin/modelstage.mjs",
|
|
14
|
+
"test": "node --test test/*.test.mjs",
|
|
15
|
+
"check:pack": "node tool/check-pack-boundary.mjs",
|
|
16
|
+
"prepublishOnly": "npm run check:pack && npm run test"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/",
|
|
20
|
+
"src/server/",
|
|
21
|
+
"src/shared/",
|
|
22
|
+
"src/web/",
|
|
23
|
+
"plugins/unity-live2d-bundle/",
|
|
24
|
+
"plugins/unity-spine-bundle/",
|
|
25
|
+
"tool/parse-jsonc.mjs",
|
|
26
|
+
"tool/resolve-live2d-runtimes.mjs",
|
|
27
|
+
"tool/lib/bundle-probe-node.mjs",
|
|
28
|
+
"tool/lib/paths.mjs",
|
|
29
|
+
"tool/lib/runtime-guides.mjs",
|
|
30
|
+
"tool/lib/runtime-package.mjs",
|
|
31
|
+
"tool/lib/spine-meta.mjs",
|
|
32
|
+
"tool/lib/spine-motions.mjs",
|
|
33
|
+
"tool/spine-motion-rules.json",
|
|
34
|
+
"config/plugins.json",
|
|
35
|
+
"config/models/",
|
|
36
|
+
"config/names/",
|
|
37
|
+
"config/resources.example.json",
|
|
38
|
+
"config/diag-upload.example.json",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"!**/.tmp-*",
|
|
42
|
+
"!**/*.bak",
|
|
43
|
+
"THIRD_PARTY_NOTICES.md"
|
|
44
|
+
],
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/EIGHTfs/ModelStage.git"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/EIGHTfs/ModelStage#readme",
|
|
51
|
+
"author": "EIGHTfs",
|
|
52
|
+
"keywords": [
|
|
53
|
+
"spine",
|
|
54
|
+
"live2d",
|
|
55
|
+
"unityfs",
|
|
56
|
+
"assetbundle",
|
|
57
|
+
"viewer",
|
|
58
|
+
"model-viewer",
|
|
59
|
+
"cubism",
|
|
60
|
+
"animation"
|
|
61
|
+
],
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/EIGHTfs/ModelStage/issues"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# unity-live2d-bundle
|
|
2
|
+
|
|
3
|
+
把 **UnityFS 容器**(Unity AssetBundle)里的 Live2D 资产还原成标准 Live2D 模型文件集,交给核心装进 VirtualFS 渲染。
|
|
4
|
+
|
|
5
|
+
- 角色:`provides: ["asset-provider"]`
|
|
6
|
+
- 接管条目:`fileKinds: ["bundle"]`(无扩展名的单文件资源包)
|
|
7
|
+
- 产物类型:`produces.kind: "live2d"`
|
|
8
|
+
|
|
9
|
+
## 目录结构
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
plugin.json 清单(provides / fileKinds / produces / assets / errorCodes)
|
|
13
|
+
index.js 入口:canHandle + resolve(注册到 window.SpineViewerPlugins)
|
|
14
|
+
lib/unityfs.js UnityFS 容器解析(头部字段、blocksInfo 两种布局、LZ4 块解压)
|
|
15
|
+
lib/bytes.js 字节读写工具
|
|
16
|
+
lib/serialized.js SerializedFile 解析
|
|
17
|
+
lib/typetree.js 类型树
|
|
18
|
+
lib/errors.js 错误码与 fail()
|
|
19
|
+
lib/common-strings.js
|
|
20
|
+
profiles/ 容器族规则(按容器类型命名,不绑定具体游戏)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 契约要点(照这些实现,不要自创)
|
|
24
|
+
|
|
25
|
+
**`canHandle(file)` 必须是纯判定**
|
|
26
|
+
- 只允许读 `file` 的字段(含 `file.bytes`)做容器魔数判定
|
|
27
|
+
- 禁止任何 I/O、禁止修改外部状态、禁止把异常抛给宿主
|
|
28
|
+
- 没有 `file.bytes` 时**返回 `true`**(保守放行)——判 `false` 会让无扩展名的包永远选不中
|
|
29
|
+
- 内部 try/catch 允许,但 catch 后 `return false` 时**必须记一条 debug 日志**(`host.log` 不可用时降级 `console.debug`)
|
|
30
|
+
|
|
31
|
+
**`resolve(file)` 成功只返回三键**
|
|
32
|
+
```js
|
|
33
|
+
{ prefix, files, entry }
|
|
34
|
+
```
|
|
35
|
+
- `prefix` 格式:`vfs://<providerId>/<rootId>/<相对目录>/`,全局唯一、恒以 `/` 结尾
|
|
36
|
+
- `files`:`relPath → Uint8Array | string`,`relPath` 用 `/` 分隔、允许子目录;`string` 按 UTF-8 读回(model3/motion3/physics3 用 JSON 文本)
|
|
37
|
+
- `entry`:包内**实际存在**的 `*.model3.json` 相对路径
|
|
38
|
+
- 不返回 `report` 之类的附加字段;诊断信息走 `host.log`
|
|
39
|
+
|
|
40
|
+
**取字节通道**:优先 `file.bytes`;缺失时用 `host.fetchFile(rootId, rel) → Promise<Uint8Array>`
|
|
41
|
+
(注意:直接返回 `Uint8Array`,不是 `{ bytes }`;`host` 不可用则抛 `ULB_ERR_NO_HOST`)
|
|
42
|
+
|
|
43
|
+
**没有 prepare / revoke 钩子**。渲染前要做的事(重建 model3、解纹理并编码 PNG、把 AnimationClip 转成 motion3)**全部在 `resolve()` 内完成**,`files` 就是最终产物;资源释放由核心按 `prefix` 调 `VirtualFS.revoke()`。
|
|
44
|
+
|
|
45
|
+
**失败一律抛带 `code` 的 Error**,码表见 `plugin.json` 的 `errorCodes`,核心按 `code` 决定提示文案。
|
|
46
|
+
|
|
47
|
+
## 容器解析支持范围
|
|
48
|
+
|
|
49
|
+
UnityFS 的 `blocksInfo` 有两种布局,**必须都支持**(这是踩过的坑):
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
(flags & 0x80) == 0 blocksInfo 内联在头部
|
|
53
|
+
数据起点 = blocksInfoStart + blocksInfoCompressedSize
|
|
54
|
+
(该段按"声明长度"占位,声明长度 > 表内容长度时差额是表尾对齐填充,必须跳过)
|
|
55
|
+
|
|
56
|
+
(flags & 0x80) != 0 blocksInfo 在文件尾
|
|
57
|
+
先存 position → 跳到 Length - compressedSize 读表 → seek 回保存值
|
|
58
|
+
回来后就是 header 结束、数据块开始的位置,**不能再加 compressedSize**
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> 真实事故:旧实现只写了第一种,对第二种的包也加了 `compressedSize`,把数据起点整体推后
|
|
62
|
+
> (`aijier_3`,Unity 2018.4 / version 6 / LZ4 / `dataflags 0xC2`,推后 101 字节)→ 数据块错位
|
|
63
|
+
> → LZ4 解出垃圾 → 报「LZ4 数据损坏:匹配位置越界」,**报错位置与真实根因相距极远**。
|
|
64
|
+
>
|
|
65
|
+
> 另一个坑:`ArchiveFlags` 里 `0x40` 名义上叫 `BlocksAndDirectoryInfoCombined`,但**实现的判断链里
|
|
66
|
+
> 从不读它**(正常包 `dataflags 0x240` 也带这一位)。拿它当"不支持该布局"的依据会把全部正常包一起拒掉。
|
|
67
|
+
|
|
68
|
+
**不要相信"解压成功"**:LZ4 块解压通常只校验"输出长度 == expectedSize",错位数据可能恰好自洽解出。
|
|
69
|
+
必须用结构自洽交叉验证(各段长度相加等于段起点、`bundleSize` 等于实际文件长度、node size 之和等于 block unc 之和等)。
|
|
70
|
+
|
|
71
|
+
## profile 机制
|
|
72
|
+
|
|
73
|
+
游戏/容器族的差异走 `profiles/<profile>.json`,**代码里不写死任何游戏名**:
|
|
74
|
+
|
|
75
|
+
- 资源根配置透传 `profile` 字段 → `resolve` 读到 `ctx.profile` → 自读 `profiles/<profile>.json`
|
|
76
|
+
- 缺 `profile` 或文件不存在 ⇒ 走默认规则,**不报错**
|
|
77
|
+
- profile 按**容器类型/容器族**命名,不要按单一游戏命名(会让"只支持某游戏"的错觉传下去)
|
|
78
|
+
|
|
79
|
+
## 自检
|
|
80
|
+
|
|
81
|
+
插件自身的判定/解析/产物形态由仓库统一检查工具覆盖(带契约条款号):
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
node tool/check-plugin.mjs plugins/unity-live2d-bundle
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
覆盖:清单与角色合法性、register 形态、`canHandle` 同步布尔、`resolve` 错误码、PL1–PL8 契约条目。
|
|
88
|
+
|
|
89
|
+
## 边界
|
|
90
|
+
|
|
91
|
+
- 不读 `src/web/engine`、不假设渲染层细节;产物只按契约三键交付
|
|
92
|
+
- 不做 Blob URL 装载、不安装运行时适配器(那些属于旧宿主通道,已删除)
|
|
93
|
+
- 不设单包体积上限(峰值由核心 `revoke` 控住)
|
|
94
|
+
|
|
95
|
+
## 只保留一套契约
|
|
96
|
+
|
|
97
|
+
插件只实现 `canHandle` / `resolve` 两个入口(`probe` / `open` / `produces.legacyEntry` 已移除)。
|
|
98
|
+
宿主按这套契约调用,不再保留任何兼容层。
|