Arrange config to enable better live reloading

This commit is contained in:
Tony Garnock-Jones 2023-01-09 16:53:14 +01:00
parent e4be2c0783
commit d005981200
10 changed files with 119 additions and 98 deletions

View File

@ -1,6 +1,13 @@
let ?sceneDs = dataspace let ?sceneDs = dataspace
<require-service <config-watcher "scene" { config: $sceneDs }>> <require-service <config-watcher "scene/boot" { config: $sceneDs }>>
$sceneDs ? <LoadRoomInto ?name ?fileName ?scene> [
<Scene $name $scene>
$config [
<require-service <config-watcher $fileName { config: $scene, lobby: $sceneDs }>>
]
]
? <MainDataspace ?ds> [ ? <MainDataspace ?ds> [
$ds [ $ds [

View File

@ -1,7 +0,0 @@
<Scene "lobby" $config>
<Room "other">
? <Room ?name> [
let ?scene = dataspace
<Scene $name $scene>
]

View File

@ -1,62 +0,0 @@
? <Scene "lobby" ?scene> $scene [
<sprite "light" <hemispheric-light <v 0.1 1.0 0.0>>>
<gravity <v 0.0 -9.81 0.0>>
<sprite "ground"
<texture ["textures/grass-256x256.jpg"
<v 100.0 100.0>
<v 0.0 0.0>]
<floor <ground <v 300.0 300.0>>>>>
<sprite "box"
<move <v -6.0 1.0 8.0>
<scale <v 10.0 0.1 10.0>
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"
<v 10.0 10.0>
<v 0.0 0.0>
0.75]
<floor <box>>>>>>
<sprite "box2"
<move <v -500.0 0.5 3.0>
<floor
<color 0.0 0.0 1.0 1.0
<scale <v 1000.0 1.0 1.0> <box>>>>>>
<sprite "steps"
<color 0.0 0.5 0.0
<move <v 0.0 0.0 3.5>
<scale <v 1.0 1.0 3.0>
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"]
[
<move <v 0.0 0.25 0.0> <box>>
<move <v 1.0 0.0 0.0> <box>>
<move <v 2.0 -0.25 0.0> <box>>
]>>>>>
<Exit "zball" "other">
<sprite "zball"
<move <v 0.0 1.5 30.0>
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"]
<touchable <sphere>>>>>
<sprite "plans"
<texture ["plans/signal-2022-12-27-125451_002.jpeg"]
<move <v 0.0 1.0 -10.0>
<rotate <v 0.5 0.0 0.0>
<scale <v 2.0 2.0 0.1>
<box>>>>>>
<sprite "tower"
<rotate <v 0.6 0.0 0.0>
<move <v -10.0 50.0 13.0>
<scale <v 3.0 100.0 3.0>
<floor
<color 0.5 0.5 0.0
<box>>>>>>>
<sprite "house"
<scale <v 10.0 4.0 15.0>
<floor
<move <v 1.5 0.5 -0.5> <box>>>>>
]

View File

@ -1,12 +0,0 @@
? <Scene "other" ?scene> $scene [
<sprite "light" <hemispheric-light <v 0.1 1.0 0.0>>>
<sprite "ground2"
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"
<v 100.0 100.0>
<v 0.0 0.0>]
<floor <ground <v 300.0 300.0>>>>>
<Exit "home" "lobby" <v 0.0 15.0 4.0>>
<sprite "home" <move <v 0.0 1.5 5.0> <color 1.0 0.0 0.0 <touchable <sphere>>>>>
]

7
scene/boot/00-rooms.pr Normal file
View File

@ -0,0 +1,7 @@
<LoadRoomInto "lobby" "scene/lobby.pr" $config>
<Room "other" "scene/other.pr">
? <Room ?name ?fileName> [
let ?scene = dataspace
<LoadRoomInto $name $fileName $scene>
]

67
scene/lobby.pr Normal file
View File

@ -0,0 +1,67 @@
<sprite "light" <hemispheric-light <v 0.1 1.0 0.0>>>
<gravity <v 0.0 -9.81 0.0>>
<sprite "ground"
<texture ["textures/grass-256x256.jpg"
<v 100.0 100.0>
<v 0.0 0.0>]
<floor <ground <v 300.0 300.0>>>>>
<sprite "box"
<move <v -6.0 1.0 8.0>
<scale <v 10.0 0.1 10.0>
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"
<v 10.0 10.0>
<v 0.0 0.0>
0.75]
<floor <box>>>>>>
<sprite "box2"
<move <v -500.0 0.5 3.0>
<floor
<color 0.0 0.0 1.0 1.0
<scale <v 1000.0 1.0 1.0> <box>>>>>>
<Exit "p" "lobby">
<sprite "p"
<move <v -1000.0 2.0 3.0>
<rotate <v 0.0 -0.25 0.0>
<color 1.0 0.0 1.0
<touchable <scale <v 1.0 2.0 1.0> <plane>>>>>>>
<sprite "steps"
<color 0.0 0.5 0.0
<move <v 0.0 0.0 3.5>
<scale <v 1.0 1.0 3.0>
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"]
[
<move <v 0.0 0.25 0.0> <box>>
<move <v 1.0 0.0 0.0> <box>>
<move <v 2.0 -0.25 0.0> <box>>
]>>>>>
<Exit "zball" "other">
<sprite "zball"
<move <v 0.0 1.5 30.0>
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"]
<touchable <sphere>>>>>
<sprite "plans"
<texture ["plans/signal-2022-12-27-125451_002.jpeg"]
<move <v 0.0 1.0 -10.0>
<rotate <v 0.5 0.0 0.0>
<scale <v 2.0 2.0 0.1>
<box>>>>>>
<sprite "tower"
<rotate <v 0.1 0.0 0.0>
<move <v -10.0 50.0 13.0>
<scale <v 3.0 100.0 3.0>
<floor
<color 0.5 0.5 0.0
<box>>>>>>>
<sprite "house"
<scale <v 10.0 4.0 15.0>
<floor
<move <v 1.5 0.5 -0.5> <box>>>>>

10
scene/other.pr Normal file
View File

@ -0,0 +1,10 @@
<sprite "light" <hemispheric-light <v 0.1 1.0 0.0>>>
<sprite "ground2"
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"
<v 100.0 100.0>
<v 0.0 0.0>]
<floor <ground <v 300.0 300.0>>>>>
<Exit "home" "lobby" <v 0.0 15.0 4.0>>
<sprite "home" <move <v 0.0 1.5 5.0> <color 1.0 0.0 0.0 <touchable <sphere>>>>>

