Fixed snap rotation, added teleportation disable to constructor options.

This commit is contained in:
Michael Mainguy 2023-07-14 06:08:14 -05:00
parent 5fd12c909b
commit f511eb4ad5
3 changed files with 19 additions and 9 deletions

View File

@ -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();

View File

@ -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) {
if (Math.abs(val) > .1) {
this.turning = true;
const q = this.rigMesh.rotation.y += Math.abs(val) * 22.5;
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));
});
}

View File

@ -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;
@ -113,7 +114,6 @@ export class Bmenu {
break;
case "doneAdding":
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;