|
@@ -221,7 +221,7 @@ module BABYLON {
|
|
|
this._vrDeviceOrientationCamera = new BABYLON.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene);
|
|
|
}
|
|
|
this._webVRCamera = new BABYLON.WebVRFreeCamera("WebVRHelper", this._position, this._scene, webVROptions);
|
|
|
-
|
|
|
+ this._webVRCamera.useStandingMatrix()
|
|
|
// Create default button
|
|
|
if (!this._useCustomVRButton) {
|
|
|
this._btnVR = <HTMLButtonElement>document.createElement("BUTTON");
|
|
@@ -305,6 +305,10 @@ module BABYLON {
|
|
|
scene.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete);
|
|
|
window.addEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
|
|
|
|
|
|
+ scene.onDisposeObservable.add(()=>{
|
|
|
+ this.dispose();
|
|
|
+ })
|
|
|
+
|
|
|
// Gamepad connection events
|
|
|
this._webVRCamera.onControllerMeshLoadedObservable.add((webVRController) => this._onDefaultMeshLoaded(webVRController));
|
|
|
this._scene.gamepadManager.onGamepadConnectedObservable.add(this._onNewGamepadConnected);
|
|
@@ -642,12 +646,12 @@ module BABYLON {
|
|
|
if (gamepad.leftStick) {
|
|
|
gamepad.onleftstickchanged((stickValues) => {
|
|
|
if (this._teleportationEnabled) {
|
|
|
- this._checkTeleportBackwards(stickValues);
|
|
|
// Listening to classic/xbox gamepad only if no VR controller is active
|
|
|
if ((!this._leftLaserPointer && !this._rightLaserPointer) ||
|
|
|
((this._leftLaserPointer && !this._leftLaserPointer.isVisible) &&
|
|
|
(this._rightLaserPointer && !this._rightLaserPointer.isVisible))) {
|
|
|
this._checkTeleportWithRay(stickValues);
|
|
|
+ this._checkTeleportBackwards(stickValues);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -698,10 +702,17 @@ module BABYLON {
|
|
|
private _enableInteractionOnController(webVRController: WebVRController) {
|
|
|
var controllerMesh = webVRController.mesh;
|
|
|
if (controllerMesh) {
|
|
|
+ var makeNotPick = (root:AbstractMesh)=>{
|
|
|
+ root.name += " laserPointer";
|
|
|
+ root.getChildMeshes().forEach((c)=>{
|
|
|
+ makeNotPick(c);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ makeNotPick(controllerMesh);
|
|
|
var childMeshes = controllerMesh.getChildMeshes();
|
|
|
|
|
|
for (var i = 0; i < childMeshes.length; i++) {
|
|
|
- if (childMeshes[i].name === "POINTING_POSE") {
|
|
|
+ if (childMeshes[i].name && childMeshes[i].name.indexOf("POINTING_POSE") >= 0) {
|
|
|
controllerMesh = childMeshes[i];
|
|
|
break;
|
|
|
}
|
|
@@ -714,7 +725,6 @@ module BABYLON {
|
|
|
laserPointer.rotation.x = Math.PI / 2;
|
|
|
laserPointer.parent = controllerMesh;
|
|
|
laserPointer.position.z = -0.5;
|
|
|
- laserPointer.position.y = 0;
|
|
|
laserPointer.isVisible = false;
|
|
|
if (webVRController.hand === "left") {
|
|
|
this._leftLaserPointer = laserPointer;
|
|
@@ -1101,19 +1111,23 @@ module BABYLON {
|
|
|
}
|
|
|
|
|
|
if(!location){
|
|
|
- // 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.
|
|
|
- if (this.webVRCamera.leftCamera) {
|
|
|
- this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition);
|
|
|
- this._workingVector.subtractInPlace(this.webVRCamera.position);
|
|
|
- this._haloCenter.subtractToRef(this._workingVector, this._workingVector);
|
|
|
- } else {
|
|
|
- this._workingVector.copyFrom(this._haloCenter);
|
|
|
- }
|
|
|
- location = this._workingVector;
|
|
|
+ location = this._haloCenter;
|
|
|
+ }
|
|
|
+ // 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.
|
|
|
+ if (this.webVRCamera.leftCamera) {
|
|
|
+ this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition);
|
|
|
+ this._workingVector.subtractInPlace(this.webVRCamera.position);
|
|
|
+ location.subtractToRef(this._workingVector, this._workingVector);
|
|
|
+ } else {
|
|
|
+ this._workingVector.copyFrom(location);
|
|
|
}
|
|
|
// Add height to account for user's height offset
|
|
|
- location.y += this._defaultHeight;
|
|
|
+ if(this.isInVRMode){
|
|
|
+ this._workingVector.y += this.webVRCamera.deviceDistanceToRoomGround();
|
|
|
+ }else{
|
|
|
+ this._workingVector.y += this._defaultHeight;
|
|
|
+ }
|
|
|
|
|
|
// Create animation from the camera's position to the new location
|
|
|
this.currentVRCamera.animations = [];
|
|
@@ -1124,7 +1138,7 @@ module BABYLON {
|
|
|
},
|
|
|
{
|
|
|
frame: 11,
|
|
|
- value: location
|
|
|
+ value: this._workingVector
|
|
|
}
|
|
|
];
|
|
|
|
|
@@ -1189,7 +1203,7 @@ module BABYLON {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var ray;
|
|
|
+ var ray:Ray;
|
|
|
if (this._leftLaserPointer && this._leftLaserPointer.isVisible && (<any>this.currentVRCamera).leftController) {
|
|
|
ray = (<any>this.currentVRCamera).leftController.getForwardRay(this._rayLength);
|
|
|
}
|