oda-engine 0.0.0-stage → 0.1.1

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.
Files changed (204) hide show
  1. package/README.md +151 -2
  2. package/bin/nowhere.mjs +352 -0
  3. package/lib/account.mjs +57 -0
  4. package/lib/agentModules.mjs +57 -0
  5. package/lib/devServer.mjs +351 -0
  6. package/lib/headless.mjs +231 -0
  7. package/lib/headlessPreview.mjs +212 -0
  8. package/lib/keys.mjs +517 -0
  9. package/lib/make.mjs +855 -0
  10. package/lib/mcp.mjs +537 -0
  11. package/lib/open.mjs +22 -0
  12. package/lib/preview.mjs +87 -0
  13. package/lib/previewRpc.mjs +134 -0
  14. package/lib/project.mjs +359 -0
  15. package/lib/publishFlow.mjs +131 -0
  16. package/lib/resources.mjs +50 -0
  17. package/lib/rules.mjs +60 -0
  18. package/lib/scaffold.mjs +42 -0
  19. package/lib/setup.mjs +59 -0
  20. package/lib/tools.mjs +668 -0
  21. package/package.json +51 -4
  22. package/template/game.config.json +9 -0
  23. package/template/scene.json +4 -0
  24. package/template/src/main.ts +11 -0
  25. package/vendor/DOCS.md +447 -0
  26. package/vendor/agent/appRun.mjs +520 -0
  27. package/vendor/agent/assets/brief.mjs +242 -0
  28. package/vendor/agent/assets/collider.mjs +531 -0
  29. package/vendor/agent/assets/environments/index.mjs +12 -0
  30. package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
  31. package/vendor/agent/assets/fetch.mjs +168 -0
  32. package/vendor/agent/assets/footprint.mjs +13 -0
  33. package/vendor/agent/assets/gltf.mjs +547 -0
  34. package/vendor/agent/assets/hdr.mjs +269 -0
  35. package/vendor/agent/assets/imageOps.mjs +171 -0
  36. package/vendor/agent/assets/images/codex.mjs +307 -0
  37. package/vendor/agent/assets/images/fal.mjs +75 -0
  38. package/vendor/agent/assets/images/gemini.mjs +84 -0
  39. package/vendor/agent/assets/images/index.mjs +25 -0
  40. package/vendor/agent/assets/images/openai.mjs +75 -0
  41. package/vendor/agent/assets/images/stability.mjs +71 -0
  42. package/vendor/agent/assets/images/views.mjs +31 -0
  43. package/vendor/agent/assets/import.mjs +1352 -0
  44. package/vendor/agent/assets/inspect.mjs +465 -0
  45. package/vendor/agent/assets/jobs.mjs +196 -0
  46. package/vendor/agent/assets/ktx2.mjs +290 -0
  47. package/vendor/agent/assets/ledger.mjs +466 -0
  48. package/vendor/agent/assets/net.mjs +254 -0
  49. package/vendor/agent/assets/prices.json +39 -0
  50. package/vendor/agent/assets/providers/fal.mjs +115 -0
  51. package/vendor/agent/assets/providers/index.mjs +22 -0
  52. package/vendor/agent/assets/providers/meshy.mjs +119 -0
  53. package/vendor/agent/assets/providers/tripo.mjs +188 -0
  54. package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
  55. package/vendor/agent/assets/sources/index.mjs +23 -0
  56. package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
  57. package/vendor/agent/assets/sources/polypizza.mjs +121 -0
  58. package/vendor/agent/assets/splat.mjs +631 -0
  59. package/vendor/agent/assets/targets.mjs +122 -0
  60. package/vendor/agent/assets/tile.mjs +261 -0
  61. package/vendor/agent/assets/unzip.mjs +180 -0
  62. package/vendor/agent/blender/cleanup.py +360 -0
  63. package/vendor/agent/blender/convert.py +167 -0
  64. package/vendor/agent/blender/find.mjs +192 -0
  65. package/vendor/agent/blender/nw_export.py +104 -0
  66. package/vendor/agent/blender/nw_rubric.py +426 -0
  67. package/vendor/agent/blender/run.mjs +193 -0
  68. package/vendor/agent/blender/runner.py +252 -0
  69. package/vendor/agent/blender/sheet.py +743 -0
  70. package/vendor/agent/depth.mjs +134 -0
  71. package/vendor/agent/director/board.mjs +451 -0
  72. package/vendor/agent/director/contracts.mjs +663 -0
  73. package/vendor/agent/director/director.mjs +2365 -0
  74. package/vendor/agent/director/estimate.mjs +200 -0
  75. package/vendor/agent/director/gate.mjs +802 -0
  76. package/vendor/agent/director/limits.json +16 -0
  77. package/vendor/agent/director/methods.mjs +457 -0
  78. package/vendor/agent/director/policy.json +33 -0
  79. package/vendor/agent/director/prompts.mjs +244 -0
  80. package/vendor/agent/director/reading.mjs +341 -0
  81. package/vendor/agent/director/router.mjs +184 -0
  82. package/vendor/agent/director/seams.mjs +243 -0
  83. package/vendor/agent/director/session.mjs +643 -0
  84. package/vendor/agent/director/store.mjs +119 -0
  85. package/vendor/agent/director/taskGate.mjs +110 -0
  86. package/vendor/agent/director/teamLedger.mjs +118 -0
  87. package/vendor/agent/director/triage.mjs +63 -0
  88. package/vendor/agent/downloads.cjs +363 -0
  89. package/vendor/agent/flow.mjs +78 -0
  90. package/vendor/agent/guard.mjs +613 -0
  91. package/vendor/agent/host.mjs +1736 -0
  92. package/vendor/agent/language.mjs +58 -0
  93. package/vendor/agent/ledger.mjs +360 -0
  94. package/vendor/agent/locale.cjs +186 -0
  95. package/vendor/agent/loop/capacity.mjs +74 -0
  96. package/vendor/agent/loop/compose.mjs +127 -0
  97. package/vendor/agent/loop/gate.mjs +205 -0
  98. package/vendor/agent/loop/judge.mjs +189 -0
  99. package/vendor/agent/loop/levels.mjs +273 -0
  100. package/vendor/agent/loop/state.mjs +358 -0
  101. package/vendor/agent/notes.cjs +278 -0
  102. package/vendor/agent/pace.mjs +258 -0
  103. package/vendor/agent/panels.mjs +431 -0
  104. package/vendor/agent/prompt.mjs +342 -0
  105. package/vendor/agent/reference/board.mjs +410 -0
  106. package/vendor/agent/reference/compose.mjs +364 -0
  107. package/vendor/agent/reference/decode.mjs +56 -0
  108. package/vendor/agent/reference/facts.mjs +1874 -0
  109. package/vendor/agent/reference/png.mjs +107 -0
  110. package/vendor/agent/reference/records.mjs +63 -0
  111. package/vendor/agent/reference/web.mjs +252 -0
  112. package/vendor/agent/roles/artist.mjs +69 -0
  113. package/vendor/agent/roles/builder.mjs +79 -0
  114. package/vendor/agent/roles/checks.mjs +223 -0
  115. package/vendor/agent/roles/common.mjs +188 -0
  116. package/vendor/agent/roles/critic.mjs +171 -0
  117. package/vendor/agent/roles/index.mjs +39 -0
  118. package/vendor/agent/roles/modeller.mjs +142 -0
  119. package/vendor/agent/roles/qa.mjs +58 -0
  120. package/vendor/agent/roles/rubrics.mjs +79 -0
  121. package/vendor/agent/roles/sound.mjs +69 -0
  122. package/vendor/agent/rounds.cjs +333 -0
  123. package/vendor/agent/shared.mjs +284 -0
  124. package/vendor/agent/stopGate.mjs +574 -0
  125. package/vendor/agent/subagents.mjs +129 -0
  126. package/vendor/agent/tools/assets.mjs +499 -0
  127. package/vendor/agent/tools/blender.mjs +754 -0
  128. package/vendor/agent/tools/cards.mjs +479 -0
  129. package/vendor/agent/tools/choices.mjs +479 -0
  130. package/vendor/agent/tools/compose.mjs +74 -0
  131. package/vendor/agent/tools/environment.mjs +488 -0
  132. package/vendor/agent/tools/eyes.mjs +733 -0
  133. package/vendor/agent/tools/generate.mjs +338 -0
  134. package/vendor/agent/tools/guide.mjs +46 -0
  135. package/vendor/agent/tools/harness.mjs +193 -0
  136. package/vendor/agent/tools/image.mjs +643 -0
  137. package/vendor/agent/tools/index.mjs +162 -0
  138. package/vendor/agent/tools/look.mjs +578 -0
  139. package/vendor/agent/tools/loop.mjs +858 -0
  140. package/vendor/agent/tools/others.mjs +123 -0
  141. package/vendor/agent/tools/pictures.mjs +535 -0
  142. package/vendor/agent/tools/reference.mjs +366 -0
  143. package/vendor/agent/transcripts.mjs +118 -0
  144. package/vendor/agent-loop.mjs +602 -0
  145. package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
  146. package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
  147. package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
  148. package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
  149. package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
  150. package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
  151. package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
  152. package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
  153. package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
  154. package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
  155. package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
  156. package/vendor/auth.cjs +570 -0
  157. package/vendor/build.cjs +953 -0
  158. package/vendor/catalog.json +455 -0
  159. package/vendor/connectors.cjs +688 -0
  160. package/vendor/eyes.mjs +733 -0
  161. package/vendor/gameExports.json +1390 -0
  162. package/vendor/git.cjs +222 -0
  163. package/vendor/models.json +57 -0
  164. package/vendor/publish.cjs +1018 -0
  165. package/vendor/refBoard.cjs +301 -0
  166. package/vendor/schema/dist/assets.d.ts +335 -0
  167. package/vendor/schema/dist/assets.js +439 -0
  168. package/vendor/schema/dist/brief.d.ts +357 -0
  169. package/vendor/schema/dist/brief.js +302 -0
  170. package/vendor/schema/dist/common.d.ts +9 -0
  171. package/vendor/schema/dist/common.js +13 -0
  172. package/vendor/schema/dist/config.d.ts +406 -0
  173. package/vendor/schema/dist/config.js +355 -0
  174. package/vendor/schema/dist/contract.d.ts +599 -0
  175. package/vendor/schema/dist/contract.js +1146 -0
  176. package/vendor/schema/dist/index.d.ts +14 -0
  177. package/vendor/schema/dist/index.js +21 -0
  178. package/vendor/schema/dist/look.d.ts +463 -0
  179. package/vendor/schema/dist/look.js +681 -0
  180. package/vendor/schema/dist/lookStats.d.ts +230 -0
  181. package/vendor/schema/dist/lookStats.js +768 -0
  182. package/vendor/schema/dist/pilot.d.ts +32 -0
  183. package/vendor/schema/dist/pilot.js +44 -0
  184. package/vendor/schema/dist/publish.d.ts +214 -0
  185. package/vendor/schema/dist/publish.js +291 -0
  186. package/vendor/schema/dist/scene.d.ts +75 -0
  187. package/vendor/schema/dist/scene.js +120 -0
  188. package/vendor/schema/dist/skyLight.d.ts +141 -0
  189. package/vendor/schema/dist/skyLight.js +436 -0
  190. package/vendor/schema/dist/style.d.ts +131 -0
  191. package/vendor/schema/dist/style.js +155 -0
  192. package/vendor/schema/package.json +1 -0
  193. package/vendor/selectionPrompt.mjs +51 -0
  194. package/vendor/useTools.mjs +195 -0
  195. package/vendor/userMessage.mjs +26 -0
  196. package/web-dist/assets/GaussianSplatUtils-CptQkDVX.js +1 -0
  197. package/web-dist/assets/KTX2Loader-C53LJqss.js +2 -0
  198. package/web-dist/assets/SPZLoader-BQ3tjaTv.js +1 -0
  199. package/web-dist/assets/gaussianSplat-_9tcWegB.js +1 -0
  200. package/web-dist/assets/index-Baka-ZO7.js +693 -0
  201. package/web-dist/assets/index-CcjyyQco.css +1 -0
  202. package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
  203. package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
  204. package/web-dist/index.html +34 -0
