roamwright 0.61.24 → 0.61.25

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 CHANGED
@@ -30,7 +30,7 @@ npm resolves the Three.js peer in a new project. Roamwright targets Three.js **0
30
30
 
31
31
  ## Examples
32
32
 
33
- Browse all twenty-one examples on the [live showcase](https://enestaylan.github.io/roamwright/).
33
+ Browse all twenty-two examples on the [live showcase](https://enestaylan.github.io/roamwright/).
34
34
 
35
35
  | Live example | What the example shows | Source |
36
36
  | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
@@ -55,6 +55,7 @@ Browse all twenty-one examples on the [live showcase](https://enestaylan.github.
55
55
  | [Pacing and measuring](https://enestaylan.github.io/roamwright/examples/pacing.html?seed=42) | Device-aware presets, ground render order, frame-pacing watch and a live performance box over a coastal valley. | [pacing.js](examples/pacing.js) |
56
56
  | [World map and wayfinding](https://enestaylan.github.io/roamwright/examples/world-map.html?seed=42) | Shaded atlas relief, baked terrain sheets, collision-free lettering, interactive pan/zoom/tap and a live compass strip. | [world-map.js](examples/world-map.js) |
57
57
  | [Scenes](https://enestaylan.github.io/roamwright/examples/scenes.html?seed=42) | Melee duels with blade trails, flying bolts, energy beams, props, instanced scene markers and automated camera cuts. | [scenes.js](examples/scenes.js) |
58
+ | [Title backdrop](https://enestaylan.github.io/roamwright/examples/title-backdrop.html?seed=42) | Procedural 2D parallax mountain ranges, snow lines, sunlit cumulus banks and freeze-on-load canvas handoff. | [title-backdrop.js](examples/title-backdrop.js) |
58
59
 
59
60
  ### Run locally
60
61
 
@@ -0,0 +1,52 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="theme-color" content="#152c2c" />
7
+ <title>Title backdrop · Roamwright</title>
8
+ <link rel="stylesheet" href="./showcase.css" />
9
+ <script type="importmap">
10
+ {
11
+ "imports": {
12
+ "three": "../node_modules/three/build/three.module.js",
13
+ "three/addons/": "../node_modules/three/examples/jsm/",
14
+ "roamwright": "../index.js",
15
+ "roamwright/": "../"
16
+ }
17
+ }
18
+ </script>
19
+ </head>
20
+ <body>
21
+ <canvas
22
+ tabindex="0"
23
+ aria-label="Layered 2D parallax title backdrop with procedural ridge-noise mountain ranges, drifting cumulus clouds and sunlit sky"
24
+ ></canvas>
25
+ <header>
26
+ <a class="back" href="../index.html"><span aria-hidden="true">←</span> Roamwright</a>
27
+ <div class="meta">
28
+ <a class="source" href="https://github.com/enestaylan/roamwright/blob/main/examples/title-backdrop.js">Source</a>
29
+ <form method="get">
30
+ <label for="seed">Seed</label>
31
+ <input id="seed" name="seed" type="number" step="1" min="-2147483648" max="2147483647" value="42" required />
32
+ <button type="submit" title="Generate another mountain skyline" aria-label="Generate another mountain skyline">→</button>
33
+ </form>
34
+ </div>
35
+ </header>
36
+ <footer>
37
+ <div class="caption">
38
+ <h1>Title backdrop</h1>
39
+ <p>Procedural 2D parallax skyline: multi-octave ridge noise, snow-capped peaks, sunlit cumulus banks and freeze-on-load handoff.</p>
40
+ </div>
41
+ <div class="tools">
42
+ <div class="views" role="group" aria-label="Sky mood">
43
+ <button type="button" data-mood="morning" aria-pressed="true">Alpine morning</button>
44
+ <button type="button" data-mood="dusk" aria-pressed="false">Amber dusk</button>
45
+ <button type="button" data-mood="highland" aria-pressed="false">Misty highlands</button>
46
+ </div>
47
+ <button type="button" id="freeze-btn" aria-pressed="false">Freeze</button>
48
+ </div>
49
+ </footer>
50
+ <script type="module" src="./title-backdrop.js"></script>
51
+ </body>
52
+ </html>
@@ -0,0 +1,160 @@
1
+ import { createTitleBackdrop } from 'roamwright';
2
+ import { readSeed } from './stage.js';
3
+
4
+ const seed = readSeed(42);
5
+ const canvas = document.querySelector('canvas');
6
+ const freezeBtn = document.getElementById('freeze-btn');
7
+ const moodButtons = [...document.querySelectorAll('[data-mood]')];
8
+
9
+ const MOODS = {
10
+ morning: {
11
+ sky: {
12
+ stops: [
13
+ [0, '#6e97be'],
14
+ [0.4, '#9ebbd4'],
15
+ [0.68, '#e3dac8'],
16
+ [0.82, '#f5e1be'],
17
+ [1, '#edd5ad'],
18
+ ],
19
+ sun: {
20
+ x: 0.32,
21
+ y: 0.64,
22
+ radius: 0.52,
23
+ stops: [
24
+ [0, 'rgba(255,247,222,0.95)'],
25
+ [0.1, 'rgba(255,232,190,0.52)'],
26
+ [0.42, 'rgba(255,220,170,0.16)'],
27
+ [1, 'rgba(255,220,170,0)'],
28
+ ],
29
+ },
30
+ },
31
+ ranges: [
32
+ { rock: '#91a5bc', haze: '#dfe4e5', snowLine: 0.34, height: 0.44, top: 0.46 },
33
+ { rock: '#6f849c', haze: '#d7dede', snowLine: 0.16, height: 0.34, top: 0.58 },
34
+ { rock: '#4f6478', haze: '#96a8b4', snowLine: 0, height: 0.28, top: 0.72 },
35
+ ],
36
+ cloudCount: 8,
37
+ shade: '#e2dcd3',
38
+ veil: null,
39
+ },
40
+ dusk: {
41
+ sky: {
42
+ stops: [
43
+ [0, '#384b6e'],
44
+ [0.36, '#6d6988'],
45
+ [0.66, '#c78973'],
46
+ [0.82, '#e8ae7d'],
47
+ [1, '#f2c58f'],
48
+ ],
49
+ sun: {
50
+ x: 0.68,
51
+ y: 0.66,
52
+ radius: 0.5,
53
+ stops: [
54
+ [0, 'rgba(255,238,196,0.95)'],
55
+ [0.12, 'rgba(248,186,120,0.58)'],
56
+ [0.45, 'rgba(220,132,96,0.18)'],
57
+ [1, 'rgba(220,132,96,0)'],
58
+ ],
59
+ },
60
+ },
61
+ ranges: [
62
+ {
63
+ rock: '#6c5d75',
64
+ haze: '#d9a487',
65
+ snowLine: 0.28,
66
+ height: 0.44,
67
+ top: 0.46,
68
+ litStops: [
69
+ [0, 'rgba(255,204,152,0.36)'],
70
+ [1, 'rgba(255,204,152,0)'],
71
+ ],
72
+ shadeStops: [
73
+ [0, 'rgba(38,34,62,0.36)'],
74
+ [1, 'rgba(38,34,62,0)'],
75
+ ],
76
+ },
77
+ {
78
+ rock: '#4b455e',
79
+ haze: '#c48f7b',
80
+ snowLine: 0.1,
81
+ height: 0.34,
82
+ top: 0.58,
83
+ litStops: [
84
+ [0, 'rgba(255,192,138,0.3)'],
85
+ [1, 'rgba(255,192,138,0)'],
86
+ ],
87
+ shadeStops: [
88
+ [0, 'rgba(30,28,50,0.4)'],
89
+ [1, 'rgba(30,28,50,0)'],
90
+ ],
91
+ },
92
+ { rock: '#333447', haze: '#68525b', snowLine: 0, height: 0.28, top: 0.72 },
93
+ ],
94
+ cloudCount: 7,
95
+ shade: null,
96
+ veil: null,
97
+ },
98
+ highland: {
99
+ sky: {
100
+ stops: [
101
+ [0, '#728796'],
102
+ [0.42, '#99adb8'],
103
+ [0.72, '#cfd8da'],
104
+ [1, '#dde3e1'],
105
+ ],
106
+ sun: {
107
+ x: 0.48,
108
+ y: 0.56,
109
+ radius: 0.48,
110
+ stops: [
111
+ [0, 'rgba(246,249,248,0.85)'],
112
+ [0.18, 'rgba(226,235,236,0.4)'],
113
+ [1, 'rgba(226,235,236,0)'],
114
+ ],
115
+ },
116
+ },
117
+ ranges: [
118
+ { rock: '#7d8f98', haze: '#d5dddd', snowLine: 0.22, height: 0.46, top: 0.44 },
119
+ { rock: '#5c7276', haze: '#c6d2d0', snowLine: 0.08, height: 0.36, top: 0.56 },
120
+ { rock: '#3f5756', haze: '#849894', snowLine: 0, height: 0.3, top: 0.7 },
121
+ ],
122
+ cloudCount: 10,
123
+ shade: '#dde2e0',
124
+ veil: null,
125
+ },
126
+ };
127
+
128
+ let active = null;
129
+ let currentMood = 'morning';
130
+ let frozen = false;
131
+
132
+ function startMood(name) {
133
+ currentMood = name;
134
+ active?.stop();
135
+ frozen = false;
136
+ freezeBtn.setAttribute('aria-pressed', 'false');
137
+ freezeBtn.textContent = 'Freeze';
138
+ for (const btn of moodButtons) btn.setAttribute('aria-pressed', String(btn.dataset.mood === name));
139
+ active = createTitleBackdrop(canvas, {
140
+ seed,
141
+ ...MOODS[name],
142
+ });
143
+ }
144
+
145
+ for (const btn of moodButtons) {
146
+ btn.addEventListener('click', () => startMood(btn.dataset.mood));
147
+ }
148
+
149
+ freezeBtn.addEventListener('click', () => {
150
+ if (!frozen) {
151
+ frozen = true;
152
+ freezeBtn.setAttribute('aria-pressed', 'true');
153
+ freezeBtn.textContent = 'Resume';
154
+ active?.freeze();
155
+ } else {
156
+ startMood(currentMood);
157
+ }
158
+ });
159
+
160
+ startMood('morning');
package/index.js CHANGED
@@ -362,6 +362,7 @@ export { DEFAULT_POSE_SHOTS, actorHeadTop, createSceneCoverage } from './renderi
362
362
  export { createSceneShots, gallopTremorLevel, protectMasterHeadroom, trackOrigin } from './rendering/scene-shots.js';
363
363
  export { createPropContact } from './motion/prop-contact.js';
364
364
  export { createSceneProps } from './rendering/scene-props.js';
365
+ export { createSceneFlash } from './rendering/scene-flash.js';
365
366
  export { createSceneMarkers, createShaftLabel, DEFAULT_MARKER_COLORS, projectWaypoint } from './rendering/scene-markers.js';
366
367
 
367
368
  // ── Map kit ──────────────────────────────────────────────────────────────
@@ -412,6 +413,30 @@ export { createWorldControls } from './runtime/world-controls.js';
412
413
  export { COMPASS_POINTS, compassStripHtml, createCompassStrip } from './runtime/compass-strip.js';
413
414
  export { createWayBack } from './runtime/way-back.js';
414
415
  export { createHudFrame, formatDayClock } from './runtime/hud-frame.js';
416
+ export { createHudRoom } from './runtime/hud-room.js';
417
+ export {
418
+ ARTICLE_LINK,
419
+ collectArticleLinks,
420
+ createArticleCatalog,
421
+ formatArticleText,
422
+ parseArticle,
423
+ plainArticleParagraph,
424
+ } from './runtime/articles.js';
425
+ export { createArticlePageRenderer, escapeHtml, renderArticleParagraph } from './runtime/article-page.js';
426
+ export { createJourneyStore } from './runtime/journey.js';
427
+ export { createSitePages, slugify } from './runtime/site-pages.js';
428
+ export {
429
+ DEFAULT_BACKDROP_RANGES,
430
+ DEFAULT_BACKDROP_SKY,
431
+ DEFAULT_BACKDROP_VEIL,
432
+ applyBackdropFinish,
433
+ createCanvasSprite,
434
+ createTitleBackdrop,
435
+ paintCumulusSprite,
436
+ paintMountainRange,
437
+ paintSkyGradient,
438
+ ridgeNoise,
439
+ } from './rendering/title-backdrop.js';
415
440
  export {
416
441
  COMPASS_CARDINALS,
417
442
  DEFAULT_PLACE_KINDS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roamwright",
3
- "version": "0.61.24",
3
+ "version": "0.61.25",
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",
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Scene flash controller: short-lived exposure pulse, glare/bloom boost, and optional world-space
3
+ * point-light spill for scripted impacts, lightning, or sudden shadow dips.
4
+ * @module
5
+ */
6
+
7
+ import { Color } from 'three';
8
+
9
+ /**
10
+ * Creates a scripted exposure, bloom-boost, and light-spill flash controller.
11
+ *
12
+ * Bright tints lift renderer and post-composite exposure, raise the glare/bloom cap, and emit a
13
+ * transient light spill above `subject`. Very dark tints (below `darkThreshold`) briefly pull
14
+ * exposure down as a shadow dip without emitting light or bloom.
15
+ *
16
+ * @param {object} options
17
+ * @param {{ toneMappingExposure: number }} options.renderer Renderer whose `toneMappingExposure` is pulsed.
18
+ * @param {{ value: number } | (() => { value: number } | null | undefined) | null} [options.exposureUniform=null]
19
+ * Final post-processing pass exposure uniform, or a getter returning it when post-processing may toggle at run time.
20
+ * @param {(boost: number) => void} [options.setBloomBoost] Callback receiving the active glare/bloom cap boost.
21
+ * @param {(x: number, y: number, z: number, rgb: [number, number, number], intensity: number, seconds: number) => void} [options.onLightSpill]
22
+ * Optional callback emitting a transient world point light above `subject`.
23
+ * @param {number} [options.subjectOffsetY=1.15] Metres above `subject.y` where the light spill originates.
24
+ * @param {number} [options.spillThreshold=0.01] Minimum linear RGB peak required to emit a point-light spill.
25
+ * @param {number} [options.spillIntensityScale=6] Multiplier applied to `sqrt(peak)` for the light spill intensity.
26
+ * @param {number} [options.darkThreshold=0.02] Peak luminance below which a cue acts as a dark shadow dip.
27
+ * @param {number} [options.darkLift=-0.18] Fractional exposure change at the peak of a dark shadow dip.
28
+ * @param {number} [options.brightLiftScale=0.1] Fractional exposure lift multiplier applied to `sqrt(peak)` for bright flashes.
29
+ * @param {number} [options.bloomBoostScale=28] Bloom-cap boost multiplier applied to `sqrt(peak)` for bright flashes.
30
+ * @param {number} [options.minDuration=0.01] Minimum flash duration in seconds.
31
+ * @returns {{ trigger: (tint: import('three').ColorRepresentation, seconds: number, subject?: { x: number, y: number, z: number }) => void,
32
+ * update: (dt: number) => void, clear: () => void }}
33
+ */
34
+ export function createSceneFlash({
35
+ renderer,
36
+ exposureUniform = null,
37
+ setBloomBoost = () => {},
38
+ onLightSpill = null,
39
+ subjectOffsetY = 1.15,
40
+ spillThreshold = 0.01,
41
+ spillIntensityScale = 6,
42
+ darkThreshold = 0.02,
43
+ darkLift = -0.18,
44
+ brightLiftScale = 0.1,
45
+ bloomBoostScale = 28,
46
+ minDuration = 0.01,
47
+ }) {
48
+ const color = new Color();
49
+ const isUniformGetter = typeof exposureUniform === 'function';
50
+ let remaining = 0;
51
+ let duration = 0;
52
+ let lift = 0;
53
+ let glareBoost = 0;
54
+ let baseExposure = 1;
55
+ let baseComposite = 1;
56
+
57
+ function resolveUniform() {
58
+ return isUniformGetter ? exposureUniform() : exposureUniform;
59
+ }
60
+
61
+ function setPulse(strength) {
62
+ renderer.toneMappingExposure = baseExposure * (1 + lift * strength);
63
+ const uniform = resolveUniform();
64
+ if (uniform) uniform.value = baseComposite * (1 + lift * strength);
65
+ setBloomBoost(glareBoost * strength);
66
+ }
67
+
68
+ function clear() {
69
+ if (remaining > 0) setPulse(0);
70
+ setBloomBoost(0);
71
+ remaining = 0;
72
+ }
73
+
74
+ function trigger(tint, seconds, subject) {
75
+ clear();
76
+ color.set(tint);
77
+ const peak = Math.max(color.r, color.g, color.b);
78
+ if (peak > spillThreshold && onLightSpill && subject) {
79
+ // Allocate a small RGB tuple per cue rather than reusing a scratch array, because light budgets retain it across frames.
80
+ onLightSpill(
81
+ subject.x,
82
+ subject.y + subjectOffsetY,
83
+ subject.z,
84
+ [color.r / peak, color.g / peak, color.b / peak],
85
+ spillIntensityScale * Math.sqrt(peak),
86
+ seconds,
87
+ );
88
+ }
89
+ baseExposure = renderer.toneMappingExposure;
90
+ const uniform = resolveUniform();
91
+ baseComposite = uniform ? uniform.value : 1;
92
+ lift = peak < darkThreshold ? darkLift : brightLiftScale * Math.sqrt(peak);
93
+ glareBoost = peak < darkThreshold ? 0 : bloomBoostScale * Math.sqrt(peak);
94
+ remaining = duration = Math.max(minDuration, seconds);
95
+ setPulse(1);
96
+ }
97
+
98
+ function update(dt) {
99
+ if (remaining <= 0) return;
100
+ remaining = Math.max(0, remaining - dt);
101
+ setPulse((remaining / duration) ** 2);
102
+ }
103
+
104
+ return { trigger, update, clear };
105
+ }