roamwright 0.61.21 → 0.61.22
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/package.json +1 -1
- package/tools/README.md +34 -25
- package/tools/cpu-profile.cjs +117 -0
- package/tools/cpu-profile.test.cjs +31 -1
- package/tools/figure-inspect.cjs +475 -0
- package/tools/figure-inspect.test.cjs +153 -0
- package/tools/geometry-hash.cjs +361 -0
- package/tools/geometry-hash.test.cjs +146 -0
- package/tools/load-audit.cjs +199 -2
- package/tools/load-audit.test.cjs +68 -0
- package/tools/quiet-bench.cjs +202 -0
- package/tools/quiet-bench.test.cjs +91 -0
- package/tools/scene-detail.cjs +355 -0
- package/tools/scene-detail.test.cjs +162 -0
- package/tools/scrub-clear.cjs +191 -0
- package/tools/scrub-clear.test.cjs +100 -0
- package/tools/tree-inspect.cjs +271 -0
- package/tools/tree-inspect.test.cjs +123 -0
- package/tools/world-tour.cjs +223 -0
- package/tools/world-tour.test.cjs +77 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
// Character, crowd, and head-sheet visual inspection runners built on a Roamwright page driver:
|
|
2
|
+
// five-angle character inspection at home (`runPersonLook`), street-level crowd still (`runCrowdLook`),
|
|
3
|
+
// and multi-actor head contact sheet (`runHeadSheet`).
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/** Default views for `runPersonLook`: `[view, turnRadians, distanceMetres, lookHeightShare]`. */
|
|
7
|
+
const PERSON_LOOK_VIEWS = [
|
|
8
|
+
['front', 0, 2.6, 0.55],
|
|
9
|
+
['three', 0.75, 2.6, 0.55],
|
|
10
|
+
['side', 1.57, 2.6, 0.55],
|
|
11
|
+
['back', 3.14, 2.6, 0.55],
|
|
12
|
+
['face', 0.35, 0.95, 0.92],
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const DEFAULT_HUD_SELECTORS = '#hud, #card, #hints, #debug, #toast, #btns, #compass, #wp, #objective, #locname, #flybtns, #joy, #cross';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Parses CLI arguments for `runPersonLook`: `<name> <characterId> [hour=0.4] [width=1400] [height=1000]`.
|
|
19
|
+
*
|
|
20
|
+
* @param {string[]} [argv=[]]
|
|
21
|
+
* @param {object} [defaults]
|
|
22
|
+
* @param {string} [defaults.defaultId='']
|
|
23
|
+
* @returns {{ name: string, id: string, hour: number, width: number, height: number }}
|
|
24
|
+
*/
|
|
25
|
+
function parsePersonLookArgs(argv = [], { defaultId = '' } = {}) {
|
|
26
|
+
const [name = 'person', id = defaultId, hour = '0.4', width = 1400, height = 1000] = argv;
|
|
27
|
+
return { name, id, hour: +hour, width: +width, height: +height };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parses CLI arguments for `runCrowdLook`: `<name> <address> <kind> <member> <hour> [metres] [width] [height] [fov]`.
|
|
32
|
+
*
|
|
33
|
+
* @param {string[]} [argv=[]]
|
|
34
|
+
* @returns {{ name: string, address: string, kind: string, member: number, hour: number, metres: number, width: number, height: number, fov: number }}
|
|
35
|
+
*/
|
|
36
|
+
function parseCrowdLookArgs(argv = []) {
|
|
37
|
+
const [name = 'crowd', address = '', kind = 'city', member = '0', hour = '0.5', metres = '4', width = '1280', height = '720', fov = ''] =
|
|
38
|
+
argv;
|
|
39
|
+
return {
|
|
40
|
+
name,
|
|
41
|
+
address,
|
|
42
|
+
kind,
|
|
43
|
+
member: +member,
|
|
44
|
+
hour: +hour,
|
|
45
|
+
metres: +metres,
|
|
46
|
+
width: +width,
|
|
47
|
+
height: +height,
|
|
48
|
+
fov: +fov || 0,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parses CLI arguments and semicolon-delimited options string for `runHeadSheet`.
|
|
54
|
+
*
|
|
55
|
+
* @param {string[]} [argv=[]]
|
|
56
|
+
* @param {object} [defaults]
|
|
57
|
+
* @param {string} [defaults.defaultIds='']
|
|
58
|
+
* @returns {{ name: string, address: string, ids: string[], time: number, dist: number, angle: number, where: string, script: string, cell: number, view: number, pose: string, expr: number[] | null, frames: number, aim: number[], beside: string, cols: number }}
|
|
59
|
+
*/
|
|
60
|
+
function parseHeadSheetArgs(argv = [], { defaultIds = '' } = {}) {
|
|
61
|
+
const [
|
|
62
|
+
name = 'heads',
|
|
63
|
+
address = '',
|
|
64
|
+
idsStr = defaultIds,
|
|
65
|
+
time = '0.4',
|
|
66
|
+
dist = '0.9',
|
|
67
|
+
angle = '20',
|
|
68
|
+
where = 'sky',
|
|
69
|
+
script = '',
|
|
70
|
+
optStr = '',
|
|
71
|
+
] = argv;
|
|
72
|
+
const opt = Object.fromEntries(
|
|
73
|
+
String(optStr || '')
|
|
74
|
+
.split(';')
|
|
75
|
+
.filter(Boolean)
|
|
76
|
+
.map(kv => kv.split('=')),
|
|
77
|
+
);
|
|
78
|
+
return {
|
|
79
|
+
name,
|
|
80
|
+
address,
|
|
81
|
+
ids: String(idsStr).split(',').filter(Boolean),
|
|
82
|
+
time: +time,
|
|
83
|
+
dist: +dist,
|
|
84
|
+
angle: +angle,
|
|
85
|
+
where,
|
|
86
|
+
script,
|
|
87
|
+
cell: +(opt.cell || 360),
|
|
88
|
+
view: +(opt.view || 0.2),
|
|
89
|
+
pose: opt.pose || '',
|
|
90
|
+
expr: opt.expr ? JSON.parse(opt.expr) : null,
|
|
91
|
+
frames: +(opt.frames || 1),
|
|
92
|
+
aim: (opt.aim || '0,0.12,0.03').split(',').map(Number),
|
|
93
|
+
beside: opt.beside || '',
|
|
94
|
+
cols: +(opt.cols || 5),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Computes the vertical field of view (degrees) that frames half-height `view * scale` at distance `dist`.
|
|
100
|
+
*
|
|
101
|
+
* @param {number} view Half-height framed in metres.
|
|
102
|
+
* @param {number} scale Actor vertical scale.
|
|
103
|
+
* @param {number} dist Camera distance in metres.
|
|
104
|
+
* @returns {number}
|
|
105
|
+
*/
|
|
106
|
+
function headCameraFov(view, scale, dist) {
|
|
107
|
+
return (2 * Math.atan((view * scale) / dist) * 180) / Math.PI;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Finds a character's first home anchor in `window[debug]` and moves the visitor beside them so their figure raises.
|
|
112
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
113
|
+
*
|
|
114
|
+
* @param {{ debug: string, id: string }} arg
|
|
115
|
+
* @returns {{ x: number, z: number } | null}
|
|
116
|
+
*/
|
|
117
|
+
function locateActorHomeInPage({ debug, id }) {
|
|
118
|
+
const app = window[debug];
|
|
119
|
+
const a = app.actors[id];
|
|
120
|
+
if (!a) return null;
|
|
121
|
+
const home = [].concat(a.def.home)[0];
|
|
122
|
+
const anchor = app.P[home.at];
|
|
123
|
+
const x = anchor.x + (home.d?.[0] ?? 0);
|
|
124
|
+
const z = anchor.z + (home.d?.[1] ?? 0);
|
|
125
|
+
app.placePlayer(x + 6, z + 6, 0);
|
|
126
|
+
return { x, z };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Aims the inspect camera at `(x, ground + 1, z)` so an actor there enters frustum and builds their near mesh.
|
|
131
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
132
|
+
*
|
|
133
|
+
* @param {{ debug: string, x: number, z: number }} arg
|
|
134
|
+
*/
|
|
135
|
+
function focusPointForActorInPage({ debug, x, z }) {
|
|
136
|
+
const app = window[debug];
|
|
137
|
+
const y = typeof app.terrainHeight === 'function' ? app.terrainHeight(x, z) : app.space.ground(x, z);
|
|
138
|
+
app.state.mode = 'inspect';
|
|
139
|
+
app.camera.position.set(x + 3, y + 1.6, z + 3);
|
|
140
|
+
app.camera.lookAt(x, y + 1, z);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Checks whether an actor has both its base and near figure built.
|
|
145
|
+
* Passed to `page.waitForFunction`; must remain self-contained.
|
|
146
|
+
*
|
|
147
|
+
* @param {{ debug: string, id: string }} arg
|
|
148
|
+
* @returns {boolean}
|
|
149
|
+
*/
|
|
150
|
+
function waitActorNearBuiltInPage({ debug, id }) {
|
|
151
|
+
const a = window[debug]?.actors?.[id];
|
|
152
|
+
return !!(a && a.built && a.nearBuilt);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Poses the inspect camera at `(turn, distance, look)` relative to an actor's bounding box and facing.
|
|
157
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
158
|
+
*
|
|
159
|
+
* @param {{ debug: string, id: string, turn: number, distance: number, look: number, hour: number }} arg
|
|
160
|
+
* @returns {{ tall: number }}
|
|
161
|
+
*/
|
|
162
|
+
function posePersonViewInPage({ debug, id, turn, distance, look, hour }) {
|
|
163
|
+
const app = window[debug];
|
|
164
|
+
const { THREE, camera } = app;
|
|
165
|
+
const g = app.actors[id].group;
|
|
166
|
+
const box = new THREE.Box3().setFromObject(g);
|
|
167
|
+
const tall = box.max.y - box.min.y;
|
|
168
|
+
const facing = g.rotation.y + turn;
|
|
169
|
+
const aim = new THREE.Vector3(g.position.x, box.min.y + tall * look, g.position.z);
|
|
170
|
+
app.holdQuality(true);
|
|
171
|
+
app.env.flow = false;
|
|
172
|
+
app.env.time = hour;
|
|
173
|
+
app.state.mode = 'inspect';
|
|
174
|
+
camera.position.set(aim.x + Math.sin(facing) * distance, aim.y + 0.05, aim.z + Math.cos(facing) * distance);
|
|
175
|
+
camera.lookAt(aim);
|
|
176
|
+
return { tall: +tall.toFixed(2) };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Stands the visitor on a crowd member's street walk facing its midpoint and hides HUD overlays.
|
|
181
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
182
|
+
*
|
|
183
|
+
* @param {{ debug: string, kind: string, member: number, hour: number, metres: number, fov: number, hideSelectors?: string }} arg
|
|
184
|
+
* @returns {{ members: number, at: number[], looks: string }}
|
|
185
|
+
*/
|
|
186
|
+
function positionCrowdLookInPage({
|
|
187
|
+
debug,
|
|
188
|
+
kind,
|
|
189
|
+
member,
|
|
190
|
+
hour,
|
|
191
|
+
metres,
|
|
192
|
+
fov,
|
|
193
|
+
hideSelectors = '#hud, #card, #hints, #toast, #btns, #compass, #wp, #objective, #locname, #flybtns, #joy, #cross',
|
|
194
|
+
}) {
|
|
195
|
+
const app = window[debug];
|
|
196
|
+
const crowd = app.crowds.find(c => c.kind === kind && c.list.length > member);
|
|
197
|
+
const who = crowd.list[member];
|
|
198
|
+
app.env.flow = false;
|
|
199
|
+
app.env.time = hour;
|
|
200
|
+
if (app.holdQuality) app.holdQuality(true);
|
|
201
|
+
if (typeof document !== 'undefined') document.querySelectorAll(hideSelectors).forEach(e => (e.style.display = 'none'));
|
|
202
|
+
const walks = Number.isFinite(who.bx) && Math.hypot(who.bx - who.ax, who.bz - who.az) > 1;
|
|
203
|
+
const mx = walks ? (who.ax + who.bx) / 2 : who.ax;
|
|
204
|
+
const mz = walks ? (who.az + who.bz) / 2 : who.az;
|
|
205
|
+
const dx = walks ? who.bx - who.ax : 1;
|
|
206
|
+
const dz = walks ? who.bz - who.az : 0;
|
|
207
|
+
const len = Math.hypot(dx, dz);
|
|
208
|
+
const x = mx - (dx / len) * metres;
|
|
209
|
+
const z = mz - (dz / len) * metres;
|
|
210
|
+
if (app.state.fly) app.setFly(false);
|
|
211
|
+
app.placePlayer(x, z, Math.atan2(mx - x, mz - z));
|
|
212
|
+
if (fov) {
|
|
213
|
+
app.camera.fov = fov;
|
|
214
|
+
app.state.baseFov = fov;
|
|
215
|
+
app.camera.updateProjectionMatrix();
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
members: crowd.list.length,
|
|
219
|
+
at: [mx, mz].map(v => +v.toFixed(1)),
|
|
220
|
+
looks: crowd.list
|
|
221
|
+
.slice(0, 40)
|
|
222
|
+
.map(p => p.look)
|
|
223
|
+
.join(','),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Places a single actor (and optional comparison actor beside them) at the visitor's position for head inspection.
|
|
229
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
230
|
+
*
|
|
231
|
+
* @param {{ debug: string, id: string, time: number, where: string, pose: string, expr: number[] | null, beside: string }} arg
|
|
232
|
+
* @returns {string} `'ok'` or `'no actor <id>'`.
|
|
233
|
+
*/
|
|
234
|
+
function placeHeadActorInPage({ debug, id, time, where, pose, expr, beside }) {
|
|
235
|
+
const app = window[debug];
|
|
236
|
+
const a = app.actors[id];
|
|
237
|
+
if (!a) return 'no actor ' + id;
|
|
238
|
+
for (const b of Object.values(app.actors)) if (b !== a && b.active && b.space === app.space.id) b.active = false;
|
|
239
|
+
app.env.flow = false;
|
|
240
|
+
app.env.time = time;
|
|
241
|
+
app.state.mode = 'inspect';
|
|
242
|
+
const p = app.player.pos || app.camera.position;
|
|
243
|
+
const x = p.x,
|
|
244
|
+
z = p.z;
|
|
245
|
+
const groundY = typeof app.terrainHeight === 'function' ? app.terrainHeight(x, z) : app.space.ground(x, z);
|
|
246
|
+
a.space = app.space.id;
|
|
247
|
+
a.active = true;
|
|
248
|
+
a.inScene = false;
|
|
249
|
+
a.move = null;
|
|
250
|
+
a.home = null;
|
|
251
|
+
a.x = x;
|
|
252
|
+
a.z = z;
|
|
253
|
+
a.px = x;
|
|
254
|
+
a.pz = z;
|
|
255
|
+
a.yaw = 0.6;
|
|
256
|
+
a.fixY = where === 'sky' ? groundY + 40 : null;
|
|
257
|
+
if (pose) a.pose = pose;
|
|
258
|
+
if (expr) a.expression = expr;
|
|
259
|
+
const b = beside && app.actors[beside];
|
|
260
|
+
if (b) {
|
|
261
|
+
b.space = app.space.id;
|
|
262
|
+
b.active = true;
|
|
263
|
+
b.inScene = false;
|
|
264
|
+
b.move = null;
|
|
265
|
+
b.home = null;
|
|
266
|
+
b.x = b.px = x + 0.95 * Math.cos(0.6);
|
|
267
|
+
b.z = b.pz = z - 0.95 * Math.sin(0.6);
|
|
268
|
+
b.yaw = 0.6;
|
|
269
|
+
b.fixY = a.fixY;
|
|
270
|
+
}
|
|
271
|
+
return 'ok';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Aims the camera at an actor's head bone and sets FOV so the head fills the still at any distance.
|
|
276
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
277
|
+
*
|
|
278
|
+
* @param {{ debug: string, id: string, dist: number, angle: number, view: number, aim: number[] }} arg
|
|
279
|
+
* @returns {string}
|
|
280
|
+
*/
|
|
281
|
+
function aimHeadCameraInPage({ debug, id, dist, angle, view, aim }) {
|
|
282
|
+
const app = window[debug];
|
|
283
|
+
const a = app.actors[id];
|
|
284
|
+
const T = app.THREE;
|
|
285
|
+
a.head.updateWorldMatrix(true, false);
|
|
286
|
+
const h = new T.Vector3(...aim);
|
|
287
|
+
a.head.localToWorld(h);
|
|
288
|
+
const yaw = a.yaw + (angle * Math.PI) / 180;
|
|
289
|
+
const s = a.group.scale.y;
|
|
290
|
+
app.camera.position.set(h.x + Math.sin(yaw) * dist * s, h.y + 0.02 * s, h.z + Math.cos(yaw) * dist * s);
|
|
291
|
+
app.camera.lookAt(h.x, h.y, h.z);
|
|
292
|
+
const fov = (2 * Math.atan((view * s) / dist) * 180) / Math.PI;
|
|
293
|
+
app.camera.fov = fov;
|
|
294
|
+
app.state.baseFov = fov;
|
|
295
|
+
app.camera.updateProjectionMatrix();
|
|
296
|
+
app.camera.updateMatrixWorld();
|
|
297
|
+
return a.kind + ' h ' + s.toFixed(2) + ' head at ' + h.y.toFixed(2) + ' ' + (a.hi && a.hi.visible ? 'near' : 'far');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Shoots five stills (`front`, `three`, `side`, `back`, `face`) of one character where they stand at home.
|
|
302
|
+
*
|
|
303
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
304
|
+
* @param {object} [options]
|
|
305
|
+
* @param {string[]} [options.argv=[]]
|
|
306
|
+
* @param {string} [options.defaultId='']
|
|
307
|
+
* @param {string} [options.address='']
|
|
308
|
+
* @param {Array} [options.views=PERSON_LOOK_VIEWS]
|
|
309
|
+
* @returns {Promise<{ id: string, files: string[] }>}
|
|
310
|
+
*/
|
|
311
|
+
async function runPersonLook(driver, { argv = [], defaultId = '', address = '', views = PERSON_LOOK_VIEWS } = {}) {
|
|
312
|
+
const { name, id, hour, width, height } = parsePersonLookArgs(argv, { defaultId });
|
|
313
|
+
const debug = driver.debug;
|
|
314
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
315
|
+
const ctx = await browser.newContext({ viewport: { width, height } });
|
|
316
|
+
await driver.applyStorage(ctx, { quality: 'high', muted: '1' });
|
|
317
|
+
const page = await ctx.newPage();
|
|
318
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 300)));
|
|
319
|
+
page.on('console', m => m.type() === 'error' && console.log('CONSOLE', m.text().slice(0, 300)));
|
|
320
|
+
await driver.enter(page, driver.routeUrl(address));
|
|
321
|
+
await page.waitForTimeout(2000);
|
|
322
|
+
await page.addStyleTag({ content: '#card, #keys, .card { display: none !important; }' });
|
|
323
|
+
const at = await page.evaluate(locateActorHomeInPage, { debug, id });
|
|
324
|
+
if (!at) {
|
|
325
|
+
console.log('FAILED no character', id);
|
|
326
|
+
await driver.closeBrowser(browser);
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
329
|
+
await page.waitForTimeout(4000);
|
|
330
|
+
await page.evaluate(focusPointForActorInPage, { debug, x: at.x, z: at.z });
|
|
331
|
+
await page.waitForFunction(waitActorNearBuiltInPage, { debug, id }, { timeout: 90000 });
|
|
332
|
+
await page.waitForTimeout(3000);
|
|
333
|
+
const files = [];
|
|
334
|
+
for (const [view, turn, distance, look] of views) {
|
|
335
|
+
const said = await page.evaluate(posePersonViewInPage, { debug, id, turn, distance, look, hour });
|
|
336
|
+
await page.waitForTimeout(2000);
|
|
337
|
+
const outFile = `${driver.OUT}/${name}-${view}.jpg`;
|
|
338
|
+
await page.screenshot({ path: outFile, type: 'jpeg', quality: 86 });
|
|
339
|
+
files.push(outFile);
|
|
340
|
+
console.log('saved', `${name}-${view}`, JSON.stringify(said));
|
|
341
|
+
}
|
|
342
|
+
await driver.closeBrowser(browser);
|
|
343
|
+
return { id, files };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Takes a walking-height still of a crowd member along their street walk.
|
|
348
|
+
*
|
|
349
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
350
|
+
* @param {object} [options]
|
|
351
|
+
* @param {string[]} [options.argv=[]]
|
|
352
|
+
* @returns {Promise<{ info: object, file: string }>}
|
|
353
|
+
*/
|
|
354
|
+
async function runCrowdLook(driver, { argv = [] } = {}) {
|
|
355
|
+
const { name, address, kind, member, hour, metres, width, height, fov } = parseCrowdLookArgs(argv);
|
|
356
|
+
const debug = driver.debug;
|
|
357
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
358
|
+
const page = await browser.newPage({ viewport: { width, height } });
|
|
359
|
+
await driver.applyStorage(page, { quality: 'high', muted: '1' });
|
|
360
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 300)));
|
|
361
|
+
page.on('console', m => (m.type() === 'error' || /WebGL|INVALID/.test(m.text())) && console.log('CONSOLE', m.text().slice(0, 300)));
|
|
362
|
+
await driver.enter(page, driver.routeUrl(address), { titledMs: 180000 });
|
|
363
|
+
await page.waitForTimeout(2500);
|
|
364
|
+
const info = await page.evaluate(positionCrowdLookInPage, { debug, kind, member, hour, metres, fov });
|
|
365
|
+
console.log(JSON.stringify(info));
|
|
366
|
+
await page.waitForTimeout(6000);
|
|
367
|
+
const file = `${driver.OUT}/${name}.jpg`;
|
|
368
|
+
await page.screenshot({ path: file, type: 'jpeg', quality: 86 });
|
|
369
|
+
console.log('saved', name, JSON.stringify(await page.evaluate(d => (window[d].bench ? 'bench there' : ''), debug)));
|
|
370
|
+
console.log(
|
|
371
|
+
'LOG',
|
|
372
|
+
JSON.stringify(await page.evaluate(d => window[d].log('warn').slice(-6).concat(window[d].log('error').slice(-6)), debug)).slice(
|
|
373
|
+
0,
|
|
374
|
+
1200,
|
|
375
|
+
),
|
|
376
|
+
);
|
|
377
|
+
await browser.close();
|
|
378
|
+
return { info, file };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Shoots close-up head stills of named actors and stitches them onto one labelled contact sheet (`<OUT>/<name>.jpg`).
|
|
383
|
+
*
|
|
384
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
385
|
+
* @param {object} [options]
|
|
386
|
+
* @param {string[]} [options.argv=[]]
|
|
387
|
+
* @param {string} [options.defaultIds='']
|
|
388
|
+
* @returns {Promise<{ file: string, count: number }>}
|
|
389
|
+
*/
|
|
390
|
+
async function runHeadSheet(driver, { argv = [], defaultIds = '' } = {}) {
|
|
391
|
+
const parsed = parseHeadSheetArgs(argv, { defaultIds });
|
|
392
|
+
const debug = driver.debug;
|
|
393
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
394
|
+
const page = await browser.newPage({ viewport: { width: parsed.cell, height: parsed.cell } });
|
|
395
|
+
await driver.applyStorage(page, { quality: 'high' });
|
|
396
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 300)));
|
|
397
|
+
page.on('console', m => (m.type() === 'error' || /WebGL|INVALID/.test(m.text())) && console.log('CONSOLE', m.text().slice(0, 300)));
|
|
398
|
+
await driver.enter(page, driver.routeUrl(parsed.address), { titledMs: 180000 });
|
|
399
|
+
await page.waitForTimeout(3000);
|
|
400
|
+
await page.evaluate(
|
|
401
|
+
([d, selectors]) => {
|
|
402
|
+
if (window[d].holdQuality) window[d].holdQuality(true);
|
|
403
|
+
document.querySelectorAll(selectors).forEach(e => (e.style.display = 'none'));
|
|
404
|
+
},
|
|
405
|
+
[debug, DEFAULT_HUD_SELECTORS],
|
|
406
|
+
);
|
|
407
|
+
if (parsed.script) console.log('script ->', JSON.stringify(await page.evaluate(parsed.script)));
|
|
408
|
+
const shots = [];
|
|
409
|
+
for (const id of parsed.ids) {
|
|
410
|
+
const r = await page.evaluate(placeHeadActorInPage, {
|
|
411
|
+
debug,
|
|
412
|
+
id,
|
|
413
|
+
time: parsed.time,
|
|
414
|
+
where: parsed.where,
|
|
415
|
+
pose: parsed.pose,
|
|
416
|
+
expr: parsed.expr,
|
|
417
|
+
beside: parsed.beside,
|
|
418
|
+
});
|
|
419
|
+
if (r !== 'ok') {
|
|
420
|
+
console.log(r);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
await page.waitForTimeout(900);
|
|
424
|
+
const aim = await page.evaluate(aimHeadCameraInPage, {
|
|
425
|
+
debug,
|
|
426
|
+
id,
|
|
427
|
+
dist: parsed.dist,
|
|
428
|
+
angle: parsed.angle,
|
|
429
|
+
view: parsed.view,
|
|
430
|
+
aim: parsed.aim,
|
|
431
|
+
});
|
|
432
|
+
for (let k = 0; k < parsed.frames; k++) {
|
|
433
|
+
await page.waitForTimeout(k ? 170 : 500);
|
|
434
|
+
shots.push([id, (await page.screenshot({ type: 'jpeg', quality: 85 })).toString('base64')]);
|
|
435
|
+
}
|
|
436
|
+
console.log(id, aim);
|
|
437
|
+
}
|
|
438
|
+
const cols = Math.min(shots.length || 1, parsed.cols);
|
|
439
|
+
const rows = Math.ceil(shots.length / cols) || 1;
|
|
440
|
+
const sheet = await browser.newPage({ viewport: { width: cols * parsed.cell, height: rows * (parsed.cell + 18) } });
|
|
441
|
+
await sheet.setContent(
|
|
442
|
+
`<body style="margin:0;background:#222;display:grid;grid-template-columns:repeat(${cols},${parsed.cell}px);font:12px sans-serif;color:#ddd">` +
|
|
443
|
+
shots
|
|
444
|
+
.map(
|
|
445
|
+
([id, b]) =>
|
|
446
|
+
`<div><img src="data:image/jpeg;base64,${b}" width=${parsed.cell} height=${parsed.cell} style="display:block"><div style="height:18px">${id}</div></div>`,
|
|
447
|
+
)
|
|
448
|
+
.join('') +
|
|
449
|
+
'</body>',
|
|
450
|
+
);
|
|
451
|
+
await sheet.waitForTimeout(300);
|
|
452
|
+
const file = `${driver.OUT}/${parsed.name}.jpg`;
|
|
453
|
+
await sheet.screenshot({ path: file, type: 'jpeg', quality: 82, fullPage: true });
|
|
454
|
+
console.log('saved', parsed.name);
|
|
455
|
+
await browser.close();
|
|
456
|
+
return { file, count: shots.length };
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
module.exports = {
|
|
460
|
+
PERSON_LOOK_VIEWS,
|
|
461
|
+
aimHeadCameraInPage,
|
|
462
|
+
focusPointForActorInPage,
|
|
463
|
+
headCameraFov,
|
|
464
|
+
locateActorHomeInPage,
|
|
465
|
+
parseCrowdLookArgs,
|
|
466
|
+
parseHeadSheetArgs,
|
|
467
|
+
parsePersonLookArgs,
|
|
468
|
+
placeHeadActorInPage,
|
|
469
|
+
posePersonViewInPage,
|
|
470
|
+
positionCrowdLookInPage,
|
|
471
|
+
runCrowdLook,
|
|
472
|
+
runHeadSheet,
|
|
473
|
+
runPersonLook,
|
|
474
|
+
waitActorNearBuiltInPage,
|
|
475
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const {
|
|
5
|
+
PERSON_LOOK_VIEWS,
|
|
6
|
+
aimHeadCameraInPage,
|
|
7
|
+
focusPointForActorInPage,
|
|
8
|
+
headCameraFov,
|
|
9
|
+
locateActorHomeInPage,
|
|
10
|
+
parseCrowdLookArgs,
|
|
11
|
+
parseHeadSheetArgs,
|
|
12
|
+
parsePersonLookArgs,
|
|
13
|
+
placeHeadActorInPage,
|
|
14
|
+
posePersonViewInPage,
|
|
15
|
+
positionCrowdLookInPage,
|
|
16
|
+
waitActorNearBuiltInPage,
|
|
17
|
+
} = require('./figure-inspect.cjs');
|
|
18
|
+
|
|
19
|
+
test('figure-inspect arg parsers decode CLI options and caller defaults', () => {
|
|
20
|
+
assert.deepEqual(parsePersonLookArgs(['hero', 'scout', '0.5', '800', '600']), {
|
|
21
|
+
name: 'hero',
|
|
22
|
+
id: 'scout',
|
|
23
|
+
hour: 0.5,
|
|
24
|
+
width: 800,
|
|
25
|
+
height: 600,
|
|
26
|
+
});
|
|
27
|
+
assert.equal(parsePersonLookArgs([], { defaultId: 'guide' }).id, 'guide');
|
|
28
|
+
assert.equal(PERSON_LOOK_VIEWS.length, 5);
|
|
29
|
+
|
|
30
|
+
assert.deepEqual(parseCrowdLookArgs(['street', 'location/port', 'city', '3', '0.4', '5', '960', '540', '42']), {
|
|
31
|
+
name: 'street',
|
|
32
|
+
address: 'location/port',
|
|
33
|
+
kind: 'city',
|
|
34
|
+
member: 3,
|
|
35
|
+
hour: 0.4,
|
|
36
|
+
metres: 5,
|
|
37
|
+
width: 960,
|
|
38
|
+
height: 540,
|
|
39
|
+
fov: 42,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const head = parseHeadSheetArgs(
|
|
43
|
+
['sheet', '', 'a,b', '0.45', '0.9', '20', 'sky', '', 'cell=280;view=0.12;pose=talk;frames=5;expr=[1,0,0,0];cols=3;beside=c'],
|
|
44
|
+
{ defaultIds: 'fallback' },
|
|
45
|
+
);
|
|
46
|
+
assert.deepEqual(head.ids, ['a', 'b']);
|
|
47
|
+
assert.equal(head.cell, 280);
|
|
48
|
+
assert.equal(head.view, 0.12);
|
|
49
|
+
assert.equal(head.pose, 'talk');
|
|
50
|
+
assert.deepEqual(head.expr, [1, 0, 0, 0]);
|
|
51
|
+
assert.equal(head.frames, 5);
|
|
52
|
+
assert.equal(head.cols, 3);
|
|
53
|
+
assert.equal(head.beside, 'c');
|
|
54
|
+
assert.ok(Math.abs(headCameraFov(0.2, 1.0, 0.9) - 25.0576) < 0.01);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('figure-inspect in-page helpers talk strictly through window[debug]', () => {
|
|
58
|
+
class Vector3 {
|
|
59
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
60
|
+
this.x = x;
|
|
61
|
+
this.y = y;
|
|
62
|
+
this.z = z;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class Box3 {
|
|
66
|
+
setFromObject() {
|
|
67
|
+
this.min = { y: 1 };
|
|
68
|
+
this.max = { y: 2.8 };
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let placed = null;
|
|
73
|
+
const camPos = {
|
|
74
|
+
x: 0,
|
|
75
|
+
y: 0,
|
|
76
|
+
z: 0,
|
|
77
|
+
set(x, y, z) {
|
|
78
|
+
this.x = x;
|
|
79
|
+
this.y = y;
|
|
80
|
+
this.z = z;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const actorA = {
|
|
84
|
+
kind: 'human',
|
|
85
|
+
built: true,
|
|
86
|
+
nearBuilt: true,
|
|
87
|
+
active: false,
|
|
88
|
+
space: 'valley',
|
|
89
|
+
def: { home: { at: 'square', d: [2, -3] } },
|
|
90
|
+
group: { position: { x: 12, y: 1, z: 7 }, rotation: { y: 0 }, scale: { y: 1.05 } },
|
|
91
|
+
hi: { visible: true },
|
|
92
|
+
head: {
|
|
93
|
+
updateWorldMatrix() {},
|
|
94
|
+
localToWorld(v) {
|
|
95
|
+
v.x += 12;
|
|
96
|
+
v.y += 2.6;
|
|
97
|
+
v.z += 7;
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
const actorB = { kind: 'human', active: true, space: 'valley' };
|
|
102
|
+
|
|
103
|
+
globalThis.window = {
|
|
104
|
+
APP: {
|
|
105
|
+
THREE: { Vector3, Box3 },
|
|
106
|
+
P: { square: { x: 10, z: 10 } },
|
|
107
|
+
space: { id: 'valley', ground: () => 1 },
|
|
108
|
+
terrainHeight: () => 2,
|
|
109
|
+
player: { pos: { x: 12, z: 7 } },
|
|
110
|
+
state: { mode: 'play', fly: true, baseFov: 50 },
|
|
111
|
+
env: { flow: true, time: 0.5 },
|
|
112
|
+
camera: {
|
|
113
|
+
fov: 50,
|
|
114
|
+
position: camPos,
|
|
115
|
+
lookAt() {},
|
|
116
|
+
updateProjectionMatrix() {},
|
|
117
|
+
updateMatrixWorld() {},
|
|
118
|
+
},
|
|
119
|
+
actors: { a: actorA, b: actorB },
|
|
120
|
+
crowds: [{ kind: 'city', list: [{ ax: 0, az: 0, bx: 10, bz: 0, look: 2 }] }],
|
|
121
|
+
holdQuality() {},
|
|
122
|
+
setFly(f) {
|
|
123
|
+
this.state.fly = f;
|
|
124
|
+
},
|
|
125
|
+
placePlayer(x, z, yaw) {
|
|
126
|
+
placed = { x, z, yaw };
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
assert.deepEqual(locateActorHomeInPage({ debug: 'APP', id: 'a' }), { x: 12, z: 7 });
|
|
132
|
+
assert.deepEqual(placed, { x: 18, z: 13, yaw: 0 });
|
|
133
|
+
focusPointForActorInPage({ debug: 'APP', x: 12, z: 7 });
|
|
134
|
+
assert.equal(waitActorNearBuiltInPage({ debug: 'APP', id: 'a' }), true);
|
|
135
|
+
assert.deepEqual(posePersonViewInPage({ debug: 'APP', id: 'a', turn: 0, distance: 2.6, look: 0.55, hour: 0.4 }), { tall: 1.8 });
|
|
136
|
+
|
|
137
|
+
const crowd = positionCrowdLookInPage({ debug: 'APP', kind: 'city', member: 0, hour: 0.5, metres: 4, fov: 40 });
|
|
138
|
+
assert.deepEqual(crowd, { members: 1, at: [5, 0], looks: '2' });
|
|
139
|
+
assert.equal(globalThis.window.APP.state.fly, false);
|
|
140
|
+
assert.equal(globalThis.window.APP.camera.fov, 40);
|
|
141
|
+
|
|
142
|
+
assert.equal(
|
|
143
|
+
placeHeadActorInPage({ debug: 'APP', id: 'a', time: 0.4, where: 'sky', pose: 'talk', expr: [1, 0, 0, 0], beside: 'b' }),
|
|
144
|
+
'ok',
|
|
145
|
+
);
|
|
146
|
+
assert.equal(actorA.fixY, 42);
|
|
147
|
+
assert.equal(actorB.active, true);
|
|
148
|
+
const desc = aimHeadCameraInPage({ debug: 'APP', id: 'a', dist: 0.9, angle: 20, view: 0.2, aim: [0, 0.12, 0.03] });
|
|
149
|
+
assert.match(desc, /^human h 1\.05 head at 2\.72 near$/);
|
|
150
|
+
} finally {
|
|
151
|
+
delete globalThis.window;
|
|
152
|
+
}
|
|
153
|
+
});
|