modelstage 0.10.1 → 0.11.2
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 +5 -1
- package/THIRD_PARTY_NOTICES.md +20 -0
- package/config/models/live2d.root.json +1 -0
- package/config/models/spine.root.json +1 -0
- package/package.json +1 -1
- package/plugins/unity-live2d-bundle/index.js +76 -4
- package/plugins/unity-live2d-bundle/lib/astc.js +1315 -0
- package/plugins/unity-live2d-bundle/lib/texdecode.js +60 -15
- package/plugins/unity-live2d-bundle/plugin.json +1 -0
- package/plugins/unity-spine-bundle/index.js +192 -16
- package/plugins/unity-spine-bundle/lib/astc.js +1315 -0
- package/plugins/unity-spine-bundle/lib/extract.js +69 -0
- package/plugins/unity-spine-bundle/lib/texdecode.js +60 -15
- package/plugins/unity-spine-bundle/plugin.json +1 -0
- package/src/server/unpack/plugin-runner.mjs +39 -5
- package/src/server/unpack/runtime/exec.mjs +19 -1
- package/src/web/infra/plugin-host-unpack.mjs +29 -4
- package/src/web/main.js +42 -2
- package/src/web/render/camera/constants.js +41 -3
- package/src/web/render/demo-3d.js +131 -0
- package/src/web/render/interaction.js +129 -12
- package/src/web/render/surfaces.js +4 -0
|
@@ -49,33 +49,94 @@ function midpoint(a, b) {
|
|
|
49
49
|
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* 相机语义取值:来自渲染器声明的 `capabilities.camera`。
|
|
54
|
+
* 取值集合与契约文档一致,未知值一律按 2D 处理。
|
|
55
|
+
*/
|
|
56
|
+
export const CAMERA_SEMANTICS = Object.freeze({
|
|
57
|
+
ORTHO_2D: 'ortho-2d',
|
|
58
|
+
ORBIT_3D: 'orbit-3d',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 读舞台门面声明的相机语义。
|
|
63
|
+
*
|
|
64
|
+
* 为什么在这里归一而不是让调用方各自判断:门面上的取值直接来自渲染器声明的能力,
|
|
65
|
+
* 旧渲染面/旧门面可能压根没有这个字段,未来也可能出现新语义。把"缺失/未知 ⇒ 2D"
|
|
66
|
+
* 这条兜底钉在一个函数里,2D 面的既有行为才不会因为字段缺省而改变。
|
|
67
|
+
* 也支持传函数(门面动态取当前激活面的能力,切面后无需重建桥)。
|
|
68
|
+
*
|
|
69
|
+
* @param {object} stage
|
|
70
|
+
* @returns {'ortho-2d'|'orbit-3d'}
|
|
71
|
+
*/
|
|
72
|
+
export function readCameraSemantics(stage) {
|
|
73
|
+
const raw = stage && stage.cameraCapability;
|
|
74
|
+
let value = raw;
|
|
75
|
+
if (typeof raw === 'function') {
|
|
76
|
+
try { value = raw(); } catch { value = null; }
|
|
77
|
+
}
|
|
78
|
+
return value === CAMERA_SEMANTICS.ORBIT_3D ? CAMERA_SEMANTICS.ORBIT_3D : CAMERA_SEMANTICS.ORTHO_2D;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 相机是否真的支持轨道转动。
|
|
83
|
+
*
|
|
84
|
+
* 先问 `hasOrbit()`:门面是固定形状的代理,键总是存在(转发不存在的实现会返回 null),
|
|
85
|
+
* 只看键会让 2D 面被误判成 3D 面。真实相机没有探针时退回看方法本身。
|
|
86
|
+
* @param {object} camera
|
|
87
|
+
* @returns {boolean}
|
|
88
|
+
*/
|
|
89
|
+
function supportsOrbit(camera) {
|
|
90
|
+
if (camera && typeof camera.hasOrbit === 'function') {
|
|
91
|
+
try { return camera.hasOrbit() === true; } catch { return false; }
|
|
92
|
+
}
|
|
93
|
+
return !!(camera && typeof camera.orbitBy === 'function');
|
|
94
|
+
}
|
|
95
|
+
|
|
52
96
|
/**
|
|
53
97
|
* 相机桥:把交互动作落到 stage.camera(薄转发),缺失时退到 stage 的兼容入口。
|
|
98
|
+
*
|
|
99
|
+
* 为什么要按语义分策略:契约早已把 `capabilities.camera` 声明出来,但此前没人消费,
|
|
100
|
+
* 于是"拖动 = 平移"被写死在桥里,3D 面即使声明了 orbit 也只会平移。
|
|
101
|
+
* 这里把两种语义做成策略对象,桥只按当前面的声明选一个。
|
|
102
|
+
*
|
|
103
|
+
* **2D 策略的五个方法逐字保留改造前的实现**:滚轮一档 ±10%、拖动跟手、捏合中点平移、
|
|
104
|
+
* 复位重新 fit 全部依赖这条路径,任何"顺手优化"都会变成手感回归。
|
|
105
|
+
*
|
|
54
106
|
* @param {object} stage
|
|
107
|
+
* @param {{log?: (message: string, level?: 'info'|'warn') => void}} [options] 日志出口(缺省退到控制台)
|
|
55
108
|
*/
|
|
56
|
-
function createCameraBridge(stage) {
|
|
109
|
+
export function createCameraBridge(stage, options = {}) {
|
|
57
110
|
const camera = stage && stage.camera;
|
|
58
|
-
|
|
59
|
-
|
|
111
|
+
const outerLog = typeof options.log === 'function' ? options.log : null;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 日志:优先外部出口(应用侧的状态栏),其次相机自己的 note,最后控制台。
|
|
115
|
+
*
|
|
116
|
+
* 为什么要有控制台兜底:相机的 note 在没有挂 logger 时是静默的,
|
|
117
|
+
* "这台相机不支持轨道转动"这类信息一旦静默,用户只看到"拖不动",排查只能靠猜。
|
|
118
|
+
*/
|
|
60
119
|
function note(message, data) {
|
|
120
|
+
if (outerLog) {
|
|
121
|
+
try { outerLog(message, data && data.level ? data.level : 'warn'); return; } catch { /* 落到下一档 */ }
|
|
122
|
+
}
|
|
61
123
|
if (camera && typeof camera.note === 'function') {
|
|
62
|
-
try { camera.note(message, data); } catch { /*
|
|
124
|
+
try { camera.note(message, data); return; } catch { /* 落到下一档 */ }
|
|
63
125
|
}
|
|
126
|
+
try { console.warn(`[camera] ${message}`, data || ''); } catch { /* 日志失败不影响交互 */ }
|
|
64
127
|
}
|
|
65
128
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
129
|
+
/** 2D:拖动即平移,缩放作用在 userScale 上(改造前行为,禁止改动) */
|
|
130
|
+
const orthoStrategy = {
|
|
131
|
+
semantics: CAMERA_SEMANTICS.ORTHO_2D,
|
|
69
132
|
zoomStep(dir) {
|
|
70
133
|
if (camera && typeof camera.zoomStep === 'function') return camera.zoomStep(dir);
|
|
71
134
|
return null;
|
|
72
135
|
},
|
|
73
|
-
/** 缩放到绝对 userScale(捏合:起始 userScale × 距离比) */
|
|
74
136
|
zoomTo(scale) {
|
|
75
137
|
if (camera && typeof camera.zoomTo === 'function') return camera.zoomTo(scale);
|
|
76
138
|
return null;
|
|
77
139
|
},
|
|
78
|
-
/** 平移:原始屏幕像素差值 */
|
|
79
140
|
panBy(dx, dy) {
|
|
80
141
|
if (camera && typeof camera.panBy === 'function') return camera.panBy(dx, dy);
|
|
81
142
|
// 回退:仅有 setView 的旧契约,本地累计后按绝对量下发(不做任何换算)
|
|
@@ -85,18 +146,71 @@ function createCameraBridge(stage) {
|
|
|
85
146
|
}
|
|
86
147
|
return null;
|
|
87
148
|
},
|
|
88
|
-
/** 复位:交给引擎 resetCamera(重新 fit) */
|
|
89
149
|
reset() {
|
|
90
150
|
if (camera && typeof camera.reset === 'function') return camera.reset();
|
|
91
151
|
if (typeof stage.resetView === 'function') return stage.resetView();
|
|
92
152
|
return null;
|
|
93
153
|
},
|
|
94
|
-
/** 当前 userScale(捏合起点用);拿不到时返回 null */
|
|
95
154
|
scale() {
|
|
96
155
|
if (camera && typeof camera.scale === 'function') return camera.scale();
|
|
97
156
|
return null;
|
|
98
157
|
},
|
|
99
158
|
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 3D:拖动 = 绕轨道转,其余(缩放/复位/读值)仍走统一相机。
|
|
162
|
+
*
|
|
163
|
+
* 相机没有 orbitBy 时不把它近似成 panBy:那样界面看起来"能拖",但视角其实没转,
|
|
164
|
+
* 是最难发现的静默降级。这里只记一条日志并忽略,把"能力缺失"暴露出来。
|
|
165
|
+
*/
|
|
166
|
+
const orbitStrategy = {
|
|
167
|
+
semantics: CAMERA_SEMANTICS.ORBIT_3D,
|
|
168
|
+
zoomStep(dir) {
|
|
169
|
+
if (camera && typeof camera.zoomStep === 'function') return camera.zoomStep(dir);
|
|
170
|
+
return null;
|
|
171
|
+
},
|
|
172
|
+
zoomTo(scale) {
|
|
173
|
+
if (camera && typeof camera.zoomTo === 'function') return camera.zoomTo(scale);
|
|
174
|
+
return null;
|
|
175
|
+
},
|
|
176
|
+
panBy(dx, dy) {
|
|
177
|
+
if (supportsOrbit(camera)) {
|
|
178
|
+
try { return camera.orbitBy(dx, dy); } catch (err) { note(`orbitBy 失败:${err && err.message}`); return null; }
|
|
179
|
+
}
|
|
180
|
+
note('orbit-3d:相机未提供 orbitBy,本次拖动已忽略', { dx, dy });
|
|
181
|
+
return null;
|
|
182
|
+
},
|
|
183
|
+
reset() {
|
|
184
|
+
if (camera && typeof camera.reset === 'function') return camera.reset();
|
|
185
|
+
if (typeof stage.resetView === 'function') return stage.resetView();
|
|
186
|
+
return null;
|
|
187
|
+
},
|
|
188
|
+
scale() {
|
|
189
|
+
if (camera && typeof camera.scale === 'function') return camera.scale();
|
|
190
|
+
return null;
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/** 每次调用现取语义:切面后同一座桥自动切策略,不需要重建(重建会丢进行中的手势) */
|
|
195
|
+
function strategy() {
|
|
196
|
+
return readCameraSemantics(stage) === CAMERA_SEMANTICS.ORBIT_3D ? orbitStrategy : orthoStrategy;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
note,
|
|
201
|
+
/** 当前生效的相机语义(验收与排查读它) */
|
|
202
|
+
get semantics() { return readCameraSemantics(stage); },
|
|
203
|
+
/** 缩放一档(dir=±1,由引擎处理 ±10% 与 clamp) */
|
|
204
|
+
zoomStep(dir) { return strategy().zoomStep(dir); },
|
|
205
|
+
/** 缩放到绝对 userScale(捏合:起始 userScale × 距离比) */
|
|
206
|
+
zoomTo(scale) { return strategy().zoomTo(scale); },
|
|
207
|
+
/** 平移(2D)/ 绕轨道转(3D):原始屏幕像素差值 */
|
|
208
|
+
panBy(dx, dy) { return strategy().panBy(dx, dy); },
|
|
209
|
+
/** 复位:交给引擎 resetCamera(重新 fit) */
|
|
210
|
+
reset() { return strategy().reset(); },
|
|
211
|
+
/** 当前 userScale(捏合起点用);拿不到时返回 null */
|
|
212
|
+
scale() { return strategy().scale(); },
|
|
213
|
+
};
|
|
100
214
|
}
|
|
101
215
|
|
|
102
216
|
/**
|
|
@@ -468,7 +582,7 @@ export function attachStageInteraction({ canvas, stage, options } = {}) {
|
|
|
468
582
|
throw new Error('attachStageInteraction: 需要提供 camera 入口或 getView/setView 的 stage');
|
|
469
583
|
}
|
|
470
584
|
|
|
471
|
-
const camera = createCameraBridge(stage);
|
|
585
|
+
const camera = createCameraBridge(stage, { log: (options && options.log) || null });
|
|
472
586
|
const ctx = {
|
|
473
587
|
canvas,
|
|
474
588
|
camera,
|
|
@@ -486,6 +600,8 @@ export function attachStageInteraction({ canvas, stage, options } = {}) {
|
|
|
486
600
|
window.__WEB__.zoomStats = () => zoomScheduler.stats();
|
|
487
601
|
// 最近一次手势的汇总(含真实 calls);stats 每轮手势后清零,验收读这个更稳
|
|
488
602
|
window.__WEB__.zoomLast = () => zoomReporter.last();
|
|
603
|
+
// 当前生效的相机语义('ortho-2d' / 'orbit-3d'):验收与排查时不靠猜,直接读
|
|
604
|
+
window.__WEB__.cameraSemantics = () => camera.semantics;
|
|
489
605
|
}
|
|
490
606
|
const zoomReporter = createZoomReporter(ctx, zoomScheduler);
|
|
491
607
|
const handler = createPointerHandler(ctx, panScheduler, zoomScheduler, zoomReporter);
|
|
@@ -511,6 +627,7 @@ export function attachStageInteraction({ canvas, stage, options } = {}) {
|
|
|
511
627
|
if (typeof window !== 'undefined' && window.__WEB__) {
|
|
512
628
|
delete window.__WEB__.zoomStats;
|
|
513
629
|
delete window.__WEB__.zoomLast;
|
|
630
|
+
delete window.__WEB__.cameraSemantics;
|
|
514
631
|
}
|
|
515
632
|
canvas.removeEventListener('pointerdown', handler.onDown);
|
|
516
633
|
canvas.removeEventListener('pointermove', handler.onMove);
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
export const SURFACES = [
|
|
26
26
|
{ id: 'spine', kind: 'spine', label: 'Spine', badge: 'spine', stageMode: 'spine', overlay: null, overlayVisible: false, cameraKind: 'spine', deepLink: true },
|
|
27
27
|
{ id: 'live2d', kind: 'live2d', label: 'Live2D', badge: 'live2d', stageMode: 'live2d', overlay: 'canvas', overlayVisible: true, cameraKind: 'live2d', deepLink: true },
|
|
28
|
+
// 三维预留面:用来证明"新面能注册、相机语义能派发",本身不含任何 3D 渲染。
|
|
29
|
+
// 默认不使用(没有内容类型会产出 kind=three),deepLink=false 表示不接受 ?model= 深链,
|
|
30
|
+
// 避免它被当成"可以用深链打开的面"而让用户撞到空实现。
|
|
31
|
+
{ id: 'three', kind: 'three', label: '三维(预留)', badge: 'three', stageMode: 'three', overlay: null, overlayVisible: false, cameraKind: 'orbit-3d', deepLink: false },
|
|
28
32
|
];
|
|
29
33
|
|
|
30
34
|
/** 按 kind 查(未知 → null) */
|