View File

@ -18,7 +18,7 @@ import {
WebXRCamera, WebXRCamera,
} from '@babylonjs/core/Legacy/legacy'; } from '@babylonjs/core/Legacy/legacy';
import { activeFloorMeshes, activeTouchableMeshes, ShapeTree, builder as B } from './shapes.js'; import { activeFloorMeshes, activeTouchableMeshes, ShapeTree, scale3, builder as B } from './shapes.js';
import { RunningEngine } from './engine.js'; import { RunningEngine } from './engine.js';
import { uuid } from './uuid.js'; import { uuid } from './uuid.js';
@ -134,22 +134,28 @@ async function enterScene(
"destination": $dest: SceneProtocol.PortalDestination, "destination": $dest: SceneProtocol.PortalDestination,
"position": $targetPosition: Shapes.Vector3, "position": $targetPosition: Shapes.Vector3,
}) => { }) => {
const newPos = new Vector3(targetPosition.x,
targetPosition.y,
targetPosition.z);
needStop = false; needStop = false;
switch (dest._variant) { switch (dest._variant) {
case "local": case "local":
runningEngine.scene.removeMesh(rootMesh, true); runningEngine.scene.removeMesh(rootMesh, true);
Turn.active.stop(currentSceneFacet, () => { if (dest.value === sceneDs) {
react { // TODO: the test above ^ isn't working right. Are the membranes being maintained correctly?
enterScene(id, camera.position = newPos;
runningEngine, } else {
ds, Turn.active.stop(currentSceneFacet, () => {
dest.value, react {
new Vector3(targetPosition.x, enterScene(id,
targetPosition.y, runningEngine,
targetPosition.z), ds,
email); dest.value,
} newPos,
}); email);
}
});
}
break; break;
default: default:
break; break;
@ -169,9 +175,9 @@ async function enterScene(
shape: B.nonphysical( shape: B.nonphysical(
B.move(position.value, B.many([ B.move(position.value, B.many([
B.move({ x: 0, y: -0.9, z: 0 }, B.move({ x: 0, y: -0.9, z: 0 },
B.rotate({ x: 0, y: rotation.value.y, z: 0 }, B.rotate(scale3({ x: 0, y: rotation.value.y, z: 0 }, 1 / (2 * Math.PI)),
B.scale({ x: 0.4, y: 1.4, z: 0.1 }, B.box()))), B.scale({ x: 0.4, y: 1.4, z: 0.1 }, B.box()))),
B.rotate(rotation.value, B.rotate(scale3(rotation.value, 1 / (2 * Math.PI)),
B.scale({ x: 0.15, y: 0.23, z: 0.18 }, B.many([ B.scale({ x: 0.15, y: 0.23, z: 0.18 }, B.many([
B.box(), B.box(),
B.move({ x: 0, y: 0, z: 0.501 }, B.move({ x: 0, y: 0, z: 0.501 },
@ -182,7 +188,7 @@ async function enterScene(
offset: Shapes.Vector2({ x:0, y:0 }), offset: Shapes.Vector2({ x:0, y:0 }),
alpha: 1 alpha: 1
}), }),
B.rotate({ x: 0, y: Math.PI, z: 0 }, B.rotate({ x: 0, y: 0.5, z: 0 },
B.plane()))), B.plane()))),
]))), ]))),
]))), ]))),

View File

@ -112,6 +112,10 @@ export function v3(v: Shapes.Vector3): Vector3 {
return new Vector3(v.x, v.y, v.z); return new Vector3(v.x, v.y, v.z);
} }
export function scale3(v: Shapes.Vector3, scale: number): Shapes.Vector3 {
return Shapes.Vector3({ x: v.x * scale, y: v.y * scale, z: v.z * scale });
}
export function q(q: Shapes.Quaternion): Quaternion { export function q(q: Shapes.Quaternion): Quaternion {
return new Quaternion(q.a, q.b, q.c, q.d); return new Quaternion(q.a, q.b, q.c, q.d);
} }
@ -227,6 +231,7 @@ export function build(name: string, scene: Scene, shape: Shapes.Shape, customize
switch (shape.value._variant) { switch (shape.value._variant) {
case "euler": case "euler":
t.node.rotation = v3(shape.value.v); t.node.rotation = v3(shape.value.v);
t.node.rotation.scaleInPlace(2 * Math.PI);
break; break;
case "quaternion": case "quaternion":
t.node.rotationQuaternion = q(shape.value.q); t.node.rotationQuaternion = q(shape.value.q);