@rig-c/review 2.11.0 → 2.13.0
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/docs/DESIGN.md +145 -74
- package/docs/PANELS.md +20 -12
- package/docs/PARTS_VIEW.md +31 -11
- package/docs/REVIEW_PACKAGE.md +215 -0
- package/docs/STABILITY.md +98 -2
- package/docs/WORKFLOWS.md +40 -12
- package/package.json +2 -1
- package/skills/rig-review/SKILL.md +29 -1
- package/src/build.ts +10 -2
- package/src/cli.ts +14 -12
- package/src/comment-crops.ts +6 -1
- package/src/compare-html.ts +22 -24
- package/src/compare-server.ts +1 -1
- package/src/compare-session.ts +41 -3
- package/src/create-pin-gate.ts +3 -0
- package/src/feedback-export.ts +67 -0
- package/src/front.ts +10 -16
- package/src/interview-routes.ts +1 -1
- package/src/job-act.ts +39 -21
- package/src/job-api.ts +291 -0
- package/src/job-cli.ts +20 -11
- package/src/job-contract.ts +91 -3
- package/src/job-front.ts +15 -7
- package/src/job-host.ts +15 -0
- package/src/job-hub.ts +4 -4
- package/src/job-image-set.ts +32 -9
- package/src/job-session.ts +19 -11
- package/src/job-source.ts +74 -30
- package/src/joined-project.ts +61 -4
- package/src/open-workspace.ts +12 -12
- package/src/open.ts +17 -9
- package/src/parts-comment.ts +31 -1
- package/src/parts-server.ts +19 -7
- package/src/parts-view.ts +103 -20
- package/src/server.ts +30 -21
- package/src/session.ts +58 -0
- package/src/stage-comment.ts +39 -0
- package/src/stage-parts.ts +18 -10
- package/web/animation-inspection.ts +1 -1
- package/web/bones-panel.ts +1 -3
- package/web/catalog-en.ts +76 -12
- package/web/catalog-ko.ts +76 -12
- package/web/cloth-panel.ts +1 -2
- package/web/compare.css +3 -9
- package/web/compare.html +3 -3
- package/web/compare.ts +69 -64
- package/web/cuts-panel.ts +1 -3
- package/web/density-strip-panel.ts +1 -2
- package/web/i18n.ts +13 -1
- package/web/idle-panel.ts +1 -2
- package/web/index.html +1 -5
- package/web/inspection-persistence.ts +2 -1
- package/web/inspector-blocks.ts +144 -39
- package/web/instance-access.ts +24 -5
- package/web/interview-panel.ts +224 -175
- package/web/job-hub.ts +50 -69
- package/web/job-rig-capture.ts +103 -10
- package/web/job-rig-screen.ts +317 -0
- package/web/job-session.ts +927 -1365
- package/web/main.ts +535 -129
- package/web/mesh-panel.ts +1 -2
- package/web/owner-workspace.ts +88 -109
- package/web/part-selection.ts +47 -6
- package/web/part-thumbnails.ts +20 -6
- package/web/parts-viewport-provider.ts +166 -9
- package/web/physics-panel.ts +1 -2
- package/web/readings-panel.ts +1 -2
- package/web/requirements-panel.ts +1 -3
- package/web/retained-frame-stage.ts +105 -0
- package/web/retarget-panel.ts +2 -3
- package/web/rig-fields-panel.ts +1 -2
- package/web/rig-host.ts +62 -0
- package/web/rig-viewport-provider.ts +63 -16
- package/web/stage-comments.ts +29 -26
- package/web/styles.css +127 -43
- package/web/view-controls.ts +201 -12
- package/web/viewport-controller.ts +97 -26
- package/web/viewport-pair.ts +2 -1
- package/web/workspace-preferences.ts +5 -4
- package/web/workspace-ui.ts +152 -19
- package/src/interview-server.ts +0 -54
- package/web/interview.css +0 -28
- package/web/interview.html +0 -17
- package/web/interview.ts +0 -40
- package/web/job-hub.css +0 -14
- package/web/job-hub.html +0 -5
- package/web/owner-workspace.css +0 -14
- package/web/owner-workspace.html +0 -5
- package/web/parts-flags.ts +0 -48
- package/web/parts-page.ts +0 -217
- package/web/parts.css +0 -116
- package/web/parts.html +0 -15
- package/web/parts.ts +0 -986
- package/web/stage-nav.ts +0 -136
package/web/job-hub.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {createRetainedFrameStage, mountRetainedWorkspace} from './retained-frame-stage.ts';
|
|
2
|
+
import {hashCapabilityAccess} from './instance-access.ts';
|
|
1
3
|
/** Owner-only job selection. Each retained frame owns its existing job window and draft. */
|
|
2
4
|
import type {JobHubList, JobHubRow} from '../src/job-hub.ts';
|
|
3
5
|
|
|
@@ -23,22 +25,14 @@ export function jobHubMessageMatches(event: Pick<MessageEvent, 'origin' | 'sourc
|
|
|
23
25
|
typeof binding.sourceHash === 'string' && /^[a-f0-9]{64}$/.test(binding.sourceHash)) &&
|
|
24
26
|
(kind === 'ready' || typeof value.visible === 'boolean' && ['en', 'ko'].includes(value.language));
|
|
25
27
|
}
|
|
26
|
-
export function
|
|
28
|
+
export function checkedJobHubLocation(href: string) {
|
|
27
29
|
const url = new URL(href), incarnation = url.searchParams.get('workspace');
|
|
28
30
|
if (url.pathname !== '/hub/' || !incarnation || !/^[a-f0-9-]{36}$/.test(incarnation) ||
|
|
29
31
|
[...url.searchParams.keys()].some(key => !['workspace', 'lang'].includes(key) || url.searchParams.getAll(key).length !== 1) ||
|
|
30
32
|
url.searchParams.has('lang') && !['en', 'ko'].includes(url.searchParams.get('lang')!)) throw new Error('JOB_REQUEST_INVALID');
|
|
31
|
-
|
|
32
|
-
let capability = url.hash.startsWith('#cap=') ? url.hash.slice(5) : '';
|
|
33
|
-
if (!/^[a-f0-9]{64}$/.test(capability)) capability = '';
|
|
34
|
-
try {
|
|
35
|
-
if (capability) storage?.setItem(slot, capability);
|
|
36
|
-
else capability = storage?.getItem(slot) ?? '';
|
|
37
|
-
} catch { /* Memory-only owner access. */ }
|
|
38
|
-
if (!/^[a-f0-9]{64}$/.test(capability)) capability = '';
|
|
39
|
-
url.hash = ''; replace(url.href);
|
|
40
|
-
return {incarnation, capability};
|
|
33
|
+
return {url, incarnation};
|
|
41
34
|
}
|
|
35
|
+
|
|
42
36
|
export function checkedJobHubList(value: JobHubList, incarnation: string): JobHubList {
|
|
43
37
|
if (value?.schema !== 'rig-review-job-hub/1' || value.incarnation !== incarnation ||
|
|
44
38
|
!Number.isSafeInteger(value.limit) || value.limit < 1 || value.limit > 32 ||
|
|
@@ -61,85 +55,69 @@ export async function mountJobHub(root: HTMLElement): Promise<() => void> {
|
|
|
61
55
|
const {t, getLanguage} = i18n;
|
|
62
56
|
let storage: Storage | null = null;
|
|
63
57
|
try {storage = sessionStorage;} catch { /* Memory-only access. */ }
|
|
64
|
-
const
|
|
58
|
+
const {url: locationURL, incarnation} = checkedJobHubLocation(location.href);
|
|
59
|
+
const capability = hashCapabilityAccess(locationURL, 'rig-review-job-hub/1:' + locationURL.origin + ':' + incarnation,
|
|
60
|
+
() => storage, href => history.replaceState(history.state, '', href), {strip: 'always-after-storage', storedValue: 'validate', fallback: ''});
|
|
61
|
+
const access = {incarnation, capability};
|
|
65
62
|
const requestedLanguage = new URL(location.href).searchParams.get('lang');
|
|
66
63
|
if (requestedLanguage === 'en' || requestedLanguage === 'ko') i18n.setLanguagePreference(requestedLanguage);
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const notice = document.createElement('p'); notice.className = 'hub-status'; notice.setAttribute('role', 'status');
|
|
70
|
-
const language = document.createElement('select');
|
|
71
|
-
for (const name of ['en', 'ko']) {const option = document.createElement('option'); option.value = name; language.append(option);}
|
|
72
|
-
header.append(title, notice, language);
|
|
73
|
-
const list = document.createElement('nav'); list.className = 'hub-list';
|
|
74
|
-
const stage = document.createElement('main'); stage.className = 'hub-stage';
|
|
75
|
-
root.replaceChildren(header, list, stage);
|
|
64
|
+
const workspace = mountRetainedWorkspace({root, kind: 'hub'});
|
|
65
|
+
const {stage, language} = workspace;
|
|
76
66
|
type Frame = {frame: HTMLIFrameElement; row: JobHubRow; binding: JobHubBinding; announced?: JobHubBinding};
|
|
77
|
-
const
|
|
78
|
-
let current: JobHubList | null = null,
|
|
67
|
+
const cancellation = new AbortController();
|
|
68
|
+
let current: JobHubList | null = null, disposed = false;
|
|
79
69
|
let status = 'job.hubHint', timer: ReturnType<typeof setTimeout> | undefined;
|
|
80
70
|
const binding = (row: JobHubRow): JobHubBinding => ({incarnation: access.incarnation, jobId: row.jobId,
|
|
81
71
|
publicationId: row.publication?.publicationId ?? null, sourceHash: row.publication?.sourceHash ?? null});
|
|
82
|
-
|
|
83
|
-
entry
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
function showSelection() {
|
|
87
|
-
for (const entry of frames.values()) {
|
|
88
|
-
entry.frame.hidden = entry.row.jobId !== selected;
|
|
89
|
-
entry.frame.inert = entry.frame.hidden;
|
|
90
|
-
entry.frame.setAttribute('aria-hidden', String(entry.frame.hidden)); visibility(entry);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
72
|
+
const retained = createRetainedFrameStage<Frame>({stage, limit: () => current!.limit, key: entry => entry.row.jobId,
|
|
73
|
+
message: entry => ({...entry.binding, schema: JOB_HUB_VISIBILITY}), language: getLanguage, origin: location.origin,
|
|
74
|
+
visibilityOrder: 'after-state', languageChange: 'selection'});
|
|
93
75
|
function render() {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const source = document.createElement('span'); source.className = 'hub-job-source'; source.textContent = row.publication?.sourceHash ?? '';
|
|
106
|
-
button.append(name, state, source);
|
|
107
|
-
button.onclick = () => {void select(row).catch(() => {status = 'JOB_HUB_REQUEST_REFUSED'; render();});}; list.append(button);
|
|
108
|
-
}
|
|
76
|
+
workspace.render({
|
|
77
|
+
lang: getLanguage(), heading: t('job.hubTitle'), listLabel: t('job.hubJobs'),
|
|
78
|
+
languageLabel: t('interview.language'), englishLabel: t('English'), koreanLabel: t('Korean'),
|
|
79
|
+
message: t(status), selected: retained.selected,
|
|
80
|
+
items: (current?.jobs ?? []).map(row => ({
|
|
81
|
+
key: row.jobId, dataset: {jobId: row.jobId}, label: row.publication?.label || row.jobId,
|
|
82
|
+
state: row.status === 'closed' ? t('job.hubClosed') : t('job.hubPending', [row.pendingCount]),
|
|
83
|
+
detail: row.publication?.sourceHash ?? '',
|
|
84
|
+
onSelect: () => {void select(row).catch(() => {status = 'JOB_HUB_REQUEST_REFUSED'; render();});},
|
|
85
|
+
})),
|
|
86
|
+
});
|
|
109
87
|
}
|
|
110
88
|
async function select(row: JobHubRow) {
|
|
111
|
-
const selection =
|
|
112
|
-
let entry =
|
|
89
|
+
const selection = retained.beginSelection();
|
|
90
|
+
let entry = retained.get(row.jobId);
|
|
113
91
|
if (!entry && row.status === 'closed') {
|
|
114
|
-
|
|
92
|
+
status = 'job.hubClosed'; retained.select(row.jobId); render(); return;
|
|
115
93
|
}
|
|
116
94
|
if (!entry) {
|
|
117
|
-
if (!current ||
|
|
95
|
+
if (!current || retained.atLimit()) throw new Error('JOB_HUB_LIMIT');
|
|
118
96
|
const response = await fetch('/hub/api/jobs/' + row.jobId + '/open', {method: 'POST',
|
|
119
97
|
headers: {'Content-Type': 'application/json', 'X-Review-Capability': access.capability},
|
|
120
98
|
body: JSON.stringify({schema: 'rig-review-job-hub/1', incarnation: access.incarnation}),
|
|
121
99
|
signal: AbortSignal.any([cancellation.signal, AbortSignal.timeout(5000)])});
|
|
122
100
|
const grant = await response.json();
|
|
123
101
|
if (!response.ok) throw new Error('JOB_HUB_REQUEST_REFUSED');
|
|
124
|
-
if (
|
|
102
|
+
if (!retained.isCurrent(selection)) return;
|
|
125
103
|
if (grant.schema !== 'rig-review-job-hub/1' || grant.incarnation !== access.incarnation || grant.jobId !== row.jobId ||
|
|
126
104
|
grant.entry !== '/jobs/' + row.jobId + '/?hub=' + access.incarnation || !/^[a-f0-9]{64}$/.test(grant.capability)) throw new Error('JOB_HUB_STATE_INVALID');
|
|
127
105
|
const url = new URL(grant.entry, location.origin); url.searchParams.set('lang', getLanguage()); url.hash = 'cap=' + grant.capability;
|
|
128
|
-
const frame =
|
|
106
|
+
const frame = retained.createFrame(row.publication?.label || row.jobId, url.href);
|
|
129
107
|
entry = {frame, row, binding: {...binding(row), publicationId: null, sourceHash: null}};
|
|
130
|
-
|
|
108
|
+
retained.retain(entry);
|
|
131
109
|
}
|
|
132
|
-
|
|
110
|
+
status = 'job.hubHint'; retained.select(row.jobId); render();
|
|
133
111
|
}
|
|
134
112
|
function ready(event: MessageEvent) {
|
|
135
|
-
const entry =
|
|
113
|
+
const entry = retained.get(event.data?.jobId);
|
|
136
114
|
if (!entry || !current) return;
|
|
137
115
|
const candidate: JobHubBinding = {incarnation: access.incarnation, jobId: entry.row.jobId,
|
|
138
116
|
publicationId: event.data?.publicationId, sourceHash: event.data?.sourceHash};
|
|
139
117
|
if (!jobHubMessageMatches(event, location.origin, entry.frame.contentWindow, candidate, 'ready')) return;
|
|
140
118
|
entry.announced = candidate;
|
|
141
119
|
if (jobHubMessageMatches(event, location.origin, entry.frame.contentWindow, binding(entry.row), 'ready')) {
|
|
142
|
-
entry.binding = candidate; visibility(entry);
|
|
120
|
+
entry.binding = candidate; retained.visibility(entry);
|
|
143
121
|
}
|
|
144
122
|
}
|
|
145
123
|
async function refresh() {
|
|
@@ -149,31 +127,34 @@ export async function mountJobHub(root: HTMLElement): Promise<() => void> {
|
|
|
149
127
|
if (!response.ok) throw new Error('JOB_HUB_REQUEST_REFUSED');
|
|
150
128
|
current = checkedJobHubList(await response.json(), access.incarnation);
|
|
151
129
|
for (const row of current.jobs) {
|
|
152
|
-
const entry =
|
|
130
|
+
const entry = retained.get(row.jobId);
|
|
153
131
|
if (!entry) continue;
|
|
154
132
|
entry.row = row;
|
|
155
133
|
if (entry.announced && JSON.stringify(entry.announced) === JSON.stringify(binding(row))) entry.binding = entry.announced;
|
|
156
|
-
visibility(entry);
|
|
134
|
+
retained.visibility(entry);
|
|
157
135
|
}
|
|
158
136
|
render();
|
|
159
|
-
if (!selected && current.jobs[0]) await select(current.jobs[0]);
|
|
137
|
+
if (!retained.selected && current.jobs[0]) await select(current.jobs[0]);
|
|
160
138
|
} catch {if (!disposed) {status = 'JOB_HUB_REQUEST_REFUSED'; render();}}
|
|
161
139
|
finally {if (!disposed) timer = setTimeout(() => {void refresh();}, 1000);}
|
|
162
140
|
}
|
|
163
141
|
language.onchange = () => {i18n.setLinkLanguage(null); i18n.setLanguagePreference(language.value === 'ko' ? 'ko' : 'en');};
|
|
164
|
-
const unlocalize = i18n.onLanguageChange(() => {render();
|
|
142
|
+
const unlocalize = i18n.onLanguageChange(() => {render(); retained.languageChanged();});
|
|
165
143
|
globalThis.addEventListener('message', ready);
|
|
166
144
|
const stop = () => {
|
|
167
145
|
if (disposed) return;
|
|
168
|
-
disposed = true; clearTimeout(timer); cancellation.abort(); unlocalize();
|
|
146
|
+
disposed = true; retained.dispose(); clearTimeout(timer); cancellation.abort(); unlocalize();
|
|
169
147
|
globalThis.removeEventListener('message', ready); globalThis.removeEventListener('pagehide', stop);
|
|
170
148
|
};
|
|
171
149
|
globalThis.addEventListener('pagehide', stop, {once: true});
|
|
172
150
|
render(); void refresh(); return stop;
|
|
173
151
|
}
|
|
174
|
-
if (typeof document !== 'undefined' &&
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
152
|
+
if (typeof document !== 'undefined' && typeof location !== 'undefined' && location.pathname === '/hub/') {
|
|
153
|
+
const root = document.getElementById('app');
|
|
154
|
+
if (root && !root.childElementCount) {
|
|
155
|
+
void mountJobHub(root).catch(async () => {
|
|
156
|
+
const {t} = await import('./i18n.ts');
|
|
157
|
+
root.textContent = t('JOB_HUB_REQUEST_REFUSED');
|
|
158
|
+
});
|
|
159
|
+
}
|
|
179
160
|
}
|
package/web/job-rig-capture.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import {CanvasRenderer, RigPlayer, type ModelAssets, type PosedFrame} from '@rig-c/play';
|
|
2
|
+
import {assertOriginalPaintingSize} from '../src/parts-comparison.ts';
|
|
2
3
|
import {jobStillByteLimit, type JobRigCapture, type JobUISubmission} from '../src/job-contract.ts';
|
|
3
|
-
import type {
|
|
4
|
+
import type {ControlNumericCamera} from '../src/control.ts';
|
|
5
|
+
import {presentJobRigViewport, type JobRigPresentation} from './viewport-capture.ts';
|
|
4
6
|
|
|
5
7
|
type DrawSource = Pick<JobRigCapture['binding'], 'publicationId' | 'instanceKey' | 'sourceHash' | 'pageId'>;
|
|
6
8
|
export interface JobRigDrawState {
|
|
@@ -40,6 +42,36 @@ const sourceKey = (source: DrawSource) => JSON.stringify([
|
|
|
40
42
|
source.publicationId, source.instanceKey, source.sourceHash, source.pageId,
|
|
41
43
|
]);
|
|
42
44
|
|
|
45
|
+
/** Native original-art comparison needs the declared canvas, never a fitted viewport or inferred bounds. */
|
|
46
|
+
export function rigRestCanvas(assets: Pick<ModelAssets, 'stage'>, painting: {width: number; height: number}) {
|
|
47
|
+
const stage = assets.stage;
|
|
48
|
+
assertOriginalPaintingSize(painting.width, painting.height, stage ? [stage.width, stage.height] : null, 1);
|
|
49
|
+
if (!stage || !Number.isSafeInteger(stage.x) || !Number.isSafeInteger(stage.y) ||
|
|
50
|
+
stage.width > 16384 || stage.height > 16384 || stage.width * stage.height > 16777216) {
|
|
51
|
+
throw new Error('PARTS_PAINTING_MAPPING: declared rig_size and positive scale_rig_per_source required');
|
|
52
|
+
}
|
|
53
|
+
return {x: stage.x, y: stage.y, width: stage.width, height: stage.height};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Standalone Setup operand. A fresh public player has no animation, slot filter, previews or environment history.
|
|
57
|
+
* This is deliberately separate from freezing the displayed job bitmap: its fixed-camera and binding guards stay intact. */
|
|
58
|
+
export function captureRigRestStill(assets: ModelAssets, painting: {width: number; height: number}): HTMLCanvasElement {
|
|
59
|
+
const viewport = rigRestCanvas(assets, painting), root = document.createElement('div');
|
|
60
|
+
const player = new RigPlayer(root, assets, {mode: 'canvas'});
|
|
61
|
+
try {
|
|
62
|
+
const renderer = player.renderer;
|
|
63
|
+
if (!(renderer instanceof CanvasRenderer)) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
64
|
+
// Public clear(0) holds Setup even on a model without animations or sets. No clip is played.
|
|
65
|
+
renderer.viewport = viewport; renderer.pixelRatio = 1;
|
|
66
|
+
player.clear(0); player.draw();
|
|
67
|
+
const frame = player.posedFrame();
|
|
68
|
+
if (renderer.backendActive === 'canvas2d' && frame.order.some(row => row.tint.slice(0, 3).some(c => c !== 1) || row.dark?.some(c => c !== 0))) {
|
|
69
|
+
throw new Error('COMMENT_CAPTURE_UNAVAILABLE: Canvas2D cannot reproduce active RGB/dark tint');
|
|
70
|
+
}
|
|
71
|
+
return copyRigBitmap(renderer.canvas, viewport.width, viewport.height);
|
|
72
|
+
} finally {player.dispose();}
|
|
73
|
+
}
|
|
74
|
+
|
|
43
75
|
/** Bind local placement and physical-pixel phase while allowing whole-pixel page movement. */
|
|
44
76
|
export function jobRigPixelPlacement(pane: Pick<DOMRect, 'left' | 'top'>,
|
|
45
77
|
canvas: Pick<DOMRect, 'left' | 'top'>, ratio: number) {
|
|
@@ -153,14 +185,8 @@ export function freezeJobRigCapture(draw: JobRigDraw | undefined, state: JobRigD
|
|
|
153
185
|
}};
|
|
154
186
|
}
|
|
155
187
|
|
|
156
|
-
/**
|
|
157
|
-
|
|
158
|
-
const {canvas: displayed, width, height, ratio} = presentation;
|
|
159
|
-
if (!displayed.isConnected || displayed.width !== width || displayed.height !== height ||
|
|
160
|
-
ratio !== (globalThis.devicePixelRatio || 1) || width < 1 || height < 1 ||
|
|
161
|
-
width > 16384 || height > 16384 || width * height > 16777216) {
|
|
162
|
-
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
163
|
-
}
|
|
188
|
+
/** One lossless bitmap-copy implementation for job evidence and standalone native rest inspection. */
|
|
189
|
+
function copyRigBitmap(displayed: HTMLCanvasElement, width: number, height: number): HTMLCanvasElement {
|
|
164
190
|
const canvas = document.createElement('canvas');
|
|
165
191
|
canvas.width = width;
|
|
166
192
|
canvas.height = height;
|
|
@@ -170,6 +196,18 @@ export function copyJobRigViewport(presentation: JobRigPresentation): JobRigPixe
|
|
|
170
196
|
if (!source || !context) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
171
197
|
context.putImageData(source.getImageData(0, 0, width, height), 0, 0);
|
|
172
198
|
} catch { throw new Error('JOB_STILL_CAPTURE_FAILED'); }
|
|
199
|
+
return canvas;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Copy the committed display bitmap synchronously, before asynchronous PNG encoding. */
|
|
203
|
+
export function copyJobRigViewport(presentation: JobRigPresentation): JobRigPixels {
|
|
204
|
+
const {canvas: displayed, width, height, ratio} = presentation;
|
|
205
|
+
if (!displayed.isConnected || displayed.width !== width || displayed.height !== height ||
|
|
206
|
+
ratio !== (globalThis.devicePixelRatio || 1) || width < 1 || height < 1 ||
|
|
207
|
+
width > 16384 || height > 16384 || width * height > 16777216) {
|
|
208
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
209
|
+
}
|
|
210
|
+
const canvas = copyRigBitmap(displayed, width, height);
|
|
173
211
|
return {width, height, encode: () => new Promise<string>((resolve, reject) => {
|
|
174
212
|
canvas.toBlob(blob => {
|
|
175
213
|
if (!blob || blob.size > jobStillByteLimit) {reject(new Error('JOB_STILL_CAPTURE_FAILED')); return;}
|
|
@@ -209,3 +247,58 @@ export function createJobRigSubmission() {
|
|
|
209
247
|
},
|
|
210
248
|
};
|
|
211
249
|
}
|
|
250
|
+
|
|
251
|
+
/** One screen's rig pane as the still reads it: the job window's and the one review screen's share this. */
|
|
252
|
+
export interface JobRigStage {
|
|
253
|
+
readonly pane: HTMLElement;
|
|
254
|
+
readonly paneHidden: boolean;
|
|
255
|
+
readonly root: HTMLElement;
|
|
256
|
+
readonly player: RigPlayer;
|
|
257
|
+
readonly presentation: JobRigPresentation | undefined;
|
|
258
|
+
readonly frameGeneration: number | undefined;
|
|
259
|
+
readonly camera: ControlNumericCamera | null | undefined;
|
|
260
|
+
readonly frame: {readonly center: {readonly x: number; readonly y: number}} | null;
|
|
261
|
+
readonly source: DrawSource;
|
|
262
|
+
/** No part selected or solo, images only, no mesh, bones or background sentinel. */
|
|
263
|
+
readonly wholeRig: boolean;
|
|
264
|
+
readonly playing: boolean;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The draw state a still is bound to: pane geometry, camera, canonical pixels and the posed frame. */
|
|
268
|
+
export function jobRigDrawState(stage: JobRigStage): JobRigDrawState {
|
|
269
|
+
const {pane, root, player, presentation, frame, camera} = stage;
|
|
270
|
+
const rect = pane.getBoundingClientRect(), ratio = globalThis.devicePixelRatio || 1;
|
|
271
|
+
if (!frame || !camera || !pane.isConnected || !root.isConnected || stage.paneHidden ||
|
|
272
|
+
rect.width <= 0 || rect.height <= 0) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
273
|
+
const style = getComputedStyle(root), paneStyle = getComputedStyle(pane);
|
|
274
|
+
const plain = style.filter === 'none' && style.perspective === 'none' && style.opacity === '1' &&
|
|
275
|
+
paneStyle.filter === 'none' && paneStyle.transform === 'none' && paneStyle.perspective === 'none' && paneStyle.opacity === '1';
|
|
276
|
+
const canvas = presentation?.canvas;
|
|
277
|
+
const pixels = canvas?.getBoundingClientRect();
|
|
278
|
+
const canvasStyle = canvas ? getComputedStyle(canvas) : null;
|
|
279
|
+
if (canvas && (!canvas.isConnected || canvasStyle?.visibility !== 'visible' ||
|
|
280
|
+
canvasStyle.display === 'none' || canvasStyle.opacity !== '1' || canvasStyle.filter !== 'none' ||
|
|
281
|
+
canvasStyle.transform !== 'none')) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
282
|
+
return {player, presentation, frameGeneration: stage.frameGeneration, source: stage.source,
|
|
283
|
+
layout: JSON.stringify([
|
|
284
|
+
pane.clientWidth, pane.clientHeight, rect.width, rect.height, ratio,
|
|
285
|
+
root.getAttribute('style'), style.transform, camera, presentation?.area, presentation?.ratio,
|
|
286
|
+
pixels ? jobRigPixelPlacement(rect, pixels, ratio) : null,
|
|
287
|
+
pixels?.width, pixels?.height, canvas?.width, canvas?.height, canvas?.getAttribute('style'),
|
|
288
|
+
]),
|
|
289
|
+
defaultCamera: plain && camera.zoom === 1 && camera.center.x === frame.center.x && camera.center.y === frame.center.y,
|
|
290
|
+
wholeRig: stage.wholeRig, playing: stage.playing};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Paint the pane's actual pixels into one canonical canvas and put it on the pane. */
|
|
294
|
+
export function presentJobRigStage(stage: Pick<JobRigStage, 'pane' | 'root' | 'player' | 'camera'> &
|
|
295
|
+
{readonly posed: PosedFrame | undefined; readonly assets: ModelAssets | null}): JobRigPresentation {
|
|
296
|
+
const renderer = stage.player.renderer;
|
|
297
|
+
if (!stage.posed || !stage.assets || !stage.camera) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
298
|
+
const presentation = presentJobRigViewport({pane: stage.pane, root: stage.root, images: true,
|
|
299
|
+
canvas: renderer instanceof CanvasRenderer ? renderer.canvas : undefined,
|
|
300
|
+
backend: renderer instanceof CanvasRenderer ? renderer.backendActive : renderer.meshBackendActive},
|
|
301
|
+
{camera: stage.camera, posed: stage.posed, assets: stage.assets});
|
|
302
|
+
stage.pane.append(presentation.canvas);
|
|
303
|
+
return presentation;
|
|
304
|
+
}
|