@a2f0/skyline 0.2.20 → 0.2.23
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/docs/package.md +10 -0
- package/lib/models/colour-materials.d.ts +8 -1
- package/lib/models/colour-materials.js +38 -7
- package/lib/models/colour-palette.d.ts +32 -0
- package/lib/models/colour-palette.js +11 -0
- package/lib/models/colour-reflections.d.ts +13 -1
- package/lib/models/colour-reflections.js +69 -10
- package/lib/models/night-windows.d.ts +13 -0
- package/lib/models/night-windows.js +76 -0
- package/lib/skyline-package.d.ts +3 -1
- package/lib/skyline-package.js +2 -2
- package/lib/skyline-shell.d.ts +4 -1
- package/lib/skyline-shell.js +10 -2
- package/lib/study-types.d.ts +2 -0
- package/package.json +1 -1
- package/site/building-detail.js +30 -7
- package/site/index.html +14 -1
- package/site/models/colour-materials.js +38 -7
- package/site/models/colour-palette.js +11 -0
- package/site/models/colour-reflections.js +69 -10
- package/site/models/night-windows.js +76 -0
- package/site/skyline-3d.html +6 -0
- package/site/skyline-3d.js +50 -13
- package/site/skyline-shell.js +10 -2
- package/site/skyline-viewer.js +4 -2
- package/site/solar-time.js +53 -0
- package/site/study-loader.js +1 -1
- package/site/study-viewer.js +27 -0
- package/site/study.css +14 -2
- package/site/time-of-day.js +56 -0
- package/site/viewer-page.js +2 -0
- package/site/viewer.css +13 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as THREE from "./vendor/three-r186.js";
|
|
2
|
+
import { daylightGround, daylightIntensities } from "./models/colour-materials.js";
|
|
3
|
+
import { nightColours, timeOfDayColours } from "./models/colour-palette.js";
|
|
4
|
+
import { smooth, windowActivity } from "./models/night-windows.js";
|
|
5
|
+
import { chicagoHour, solarPosition } from "./solar-time.js";
|
|
6
|
+
// One tiny texture per viewer, updated in place while dragging and disposed at teardown.
|
|
7
|
+
// Transparent night sky reveals the viewer's existing stars behind opaque buildings.
|
|
8
|
+
export function createTimeLighting(latitude, longitude, transparentNight) {
|
|
9
|
+
const rows = 256, data = new Uint8Array(rows * 4);
|
|
10
|
+
const sky = new THREE.DataTexture(data, 1, rows);
|
|
11
|
+
sky.colorSpace = "srgb";
|
|
12
|
+
const a = new THREE.Color(), b = new THREE.Color(), pixel = new THREE.Color();
|
|
13
|
+
function blend(from, to, amount, coloured) {
|
|
14
|
+
a.setHex(from).lerp(b.setHex(to), amount);
|
|
15
|
+
if (!coloured) {
|
|
16
|
+
const grey = a.r * 0.2126 + a.g * 0.7152 + a.b * 0.0722;
|
|
17
|
+
a.setRGB(grey, grey, grey);
|
|
18
|
+
}
|
|
19
|
+
return a.getHex();
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
sky,
|
|
23
|
+
update(date, coloured) {
|
|
24
|
+
const { elevation, direction } = solarPosition(date, latitude, longitude);
|
|
25
|
+
const upper = timeOfDayColours.findIndex((stop) => stop.elevation > elevation);
|
|
26
|
+
const last = timeOfDayColours.length - 1;
|
|
27
|
+
const low = timeOfDayColours[upper < 0 ? last : Math.max(0, upper - 1)];
|
|
28
|
+
const high = timeOfDayColours[upper < 0 ? last : upper];
|
|
29
|
+
const amount = high === low ? 0 : smooth(low.elevation, high.elevation, elevation);
|
|
30
|
+
const top = blend(low.sky, high.sky, amount, coloured);
|
|
31
|
+
const horizon = blend(low.horizon, high.horizon, amount, coloured);
|
|
32
|
+
const sun = blend(low.sun, high.sun, amount, coloured);
|
|
33
|
+
const day = smooth(-6, 18, elevation);
|
|
34
|
+
const opacity = transparentNight ? smooth(-18, -2, elevation) : 1;
|
|
35
|
+
const topColour = new THREE.Color(top), bottomColour = new THREE.Color(horizon);
|
|
36
|
+
for (let row = 0; row < rows; row += 1) {
|
|
37
|
+
const hex = pixel.copy(bottomColour).lerp(topColour, row / (rows - 1)).getHex();
|
|
38
|
+
// The canvas is composited with premultiplied alpha. Background textures write
|
|
39
|
+
// directly to it, so premultiply the final sRGB channels here as well.
|
|
40
|
+
data.set([Math.round(((hex >> 16) & 255) * opacity), Math.round(((hex >> 8) & 255) * opacity), Math.round((hex & 255) * opacity), Math.round(255 * opacity)], row * 4);
|
|
41
|
+
}
|
|
42
|
+
sky.needsUpdate = true;
|
|
43
|
+
const ground = blend(0x161616, daylightGround.blocks, day, false);
|
|
44
|
+
return {
|
|
45
|
+
sky, direction, ground,
|
|
46
|
+
roads: blend(0x2c2c2c, daylightGround.roads, day, false),
|
|
47
|
+
sun: [sun, daylightIntensities.sun * smooth(-0.833, 8, elevation)],
|
|
48
|
+
ambient: [blend(nightColours.ambient, top, day, coloured), 0.16 + day * (daylightIntensities.ambient - 0.16)],
|
|
49
|
+
fill: [blend(nightColours.fill, horizon, day, coloured), 0.08 + day * (daylightIntensities.fill - 0.08)],
|
|
50
|
+
reflections: { sky: top, horizon, ground: blend(0x080808, 0x444444, day, false) },
|
|
51
|
+
night: { darkness: 1 - smooth(-6, 3, elevation), activity: windowActivity(chicagoHour(date)), outlineStrength: 0.05 + 0.95 * day },
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
dispose() { sky.dispose(); },
|
|
55
|
+
};
|
|
56
|
+
}
|
package/site/viewer-page.js
CHANGED
|
@@ -6,6 +6,7 @@ import { mountViewer } from "./skyline-shell.js";
|
|
|
6
6
|
// bar open or folded; and `?attribution=hidden` leaves out the OpenStreetMap credit. The site
|
|
7
7
|
// starts the bar open, to show what the scene can do; embedded, it starts folded behind its
|
|
8
8
|
// star, as `mountSkyline` does.
|
|
9
|
+
// `?colour=1` starts in daylight; `?theme=light` or `?theme=dark` overrides the boot palette.
|
|
9
10
|
const settings = new URLSearchParams(location.search);
|
|
10
11
|
const embedded = settings.get("embed") === "1";
|
|
11
12
|
const controls = settings.get("controls");
|
|
@@ -15,6 +16,7 @@ mountViewer(document.querySelector("#viewer"), {
|
|
|
15
16
|
controls: controls === "open" || controls === "closed" ? controls : embedded ? "closed" : "open",
|
|
16
17
|
attribution: settings.get("attribution") !== "hidden",
|
|
17
18
|
colour: settings.get("colour") === "1",
|
|
19
|
+
theme: document.documentElement.dataset["theme"] === "light" ? "light" : "dark",
|
|
18
20
|
navigation: !embedded,
|
|
19
21
|
page: true,
|
|
20
22
|
});
|
package/site/viewer.css
CHANGED
|
@@ -35,6 +35,19 @@
|
|
|
35
35
|
pointer-events: none;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/* Keep this boot palette in sync with skyline-shell.ts and index.html. It gives
|
|
39
|
+
way to the scene's own sky at the first frame. The original drawing always
|
|
40
|
+
keeps its dark sky, including when opened during loading or after a failure. */
|
|
41
|
+
.skyline-viewer[data-theme="light"][data-booting] { color-scheme: light; background: #f5f5f5; color: #444; }
|
|
42
|
+
.skyline-viewer[data-theme="light"][data-booting] > .stars { visibility: hidden; }
|
|
43
|
+
.skyline-viewer[data-theme="light"][data-booting] .loading { color: #444; }
|
|
44
|
+
.skyline-viewer[data-theme="light"][data-booting] .skyline-trace { stroke: #555; }
|
|
45
|
+
.skyline-viewer[data-theme="light"][data-booting] .skyline-trace-tip { stroke: #222; filter: drop-shadow(0 0 9px #22222266); }
|
|
46
|
+
.skyline-viewer[data-theme="light"][data-booting] .controls { color: #444; }
|
|
47
|
+
.skyline-viewer[data-theme="light"][data-booting] .motion-status { color: #555; }
|
|
48
|
+
.skyline-viewer[data-theme="light"][data-booting] .controls :is(button, a):is(:hover, :focus-visible, [aria-pressed="true"]) { color: #111; }
|
|
49
|
+
.skyline-viewer[data-theme="light"][data-booting] .controls :focus-visible { outline-color: #111; }
|
|
50
|
+
|
|
38
51
|
.stars svg {
|
|
39
52
|
display: block;
|
|
40
53
|
width: 100%;
|