@@ -0,0 +1,436 @@
1
+ // The light in a sky picture: where its sun is, how strong and what colour,
2
+ // read from the picture's own pixels. An HDRI is measured light, so the
3
+ // config's sun (which casts the shadow) can be the picture's sun rather than
4
+ // a guess: nw_check reads the file and says how far the two are apart, and
5
+ // the SDK takes the sun out of the light the picture gives when the config's
6
+ // sun stands in for it, so the sun is not counted twice.
7
+ //
8
+ // Pure arithmetic on the picture's floats, with no three and no DOM, so the
9
+ // studio's renderer, the CLI and the checks measure the same sun. The frame
10
+ // is three's equirectangular one: u = atan2(z, x) / 2pi + 0.5 across,
11
+ // v = asin(y) / pi + 0.5 up, and sky.rotation turns it about +Y.
12
+ /** A picture whose brightest pixel is not this many times its sky's median
13
+ * has no sun of its own (an overcast sky, an interior). */
14
+ const SUN_OVER_SKY = 24;
15
+ /** Above this many times the sky's median a pixel near the peak is sun: no
16
+ * lit cloud or bright patch of a clear sky comes near it, and the halo
17
+ * just round the disc, which lights as the sun does, goes with it. */
18
+ const SUN_THRESHOLD = 16;
19
+ /** How far from the peak, in degrees, the sun's pixels are looked for. */
20
+ const SUN_RADIUS = 12;
21
+ const HALF_EXP = new Float64Array(32);
22
+ for (let e = 0; e < 32; e++)
23
+ HALF_EXP[e] = Math.pow(2, e - 15);
24
+ /** An IEEE half float (as its 16 bits) as a number. */
25
+ export function halfToFloat(bits) {
26
+ const sign = bits & 0x8000 ? -1 : 1;
27
+ const e = (bits >> 10) & 0x1f;
28
+ const m = bits & 0x3ff;
29
+ if (e === 0)
30
+ return sign * m * Math.pow(2, -24);
31
+ if (e === 31)
32
+ return m ? NaN : sign * Infinity;
33
+ return sign * HALF_EXP[e] * (1 + m / 1024);
34
+ }
35
+ const luminanceOf = (r, g, b) => 0.2126 * r + 0.7152 * g + 0.0722 * b;
36
+ /** The unit direction of a pixel's centre, in the picture's frame. */
37
+ export function skyPixelDirection(px, i, j) {
38
+ const u = (i + 0.5) / px.width;
39
+ const v = px.topRowFirst ? 1 - (j + 0.5) / px.height : (j + 0.5) / px.height;
40
+ const a = (u - 0.5) * Math.PI * 2;
41
+ const e = (v - 0.5) * Math.PI;
42
+ return [Math.cos(e) * Math.cos(a), Math.sin(e), Math.cos(e) * Math.sin(a)];
43
+ }
44
+ /** A direction in the picture's frame as the world sees it under sky.rotation
45
+ * (radians about +Y, as three's scene.environmentRotation turns it). */
46
+ export function skyToWorld(d, rotation = 0) {
47
+ const c = Math.cos(rotation);
48
+ const s = Math.sin(rotation);
49
+ return [c * d[0] + s * d[2], d[1], -s * d[0] + c * d[2]];
50
+ }
51
+ const toSrgbByte = (linear) => {
52
+ const c = Math.max(0, Math.min(1, linear));
53
+ const s = c <= 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
54
+ return Math.round(s * 255);
55
+ };
56
+ /**
57
+ * The sun in a sky picture, or null when it has none: the pixels within
58
+ * SUN_RADIUS degrees of the brightest one that stand SUN_THRESHOLD times
59
+ * over the sky's median, their light above that line summed by the solid
60
+ * angle each pixel covers. That excess is what `clampSkySun` takes out of
61
+ * the picture, so the two agree to the pixel.
62
+ */
63
+ export function measureSkySun(px) {
64
+ const { width: w, height: h, data, channels } = px;
65
+ if (!(w > 0 && h > 0) || data.length < w * h * channels)
66
+ return null;
67
+ const read = px.half ? (k) => halfToFloat(data[k]) : (k) => data[k];
68
+ const lum = new Float32Array(w * h);
69
+ const upper = [];
70
+ let peak = -1;
71
+ let peakAt = -1;
72
+ for (let j = 0; j < h; j++) {
73
+ const up = skyPixelDirection(px, 0, j)[1] > -0.035;
74
+ for (let i = 0; i < w; i++) {
75
+ const k = (j * w + i) * channels;
76
+ const r = read(k);
77
+ const g = read(k + 1);
78
+ const b = read(k + 2);
79
+ const l = Number.isFinite(r + g + b) ? Math.max(0, luminanceOf(r, g, b)) : 0;
80
+ lum[j * w + i] = l;
81
+ if (!up)
82
+ continue;
83
+ if ((i + j) % 4 === 0)
84
+ upper.push(l);
85
+ if (l > peak) {
86
+ peak = l;
87
+ peakAt = j * w + i;
88
+ }
89
+ }
90
+ }
91
+ if (peakAt < 0 || upper.length === 0)
92
+ return null;
93
+ upper.sort((a, b) => a - b);
94
+ const median = upper[upper.length >> 1];
95
+ if (!(peak > 0) || peak < SUN_OVER_SKY * Math.max(median, 1e-6))
96
+ return null;
97
+ const threshold = SUN_THRESHOLD * Math.max(median, 1e-6);
98
+ const peakDir = skyPixelDirection(px, peakAt % w, Math.floor(peakAt / w));
99
+ const near = Math.cos((SUN_RADIUS * Math.PI) / 180);
100
+ const cell = ((Math.PI * 2) / w) * (Math.PI / h);
101
+ let e = 0;
102
+ const sum = [0, 0, 0];
103
+ const rgb = [0, 0, 0];
104
+ let groundSun = 0;
105
+ let groundAll = 0;
106
+ for (let j = 0; j < h; j++) {
107
+ const up = skyPixelDirection(px, 0, j)[1];
108
+ const omega = cell * Math.sqrt(Math.max(0, 1 - up * up));
109
+ for (let i = 0; i < w; i++) {
110
+ const l = lum[j * w + i];
111
+ if (up > 0)
112
+ groundAll += l * omega * up;
113
+ if (l <= threshold)
114
+ continue;
115
+ const d = skyPixelDirection(px, i, j);
116
+ if (d[0] * peakDir[0] + d[1] * peakDir[1] + d[2] * peakDir[2] < near)
117
+ continue;
118
+ const excess = (l - threshold) * omega;
119
+ e += excess;
120
+ sum[0] += d[0] * excess;
121
+ sum[1] += d[1] * excess;
122
+ sum[2] += d[2] * excess;
123
+ const k = (j * w + i) * channels;
124
+ const keep = 1 - threshold / l;
125
+ rgb[0] += read(k) * keep * omega;
126
+ rgb[1] += read(k + 1) * keep * omega;
127
+ rgb[2] += read(k + 2) * keep * omega;
128
+ if (d[1] > 0)
129
+ groundSun += excess * d[1];
130
+ }
131
+ }
132
+ const len = Math.hypot(sum[0], sum[1], sum[2]);
133
+ if (!(e > 0) || !(len > 0))
134
+ return null;
135
+ const toSun = [sum[0] / len, sum[1] / len, sum[2] / len];
136
+ const top = Math.max(rgb[0], rgb[1], rgb[2], 1e-12);
137
+ const hex = '#' + rgb.map((c) => toSrgbByte(c / top).toString(16).padStart(2, '0')).join('');
138
+ return {
139
+ direction: [-toSun[0], -toSun[1], -toSun[2]],
140
+ elevation: (Math.asin(Math.max(-1, Math.min(1, toSun[1]))) * 180) / Math.PI,
141
+ intensity: e,
142
+ color: hex,
143
+ threshold,
144
+ share: groundAll > 0 ? Math.min(1, groundSun / groundAll) : 0,
145
+ };
146
+ }
147
+ /**
148
+ * Takes the sun out of a sky picture's light, in place: every pixel within
149
+ * SUN_RADIUS degrees of it that stands over its threshold is brought down to
150
+ * it, keeping its hue. What is left is the sky's own light; the config's sun
151
+ * gives the rest, with its shadow. Returns how many pixels it changed.
152
+ */
153
+ export function clampSkySun(px, sun, write) {
154
+ const { width: w, height: h, data, channels } = px;
155
+ const read = px.half ? (k) => halfToFloat(data[k]) : (k) => data[k];
156
+ const toSun = [-sun.direction[0], -sun.direction[1], -sun.direction[2]];
157
+ const reach = ((SUN_RADIUS + 2) * Math.PI) / 180;
158
+ const near = Math.cos(reach);
159
+ const sunUp = Math.asin(Math.max(-1, Math.min(1, toSun[1])));
160
+ let changed = 0;
161
+ for (let j = 0; j < h; j++) {
162
+ // Only the rows within reach of the sun's height can hold it.
163
+ const up = Math.asin(Math.max(-1, Math.min(1, skyPixelDirection(px, 0, j)[1])));
164
+ if (Math.abs(up - sunUp) > reach)
165
+ continue;
166
+ for (let i = 0; i < w; i++) {
167
+ const d = skyPixelDirection(px, i, j);
168
+ if (d[0] * toSun[0] + d[1] * toSun[1] + d[2] * toSun[2] < near)
169
+ continue;
170
+ const k = (j * w + i) * channels;
171
+ const r = read(k);
172
+ const g = read(k + 1);
173
+ const b = read(k + 2);
174
+ const l = luminanceOf(r, g, b);
175
+ if (!(l > sun.threshold) || !Number.isFinite(l))
176
+ continue;
177
+ const s = sun.threshold / l;
178
+ write(k, r * s);
179
+ write(k + 1, g * s);
180
+ write(k + 2, b * s);
181
+ changed++;
182
+ }
183
+ }
184
+ return changed;
185
+ }
186
+ /**
187
+ * A Radiance .hdr file's pixels as linear RGB floats, top row first, or null
188
+ * when the bytes are not one: the header, then flat or run-length scanlines
189
+ * (the "new" encoding every current writer uses).
190
+ */
191
+ export function decodeRadiance(bytes) {
192
+ let at = 0;
193
+ const line = () => {
194
+ let s = '';
195
+ while (at < bytes.length && bytes[at] !== 0x0a)
196
+ s += String.fromCharCode(bytes[at++]);
197
+ at++;
198
+ return s;
199
+ };
200
+ const first = line();
201
+ if (!/^#\?(RADIANCE|RGBE)/.test(first))
202
+ return null;
203
+ for (;;) {
204
+ if (at >= bytes.length)
205
+ return null;
206
+ const l = line();
207
+ if (l === '')
208
+ break;
209
+ if (/^FORMAT=/.test(l) && !/32-bit_rle_rgbe/.test(l))
210
+ return null;
211
+ }
212
+ const size = /^-Y (\d+) \+X (\d+)$/.exec(line().trim());
213
+ if (!size)
214
+ return null;
215
+ const height = Number(size[1]);
216
+ const width = Number(size[2]);
217
+ if (!(width > 0 && height > 0) || width * height > 64 * 1024 * 1024)
218
+ return null;
219
+ const rgbe = new Uint8Array(width * height * 4);
220
+ const scan = new Uint8Array(width * 4);
221
+ for (let y = 0; y < height; y++) {
222
+ if (at + 4 > bytes.length)
223
+ return null;
224
+ const rle = width >= 8 && width < 32768 && bytes[at] === 2 && bytes[at + 1] === 2 && ((bytes[at + 2] << 8) | bytes[at + 3]) === width && !(bytes[at + 2] & 0x80);
225
+ if (!rle) {
226
+ // Flat: four bytes a pixel.
227
+ if (at + width * 4 > bytes.length)
228
+ return null;
229
+ rgbe.set(bytes.subarray(at, at + width * 4), y * width * 4);
230
+ at += width * 4;
231
+ continue;
232
+ }
233
+ at += 4;
234
+ for (let c = 0; c < 4; c++) {
235
+ let x = 0;
236
+ while (x < width) {
237
+ if (at >= bytes.length)
238
+ return null;
239
+ let n = bytes[at++];
240
+ if (n > 128) {
241
+ n -= 128;
242
+ const v = bytes[at++];
243
+ if (x + n > width)
244
+ return null;
245
+ for (let k = 0; k < n; k++)
246
+ scan[(x++) * 4 + c] = v;
247
+ }
248
+ else {
249
+ if (n === 0 || x + n > width || at + n > bytes.length)
250
+ return null;
251
+ for (let k = 0; k < n; k++)
252
+ scan[(x++) * 4 + c] = bytes[at++];
253
+ }
254
+ }
255
+ }
256
+ rgbe.set(scan, y * width * 4);
257
+ }
258
+ const data = new Float32Array(width * height * 3);
259
+ for (let p = 0; p < width * height; p++) {
260
+ const e = rgbe[p * 4 + 3];
261
+ if (e === 0)
262
+ continue;
263
+ const f = Math.pow(2, e - 136);
264
+ data[p * 3] = rgbe[p * 4] * f;
265
+ data[p * 3 + 1] = rgbe[p * 4 + 1] * f;
266
+ data[p * 3 + 2] = rgbe[p * 4 + 2] * f;
267
+ }
268
+ return { width, height, data };
269
+ }
270
+ const angleBetween = (a, b) => {
271
+ const la = Math.hypot(a[0], a[1], a[2]);
272
+ const lb = Math.hypot(b[0], b[1], b[2]);
273
+ if (!(la > 0 && lb > 0))
274
+ return 180;
275
+ const c = (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]) / (la * lb);
276
+ return (Math.acos(Math.max(-1, Math.min(1, c))) * 180) / Math.PI;
277
+ };
278
+ const round = (n, places = 2) => Math.round(n * 10 ** places) / 10 ** places;
279
+ /**
280
+ * How the config's sun stands against the sun measured in its HDRI, as
281
+ * sentences for nw_check: the direction (and the sky.rotation that would
282
+ * bring the picture's sun over the config's), the strength at the sky's
283
+ * light, and a sky with no sun under a config that has one. Empty when they
284
+ * agree.
285
+ */
286
+ export function skySunAdvice(config, sun, environmentIntensity) {
287
+ const out = [];
288
+ const cfgSun = config.lighting?.sun;
289
+ const rotation = typeof config.sky?.rotation === 'number' ? config.sky.rotation : 0;
290
+ if (!sun) {
291
+ if (cfgSun)
292
+ out.push("The sky's picture has no sun of its own (its light comes from all round), yet lighting.sun casts a hard shadow from one. If the reference is overcast, set lighting.sun to null or keep it dim; if it has a sun, choose a picture that has one.");
293
+ return out;
294
+ }
295
+ const seen = skyToWorld(sun.direction, rotation);
296
+ const at = `pointing ${JSON.stringify(seen.map((v) => round(v, 3)))}, ${round(sun.elevation, 1)} degrees up, colour ${sun.color}, giving ${round(sun.intensity * environmentIntensity, 2)} at this sky light`;
297
+ if (!cfgSun) {
298
+ out.push(`The sky's picture has a sun (${at}) and lighting.sun is null, so it lights the world from the picture with no shadow. Give lighting.sun that direction, colour and intensity to have its shadow.`);
299
+ return out;
300
+ }
301
+ const off = angleBetween(cfgSun.direction ?? [0.85, -1, -0.35], seen);
302
+ if (off > 5) {
303
+ // The rotation that turns the picture's sun to the config's azimuth.
304
+ const d = cfgSun.direction ?? [0.85, -1, -0.35];
305
+ const want = Math.atan2(-d[2], -d[0]);
306
+ const have = Math.atan2(-sun.direction[2], -sun.direction[0]);
307
+ let turn = have - want;
308
+ while (turn > Math.PI)
309
+ turn -= Math.PI * 2;
310
+ while (turn < -Math.PI)
311
+ turn += Math.PI * 2;
312
+ out.push(`lighting.sun points ${round(off, 0)} degrees away from the sun in the sky's picture (${at}): its shadow falls where the picture's light says it cannot. Set lighting.sun.direction to ${JSON.stringify(seen.map((v) => round(v, 3)))}, or turn the picture with sky.rotation ${round(turn, 3)} to bring its sun over the config's.`);
313
+ }
314
+ const want = sun.intensity * environmentIntensity;
315
+ const have = typeof cfgSun.intensity === 'number' ? cfgSun.intensity : 3.4;
316
+ if (want > 0 && (have / want > 1.33 || have / want < 0.75)) {
317
+ out.push(`lighting.sun.intensity is ${round(have)}; the sun in the sky's picture gives ${round(want)} at this sky light (look.environment.intensity ${round(environmentIntensity)}). The picture's own sun is taken out of its light while lighting.sun stands in for it, so ${round(want)} keeps the sun as strong as the picture has it.`);
318
+ }
319
+ return out;
320
+ }
321
+ /** mieCoefficient and mieDirectionalG when a sky leaves them out: the
322
+ * model's own (SkyMesh's), a clear day's aerosol. */
323
+ export const PHYSICAL_SKY_MIE = { coefficient: 0.005, directionalG: 0.8 };
324
+ const TOTAL_RAYLEIGH = [5.804542996261093e-6, 1.3562911419845635e-5, 3.0265902468824876e-5];
325
+ const MIE_CONST = [1.8399918514433978e14, 2.7798023919660528e14, 4.0790479543861094e14];
326
+ const CUTOFF = 1.6110731556870734;
327
+ const STEEPNESS = 1.5;
328
+ const EE = 1000;
329
+ /** The model's radiance for a view direction under a sun (both unit vectors,
330
+ * `toSun` pointing at it), without the sun's disc and without clouds, in the
331
+ * model's own units (SkyMesh's colour before any scale). Line for line the
332
+ * colour SkyMesh computes, so the light and the picture are one sky. */
333
+ export function physicalSkyRadiance(p, toSun, dir) {
334
+ const up = toSun[1];
335
+ const sunE = EE * Math.max(0, 1 - Math.exp(-(CUTOFF - Math.acos(Math.max(-1, Math.min(1, up)))) / STEEPNESS));
336
+ const sunfade = 1 - Math.max(0, Math.min(1, 1 - Math.exp(toSun[1] / 450000)));
337
+ const rayleighCoefficient = p.rayleigh - (1 - sunfade);
338
+ const betaR = TOTAL_RAYLEIGH.map((v) => v * rayleighCoefficient);
339
+ const c = 0.2 * p.turbidity * 10e-18;
340
+ const betaM = MIE_CONST.map((v) => 0.434 * c * v * p.mieCoefficient);
341
+ const zenith = Math.acos(Math.max(0, dir[1]));
342
+ const inverse = 1 / (Math.cos(zenith) + 0.15 * Math.pow(93.885 - (zenith * 180) / Math.PI, -1.253));
343
+ const sR = 8.4e3 * inverse;
344
+ const sM = 1.25e3 * inverse;
345
+ const cosTheta = dir[0] * toSun[0] + dir[1] * toSun[1] + dir[2] * toSun[2];
346
+ const half = cosTheta * 0.5 + 0.5;
347
+ const rPhase = (3 / (16 * Math.PI)) * (1 + half * half);
348
+ const g = p.mieDirectionalG;
349
+ const g2 = g * g;
350
+ const mPhase = (1 / (4 * Math.PI)) * (1 - g2) * (1 / Math.pow(1 - 2 * g * cosTheta + g2, 1.5));
351
+ const lowSun = Math.max(0, Math.min(1, Math.pow(1 - up, 5)));
352
+ const out = [0, 0, 0];
353
+ for (let k = 0; k < 3; k++) {
354
+ const fex = Math.exp(-(betaR[k] * sR + betaM[k] * sM));
355
+ const scatter = (betaR[k] * rPhase + betaM[k] * mPhase) / (betaR[k] + betaM[k]);
356
+ let lin = Math.pow(Math.max(0, sunE * scatter * (1 - fex)), 1.5);
357
+ lin *= 1 + (Math.pow(Math.max(0, sunE * scatter * fex), 0.5) - 1) * lowSun;
358
+ const night = 0.1 * fex;
359
+ out[k] = (lin + night) * 0.04 + [0, 0.0003, 0.00075][k];
360
+ }
361
+ return out;
362
+ }
363
+ /** The model's sun as it arrives, on a surface facing it, in its own units:
364
+ * the light the model's sky stands beside. Not its drawn disc, whose
365
+ * brightness is chosen only to read as white: CALIBRATION ties the two so
366
+ * a clear day's sky gives level ground about 0.16 of what the sun gives it
367
+ * there (turbidity 3, the sun 45 degrees up), as clear-sky models of the
368
+ * real atmosphere have it (diffuse about 100 W/m2 under a direct 620). */
369
+ export function physicalSkySun(p, toSun) {
370
+ const up = toSun[1];
371
+ const sunE = EE * Math.max(0, 1 - Math.exp(-(CUTOFF - Math.acos(Math.max(-1, Math.min(1, up)))) / STEEPNESS));
372
+ const zenith = Math.acos(Math.max(0, up));
373
+ const inverse = 1 / (Math.cos(zenith) + 0.15 * Math.pow(93.885 - (zenith * 180) / Math.PI, -1.253));
374
+ const c = 0.2 * p.turbidity * 10e-18;
375
+ const sunfade = 1 - Math.max(0, Math.min(1, 1 - Math.exp(up / 450000)));
376
+ const fex = [0, 1, 2].map((k) => Math.exp(-(TOTAL_RAYLEIGH[k] * (p.rayleigh - (1 - sunfade)) * 8.4e3 * inverse + 0.434 * c * MIE_CONST[k] * p.mieCoefficient * 1.25e3 * inverse)));
377
+ return sunE * PHYSICAL_SKY_CALIBRATION * luminanceOf(fex[0], fex[1], fex[2]);
378
+ }
379
+ /** See physicalSkySun: measured once with skyIrradianceOf below, at
380
+ * turbidity 3, rayleigh 1, the model's Mie, and the sun 45 degrees up. */
381
+ export const PHYSICAL_SKY_CALIBRATION = 0.0924;
382
+ /** Light the model's sky (no sun) puts on level ground, in its units. */
383
+ export function skyIrradianceOf(p, toSun, steps = 96) {
384
+ let e = 0;
385
+ const dTheta = Math.PI / 2 / steps;
386
+ const dPhi = (Math.PI * 2) / (steps * 4);
387
+ for (let a = 0; a < steps; a++) {
388
+ const el = (a + 0.5) * dTheta;
389
+ const sinEl = Math.sin(el);
390
+ const cosEl = Math.cos(el);
391
+ for (let b = 0; b < steps * 4; b++) {
392
+ const az = (b + 0.5) * dPhi;
393
+ const d = [cosEl * Math.cos(az), sinEl, cosEl * Math.sin(az)];
394
+ const r = physicalSkyRadiance(p, toSun, d);
395
+ e += luminanceOf(r[0], r[1], r[2]) * sinEl * cosEl * dTheta * dPhi;
396
+ }
397
+ }
398
+ return e;
399
+ }
400
+ /** The factor that scales the model's sky to the config's sun: its sun as it
401
+ * arrives (physicalSkySun) becomes lighting.sun.intensity. 1 for a sky with
402
+ * no sun (night: the model's own faint glow). */
403
+ export function physicalSkyScale(p, toSun, sunIntensity) {
404
+ if (!toSun)
405
+ return 1;
406
+ const overhead = physicalSkySun(p, [0, 1, 0]);
407
+ const arriving = Math.max(physicalSkySun(p, toSun), overhead * 1e-3);
408
+ return sunIntensity / arriving;
409
+ }
410
+ /** A sky's model numbers, its own or the model's for what it leaves out. */
411
+ export function physicalSkyParams(sky) {
412
+ const n = (v, fallback) => (typeof v === 'number' && Number.isFinite(v) ? v : fallback);
413
+ return {
414
+ turbidity: n(sky.turbidity, 2),
415
+ rayleigh: n(sky.rayleigh, 1),
416
+ mieCoefficient: n(sky.mieCoefficient, PHYSICAL_SKY_MIE.coefficient),
417
+ mieDirectionalG: n(sky.mieDirectionalG, PHYSICAL_SKY_MIE.directionalG),
418
+ };
419
+ }
420
+ const toHex = (rgb) => '#' + rgb.map((c) => toSrgbByte(c).toString(16).padStart(2, '0')).join('');
421
+ /** A physical sky's two colours for what reads a sky by them (the figure's
422
+ * glow, the universe's globe, the splat): straight up and at the horizon
423
+ * opposite the sun, scaled to the config's sun and clipped to display. */
424
+ export function physicalSkyColors(sky, sun) {
425
+ const p = physicalSkyParams(sky);
426
+ const d = sun?.direction ?? [0.85, -1, -0.35];
427
+ const len = Math.hypot(d[0], d[1], d[2]) || 1;
428
+ const toSun = sun ? [-d[0] / len, -d[1] / len, -d[2] / len] : null;
429
+ const scale = physicalSkyScale(p, toSun, typeof sun?.intensity === 'number' ? sun.intensity : 3.4);
430
+ const at = toSun ?? [0, -1, 0];
431
+ const flat = Math.hypot(at[0], at[2]) || 1;
432
+ const away = [-at[0] / flat, 0.02, -at[2] / flat];
433
+ const top = physicalSkyRadiance(p, at, [0, 1, 0]).map((v) => v * scale);
434
+ const bottom = physicalSkyRadiance(p, at, away).map((v) => v * scale);
435
+ return { top: toHex(top), bottom: toHex(bottom) };
436
+ }
@@ -0,0 +1,131 @@
1
+ import { z } from 'zod';
2
+ import type { Finding } from './config.js';
3
+ export declare const STYLE_FILE = "style.json";
4
+ export declare const STYLE_SCHEMA = "nowhere/style@1";
5
+ /** One work the style is read from: a picture the creator attached, an
6
+ * artist, a game, a film, a print, a movement. */
7
+ export declare const StyleSource: z.ZodObject<{
8
+ what: z.ZodString;
9
+ url: z.ZodOptional<z.ZodString>;
10
+ path: z.ZodOptional<z.ZodString>;
11
+ takes: z.ZodString;
12
+ }, z.core.$strict>;
13
+ /** A direction that was proposed, kept so the choice can be read back. */
14
+ export declare const StyleDirection: z.ZodObject<{
15
+ name: z.ZodString;
16
+ medium: z.ZodString;
17
+ why: z.ZodString;
18
+ picture: z.ZodOptional<z.ZodString>;
19
+ }, z.core.$strict>;
20
+ export declare const SpaceStyle: z.ZodObject<{
21
+ schema: z.ZodLiteral<"nowhere/style@1">;
22
+ medium: z.ZodString;
23
+ from: z.ZodEnum<{
24
+ attached: "attached";
25
+ named: "named";
26
+ chosen: "chosen";
27
+ researched: "researched";
28
+ }>;
29
+ sources: z.ZodArray<z.ZodObject<{
30
+ what: z.ZodString;
31
+ url: z.ZodOptional<z.ZodString>;
32
+ path: z.ZodOptional<z.ZodString>;
33
+ takes: z.ZodString;
34
+ }, z.core.$strict>>;
35
+ shape: z.ZodObject<{
36
+ language: z.ZodString;
37
+ proportions: z.ZodString;
38
+ detail: z.ZodEnum<{
39
+ sparse: "sparse";
40
+ moderate: "moderate";
41
+ dense: "dense";
42
+ }>;
43
+ }, z.core.$strict>;
44
+ line: z.ZodObject<{
45
+ kind: z.ZodEnum<{
46
+ none: "none";
47
+ outline: "outline";
48
+ ink: "ink";
49
+ sketch: "sketch";
50
+ painted: "painted";
51
+ }>;
52
+ weight: z.ZodOptional<z.ZodString>;
53
+ color: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strict>;
55
+ shading: z.ZodObject<{
56
+ kind: z.ZodEnum<{
57
+ flat: "flat";
58
+ bands: "bands";
59
+ physical: "physical";
60
+ soft: "soft";
61
+ hatched: "hatched";
62
+ dotted: "dotted";
63
+ painterly: "painterly";
64
+ }>;
65
+ steps: z.ZodOptional<z.ZodNumber>;
66
+ shadowColor: z.ZodOptional<z.ZodString>;
67
+ }, z.core.$strict>;
68
+ surface: z.ZodString;
69
+ palette: z.ZodObject<{
70
+ colors: z.ZodArray<z.ZodString>;
71
+ rule: z.ZodString;
72
+ }, z.core.$strict>;
73
+ rules: z.ZodArray<z.ZodString>;
74
+ look: z.ZodNullable<z.ZodObject<{
75
+ outline: z.ZodOptional<z.ZodNullable<z.ZodObject<{
76
+ width: z.ZodNumber;
77
+ color: z.ZodString;
78
+ depth: z.ZodOptional<z.ZodNumber>;
79
+ crease: z.ZodOptional<z.ZodNumber>;
80
+ }, z.core.$strip>>>;
81
+ bands: z.ZodOptional<z.ZodNullable<z.ZodObject<{
82
+ count: z.ZodNumber;
83
+ softness: z.ZodOptional<z.ZodNumber>;
84
+ }, z.core.$strip>>>;
85
+ hatch: z.ZodOptional<z.ZodNullable<z.ZodObject<{
86
+ amount: z.ZodNumber;
87
+ spacing: z.ZodNumber;
88
+ color: z.ZodString;
89
+ angle: z.ZodOptional<z.ZodNumber>;
90
+ }, z.core.$strip>>>;
91
+ halftone: z.ZodOptional<z.ZodNullable<z.ZodObject<{
92
+ amount: z.ZodNumber;
93
+ spacing: z.ZodNumber;
94
+ color: z.ZodString;
95
+ angle: z.ZodOptional<z.ZodNumber>;
96
+ }, z.core.$strip>>>;
97
+ paint: z.ZodOptional<z.ZodNullable<z.ZodObject<{
98
+ radius: z.ZodNumber;
99
+ }, z.core.$strip>>>;
100
+ paper: z.ZodOptional<z.ZodNullable<z.ZodObject<{
101
+ amount: z.ZodNumber;
102
+ color: z.ZodString;
103
+ grain: z.ZodNumber;
104
+ }, z.core.$strip>>>;
105
+ pixel: z.ZodOptional<z.ZodNullable<z.ZodObject<{
106
+ size: z.ZodNumber;
107
+ }, z.core.$strip>>>;
108
+ }, z.core.$strip>>;
109
+ avoid: z.ZodOptional<z.ZodArray<z.ZodString>>;
110
+ directions: z.ZodOptional<z.ZodArray<z.ZodObject<{
111
+ name: z.ZodString;
112
+ medium: z.ZodString;
113
+ why: z.ZodString;
114
+ picture: z.ZodOptional<z.ZodString>;
115
+ }, z.core.$strict>>>;
116
+ }, z.core.$strict>;
117
+ export type SpaceStyleT = z.infer<typeof SpaceStyle>;
118
+ export interface StyleResult {
119
+ ok: boolean;
120
+ style?: SpaceStyleT;
121
+ findings: Finding[];
122
+ }
123
+ /** Validates a raw style.json value: the schema, then what it alone cannot say. */
124
+ export declare function validateStyle(raw: unknown): StyleResult;
125
+ /**
126
+ * Where game.config.json's look draws otherwise than style.json says, as
127
+ * sentences for nw_status and the stop gate: a technique the style names
128
+ * and the look does not draw, and one the look draws that the style does
129
+ * not name. Empty when they agree, or when there is no style.
130
+ */
131
+ export declare function styleAdvice(style: SpaceStyleT | null | undefined, config: unknown): string[];