roamwright 0.61.20 → 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/README.md +13 -12
- package/examples/scenes.html +54 -0
- package/examples/scenes.js +594 -0
- package/geometry/projectile-shapes.js +85 -0
- package/index.js +50 -0
- package/motion/fallen-mount.js +63 -0
- package/motion/melee-combat.js +328 -0
- package/motion/melee-cuts.js +395 -0
- package/motion/melee-duels.js +142 -0
- package/motion/melee-exchange-creatures.js +86 -0
- package/motion/melee-exchange.js +498 -0
- package/motion/melee-reactions.js +147 -0
- package/motion/prop-contact.js +87 -0
- package/package.json +1 -1
- package/rendering/blade-trails.js +128 -0
- package/rendering/scene-beams.js +486 -0
- package/rendering/scene-coverage.js +500 -0
- package/rendering/scene-markers.js +421 -0
- package/rendering/scene-projectiles.js +395 -0
- package/rendering/scene-props.js +383 -0
- package/rendering/scene-shots.js +199 -0
- package/runtime/foley-surface.js +79 -0
- package/runtime/scene-script.js +137 -0
- package/runtime/scene-zones.js +117 -0
- 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,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const { computeCenterDiffShare, findClearingBushInPage, parseScrubClearArgs, poseScrubShotInPage } = require('./scrub-clear.cjs');
|
|
5
|
+
|
|
6
|
+
test('parseScrubClearArgs and computeCenterDiffShare measure center-frame pixel change', () => {
|
|
7
|
+
assert.deepEqual(parseScrubClearArgs(['coast']), { land: 'coast' });
|
|
8
|
+
assert.deepEqual(parseScrubClearArgs([]), { land: '' });
|
|
9
|
+
|
|
10
|
+
const w = 10,
|
|
11
|
+
h = 10;
|
|
12
|
+
const a = new Uint8Array(w * h * 4);
|
|
13
|
+
const b = new Uint8Array(w * h * 4);
|
|
14
|
+
for (let i = 0; i < w * h; i++) {
|
|
15
|
+
a[i * 4] = 80;
|
|
16
|
+
a[i * 4 + 1] = 100;
|
|
17
|
+
a[i * 4 + 2] = 60;
|
|
18
|
+
a[i * 4 + 3] = 255;
|
|
19
|
+
b[i * 4] = i % 2 === 0 ? 110 : 80;
|
|
20
|
+
b[i * 4 + 1] = i % 2 === 0 ? 115 : 100;
|
|
21
|
+
b[i * 4 + 2] = 60;
|
|
22
|
+
b[i * 4 + 3] = 255;
|
|
23
|
+
}
|
|
24
|
+
assert.equal(computeCenterDiffShare(a, b, w, h, 36), 0.5);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('scrub-clear in-page helpers locate clearing bushes and press discs via window[debug]', () => {
|
|
28
|
+
class Vec3 {
|
|
29
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
30
|
+
this.x = x;
|
|
31
|
+
this.y = y;
|
|
32
|
+
this.z = z;
|
|
33
|
+
}
|
|
34
|
+
set(x, y, z) {
|
|
35
|
+
this.x = x;
|
|
36
|
+
this.y = y;
|
|
37
|
+
this.z = z;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
setFromMatrixPosition(m) {
|
|
41
|
+
[this.x, this.y, this.z] = m.p;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
applyMatrix4() {
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class Matrix4 {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.p = [0, 0, 0];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const discs = [
|
|
54
|
+
{
|
|
55
|
+
x: 0,
|
|
56
|
+
z: 0,
|
|
57
|
+
r: 0,
|
|
58
|
+
set(x, z, r) {
|
|
59
|
+
this.x = x;
|
|
60
|
+
this.z = z;
|
|
61
|
+
this.r = r;
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
let pressedCount = -1;
|
|
66
|
+
const bushMesh = {
|
|
67
|
+
isInstancedMesh: true,
|
|
68
|
+
count: 3,
|
|
69
|
+
material: { customProgramCacheKey: () => 'bush-cleared-in-discs' },
|
|
70
|
+
geometry: { attributes: { position: { count: 400 } } },
|
|
71
|
+
matrixWorld: {},
|
|
72
|
+
getMatrixAt(i, m) {
|
|
73
|
+
m.p = [20 + i, 1, 0];
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
globalThis.window = {
|
|
77
|
+
APP: {
|
|
78
|
+
THREE: { Matrix4 },
|
|
79
|
+
env: { flow: true, time: 0.4 },
|
|
80
|
+
state: { mode: 'play' },
|
|
81
|
+
camera: { position: new Vec3(0, 1.5, 0), lookAt() {} },
|
|
82
|
+
scene: { traverse: fn => fn(bushMesh) },
|
|
83
|
+
holdQuality() {},
|
|
84
|
+
placePlayer() {},
|
|
85
|
+
pressGrass(n) {
|
|
86
|
+
pressedCount = n;
|
|
87
|
+
return discs;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
const bush = findClearingBushInPage({ debug: 'APP' });
|
|
93
|
+
assert.ok(bush && bush.x === 20);
|
|
94
|
+
poseScrubShotInPage({ debug: 'APP', bush, pressed: true, radius: 1.6 });
|
|
95
|
+
assert.equal(pressedCount, 1);
|
|
96
|
+
assert.equal(discs[0].r, 1.6);
|
|
97
|
+
} finally {
|
|
98
|
+
delete globalThis.window;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// Tree look and dense-wood benchmark runners built on a Roamwright page driver.
|
|
2
|
+
// Inspects instanced `tree:<kind>` meshes from four distances (`runTreeLook`) and benchmarks GPU frame time
|
|
3
|
+
// across the densest 100 m square of a given tree kind (`runTreeBench`).
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/** Default camera distances for `runTreeLook`: `[view, metresBack, metresUp, lookHeightScale]`. */
|
|
7
|
+
const TREE_LOOK_VIEWS = [
|
|
8
|
+
['eye', 13, 1.7, 3.5],
|
|
9
|
+
['above', 20, 17, 3],
|
|
10
|
+
['middle', 55, 6, 4],
|
|
11
|
+
['far', 240, 30, 4],
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
/** Default camera distances for `runTreeBench`: `[view, metresBack, metresUp]`. */
|
|
15
|
+
const TREE_BENCH_VIEWS = [
|
|
16
|
+
['eye', 70, 1.7],
|
|
17
|
+
['over', 90, 22],
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parses CLI arguments for `runTreeLook`: `<name> [kind=1] [x,z] [hour=0.42] [width=1728] [height=1117]`.
|
|
22
|
+
*
|
|
23
|
+
* @param {string[]} [argv=[]]
|
|
24
|
+
* @returns {{ name: string, kind: string, near: [number, number] | null, hour: number, width: number, height: number }}
|
|
25
|
+
*/
|
|
26
|
+
function parseTreeLookArgs(argv = []) {
|
|
27
|
+
const [name = 'tree', kind = '1', nearStr = '', hour = '0.42', width = 1728, height = 1117] = argv;
|
|
28
|
+
const near = nearStr ? nearStr.split(',').map(Number) : null;
|
|
29
|
+
return { name, kind: String(kind), near, hour: +hour, width: +width, height: +height };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Parses CLI arguments for `runTreeBench`: `<name> [kind=1] [quality=high]`.
|
|
34
|
+
*
|
|
35
|
+
* @param {string[]} [argv=[]]
|
|
36
|
+
* @returns {{ name: string, kind: string, quality: string }}
|
|
37
|
+
*/
|
|
38
|
+
function parseTreeBenchArgs(argv = []) {
|
|
39
|
+
const [name = 'trees', kind = '1', quality = 'high'] = argv;
|
|
40
|
+
return { name, kind: String(kind), quality };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Places the visitor at `(x, z, yaw)` inside `window[debug]`.
|
|
45
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
46
|
+
*
|
|
47
|
+
* @param {{ debug: string, x: number, z: number, yaw?: number }} arg
|
|
48
|
+
*/
|
|
49
|
+
function placeVisitorInPage({ debug, x, z, yaw = 0 }) {
|
|
50
|
+
window[debug].placePlayer(x, z, yaw);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Finds the nearest instanced tree of `meshPrefix + kind` to the camera and chooses the openest
|
|
55
|
+
* of 16 compass headings (fewest blocking trees within 3..60 m along and 6 m aside).
|
|
56
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
57
|
+
*
|
|
58
|
+
* @param {{ debug: string, kind: string, meshPrefix?: string }} arg
|
|
59
|
+
* @returns {{ d: number, x: number, y: number, z: number, scale: number, open: number } | null}
|
|
60
|
+
*/
|
|
61
|
+
function findNearestTreeInPage({ debug, kind, meshPrefix = 'tree:' }) {
|
|
62
|
+
const { THREE, scene, camera } = window[debug];
|
|
63
|
+
const m = new THREE.Matrix4();
|
|
64
|
+
const at = new THREE.Vector3();
|
|
65
|
+
const all = [];
|
|
66
|
+
let best = null;
|
|
67
|
+
scene.traverse(o => {
|
|
68
|
+
if (!o.isInstancedMesh || !o.name?.startsWith(meshPrefix)) return;
|
|
69
|
+
for (let i = 0; i < o.count; i++) {
|
|
70
|
+
o.getMatrixAt(i, m);
|
|
71
|
+
at.setFromMatrixPosition(m);
|
|
72
|
+
all.push([at.x, at.z]);
|
|
73
|
+
const d = Math.hypot(at.x - camera.position.x, at.z - camera.position.z);
|
|
74
|
+
if (o.name === meshPrefix + kind && (!best || d < best.d))
|
|
75
|
+
best = { d, x: at.x, y: at.y, z: at.z, scale: new THREE.Vector3().setFromMatrixScale(m).y };
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (!best) return null;
|
|
79
|
+
let open = 0,
|
|
80
|
+
fewest = Infinity;
|
|
81
|
+
for (let k = 0; k < 16; k++) {
|
|
82
|
+
const a = (k / 16) * Math.PI * 2,
|
|
83
|
+
dx = Math.sin(a),
|
|
84
|
+
dz = Math.cos(a);
|
|
85
|
+
const blocking = all.filter(([x, z]) => {
|
|
86
|
+
const along = (x - best.x) * dx + (z - best.z) * dz,
|
|
87
|
+
aside = Math.abs((x - best.x) * dz - (z - best.z) * dx);
|
|
88
|
+
return along > 3 && along < 60 && aside < 6;
|
|
89
|
+
}).length;
|
|
90
|
+
if (blocking < fewest) [fewest, open] = [blocking, a];
|
|
91
|
+
}
|
|
92
|
+
return { ...best, open };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Poses the inspect camera along `tree.open` at `(distance, up)` aimed at `tree.y + look * tree.scale`.
|
|
97
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
98
|
+
*
|
|
99
|
+
* @param {{ debug: string, tree: object, distance: number, up: number, look: number, hour: number }} arg
|
|
100
|
+
* @returns {{ y: number }}
|
|
101
|
+
*/
|
|
102
|
+
function poseTreeViewInPage({ debug, tree, distance, up, look, hour }) {
|
|
103
|
+
const app = window[debug];
|
|
104
|
+
app.holdQuality(true);
|
|
105
|
+
app.env.flow = false;
|
|
106
|
+
app.env.time = hour;
|
|
107
|
+
app.state.mode = 'inspect';
|
|
108
|
+
const x = tree.x + Math.sin(tree.open) * distance;
|
|
109
|
+
const z = tree.z + Math.cos(tree.open) * distance;
|
|
110
|
+
const y = Math.max(tree.y, app.space.ground(x, z)) + up;
|
|
111
|
+
app.camera.position.set(x, y, z);
|
|
112
|
+
app.camera.lookAt(tree.x, tree.y + look * tree.scale, tree.z);
|
|
113
|
+
return { y: +y.toFixed(1) };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Finds the `cellSize`-metre grid square containing the most instanced trees of `meshPrefix + kind`.
|
|
118
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
119
|
+
*
|
|
120
|
+
* @param {{ debug: string, kind: string, meshPrefix?: string, cellSize?: number }} arg
|
|
121
|
+
* @returns {{ x: number, z: number, count: number } | null}
|
|
122
|
+
*/
|
|
123
|
+
function findDensestTreeSquareInPage({ debug, kind, meshPrefix = 'tree:', cellSize = 100 }) {
|
|
124
|
+
const { THREE, scene } = window[debug];
|
|
125
|
+
const m = new THREE.Matrix4();
|
|
126
|
+
const at = new THREE.Vector3();
|
|
127
|
+
const squares = new Map();
|
|
128
|
+
scene.traverse(o => {
|
|
129
|
+
if (o.name !== meshPrefix + kind) return;
|
|
130
|
+
for (let i = 0; i < o.count; i++) {
|
|
131
|
+
o.getMatrixAt(i, m);
|
|
132
|
+
at.setFromMatrixPosition(m);
|
|
133
|
+
const key = Math.floor(at.x / cellSize) + ':' + Math.floor(at.z / cellSize);
|
|
134
|
+
squares.set(key, (squares.get(key) ?? 0) + 1);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
let best = null;
|
|
138
|
+
for (const [key, count] of squares) if (!best || count > best.count) best = { key, count };
|
|
139
|
+
if (!best) return null;
|
|
140
|
+
const [cx, cz] = best.key.split(':').map(Number);
|
|
141
|
+
return { x: cx * cellSize + cellSize / 2, z: cz * cellSize + cellSize / 2, count: best.count };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Poses the inspect camera south of the densest wood square looking across its crowns.
|
|
146
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
147
|
+
*
|
|
148
|
+
* @param {{ debug: string, wood: { x: number, z: number }, back: number, up: number, hour: number }} arg
|
|
149
|
+
*/
|
|
150
|
+
function poseTreeBenchViewInPage({ debug, wood, back, up, hour }) {
|
|
151
|
+
const app = window[debug];
|
|
152
|
+
app.holdQuality(true);
|
|
153
|
+
app.env.flow = false;
|
|
154
|
+
app.env.time = hour;
|
|
155
|
+
app.state.mode = 'inspect';
|
|
156
|
+
const x = wood.x;
|
|
157
|
+
const z = wood.z + back;
|
|
158
|
+
const y = app.space.ground(x, z) + up;
|
|
159
|
+
app.camera.position.set(x, y, z);
|
|
160
|
+
app.camera.lookAt(wood.x, app.space.ground(wood.x, wood.z) + 4, wood.z);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Captures four stills (`eye`, `above`, `middle`, `far`) of the nearest tree of a given kind from its openest side.
|
|
165
|
+
*
|
|
166
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
167
|
+
* @param {object} [options]
|
|
168
|
+
* @param {string[]} [options.argv=[]] Raw CLI arguments (`<name> [kind=1] [x,z] [hour=0.42] [width] [height]`).
|
|
169
|
+
* @param {string} [options.address=''] Route address to enter.
|
|
170
|
+
* @param {string} [options.meshPrefix='tree:'] Instanced mesh name prefix.
|
|
171
|
+
* @param {Array} [options.views=TREE_LOOK_VIEWS]
|
|
172
|
+
* @returns {Promise<{ tree: object, files: string[] }>}
|
|
173
|
+
*/
|
|
174
|
+
async function runTreeLook(driver, { argv = [], address = '', meshPrefix = 'tree:', views = TREE_LOOK_VIEWS } = {}) {
|
|
175
|
+
const { name, kind, near, hour, width, height } = parseTreeLookArgs(argv);
|
|
176
|
+
const debug = driver.debug;
|
|
177
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
178
|
+
const ctx = await browser.newContext({ viewport: { width, height } });
|
|
179
|
+
await driver.applyStorage(ctx, { quality: 'high', muted: '1' });
|
|
180
|
+
const page = await ctx.newPage();
|
|
181
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 300)));
|
|
182
|
+
page.on('console', m => m.type() === 'error' && console.log('CONSOLE', m.text().slice(0, 300)));
|
|
183
|
+
await driver.enter(page, driver.routeUrl(address));
|
|
184
|
+
await page.waitForTimeout(3000);
|
|
185
|
+
await page.addStyleTag({ content: '#card, #keys, .card { display: none !important; }' });
|
|
186
|
+
if (near) {
|
|
187
|
+
await page.evaluate(placeVisitorInPage, { debug, x: near[0], z: near[1], yaw: 0 });
|
|
188
|
+
await page.waitForTimeout(5000);
|
|
189
|
+
}
|
|
190
|
+
const tree = await page.evaluate(findNearestTreeInPage, { debug, kind, meshPrefix });
|
|
191
|
+
if (!tree) {
|
|
192
|
+
console.log('FAILED no tree of kind', kind, 'is built near there');
|
|
193
|
+
await driver.closeBrowser(browser);
|
|
194
|
+
process.exit(1);
|
|
195
|
+
}
|
|
196
|
+
console.log(
|
|
197
|
+
'tree',
|
|
198
|
+
JSON.stringify({ x: +tree.x.toFixed(1), z: +tree.z.toFixed(1), scale: +tree.scale.toFixed(2), open: +tree.open.toFixed(2) }),
|
|
199
|
+
);
|
|
200
|
+
const files = [];
|
|
201
|
+
for (const [view, distance, up, look] of views) {
|
|
202
|
+
const said = await page.evaluate(poseTreeViewInPage, { debug, tree, distance, up, look, hour });
|
|
203
|
+
await page.waitForTimeout(2500);
|
|
204
|
+
const outFile = `${driver.OUT}/${name}-${view}.jpg`;
|
|
205
|
+
await page.screenshot({ path: outFile, type: 'jpeg', quality: 82 });
|
|
206
|
+
files.push(outFile);
|
|
207
|
+
console.log('saved', `${name}-${view}`, JSON.stringify(said));
|
|
208
|
+
}
|
|
209
|
+
await driver.closeBrowser(browser);
|
|
210
|
+
return { tree, files };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Benchmarks GPU frame cost looking across the densest 100 m square of a given tree kind (`bench()` x 3 per view)
|
|
215
|
+
* and saves a still of each view.
|
|
216
|
+
*
|
|
217
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
218
|
+
* @param {object} [options]
|
|
219
|
+
* @param {string[]} [options.argv=[]] Raw CLI arguments (`<name> [kind=1] [quality=high]`).
|
|
220
|
+
* @param {string} [options.address=''] Route address to enter.
|
|
221
|
+
* @param {string} [options.meshPrefix='tree:'] Instanced mesh name prefix.
|
|
222
|
+
* @param {number} [options.hour=0.45] Time of day (`0..1`).
|
|
223
|
+
* @param {Array} [options.views=TREE_BENCH_VIEWS]
|
|
224
|
+
* @returns {Promise<{ wood: object, views: Record<string, Array<object>> }>}
|
|
225
|
+
*/
|
|
226
|
+
async function runTreeBench(driver, { argv = [], address = '', meshPrefix = 'tree:', hour = 0.45, views = TREE_BENCH_VIEWS } = {}) {
|
|
227
|
+
const { name, kind, quality } = parseTreeBenchArgs(argv);
|
|
228
|
+
const debug = driver.debug;
|
|
229
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
230
|
+
const ctx = await browser.newContext({ viewport: { width: 1728, height: 1117 }, deviceScaleFactor: 2 });
|
|
231
|
+
await driver.applyStorage(ctx, { quality, muted: '1' });
|
|
232
|
+
const page = await ctx.newPage();
|
|
233
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 300)));
|
|
234
|
+
await driver.enter(page, driver.routeUrl(address));
|
|
235
|
+
await page.waitForTimeout(3000);
|
|
236
|
+
const wood = await page.evaluate(findDensestTreeSquareInPage, { debug, kind, meshPrefix, cellSize: 100 });
|
|
237
|
+
if (!wood) {
|
|
238
|
+
console.log('FAILED no tree of kind', kind);
|
|
239
|
+
await driver.closeBrowser(browser);
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
console.log('wood', JSON.stringify(wood));
|
|
243
|
+
await page.evaluate(placeVisitorInPage, { debug, x: wood.x, z: wood.z + 70, yaw: Math.PI });
|
|
244
|
+
await page.waitForTimeout(6000);
|
|
245
|
+
const results = {};
|
|
246
|
+
for (const [view, back, up] of views) {
|
|
247
|
+
await page.evaluate(poseTreeBenchViewInPage, { debug, wood, back, up, hour });
|
|
248
|
+
await page.waitForTimeout(3000);
|
|
249
|
+
const runs = [];
|
|
250
|
+
for (let k = 0; k < 3; k++) runs.push(await page.evaluate(d => window[d].bench(), debug));
|
|
251
|
+
await page.screenshot({ path: `${driver.OUT}/${name}-${view}.jpg`, type: 'jpeg', quality: 78 });
|
|
252
|
+
console.log(view, JSON.stringify(runs));
|
|
253
|
+
results[view] = runs;
|
|
254
|
+
}
|
|
255
|
+
await driver.closeBrowser(browser);
|
|
256
|
+
return { wood, views: results };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
module.exports = {
|
|
260
|
+
TREE_BENCH_VIEWS,
|
|
261
|
+
TREE_LOOK_VIEWS,
|
|
262
|
+
findDensestTreeSquareInPage,
|
|
263
|
+
findNearestTreeInPage,
|
|
264
|
+
parseTreeBenchArgs,
|
|
265
|
+
parseTreeLookArgs,
|
|
266
|
+
placeVisitorInPage,
|
|
267
|
+
poseTreeBenchViewInPage,
|
|
268
|
+
poseTreeViewInPage,
|
|
269
|
+
runTreeBench,
|
|
270
|
+
runTreeLook,
|
|
271
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const {
|
|
5
|
+
TREE_BENCH_VIEWS,
|
|
6
|
+
TREE_LOOK_VIEWS,
|
|
7
|
+
findDensestTreeSquareInPage,
|
|
8
|
+
findNearestTreeInPage,
|
|
9
|
+
parseTreeBenchArgs,
|
|
10
|
+
parseTreeLookArgs,
|
|
11
|
+
poseTreeBenchViewInPage,
|
|
12
|
+
poseTreeViewInPage,
|
|
13
|
+
} = require('./tree-inspect.cjs');
|
|
14
|
+
|
|
15
|
+
test('parseTreeLookArgs and parseTreeBenchArgs decode CLI arguments and defaults', () => {
|
|
16
|
+
assert.deepEqual(parseTreeLookArgs(['oak', '0', '10,20', '0.5', '800', '600']), {
|
|
17
|
+
name: 'oak',
|
|
18
|
+
kind: '0',
|
|
19
|
+
near: [10, 20],
|
|
20
|
+
hour: 0.5,
|
|
21
|
+
width: 800,
|
|
22
|
+
height: 600,
|
|
23
|
+
});
|
|
24
|
+
assert.deepEqual(parseTreeLookArgs([]), {
|
|
25
|
+
name: 'tree',
|
|
26
|
+
kind: '1',
|
|
27
|
+
near: null,
|
|
28
|
+
hour: 0.42,
|
|
29
|
+
width: 1728,
|
|
30
|
+
height: 1117,
|
|
31
|
+
});
|
|
32
|
+
assert.deepEqual(parseTreeBenchArgs(['wood', '2', 'medium']), { name: 'wood', kind: '2', quality: 'medium' });
|
|
33
|
+
assert.equal(TREE_LOOK_VIEWS.length, 4);
|
|
34
|
+
assert.equal(TREE_BENCH_VIEWS.length, 2);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('tree-inspect in-page helpers locate nearest tree, densest square, and pose camera via window[debug]', () => {
|
|
38
|
+
class Matrix4 {
|
|
39
|
+
constructor() {
|
|
40
|
+
this.p = [0, 0, 0];
|
|
41
|
+
this.s = 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class Vector3 {
|
|
45
|
+
constructor() {
|
|
46
|
+
this.x = 0;
|
|
47
|
+
this.y = 0;
|
|
48
|
+
this.z = 0;
|
|
49
|
+
}
|
|
50
|
+
setFromMatrixPosition(m) {
|
|
51
|
+
[this.x, this.y, this.z] = m.p;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
setFromMatrixScale(m) {
|
|
55
|
+
this.x = this.y = this.z = m.s;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const positions = [
|
|
60
|
+
[10, 2, 20],
|
|
61
|
+
[10, 2, 35],
|
|
62
|
+
[115, 2, 210],
|
|
63
|
+
[130, 2, 220],
|
|
64
|
+
[140, 2, 240],
|
|
65
|
+
];
|
|
66
|
+
const inst = {
|
|
67
|
+
isInstancedMesh: true,
|
|
68
|
+
name: 'tree:1',
|
|
69
|
+
count: positions.length,
|
|
70
|
+
getMatrixAt(i, m) {
|
|
71
|
+
m.p = positions[i];
|
|
72
|
+
m.s = 1.2;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
let lookedAt = null;
|
|
76
|
+
const camPos = {
|
|
77
|
+
x: 0,
|
|
78
|
+
y: 0,
|
|
79
|
+
z: 0,
|
|
80
|
+
set(x, y, z) {
|
|
81
|
+
this.x = x;
|
|
82
|
+
this.y = y;
|
|
83
|
+
this.z = z;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
globalThis.window = {
|
|
87
|
+
APP: {
|
|
88
|
+
THREE: { Matrix4, Vector3 },
|
|
89
|
+
scene: { traverse: fn => fn(inst) },
|
|
90
|
+
camera: {
|
|
91
|
+
position: camPos,
|
|
92
|
+
lookAt(x, y, z) {
|
|
93
|
+
lookedAt = [x, y, z];
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
space: { ground: () => 5 },
|
|
97
|
+
env: { flow: true, time: 0.2 },
|
|
98
|
+
state: { mode: 'play' },
|
|
99
|
+
holdQuality() {},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
try {
|
|
103
|
+
const found = findNearestTreeInPage({ debug: 'APP', kind: '1' });
|
|
104
|
+
assert.ok(found);
|
|
105
|
+
assert.equal(found.x, 10);
|
|
106
|
+
assert.equal(found.z, 20);
|
|
107
|
+
assert.equal(found.scale, 1.2);
|
|
108
|
+
assert.notEqual(found.open, 0, 'heading 0 (+z) is blocked by tree at (10, 35)');
|
|
109
|
+
|
|
110
|
+
const posed = poseTreeViewInPage({ debug: 'APP', tree: found, distance: 13, up: 1.7, look: 3.5, hour: 0.42 });
|
|
111
|
+
assert.equal(posed.y, 6.7);
|
|
112
|
+
assert.deepEqual(lookedAt, [10, 2 + 3.5 * 1.2, 20]);
|
|
113
|
+
|
|
114
|
+
const wood = findDensestTreeSquareInPage({ debug: 'APP', kind: '1' });
|
|
115
|
+
assert.deepEqual(wood, { x: 150, z: 250, count: 3 });
|
|
116
|
+
|
|
117
|
+
poseTreeBenchViewInPage({ debug: 'APP', wood, back: 70, up: 1.7, hour: 0.45 });
|
|
118
|
+
assert.deepEqual([camPos.x, camPos.y, camPos.z], [150, 6.7, 320]);
|
|
119
|
+
assert.deepEqual(lookedAt, [150, 9, 250]);
|
|
120
|
+
} finally {
|
|
121
|
+
delete globalThis.window;
|
|
122
|
+
}
|
|
123
|
+
});
|