Fixed snap rotation, added teleportation disable to constructor options.
This commit is contained in:
parent
5fd12c909b
commit
f511eb4ad5
@ -60,12 +60,14 @@ class App {
|
|||||||
|
|
||||||
const xr = await WebXRDefaultExperience.CreateAsync(scene, {
|
const xr = await WebXRDefaultExperience.CreateAsync(scene, {
|
||||||
floorMeshes: [this.createGround(scene)],
|
floorMeshes: [this.createGround(scene)],
|
||||||
|
disableTeleportation: true,
|
||||||
optionalFeatures: true
|
optionalFeatures: true
|
||||||
|
|
||||||
});
|
});
|
||||||
const rig = new Rigplatform(scene, xr);
|
const rig = new Rigplatform(scene, xr);
|
||||||
//const ring = new Cameras(scene, this.token);
|
//const ring = new Cameras(scene, this.token);
|
||||||
//ring.getCameras().then(() => ring.createCameras());
|
//ring.getCameras().then(() => ring.createCameras());
|
||||||
xr.teleportation.detach();
|
//xr.teleportation.detach();
|
||||||
|
|
||||||
// hide/show the Inspector
|
// hide/show the Inspector
|
||||||
window.addEventListener("keydown", (ev) => {
|
window.addEventListener("keydown", (ev) => {
|
||||||
@ -81,6 +83,7 @@ class App {
|
|||||||
|
|
||||||
engine.runRenderLoop(() => {
|
engine.runRenderLoop(() => {
|
||||||
scene.render();
|
scene.render();
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,3 +106,4 @@ class App {
|
|||||||
|
|
||||||
const app = new App();
|
const app = new App();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
Angle,
|
||||||
Camera,
|
Camera,
|
||||||
Color3,
|
Color3,
|
||||||
Mesh,
|
Mesh,
|
||||||
@ -8,7 +9,7 @@ import {
|
|||||||
PhysicsMotionType,
|
PhysicsMotionType,
|
||||||
PhysicsShapeType,
|
PhysicsShapeType,
|
||||||
Quaternion,
|
Quaternion,
|
||||||
Scene,
|
Scene, Space,
|
||||||
StandardMaterial,
|
StandardMaterial,
|
||||||
Vector3,
|
Vector3,
|
||||||
WebXRDefaultExperience
|
WebXRDefaultExperience
|
||||||
@ -22,6 +23,7 @@ export class Rigplatform {
|
|||||||
static ANGULAR_VELOCITY = 3;
|
static ANGULAR_VELOCITY = 3;
|
||||||
static x90 = Quaternion.RotationAxis(Vector3.Up(), 1.5708);
|
static x90 = Quaternion.RotationAxis(Vector3.Up(), 1.5708);
|
||||||
public bMenu: Bmenu;
|
public bMenu: Bmenu;
|
||||||
|
private yRotation: number = 0;
|
||||||
public right: Right;
|
public right: Right;
|
||||||
public left: Left;
|
public left: Left;
|
||||||
public body: PhysicsBody;
|
public body: PhysicsBody;
|
||||||
@ -57,6 +59,7 @@ export class Rigplatform {
|
|||||||
scene);
|
scene);
|
||||||
rigAggregate.body.setMotionType(PhysicsMotionType.ANIMATED);
|
rigAggregate.body.setMotionType(PhysicsMotionType.ANIMATED);
|
||||||
rigAggregate.body.setGravityFactor(0);
|
rigAggregate.body.setGravityFactor(0);
|
||||||
|
|
||||||
this.#fixRotation();
|
this.#fixRotation();
|
||||||
this.body = rigAggregate.body;
|
this.body = rigAggregate.body;
|
||||||
this.#setupKeyboard();
|
this.#setupKeyboard();
|
||||||
@ -100,12 +103,15 @@ export class Rigplatform {
|
|||||||
const snap = true;
|
const snap = true;
|
||||||
if (snap) {
|
if (snap) {
|
||||||
if (!this.turning) {
|
if (!this.turning) {
|
||||||
|
if (Math.abs(val) > .1) {
|
||||||
this.turning = true;
|
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 {
|
} else {
|
||||||
if (val < .1) {
|
if (Math.abs(val) < .1) {
|
||||||
this.turning = false;
|
this.turning = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -192,6 +198,7 @@ export class Rigplatform {
|
|||||||
this.scene.registerBeforeRender(() => {
|
this.scene.registerBeforeRender(() => {
|
||||||
const q = this.rigMesh.rotationQuaternion;
|
const q = this.rigMesh.rotationQuaternion;
|
||||||
const e = q.toEulerAngles();
|
const e = q.toEulerAngles();
|
||||||
|
e.y += this.yRotation;
|
||||||
q.copyFrom(Quaternion.FromEulerAngles(0, e.y, 0));
|
q.copyFrom(Quaternion.FromEulerAngles(0, e.y, 0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import {
|
|||||||
WebXRExperienceHelper,
|
WebXRExperienceHelper,
|
||||||
WebXRInputSource
|
WebXRInputSource
|
||||||
} from "@babylonjs/core";
|
} 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";
|
import {DiagramEntity, DiagramEvent, DiagramEventType, DiagramManager} from "../diagram/diagramManager";
|
||||||
|
|
||||||
export enum BmenuState {
|
export enum BmenuState {
|
||||||
@ -69,6 +69,7 @@ export class Bmenu {
|
|||||||
const anchor = new TransformNode("bMenuAnchor");
|
const anchor = new TransformNode("bMenuAnchor");
|
||||||
anchor.rotation.y = Angle.FromDegrees(180).radians();
|
anchor.rotation.y = Angle.FromDegrees(180).radians();
|
||||||
const cam = this.xr.camera.getFrontPosition(1);
|
const cam = this.xr.camera.getFrontPosition(1);
|
||||||
|
cam.y = cam.y - .5;
|
||||||
anchor.position = cam;
|
anchor.position = cam;
|
||||||
const panel = new PlanePanel();
|
const panel = new PlanePanel();
|
||||||
panel.margin = .06;
|
panel.margin = .06;
|
||||||
@ -113,7 +114,6 @@ export class Bmenu {
|
|||||||
break;
|
break;
|
||||||
case "doneAdding":
|
case "doneAdding":
|
||||||
this.state = BmenuState.NONE;
|
this.state = BmenuState.NONE;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log("Unknown button");
|
console.log("Unknown button");
|
||||||
@ -128,7 +128,6 @@ export class Bmenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#createDefaultMaterial() {
|
#createDefaultMaterial() {
|
||||||
|
|
||||||
const myMaterial = new StandardMaterial("myMaterial", this.scene);
|
const myMaterial = new StandardMaterial("myMaterial", this.scene);
|
||||||
myMaterial.diffuseColor = Color3.FromHexString("#CEE");
|
myMaterial.diffuseColor = Color3.FromHexString("#CEE");
|
||||||
return myMaterial;
|
return myMaterial;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user