@zaisma/lighting-studio 0.0.0-stage → 1.0.0
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/LICENSE.txt +93 -0
- package/README.md +48 -2
- package/index.html +59 -0
- package/package.json +35 -4
- package/piece.json +20 -0
- package/scene.js +172 -0
- package/serve.mjs +179 -0
- package/studio.js +424 -0
- package/style.css +83 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# PolyForm Shield License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
12
|
+
|
|
13
|
+
## Distribution License
|
|
14
|
+
|
|
15
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
16
|
+
|
|
17
|
+
## Notices
|
|
18
|
+
|
|
19
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
20
|
+
|
|
21
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
22
|
+
|
|
23
|
+
## Changes and New Works License
|
|
24
|
+
|
|
25
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
26
|
+
|
|
27
|
+
## Patent License
|
|
28
|
+
|
|
29
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
30
|
+
|
|
31
|
+
## Noncompete
|
|
32
|
+
|
|
33
|
+
Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
|
|
34
|
+
|
|
35
|
+
## Competition
|
|
36
|
+
|
|
37
|
+
Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
|
|
38
|
+
|
|
39
|
+
## New Products
|
|
40
|
+
|
|
41
|
+
If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
|
|
42
|
+
|
|
43
|
+
## Discontinued Products
|
|
44
|
+
|
|
45
|
+
You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
|
|
46
|
+
|
|
47
|
+
> Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
|
|
48
|
+
|
|
49
|
+
## Sales of Business
|
|
50
|
+
|
|
51
|
+
If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
|
|
52
|
+
|
|
53
|
+
## Fair Use
|
|
54
|
+
|
|
55
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
56
|
+
|
|
57
|
+
## No Other Rights
|
|
58
|
+
|
|
59
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
60
|
+
|
|
61
|
+
## Patent Defense
|
|
62
|
+
|
|
63
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
64
|
+
|
|
65
|
+
## Violations
|
|
66
|
+
|
|
67
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
68
|
+
|
|
69
|
+
## No Liability
|
|
70
|
+
|
|
71
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
76
|
+
|
|
77
|
+
A **product** can be a good or service, or a combination of them.
|
|
78
|
+
|
|
79
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
80
|
+
|
|
81
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
|
|
82
|
+
|
|
83
|
+
**Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
|
|
84
|
+
|
|
85
|
+
**Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
86
|
+
|
|
87
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
88
|
+
|
|
89
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
|
90
|
+
|
|
91
|
+
Required Notice: Copyright (c) 2026 Zaisma LLC (https://zaisma.com)
|
|
92
|
+
|
|
93
|
+
Versions of @zaisma/lighting before 1.2.0 were published under the MIT License, and stay under it.
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zaisma/lighting-studio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A page for choosing and tuning a game's look with [`@zaisma/lighting`](https://www.npmjs.com/package/@zaisma/lighting). It draws one test scene with something for every part of the lighting to show on (a house light has to bounce into, columns, balls from rough to mirror, a walking figure, trees and grass, a pond, glass, street lamps and a hundred and sixty small lights), and it works on a game's own look files:
|
|
4
|
+
|
|
5
|
+
- **Every look in one click.** The seven that come with the piece, and the game's own beside them.
|
|
6
|
+
- **Any moment.** A time of day (or the day turning by itself), every weather, every season, the wind.
|
|
7
|
+
- **Every setting is a control,** grouped by what it changes and found by typing its name. A dot marks what's been tuned away from the look.
|
|
8
|
+
- **A tuned look saves as a small file,** and the page takes a look the moment its file is saved, by an AI, an editor or anything else. A file with a mistake shows what's wrong and how to fix it.
|
|
9
|
+
- **It measures.** A meter shows frames a second, the milliseconds a frame takes, the quality level in use, the picture's size, the lights lit and which of the heavier features are on. The quality level can be held at low, medium or high, and the page can be tried on WebGL 2, the fallback for devices without WebGPU.
|
|
10
|
+
|
|
11
|
+
A tool for a developer's own computer: a game never holds it.
|
|
12
|
+
|
|
13
|
+
## Run it
|
|
14
|
+
|
|
15
|
+
In the game's folder, with the lighting piece already added (`npx @zaisma/cli pieces add @zaisma/lighting`):
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
npx @zaisma/cli pieces get @zaisma/lighting-studio --to tools/lighting-studio
|
|
19
|
+
node tools/lighting-studio/serve.mjs --looks ./looks
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then open `http://localhost:4852/`. On npm instead: `npm install --save-dev @zaisma/lighting-studio`, and `node node_modules/@zaisma/lighting-studio/serve.mjs --looks ./looks`.
|
|
23
|
+
|
|
24
|
+
| Option | What it does |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `--looks <folder>` | The game's look files, one `name.json` each. Made if it isn't there. Left out, the page shows the piece's own looks to try and saves nothing. |
|
|
27
|
+
| `--port <number>` | The port. Default 4852. |
|
|
28
|
+
| `--host <address>` | Default `127.0.0.1`, this computer only. `0.0.0.0` lets a phone on the same network open it: the frame rate that counts is the phone's. |
|
|
29
|
+
| `--pieces <folder>` | The folder holding `lighting` and `piece`, when it isn't beside this tool, in `./pieces/@zaisma` or in `./node_modules/@zaisma`. |
|
|
30
|
+
|
|
31
|
+
## Using a saved look
|
|
32
|
+
|
|
33
|
+
A look file is a name, a title, a summary and the settings that differ from the piece's own. The game loads it and gives it to the lighting:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const look = await fetch("looks/harbor_dusk.json").then((answer) => answer.json());
|
|
37
|
+
const lighting = await createLighting({ canvas, scene, look });
|
|
38
|
+
// or later: lighting.setLook(look);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## With an AI
|
|
42
|
+
|
|
43
|
+
Ask for a look in words. The AI writes `looks/<name>.json` from the lighting piece's settings (each with its unit and range in `index.d.ts`), and the page shows it as it's saved. Tune by eye, save, and the AI reads the same file back.
|
|
44
|
+
|
|
45
|
+
## What it writes
|
|
46
|
+
|
|
47
|
+
Only `.json` files that pass the look check, only into the folder `--looks` names, and only from its own page: a write from another site is refused. It runs nothing and sends nothing anywhere.
|
|
48
|
+
|
|
49
|
+
PolyForm Shield 1.0.0 licensed (`LICENSE.txt`): use it for any game, sold or free; only a product that competes with it, or with what Zaisma makes with it, is ruled out.
|
package/index.html
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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, viewport-fit=cover" />
|
|
6
|
+
<title>Lighting studio</title>
|
|
7
|
+
<link rel="stylesheet" href="/style.css" />
|
|
8
|
+
<script type="importmap">
|
|
9
|
+
{ "imports": { "three": "/three/build/three.module.js", "three/webgpu": "/three/build/three.webgpu.js", "three/tsl": "/three/build/three.tsl.js", "three/addons/": "/three/examples/jsm/" } }
|
|
10
|
+
</script>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<div id="app">
|
|
14
|
+
<main id="stage">
|
|
15
|
+
<canvas id="view" aria-label="The test scene"></canvas>
|
|
16
|
+
<div id="stage-top">
|
|
17
|
+
<div id="looks" role="radiogroup" aria-label="Look"></div>
|
|
18
|
+
<button id="tune-open" class="sheet-open" type="button">Tune</button>
|
|
19
|
+
</div>
|
|
20
|
+
<p id="notice" role="status" hidden></p>
|
|
21
|
+
<div id="stage-bar">
|
|
22
|
+
<label class="bar-group">Time <input id="time" type="range" min="0" max="24" step="0.05" /> <output id="time-text"></output></label>
|
|
23
|
+
<label class="check"><input id="day-turns" type="checkbox" /> Day turns</label>
|
|
24
|
+
<label class="bar-group">Weather <select id="weather"></select></label>
|
|
25
|
+
<label class="bar-group">Season <select id="season"></select></label>
|
|
26
|
+
<label class="bar-group">Wind <input id="wind" type="range" min="0" max="100" step="1" /></label>
|
|
27
|
+
</div>
|
|
28
|
+
</main>
|
|
29
|
+
<aside id="tune-pane" class="pane" aria-label="Tune the look">
|
|
30
|
+
<div class="pane-head">
|
|
31
|
+
<input id="filter" type="search" placeholder="Find a setting" aria-label="Find a setting" />
|
|
32
|
+
<button id="tune-close" class="sheet-close" type="button">Close</button>
|
|
33
|
+
</div>
|
|
34
|
+
<div id="tune"></div>
|
|
35
|
+
<div id="tune-foot">
|
|
36
|
+
<input id="look-name" type="text" placeholder="harbor_dusk" aria-label="The look's name" maxlength="40" />
|
|
37
|
+
<button id="save-look" class="primary" type="button">Save look</button>
|
|
38
|
+
<button id="reset-look" type="button">Reset</button>
|
|
39
|
+
</div>
|
|
40
|
+
<p id="save-state" role="status"></p>
|
|
41
|
+
</aside>
|
|
42
|
+
<footer id="meter">
|
|
43
|
+
<span><b id="meter-frames">0</b> frames a second</span>
|
|
44
|
+
<span><b id="meter-ms">0</b> ms</span>
|
|
45
|
+
<span>Quality <b id="meter-quality"></b></span>
|
|
46
|
+
<span>Picture <b id="meter-scale"></b></span>
|
|
47
|
+
<span>Lights <b id="meter-lights"></b></span>
|
|
48
|
+
<span id="meter-levels"></span>
|
|
49
|
+
<span class="meter-right">
|
|
50
|
+
<select id="quality" aria-label="Quality"></select>
|
|
51
|
+
<button id="graphics" type="button"></button>
|
|
52
|
+
<button id="bake" type="button">Bake bounce</button>
|
|
53
|
+
<button id="flash" type="button">Flash</button>
|
|
54
|
+
</span>
|
|
55
|
+
</footer>
|
|
56
|
+
</div>
|
|
57
|
+
<script type="module" src="/studio.js"></script>
|
|
58
|
+
</body>
|
|
59
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zaisma/lighting-studio",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A page for choosing and tuning a game's look with @zaisma/lighting: one test scene in every look, at any time of day, in any weather and season, with a control for every setting and a meter. A tuned look saves as a small file the game loads in one line.",
|
|
5
|
+
"license": "PolyForm-Shield-1.0.0",
|
|
6
|
+
"homepage": "https://zaisma.com",
|
|
7
|
+
"bugs": "https://zaisma.com/forum",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"zaisma",
|
|
10
|
+
"zaisma-piece",
|
|
11
|
+
"games",
|
|
12
|
+
"browser-games",
|
|
13
|
+
"three",
|
|
14
|
+
"lighting",
|
|
15
|
+
"webgpu",
|
|
16
|
+
"art-direction",
|
|
17
|
+
"editor"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./serve.mjs",
|
|
22
|
+
"./piece.json": "./piece.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"LICENSE.txt",
|
|
26
|
+
"README.md",
|
|
27
|
+
"index.html",
|
|
28
|
+
"piece.json",
|
|
29
|
+
"scene.js",
|
|
30
|
+
"serve.mjs",
|
|
31
|
+
"studio.js",
|
|
32
|
+
"style.css"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/piece.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"statement_version_number": 2,
|
|
3
|
+
"name": "@zaisma/lighting-studio",
|
|
4
|
+
"title": "Lighting Studio",
|
|
5
|
+
"piece_version": "1.0.0",
|
|
6
|
+
"kind": "tool",
|
|
7
|
+
"standard": "@zaisma/standard",
|
|
8
|
+
"summary": "A page for choosing and tuning a game's look with the lighting piece: one test scene in every look, at any time of day, in any weather and season, with a control for every setting and a meter. A tuned look saves as a small file the game loads in one line.",
|
|
9
|
+
"license": "PolyForm-Shield-1.0.0",
|
|
10
|
+
"entry_path": "serve.mjs",
|
|
11
|
+
"server_entry_path": null,
|
|
12
|
+
"file_paths": ["serve.mjs", "index.html", "studio.js", "scene.js", "style.css", "README.md", "LICENSE.txt"],
|
|
13
|
+
"server_file_paths": [],
|
|
14
|
+
"needs": [
|
|
15
|
+
{ "name": "@zaisma/lighting", "version_range": "^2.0.0", "kind": "piece" },
|
|
16
|
+
{ "name": "three", "version_range": ">=0.187.0 <1.0.0", "kind": "library" }
|
|
17
|
+
],
|
|
18
|
+
"settings": [],
|
|
19
|
+
"hooks": []
|
|
20
|
+
}
|
package/scene.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// The studio's test scene: a small place with something for every part of the lighting to show on. Rolling
|
|
2
|
+
// ground with a pond in a hollow, a paved square, a house open on one side (bounce light, a torch, a glowing
|
|
3
|
+
// sign), a row of columns (shadows and corner shade), balls from rough to mirror (highlights and reflections),
|
|
4
|
+
// a figure walking a circle (contact shadow, moving through the bounce), trees and grass in the wind, a pane of
|
|
5
|
+
// glass, and street lamps that come on at night. Everything is made here from plain shapes: no files to load.
|
|
6
|
+
import * as THREE from "three/webgpu";
|
|
7
|
+
|
|
8
|
+
/** How high the ground is at a place, in metres: hills far out, flat in the middle, a hollow for the pond. */
|
|
9
|
+
export function groundHeightAt(x, z) {
|
|
10
|
+
const farM = Math.max(0, Math.hypot(x, z) - 45);
|
|
11
|
+
const hillsM = (Math.sin(x * 0.045) * Math.cos(z * 0.038) + Math.sin((x + z) * 0.021) * 0.7) * Math.min(farM * 0.09, 6);
|
|
12
|
+
const toPondM = Math.hypot(x - POND.x, z - POND.z);
|
|
13
|
+
const hollowM = toPondM < POND.radiusM + 3 ? -2.1 * (0.5 + 0.5 * Math.cos((Math.PI * toPondM) / (POND.radiusM + 3))) : 0;
|
|
14
|
+
return hillsM + hollowM;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const POND = { x: -24, z: 8, radiusM: 9 };
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Builds the scene's contents into the scene. lighting gives the surfaces and the lights. Answers
|
|
21
|
+
* { walker, update(clockSec), boundsM }: the walking figure, what moves each frame, and the box worth baking
|
|
22
|
+
* bounce for.
|
|
23
|
+
*/
|
|
24
|
+
export function buildScene({ scene, lighting }) {
|
|
25
|
+
const standard = (color, roughnessNumber = 0.8, metalnessNumber = 0) => new THREE.MeshStandardMaterial({ color, roughness: roughnessNumber, metalness: metalnessNumber });
|
|
26
|
+
const add = (mesh, x, y, z) => {
|
|
27
|
+
mesh.position.set(x, y, z);
|
|
28
|
+
scene.add(mesh);
|
|
29
|
+
return mesh;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// The ground.
|
|
33
|
+
const groundGeometry = new THREE.PlaneGeometry(420, 420, 140, 140);
|
|
34
|
+
groundGeometry.rotateX(-Math.PI / 2);
|
|
35
|
+
const groundSpots = groundGeometry.attributes.position;
|
|
36
|
+
for (let index = 0; index < groundSpots.count; index += 1) groundSpots.setY(index, groundHeightAt(groundSpots.getX(index), groundSpots.getZ(index)));
|
|
37
|
+
groundGeometry.computeVertexNormals();
|
|
38
|
+
add(new THREE.Mesh(groundGeometry, standard(0x6d8f4c, 0.95)), 0, 0, 0);
|
|
39
|
+
|
|
40
|
+
// The square.
|
|
41
|
+
add(new THREE.Mesh(new THREE.BoxGeometry(30, 0.2, 30), standard(0x9a948a, 0.7)), 0, -0.02, 0);
|
|
42
|
+
|
|
43
|
+
// The house: three walls, a floor and a roof, open toward the square, so light has to bounce to reach inside.
|
|
44
|
+
const wall = standard(0xd8c7a8, 0.85);
|
|
45
|
+
const house = new THREE.Group();
|
|
46
|
+
house.position.set(-9, 0, -9);
|
|
47
|
+
scene.add(house);
|
|
48
|
+
const part = (width, heightM, depth, x, y, z, material = wall) => {
|
|
49
|
+
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, heightM, depth), material);
|
|
50
|
+
mesh.position.set(x, y, z);
|
|
51
|
+
house.add(mesh);
|
|
52
|
+
return mesh;
|
|
53
|
+
};
|
|
54
|
+
part(9, 4.2, 0.35, 0, 2.1, -3.5);
|
|
55
|
+
part(0.35, 4.2, 7, -4.5, 2.1, 0);
|
|
56
|
+
part(0.35, 4.2, 7, 4.5, 2.1, 0);
|
|
57
|
+
part(9.6, 0.35, 7.6, 0, 4.35, 0, standard(0x8a4b3a, 0.8));
|
|
58
|
+
part(9, 0.12, 7, 0, 0.14, 0, standard(0xb9532f, 0.75));
|
|
59
|
+
part(2.2, 0.5, 0.12, 0, 3.1, -3.28, lighting.surfaces.glow({ color: "#ff7ad9", strengthPct: 160, pulsePerSec: 0.4 }));
|
|
60
|
+
lighting.lights.add({ positionM: { x: -9, y: 2.6, z: -9.5 }, color: "#ffb36b", strengthLux: 26, rangeM: 13, flickerPct: 22, isShadowCaster: true });
|
|
61
|
+
|
|
62
|
+
// The columns.
|
|
63
|
+
const stone = standard(0xc9c2b4, 0.6);
|
|
64
|
+
for (let index = 0; index < 6; index += 1) add(new THREE.Mesh(new THREE.CylinderGeometry(0.42, 0.48, 4, 20), stone), 5 + index * 2.4, 2.1, -10);
|
|
65
|
+
add(new THREE.Mesh(new THREE.BoxGeometry(13.6, 0.6, 1.4), stone), 11, 4.4, -10);
|
|
66
|
+
|
|
67
|
+
// The balls: rough to mirror, then metal.
|
|
68
|
+
const ballTones = [0xd94f3a, 0xe0a030, 0x3f9c6a, 0x3f78c9, 0xc9c9c9, 0xd9b45a];
|
|
69
|
+
ballTones.forEach((toneNumber, index) => {
|
|
70
|
+
const isMetal = index >= 4;
|
|
71
|
+
add(new THREE.Mesh(new THREE.SphereGeometry(0.85, 40, 20), standard(toneNumber, isMetal ? 0.22 : 0.85 - index * 0.22, isMetal ? 1 : 0)), -5 + index * 2.1, 0.95, 5.5);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Blocks in soft colours, for flat faces and long shadows.
|
|
75
|
+
for (let index = 0; index < 9; index += 1) {
|
|
76
|
+
const heightM = 1.2 + ((index * 7) % 4);
|
|
77
|
+
add(new THREE.Mesh(new THREE.BoxGeometry(2.2, heightM, 2.2), standard(new THREE.Color().setHSL((index * 0.17 + 0.55) % 1, 0.42, 0.62), 0.7)), 18 + ((index * 5) % 3) * 4.5, heightM / 2, -2 + Math.floor(index / 3) * 5);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The figure that walks a circle round the square.
|
|
81
|
+
const walker = new THREE.Group();
|
|
82
|
+
const cloth = standard(0x2f5fa8, 0.7);
|
|
83
|
+
const body = new THREE.Mesh(new THREE.CapsuleGeometry(0.34, 0.9, 6, 16), cloth);
|
|
84
|
+
body.position.y = 0.95;
|
|
85
|
+
const head = new THREE.Mesh(new THREE.SphereGeometry(0.27, 24, 12), standard(0xe8b995, 0.7));
|
|
86
|
+
head.position.y = 1.78;
|
|
87
|
+
walker.add(body, head);
|
|
88
|
+
scene.add(walker);
|
|
89
|
+
lighting.giveContactShadow(walker, { radiusM: 0.55 });
|
|
90
|
+
|
|
91
|
+
// Trees and grass.
|
|
92
|
+
const bark = standard(0x6b4a33, 0.9);
|
|
93
|
+
const treeSpots = [[-18, -14], [-26, -6], [-34, 4], [-30, 22], [-14, 20], [-4, 26], [10, 24], [24, 20], [34, 8], [36, -10], [26, -22], [8, -26], [-8, -28], [-36, -20], [-42, 12], [44, 26]];
|
|
94
|
+
treeSpots.forEach(([x, z], index) => {
|
|
95
|
+
const heightM = 5 + (index % 4) * 1.1;
|
|
96
|
+
const y = groundHeightAt(x, z);
|
|
97
|
+
add(new THREE.Mesh(new THREE.CylinderGeometry(0.22, 0.34, heightM * 0.5, 10), bark), x, y + heightM * 0.25, z);
|
|
98
|
+
const leaves = lighting.surfaces.foliage({ color: index % 3 === 0 ? "#4f8136" : "#5f9440", heightM: heightM, swayPct: 60 });
|
|
99
|
+
const crown = new THREE.Mesh(new THREE.ConeGeometry(heightM * 0.34, heightM * 0.75, 12, 6), leaves);
|
|
100
|
+
// The crown's own shape starts at its base, so its base stays still and its tip sways.
|
|
101
|
+
crown.geometry.translate(0, heightM * 0.375 + heightM * 0.3, 0);
|
|
102
|
+
add(crown, x, y, z);
|
|
103
|
+
});
|
|
104
|
+
const bladeGeometry = new THREE.ConeGeometry(0.05, 0.55, 4, 3);
|
|
105
|
+
bladeGeometry.translate(0, 0.275, 0);
|
|
106
|
+
const grass = new THREE.InstancedMesh(bladeGeometry, lighting.surfaces.foliage({ color: "#7aa64e", heightM: 0.55 }), 5200);
|
|
107
|
+
const placed = new THREE.Object3D();
|
|
108
|
+
let grassIndex = 0;
|
|
109
|
+
for (let index = 0; grassIndex < grass.count && index < 40_000; index += 1) {
|
|
110
|
+
// A fixed scatter: the same grass every visit.
|
|
111
|
+
const x = ((index * 37.13) % 110) - 55;
|
|
112
|
+
const z = ((index * 91.71) % 110) - 55;
|
|
113
|
+
if (Math.abs(x) < 16 && Math.abs(z) < 16) continue;
|
|
114
|
+
if (Math.hypot(x - POND.x, z - POND.z) < POND.radiusM + 1) continue;
|
|
115
|
+
placed.position.set(x, groundHeightAt(x, z), z);
|
|
116
|
+
placed.rotation.y = index * 2.4;
|
|
117
|
+
placed.scale.setScalar(0.7 + ((index * 0.37) % 0.9));
|
|
118
|
+
placed.updateMatrix();
|
|
119
|
+
grass.setMatrixAt(grassIndex, placed.matrix);
|
|
120
|
+
grassIndex += 1;
|
|
121
|
+
}
|
|
122
|
+
grass.count = grassIndex;
|
|
123
|
+
scene.add(grass);
|
|
124
|
+
|
|
125
|
+
// The pond.
|
|
126
|
+
const water = new THREE.Mesh(new THREE.CircleGeometry(POND.radiusM + 2.4, 48), lighting.surfaces.water({ waveSizeM: 3, waveStrengthPct: 45 }));
|
|
127
|
+
water.rotation.x = -Math.PI / 2;
|
|
128
|
+
water.userData.isWater = true;
|
|
129
|
+
add(water, POND.x, -0.45, POND.z);
|
|
130
|
+
|
|
131
|
+
// A pane of glass in a frame.
|
|
132
|
+
const frame = standard(0x3a3f47, 0.5, 0.6);
|
|
133
|
+
add(new THREE.Mesh(new THREE.BoxGeometry(4.4, 0.16, 0.16), frame), 9, 3.1, 8);
|
|
134
|
+
add(new THREE.Mesh(new THREE.BoxGeometry(0.16, 3.1, 0.16), frame), 6.9, 1.55, 8);
|
|
135
|
+
add(new THREE.Mesh(new THREE.BoxGeometry(0.16, 3.1, 0.16), frame), 11.1, 1.55, 8);
|
|
136
|
+
const pane = add(new THREE.Mesh(new THREE.PlaneGeometry(4.1, 3), lighting.surfaces.glass()), 9, 1.55, 8);
|
|
137
|
+
pane.userData.isGlass = true;
|
|
138
|
+
|
|
139
|
+
// Street lamps round the square: on at night.
|
|
140
|
+
const post = standard(0x2c3037, 0.5, 0.7);
|
|
141
|
+
const lampSpots = [[-13, 13], [0, 14.5], [13, 13], [14.5, 0], [-14.5, 0], [13, -13]];
|
|
142
|
+
lampSpots.forEach(([x, z], index) => {
|
|
143
|
+
add(new THREE.Mesh(new THREE.CylinderGeometry(0.07, 0.1, 4.2, 10), post), x, 2.1, z);
|
|
144
|
+
add(new THREE.Mesh(new THREE.SphereGeometry(0.2, 16, 8), lighting.surfaces.glow({ color: "#ffe1a8", strengthPct: 90 })), x, 4.3, z);
|
|
145
|
+
lighting.lights.add({ positionM: { x, y: 4.2, z }, color: "#ffd9a0", strengthLux: 46, rangeM: 17, isNightOnly: true, isShadowCaster: index < 2 });
|
|
146
|
+
});
|
|
147
|
+
// And a scatter of small coloured lights out in the grass, to show how many is cheap.
|
|
148
|
+
const lanternTones = ["#ff9a52", "#63d2ff", "#ff6aa8", "#b7ff7a"];
|
|
149
|
+
for (let index = 0; index < 160; index += 1) {
|
|
150
|
+
const turnRad = index * 2.399;
|
|
151
|
+
const reachM = 20 + ((index * 13) % 70);
|
|
152
|
+
const x = Math.cos(turnRad) * reachM;
|
|
153
|
+
const z = Math.sin(turnRad) * reachM;
|
|
154
|
+
if (Math.hypot(x - POND.x, z - POND.z) < POND.radiusM + 1) continue;
|
|
155
|
+
lighting.lights.add({ positionM: { x, y: groundHeightAt(x, z) + 0.7, z }, color: lanternTones[index % 4], strengthLux: 5, rangeM: 6, isNightOnly: true, flickerPct: index % 3 === 0 ? 20 : 0 });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
lighting.giveShadows(scene);
|
|
159
|
+
scene.traverse((child) => {
|
|
160
|
+
if (child.userData.isWater || child.userData.isGlass) child.castShadow = false;
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
walker,
|
|
165
|
+
boundsM: { minimum: { x: -22, y: 0, z: -18 }, maximum: { x: 30, y: 8, z: 16 } },
|
|
166
|
+
update(clockSec) {
|
|
167
|
+
const turnRad = clockSec * 0.35;
|
|
168
|
+
walker.position.set(Math.cos(turnRad) * 9.5, 0.08, Math.sin(turnRad) * 9.5);
|
|
169
|
+
walker.rotation.y = -turnRad;
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
package/serve.mjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// The lighting studio's server: it serves the studio page, the pieces it draws with and three.js, and one folder
|
|
2
|
+
// of saved looks to work on. It watches that folder, so the page takes a look the moment its file is saved (by an
|
|
3
|
+
// AI, an editor, anything), and it saves the looks tuned on the page back to the folder.
|
|
4
|
+
//
|
|
5
|
+
// node serve.mjs --looks ./looks [--port 4852] [--host 127.0.0.1] [--pieces ./pieces/@zaisma]
|
|
6
|
+
//
|
|
7
|
+
// Run it from the game's folder. It draws with the game's own copy of the pieces (@zaisma/lighting and three.js),
|
|
8
|
+
// found beside this file, in ./pieces/@zaisma or in ./node_modules/@zaisma, or where --pieces says. Plain node,
|
|
9
|
+
// nothing to install. It writes only .json files that pass the look check, only into the folder named, and takes
|
|
10
|
+
// writes only from its own page.
|
|
11
|
+
import { createServer } from "node:http";
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, watch, writeFileSync } from "node:fs";
|
|
13
|
+
import { dirname, extname, join, normalize, resolve, sep } from "node:path";
|
|
14
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
15
|
+
|
|
16
|
+
const ownFolder = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
const optionAfter = (name) => {
|
|
18
|
+
const optionIndex = process.argv.indexOf(name);
|
|
19
|
+
return optionIndex === -1 ? null : (process.argv[optionIndex + 1] ?? null);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const NEEDED_PIECE_NAMES = ["lighting", "piece"];
|
|
23
|
+
const holdsPieces = (folder) => NEEDED_PIECE_NAMES.every((name) => existsSync(join(folder, name, "piece.json")));
|
|
24
|
+
const piecesFolder = [optionAfter("--pieces"), resolve(ownFolder, ".."), "pieces/@zaisma", "node_modules/@zaisma"].filter(Boolean).map((folder) => resolve(folder)).find(holdsPieces) ?? null;
|
|
25
|
+
if (!piecesFolder) {
|
|
26
|
+
console.error("The lighting studio draws with the game's own pieces, and found none here.");
|
|
27
|
+
console.error("Run it from the game's folder after: npx @zaisma/cli pieces add @zaisma/lighting");
|
|
28
|
+
console.error("Or say where they are: --pieces <the folder holding lighting and piece>");
|
|
29
|
+
console.error("FAIL");
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
const portNumber = Number(optionAfter("--port") ?? process.env.PORT ?? 4852);
|
|
33
|
+
const host = optionAfter("--host") ?? "127.0.0.1";
|
|
34
|
+
const looksFolder = optionAfter("--looks") ? resolve(optionAfter("--looks")) : null;
|
|
35
|
+
if (looksFolder) mkdirSync(looksFolder, { recursive: true });
|
|
36
|
+
|
|
37
|
+
/** three.js: brought beside the game's pieces (pieces/three), or in a node_modules from here or this file upward. */
|
|
38
|
+
function findThreeFolder() {
|
|
39
|
+
const isThree = (folder) => existsSync(join(folder, "build", "three.webgpu.js"));
|
|
40
|
+
const brought = [resolve(piecesFolder, "..", "three"), resolve(piecesFolder, "three")].find(isThree);
|
|
41
|
+
if (brought) return brought;
|
|
42
|
+
for (const start of [process.cwd(), ownFolder]) {
|
|
43
|
+
let folder = start;
|
|
44
|
+
for (;;) {
|
|
45
|
+
if (isThree(join(folder, "node_modules", "three"))) return join(folder, "node_modules", "three");
|
|
46
|
+
const parent = dirname(folder);
|
|
47
|
+
if (parent === folder) break;
|
|
48
|
+
folder = parent;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const threeFolder = findThreeFolder();
|
|
54
|
+
|
|
55
|
+
const CONTENT_TYPES = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8", ".json": "application/json; charset=utf-8", ".svg": "image/svg+xml", ".png": "image/png", ".webp": "image/webp", ".bin": "application/octet-stream" };
|
|
56
|
+
const OWN_FILE_PATTERN = /^[a-z][a-z0-9-]*\.(html|js|css)$/;
|
|
57
|
+
const LOOK_FILE_PATTERN = /^[a-z][a-z0-9]*(_[a-z0-9]+)*\.json$/;
|
|
58
|
+
const MAXIMUM_LOOK_FILE_BYTES = 64 * 1024;
|
|
59
|
+
|
|
60
|
+
function answer(response, status, body, contentType = "application/json; charset=utf-8") {
|
|
61
|
+
response.writeHead(status, { "content-type": contentType, "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
62
|
+
response.end(body);
|
|
63
|
+
}
|
|
64
|
+
const answerJson = (response, status, answerValue) => answer(response, status, JSON.stringify(answerValue));
|
|
65
|
+
const answerProblem = (response, status, code, message, fix) => answerJson(response, status, { error: { code, message, field: null, fix } });
|
|
66
|
+
|
|
67
|
+
/** Serves a file from inside a folder, never from outside it. */
|
|
68
|
+
function serveFrom(response, folder, relativePath) {
|
|
69
|
+
const filePath = normalize(join(folder, relativePath));
|
|
70
|
+
if (!filePath.startsWith(folder + sep) || !existsSync(filePath) || !statSync(filePath).isFile()) return answerProblem(response, 404, "not_found", "There's no such file.", "Check the address.");
|
|
71
|
+
return answer(response, 200, readFileSync(filePath), CONTENT_TYPES[extname(filePath)] ?? "application/octet-stream");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let checkLook = null;
|
|
75
|
+
async function lookProblems(look) {
|
|
76
|
+
checkLook ??= (await import(pathToFileURL(join(piecesFolder, "lighting", "looks.js")).href)).checkLook;
|
|
77
|
+
return checkLook(look);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function listLooks() {
|
|
81
|
+
if (!looksFolder) return [];
|
|
82
|
+
const listed = [];
|
|
83
|
+
for (const fileName of readdirSync(looksFolder).filter((name) => LOOK_FILE_PATTERN.test(name)).sort()) {
|
|
84
|
+
try {
|
|
85
|
+
const look = JSON.parse(readFileSync(join(looksFolder, fileName), "utf8"));
|
|
86
|
+
listed.push({ file_name: fileName, look, problems: await lookProblems(look) });
|
|
87
|
+
} catch (error) {
|
|
88
|
+
listed.push({ file_name: fileName, look: null, problems: [{ code: "bad_look_file", message: `${fileName} isn't JSON: ${error.message}`, field: null, fix: "Fix the file's JSON." }] });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return listed;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ---- Changes to the folder, told to every open page ----
|
|
95
|
+
const listeners = new Set();
|
|
96
|
+
if (looksFolder) {
|
|
97
|
+
const pending = new Map();
|
|
98
|
+
watch(looksFolder, (eventKind, fileName) => {
|
|
99
|
+
if (!fileName || !LOOK_FILE_PATTERN.test(fileName)) return;
|
|
100
|
+
// An editor's save is often several events: one telling, a moment after the last.
|
|
101
|
+
clearTimeout(pending.get(fileName));
|
|
102
|
+
pending.set(
|
|
103
|
+
fileName,
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
pending.delete(fileName);
|
|
106
|
+
for (const listener of listeners) listener.write(`data: ${JSON.stringify({ file_name: fileName })}\n\n`);
|
|
107
|
+
}, 80),
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function readBody(request, maximumBytes) {
|
|
113
|
+
return new Promise((resolveBody, rejectBody) => {
|
|
114
|
+
const parts = [];
|
|
115
|
+
let byteCount = 0;
|
|
116
|
+
request.on("data", (part) => {
|
|
117
|
+
byteCount += part.length;
|
|
118
|
+
if (byteCount > maximumBytes) {
|
|
119
|
+
rejectBody(new Error("too_large"));
|
|
120
|
+
request.destroy();
|
|
121
|
+
} else parts.push(part);
|
|
122
|
+
});
|
|
123
|
+
request.on("end", () => resolveBody(Buffer.concat(parts).toString("utf8")));
|
|
124
|
+
request.on("error", rejectBody);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function saveLook(request, response, fileName) {
|
|
129
|
+
if (!looksFolder) return answerProblem(response, 409, "no_looks_folder", "The studio was started without a folder to save to.", "Start it with --looks <folder>.");
|
|
130
|
+
if (!LOOK_FILE_PATTERN.test(fileName)) return answerProblem(response, 400, "bad_look_file_name", "A look file is named like harbor_dusk.json.", "Name it in lowercase words joined by underscores, ending .json.");
|
|
131
|
+
// Only this server's own page may write: a page of another site can't send JSON here without asking first, and its origin is never this one.
|
|
132
|
+
const origin = request.headers.origin;
|
|
133
|
+
if ((origin && origin !== `http://${request.headers.host}`) || !String(request.headers["content-type"] ?? "").startsWith("application/json")) {
|
|
134
|
+
return answerProblem(response, 403, "not_own_page", "Only the studio's own page saves looks.", "Save from the studio.");
|
|
135
|
+
}
|
|
136
|
+
let look;
|
|
137
|
+
try {
|
|
138
|
+
look = JSON.parse(await readBody(request, MAXIMUM_LOOK_FILE_BYTES));
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return answerProblem(response, 400, "bad_look_file", error.message === "too_large" ? "The look file is over 64 KB." : "The look file isn't JSON.", "Send the look as JSON.");
|
|
141
|
+
}
|
|
142
|
+
const problems = await lookProblems(look);
|
|
143
|
+
if (problems.length > 0) return answerJson(response, 400, { error: problems[0], problems });
|
|
144
|
+
if (`${look.name}.json` !== fileName) return answerProblem(response, 400, "bad_look_file_name", "The file's name isn't the look's name.", `Save it as ${look.name}.json.`);
|
|
145
|
+
writeFileSync(join(looksFolder, fileName), `${JSON.stringify(look, null, 2)}\n`);
|
|
146
|
+
return answerJson(response, 200, { file_name: fileName });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const server = createServer((request, response) => {
|
|
150
|
+
const url = new URL(request.url, "http://localhost");
|
|
151
|
+
let path;
|
|
152
|
+
try {
|
|
153
|
+
path = decodeURIComponent(url.pathname);
|
|
154
|
+
} catch {
|
|
155
|
+
return answerProblem(response, 400, "bad_address", "The address isn't readable.", "Check the address.");
|
|
156
|
+
}
|
|
157
|
+
const failed = () => answerProblem(response, 500, "not_done", "The studio couldn't do that.", "Check the looks folder can be read and written.");
|
|
158
|
+
if (request.method === "PUT" && path.startsWith("/api/looks/")) return saveLook(request, response, path.slice("/api/looks/".length)).catch(failed);
|
|
159
|
+
if (request.method !== "GET" && request.method !== "HEAD") return answerProblem(response, 405, "method_not_allowed", "The studio takes GET, and PUT for a look file.", "Use GET.");
|
|
160
|
+
if (path === "/") return serveFrom(response, ownFolder, "index.html");
|
|
161
|
+
if (OWN_FILE_PATTERN.test(path.slice(1))) return serveFrom(response, ownFolder, path.slice(1));
|
|
162
|
+
if (path === "/api/looks") return listLooks().then((looks) => answerJson(response, 200, { can_save: Boolean(looksFolder), folder_name: looksFolder ? looksFolder.split(sep).slice(-2).join("/") : null, looks }), failed);
|
|
163
|
+
if (path === "/api/changes") {
|
|
164
|
+
response.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" });
|
|
165
|
+
response.write(": watching\n\n");
|
|
166
|
+
listeners.add(response);
|
|
167
|
+
request.on("close", () => listeners.delete(response));
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
if (path.startsWith("/pieces/")) return serveFrom(response, piecesFolder, path.slice("/pieces/".length));
|
|
171
|
+
if (path.startsWith("/three/") && threeFolder) return serveFrom(response, threeFolder, path.slice("/three/".length));
|
|
172
|
+
return answerProblem(response, 404, "not_found", "There's no such page.", "Open / for the studio.");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
server.listen(portNumber, host, () => {
|
|
176
|
+
console.log(`Lighting studio: http://${host === "0.0.0.0" ? "localhost" : host}:${portNumber}/`);
|
|
177
|
+
console.log(looksFolder ? `Saving looks to ${looksFolder}` : "No --looks folder: the piece's own looks, to try. Start with --looks <folder> to save a game's own.");
|
|
178
|
+
if (!threeFolder) console.log("three.js wasn't found beside the pieces or in node_modules: run npm install three in the game's folder.");
|
|
179
|
+
});
|
package/studio.js
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
// The lighting studio's page: the test scene drawn by @zaisma/lighting, with every look a press away, the time
|
|
2
|
+
// of day, the weather and the season under the scene, a control for every setting beside it, a meter under it,
|
|
3
|
+
// and a look saved to a file once it's tuned. The address keeps what's picked (?look=moody&hours=21), so a link
|
|
4
|
+
// shows someone else the same thing.
|
|
5
|
+
import * as THREE from "three/webgpu";
|
|
6
|
+
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
7
|
+
import { LOOKS, LOOK_NAMES, LOOK_SETTING_NAMES, SEASON_NAMES, WEATHER_NAMES, createLighting } from "/pieces/lighting/index.js";
|
|
8
|
+
import { buildScene } from "/scene.js";
|
|
9
|
+
|
|
10
|
+
const byId = (id) => document.getElementById(id);
|
|
11
|
+
const pageSearch = new URLSearchParams(location.search);
|
|
12
|
+
const canvas = byId("view");
|
|
13
|
+
const notice = byId("notice");
|
|
14
|
+
|
|
15
|
+
// What each group of settings is called, and which settings it holds, in the order they're shown.
|
|
16
|
+
const GROUPS = [
|
|
17
|
+
["Shading", ["shading_kind", "tone_step_count", "tone_softness_pct", "rim_light_pct", "shine_pct", "outline_width_px", "outline_color", "outline_fade_distance_m"]],
|
|
18
|
+
["Light and shadow", ["light_strength_pct", "fill_strength_pct", "light_tint_color", "shadow_tint_color", "shadow_tint_pct", "shadows_enabled", "shadow_softness_pct", "contact_shadows_pct", "bounce_strength_pct", "reflections_enabled", "corner_shade_level", "corner_shade_strength_pct", "corner_shade_radius_m"]],
|
|
19
|
+
["Sky and clouds", ["sky_style", "sky_saturation_pct", "cloud_style", "volumetric_clouds_level", "stars_enabled", "sun_disc_size_pct"]],
|
|
20
|
+
["Air", ["fog_enabled", "fog_sun_glow_pct", "ground_fog_pct", "haze_pct", "light_shafts_level", "light_shafts_strength_pct", "lamp_halos_pct"]],
|
|
21
|
+
["Camera", ["exposure_pct", "tone_mapping", "eye_adaptation_enabled", "eye_adaptation_range_pct", "bloom_level", "bloom_strength_pct", "bloom_threshold_pct", "bloom_spread_pct", "edge_smoothing_level", "sharpen_pct", "vignette_pct", "grain_pct"]],
|
|
22
|
+
["Colour", ["saturation_pct", "contrast_pct", "brightness_pct", "warmth_pct", "shadow_grade_color", "highlight_grade_color"]],
|
|
23
|
+
["Pixels and paint", ["pixel_size_px", "color_bit_count", "dither_pct", "vertex_snap_px", "texture_warp_pct", "brush_size_px"]],
|
|
24
|
+
["The world", ["day_length_min", "sun_peak_elevation_deg", "sun_path_turn_deg", "wind_turn_deg", "clouds_pct", "weather_change_duration_sec", "fog_start_m", "fog_end_m", "ground_fog_height_m", "ground_fog_floor_m", "shadow_distance_m", "far_shadows_enabled", "far_shadow_distance_m"]],
|
|
25
|
+
["Focus", ["focus_blur_pct", "focus_distance_m", "focus_range_m", "menu_blur_pct"]],
|
|
26
|
+
["Device", ["target_frames_per_sec", "picture_scale_pct"]],
|
|
27
|
+
];
|
|
28
|
+
// Settings with a control of their own outside the panel.
|
|
29
|
+
const OUTSIDE_PANEL = ["time_of_day_hours", "weather", "season", "wind_strength_pct", "quality_level"];
|
|
30
|
+
|
|
31
|
+
const titleOf = (statedName) => {
|
|
32
|
+
const words = statedName.replace(/_(pct|px|m|deg|min|sec|hours|level|enabled|lux|bits|count)$/, "").split("_");
|
|
33
|
+
return words.map((word, index) => (index === 0 ? word[0].toUpperCase() + word.slice(1) : word)).join(" ");
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function showNotice(message) {
|
|
37
|
+
notice.textContent = message;
|
|
38
|
+
notice.hidden = false;
|
|
39
|
+
clearTimeout(showNotice.timer);
|
|
40
|
+
showNotice.timer = setTimeout(() => (notice.hidden = true), 6000);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const scene = new THREE.Scene();
|
|
44
|
+
const camera = new THREE.PerspectiveCamera(55, 1, 0.1, 3000);
|
|
45
|
+
camera.position.set(17, 6.5, 19);
|
|
46
|
+
|
|
47
|
+
// ?trace=1 has three.js say where in the code a shader problem came from.
|
|
48
|
+
if (pageSearch.has("trace")) {
|
|
49
|
+
THREE.Node.captureStackTrace = true;
|
|
50
|
+
Error.stackTraceLimit = 40;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let lighting;
|
|
54
|
+
try {
|
|
55
|
+
lighting = await createLighting({
|
|
56
|
+
canvas,
|
|
57
|
+
scene,
|
|
58
|
+
look: LOOK_NAMES.includes(pageSearch.get("look")) ? pageSearch.get("look") : "clean",
|
|
59
|
+
graphicsKind: pageSearch.get("graphics") === "webgl2" ? "webgl2" : "auto",
|
|
60
|
+
settings: {
|
|
61
|
+
timeOfDayHours: Number.isFinite(Number(pageSearch.get("hours"))) && pageSearch.has("hours") ? Math.min(24, Math.max(0, Number(pageSearch.get("hours")))) : 15,
|
|
62
|
+
weather: WEATHER_NAMES.includes(pageSearch.get("weather")) ? pageSearch.get("weather") : "clear",
|
|
63
|
+
season: SEASON_NAMES.includes(pageSearch.get("season")) ? pageSearch.get("season") : "none",
|
|
64
|
+
weatherChangeDurationSec: 4,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
showNotice(`The lighting couldn't start: ${error.message}`);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
const { settings } = lighting;
|
|
72
|
+
const world = buildScene({ scene, lighting });
|
|
73
|
+
lighting.follow(world.walker);
|
|
74
|
+
|
|
75
|
+
const controls = new OrbitControls(camera, canvas);
|
|
76
|
+
controls.target.set(0, 1.6, 0);
|
|
77
|
+
controls.enableDamping = true;
|
|
78
|
+
controls.maxPolarAngle = Math.PI * 0.495;
|
|
79
|
+
controls.minDistance = 2;
|
|
80
|
+
controls.maxDistance = 160;
|
|
81
|
+
|
|
82
|
+
// ---- The looks ----
|
|
83
|
+
const looksBar = byId("looks");
|
|
84
|
+
let savedLooks = [];
|
|
85
|
+
let lookInUse = lighting.lookName;
|
|
86
|
+
|
|
87
|
+
function drawLooks() {
|
|
88
|
+
looksBar.replaceChildren();
|
|
89
|
+
const entries = [...LOOK_NAMES.map((name) => ({ name, title: LOOKS[name].title, summary: LOOKS[name].summary, look: name })), ...savedLooks.filter((saved) => saved.problems.length === 0).map((saved) => ({ name: saved.look.name, title: saved.look.title, summary: saved.look.summary, look: saved.look, isSaved: true }))];
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
const button = document.createElement("button");
|
|
92
|
+
button.type = "button";
|
|
93
|
+
button.role = "radio";
|
|
94
|
+
button.textContent = entry.title;
|
|
95
|
+
button.title = entry.summary;
|
|
96
|
+
button.ariaChecked = String(entry.name === lookInUse);
|
|
97
|
+
if (entry.isSaved) button.classList.add("is-saved");
|
|
98
|
+
button.addEventListener("click", () => {
|
|
99
|
+
lighting.setLook(entry.look);
|
|
100
|
+
lookInUse = entry.name;
|
|
101
|
+
if (!entry.isSaved) rememberInAddress({ look: entry.name });
|
|
102
|
+
drawLooks();
|
|
103
|
+
syncFields();
|
|
104
|
+
});
|
|
105
|
+
looksBar.append(button);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// A look changed from anywhere (a saved file, the console) shows as the one in use.
|
|
110
|
+
lighting.hooks.on("lookChanged", ({ lookName }) => {
|
|
111
|
+
if (lookName === lookInUse) return;
|
|
112
|
+
lookInUse = lookName;
|
|
113
|
+
drawLooks();
|
|
114
|
+
syncFields();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
async function loadSavedLooks() {
|
|
118
|
+
try {
|
|
119
|
+
const answer = await fetch("/api/looks");
|
|
120
|
+
if (!answer.ok) return;
|
|
121
|
+
savedLooks = (await answer.json()).looks ?? [];
|
|
122
|
+
drawLooks();
|
|
123
|
+
} catch {
|
|
124
|
+
// No looks folder to read: the looks that come with the piece are enough to work with.
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function rememberInAddress(changes) {
|
|
129
|
+
for (const [name, settingValue] of Object.entries(changes)) pageSearch.set(name, settingValue);
|
|
130
|
+
history.replaceState(null, "", `?${pageSearch}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ---- Under the scene: time, weather, season, wind ----
|
|
134
|
+
const timeSlider = byId("time");
|
|
135
|
+
const timeText = byId("time-text");
|
|
136
|
+
const dayTurns = byId("day-turns");
|
|
137
|
+
const weatherSelect = byId("weather");
|
|
138
|
+
const seasonSelect = byId("season");
|
|
139
|
+
const windSlider = byId("wind");
|
|
140
|
+
const showTime = () => {
|
|
141
|
+
const hours = settings.get("timeOfDayHours");
|
|
142
|
+
timeSlider.value = String(hours);
|
|
143
|
+
timeText.textContent = `${String(Math.floor(hours) % 24).padStart(2, "0")}:${String(Math.floor((hours % 1) * 60)).padStart(2, "0")}`;
|
|
144
|
+
};
|
|
145
|
+
for (const name of WEATHER_NAMES) weatherSelect.add(new Option(name[0].toUpperCase() + name.slice(1), name));
|
|
146
|
+
for (const name of ["none", ...SEASON_NAMES.filter((season) => season !== "none")]) seasonSelect.add(new Option(name === "none" ? "No season" : name[0].toUpperCase() + name.slice(1), name));
|
|
147
|
+
weatherSelect.value = settings.get("weather");
|
|
148
|
+
seasonSelect.value = settings.get("season");
|
|
149
|
+
windSlider.value = String(settings.get("windStrengthPct"));
|
|
150
|
+
showTime();
|
|
151
|
+
timeSlider.addEventListener("input", () => {
|
|
152
|
+
settings.set({ timeOfDayHours: Number(timeSlider.value) % 24 });
|
|
153
|
+
showTime();
|
|
154
|
+
rememberInAddress({ hours: Number(timeSlider.value).toFixed(2) });
|
|
155
|
+
});
|
|
156
|
+
dayTurns.addEventListener("change", () => settings.set({ dayLengthMin: dayTurns.checked ? 2 : 0 }));
|
|
157
|
+
weatherSelect.addEventListener("change", () => {
|
|
158
|
+
settings.set({ weather: weatherSelect.value });
|
|
159
|
+
rememberInAddress({ weather: weatherSelect.value });
|
|
160
|
+
});
|
|
161
|
+
seasonSelect.addEventListener("change", () => {
|
|
162
|
+
settings.set({ season: seasonSelect.value });
|
|
163
|
+
rememberInAddress({ season: seasonSelect.value });
|
|
164
|
+
});
|
|
165
|
+
windSlider.addEventListener("input", () => settings.set({ windStrengthPct: Number(windSlider.value) }));
|
|
166
|
+
|
|
167
|
+
// ---- The panel: a control for every setting ----
|
|
168
|
+
const tune = byId("tune");
|
|
169
|
+
const fields = new Map();
|
|
170
|
+
|
|
171
|
+
function makeField(listed) {
|
|
172
|
+
const field = document.createElement("div");
|
|
173
|
+
field.className = "field";
|
|
174
|
+
field.dataset.search = `${listed.statedName} ${listed.summary}`.toLowerCase();
|
|
175
|
+
const label = document.createElement("label");
|
|
176
|
+
label.textContent = titleOf(listed.statedName);
|
|
177
|
+
label.title = listed.summary;
|
|
178
|
+
label.htmlFor = `setting-${listed.statedName}`;
|
|
179
|
+
field.append(label);
|
|
180
|
+
const change = (settingValue) => {
|
|
181
|
+
try {
|
|
182
|
+
settings.set({ [listed.name]: settingValue });
|
|
183
|
+
} catch (error) {
|
|
184
|
+
showNotice(error.message);
|
|
185
|
+
}
|
|
186
|
+
syncField(listed.name);
|
|
187
|
+
};
|
|
188
|
+
let read;
|
|
189
|
+
if (listed.valueKind === "number" || listed.valueKind === "integer") {
|
|
190
|
+
const range = document.createElement("input");
|
|
191
|
+
range.type = "range";
|
|
192
|
+
range.id = label.htmlFor;
|
|
193
|
+
range.min = String(listed.minimumNumber);
|
|
194
|
+
// A slider over a huge reach is no use: it runs to a workable end, and the number box takes the rest.
|
|
195
|
+
const reachNumber = listed.maximumNumber - listed.minimumNumber;
|
|
196
|
+
const workable = reachNumber > 4000 ? Math.max(listed.defaultValue * 4, listed.minimumNumber + 400) : listed.maximumNumber;
|
|
197
|
+
range.max = String(workable);
|
|
198
|
+
range.step = listed.valueKind === "integer" ? "1" : String(reachNumber > 50 ? 1 : reachNumber > 5 ? 0.1 : 0.01);
|
|
199
|
+
const box = document.createElement("input");
|
|
200
|
+
box.type = "number";
|
|
201
|
+
box.min = String(listed.minimumNumber);
|
|
202
|
+
box.max = String(listed.maximumNumber);
|
|
203
|
+
box.step = range.step;
|
|
204
|
+
box.ariaLabel = label.textContent;
|
|
205
|
+
range.addEventListener("input", () => change(Number(range.value)));
|
|
206
|
+
box.addEventListener("change", () => change(Number(box.value)));
|
|
207
|
+
field.append(range, box);
|
|
208
|
+
read = (settingValue) => {
|
|
209
|
+
range.value = String(settingValue);
|
|
210
|
+
box.value = String(settingValue);
|
|
211
|
+
};
|
|
212
|
+
} else if (listed.valueKind === "boolean") {
|
|
213
|
+
const check = document.createElement("input");
|
|
214
|
+
check.type = "checkbox";
|
|
215
|
+
check.id = label.htmlFor;
|
|
216
|
+
check.addEventListener("change", () => change(check.checked));
|
|
217
|
+
label.prepend(check, " ");
|
|
218
|
+
read = (settingValue) => (check.checked = settingValue);
|
|
219
|
+
} else if (listed.valueKind === "choice") {
|
|
220
|
+
const select = document.createElement("select");
|
|
221
|
+
select.id = label.htmlFor;
|
|
222
|
+
for (const choice of listed.choices) select.add(new Option(choice, choice));
|
|
223
|
+
select.addEventListener("change", () => change(select.value));
|
|
224
|
+
field.append(select);
|
|
225
|
+
read = (settingValue) => (select.value = settingValue);
|
|
226
|
+
} else if (listed.valueKind === "color") {
|
|
227
|
+
const color = document.createElement("input");
|
|
228
|
+
color.type = "color";
|
|
229
|
+
color.id = label.htmlFor;
|
|
230
|
+
color.className = "wide";
|
|
231
|
+
color.addEventListener("input", () => change(color.value));
|
|
232
|
+
field.append(color);
|
|
233
|
+
read = (settingValue) => (color.value = settingValue);
|
|
234
|
+
} else {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
fields.set(listed.name, { field, read, statedName: listed.statedName });
|
|
238
|
+
return field;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function syncField(name) {
|
|
242
|
+
const entry = fields.get(name);
|
|
243
|
+
if (!entry) return;
|
|
244
|
+
const settingValue = settings.get(name);
|
|
245
|
+
entry.read(settingValue);
|
|
246
|
+
entry.field.classList.toggle("is-changed", LOOK_SETTING_NAMES.includes(entry.statedName) && settingValue !== lookBaseValues()[entry.statedName]);
|
|
247
|
+
}
|
|
248
|
+
const syncFields = () => {
|
|
249
|
+
for (const name of fields.keys()) syncField(name);
|
|
250
|
+
};
|
|
251
|
+
// What each look setting is in the look in use, before any tuning: a dot marks the ones tuned away from it.
|
|
252
|
+
let baseCache = { key: null, values: null };
|
|
253
|
+
function lookBaseValues() {
|
|
254
|
+
if (baseCache.key !== lookInUse) {
|
|
255
|
+
const listed = settings.list();
|
|
256
|
+
const values = Object.fromEntries(listed.map((setting) => [setting.statedName, setting.defaultValue]));
|
|
257
|
+
const saved = savedLooks.find((entry) => entry.look?.name === lookInUse)?.look;
|
|
258
|
+
const chain = [];
|
|
259
|
+
for (let look = LOOKS[lookInUse] ?? saved; look; look = look.extends ? LOOKS[look.extends] : null) chain.unshift(look);
|
|
260
|
+
for (const look of chain) Object.assign(values, look.settings);
|
|
261
|
+
baseCache = { key: lookInUse, values };
|
|
262
|
+
}
|
|
263
|
+
return baseCache.values;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function drawPanel() {
|
|
267
|
+
const listed = new Map(settings.list().map((setting) => [setting.statedName, setting]));
|
|
268
|
+
const grouped = new Set(GROUPS.flatMap(([, names]) => names));
|
|
269
|
+
const more = [...listed.keys()].filter((name) => !grouped.has(name) && !OUTSIDE_PANEL.includes(name));
|
|
270
|
+
for (const [title, names] of [...GROUPS, ["More", more]]) {
|
|
271
|
+
const made = names.map((name) => listed.get(name)).filter(Boolean).map(makeField).filter(Boolean);
|
|
272
|
+
if (made.length === 0) continue;
|
|
273
|
+
const details = document.createElement("details");
|
|
274
|
+
details.open = title === "Shading" || title === "Light and shadow";
|
|
275
|
+
const summary = document.createElement("summary");
|
|
276
|
+
summary.textContent = title;
|
|
277
|
+
details.append(summary, ...made);
|
|
278
|
+
tune.append(details);
|
|
279
|
+
}
|
|
280
|
+
syncFields();
|
|
281
|
+
}
|
|
282
|
+
drawPanel();
|
|
283
|
+
settings.onChange((change) => {
|
|
284
|
+
syncField(change.name);
|
|
285
|
+
if (change.name === "timeOfDayHours") showTime();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
byId("filter").addEventListener("input", (event) => {
|
|
289
|
+
const wanted = event.target.value.trim().toLowerCase();
|
|
290
|
+
for (const details of tune.querySelectorAll("details")) {
|
|
291
|
+
let shownCount = 0;
|
|
292
|
+
for (const field of details.querySelectorAll(".field")) {
|
|
293
|
+
field.hidden = wanted !== "" && !field.dataset.search.includes(wanted);
|
|
294
|
+
if (!field.hidden) shownCount += 1;
|
|
295
|
+
}
|
|
296
|
+
details.hidden = shownCount === 0;
|
|
297
|
+
if (wanted !== "") details.open = true;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// ---- Saving a look ----
|
|
302
|
+
const saveState = byId("save-state");
|
|
303
|
+
const lookName = byId("look-name");
|
|
304
|
+
const tell = (message, isProblem = false) => {
|
|
305
|
+
saveState.textContent = message;
|
|
306
|
+
saveState.classList.toggle("is-problem", isProblem);
|
|
307
|
+
};
|
|
308
|
+
byId("save-look").addEventListener("click", async () => {
|
|
309
|
+
const name = lookName.value.trim();
|
|
310
|
+
try {
|
|
311
|
+
const title = name.split("_").map((word) => (word ? word[0].toUpperCase() + word.slice(1) : word)).join(" ");
|
|
312
|
+
const look = lighting.lookFile({ name, title, summary: "" });
|
|
313
|
+
const answer = await fetch(`/api/looks/${encodeURIComponent(name)}.json`, { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify(look, null, 2) });
|
|
314
|
+
const savedAnswer = await answer.json().catch(() => ({}));
|
|
315
|
+
if (!answer.ok) return tell(savedAnswer.error?.message ?? "The look couldn't be saved.", true);
|
|
316
|
+
tell(`Saved ${savedAnswer.file_name ?? `${name}.json`}`);
|
|
317
|
+
lookInUse = name;
|
|
318
|
+
await loadSavedLooks();
|
|
319
|
+
} catch (error) {
|
|
320
|
+
tell(error.message, true);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
byId("reset-look").addEventListener("click", () => {
|
|
324
|
+
const saved = savedLooks.find((entry) => entry.look?.name === lookInUse)?.look;
|
|
325
|
+
lighting.setLook(saved ?? lookInUse);
|
|
326
|
+
syncFields();
|
|
327
|
+
tell("");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// ---- The meter ----
|
|
331
|
+
const qualitySelect = byId("quality");
|
|
332
|
+
for (const level of ["auto", "low", "medium", "high"]) qualitySelect.add(new Option(`Quality: ${level}`, level));
|
|
333
|
+
qualitySelect.value = settings.get("qualityLevel");
|
|
334
|
+
qualitySelect.addEventListener("change", () => settings.set({ qualityLevel: qualitySelect.value }));
|
|
335
|
+
const graphicsButton = byId("graphics");
|
|
336
|
+
graphicsButton.textContent = lighting.graphicsKind === "webgpu" ? "Try WebGL 2" : "Try WebGPU";
|
|
337
|
+
graphicsButton.title = lighting.graphicsKind === "webgpu" ? "Drawn with WebGPU now. Loads the page again drawn with WebGL 2, as on a device without WebGPU." : "Drawn with WebGL 2 now. Loads the page again with WebGPU where this device has it.";
|
|
338
|
+
graphicsButton.addEventListener("click", () => {
|
|
339
|
+
if (lighting.graphicsKind === "webgpu") pageSearch.set("graphics", "webgl2");
|
|
340
|
+
else pageSearch.delete("graphics");
|
|
341
|
+
location.search = `?${pageSearch}`;
|
|
342
|
+
});
|
|
343
|
+
const bakeButton = byId("bake");
|
|
344
|
+
bakeButton.addEventListener("click", async () => {
|
|
345
|
+
bakeButton.disabled = true;
|
|
346
|
+
try {
|
|
347
|
+
const answer = await lighting.bounce.bake({ boundsM: world.boundsM, spacingM: 2, bounceCount: 1 });
|
|
348
|
+
showNotice(`Bounce baked: ${answer.probeCount} probes in ${(answer.bakeDurationMs / 1000).toFixed(1)} s.`);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
showNotice(error.message);
|
|
351
|
+
}
|
|
352
|
+
bakeButton.disabled = false;
|
|
353
|
+
});
|
|
354
|
+
byId("flash").addEventListener("click", () => {
|
|
355
|
+
lighting.lights.flash({ positionM: { x: world.walker.position.x, y: 2.2, z: world.walker.position.z }, color: "#ffd0a0", strengthLux: 900, rangeM: 28, durationSec: 0.7 });
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const tunePane = byId("tune-pane");
|
|
359
|
+
byId("tune-open").addEventListener("click", () => tunePane.classList.add("is-open"));
|
|
360
|
+
byId("tune-close").addEventListener("click", () => tunePane.classList.remove("is-open"));
|
|
361
|
+
|
|
362
|
+
function resize() {
|
|
363
|
+
const widthPx = canvas.clientWidth;
|
|
364
|
+
const heightPx = canvas.clientHeight;
|
|
365
|
+
if (widthPx === 0 || heightPx === 0) return;
|
|
366
|
+
lighting.setSize(widthPx, heightPx);
|
|
367
|
+
camera.aspect = widthPx / heightPx;
|
|
368
|
+
camera.updateProjectionMatrix();
|
|
369
|
+
}
|
|
370
|
+
new ResizeObserver(resize).observe(canvas);
|
|
371
|
+
resize();
|
|
372
|
+
|
|
373
|
+
// What a test or a helper reads to know the page is drawing.
|
|
374
|
+
window.lighting = lighting;
|
|
375
|
+
window.studio = { scene, camera, controls, world, frameCount: 0, errors: [] };
|
|
376
|
+
|
|
377
|
+
const meter = { frames: byId("meter-frames"), ms: byId("meter-ms"), quality: byId("meter-quality"), scale: byId("meter-scale"), lights: byId("meter-lights"), levels: byId("meter-levels") };
|
|
378
|
+
let meterAtMs = 0;
|
|
379
|
+
let meterFrameCount = 0;
|
|
380
|
+
// The page's clock: the browser's, plus what advance stepped on by hand, so time never runs back.
|
|
381
|
+
const clock = { startMs: null, lastMs: 0, steppedMs: 0 };
|
|
382
|
+
function draw(nowMs) {
|
|
383
|
+
clock.startMs ??= nowMs;
|
|
384
|
+
clock.lastMs = nowMs;
|
|
385
|
+
world.update((nowMs - clock.startMs) / 1000);
|
|
386
|
+
controls.update();
|
|
387
|
+
try {
|
|
388
|
+
lighting.render(camera, nowMs);
|
|
389
|
+
window.studio.frameCount += 1;
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (window.studio.errors.length < 5) {
|
|
392
|
+
window.studio.errors.push(String(error.stack ?? error));
|
|
393
|
+
showNotice(error.message);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/** Draws frames by hand, for a still or a page that isn't on screen: so many seconds on, in steps. */
|
|
398
|
+
window.studio.advance = (durationSec, stepSec = 1 / 30) => {
|
|
399
|
+
for (let passedSec = 0; passedSec < durationSec; passedSec += stepSec) {
|
|
400
|
+
clock.steppedMs += stepSec * 1000;
|
|
401
|
+
draw(clock.lastMs + stepSec * 1000);
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
lighting.renderer.setAnimationLoop((browserMs) => {
|
|
405
|
+
const nowMs = browserMs + clock.steppedMs;
|
|
406
|
+
draw(nowMs);
|
|
407
|
+
meterFrameCount += 1;
|
|
408
|
+
if (nowMs - meterAtMs >= 500) {
|
|
409
|
+
meter.frames.textContent = ((meterFrameCount * 1000) / (nowMs - meterAtMs)).toFixed(0);
|
|
410
|
+
meter.ms.textContent = lighting.frameDurationMs.toFixed(1);
|
|
411
|
+
meter.quality.textContent = lighting.qualityLevel;
|
|
412
|
+
meter.scale.textContent = `${lighting.pictureScalePct.toFixed(0)}%`;
|
|
413
|
+
meter.lights.textContent = `${lighting.lights.litCount} of ${lighting.lights.lightCount}`;
|
|
414
|
+
const on = Object.entries(lighting.levels).filter(([, level]) => level !== "off").map(([name, level]) => `${name.replace(/Level$/, "").replace(/([A-Z])/g, " $1").toLowerCase()} ${level}`);
|
|
415
|
+
meter.levels.textContent = on.length > 0 ? on.join(", ") : "";
|
|
416
|
+
meterAtMs = nowMs;
|
|
417
|
+
meterFrameCount = 0;
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
drawLooks();
|
|
422
|
+
loadSavedLooks();
|
|
423
|
+
const changes = new EventSource("/api/changes");
|
|
424
|
+
changes.addEventListener("message", loadSavedLooks);
|
package/style.css
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: dark;
|
|
3
|
+
--ground: #0e1116;
|
|
4
|
+
--pane: #151a21;
|
|
5
|
+
--line: #262d38;
|
|
6
|
+
--text: #e6eaf0;
|
|
7
|
+
--quiet: #8d98a8;
|
|
8
|
+
--accent: #5aa2ff;
|
|
9
|
+
--accent-text: #06121f;
|
|
10
|
+
--field: #1c222b;
|
|
11
|
+
--warn: #ffb454;
|
|
12
|
+
font: 13px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
13
|
+
}
|
|
14
|
+
* { box-sizing: border-box; }
|
|
15
|
+
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ground); color: var(--text); }
|
|
16
|
+
button, input, select { font: inherit; color: inherit; }
|
|
17
|
+
button, select { background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
|
|
18
|
+
button:hover:not(:disabled), select:hover { border-color: #3a4556; }
|
|
19
|
+
button:disabled { opacity: 0.45; cursor: default; }
|
|
20
|
+
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
|
|
21
|
+
button[aria-checked="true"], button[aria-pressed="true"] { background: #24364f; border-color: var(--accent); }
|
|
22
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
|
23
|
+
input[type="search"], input[type="number"], input[type="text"] { background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-width: 0; }
|
|
24
|
+
input[type="range"] { accent-color: var(--accent); min-width: 0; }
|
|
25
|
+
input[type="color"] { width: 100%; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
|
|
26
|
+
|
|
27
|
+
#app { display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: minmax(0, 1fr) auto; height: 100dvh; }
|
|
28
|
+
#stage { position: relative; min-width: 0; min-height: 0; }
|
|
29
|
+
#view { display: block; width: 100%; height: 100%; touch-action: none; }
|
|
30
|
+
#stage-top { position: absolute; left: 0; right: 0; top: 0; display: flex; gap: 8px; align-items: flex-start; justify-content: center; padding: 10px; pointer-events: none; }
|
|
31
|
+
#stage-top > * { pointer-events: auto; }
|
|
32
|
+
#looks { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 6px; border-radius: 12px; background: rgba(14, 17, 22, 0.78); backdrop-filter: blur(10px); border: 1px solid var(--line); }
|
|
33
|
+
#looks button { padding: 5px 10px; }
|
|
34
|
+
#looks button.is-saved { font-style: italic; }
|
|
35
|
+
#stage-bar { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: center; padding: 8px 12px; border-radius: 12px; background: rgba(14, 17, 22, 0.78); backdrop-filter: blur(10px); border: 1px solid var(--line); }
|
|
36
|
+
.bar-group { display: flex; gap: 6px; align-items: center; min-width: 0; }
|
|
37
|
+
.bar-group input[type="range"] { width: 150px; }
|
|
38
|
+
#time-text { min-width: 40px; font-variant-numeric: tabular-nums; }
|
|
39
|
+
.check { display: inline-flex; gap: 5px; align-items: center; white-space: nowrap; }
|
|
40
|
+
#notice { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); max-width: min(520px, calc(100% - 24px)); margin: 0; padding: 8px 12px; border-radius: 10px; background: #33240f; border: 1px solid #6b4a17; color: #ffd9a0; }
|
|
41
|
+
|
|
42
|
+
.pane { background: var(--pane); display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); }
|
|
43
|
+
.pane-head { display: flex; gap: 8px; align-items: center; padding: 10px; border-bottom: 1px solid var(--line); }
|
|
44
|
+
.pane-head input { flex: 1; }
|
|
45
|
+
.sheet-open, .sheet-close { display: none; }
|
|
46
|
+
#tune { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }
|
|
47
|
+
#tune details { border-bottom: 1px solid var(--line); padding: 4px 0; }
|
|
48
|
+
#tune summary { cursor: pointer; padding: 6px 0; font-weight: 600; }
|
|
49
|
+
#tune summary small { font-weight: 400; color: var(--quiet); margin-left: 6px; }
|
|
50
|
+
.field { display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 2px 8px; align-items: center; padding: 3px 0; }
|
|
51
|
+
.field[hidden] { display: none; }
|
|
52
|
+
.field > label { grid-column: 1 / -1; color: var(--quiet); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
53
|
+
.field.is-changed > label { color: var(--text); }
|
|
54
|
+
.field.is-changed > label::after { content: " •"; color: var(--accent); }
|
|
55
|
+
.field > input[type="range"] { width: 100%; }
|
|
56
|
+
.field > input[type="number"] { width: 100%; padding: 3px 6px; }
|
|
57
|
+
.field > select, .field > .wide { grid-column: 1 / -1; }
|
|
58
|
+
#tune-foot { display: flex; gap: 8px; align-items: center; padding: 10px 10px 4px; border-top: 1px solid var(--line); }
|
|
59
|
+
#tune-foot input { flex: 1; }
|
|
60
|
+
#save-state { margin: 0; padding: 0 10px 10px; min-height: 28px; color: var(--quiet); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
61
|
+
#save-state.is-problem { color: var(--warn); white-space: normal; }
|
|
62
|
+
|
|
63
|
+
#meter { grid-column: 1 / -1; display: flex; gap: 6px 18px; flex-wrap: wrap; align-items: center; padding: 6px 12px; border-top: 1px solid var(--line); background: var(--pane); color: var(--quiet); font-variant-numeric: tabular-nums; }
|
|
64
|
+
#meter b { color: var(--text); font-weight: 600; }
|
|
65
|
+
.meter-right { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
|
|
66
|
+
#meter button, #meter select { padding: 3px 8px; }
|
|
67
|
+
|
|
68
|
+
/* A phone: the scene fills the screen, and the sliders are a sheet over it. */
|
|
69
|
+
@media (max-width: 860px) {
|
|
70
|
+
#app { grid-template-columns: minmax(0, 1fr); }
|
|
71
|
+
.pane { position: fixed; inset: auto 0 0 0; height: min(64dvh, 520px); z-index: 5; border: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform 0.18s ease; padding-bottom: env(safe-area-inset-bottom); }
|
|
72
|
+
.pane.is-open { transform: none; }
|
|
73
|
+
.sheet-open, .sheet-close { display: inline-block; }
|
|
74
|
+
#stage-top { flex-direction: column; align-items: stretch; }
|
|
75
|
+
#looks { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
|
76
|
+
#looks button { padding: 6px 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
77
|
+
#tune-open { align-self: flex-end; }
|
|
78
|
+
#stage-bar { gap: 6px 10px; padding: 8px; }
|
|
79
|
+
.bar-group input[type="range"] { width: 96px; }
|
|
80
|
+
#meter { gap: 4px 12px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
|
|
81
|
+
.meter-right { margin-left: 0; }
|
|
82
|
+
}
|
|
83
|
+
@media (prefers-reduced-motion: reduce) { .pane { transition: none; } }
|