roamwright 0.61.9 → 0.61.11
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/geometry/animal-ear.js +5 -12
- package/package.json +2 -1
- package/scripts/browser-scripts.mjs +4 -2
- package/scripts/build.py +404 -0
- package/tools/README.md +11 -0
- package/tools/bake-publish.cjs +212 -0
- package/tools/build-freshness.cjs +148 -0
- package/tools/look-guard.sh +61 -0
- package/tools/motion-lab.cjs +451 -0
- package/tools/motion-lab.test.cjs +43 -0
- package/tools/phone-guard.py +161 -0
- package/tools/remote-runner.sh +4 -1
- package/tools/runners.test.cjs +92 -0
- package/tools/runtime-checks.test.cjs +53 -0
- package/tools/scene-lint.cjs +301 -0
- package/tools/scene-lint.test.cjs +75 -0
- package/tools/service-worker-check.cjs +257 -0
- package/tools/set-cost.cjs +110 -0
- package/tools/speed-guard.sh +124 -0
- package/tools/travel-free.cjs +90 -0
- package/tools/viewport-check.cjs +228 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
// Generic figure motion bench built on a Roamwright page driver: plays short synthetic scenarios
|
|
2
|
+
// (walk, run, turn, bow, handover, combat, poses) through the world's scene director on open ground,
|
|
3
|
+
// stepped at a fixed frame interval with the render loop held, and writes labelled contact sheets.
|
|
4
|
+
//
|
|
5
|
+
// const { createStandardScenarios, runMotionLab } = require('roamwright/tools/motion-lab.cjs');
|
|
6
|
+
// await runMotionLab(driver, { scenarios: createStandardScenarios({ primary: 'scout', partner: 'guard' }), args });
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const DEFAULT_VIEWS = Object.freeze({
|
|
10
|
+
SIDE: { from: [0, 1.0, 5.2], look: [0, 0.95, 0], fov: 30 },
|
|
11
|
+
FRONT: { from: [5.2, 1.0, 0], look: [0, 0.95, 0], fov: 30 },
|
|
12
|
+
THREE_QUARTER: { from: [-1.2, 1.35, 4.3], look: [0, 1.0, 0], fov: 30 },
|
|
13
|
+
PAIR: { from: [0.75, 1.25, 4.2], look: [0.75, 1.05, 0], fov: 30 },
|
|
14
|
+
WIDE_TILE: { cols: 4, tile: [450, 450] },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Builds the standard motion-bench scenario table parameterized by two cast actor ids and a handover prop id.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} [options]
|
|
21
|
+
* @param {string} [options.primary='actorA'] Primary figure id.
|
|
22
|
+
* @param {string} [options.partner='actorB'] Partner figure id for two-person scenarios.
|
|
23
|
+
* @param {string} [options.handoverProp='note'] Prop id used in the `give` handover scenario.
|
|
24
|
+
* @returns {Record<string, object>}
|
|
25
|
+
*/
|
|
26
|
+
function createStandardScenarios({ primary = 'actorA', partner = 'actorB', handoverProp = 'note' } = {}) {
|
|
27
|
+
const { SIDE, FRONT, THREE_QUARTER, PAIR, WIDE_TILE } = DEFAULT_VIEWS;
|
|
28
|
+
const two = { [primary]: { p: [0, 0], face: [5, 0] }, [partner]: { p: [1.5, 0], face: [-5, 0] } };
|
|
29
|
+
const duelPair = { [primary]: { p: [-1.2, 0], face: [5, 0] }, [partner]: { p: [1.2, 0], face: [-5, 0] } };
|
|
30
|
+
const closePair = { [primary]: { p: [-0.9, 0], face: [5, 0] }, [partner]: { p: [0.9, 0], face: [-5, 0] } };
|
|
31
|
+
return {
|
|
32
|
+
walk: {
|
|
33
|
+
cast: { [primary]: { p: [-6, 0], face: [5, 0] } },
|
|
34
|
+
steps: [[0.2, 'move', primary, 6, 0, 8.6]],
|
|
35
|
+
dur: 9,
|
|
36
|
+
view: { follow: primary, ...SIDE },
|
|
37
|
+
every: 0.1,
|
|
38
|
+
from: 3,
|
|
39
|
+
to: 5.3,
|
|
40
|
+
},
|
|
41
|
+
walkfront: {
|
|
42
|
+
cast: { [primary]: { p: [-6, 0], face: [5, 0] } },
|
|
43
|
+
steps: [[0.2, 'move', primary, 6, 0, 8.6]],
|
|
44
|
+
dur: 9,
|
|
45
|
+
view: { follow: primary, ...FRONT },
|
|
46
|
+
every: 0.1,
|
|
47
|
+
from: 3,
|
|
48
|
+
to: 5.3,
|
|
49
|
+
},
|
|
50
|
+
start: {
|
|
51
|
+
cast: { [primary]: { p: [-2, 0], face: [0, 5] } },
|
|
52
|
+
steps: [[0.5, 'move', primary, 3, 0, 4.2]],
|
|
53
|
+
dur: 6,
|
|
54
|
+
view: { follow: primary, ...SIDE },
|
|
55
|
+
every: 0.2,
|
|
56
|
+
from: 0.2,
|
|
57
|
+
to: 5.6,
|
|
58
|
+
},
|
|
59
|
+
run: {
|
|
60
|
+
cast: { [primary]: { p: [-12, 0], face: [5, 0] } },
|
|
61
|
+
steps: [[0.2, 'move', primary, 12, 0, 5.4]],
|
|
62
|
+
dur: 6,
|
|
63
|
+
view: { follow: primary, ...SIDE },
|
|
64
|
+
every: 0.05,
|
|
65
|
+
from: 2.5,
|
|
66
|
+
to: 3.65,
|
|
67
|
+
},
|
|
68
|
+
turn: {
|
|
69
|
+
cast: { [primary]: { p: [-3, 0], face: [5, 0] } },
|
|
70
|
+
steps: [
|
|
71
|
+
[0.2, 'move', primary, 1.5, 0, 3.4],
|
|
72
|
+
[3.8, 'move', primary, -3, 0.4, 3.6],
|
|
73
|
+
],
|
|
74
|
+
dur: 8,
|
|
75
|
+
view: { follow: [0, 0, 0], from: [0, 1.6, 7], look: [0, 0.9, 0], fov: 34 },
|
|
76
|
+
every: 0.25,
|
|
77
|
+
from: 2.5,
|
|
78
|
+
to: 8,
|
|
79
|
+
},
|
|
80
|
+
bow: {
|
|
81
|
+
...WIDE_TILE,
|
|
82
|
+
cast: two,
|
|
83
|
+
steps: [[0.5, 'act', primary, 'bow', partner]],
|
|
84
|
+
dur: 3.6,
|
|
85
|
+
view: { follow: primary, ...PAIR },
|
|
86
|
+
every: 0.15,
|
|
87
|
+
from: 0.4,
|
|
88
|
+
to: 3.2,
|
|
89
|
+
},
|
|
90
|
+
give: {
|
|
91
|
+
...WIDE_TILE,
|
|
92
|
+
cast: two,
|
|
93
|
+
steps: [
|
|
94
|
+
[0.1, 'prop', handoverProp, 'hand', primary],
|
|
95
|
+
[1, 'act', primary, 'give', partner],
|
|
96
|
+
[1.9, 'prop', handoverProp, 'hand', partner, undefined, 0.3],
|
|
97
|
+
],
|
|
98
|
+
dur: 4.4,
|
|
99
|
+
view: { follow: primary, ...PAIR },
|
|
100
|
+
every: 0.15,
|
|
101
|
+
from: 0.8,
|
|
102
|
+
to: 4,
|
|
103
|
+
},
|
|
104
|
+
punch: {
|
|
105
|
+
...WIDE_TILE,
|
|
106
|
+
cast: two,
|
|
107
|
+
steps: [[0.6, 'act', primary, 'punch', partner]],
|
|
108
|
+
dur: 3,
|
|
109
|
+
view: { follow: primary, ...PAIR },
|
|
110
|
+
every: 0.08,
|
|
111
|
+
from: 0.5,
|
|
112
|
+
to: 2.3,
|
|
113
|
+
},
|
|
114
|
+
draw: {
|
|
115
|
+
cast: { [primary]: { p: [0, 0], face: [1.5, 4] } },
|
|
116
|
+
steps: [
|
|
117
|
+
[0.5, 'act', primary, 'draw'],
|
|
118
|
+
[2.6, 'act', primary, 'sheathe'],
|
|
119
|
+
],
|
|
120
|
+
dur: 4.4,
|
|
121
|
+
view: { follow: primary, ...THREE_QUARTER },
|
|
122
|
+
every: 0.15,
|
|
123
|
+
from: 0.4,
|
|
124
|
+
to: 4.2,
|
|
125
|
+
},
|
|
126
|
+
duel: {
|
|
127
|
+
...WIDE_TILE,
|
|
128
|
+
cast: duelPair,
|
|
129
|
+
steps: [
|
|
130
|
+
[0.3, 'act', primary, 'draw'],
|
|
131
|
+
[0.3, 'act', partner, 'draw'],
|
|
132
|
+
[1.6, 'duel', primary, partner, 6],
|
|
133
|
+
],
|
|
134
|
+
dur: 8.4,
|
|
135
|
+
view: { follow: [0, 0, 0], from: [0, 1.4, 5.4], look: [0, 1.0, 0], fov: 32 },
|
|
136
|
+
every: 0.15,
|
|
137
|
+
from: 1.5,
|
|
138
|
+
to: 5.0,
|
|
139
|
+
},
|
|
140
|
+
parry: {
|
|
141
|
+
...WIDE_TILE,
|
|
142
|
+
cast: closePair,
|
|
143
|
+
steps: [
|
|
144
|
+
[0.3, 'act', primary, 'draw'],
|
|
145
|
+
[0.3, 'act', partner, 'draw'],
|
|
146
|
+
[2, 'attack', primary, partner, 'parry'],
|
|
147
|
+
],
|
|
148
|
+
dur: 5,
|
|
149
|
+
view: { follow: [0, 0, 0], from: [0, 1.3, 4.6], look: [0, 1.0, 0], fov: 32 },
|
|
150
|
+
every: 0.1,
|
|
151
|
+
from: 1.7,
|
|
152
|
+
to: 4.0,
|
|
153
|
+
},
|
|
154
|
+
slay: {
|
|
155
|
+
...WIDE_TILE,
|
|
156
|
+
cast: closePair,
|
|
157
|
+
steps: [
|
|
158
|
+
[0.3, 'act', primary, 'draw'],
|
|
159
|
+
[0.3, 'act', partner, 'draw'],
|
|
160
|
+
[2, 'attack', partner, primary, 'kill'],
|
|
161
|
+
],
|
|
162
|
+
dur: 7.5,
|
|
163
|
+
view: { follow: [0, 0, 0], from: [0, 1.3, 4.9], look: [0, 0.9, 0], fov: 32 },
|
|
164
|
+
every: 0.15,
|
|
165
|
+
from: 1.85,
|
|
166
|
+
to: 5.3,
|
|
167
|
+
},
|
|
168
|
+
kill: {
|
|
169
|
+
...WIDE_TILE,
|
|
170
|
+
cast: duelPair,
|
|
171
|
+
steps: [
|
|
172
|
+
[0.3, 'act', primary, 'draw'],
|
|
173
|
+
[0.3, 'act', partner, 'draw'],
|
|
174
|
+
[1.6, 'duel', partner, primary, 2.4, 'kill'],
|
|
175
|
+
],
|
|
176
|
+
dur: 7,
|
|
177
|
+
view: { follow: [0, 0, 0], from: [0, 1.4, 5.4], look: [0, 0.9, 0], fov: 32 },
|
|
178
|
+
every: 0.15,
|
|
179
|
+
from: 2.6,
|
|
180
|
+
to: 6.1,
|
|
181
|
+
},
|
|
182
|
+
poses: {
|
|
183
|
+
cast: { [primary]: { p: [0, 0], face: [1.5, 4] } },
|
|
184
|
+
steps: [
|
|
185
|
+
'talk',
|
|
186
|
+
'point',
|
|
187
|
+
'reach',
|
|
188
|
+
'kneel',
|
|
189
|
+
'cower',
|
|
190
|
+
'crouch',
|
|
191
|
+
'sit',
|
|
192
|
+
'sittalk',
|
|
193
|
+
'carry',
|
|
194
|
+
'guard',
|
|
195
|
+
'strike',
|
|
196
|
+
'cast',
|
|
197
|
+
'search',
|
|
198
|
+
'rest',
|
|
199
|
+
'idle',
|
|
200
|
+
].map((pose, i) => [0.2 + i * 2.2, 'pose', primary, pose]),
|
|
201
|
+
dur: 33.5,
|
|
202
|
+
view: { follow: primary, ...THREE_QUARTER },
|
|
203
|
+
every: 1.1,
|
|
204
|
+
from: 1.2,
|
|
205
|
+
to: 33.2,
|
|
206
|
+
},
|
|
207
|
+
talk: {
|
|
208
|
+
cast: { [primary]: { p: [0, 0], face: [1.5, 4] } },
|
|
209
|
+
steps: [
|
|
210
|
+
[0.4, 'pose', primary, 'talk'],
|
|
211
|
+
[6.4, 'pose', primary, 'point'],
|
|
212
|
+
[9.4, 'pose', primary, 'idle'],
|
|
213
|
+
],
|
|
214
|
+
dur: 11,
|
|
215
|
+
view: { follow: primary, ...THREE_QUARTER },
|
|
216
|
+
every: 0.45,
|
|
217
|
+
from: 0.3,
|
|
218
|
+
to: 10.7,
|
|
219
|
+
},
|
|
220
|
+
kneel: {
|
|
221
|
+
cast: { [primary]: { p: [0, 0], face: [1.5, 4] } },
|
|
222
|
+
steps: [
|
|
223
|
+
[0.4, 'pose', primary, 'kneel'],
|
|
224
|
+
[3.4, 'pose', primary, 'idle'],
|
|
225
|
+
],
|
|
226
|
+
dur: 6,
|
|
227
|
+
view: { follow: primary, ...THREE_QUARTER },
|
|
228
|
+
every: 0.2,
|
|
229
|
+
from: 0.3,
|
|
230
|
+
to: 5.9,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Parses CLI arguments for the motion bench (`--list`, `--trace`, named scenarios, or inline JSON).
|
|
237
|
+
*
|
|
238
|
+
* @param {string[]} argv Raw CLI arguments (excluding `node` and script path).
|
|
239
|
+
* @param {Record<string, object>} scenarios Named scenario map.
|
|
240
|
+
* @returns {{ list: boolean, trace: boolean, asked: Array<[string, object]>, missing: string[] }}
|
|
241
|
+
*/
|
|
242
|
+
function parseMotionLabArgs(argv, scenarios) {
|
|
243
|
+
const trace = argv.includes('--trace');
|
|
244
|
+
const raw = argv.filter(a => a !== '--trace');
|
|
245
|
+
const list = raw.includes('--list');
|
|
246
|
+
if (list) return { list: true, trace, asked: [], missing: [] };
|
|
247
|
+
const asked = raw.map(a => (a.trim().startsWith('{') ? ['own', JSON.parse(a)] : [a, scenarios[a]]));
|
|
248
|
+
const missing = asked.filter(([, s]) => !s).map(([name]) => name);
|
|
249
|
+
return { list: false, trace, asked, missing };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Runs one or more motion-bench scenarios in a headless browser and saves labelled JPEG contact sheets.
|
|
254
|
+
*
|
|
255
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
256
|
+
* @param {object} options
|
|
257
|
+
* @param {Record<string, object>} options.scenarios Named scenario map.
|
|
258
|
+
* @param {string[]} [options.argv=[]] CLI arguments.
|
|
259
|
+
* @param {{ space?: string, at?: string, off?: [number, number], time?: number }} [options.defaultAnchor] Default open-ground anchor.
|
|
260
|
+
* @param {number} [options.step=1/60] Fixed simulation step size in seconds.
|
|
261
|
+
* @param {number} [options.tilesPerSheet=24] Maximum tiles per JPEG sheet.
|
|
262
|
+
* @param {{ width: number, height: number }} [options.viewport] Capture viewport size.
|
|
263
|
+
* @param {string} [options.perfId='perf'] Performance HUD element id to hide during capture.
|
|
264
|
+
* @param {string} [options.sceneOverlayId='scene'] Scene caption overlay element id to hide during capture.
|
|
265
|
+
* @returns {Promise<number>} Process exit status (`0` OK, `1` page errors, `2` usage error).
|
|
266
|
+
*/
|
|
267
|
+
async function runMotionLab(
|
|
268
|
+
driver,
|
|
269
|
+
{
|
|
270
|
+
scenarios,
|
|
271
|
+
argv = [],
|
|
272
|
+
defaultAnchor = { space: 'world', at: '', off: [0, 0], time: 0.5 },
|
|
273
|
+
step = 1 / 60,
|
|
274
|
+
tilesPerSheet = 24,
|
|
275
|
+
viewport = { width: 1440, height: 900 },
|
|
276
|
+
perfId = 'perf',
|
|
277
|
+
sceneOverlayId = 'scene',
|
|
278
|
+
} = {},
|
|
279
|
+
) {
|
|
280
|
+
const { list, trace, asked, missing } = parseMotionLabArgs(argv, scenarios);
|
|
281
|
+
if (list) {
|
|
282
|
+
console.log(Object.keys(scenarios).join(' '));
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
if (!asked.length || missing.length) {
|
|
286
|
+
console.error(
|
|
287
|
+
missing.length ? 'no scenario called ' + missing.join(', ') : 'usage: node motion-lab.cjs <scenario | JSON> [...]',
|
|
288
|
+
'\n',
|
|
289
|
+
Object.keys(scenarios).join(' '),
|
|
290
|
+
);
|
|
291
|
+
return 2;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const { chromium, shell, BASE, OUT, GPU, debug, enter, applyStorage, closeBrowser } = driver;
|
|
295
|
+
const browser = await chromium.launch({ executablePath: shell, ...GPU });
|
|
296
|
+
try {
|
|
297
|
+
const ctx = await browser.newContext({ viewport });
|
|
298
|
+
await applyStorage(ctx, { quality: 'high', muted: '1' });
|
|
299
|
+
const page = await ctx.newPage();
|
|
300
|
+
const sheet = await ctx.newPage();
|
|
301
|
+
const errors = new Set();
|
|
302
|
+
page.on('pageerror', e => errors.add('PAGE ' + e.message.slice(0, 300)));
|
|
303
|
+
page.on('console', m => m.type() === 'error' && errors.add('console ' + m.text().slice(0, 300)));
|
|
304
|
+
await enter(page, BASE + '?v=' + Date.now(), { titledMs: 180000 });
|
|
305
|
+
await page.waitForTimeout(2000);
|
|
306
|
+
|
|
307
|
+
for (const [name, scenario] of asked) {
|
|
308
|
+
const { cols = 6, tile = [300, 400], every = 0.1, from = 0, to = scenario.dur } = scenario;
|
|
309
|
+
await page.evaluate(
|
|
310
|
+
({ s, d, anchor, pId }) => {
|
|
311
|
+
const app = window[d];
|
|
312
|
+
const perf = document.getElementById(pId);
|
|
313
|
+
if (perf) perf.hidden = true;
|
|
314
|
+
app.state.debug = false;
|
|
315
|
+
app.startScene(
|
|
316
|
+
{
|
|
317
|
+
id: 'lab',
|
|
318
|
+
n: 1,
|
|
319
|
+
title: '',
|
|
320
|
+
where: '',
|
|
321
|
+
space: s.space || anchor.space || 'world',
|
|
322
|
+
at: s.at || anchor.at || '',
|
|
323
|
+
off: s.off || anchor.off || [0, 0],
|
|
324
|
+
time: s.time ?? anchor.time ?? 0.5,
|
|
325
|
+
dur: s.dur + 5,
|
|
326
|
+
plates: 0,
|
|
327
|
+
narration: [''],
|
|
328
|
+
cast: s.cast,
|
|
329
|
+
steps: [[0, 'master', s.dur + 5], ...s.steps].sort((a, b) => a[0] - b[0]),
|
|
330
|
+
cam: [
|
|
331
|
+
[0, 0, 1.6, 6, 0, 1, 0],
|
|
332
|
+
[s.dur + 5, 0, 1.6, 6, 0, 1, 0],
|
|
333
|
+
],
|
|
334
|
+
},
|
|
335
|
+
true,
|
|
336
|
+
);
|
|
337
|
+
},
|
|
338
|
+
{ s: scenario, d: debug, anchor: defaultAnchor, pId: perfId },
|
|
339
|
+
);
|
|
340
|
+
await page.waitForFunction(
|
|
341
|
+
d => {
|
|
342
|
+
const dir = window[d].director;
|
|
343
|
+
return (dir.ev && dir.ready) || (!dir.ev && !dir.preparing);
|
|
344
|
+
},
|
|
345
|
+
debug,
|
|
346
|
+
{ timeout: 180000 },
|
|
347
|
+
);
|
|
348
|
+
if (!(await page.evaluate(d => Boolean(window[d].director.ev && window[d].director.ready), debug)))
|
|
349
|
+
throw new Error(name + ': the bench could not be set up');
|
|
350
|
+
await page.evaluate(
|
|
351
|
+
({ d, ovId }) => {
|
|
352
|
+
window[d].state.measuring = true;
|
|
353
|
+
const overlay = document.getElementById(ovId);
|
|
354
|
+
if (overlay) overlay.hidden = true;
|
|
355
|
+
window.labFastest = {};
|
|
356
|
+
window.labProbe = { hipLow: 9, hipHigh: 0, slope: 0 };
|
|
357
|
+
},
|
|
358
|
+
{ d: debug, ovId: sceneOverlayId },
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
const tiles = [];
|
|
362
|
+
for (let t = from; t <= to + 1e-6; t += every) {
|
|
363
|
+
const read = await page.evaluate(
|
|
364
|
+
({ until, dt, view, d }) => {
|
|
365
|
+
const app = window[d];
|
|
366
|
+
const dir = app.director;
|
|
367
|
+
const cam = app.camera;
|
|
368
|
+
const who0 = typeof view.follow === 'string' ? app.actors[view.follow] : null;
|
|
369
|
+
while (dir.ev && dir.t < until - 1e-6) {
|
|
370
|
+
app.step(Math.min(dt, until - dir.t));
|
|
371
|
+
for (const id in dir.ev.cast) window.labFastest[id] = Math.max(window.labFastest[id] || 0, app.actors[id].speed);
|
|
372
|
+
if (who0) {
|
|
373
|
+
const p = window.labProbe;
|
|
374
|
+
p.hipLow = Math.min(p.hipLow, who0.hip);
|
|
375
|
+
p.hipHigh = Math.max(p.hipHigh, who0.hip);
|
|
376
|
+
p.slope = Math.max(p.slope, Math.abs(who0.slope));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const who = typeof view.follow === 'string' ? app.actors[view.follow] : null;
|
|
380
|
+
const x = who ? who.x : dir.A.x + view.follow[0];
|
|
381
|
+
const y = who ? who.y : dir.A.y + view.follow[1];
|
|
382
|
+
const z = who ? who.z : dir.A.z + view.follow[2];
|
|
383
|
+
cam.position.set(x + view.from[0], y + view.from[1], z + view.from[2]);
|
|
384
|
+
cam.lookAt(x + view.look[0], y + view.look[1], z + view.look[2]);
|
|
385
|
+
cam.fov = view.fov;
|
|
386
|
+
cam.updateProjectionMatrix();
|
|
387
|
+
cam.updateMatrixWorld();
|
|
388
|
+
for (let i = 0; i < 8; i++) app.draw(); // settle temporal accumulation with no ghost of the last pose
|
|
389
|
+
const f = who && who.feet;
|
|
390
|
+
return who
|
|
391
|
+
? [who.speed, who.hip, f ? f[0] : 0, f ? f[1] : 0, f ? f[4] : 0, f ? f[5] : 0, who.x - dir.A.x, who.z - dir.A.z].map(
|
|
392
|
+
v => +v.toFixed(3),
|
|
393
|
+
)
|
|
394
|
+
: null;
|
|
395
|
+
},
|
|
396
|
+
{ until: t, dt: step, view: scenario.view, d: debug },
|
|
397
|
+
);
|
|
398
|
+
const clip = {
|
|
399
|
+
x: (viewport.width - tile[0] * 2) / 2,
|
|
400
|
+
y: (viewport.height - tile[1] * 2) / 2,
|
|
401
|
+
width: tile[0] * 2,
|
|
402
|
+
height: tile[1] * 2,
|
|
403
|
+
};
|
|
404
|
+
if (read && trace)
|
|
405
|
+
console.log(
|
|
406
|
+
` ${t.toFixed(2)} s: ${read[0]} m/s, hips ${read[1]}, feet ahead ${read[2]} ${read[3]}, lifted ${read[4]} ${read[5]}, at ${read[6]} ${read[7]}`,
|
|
407
|
+
);
|
|
408
|
+
tiles.push([t, (await page.screenshot({ type: 'jpeg', quality: 88, clip })).toString('base64')]);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const fastest = await page.evaluate(d => {
|
|
412
|
+
const app = window[d];
|
|
413
|
+
const out = Object.entries(window.labFastest).map(([id, v]) => `${id} ${v.toFixed(2)} m/s`);
|
|
414
|
+
const p = window.labProbe;
|
|
415
|
+
if (p.hipHigh)
|
|
416
|
+
out.push(`hips ${p.hipLow.toFixed(3)} to ${p.hipHigh.toFixed(3)} of a figure 1.9 high, steepest ground ${p.slope.toFixed(2)}`);
|
|
417
|
+
app.state.measuring = false;
|
|
418
|
+
app.endScene();
|
|
419
|
+
return out.join(', ');
|
|
420
|
+
}, debug);
|
|
421
|
+
await page.waitForFunction(d => window[d].state.mode === 'play' && !window[d].director.ev, debug, { timeout: 60000 });
|
|
422
|
+
|
|
423
|
+
const sheets = Math.ceil(tiles.length / tilesPerSheet);
|
|
424
|
+
for (let k = 0; k < sheets; k++) {
|
|
425
|
+
const part = tiles.slice(k * tilesPerSheet, (k + 1) * tilesPerSheet);
|
|
426
|
+
const tileHeight = tile[1];
|
|
427
|
+
await sheet.setViewportSize({ width: tile[0] * cols, height: tileHeight * Math.ceil(part.length / cols) });
|
|
428
|
+
await sheet.setContent(
|
|
429
|
+
`<body style="margin:0;background:#000;display:grid;grid-template-columns:repeat(${cols},${tile[0]}px)">` +
|
|
430
|
+
part
|
|
431
|
+
.map(
|
|
432
|
+
([t, jpg]) =>
|
|
433
|
+
`<div style="position:relative;height:${tileHeight}px"><img src="data:image/jpeg;base64,${jpg}" style="width:${tile[0]}px;height:${tileHeight}px;display:block"><b style="position:absolute;left:5px;top:3px;color:#fff;font:13px sans-serif;text-shadow:0 0 3px #000">${name} ${t.toFixed(2)}</b></div>`,
|
|
434
|
+
)
|
|
435
|
+
.join('') +
|
|
436
|
+
'</body>',
|
|
437
|
+
);
|
|
438
|
+
await sheet.waitForTimeout(250);
|
|
439
|
+
await sheet.screenshot({ path: `${OUT}/lab-${name}${sheets > 1 ? '-' + (k + 1) : ''}.jpg`, type: 'jpeg', quality: 86 });
|
|
440
|
+
}
|
|
441
|
+
console.log(`${name}: ${tiles.length} stills on ${sheets} sheet${sheets > 1 ? 's' : ''}; fastest ${fastest}`);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (errors.size) console.log([...errors].join('\n'));
|
|
445
|
+
return errors.size ? 1 : 0;
|
|
446
|
+
} finally {
|
|
447
|
+
await closeBrowser(browser);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
module.exports = { DEFAULT_VIEWS, createStandardScenarios, parseMotionLabArgs, runMotionLab };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const { createStandardScenarios, parseMotionLabArgs } = require('./motion-lab.cjs');
|
|
5
|
+
|
|
6
|
+
test('createStandardScenarios binds primary, partner, and handover prop names without consumer defaults', () => {
|
|
7
|
+
const scenarios = createStandardScenarios({ primary: 'scout', partner: 'guard', handoverProp: 'scroll' });
|
|
8
|
+
assert.deepEqual(Object.keys(scenarios), [
|
|
9
|
+
'walk',
|
|
10
|
+
'walkfront',
|
|
11
|
+
'start',
|
|
12
|
+
'run',
|
|
13
|
+
'turn',
|
|
14
|
+
'bow',
|
|
15
|
+
'give',
|
|
16
|
+
'punch',
|
|
17
|
+
'draw',
|
|
18
|
+
'duel',
|
|
19
|
+
'parry',
|
|
20
|
+
'slay',
|
|
21
|
+
'kill',
|
|
22
|
+
'poses',
|
|
23
|
+
'talk',
|
|
24
|
+
'kneel',
|
|
25
|
+
]);
|
|
26
|
+
assert.ok(scenarios.walk.cast.scout);
|
|
27
|
+
assert.equal(scenarios.give.steps[0][2], 'scroll');
|
|
28
|
+
assert.equal(scenarios.duel.steps[2][3], 'guard');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('parseMotionLabArgs handles --list, --trace, inline JSON, and unknown scenario names', () => {
|
|
32
|
+
const scenarios = createStandardScenarios();
|
|
33
|
+
assert.equal(parseMotionLabArgs(['--list'], scenarios).list, true);
|
|
34
|
+
const traced = parseMotionLabArgs(['--trace', 'walk', '{"dur":2,"cast":{},"steps":[],"view":{}}'], scenarios);
|
|
35
|
+
assert.equal(traced.trace, true);
|
|
36
|
+
assert.equal(traced.missing.length, 0);
|
|
37
|
+
assert.deepEqual(
|
|
38
|
+
traced.asked.map(([name]) => name),
|
|
39
|
+
['walk', 'own'],
|
|
40
|
+
);
|
|
41
|
+
const bad = parseMotionLabArgs(['walk', 'nonexistent'], scenarios);
|
|
42
|
+
assert.deepEqual(bad.missing, ['nonexistent']);
|
|
43
|
+
});
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Generic phone performance guard runner for worlds built on Roamwright.
|
|
3
|
+
|
|
4
|
+
Measures standing frames shown (`probe=count`) and flown-route frame pacing (`probe=route`) on the iOS Simulator
|
|
5
|
+
via a world's simulator wrapper script, compares every place against a YAML baseline, and optionally rewrites the
|
|
6
|
+
baseline (`--mode keep`).
|
|
7
|
+
|
|
8
|
+
python3 phone-guard.py --baseline <path> --sim <sim.sh> [--mode keep] [--port 8764] [--margin 3]
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import time
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
STANDING_RE = re.compile(r"probe at \w+, [^:]*: (\d+) (\d+) (\d+) frames shown")
|
|
20
|
+
FLOWN_RE = re.compile(r"flown .*: (\d+) frames a second, \d+ stood over 25 ms, (\d+) over 50, (\d+) over 100")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def read_baseline(path):
|
|
24
|
+
"""Parse a phone-baseline YAML file into `(preset, standing, flown)`."""
|
|
25
|
+
preset, standing, flown, part = "medium", {}, {}, None
|
|
26
|
+
for line in Path(path).read_text(encoding="utf-8").splitlines():
|
|
27
|
+
if line.lstrip().startswith("#") or not line.strip():
|
|
28
|
+
continue
|
|
29
|
+
if line.startswith("preset:"):
|
|
30
|
+
preset = line.split(":", 1)[1].strip()
|
|
31
|
+
elif line.startswith("standing:"):
|
|
32
|
+
part = standing
|
|
33
|
+
elif line.startswith("flown:"):
|
|
34
|
+
part = flown
|
|
35
|
+
elif part is not None:
|
|
36
|
+
place, value = line.strip().split(":", 1)
|
|
37
|
+
if part is standing:
|
|
38
|
+
part[place] = int(value)
|
|
39
|
+
else:
|
|
40
|
+
part[place] = {key: int(re.search(key + r": (\d+)", value).group(1)) for key in ("least", "over100", "over50")}
|
|
41
|
+
return preset, standing, flown
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def parse_standing_log(lines):
|
|
45
|
+
"""Extract the median standing FPS from `probe=count` log lines, or None if missing."""
|
|
46
|
+
for line in lines:
|
|
47
|
+
found = STANDING_RE.search(line)
|
|
48
|
+
if found:
|
|
49
|
+
return sorted(int(n) for n in found.groups())[1]
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def parse_flown_log(lines):
|
|
54
|
+
"""Extract worst-leg `{least, over50, over100}` from `probe=route` log lines, or None if missing."""
|
|
55
|
+
legs = []
|
|
56
|
+
for line in lines:
|
|
57
|
+
found = FLOWN_RE.search(line)
|
|
58
|
+
if found:
|
|
59
|
+
legs.append([int(n) for n in found.groups()])
|
|
60
|
+
if not legs:
|
|
61
|
+
return None
|
|
62
|
+
return {
|
|
63
|
+
"least": min(leg[0] for leg in legs),
|
|
64
|
+
"over50": max(leg[1] for leg in legs),
|
|
65
|
+
"over100": max(leg[2] for leg in legs),
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def evaluate_standing(shown, floor, mode=""):
|
|
70
|
+
"""Return True when standing FPS passes its floor (or mode is `keep` and a measurement arrived)."""
|
|
71
|
+
return shown is not None and (mode == "keep" or shown >= floor)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def evaluate_flown(seen, asked, mode=""):
|
|
75
|
+
"""Return True when flown FPS and long-frame counts pass the baseline (or mode is `keep` and a measurement arrived)."""
|
|
76
|
+
return seen is not None and (
|
|
77
|
+
mode == "keep" or (seen["least"] >= asked["least"] and seen["over100"] <= asked["over100"] and seen["over50"] <= asked["over50"])
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def format_baseline(header, preset, measured_standing, measured_flown, margin=3):
|
|
82
|
+
"""Format a refreshed phone-baseline YAML document preserving leading comment lines."""
|
|
83
|
+
body = f"preset: {preset}\nstanding:\n" + "".join(f" {place}: {shown - margin}\n" for place, shown in measured_standing.items())
|
|
84
|
+
body += "flown:\n" + "".join(
|
|
85
|
+
f" {place}: {{ least: {seen['least'] - margin}, over100: {seen['over100']}, over50: {max(seen['over50'], 2)} }}\n"
|
|
86
|
+
for place, seen in measured_flown.items()
|
|
87
|
+
)
|
|
88
|
+
return header + body
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def phone_free(port=8764):
|
|
92
|
+
"""Return True when no server listens on the simulator port and no competing headless Chrome runs locally."""
|
|
93
|
+
busy = f"lsof -tiTCP:{int(port)} -sTCP:LISTEN; pgrep -x chrome-headless-shell; pgrep -f 'Google Chrome for Testing'"
|
|
94
|
+
return subprocess.run(busy, shell=True, capture_output=True).stdout.strip() == b""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def visit(sim_script, place, seconds, preset, probe, port=8764, max_wait=900, retries=4):
|
|
98
|
+
"""Run one simulator visit and return its `LOG` lines, retrying when another process held the simulator."""
|
|
99
|
+
for attempt in range(retries):
|
|
100
|
+
waited = 0
|
|
101
|
+
while not phone_free(port) and waited < max_wait:
|
|
102
|
+
time.sleep(2)
|
|
103
|
+
waited += 2
|
|
104
|
+
name = "guard-" + place.split("/")[-1]
|
|
105
|
+
out = subprocess.run([sim_script, place, str(seconds), name, preset, probe], capture_output=True, text=True)
|
|
106
|
+
log = [line for line in (out.stdout + out.stderr).splitlines() if line.startswith("LOG")]
|
|
107
|
+
if any("probe" in line for line in log):
|
|
108
|
+
return log
|
|
109
|
+
tail = (out.stdout + out.stderr).strip().splitlines()[-1:]
|
|
110
|
+
print(f"phone-guard: {place} wrote no measure (try {attempt + 1}): {tail}", flush=True)
|
|
111
|
+
return []
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def parse_args(argv):
|
|
115
|
+
parser = argparse.ArgumentParser(description="Run iOS Simulator phone performance guard against a YAML baseline.")
|
|
116
|
+
parser.add_argument("--baseline", required=True, help="Path to phone-baseline.yaml")
|
|
117
|
+
parser.add_argument("--sim", required=True, help="Path to the world's simulator wrapper script")
|
|
118
|
+
parser.add_argument("--mode", default="", help="Pass 'keep' to rewrite the baseline")
|
|
119
|
+
parser.add_argument("--port", type=int, default=8764, help="Simulator HTTP port (default: 8764)")
|
|
120
|
+
parser.add_argument("--margin", type=int, default=3, help="FPS margin subtracted when keeping a baseline")
|
|
121
|
+
parser.add_argument("--standing-s", type=int, default=45, help="Duration of standing probe=count run in seconds")
|
|
122
|
+
parser.add_argument("--flown-s", type=int, default=95, help="Duration of flown probe=route run in seconds")
|
|
123
|
+
parser.add_argument("--label", default="", help="Display label for baseline path in status output")
|
|
124
|
+
return parser.parse_args(argv)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def main(argv=None):
|
|
128
|
+
args = parse_args(sys.argv[1:] if argv is None else argv)
|
|
129
|
+
baseline_path = Path(args.baseline)
|
|
130
|
+
preset, standing, flown = read_baseline(baseline_path)
|
|
131
|
+
failed, measured_standing, measured_flown = [], {}, {}
|
|
132
|
+
for place, floor in standing.items():
|
|
133
|
+
shown = measured_standing[place] = parse_standing_log(
|
|
134
|
+
visit(args.sim, place, args.standing_s, preset, "probe=count", port=args.port)
|
|
135
|
+
)
|
|
136
|
+
ok = evaluate_standing(shown, floor, args.mode)
|
|
137
|
+
print(f"{'ok ' if ok else 'FAIL'} standing at {place}: {shown} frames a second shown (the baseline asks {floor})", flush=True)
|
|
138
|
+
if not ok:
|
|
139
|
+
failed.append(place)
|
|
140
|
+
for place, asked in flown.items():
|
|
141
|
+
seen = measured_flown[place] = parse_flown_log(visit(args.sim, place, args.flown_s, preset, "probe=route", port=args.port))
|
|
142
|
+
ok = evaluate_flown(seen, asked, args.mode)
|
|
143
|
+
print(
|
|
144
|
+
f"{'ok ' if ok else 'FAIL'} flown across {place}: {seen} (the baseline asks at least {asked['least']} a second, "
|
|
145
|
+
f"at most {asked['over100']} over 100 ms and {asked['over50']} over 50 ms on a leg)",
|
|
146
|
+
flush=True,
|
|
147
|
+
)
|
|
148
|
+
if not ok:
|
|
149
|
+
failed.append(place)
|
|
150
|
+
subprocess.run([args.sim, "--stop"], capture_output=True)
|
|
151
|
+
if args.mode == "keep" and not failed:
|
|
152
|
+
header = "".join(line for line in baseline_path.read_text(encoding="utf-8").splitlines(keepends=True) if line.startswith("#"))
|
|
153
|
+
baseline_path.write_text(format_baseline(header, preset, measured_standing, measured_flown, margin=args.margin), encoding="utf-8")
|
|
154
|
+
label = args.label or os.fspath(baseline_path)
|
|
155
|
+
print(f"phone-guard: the baseline is kept anew in {label}")
|
|
156
|
+
print("phone-guard: " + ("FAILED at " + ", ".join(failed) if failed else "every place holds its baseline"))
|
|
157
|
+
return 1 if failed else 0
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
if __name__ == "__main__":
|
|
161
|
+
raise SystemExit(main())
|
package/tools/remote-runner.sh
CHANGED
|
@@ -67,7 +67,10 @@ carry_engine_tools() {
|
|
|
67
67
|
echo "$NAME: no engine tools in $REPO/node_modules/roamwright/tools: run make deps there" >&2
|
|
68
68
|
return 1
|
|
69
69
|
}
|
|
70
|
-
mkdir -p "$1/node_modules/roamwright/tools"
|
|
70
|
+
mkdir -p "$1/node_modules/roamwright/tools" "$1/node_modules/roamwright/scripts" &&
|
|
71
|
+
cp "$engine/package.json" "$1/node_modules/roamwright/" &&
|
|
72
|
+
cp "$engine"/tools/*.cjs "$1/node_modules/roamwright/tools/" &&
|
|
73
|
+
{ [ ! -f "$engine/scripts/serve.py" ] || cp "$engine/scripts/serve.py" "$1/node_modules/roamwright/scripts/"; }
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
# Runs the tool locally on this Mac against a temporary HTTP server on an ephemeral port.
|