modelstage 0.6.1 → 0.11.1
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/CHANGELOG.md +12 -0
- package/THIRD_PARTY_NOTICES.md +20 -0
- package/config/models/live2d.assetbundls.json +1 -1
- package/config/models/live2d.azurlane_bundle.json +1 -1
- package/config/models/live2d.bd2_mod.json +1 -0
- package/config/models/live2d.bluearchive.json +1 -1
- package/config/models/live2d.root.json +1 -0
- package/config/models/live2d.sample_haru.json +1 -0
- package/config/models/spine.assetbundls.json +1 -1
- package/config/models/spine.azurlane_bundle.json +1 -1
- package/config/models/spine.bd2_mod.json +1 -0
- package/config/models/spine.bluearchive.json +1 -1
- package/config/models/spine.root.json +1 -0
- package/config/models/spine.sample_haru.json +1 -0
- package/package.json +2 -2
- package/plugins/unity-live2d-bundle/index.js +105 -5
- package/plugins/unity-live2d-bundle/lib/astc.js +1307 -0
- package/plugins/unity-live2d-bundle/lib/bundle-probe.js +79 -0
- package/plugins/unity-live2d-bundle/lib/texdecode.js +60 -15
- package/plugins/unity-live2d-bundle/plugin.json +3 -1
- package/plugins/unity-spine-bundle/index.js +187 -15
- package/plugins/unity-spine-bundle/lib/astc.js +1307 -0
- package/plugins/unity-spine-bundle/lib/bundle-probe.js +323 -0
- package/plugins/unity-spine-bundle/lib/texdecode.js +60 -15
- package/plugins/unity-spine-bundle/plugin.json +4 -1
- package/src/server/analyze/index.mjs +470 -0
- package/src/server/data/catalog.mjs +30 -2
- package/src/server/data/display-name-cache.mjs +142 -0
- package/src/server/data/entry-states.mjs +21 -0
- package/src/server/http/write.mjs +7 -6
- package/src/server/index.mjs +1 -1
- package/src/server/plugins/registry.mjs +2 -2
- package/src/server/routes/display-name.mjs +157 -0
- package/src/server/serve.mjs +8 -0
- package/src/server/unpack/runtime/exec.mjs +19 -1
- package/src/web/infra/plugin-host-unpack.mjs +13 -3
- package/src/web/infra/plugin-host.js +3 -0
- package/src/web/render/surface.js +49 -2
- package/src/web/roster/display-name.js +79 -0
- package/src/web/roster/events.js +40 -1
- package/src/web/roster/list.js +8 -2
- package/src/web/roster/store.js +48 -0
- package/tool/lib/bundle-probe-node.mjs +146 -32
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"rootId":"root","ts":1794875058835,"count":0,"generator":"793f6b2e","dirStamps":{"root":1794874579076,"dirs":{"chararts":1794874587422,"dynchars":1794874587422,"skinpack":1794874586435}},"models":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"rootId":"sample_haru","ts":1794132142456,"count":0,"generator":"793f6b2e","dirStamps":{"root":1794131352857,"dirs":{"Haru.2048":1794131352603,"expressions":1794131352706,"motions":1794131352853,"sounds":1794131352877}},"models":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modelstage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Spine / Live2D 模型查看器:三级名册、两套渲染面共享相机与面板、UnityFS 资源包解包",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"start": "node bin/modelstage.mjs",
|
|
14
14
|
"test": "node --test test/*.test.mjs",
|
|
15
15
|
"check:pack": "node tool/check-pack-boundary.mjs",
|
|
16
|
-
"prepublishOnly": "npm run check:pack
|
|
16
|
+
"prepublishOnly": "npm run check:pack"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"bin/",
|
|
@@ -416,7 +416,23 @@ function createContainerTools({ NS, host, ulbLog, MIME_OCTET, MIME_JSON, MIME_PN
|
|
|
416
416
|
*/
|
|
417
417
|
async function buildFileSet(extracted, profile) {
|
|
418
418
|
const files = new Map(); // 相对键 → Blob(契约 §1.2:Blob|string;二进制一律 Blob)
|
|
419
|
-
|
|
419
|
+
|
|
420
|
+
// 已写入键的**原始字节**,只用于同名冲突判定(多数包无同名,所以这条路径基本不触发)。
|
|
421
|
+
const written = new Map();
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 写入文件表;**同名不再静默覆盖**。
|
|
425
|
+
*
|
|
426
|
+
* 为什么不照 spine 那样加 pathID 改名:spine 的 entry.json 是插件自己生成的,名字随便定;
|
|
427
|
+
* Cubism 的 model3.json 是**包内原有文件**,它的 FileReferences 写的是原始文件名 ——
|
|
428
|
+
* 插件改了名,模型就找不到纹理/moc3,除非同时重写 model3.json(那是更大的改动,
|
|
429
|
+
* 且会改变包内文件的原始语义)。所以这里只能"判断是不是同一份",不能"改名区分"。
|
|
430
|
+
*
|
|
431
|
+
* 同名 + 字节相同 ⇒ 合并(同内容重复出现是合法的,不报错);
|
|
432
|
+
* 同名 + 字节不同 ⇒ 抛可读错误(需要人工确认用哪份,而不是让后写的悄悄赢)。
|
|
433
|
+
*/
|
|
434
|
+
// 委托给模块级实现(判据只有一份,且可被单测直接验证)
|
|
435
|
+
const put = (key, bytes, mime) => putFile(files, written, key, bytes, mime, NS);
|
|
420
436
|
|
|
421
437
|
const KEY_MOC3 = 'moc3.moc3';
|
|
422
438
|
const KEY_PHYSICS = 'physics3.json';
|
|
@@ -609,7 +625,7 @@ function createProvider({ NS, host, PLUGIN_ID, ulbLog, MIME_OCTET, MIME_JSON, MI
|
|
|
609
625
|
// 这些相对路径与包内文件同根,核心注册 prefix 后可直接解析。
|
|
610
626
|
const textures = collectTextures(got, resSBytes);
|
|
611
627
|
for (const f of got.nativeFiles) {
|
|
612
|
-
|
|
628
|
+
put(f.name, f.bytes, /\.json$/i.test(f.name) ? MIME_JSON : MIME_OCTET);
|
|
613
629
|
if (/\.model3\.json$/i.test(f.name)) entry = f.name;
|
|
614
630
|
}
|
|
615
631
|
// 原生 Cubism 文件集:包内可能自带 .png/.moc3 等原始文件(TextAsset 形态),直接进表;
|
|
@@ -618,7 +634,7 @@ function createProvider({ NS, host, PLUGIN_ID, ulbLog, MIME_OCTET, MIME_JSON, MI
|
|
|
618
634
|
let hasPngTexture = false;
|
|
619
635
|
for (const f of got.nativeFiles) {
|
|
620
636
|
if (/\.png$/i.test(f.name)) {
|
|
621
|
-
|
|
637
|
+
put(f.name, f.bytes, MIME_PNG);
|
|
622
638
|
hasPngTexture = true;
|
|
623
639
|
}
|
|
624
640
|
}
|
|
@@ -627,7 +643,7 @@ function createProvider({ NS, host, PLUGIN_ID, ulbLog, MIME_OCTET, MIME_JSON, MI
|
|
|
627
643
|
if (!t.comp) continue;
|
|
628
644
|
const rgba = NS.texdecode.decode(t, t.comp); // 局部变量,编完即释放
|
|
629
645
|
const png = await NS.png.encodePngAsync(rgba, t.width, t.height);
|
|
630
|
-
|
|
646
|
+
put(`${t.name}.png`, png, MIME_PNG);
|
|
631
647
|
}
|
|
632
648
|
}
|
|
633
649
|
if (!entry) throw NS.errors.fail('ULB_ERR_MODEL_BUILD', '原生文件集里找不到 model3.json 入口');
|
|
@@ -799,7 +815,7 @@ function createMemoryEstimator({ NS }) {
|
|
|
799
815
|
|
|
800
816
|
/** 浏览器侧:把本插件登记进宿主的资产提供者注册表(node 侧 host 为 null,整块跳过)。 */
|
|
801
817
|
function registerWithHost({ host, PLUGIN_ID, api }) {
|
|
802
|
-
const { canHandle, resolve, estimateMemory, explainReject } = api;
|
|
818
|
+
const { canHandle, resolve, estimateMemory, explainReject, analyze } = api;
|
|
803
819
|
|
|
804
820
|
// 契约 §一:plugin.json 的 provides=["asset-provider"] 让宿主把本插件登记进资产提供者注册表。
|
|
805
821
|
// 注册对象上 kind 是产出内容类型(live2d),与 fileKinds 的容器类型 bundle 正交;
|
|
@@ -814,6 +830,9 @@ function registerWithHost({ host, PLUGIN_ID, api }) {
|
|
|
814
830
|
resolve,
|
|
815
831
|
// 可选扩展:宿主在 not-handled 时用它拿到"为什么不认领"(浏览器侧与 node 侧同一份实现)
|
|
816
832
|
explainReject,
|
|
833
|
+
// 契约 §1.1 bundle-analyzer:只读分析容器字节流(不产模型、不写文件)。
|
|
834
|
+
// 核心按 plugin.json 的 provides 找提供者,不认插件名。
|
|
835
|
+
analyze,
|
|
817
836
|
// 契约 §2.2:让宿主与检查器都能发现"本插件能自己算内存代价"(估得准不准由本插件负责)
|
|
818
837
|
estimateMemory,
|
|
819
838
|
kind: 'live2d',
|
|
@@ -841,6 +860,46 @@ function install() {
|
|
|
841
860
|
// lib 挂载点:各 lib 文件自己往 globalThis.__ULB__ 挂能力,浏览器里 window 即 globalThis,
|
|
842
861
|
// 所以统一从 globalThis 取即可(node 侧同样落在 globalThis)。
|
|
843
862
|
const NS = (typeof globalThis !== 'undefined' && globalThis.__ULB__) || null;
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* 逐字节比较(只在同名时调用,正常包零开销)。
|
|
866
|
+
* 提到模块级是为了可单测 —— 这条判据是"防静默覆盖"的核心,不能被闭包埋掉。
|
|
867
|
+
*/
|
|
868
|
+
function sameBytes(a, b) {
|
|
869
|
+
if (a === b) return true;
|
|
870
|
+
if (!a || !b || a.length !== b.length) return false;
|
|
871
|
+
for (let i = 0; i < a.length; i += 1) if (a[i] !== b[i]) return false;
|
|
872
|
+
return true;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* 写入文件表;**同名不再静默覆盖**(与 spine 的 pathID 改名是两种不同修法)。
|
|
877
|
+
*
|
|
878
|
+
* 为什么不照 spine 那样加 pathID:spine 的 entry.json 是插件自己生成的,名字随便定;
|
|
879
|
+
* Cubism 的 model3.json 是**包内原有文件**,它的 FileReferences 写的是原始文件名 ——
|
|
880
|
+
* 插件改了名,模型就找不到纹理/moc3,除非同时重写 model3.json(那是更大的改动,
|
|
881
|
+
* 且会改变包内文件的原始语义)。所以这里只能"判断是不是同一份",不能"改名区分"。
|
|
882
|
+
*
|
|
883
|
+
* 同名 + 字节相同 ⇒ 合并(同内容重复出现合法,不报错)
|
|
884
|
+
* 同名 + 字节不同 ⇒ 抛可读错误(而不是让后写的悄悄赢 —— 那样只表现为"纹理缺失/渲染错乱",
|
|
885
|
+
* 日志看不出原因,正是要多轮才能定位的那类静默失败)
|
|
886
|
+
*/
|
|
887
|
+
function putFile(files, written, key, bytes, mime, ns) {
|
|
888
|
+
const prev = written.get(key);
|
|
889
|
+
if (prev) {
|
|
890
|
+
if (!sameBytes(prev, bytes)) {
|
|
891
|
+
throw ns.errors.fail('ULB_ERR_MODEL_BUILD',
|
|
892
|
+
`包内存在同名资源 ${key} 且内容不同(Cubism 按 model3.json 的原始文件名引用,插件无法改名区分)——当前不支持,需要人工确认用哪一份`);
|
|
893
|
+
}
|
|
894
|
+
return key; // 同内容重复写入:无害,保留已写的那份
|
|
895
|
+
}
|
|
896
|
+
written.set(key, bytes);
|
|
897
|
+
files.set(key, new Blob([bytes], { type: mime || MIME_OCTET }));
|
|
898
|
+
return key;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
if (NS) NS.live2dFiles = { sameBytes, putFile }; // live2d 前缀,避免污染共享命名空间
|
|
902
|
+
|
|
844
903
|
if (!NS || !NS.unityfs || !NS.serialized || !NS.extract) {
|
|
845
904
|
if (hasDom) {
|
|
846
905
|
console.warn('[unity-live2d-bundle] lib 未加载完整(需要 bytes/common-strings/unityfs/serialized/typetree/extract),插件未注册');
|
|
@@ -863,6 +922,43 @@ function install() {
|
|
|
863
922
|
const provider = createProvider({ NS, host, PLUGIN_ID, ulbLog, MIME_OCTET, MIME_JSON, MIME_PNG, loadProfile, container, coreMeta });
|
|
864
923
|
const mem = createMemoryEstimator({ NS });
|
|
865
924
|
|
|
925
|
+
// 契约 §1.1 bundle-analyzer:只读分析容器字节流。
|
|
926
|
+
// 实现直接复用 lib/bundle-probe.js(不重写解析),这里只做"事实 → 契约字段"的映射。
|
|
927
|
+
// verdict(model / asset-dependency)不在这里算:那是核心的判据(src/shared/bundle-shape.mjs),
|
|
928
|
+
// 插件只提供事实,判据只留一份。
|
|
929
|
+
function analyze(bytes) {
|
|
930
|
+
const bp = NS && NS.bundleProbe;
|
|
931
|
+
if (!bp || typeof bp.run !== 'function') {
|
|
932
|
+
return {
|
|
933
|
+
container: null,
|
|
934
|
+
objects: null,
|
|
935
|
+
textures: null,
|
|
936
|
+
warnings: ['插件内缺少 bundle-probe 实现(lib/bundle-probe.js 未加载)'],
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
const res = bp.run(bytes) || {};
|
|
940
|
+
return {
|
|
941
|
+
// 契约字段
|
|
942
|
+
container: res.container || null,
|
|
943
|
+
objects: typeof res.objects === 'number' ? res.objects : null,
|
|
944
|
+
textures: Array.isArray(res.textures) ? res.textures : null,
|
|
945
|
+
// 契约 §1.1 的 textAssets:名字 / 类型 / 骨架版本 / 字节数,由 lib/bundle-probe.js 从对象表取出
|
|
946
|
+
textAssets: Array.isArray(res.textAssets) ? res.textAssets : null,
|
|
947
|
+
warnings: Array.isArray(res.warnings) ? res.warnings : [],
|
|
948
|
+
// 透传既有字段:/api/bundle/probe 与页面预检此前就在用它们,
|
|
949
|
+
// 新增 analyze 不能把它们丢掉,否则行为会变。
|
|
950
|
+
ok: res.ok,
|
|
951
|
+
code: res.code,
|
|
952
|
+
error: res.error,
|
|
953
|
+
moc3: res.moc3 || null,
|
|
954
|
+
cubism2Moc: res.cubism2Moc || null,
|
|
955
|
+
physics3: res.physics3 || null,
|
|
956
|
+
motions: res.motions,
|
|
957
|
+
reject: res.reject || null,
|
|
958
|
+
nativeFiles: res.nativeFiles,
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
|
|
866
962
|
// 键顺序与原 return 字面量完全一致
|
|
867
963
|
const api = {
|
|
868
964
|
canHandle: provider.canHandle,
|
|
@@ -871,7 +967,11 @@ function install() {
|
|
|
871
967
|
explainReject: provider.explainReject,
|
|
872
968
|
estimateMemory: mem.estimateMemory,
|
|
873
969
|
peakFromDecompressed: mem.peakFromDecompressed,
|
|
970
|
+
// 契约 §1.1:只读分析能力(核心按 provides 找提供者)
|
|
971
|
+
analyze,
|
|
874
972
|
PLUGIN_ID,
|
|
973
|
+
// 单测钩子:"同名不覆盖"的判据是这几轮最贵的教训,必须能被直接验证
|
|
974
|
+
__test: { sameBytes, putFile },
|
|
875
975
|
};
|
|
876
976
|
registerWithHost({ host, PLUGIN_ID, api });
|
|
877
977
|
return api;
|