roamwright 0.61.21 → 0.61.23
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/examples/fliers.html +1 -0
- package/examples/fliers.js +41 -1
- package/examples/town-fittings.js +17 -8
- package/geometry/crawl-shapes.js +86 -1
- package/geometry/crawler-giant-spider.js +100 -0
- package/geometry/harbour-kit.js +178 -8
- package/geometry/plant-garden.js +88 -0
- package/geometry/road-bridges.js +74 -0
- package/geometry/town-garden.js +3 -44
- package/index.js +18 -4
- package/motion/crawler-pack.js +110 -0
- package/package.json +1 -1
- package/rendering/crawler-pack.js +91 -0
- package/scripts/bundle.mjs +17 -5
- package/scripts/vendor.mjs +209 -36
- 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,355 @@
|
|
|
1
|
+
// Scene-level close-up inspection runners built on a Roamwright page driver:
|
|
2
|
+
// hand/grip close-up inspection (`runHandLook`) and troop standard-bearer tracking (`runBearerLook`).
|
|
3
|
+
'use strict';
|
|
4
|
+
const { startSceneInPage } = require('./scene-run.cjs');
|
|
5
|
+
const { waitSceneReachInPage } = require('./geometry-hash.cjs');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Parses CLI arguments for `runHandLook`:
|
|
9
|
+
* `<address> <sceneId> <second> <actorId> <name> [views='cam'] [hour=''] [metres='0.3'] [eased=''] [hand='right']`.
|
|
10
|
+
*
|
|
11
|
+
* @param {string[]} [argv=[]]
|
|
12
|
+
* @returns {{ address: string, sceneId: string, at: number, actorId: string, name: string, views: string[], singleCam: boolean, hour: string, metres: number, eased: string, left: boolean }}
|
|
13
|
+
*/
|
|
14
|
+
function parseHandLookArgs(argv = []) {
|
|
15
|
+
const [
|
|
16
|
+
address = '',
|
|
17
|
+
sceneId = '',
|
|
18
|
+
at = '0',
|
|
19
|
+
actorId = '',
|
|
20
|
+
name = 'hand',
|
|
21
|
+
viewsStr = 'cam',
|
|
22
|
+
hour = '',
|
|
23
|
+
metres = '0.3',
|
|
24
|
+
eased = '',
|
|
25
|
+
hand = 'right',
|
|
26
|
+
] = argv;
|
|
27
|
+
return {
|
|
28
|
+
address,
|
|
29
|
+
sceneId,
|
|
30
|
+
at: +at,
|
|
31
|
+
actorId,
|
|
32
|
+
name,
|
|
33
|
+
views: String(viewsStr).split(',').filter(Boolean),
|
|
34
|
+
singleCam: viewsStr === 'cam',
|
|
35
|
+
hour,
|
|
36
|
+
metres: +metres,
|
|
37
|
+
eased,
|
|
38
|
+
left: hand === 'left',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Parses CLI arguments for `runBearerLook`:
|
|
44
|
+
* `<address> <sceneId> <second> <name> [which='0'] [hour=''] [views='fist,close,mid,air'] [still='']`.
|
|
45
|
+
*
|
|
46
|
+
* @param {string[]} [argv=[]]
|
|
47
|
+
* @returns {{ address: string, sceneId: string, at: number, name: string, which: string, hour: string, views: string[], still: string }}
|
|
48
|
+
*/
|
|
49
|
+
function parseBearerLookArgs(argv = []) {
|
|
50
|
+
const [address = '', sceneId = '', at = '0', name = 'bearer', which = '0', hour = '', viewsStr = 'fist,close,mid,air', still = ''] = argv;
|
|
51
|
+
return {
|
|
52
|
+
address,
|
|
53
|
+
sceneId,
|
|
54
|
+
at: +at,
|
|
55
|
+
name,
|
|
56
|
+
which,
|
|
57
|
+
hour,
|
|
58
|
+
views: String(viewsStr).split(',').filter(Boolean),
|
|
59
|
+
still,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Pauses the director at the current beat, optionally overrides the scene hour and grip easing,
|
|
65
|
+
* and starts a camera follow loop targeting an actor's hand (`handR` or `handL`).
|
|
66
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
67
|
+
*
|
|
68
|
+
* @param {{ debug: string, actorId: string, hour: string, metres: number, eased: string, left: boolean }} arg
|
|
69
|
+
* @returns {{ bends: boolean, r: number|undefined, eased: number|undefined, bones: number, item: string, armed: boolean, near: boolean, triangles: number }}
|
|
70
|
+
*/
|
|
71
|
+
function setupHandFollowInPage({ debug, actorId, hour, metres, eased, left }) {
|
|
72
|
+
const app = window[debug];
|
|
73
|
+
const a = app.actors[actorId];
|
|
74
|
+
const wrist = left ? a.handL : a.handR;
|
|
75
|
+
const grip = left ? a.gripL : a.gripR;
|
|
76
|
+
const side = left ? -1 : 1;
|
|
77
|
+
app.director.paused = true;
|
|
78
|
+
if (hour) {
|
|
79
|
+
app.env.ovTarget = -1;
|
|
80
|
+
app.env.override = +hour;
|
|
81
|
+
}
|
|
82
|
+
const c = app.camera;
|
|
83
|
+
const V = c.position.constructor;
|
|
84
|
+
const at = new V(),
|
|
85
|
+
eye = new V(),
|
|
86
|
+
way = new V();
|
|
87
|
+
const aim = () => wrist.localToWorld(at.set(-side * 0.02, -0.075, 0.004));
|
|
88
|
+
wrist.updateWorldMatrix(true, false);
|
|
89
|
+
const seen = c.position.clone().sub(aim()).normalize();
|
|
90
|
+
app.state.mode = 'inspect';
|
|
91
|
+
if (eased && grip) {
|
|
92
|
+
grip.eased = +eased;
|
|
93
|
+
grip.takes = 1e9;
|
|
94
|
+
}
|
|
95
|
+
const SIDES = {
|
|
96
|
+
palm: [-side, 0.15, 0.25],
|
|
97
|
+
back: [side, 0.15, 0.25],
|
|
98
|
+
thumb: [-side * 0.25, 0.2, 1],
|
|
99
|
+
little: [-side * 0.25, 0.2, -1],
|
|
100
|
+
tips: [-side * 0.3, -1, 0.3],
|
|
101
|
+
};
|
|
102
|
+
window.__view = 'cam';
|
|
103
|
+
const wide = c.fov;
|
|
104
|
+
const follow = () => {
|
|
105
|
+
if (app.state.mode !== 'inspect') app.state.mode = 'inspect';
|
|
106
|
+
wrist.updateWorldMatrix(true, false);
|
|
107
|
+
aim();
|
|
108
|
+
const v = window.__view;
|
|
109
|
+
const out = SIDES[v];
|
|
110
|
+
if (out) way.set(out[0], out[1], out[2]).transformDirection(wrist.matrixWorld);
|
|
111
|
+
else way.copy(seen);
|
|
112
|
+
eye.copy(at).addScaledVector(way, v === 'arm' ? 1.2 : metres);
|
|
113
|
+
if (!out) eye.y += v === 'arm' ? 0.25 : 0.04;
|
|
114
|
+
c.position.copy(eye);
|
|
115
|
+
c.lookAt(at);
|
|
116
|
+
c.updateMatrixWorld();
|
|
117
|
+
const lens = metres > 0.4 && v !== 'arm' ? 18 : wide;
|
|
118
|
+
if (c.fov !== lens) {
|
|
119
|
+
c.fov = lens;
|
|
120
|
+
c.updateProjectionMatrix();
|
|
121
|
+
}
|
|
122
|
+
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(follow);
|
|
123
|
+
};
|
|
124
|
+
follow();
|
|
125
|
+
return {
|
|
126
|
+
bends: !!grip,
|
|
127
|
+
r: grip && grip.r,
|
|
128
|
+
eased: grip && grip.eased,
|
|
129
|
+
bones: a.hi.skeleton.bones.length,
|
|
130
|
+
item: a.def.look.item || '',
|
|
131
|
+
armed: !!a.armed,
|
|
132
|
+
near: a.nearBuilt,
|
|
133
|
+
triangles: a.hi.geometry.index ? a.hi.geometry.index.count / 3 : 0,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Pauses the director, finds a crowd standard-bearer matching `which` (`'m'`, `'w'`, `'f'`, or visible index),
|
|
139
|
+
* and starts a camera follow loop tracking their held standard.
|
|
140
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
141
|
+
*
|
|
142
|
+
* @param {{ debug: string, which: string, hour: string, still: string }} arg
|
|
143
|
+
* @returns {object}
|
|
144
|
+
*/
|
|
145
|
+
function setupBearerFollowInPage({ debug, which, hour, still }) {
|
|
146
|
+
const app = window[debug];
|
|
147
|
+
app.director.paused = true;
|
|
148
|
+
if (hour) {
|
|
149
|
+
app.env.ovTarget = -1;
|
|
150
|
+
app.env.override = +hour;
|
|
151
|
+
}
|
|
152
|
+
app.state.mode = 'inspect';
|
|
153
|
+
if (still) {
|
|
154
|
+
for (const c of app.crowds)
|
|
155
|
+
for (const m of c.list)
|
|
156
|
+
if (m.move !== undefined && m.slotX !== undefined) {
|
|
157
|
+
m.move = null;
|
|
158
|
+
m.speed = 0;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const bearers = app.crowds.flatMap(c => c.list.filter(g => g.held));
|
|
162
|
+
const g =
|
|
163
|
+
which === 'm'
|
|
164
|
+
? bearers.find(b => b.mounted && b.home !== -1)
|
|
165
|
+
: which === 'w'
|
|
166
|
+
? bearers.find(b => !b.mounted && b.home !== -1 && !b.fall)
|
|
167
|
+
: which === 'f'
|
|
168
|
+
? bearers.find(b => b.home !== -1 && b.fall)
|
|
169
|
+
: bearers.filter(b => b.home !== -1)[+which];
|
|
170
|
+
window.__bearer = g;
|
|
171
|
+
window.__view = 'mid';
|
|
172
|
+
const V = app.camera.position.constructor;
|
|
173
|
+
const c = app.camera;
|
|
174
|
+
const eye = new V(),
|
|
175
|
+
fist = new V();
|
|
176
|
+
const follow = () => {
|
|
177
|
+
if (window.__bearer) {
|
|
178
|
+
if (app.state.mode !== 'inspect') app.state.mode = 'inspect';
|
|
179
|
+
const h = g.held,
|
|
180
|
+
fx = Math.sin(g.dir),
|
|
181
|
+
fz = Math.cos(g.dir);
|
|
182
|
+
fist.set(h.x, h.y, h.z);
|
|
183
|
+
if (window.__view === 'side') eye.set(h.x + fz * 0.45, h.y + 0.02, h.z - fx * 0.45);
|
|
184
|
+
else if (window.__view === 'top') eye.set(h.x + fx * 0.12 + fz * 0.05, h.y + 0.38, h.z + fz * 0.12 - fx * 0.05);
|
|
185
|
+
else if (window.__view === 'fist') eye.set(h.x + fx * 0.3 + fz * 0.22, h.y + 0.06, h.z + fz * 0.3 - fx * 0.22);
|
|
186
|
+
else if (window.__view === 'close') eye.set(h.x + fx * 0.75 + fz * 0.45, h.y + 0.15, h.z + fz * 0.75 - fx * 0.45);
|
|
187
|
+
else if (window.__view === 'down') {
|
|
188
|
+
const y = app.space.ground(h.x, h.z);
|
|
189
|
+
fist.set(h.x + fz * 2.6, y, h.z - fx * 2.6);
|
|
190
|
+
eye.set(h.x - fx * 3 + fz * 1.4, y + 5.5, h.z - fz * 3 - fx * 1.4);
|
|
191
|
+
} else if (window.__view === 'mid') {
|
|
192
|
+
eye.set(g.ax + fx * 3.4 + fz * 1.6, h.floor + 1.65, g.az + fz * 3.4 - fx * 1.6);
|
|
193
|
+
fist.y -= 0.2;
|
|
194
|
+
} else if (window.__view === 'far') {
|
|
195
|
+
eye.set(g.ax + fx * 48 + fz * 30, h.floor + 40, g.az + fz * 48 - fx * 30);
|
|
196
|
+
fist.y -= 1;
|
|
197
|
+
} else {
|
|
198
|
+
eye.set(g.ax + fx * 22 + fz * 14, h.floor + 30, g.az + fz * 22 - fx * 14);
|
|
199
|
+
fist.y -= 1;
|
|
200
|
+
}
|
|
201
|
+
c.position.copy(eye);
|
|
202
|
+
c.lookAt(fist);
|
|
203
|
+
c.updateMatrixWorld();
|
|
204
|
+
}
|
|
205
|
+
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(follow);
|
|
206
|
+
};
|
|
207
|
+
follow();
|
|
208
|
+
return {
|
|
209
|
+
bearers: bearers
|
|
210
|
+
.map(b => b.look + (b.mounted ? 'm' : '') + (b.home === -1 ? 'h' : '') + ':' + b.lod + (b.held.frame === app.state.frame ? 'd' : ''))
|
|
211
|
+
.join(' '),
|
|
212
|
+
which: +which,
|
|
213
|
+
lod: g.lod,
|
|
214
|
+
mounted: g.mounted,
|
|
215
|
+
role: g.role,
|
|
216
|
+
look: g.look,
|
|
217
|
+
speed: g.speed,
|
|
218
|
+
held: g.held,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Selects a bearer camera view (and hides crowd meshes for `'bare'`).
|
|
224
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
225
|
+
*
|
|
226
|
+
* @param {{ debug: string, view: string }} arg
|
|
227
|
+
*/
|
|
228
|
+
function setBearerViewInPage({ debug, view }) {
|
|
229
|
+
window.__view = view === 'bare' ? 'down' : view;
|
|
230
|
+
if (view === 'bare') window[debug].scene.traverse(o => /^Crowd/.test(o.name) && o.material && (o.material.visible = false));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Reads live bearer and camera telemetry for logging after each view settle.
|
|
235
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
236
|
+
*
|
|
237
|
+
* @param {{ debug: string }} arg
|
|
238
|
+
* @returns {object}
|
|
239
|
+
*/
|
|
240
|
+
function readBearerViewInPage({ debug }) {
|
|
241
|
+
const app = window[debug];
|
|
242
|
+
const c = app.camera.position;
|
|
243
|
+
const g = window.__bearer;
|
|
244
|
+
return {
|
|
245
|
+
look: g.look,
|
|
246
|
+
home: g.home,
|
|
247
|
+
fall: g.fall,
|
|
248
|
+
lod: g.lod,
|
|
249
|
+
frame: g.held.frame === app.state.frame,
|
|
250
|
+
speed: +g.speed.toFixed(2),
|
|
251
|
+
cam: [c.x, c.y, c.z].map(v => +v.toFixed(1)),
|
|
252
|
+
ground: +app.space.ground(c.x, c.z).toFixed(1),
|
|
253
|
+
at: [g.ax, g.az].map(v => +v.toFixed(1)),
|
|
254
|
+
space: app.space.id,
|
|
255
|
+
mode: app.state.mode,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function openSceneBeat(driver, address, sceneId, at) {
|
|
260
|
+
const debug = driver.debug;
|
|
261
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
262
|
+
const page = await browser.newPage({ viewport: { width: 960, height: 600 } });
|
|
263
|
+
await driver.applyStorage(page, { quality: 'high', muted: '1' });
|
|
264
|
+
const errs = new Set();
|
|
265
|
+
page.on('pageerror', e => errs.add('PAGE ' + e.message.slice(0, 200)));
|
|
266
|
+
page.on('console', m => (m.type() === 'error' || /WebGL|INVALID/.test(m.text())) && errs.add(m.type() + ' ' + m.text().slice(0, 200)));
|
|
267
|
+
await driver.enter(page, driver.routeUrl(address), { titledMs: 180000 });
|
|
268
|
+
await page.waitForTimeout(2500);
|
|
269
|
+
await page.evaluate(startSceneInPage, { debug, id: sceneId });
|
|
270
|
+
await page.waitForFunction(waitSceneReachInPage, { debug, at }, { timeout: 120000 });
|
|
271
|
+
return { browser, page, errs };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Shoots close-up stills of an actor's hand at a held beat of a scene.
|
|
276
|
+
*
|
|
277
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
278
|
+
* @param {object} [options]
|
|
279
|
+
* @param {string[]} [options.argv=[]]
|
|
280
|
+
* @returns {Promise<{ grip: object, files: string[] }>}
|
|
281
|
+
*/
|
|
282
|
+
async function runHandLook(driver, { argv = [] } = {}) {
|
|
283
|
+
const parsed = parseHandLookArgs(argv);
|
|
284
|
+
const debug = driver.debug;
|
|
285
|
+
const { browser, page, errs } = await openSceneBeat(driver, parsed.address, parsed.sceneId, parsed.at);
|
|
286
|
+
const grip = await page.evaluate(setupHandFollowInPage, {
|
|
287
|
+
debug,
|
|
288
|
+
actorId: parsed.actorId,
|
|
289
|
+
hour: parsed.hour,
|
|
290
|
+
metres: parsed.metres,
|
|
291
|
+
eased: parsed.eased,
|
|
292
|
+
left: parsed.left,
|
|
293
|
+
});
|
|
294
|
+
console.log(JSON.stringify(grip));
|
|
295
|
+
const files = [];
|
|
296
|
+
for (const v of parsed.views) {
|
|
297
|
+
await page.evaluate(x => {
|
|
298
|
+
window.__view = x;
|
|
299
|
+
}, v);
|
|
300
|
+
await page.waitForTimeout(1500);
|
|
301
|
+
const stem = parsed.singleCam ? parsed.name : `${parsed.name}-${v}`;
|
|
302
|
+
const outFile = `${driver.OUT}/${stem}.jpg`;
|
|
303
|
+
await page.screenshot({ path: outFile, type: 'jpeg', quality: 85 });
|
|
304
|
+
files.push(outFile);
|
|
305
|
+
console.log('saved', stem);
|
|
306
|
+
}
|
|
307
|
+
for (const e of errs) console.log('ERR', e);
|
|
308
|
+
await driver.closeBrowser(browser);
|
|
309
|
+
return { grip, files };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Shoots multi-angle stills tracking a troop standard-bearer at a held beat of a scene.
|
|
314
|
+
*
|
|
315
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
316
|
+
* @param {object} [options]
|
|
317
|
+
* @param {string[]} [options.argv=[]]
|
|
318
|
+
* @returns {Promise<{ summary: object, files: string[] }>}
|
|
319
|
+
*/
|
|
320
|
+
async function runBearerLook(driver, { argv = [] } = {}) {
|
|
321
|
+
const parsed = parseBearerLookArgs(argv);
|
|
322
|
+
const debug = driver.debug;
|
|
323
|
+
const { browser, page, errs } = await openSceneBeat(driver, parsed.address, parsed.sceneId, parsed.at);
|
|
324
|
+
const summary = await page.evaluate(setupBearerFollowInPage, {
|
|
325
|
+
debug,
|
|
326
|
+
which: parsed.which,
|
|
327
|
+
hour: parsed.hour,
|
|
328
|
+
still: parsed.still,
|
|
329
|
+
});
|
|
330
|
+
console.log(JSON.stringify(summary));
|
|
331
|
+
const files = [];
|
|
332
|
+
for (const v of parsed.views) {
|
|
333
|
+
await page.evaluate(setBearerViewInPage, { debug, view: v });
|
|
334
|
+
await page.waitForTimeout(1500);
|
|
335
|
+
const info = await page.evaluate(readBearerViewInPage, { debug });
|
|
336
|
+
const outFile = `${driver.OUT}/${parsed.name}-${v}.jpg`;
|
|
337
|
+
await page.screenshot({ path: outFile, type: 'jpeg', quality: 85 });
|
|
338
|
+
files.push(outFile);
|
|
339
|
+
console.log('saved', `${parsed.name}-${v}`, JSON.stringify(info));
|
|
340
|
+
}
|
|
341
|
+
for (const e of errs) console.log('ERR', e);
|
|
342
|
+
await driver.closeBrowser(browser);
|
|
343
|
+
return { summary, files };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
module.exports = {
|
|
347
|
+
parseBearerLookArgs,
|
|
348
|
+
parseHandLookArgs,
|
|
349
|
+
readBearerViewInPage,
|
|
350
|
+
runBearerLook,
|
|
351
|
+
runHandLook,
|
|
352
|
+
setBearerViewInPage,
|
|
353
|
+
setupBearerFollowInPage,
|
|
354
|
+
setupHandFollowInPage,
|
|
355
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const {
|
|
5
|
+
parseBearerLookArgs,
|
|
6
|
+
parseHandLookArgs,
|
|
7
|
+
readBearerViewInPage,
|
|
8
|
+
setBearerViewInPage,
|
|
9
|
+
setupBearerFollowInPage,
|
|
10
|
+
setupHandFollowInPage,
|
|
11
|
+
} = require('./scene-detail.cjs');
|
|
12
|
+
|
|
13
|
+
test('scene-detail arg parsers decode hand and bearer CLI options cleanly', () => {
|
|
14
|
+
assert.deepEqual(parseHandLookArgs(['location/city', 'duel', '12', 'hero', 'grip', 'cam,palm', '0.5', '0.45', '0.6', 'left']), {
|
|
15
|
+
address: 'location/city',
|
|
16
|
+
sceneId: 'duel',
|
|
17
|
+
at: 12,
|
|
18
|
+
actorId: 'hero',
|
|
19
|
+
name: 'grip',
|
|
20
|
+
views: ['cam', 'palm'],
|
|
21
|
+
singleCam: false,
|
|
22
|
+
hour: '0.5',
|
|
23
|
+
metres: 0.45,
|
|
24
|
+
eased: '0.6',
|
|
25
|
+
left: true,
|
|
26
|
+
});
|
|
27
|
+
assert.equal(parseHandLookArgs(['', 'duel', '5', 'hero', 'grip']).singleCam, true);
|
|
28
|
+
|
|
29
|
+
assert.deepEqual(parseBearerLookArgs(['location/plain', 'battle', '8', 'std', 'm', '0.5', 'fist,mid', 'still']), {
|
|
30
|
+
address: 'location/plain',
|
|
31
|
+
sceneId: 'battle',
|
|
32
|
+
at: 8,
|
|
33
|
+
name: 'std',
|
|
34
|
+
which: 'm',
|
|
35
|
+
hour: '0.5',
|
|
36
|
+
views: ['fist', 'mid'],
|
|
37
|
+
still: 'still',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('hand and bearer in-page helpers talk strictly through window[debug]', () => {
|
|
42
|
+
class Vec3 {
|
|
43
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
44
|
+
this.x = x;
|
|
45
|
+
this.y = y;
|
|
46
|
+
this.z = z;
|
|
47
|
+
}
|
|
48
|
+
set(x, y, z) {
|
|
49
|
+
this.x = x;
|
|
50
|
+
this.y = y;
|
|
51
|
+
this.z = z;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
copy(v) {
|
|
55
|
+
this.x = v.x;
|
|
56
|
+
this.y = v.y;
|
|
57
|
+
this.z = v.z;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
clone() {
|
|
61
|
+
return new Vec3(this.x, this.y, this.z);
|
|
62
|
+
}
|
|
63
|
+
sub(v) {
|
|
64
|
+
this.x -= v.x;
|
|
65
|
+
this.y -= v.y;
|
|
66
|
+
this.z -= v.z;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
normalize() {
|
|
70
|
+
const l = Math.hypot(this.x, this.y, this.z) || 1;
|
|
71
|
+
this.x /= l;
|
|
72
|
+
this.y /= l;
|
|
73
|
+
this.z /= l;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
addScaledVector(v, s) {
|
|
77
|
+
this.x += v.x * s;
|
|
78
|
+
this.y += v.y * s;
|
|
79
|
+
this.z += v.z * s;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
transformDirection() {
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const crowdMat = { visible: true };
|
|
88
|
+
const crowdMesh = { name: 'Crowd guard near', material: crowdMat };
|
|
89
|
+
const bearer = {
|
|
90
|
+
look: 3,
|
|
91
|
+
home: 0,
|
|
92
|
+
fall: 0,
|
|
93
|
+
lod: 2,
|
|
94
|
+
mounted: false,
|
|
95
|
+
role: 'ready',
|
|
96
|
+
speed: 1.5,
|
|
97
|
+
dir: 0,
|
|
98
|
+
ax: 5,
|
|
99
|
+
az: 8,
|
|
100
|
+
slotX: 0,
|
|
101
|
+
move: { x: 1 },
|
|
102
|
+
held: { x: 5, y: 2, z: 8, floor: 1, frame: 10 },
|
|
103
|
+
};
|
|
104
|
+
const gripR = { r: 0.015, eased: 0.2, takes: 0.5 };
|
|
105
|
+
const wrist = {
|
|
106
|
+
matrixWorld: {},
|
|
107
|
+
updateWorldMatrix() {},
|
|
108
|
+
localToWorld(v) {
|
|
109
|
+
v.x += 1;
|
|
110
|
+
v.y += 1.2;
|
|
111
|
+
v.z += 2;
|
|
112
|
+
return v;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
globalThis.window = {
|
|
117
|
+
APP: {
|
|
118
|
+
director: { paused: false },
|
|
119
|
+
env: { flow: true, time: 0.4, ovTarget: 0, override: -1 },
|
|
120
|
+
state: { mode: 'scene', frame: 10 },
|
|
121
|
+
space: { id: 'valley', ground: () => 1 },
|
|
122
|
+
camera: {
|
|
123
|
+
fov: 40,
|
|
124
|
+
position: new Vec3(0, 1.5, 0),
|
|
125
|
+
lookAt() {},
|
|
126
|
+
updateProjectionMatrix() {},
|
|
127
|
+
updateMatrixWorld() {},
|
|
128
|
+
},
|
|
129
|
+
actors: {
|
|
130
|
+
hero: {
|
|
131
|
+
handR: wrist,
|
|
132
|
+
gripR,
|
|
133
|
+
hi: { skeleton: { bones: new Array(54) }, geometry: { index: { count: 300 } } },
|
|
134
|
+
def: { look: { item: 'sword' } },
|
|
135
|
+
armed: true,
|
|
136
|
+
nearBuilt: true,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
crowds: [{ list: [bearer] }],
|
|
140
|
+
scene: { traverse: fn => fn(crowdMesh) },
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
try {
|
|
144
|
+
const grip = setupHandFollowInPage({ debug: 'APP', actorId: 'hero', hour: '0.5', metres: 0.5, eased: '0.7', left: false });
|
|
145
|
+
assert.equal(grip.bends, true);
|
|
146
|
+
assert.equal(grip.eased, 0.7);
|
|
147
|
+
assert.equal(grip.triangles, 100);
|
|
148
|
+
assert.equal(globalThis.window.APP.camera.fov, 18);
|
|
149
|
+
|
|
150
|
+
const summary = setupBearerFollowInPage({ debug: 'APP', which: '0', hour: '0.5', still: '1' });
|
|
151
|
+
assert.equal(summary.look, 3);
|
|
152
|
+
assert.equal(bearer.move, null);
|
|
153
|
+
setBearerViewInPage({ debug: 'APP', view: 'bare' });
|
|
154
|
+
assert.equal(globalThis.window.__view, 'down');
|
|
155
|
+
assert.equal(crowdMat.visible, false);
|
|
156
|
+
const info = readBearerViewInPage({ debug: 'APP' });
|
|
157
|
+
assert.equal(info.frame, true);
|
|
158
|
+
assert.equal(info.space, 'valley');
|
|
159
|
+
} finally {
|
|
160
|
+
delete globalThis.window;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// Ground-cover clearing disc verification runner built on a Roamwright page driver.
|
|
2
|
+
// Finds a nearby bush whose shader supports clearing discs, shoots before and after pressing a disc round it,
|
|
3
|
+
// and fails if the bush remains unchanged.
|
|
4
|
+
'use strict';
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Parses CLI arguments for `runScrubClear`: `[land]`.
|
|
9
|
+
*
|
|
10
|
+
* @param {string[]} [argv=[]]
|
|
11
|
+
* @returns {{ land: string }}
|
|
12
|
+
*/
|
|
13
|
+
function parseScrubClearArgs(argv = []) {
|
|
14
|
+
return { land: argv[0] || '' };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Computes the fraction of pixels inside the center rectangle (`x in [0.3..0.7)`, `y in [0.25..0.85)`)
|
|
19
|
+
* whose RGB L1 difference exceeds `threshold`.
|
|
20
|
+
*
|
|
21
|
+
* @param {Uint8Array|Uint8ClampedArray} rgbaA First RGBA image buffer.
|
|
22
|
+
* @param {Uint8Array|Uint8ClampedArray} rgbaB Second RGBA image buffer.
|
|
23
|
+
* @param {number} width Image width in pixels.
|
|
24
|
+
* @param {number} height Image height in pixels.
|
|
25
|
+
* @param {number} [threshold=36] Sum-of-channels RGB difference threshold.
|
|
26
|
+
* @returns {number}
|
|
27
|
+
*/
|
|
28
|
+
function computeCenterDiffShare(rgbaA, rgbaB, width, height, threshold = 36) {
|
|
29
|
+
let changed = 0,
|
|
30
|
+
total = 0;
|
|
31
|
+
for (let y = Math.floor(height * 0.25); y < height * 0.85; y++)
|
|
32
|
+
for (let x = Math.floor(width * 0.3); x < width * 0.7; x++) {
|
|
33
|
+
const i = (y * width + x) * 4;
|
|
34
|
+
total++;
|
|
35
|
+
if (Math.abs(rgbaA[i] - rgbaB[i]) + Math.abs(rgbaA[i + 1] - rgbaB[i + 1]) + Math.abs(rgbaA[i + 2] - rgbaB[i + 2]) > threshold)
|
|
36
|
+
changed++;
|
|
37
|
+
}
|
|
38
|
+
return total ? changed / total : 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Finds the nearest instanced ground-cover bush whose material includes `shaderTag` in `customProgramCacheKey()`.
|
|
43
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
44
|
+
*
|
|
45
|
+
* @param {{ debug: string, shaderTag?: string, minVertices?: number, minDistance?: number }} arg
|
|
46
|
+
* @returns {{ d: number, x: number, y: number, z: number } | null}
|
|
47
|
+
*/
|
|
48
|
+
function findClearingBushInPage({ debug, shaderTag = 'cleared-in-discs', minVertices = 300, minDistance = 12 }) {
|
|
49
|
+
const app = window[debug];
|
|
50
|
+
const V = app.camera.position.constructor;
|
|
51
|
+
const at = app.camera.position;
|
|
52
|
+
const p = new V();
|
|
53
|
+
const m = new app.THREE.Matrix4();
|
|
54
|
+
let best = null;
|
|
55
|
+
app.scene.traverse(o => {
|
|
56
|
+
if (!o.isInstancedMesh || !o.count || !o.material?.customProgramCacheKey?.().includes(shaderTag)) return;
|
|
57
|
+
if (o.geometry.attributes.position.count < minVertices) return;
|
|
58
|
+
for (let i = 0; i < o.count; i += 3) {
|
|
59
|
+
o.getMatrixAt(i, m);
|
|
60
|
+
p.setFromMatrixPosition(m).applyMatrix4(o.matrixWorld);
|
|
61
|
+
const d = Math.hypot(p.x - at.x, p.z - at.z);
|
|
62
|
+
if (d > minDistance && (!best || d < best.d)) best = { d, x: p.x, y: p.y, z: p.z };
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return best;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Places the visitor and inspect camera facing a bush and optionally presses a clearing disc round it.
|
|
70
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
71
|
+
*
|
|
72
|
+
* @param {{ debug: string, bush: { x: number, y: number, z: number }, pressed: boolean, radius?: number }} arg
|
|
73
|
+
*/
|
|
74
|
+
function poseScrubShotInPage({ debug, bush, pressed, radius = 1.6 }) {
|
|
75
|
+
const app = window[debug];
|
|
76
|
+
if (typeof document !== 'undefined') for (const el of document.body.children) if (el.id !== 'c') el.style.visibility = 'hidden';
|
|
77
|
+
app.holdQuality(true);
|
|
78
|
+
app.env.flow = false;
|
|
79
|
+
app.state.mode = 'play';
|
|
80
|
+
app.placePlayer(bush.x + 4, bush.z + 3, 0);
|
|
81
|
+
app.env.time = 0.5;
|
|
82
|
+
app.state.mode = 'inspect';
|
|
83
|
+
app.camera.position.set(bush.x + 3.2, bush.y + 1.5, bush.z + 2.4);
|
|
84
|
+
app.camera.lookAt(bush.x, bush.y + 0.5, bush.z);
|
|
85
|
+
const discs = app.pressGrass(pressed ? 1 : 0);
|
|
86
|
+
if (pressed) discs[0].set(bush.x, bush.z, radius);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Verifies that pressing a ground-cover clearing disc clears a nearby bush and saves before/after stills
|
|
91
|
+
* (`<OUT>/scrub-stands.jpg` and `<OUT>/scrub-cleared.jpg`).
|
|
92
|
+
*
|
|
93
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
94
|
+
* @param {object} [options]
|
|
95
|
+
* @param {string[]} [options.argv=[]]
|
|
96
|
+
* @param {number} [options.minChanged=0.04] Minimum center-frame changed pixel share required to pass.
|
|
97
|
+
* @returns {Promise<{ passed: boolean, changed: number, bush: object | null }>}
|
|
98
|
+
*/
|
|
99
|
+
async function runScrubClear(driver, { argv = [], minChanged = 0.04 } = {}) {
|
|
100
|
+
const { land } = parseScrubClearArgs(argv);
|
|
101
|
+
const debug = driver.debug;
|
|
102
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
103
|
+
const ctx = await browser.newContext({ viewport: { width: 960, height: 540 } });
|
|
104
|
+
const page = await ctx.newPage();
|
|
105
|
+
const url = driver.BASE + (land ? '?land=' + land : '');
|
|
106
|
+
await driver.enter(page, url, { waitUntil: 'load', titledMs: 180000 });
|
|
107
|
+
await page.waitForTimeout(1500);
|
|
108
|
+
|
|
109
|
+
const settle = () =>
|
|
110
|
+
page.evaluate(async d => {
|
|
111
|
+
const app = window[d];
|
|
112
|
+
const wait = ms => new Promise(r => setTimeout(r, ms));
|
|
113
|
+
for (let i = 0; i < 24; i++) {
|
|
114
|
+
await app.bench(3);
|
|
115
|
+
await wait(75);
|
|
116
|
+
if (i >= 8 && (!app.quarters || app.quarters.every(q => !q.job))) break;
|
|
117
|
+
}
|
|
118
|
+
}, debug);
|
|
119
|
+
|
|
120
|
+
const bush = await page.evaluate(findClearingBushInPage, { debug });
|
|
121
|
+
if (!bush) {
|
|
122
|
+
console.log('FAILED no bush of the ground cover has a material that clears in scenes');
|
|
123
|
+
await browser.close();
|
|
124
|
+
return { passed: false, changed: 0, bush: null };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const shot = async (stem, pressed) => {
|
|
128
|
+
await page.evaluate(poseScrubShotInPage, { debug, bush, pressed });
|
|
129
|
+
await settle();
|
|
130
|
+
await page.evaluate(
|
|
131
|
+
([d, b]) => {
|
|
132
|
+
const app = window[d];
|
|
133
|
+
app.state.measuring = true;
|
|
134
|
+
app.camera.position.set(b.x + 3.2, b.y + 1.5, b.z + 2.4);
|
|
135
|
+
app.camera.lookAt(b.x, b.y + 0.5, b.z);
|
|
136
|
+
app.draw();
|
|
137
|
+
app.draw();
|
|
138
|
+
},
|
|
139
|
+
[debug, bush],
|
|
140
|
+
);
|
|
141
|
+
const canvas = page.locator(driver.canvasSelector || '#c');
|
|
142
|
+
const png = await canvas.screenshot({ type: 'png' });
|
|
143
|
+
await canvas.screenshot({ path: path.join(driver.OUT, stem + '.jpg'), type: 'jpeg', quality: 85 });
|
|
144
|
+
await page.evaluate(d => {
|
|
145
|
+
window[d].state.measuring = false;
|
|
146
|
+
}, debug);
|
|
147
|
+
return png.toString('base64');
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const stands = await shot('scrub-stands', false);
|
|
151
|
+
const cleared = await shot('scrub-cleared', true);
|
|
152
|
+
const changed = await page.evaluate(
|
|
153
|
+
async ([a, b]) => {
|
|
154
|
+
const pixels = async b64 => {
|
|
155
|
+
const bmp = await createImageBitmap(await (await fetch('data:image/png;base64,' + b64)).blob());
|
|
156
|
+
const c = new OffscreenCanvas(bmp.width, bmp.height);
|
|
157
|
+
const ctx2d = c.getContext('2d');
|
|
158
|
+
ctx2d.drawImage(bmp, 0, 0);
|
|
159
|
+
return { w: bmp.width, h: bmp.height, d: ctx2d.getImageData(0, 0, bmp.width, bmp.height).data };
|
|
160
|
+
};
|
|
161
|
+
const A = await pixels(a);
|
|
162
|
+
const B = await pixels(b);
|
|
163
|
+
let n = 0,
|
|
164
|
+
of = 0;
|
|
165
|
+
for (let y = Math.floor(A.h * 0.25); y < A.h * 0.85; y++)
|
|
166
|
+
for (let x = Math.floor(A.w * 0.3); x < A.w * 0.7; x++) {
|
|
167
|
+
const i = (y * A.w + x) * 4;
|
|
168
|
+
of++;
|
|
169
|
+
if (Math.abs(A.d[i] - B.d[i]) + Math.abs(A.d[i + 1] - B.d[i + 1]) + Math.abs(A.d[i + 2] - B.d[i + 2]) > 36) n++;
|
|
170
|
+
}
|
|
171
|
+
return n / of;
|
|
172
|
+
},
|
|
173
|
+
[stands, cleared],
|
|
174
|
+
);
|
|
175
|
+
await page.evaluate(d => window[d].pressGrass(0), debug);
|
|
176
|
+
const passed = changed > minChanged;
|
|
177
|
+
console.log(
|
|
178
|
+
`scrub-clear: a bush ${bush.d.toFixed(0)} m off, ${(changed * 100).toFixed(1)}% of the frame's middle changed when its ground was pressed`,
|
|
179
|
+
);
|
|
180
|
+
console.log(passed ? 'PASSED the bush is gone from a pressed disc' : 'FAILED the bush still stands in a pressed disc');
|
|
181
|
+
await browser.close();
|
|
182
|
+
return { passed, changed, bush };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
module.exports = {
|
|
186
|
+
computeCenterDiffShare,
|
|
187
|
+
findClearingBushInPage,
|
|
188
|
+
parseScrubClearArgs,
|
|
189
|
+
poseScrubShotInPage,
|
|
190
|
+
runScrubClear,
|
|
191
|
+
};
|