diff --git a/src/app.ts b/src/app.ts index 2eb4692..fc6e39d 100644 --- a/src/app.ts +++ b/src/app.ts @@ -60,12 +60,14 @@ class App { const xr = await WebXRDefaultExperience.CreateAsync(scene, { floorMeshes: [this.createGround(scene)], + disableTeleportation: true, optionalFeatures: true + }); const rig = new Rigplatform(scene, xr); //const ring = new Cameras(scene, this.token); //ring.getCameras().then(() => ring.createCameras()); - xr.teleportation.detach(); + //xr.teleportation.detach(); // hide/show the Inspector window.addEventListener("keydown", (ev) => { @@ -81,6 +83,7 @@ class App { engine.runRenderLoop(() => { scene.render(); + }); } @@ -103,3 +106,4 @@ class App { const app = new App(); + diff --git a/src/controllers/rigplatform.ts b/src/controllers/rigplatform.ts index a6f9b55..c918ed8 100644 --- a/src/controllers/rigplatform.ts +++ b/src/controllers/rigplatform.ts @@ -1,4 +1,5 @@ import { + Angle, Camera, Color3, Mesh, @@ -8,7 +9,7 @@ import { PhysicsMotionType, PhysicsShapeType, Quaternion, - Scene, + Scene, Space, StandardMaterial, Vector3, WebXRDefaultExperience @@ -22,6 +23,7 @@ export class Rigplatform { static ANGULAR_VELOCITY = 3; static x90 = Quaternion.RotationAxis(Vector3.Up(), 1.5708); public bMenu: Bmenu; + private yRotation: number = 0; public right: Right; public left: Left; public body: PhysicsBody; @@ -57,6 +59,7 @@ export class Rigplatform { scene); rigAggregate.body.setMotionType(PhysicsMotionType.ANIMATED); rigAggregate.body.setGravityFactor(0); + this.#fixRotation(); this.body = rigAggregate.body; this.#setupKeyboard(); @@ -100,12 +103,15 @@ export class Rigplatform { const snap = true; if (snap) { if (!this.turning) { - this.turning = true; - const q = this.rigMesh.rotation.y += Math.abs(val) * 22.5; + if (Math.abs(val) > .1) { + this.turning = true; + this.yRotation += Angle.FromDegrees(Math.sign(val) * 22.5).radians(); + } } else { - if (val < .1) { + if (Math.abs(val) < .1) { this.turning = false; + } } } else { @@ -192,6 +198,7 @@ export class Rigplatform { this.scene.registerBeforeRender(() => { const q = this.rigMesh.rotationQuaternion; const e = q.toEulerAngles(); + e.y += this.yRotation; q.copyFrom(Quaternion.FromEulerAngles(0, e.y, 0)); }); } diff --git a/src/menus/bmenu.ts b/src/menus/bmenu.ts index 266f641..e75a8af 100644 --- a/src/menus/bmenu.ts +++ b/src/menus/bmenu.ts @@ -9,7 +9,7 @@ import { WebXRExperienceHelper, WebXRInputSource } from "@babylonjs/core"; -import {Button3D, GUI3DManager, HolographicButton, PlanePanel, TextBlock} from "@babylonjs/gui"; +import {GUI3DManager, HolographicButton, PlanePanel} from "@babylonjs/gui"; import {DiagramEntity, DiagramEvent, DiagramEventType, DiagramManager} from "../diagram/diagramManager"; export enum BmenuState { @@ -69,6 +69,7 @@ export class Bmenu { const anchor = new TransformNode("bMenuAnchor"); anchor.rotation.y = Angle.FromDegrees(180).radians(); const cam = this.xr.camera.getFrontPosition(1); + cam.y = cam.y - .5; anchor.position = cam; const panel = new PlanePanel(); panel.margin = .06; @@ -112,8 +113,7 @@ export class Bmenu { entity.template = "#cylinder-template"; break; case "doneAdding": - this.state=BmenuState.NONE; - + this.state = BmenuState.NONE; break; default: console.log("Unknown button"); @@ -128,7 +128,6 @@ export class Bmenu { } #createDefaultMaterial() { - const myMaterial = new StandardMaterial("myMaterial", this.scene); myMaterial.diffuseColor = Color3.FromHexString("#CEE"); return myMaterial;