192 lines
7.8 KiB
TypeScript
192 lines
7.8 KiB
TypeScript
import { Dataspace, Embedded, Reader, Ref, Schemas, Sturdy } from "@syndicate-lang/core";
|
|
import * as html from "@syndicate-lang/html";
|
|
import * as wsRelay from "@syndicate-lang/ws-relay";
|
|
import * as wakeDetector from './wake-detector.js';
|
|
|
|
import {
|
|
Engine,
|
|
HemisphericLight,
|
|
Mesh,
|
|
MeshBuilder,
|
|
Scene,
|
|
Vector3,
|
|
} from '@babylonjs/core/Legacy/legacy';
|
|
|
|
import { box, PhotoSemiDome } from './shapes.js';
|
|
import { DEFAULT_THICKNESS, room } from './interiors.js';
|
|
import { startEngine } from './engine.js';
|
|
import { uuid } from './uuid.js';
|
|
|
|
async function createScene(_canvas: HTMLCanvasElement, engine: Engine): Promise<{
|
|
scene: Scene,
|
|
floorMeshes: Mesh[]
|
|
}> {
|
|
const scene = new Scene(engine);
|
|
|
|
new HemisphericLight("light", new Vector3(0, 1, 0), scene);
|
|
|
|
const streetDome = new PhotoSemiDome("street", "papenweg-textures/individual/street-panorama.jpg", {
|
|
halfDomeMode: true,
|
|
size: 10,
|
|
}, scene);
|
|
streetDome.position.z = (3.80 / 2) - 0.4;
|
|
streetDome.position.y = 0.4;
|
|
|
|
const gardenDome = new PhotoSemiDome("garden", "papenweg-textures/individual/garden-panorama.jpg", {
|
|
halfDomeMode: true,
|
|
size: 10,
|
|
}, scene);
|
|
gardenDome.position.z = -4.06 - (3.80 / 2) - 1.2;
|
|
gardenDome.position.y = 1.2;
|
|
gardenDome.rotation.y = Math.PI;
|
|
|
|
const sittingroom = await room(
|
|
"sittingroom", 3.80, 4.06, scene,
|
|
"papenweg-textures/individual/floor1.jpg",
|
|
"papenweg-textures/individual/wallpaper1.jpg",
|
|
{
|
|
texture: "papenweg-textures/individual/sittingroom_0_window.jpg",
|
|
thickness: DEFAULT_THICKNESS / 2,
|
|
holes: [
|
|
box("w0b", 0.55, 1.25, DEFAULT_THICKNESS, -0.4, 1.55),
|
|
box("w0c", 0.55, 1.25, DEFAULT_THICKNESS, 0.3, 1.55),
|
|
box("w0d", 0.55, 1.25, DEFAULT_THICKNESS, 1.0, 1.55),
|
|
box("w0a", 0.55, 1.25, DEFAULT_THICKNESS, -1.1, 1.55),
|
|
]
|
|
},
|
|
{
|
|
texture: "papenweg-textures/individual/sittingroom_1_tvwall.jpg",
|
|
holes: []
|
|
},
|
|
{
|
|
texture: "papenweg-textures/individual/sittingroom_2_doors.jpg",
|
|
thickness: DEFAULT_THICKNESS / 2,
|
|
holes: [
|
|
box("w2a", 0.6, 1.99, DEFAULT_THICKNESS, 0.2),
|
|
box("ww1", 0.28, 0.28, DEFAULT_THICKNESS, -0.64, 1.7),
|
|
box("ww2", 0.28, 0.28, DEFAULT_THICKNESS, -0.64, 1.4),
|
|
box("ww3", 0.28, 0.28, DEFAULT_THICKNESS, -0.64, 1.1),
|
|
box("ww4", 0.28, 0.28, DEFAULT_THICKNESS, -0.64, 0.8),
|
|
box("ww5", 0.28, 0.28, DEFAULT_THICKNESS, -0.34, 1.7),
|
|
box("ww6", 0.28, 0.28, DEFAULT_THICKNESS, -0.34, 1.4),
|
|
box("ww7", 0.28, 0.28, DEFAULT_THICKNESS, -0.34, 1.1),
|
|
box("ww8", 0.28, 0.28, DEFAULT_THICKNESS, -0.34, 0.8),
|
|
box("ww9", 0.20, 0.28, DEFAULT_THICKNESS, 0.74, 1.7),
|
|
box("wwA", 0.20, 0.28, DEFAULT_THICKNESS, 0.74, 1.4),
|
|
box("wwB", 0.20, 0.28, DEFAULT_THICKNESS, 0.74, 1.1),
|
|
box("wwC", 0.20, 0.28, DEFAULT_THICKNESS, 0.74, 0.8),
|
|
]
|
|
},
|
|
{
|
|
texture: "papenweg-textures/individual/sittingroom_3_sofawall.jpg",
|
|
holes: [
|
|
box("w3a", 0.83, 2.08, DEFAULT_THICKNESS, -1.33),
|
|
]
|
|
});
|
|
|
|
const diningroom = await room(
|
|
"diningroom", 3.80, 4.06, scene,
|
|
"papenweg-textures/individual/floor1.jpg",
|
|
"papenweg-textures/individual/wallpaper1.jpg",
|
|
{
|
|
texture: "papenweg-textures/individual/diningroom_0_doors.jpg",
|
|
thickness: DEFAULT_THICKNESS / 2,
|
|
holes: [
|
|
box("dw2a", 0.6, 1.99, DEFAULT_THICKNESS, -0.2),
|
|
box("dww1", 0.28, 0.28, DEFAULT_THICKNESS, 0.64, 1.7),
|
|
box("dww2", 0.28, 0.28, DEFAULT_THICKNESS, 0.64, 1.4),
|
|
box("dww3", 0.28, 0.28, DEFAULT_THICKNESS, 0.64, 1.1),
|
|
box("dww4", 0.28, 0.28, DEFAULT_THICKNESS, 0.64, 0.8),
|
|
box("dww5", 0.28, 0.28, DEFAULT_THICKNESS, 0.34, 1.7),
|
|
box("dww6", 0.28, 0.28, DEFAULT_THICKNESS, 0.34, 1.4),
|
|
box("dww7", 0.28, 0.28, DEFAULT_THICKNESS, 0.34, 1.1),
|
|
box("dww8", 0.28, 0.28, DEFAULT_THICKNESS, 0.34, 0.8),
|
|
box("dww9", 0.20, 0.28, DEFAULT_THICKNESS, -0.74, 1.7),
|
|
box("dwwA", 0.20, 0.28, DEFAULT_THICKNESS, -0.74, 1.4),
|
|
box("dwwB", 0.20, 0.28, DEFAULT_THICKNESS, -0.74, 1.1),
|
|
box("dwwC", 0.20, 0.28, DEFAULT_THICKNESS, -0.74, 0.8),
|
|
]
|
|
},
|
|
{
|
|
texture: "papenweg-textures/individual/diningroom_1_fireplace.jpg",
|
|
holes: []
|
|
},
|
|
{
|
|
texture: "papenweg-textures/individual/diningroom_2_window.jpg",
|
|
thickness: DEFAULT_THICKNESS / 2,
|
|
holes: (() => {
|
|
const bc = (name: string, left: number, top: number, bw: number, bh: number) => [
|
|
box(name + "1", bw, bh, DEFAULT_THICKNESS, left + (0 * (bw + 0.02)), top - (0 * (bh + 0.02))),
|
|
box(name + "2", bw, bh, DEFAULT_THICKNESS, left + (0 * (bw + 0.02)), top - (1 * (bh + 0.02))),
|
|
box(name + "3", bw, bh, DEFAULT_THICKNESS, left + (0 * (bw + 0.02)), top - (2 * (bh + 0.02))),
|
|
box(name + "4", bw, bh, DEFAULT_THICKNESS, left + (0 * (bw + 0.02)), top - (3 * (bh + 0.02))),
|
|
box(name + "5", bw, bh, DEFAULT_THICKNESS, left + (1 * (bw + 0.02)), top - (0 * (bh + 0.02))),
|
|
box(name + "6", bw, bh, DEFAULT_THICKNESS, left + (1 * (bw + 0.02)), top - (1 * (bh + 0.02))),
|
|
box(name + "7", bw, bh, DEFAULT_THICKNESS, left + (1 * (bw + 0.02)), top - (2 * (bh + 0.02))),
|
|
box(name + "8", bw, bh, DEFAULT_THICKNESS, left + (1 * (bw + 0.02)), top - (3 * (bh + 0.02))),
|
|
];
|
|
return [
|
|
... bc("dwA", -0.84, 1.69, 0.25, 0.29),
|
|
... bc("dwB", -0.09, 1.69, 0.25, 0.29),
|
|
... bc("dwC", 0.57, 1.69, 0.24, 0.28),
|
|
... bc("dwD", -1.47, 1.69, 0.24, 0.28),
|
|
];
|
|
})(),
|
|
},
|
|
{
|
|
texture: "papenweg-textures/individual/diningroom_3_heater.jpg",
|
|
holes: [
|
|
box("w3a", 0.83, 2.01, DEFAULT_THICKNESS, 1.46),
|
|
]
|
|
});
|
|
diningroom.position.z = -(4.06 + DEFAULT_THICKNESS);
|
|
|
|
return {
|
|
scene,
|
|
floorMeshes: [
|
|
sittingroom,
|
|
diningroom,
|
|
MeshBuilder.CreateGround("ground", {width:30, height:30}),
|
|
],
|
|
};
|
|
}
|
|
|
|
function wsurl(): string {
|
|
const scheme = (document.location.protocol.toLowerCase() === 'https:') ? 'wss' : 'ws';
|
|
return `${scheme}://${document.location.host}/ws`;
|
|
}
|
|
|
|
function bootApp(ds: Ref) {
|
|
spawn named 'app' {
|
|
at ds {
|
|
const url = wsurl();
|
|
const serverCap = Sturdy.asSturdyRef(new Reader<Ref>(
|
|
'<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>').next());
|
|
const this_instance = uuid();
|
|
const relayAddr = wsRelay.RelayAddress(Schemas.transportAddress.WebSocket(url));
|
|
|
|
during wsRelay.Resolved({
|
|
"addr": relayAddr,
|
|
"sturdyref": serverCap,
|
|
"resolved": $remoteDs_e: Embedded,
|
|
}) => {
|
|
const remoteDs = remoteDs_e.embeddedValue;
|
|
|
|
on message wakeDetector.WakeEvent() => {
|
|
send message wsRelay.ForceRelayDisconnect(relayAddr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
window.addEventListener('load', async () => {
|
|
await startEngine(createScene);
|
|
Dataspace.boot(ds => {
|
|
html.boot(ds);
|
|
wsRelay.boot(ds, true);
|
|
wakeDetector.boot(ds);
|
|
bootApp(ds);
|
|
});
|
|
});
|