From d0059812006b8420079f08b112d89488fca02559 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 9 Jan 2023 16:53:14 +0100 Subject: [PATCH] Arrange config to enable better live reloading --- config/scene.pr | 9 +++- scene/00-rooms.pr | 7 --- scene/10-lobby.pr | 62 -------------------------- scene/10-other.pr | 12 ------ scene/boot/00-rooms.pr | 7 +++ scene/{ => boot}/05-common-scene.pr | 0 scene/lobby.pr | 67 +++++++++++++++++++++++++++++ scene/other.pr | 10 +++++ src/index.ts | 38 +++++++++------- src/shapes.ts | 5 +++ 10 files changed, 119 insertions(+), 98 deletions(-) delete mode 100644 scene/00-rooms.pr delete mode 100644 scene/10-lobby.pr delete mode 100644 scene/10-other.pr create mode 100644 scene/boot/00-rooms.pr rename scene/{ => boot}/05-common-scene.pr (100%) create mode 100644 scene/lobby.pr create mode 100644 scene/other.pr diff --git a/config/scene.pr b/config/scene.pr index 91140cb..e2d4871 100644 --- a/config/scene.pr +++ b/config/scene.pr @@ -1,6 +1,13 @@ let ?sceneDs = dataspace -> +> + +$sceneDs ? [ + + $config [ + > + ] +] ? [ $ds [ diff --git a/scene/00-rooms.pr b/scene/00-rooms.pr deleted file mode 100644 index 38579aa..0000000 --- a/scene/00-rooms.pr +++ /dev/null @@ -1,7 +0,0 @@ - - - -? [ - let ?scene = dataspace - -] diff --git a/scene/10-lobby.pr b/scene/10-lobby.pr deleted file mode 100644 index b58a1e5..0000000 --- a/scene/10-lobby.pr +++ /dev/null @@ -1,62 +0,0 @@ -? $scene [ - >> - > - - - ] - >>>> - - - - - - 0.75] - >>>>> - - - >>>>> - - - - > - > - > - ]>>>>> - - - - >>>> - - - - - >>>>> - - - - - >>>>>> - - - >>>> -] diff --git a/scene/10-other.pr b/scene/10-other.pr deleted file mode 100644 index 44cda20..0000000 --- a/scene/10-other.pr +++ /dev/null @@ -1,12 +0,0 @@ -? $scene [ - >> - - - ] - >>>> - - > - >>>> -] diff --git a/scene/boot/00-rooms.pr b/scene/boot/00-rooms.pr new file mode 100644 index 0000000..4a8adf9 --- /dev/null +++ b/scene/boot/00-rooms.pr @@ -0,0 +1,7 @@ + + + +? [ + let ?scene = dataspace + +] diff --git a/scene/05-common-scene.pr b/scene/boot/05-common-scene.pr similarity index 100% rename from scene/05-common-scene.pr rename to scene/boot/05-common-scene.pr diff --git a/scene/lobby.pr b/scene/lobby.pr new file mode 100644 index 0000000..3808292 --- /dev/null +++ b/scene/lobby.pr @@ -0,0 +1,67 @@ +>> +> + + + ] + >>>> + + + + + + 0.75] + >>>>> + + + >>>>> + + + + + >>>>>> + + + + > + > + > + ]>>>>> + + + + >>>> + + + + + >>>>> + + + + + >>>>>> + + + >>>> diff --git a/scene/other.pr b/scene/other.pr new file mode 100644 index 0000000..ad95286 --- /dev/null +++ b/scene/other.pr @@ -0,0 +1,10 @@ +>> + + + ] + >>>> + +> + >>>> diff --git a/src/index.ts b/src/index.ts index 21c10df..afa0ba9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,7 @@ import { WebXRCamera, } 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 { uuid } from './uuid.js'; @@ -134,22 +134,28 @@ async function enterScene( "destination": $dest: SceneProtocol.PortalDestination, "position": $targetPosition: Shapes.Vector3, }) => { + const newPos = new Vector3(targetPosition.x, + targetPosition.y, + targetPosition.z); needStop = false; switch (dest._variant) { case "local": runningEngine.scene.removeMesh(rootMesh, true); - Turn.active.stop(currentSceneFacet, () => { - react { - enterScene(id, - runningEngine, - ds, - dest.value, - new Vector3(targetPosition.x, - targetPosition.y, - targetPosition.z), - email); - } - }); + if (dest.value === sceneDs) { + // TODO: the test above ^ isn't working right. Are the membranes being maintained correctly? + camera.position = newPos; + } else { + Turn.active.stop(currentSceneFacet, () => { + react { + enterScene(id, + runningEngine, + ds, + dest.value, + newPos, + email); + } + }); + } break; default: break; @@ -169,9 +175,9 @@ async function enterScene( shape: B.nonphysical( B.move(position.value, B.many([ 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.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.box(), B.move({ x: 0, y: 0, z: 0.501 }, @@ -182,7 +188,7 @@ async function enterScene( offset: Shapes.Vector2({ x:0, y:0 }), alpha: 1 }), - B.rotate({ x: 0, y: Math.PI, z: 0 }, + B.rotate({ x: 0, y: 0.5, z: 0 }, B.plane()))), ]))), ]))), diff --git a/src/shapes.ts b/src/shapes.ts index ca4ed1e..bd22874 100644 --- a/src/shapes.ts +++ b/src/shapes.ts @@ -112,6 +112,10 @@ export function v3(v: Shapes.Vector3): Vector3 { 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 { 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) { case "euler": t.node.rotation = v3(shape.value.v); + t.node.rotation.scaleInPlace(2 * Math.PI); break; case "quaternion": t.node.rotationQuaternion = q(shape.value.q);