|
@@ -30,22 +30,26 @@ module BABYLON {
|
|
class VRExperienceHelperGazer {
|
|
class VRExperienceHelperGazer {
|
|
public laserPointer: Mesh;
|
|
public laserPointer: Mesh;
|
|
public gazeTracker:Mesh;
|
|
public gazeTracker:Mesh;
|
|
- public teleportationTarget:Mesh;
|
|
|
|
|
|
|
|
- public teleportationEnabled: boolean;
|
|
|
|
- public interactionsEnabled: boolean;
|
|
|
|
|
|
|
|
public currentMeshSelected:Nullable<AbstractMesh>;
|
|
public currentMeshSelected:Nullable<AbstractMesh>;
|
|
public currentHit:Nullable<PickingInfo>;
|
|
public currentHit:Nullable<PickingInfo>;
|
|
|
|
|
|
- public static counter = 0;
|
|
|
|
|
|
+ public static idCounter = 0;
|
|
public id:number;
|
|
public id:number;
|
|
|
|
|
|
public pointerDownOnMeshAsked:boolean = false;
|
|
public pointerDownOnMeshAsked:boolean = false;
|
|
public isActionableMesh:boolean = false;
|
|
public isActionableMesh:boolean = false;
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public interactionsEnabled: boolean;
|
|
|
|
+ public teleportationEnabled: boolean;
|
|
|
|
+ public teleportationRequestInitiated = false;
|
|
|
|
+ public teleportationBackRequestInitiated = false;
|
|
|
|
+
|
|
|
|
+
|
|
constructor(scene: Scene){
|
|
constructor(scene: Scene){
|
|
- this.id = VRExperienceHelperGazer.counter++;
|
|
|
|
|
|
+ this.id = VRExperienceHelperGazer.idCounter++;
|
|
// Laser pointer
|
|
// Laser pointer
|
|
this.laserPointer = Mesh.CreateCylinder("laserPointer", 1, 0.004, 0.0002, 20, 1, scene, false);
|
|
this.laserPointer = Mesh.CreateCylinder("laserPointer", 1, 0.004, 0.0002, 20, 1, scene, false);
|
|
var laserPointerMaterial = new StandardMaterial("laserPointerMat", scene);
|
|
var laserPointerMaterial = new StandardMaterial("laserPointerMat", scene);
|
|
@@ -181,10 +185,7 @@ module BABYLON {
|
|
private _teleportationRequested: boolean = false;
|
|
private _teleportationRequested: boolean = false;
|
|
private _floorMeshName: string;
|
|
private _floorMeshName: string;
|
|
private _floorMeshesCollection: Mesh[] = [];
|
|
private _floorMeshesCollection: Mesh[] = [];
|
|
- private _teleportationAllowed: boolean = false;
|
|
|
|
private _rotationAllowed: boolean = true;
|
|
private _rotationAllowed: boolean = true;
|
|
- private _teleportationRequestInitiated = false;
|
|
|
|
- private _teleportationBackRequestInitiated = false;
|
|
|
|
private teleportBackwardsVector = new Vector3(0, -1, -1);
|
|
private teleportBackwardsVector = new Vector3(0, -1, -1);
|
|
private _rotationRightAsked = false;
|
|
private _rotationRightAsked = false;
|
|
private _rotationLeftAsked = false;
|
|
private _rotationLeftAsked = false;
|
|
@@ -198,6 +199,7 @@ module BABYLON {
|
|
private _cameraGazer: VRExperienceHelperCameraGazer;
|
|
private _cameraGazer: VRExperienceHelperCameraGazer;
|
|
private _padSensibilityUp = 0.65;
|
|
private _padSensibilityUp = 0.65;
|
|
private _padSensibilityDown = 0.35;
|
|
private _padSensibilityDown = 0.35;
|
|
|
|
+
|
|
|
|
|
|
private leftController:Nullable<VRExperienceHelperControllerGazer>;
|
|
private leftController:Nullable<VRExperienceHelperControllerGazer>;
|
|
private rightController:Nullable<VRExperienceHelperControllerGazer>;
|
|
private rightController:Nullable<VRExperienceHelperControllerGazer>;
|
|
@@ -387,6 +389,13 @@ module BABYLON {
|
|
return this._vrDeviceOrientationCamera;
|
|
return this._vrDeviceOrientationCamera;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private get _teleportationRequestInitiated(): boolean {
|
|
|
|
+ var result = this._cameraGazer.teleportationRequestInitiated
|
|
|
|
+ || (this.leftController !== null && this.leftController.teleportationRequestInitiated)
|
|
|
|
+ || (this.rightController !== null && this.rightController.teleportationRequestInitiated);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Instantiates a VRExperienceHelper.
|
|
* Instantiates a VRExperienceHelper.
|
|
* Helps to quickly add VR support to an existing scene.
|
|
* Helps to quickly add VR support to an existing scene.
|
|
@@ -913,8 +922,8 @@ module BABYLON {
|
|
if ((!this.leftController && !this.rightController) ||
|
|
if ((!this.leftController && !this.rightController) ||
|
|
((this.leftController && !this.leftController.laserPointer.isVisible) &&
|
|
((this.leftController && !this.leftController.laserPointer.isVisible) &&
|
|
(this.rightController && !this.rightController.laserPointer.isVisible))) {
|
|
(this.rightController && !this.rightController.laserPointer.isVisible))) {
|
|
- this._checkTeleportWithRay(stickValues);
|
|
|
|
- this._checkTeleportBackwards(stickValues);
|
|
|
|
|
|
+ this._checkTeleportWithRay(stickValues, this._cameraGazer);
|
|
|
|
+ this._checkTeleportBackwards(stickValues, this._cameraGazer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -922,7 +931,7 @@ module BABYLON {
|
|
if (gamepad.rightStick) {
|
|
if (gamepad.rightStick) {
|
|
gamepad.onrightstickchanged((stickValues) => {
|
|
gamepad.onrightstickchanged((stickValues) => {
|
|
if (this._teleportationInitialized) {
|
|
if (this._teleportationInitialized) {
|
|
- this._checkRotate(stickValues);
|
|
|
|
|
|
+ this._checkRotate(stickValues, this._cameraGazer);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -1016,25 +1025,23 @@ module BABYLON {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private _checkTeleportWithRay(stateObject: StickValues, helperController: Nullable<VRExperienceHelperControllerGazer> = null) {
|
|
|
|
- if (!this._teleportationRequestInitiated) {
|
|
|
|
|
|
+ private _checkTeleportWithRay(stateObject: StickValues, gazer: VRExperienceHelperGazer) {
|
|
|
|
+ // Dont teleport if another gaze already requested teleportation
|
|
|
|
+ if(this._teleportationRequestInitiated && !gazer.teleportationRequestInitiated){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (!gazer.teleportationRequestInitiated) {
|
|
if (stateObject.y < -this._padSensibilityUp && this._dpadPressed) {
|
|
if (stateObject.y < -this._padSensibilityUp && this._dpadPressed) {
|
|
- if (helperController) {
|
|
|
|
- helperController.laserPointer.isVisible = true;
|
|
|
|
- }
|
|
|
|
- this._teleportationRequestInitiated = true;
|
|
|
|
|
|
+ gazer.laserPointer.isVisible = true;
|
|
|
|
+ gazer.teleportationRequestInitiated = true;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// Listening to the proper controller values changes to confirm teleportation
|
|
// Listening to the proper controller values changes to confirm teleportation
|
|
- if (helperController == null
|
|
|
|
- || (this.leftController && this.leftController.laserPointer.isVisible)
|
|
|
|
|
|
+ if ((this.leftController && this.leftController.laserPointer.isVisible)
|
|
|| (this.rightController && this.rightController.laserPointer.isVisible)) {
|
|
|| (this.rightController && this.rightController.laserPointer.isVisible)) {
|
|
if (Math.sqrt(stateObject.y * stateObject.y + stateObject.x * stateObject.x) < this._padSensibilityDown) {
|
|
if (Math.sqrt(stateObject.y * stateObject.y + stateObject.x * stateObject.x) < this._padSensibilityDown) {
|
|
- if (this._teleportationAllowed) {
|
|
|
|
- this._teleportationAllowed = false;
|
|
|
|
- this._teleportCamera();
|
|
|
|
- }
|
|
|
|
- this._teleportationRequestInitiated = false;
|
|
|
|
|
|
+ this._teleportCamera(this._haloCenter);
|
|
|
|
+ gazer.teleportationRequestInitiated = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1051,9 +1058,9 @@ module BABYLON {
|
|
}
|
|
}
|
|
gazer.pointerDownOnMeshAsked = false;
|
|
gazer.pointerDownOnMeshAsked = false;
|
|
}
|
|
}
|
|
- private _checkRotate(stateObject: StickValues) {
|
|
|
|
|
|
+ private _checkRotate(stateObject: StickValues, gazer:VRExperienceHelperGazer) {
|
|
// Only rotate when user is not currently selecting a teleportation location
|
|
// Only rotate when user is not currently selecting a teleportation location
|
|
- if (this._teleportationRequestInitiated) {
|
|
|
|
|
|
+ if (gazer.teleportationRequestInitiated) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1083,14 +1090,14 @@ module BABYLON {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- private _checkTeleportBackwards(stateObject: StickValues) {
|
|
|
|
|
|
+ private _checkTeleportBackwards(stateObject: StickValues, gazer:VRExperienceHelperGazer) {
|
|
// Only teleport backwards when user is not currently selecting a teleportation location
|
|
// Only teleport backwards when user is not currently selecting a teleportation location
|
|
- if (this._teleportationRequestInitiated) {
|
|
|
|
|
|
+ if (gazer.teleportationRequestInitiated) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// Teleport backwards
|
|
// Teleport backwards
|
|
if (stateObject.y > this._padSensibilityUp && this._dpadPressed) {
|
|
if (stateObject.y > this._padSensibilityUp && this._dpadPressed) {
|
|
- if (!this._teleportationBackRequestInitiated) {
|
|
|
|
|
|
+ if (!gazer.teleportationBackRequestInitiated) {
|
|
if (!this.currentVRCamera) {
|
|
if (!this.currentVRCamera) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1122,10 +1129,10 @@ module BABYLON {
|
|
this._teleportCamera(hit.pickedPoint);
|
|
this._teleportCamera(hit.pickedPoint);
|
|
}
|
|
}
|
|
|
|
|
|
- this._teleportationBackRequestInitiated = true;
|
|
|
|
|
|
+ gazer.teleportationBackRequestInitiated = true;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- this._teleportationBackRequestInitiated = false;
|
|
|
|
|
|
+ gazer.teleportationBackRequestInitiated = false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -1145,16 +1152,16 @@ module BABYLON {
|
|
if (!this._dpadPressed) {
|
|
if (!this._dpadPressed) {
|
|
this._rotationLeftAsked = false;
|
|
this._rotationLeftAsked = false;
|
|
this._rotationRightAsked = false;
|
|
this._rotationRightAsked = false;
|
|
- this._teleportationBackRequestInitiated = false;
|
|
|
|
|
|
+ controller.teleportationBackRequestInitiated = false;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
controller.webVRController.onPadValuesChangedObservable.add((stateObject) => {
|
|
controller.webVRController.onPadValuesChangedObservable.add((stateObject) => {
|
|
if (this.teleportationEnabled) {
|
|
if (this.teleportationEnabled) {
|
|
- this._checkTeleportBackwards(stateObject);
|
|
|
|
|
|
+ this._checkTeleportBackwards(stateObject, controller);
|
|
this._checkTeleportWithRay(stateObject, controller);
|
|
this._checkTeleportWithRay(stateObject, controller);
|
|
}
|
|
}
|
|
- this._checkRotate(stateObject);
|
|
|
|
|
|
+ this._checkRotate(stateObject, controller);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1327,17 +1334,14 @@ module BABYLON {
|
|
this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);
|
|
this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);
|
|
}
|
|
}
|
|
|
|
|
|
- private _moveTeleportationSelectorTo(hit: PickingInfo) {
|
|
|
|
|
|
+ private _moveTeleportationSelectorTo(hit: PickingInfo, gazer:VRExperienceHelperGazer) {
|
|
if (hit.pickedPoint) {
|
|
if (hit.pickedPoint) {
|
|
- this._teleportationAllowed = true;
|
|
|
|
- if (this._teleportationRequestInitiated) {
|
|
|
|
|
|
+ if (gazer.teleportationRequestInitiated) {
|
|
this._displayTeleportationTarget();
|
|
this._displayTeleportationTarget();
|
|
|
|
+ this._haloCenter.copyFrom(hit.pickedPoint);
|
|
|
|
+ this._teleportationTarget.position.copyFrom(hit.pickedPoint);
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- this._hideTeleportationTarget();
|
|
|
|
- }
|
|
|
|
- this._haloCenter.copyFrom(hit.pickedPoint);
|
|
|
|
- this._teleportationTarget.position.copyFrom(hit.pickedPoint);
|
|
|
|
|
|
+
|
|
var pickNormal = hit.getNormal(true, false);
|
|
var pickNormal = hit.getNormal(true, false);
|
|
if (pickNormal) {
|
|
if (pickNormal) {
|
|
var axis1 = Vector3.Cross(Axis.Y, pickNormal);
|
|
var axis1 = Vector3.Cross(Axis.Y, pickNormal);
|
|
@@ -1350,14 +1354,10 @@ module BABYLON {
|
|
private _workingVector = Vector3.Zero();
|
|
private _workingVector = Vector3.Zero();
|
|
private _workingQuaternion = Quaternion.Identity();
|
|
private _workingQuaternion = Quaternion.Identity();
|
|
private _workingMatrix = Matrix.Identity();
|
|
private _workingMatrix = Matrix.Identity();
|
|
- private _teleportCamera(location: Nullable<Vector3> = null) {
|
|
|
|
|
|
+ private _teleportCamera(location: Vector3) {
|
|
if (!(this.currentVRCamera instanceof FreeCamera)) {
|
|
if (!(this.currentVRCamera instanceof FreeCamera)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (!location) {
|
|
|
|
- location = this._haloCenter;
|
|
|
|
- }
|
|
|
|
// Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the
|
|
// Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the
|
|
// offset of the headset from the anchor.
|
|
// offset of the headset from the anchor.
|
|
if (this.webVRCamera.leftCamera) {
|
|
if (this.webVRCamera.leftCamera) {
|
|
@@ -1445,6 +1445,8 @@ module BABYLON {
|
|
this._scene.beginAnimation(this.currentVRCamera, 0, 11, false, 1, () => {
|
|
this._scene.beginAnimation(this.currentVRCamera, 0, 11, false, 1, () => {
|
|
this.onAfterCameraTeleport.notifyObservers(this._workingVector);
|
|
this.onAfterCameraTeleport.notifyObservers(this._workingVector);
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ this._hideTeleportationTarget();
|
|
}
|
|
}
|
|
|
|
|
|
private _castRayAndSelectObject(gazer:VRExperienceHelperGazer) {
|
|
private _castRayAndSelectObject(gazer:VRExperienceHelperGazer) {
|
|
@@ -1522,13 +1524,13 @@ module BABYLON {
|
|
}
|
|
}
|
|
|
|
|
|
gazer.currentMeshSelected = null;
|
|
gazer.currentMeshSelected = null;
|
|
-
|
|
|
|
- this._moveTeleportationSelectorTo(hit);
|
|
|
|
|
|
+ if(gazer.teleportationRequestInitiated){
|
|
|
|
+ this._moveTeleportationSelectorTo(hit, gazer);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// If not, we're in a selection scenario
|
|
// If not, we're in a selection scenario
|
|
- this._hideTeleportationTarget();
|
|
|
|
- this._teleportationAllowed = false;
|
|
|
|
|
|
+ //this._teleportationAllowed = false;
|
|
if (hit.pickedMesh !== gazer.currentMeshSelected) {
|
|
if (hit.pickedMesh !== gazer.currentMeshSelected) {
|
|
if (this.meshSelectionPredicate(hit.pickedMesh)) {
|
|
if (this.meshSelectionPredicate(hit.pickedMesh)) {
|
|
this.onNewMeshPicked.notifyObservers(hit);
|
|
this.onNewMeshPicked.notifyObservers(hit);
|
|
@@ -1562,8 +1564,7 @@ module BABYLON {
|
|
gazer.currentHit = null;
|
|
gazer.currentHit = null;
|
|
this._notifySelectedMeshUnselected(gazer.currentMeshSelected);
|
|
this._notifySelectedMeshUnselected(gazer.currentMeshSelected);
|
|
gazer.currentMeshSelected = null;
|
|
gazer.currentMeshSelected = null;
|
|
- this._teleportationAllowed = false;
|
|
|
|
- this._hideTeleportationTarget();
|
|
|
|
|
|
+ //this._teleportationAllowed = false;
|
|
this.changeGazeColor(new Color3(0.7, 0.7, 0.7));
|
|
this.changeGazeColor(new Color3(0.7, 0.7, 0.7));
|
|
this.changeLaserColor(new Color3(0.7, 0.7, 0.7));
|
|
this.changeLaserColor(new Color3(0.7, 0.7, 0.7));
|
|
}
|
|
}
|