roamwright 0.61.15 → 0.61.16
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/effects.js +19 -13
- package/examples/island.js +21 -14
- package/examples/ruins.js +3 -2
- package/examples/stage.js +0 -6
- package/package.json +1 -1
- package/rendering/scatter-instances.js +12 -0
- package/tools/beasts-near.cjs +17 -0
- package/tools/beasts-near.test.cjs +36 -1
- package/tools/viewport-check.cjs +56 -21
package/examples/effects.js
CHANGED
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
createParticleSystem,
|
|
10
10
|
createSiteSchedule,
|
|
11
11
|
createSkyPanorama,
|
|
12
|
-
|
|
12
|
+
scatterInstances,
|
|
13
13
|
scatterTrees,
|
|
14
14
|
} from 'roamwright';
|
|
15
15
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
16
|
-
import { C
|
|
16
|
+
import { C } from 'roamwright/geometry/primitives.js';
|
|
17
17
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
18
18
|
import { createParticleEmitters, shakeCamera } from 'roamwright/rendering/particle-emitters.js';
|
|
19
19
|
import { createParticleBursts } from 'roamwright/rendering/particle-bursts.js';
|
|
@@ -118,17 +118,23 @@ sites.push(
|
|
|
118
118
|
createHouseKitMeshes({ materials: createHouseKitMaterials({ doubleSide: true }) }).kitStatic(propKit, worldGroup);
|
|
119
119
|
|
|
120
120
|
// Boulders and pines ringing the hillside behind the camp and misty hollow.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
121
|
+
scatterInstances({
|
|
122
|
+
geometries: [shapes.rock.clone().scale(1.4, 0.9, 1)],
|
|
123
|
+
parent: worldGroup,
|
|
124
|
+
material: new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.94, flatShading: true }),
|
|
125
|
+
attempts: 24,
|
|
126
|
+
maxPerBucket: 24,
|
|
127
|
+
random,
|
|
128
|
+
sample: () => {
|
|
129
|
+
const a = random() * Math.PI * 2,
|
|
130
|
+
r = 25 + random() * 24;
|
|
131
|
+
return [campCenter.x + Math.cos(a) * r, campCenter.z + Math.sin(a) * r];
|
|
132
|
+
},
|
|
133
|
+
groundAt,
|
|
134
|
+
sink: 0.1,
|
|
135
|
+
scaleRange: [0.6, 1.3],
|
|
136
|
+
colorAt: color => color.fromArray(C(0x6e6a62, 0.15, random)),
|
|
137
|
+
});
|
|
132
138
|
|
|
133
139
|
scatterTrees({
|
|
134
140
|
parent: worldGroup,
|
package/examples/island.js
CHANGED
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
createRenderContext,
|
|
7
7
|
createSimpleWater,
|
|
8
8
|
createUnitShapes,
|
|
9
|
-
|
|
9
|
+
scatterInstances,
|
|
10
10
|
scatterTrees,
|
|
11
11
|
mulberry32,
|
|
12
12
|
} from 'roamwright';
|
|
13
13
|
import { createHash } from 'roamwright/math/random.js';
|
|
14
14
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
15
|
-
import { C
|
|
15
|
+
import { C } from 'roamwright/geometry/primitives.js';
|
|
16
16
|
import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
|
|
17
17
|
import { readSeed } from './stage.js';
|
|
18
18
|
|
|
@@ -53,18 +53,25 @@ const island = createHeightfieldMesh({
|
|
|
53
53
|
island.castShadow = true;
|
|
54
54
|
worldGroup.add(island);
|
|
55
55
|
|
|
56
|
-
// Sculpted weathered boulders along the rocky headland and coves.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
// Sculpted weathered boulders along the rocky headland and coves, each tinted its own way.
|
|
57
|
+
scatterInstances({
|
|
58
|
+
geometries: [shapes.rock.clone().scale(1.35, 0.82, 1)],
|
|
59
|
+
parent: worldGroup,
|
|
60
|
+
material: new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.93, flatShading: true }),
|
|
61
|
+
attempts: 140,
|
|
62
|
+
maxPerBucket: 140,
|
|
63
|
+
random,
|
|
64
|
+
sample: () => {
|
|
65
|
+
const x = (random() - 0.5) * 82,
|
|
66
|
+
z = (random() - 0.5) * 82,
|
|
67
|
+
y = height(x, z);
|
|
68
|
+
return y < -0.3 || y > 18 ? null : [x, z];
|
|
69
|
+
},
|
|
70
|
+
groundAt: height,
|
|
71
|
+
sink: 0.25,
|
|
72
|
+
scaleRange: [0.45, 1.65],
|
|
73
|
+
colorAt: color => color.fromArray(C(0x838076, 0.18, random)),
|
|
74
|
+
});
|
|
68
75
|
|
|
69
76
|
// Coastal pines and cedars clustered on the sheltered green slopes.
|
|
70
77
|
scatterTrees({
|
package/examples/ruins.js
CHANGED
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
import { instanceArrays, instancedMesh, putInstance } from 'roamwright/geometry/instances.js';
|
|
17
17
|
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
18
18
|
import { sstep, TAU } from 'roamwright/math/scalar.js';
|
|
19
|
-
import {
|
|
19
|
+
import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
|
|
20
|
+
import { initExample } from './stage.js';
|
|
20
21
|
|
|
21
22
|
const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
|
|
22
23
|
fallbackSeed: 42,
|
|
@@ -48,7 +49,7 @@ const scrubTone = new THREE.Color(0x9a9168);
|
|
|
48
49
|
const rockTone = new THREE.Color(0xb6a382);
|
|
49
50
|
const hillTone = new THREE.Color(0xc2b296);
|
|
50
51
|
|
|
51
|
-
const terrain =
|
|
52
|
+
const terrain = createHeightfieldMesh({
|
|
52
53
|
size: 360,
|
|
53
54
|
segs: 180,
|
|
54
55
|
heightAt: height,
|
package/examples/stage.js
CHANGED
|
@@ -27,9 +27,3 @@ export function initExample({ fallbackSeed = 42, fov = 42 } = {}) {
|
|
|
27
27
|
const shapes = createUnitShapes(noise.fbm);
|
|
28
28
|
return { canvas, ...ctx, seed, random, noise, hash, shapes };
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Vertex-colored rolling terrain mesh with natural variation.
|
|
33
|
-
*/
|
|
34
|
-
// the examples' old name for the engine's rolling ground, kept for pages that still import it from here
|
|
35
|
-
export { createHeightfieldMesh as makeRollingGround } from 'roamwright/geometry/heightfield.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roamwright",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.16",
|
|
4
4
|
"description": "A procedural worldbuilding engine built on top of Three.js. Generate landscapes with rivers and changing weather, animate crowds, and explore on foot or in flight.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"threejs",
|
|
@@ -38,6 +38,9 @@ function createDefaultFoliageMaterial(roughness) {
|
|
|
38
38
|
* @param {boolean} [options.castShadow=true] - Whether each instanced mesh casts shadows.
|
|
39
39
|
* @param {boolean} [options.receiveShadow=true] - Whether each instanced mesh receives shadows.
|
|
40
40
|
* @param {boolean} [options.stopWhenFull=false] - Stop sampling early once every variant bucket is full.
|
|
41
|
+
* @param {((color: THREE.Color, x: number, y: number, z: number, index: number, bucket: number) => void) | null} [options.colorAt=null]
|
|
42
|
+
* - Writes each placed instance's colour into `color` (from where it stands, its index in its variant and the variant),
|
|
43
|
+
* multiplied into the material's colour; without it the instances carry no colour of their own.
|
|
41
44
|
* @returns {{ meshes: THREE.InstancedMesh[], material: THREE.Material, total: number, dispose: () => void }}
|
|
42
45
|
*/
|
|
43
46
|
export function scatterInstances({
|
|
@@ -55,6 +58,7 @@ export function scatterInstances({
|
|
|
55
58
|
castShadow = true,
|
|
56
59
|
receiveShadow = true,
|
|
57
60
|
stopWhenFull = false,
|
|
61
|
+
colorAt = null,
|
|
58
62
|
} = {}) {
|
|
59
63
|
if (!Array.isArray(geometries) || geometries.length === 0) {
|
|
60
64
|
throw new RangeError('geometries must be a non-empty array of BufferGeometry');
|
|
@@ -74,6 +78,7 @@ export function scatterInstances({
|
|
|
74
78
|
stopWhenFull,
|
|
75
79
|
});
|
|
76
80
|
|
|
81
|
+
const color = new THREE.Color();
|
|
77
82
|
const meshes = geometries.map((geometry, index) => {
|
|
78
83
|
const { count, matrices } = plan.buckets[index];
|
|
79
84
|
const mesh = new THREE.InstancedMesh(geometry, mat, 0);
|
|
@@ -81,6 +86,13 @@ export function scatterInstances({
|
|
|
81
86
|
mesh.count = count;
|
|
82
87
|
mesh.castShadow = castShadow;
|
|
83
88
|
mesh.receiveShadow = receiveShadow;
|
|
89
|
+
if (colorAt && count > 0) {
|
|
90
|
+
mesh.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array((matrices.length / 16) * 3), 3);
|
|
91
|
+
for (let i = 0; i < count; i++) {
|
|
92
|
+
colorAt(color, matrices[i * 16 + 12], matrices[i * 16 + 13], matrices[i * 16 + 14], i, index);
|
|
93
|
+
mesh.setColorAt(i, color);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
84
96
|
if (count > 0) mesh.computeBoundingSphere();
|
|
85
97
|
if (parent) parent.add(mesh);
|
|
86
98
|
return mesh;
|
package/tools/beasts-near.cjs
CHANGED
|
@@ -204,10 +204,19 @@ function settleHerdBeastInPage({ debug, crowdIndex, memberIndex, hour }) {
|
|
|
204
204
|
*
|
|
205
205
|
* @param {{ debug: string, actorId: string, hour: number | null }} arg
|
|
206
206
|
*/
|
|
207
|
+
// When a scene's script first shows an actor (a `[seconds, 'show', actorId]` step of its `steps`), or null if it never does.
|
|
208
|
+
function sceneShowTimeInPage({ debug, sceneId, actorId }) {
|
|
209
|
+
const ev = window[debug].CONFIG.events.find(e => e.id === sceneId);
|
|
210
|
+
const step = (ev?.steps || ev?.script || []).find(s => Array.isArray(s) && s[1] === 'show' && s[2] === actorId);
|
|
211
|
+
return step ? step[0] : null;
|
|
212
|
+
}
|
|
213
|
+
|
|
207
214
|
function settleActorInPage({ debug, actorId, hour }) {
|
|
208
215
|
const app = window[debug];
|
|
209
216
|
const a = app.actors?.[actorId];
|
|
210
217
|
if (!a?.group) return null;
|
|
218
|
+
// An actor a scene has not shown yet stands where it was built (the world's origin, under the land): nothing real to frame.
|
|
219
|
+
if (a.active === false) return { hidden: true };
|
|
211
220
|
const { THREE } = app;
|
|
212
221
|
if (app.director) app.director.paused = true;
|
|
213
222
|
app.env.flow = false;
|
|
@@ -395,6 +404,13 @@ async function runBeastsNear(
|
|
|
395
404
|
actorId,
|
|
396
405
|
hour: opts.hourExplicit ? opts.hour : null,
|
|
397
406
|
});
|
|
407
|
+
if (target?.hidden) {
|
|
408
|
+
const shownAt = await page.evaluate(sceneShowTimeInPage, { debug: driver.debug, sceneId: meta.id, actorId });
|
|
409
|
+
throw new Error(
|
|
410
|
+
`${actorId} is not shown at ${targetAt}s of ${meta.id}` +
|
|
411
|
+
(Number.isFinite(shownAt) ? `: it comes on at ${shownAt}s, so ask --at ${Math.ceil(shownAt + 1)} or later` : ''),
|
|
412
|
+
);
|
|
413
|
+
}
|
|
398
414
|
if (target) {
|
|
399
415
|
saved.push(
|
|
400
416
|
...(await captureTargetViews(page, driver, target, {
|
|
@@ -493,6 +509,7 @@ module.exports = {
|
|
|
493
509
|
parseBeastsNearArgs,
|
|
494
510
|
poseCameraAndDrawInPage,
|
|
495
511
|
runBeastsNear,
|
|
512
|
+
sceneShowTimeInPage,
|
|
496
513
|
settleActorInPage,
|
|
497
514
|
settleHerdBeastInPage,
|
|
498
515
|
};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const assert = require('node:assert/strict');
|
|
3
3
|
const test = require('node:test');
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
frameBeastView,
|
|
6
|
+
locateHerdBeastInPage,
|
|
7
|
+
parseBeastsNearArgs,
|
|
8
|
+
poseCameraAndDrawInPage,
|
|
9
|
+
sceneShowTimeInPage,
|
|
10
|
+
settleActorInPage,
|
|
11
|
+
} = require('./beasts-near.cjs');
|
|
5
12
|
|
|
6
13
|
test('parseBeastsNearArgs parses kinds, scene beat options, and flags cleanly', () => {
|
|
7
14
|
const parsed = parseBeastsNearArgs([
|
|
@@ -103,3 +110,31 @@ test('locateHerdBeastInPage and poseCameraAndDrawInPage talk strictly through wi
|
|
|
103
110
|
delete globalThis.window;
|
|
104
111
|
}
|
|
105
112
|
});
|
|
113
|
+
|
|
114
|
+
test('a scene actor not shown yet is refused, with the second its script shows it', () => {
|
|
115
|
+
const debug = 'BEASTS_TEST';
|
|
116
|
+
globalThis.window = {
|
|
117
|
+
[debug]: {
|
|
118
|
+
actors: { hound: { group: {}, active: false } },
|
|
119
|
+
CONFIG: {
|
|
120
|
+
events: [
|
|
121
|
+
{
|
|
122
|
+
id: 'hunt',
|
|
123
|
+
script: [
|
|
124
|
+
[0, 'hour', 6],
|
|
125
|
+
[12.5, 'show', 'hound'],
|
|
126
|
+
[14, 'show', 'crow'],
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
try {
|
|
134
|
+
assert.deepEqual(settleActorInPage({ debug, actorId: 'hound', hour: null }), { hidden: true });
|
|
135
|
+
assert.equal(sceneShowTimeInPage({ debug, sceneId: 'hunt', actorId: 'hound' }), 12.5);
|
|
136
|
+
assert.equal(sceneShowTimeInPage({ debug, sceneId: 'hunt', actorId: 'wolf' }), null);
|
|
137
|
+
} finally {
|
|
138
|
+
delete globalThis.window;
|
|
139
|
+
}
|
|
140
|
+
});
|
package/tools/viewport-check.cjs
CHANGED
|
@@ -20,6 +20,11 @@ const assert = require('node:assert/strict');
|
|
|
20
20
|
* @param {string} [options.fullscreenButtonSelector='#b-full'] Selector for the fullscreen toggle button.
|
|
21
21
|
* @param {string} [options.turnedClass='turned'] Body class used for rotated phone landscape layout.
|
|
22
22
|
* @param {string} [options.touchNonPhoneSelector='body.touch:not(.phone)'] Selector patched to simulate stale tablet CSS width.
|
|
23
|
+
* @param {{ output?: number, scene?: number }} [options.phoneScale={ output: 1, scene: 1 }] The share of each side the
|
|
24
|
+
* phone's Medium preset draws at: the output of its render limit, and the scene texture of the output (each within a
|
|
25
|
+
* pixel of rounding).
|
|
26
|
+
* @param {{ width: number, height: number }} [options.phoneLimit={ width: 1920, height: 1080 }] The most pixels the phone's
|
|
27
|
+
* output is drawn at, before `phoneScale`; a device with more is fitted into it.
|
|
23
28
|
* @returns {Promise<void>}
|
|
24
29
|
*/
|
|
25
30
|
async function runViewportCheck(
|
|
@@ -33,6 +38,8 @@ async function runViewportCheck(
|
|
|
33
38
|
fullscreenButtonSelector = '#b-full',
|
|
34
39
|
turnedClass = 'turned',
|
|
35
40
|
touchNonPhoneSelector = 'body.touch:not(.phone)',
|
|
41
|
+
phoneScale = {},
|
|
42
|
+
phoneLimit = { width: 1920, height: 1080 },
|
|
36
43
|
} = {},
|
|
37
44
|
) {
|
|
38
45
|
const { BASE, GPU, chromium, shell, debug, enter, applyStorage, routeUrl } = driver;
|
|
@@ -135,35 +142,63 @@ async function runViewportCheck(
|
|
|
135
142
|
await picture(1920, 1080);
|
|
136
143
|
await page.close();
|
|
137
144
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
// Checks the output is `width` x `height` (or, given a `scale` `{ output, scene }`, the device's pixels of that size fitted
|
|
146
|
+
// into the phone's limit drawn at `scale.output` of each side) and the scene texture `scale.scene` of the output.
|
|
147
|
+
async function checkTouchViewport(tab, width, height, scale = null) {
|
|
148
|
+
const fit = scale
|
|
149
|
+
? Math.min(1, (phoneLimit.width * (scale.output ?? 1)) / width, (phoneLimit.height * (scale.output ?? 1)) / height)
|
|
150
|
+
: 1;
|
|
151
|
+
const outW = Math.floor(width * fit);
|
|
152
|
+
const outH = Math.floor(height * fit);
|
|
153
|
+
const sceneW = Math.round(outW * (scale?.scene ?? 1));
|
|
154
|
+
const sceneH = Math.round(outH * (scale?.scene ?? 1));
|
|
155
|
+
await tab
|
|
156
|
+
.waitForFunction(
|
|
157
|
+
([d, w, h, sw, sh]) => {
|
|
158
|
+
const { renderer, post } = window[d];
|
|
159
|
+
const gl = renderer.getContext();
|
|
160
|
+
const bounds = renderer.domElement.getBoundingClientRect();
|
|
161
|
+
const near = (a, b) => Math.abs(a - b) <= 1;
|
|
162
|
+
return (
|
|
163
|
+
near(gl.drawingBufferWidth, w) &&
|
|
164
|
+
near(gl.drawingBufferHeight, h) &&
|
|
165
|
+
near(post.sceneRT.width, sw) &&
|
|
166
|
+
near(post.sceneRT.height, sh) &&
|
|
167
|
+
Math.abs(bounds.width - innerWidth) < 1 &&
|
|
168
|
+
Math.abs(bounds.height - innerHeight) < 1
|
|
169
|
+
);
|
|
170
|
+
},
|
|
171
|
+
[debug, outW, outH, sceneW, sceneH],
|
|
172
|
+
{ timeout: 12000 },
|
|
173
|
+
)
|
|
174
|
+
.catch(async error => {
|
|
175
|
+
console.error(
|
|
176
|
+
await tab.evaluate(d => {
|
|
177
|
+
const { renderer, post } = window[d];
|
|
178
|
+
const gl = renderer.getContext();
|
|
179
|
+
const bounds = renderer.domElement.getBoundingClientRect();
|
|
180
|
+
return {
|
|
181
|
+
buffer: [gl.drawingBufferWidth, gl.drawingBufferHeight],
|
|
182
|
+
scene: [post.sceneRT.width, post.sceneRT.height],
|
|
183
|
+
bounds: [bounds.width, bounds.height],
|
|
184
|
+
viewport: [innerWidth, innerHeight],
|
|
185
|
+
ratio: renderer.getPixelRatio(),
|
|
186
|
+
};
|
|
187
|
+
}, debug),
|
|
151
188
|
);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
156
|
-
console.log(width + ' x ' + height + ' scene and output filling the touch viewport');
|
|
189
|
+
throw error;
|
|
190
|
+
});
|
|
191
|
+
console.log(`${outW} x ${outH} output and ${sceneW} x ${sceneH} scene filling the touch viewport`);
|
|
157
192
|
}
|
|
158
193
|
|
|
159
194
|
const phone = await browser.newPage({ viewport: { width: 430, height: 932 }, deviceScaleFactor: 3, hasTouch: true, isMobile: true });
|
|
160
195
|
await applyStorage(phone, { quality: 'medium' });
|
|
161
196
|
await enter(phone, pageUrl, { waitUntil: 'load', direct: true });
|
|
162
|
-
await checkTouchViewport(phone,
|
|
197
|
+
await checkTouchViewport(phone, 2796, 1290, phoneScale); // 932 x 430 at 3x, turned
|
|
163
198
|
await phone.setViewportSize({ width: 742, height: 430 });
|
|
164
|
-
await checkTouchViewport(phone,
|
|
199
|
+
await checkTouchViewport(phone, 2226, 1290, phoneScale);
|
|
165
200
|
await phone.setViewportSize({ width: 600, height: 300 });
|
|
166
|
-
await checkTouchViewport(phone, 1800, 900);
|
|
201
|
+
await checkTouchViewport(phone, 1800, 900, phoneScale);
|
|
167
202
|
await phone.close();
|
|
168
203
|
|
|
169
204
|
const tablet = await browser.newPage({
|