|
@@ -6,25 +6,25 @@ module BABYLON {
|
|
/**
|
|
/**
|
|
* Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if thats the case only the pointer from the head will be availible
|
|
* Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if thats the case only the pointer from the head will be availible
|
|
*/
|
|
*/
|
|
- public grip?: BABYLON.AbstractMesh
|
|
|
|
|
|
+ public grip?: BABYLON.AbstractMesh;
|
|
/**
|
|
/**
|
|
* Pointer which can be used to select objects or attach a visible laser to
|
|
* Pointer which can be used to select objects or attach a visible laser to
|
|
*/
|
|
*/
|
|
- public pointer: BABYLON.AbstractMesh
|
|
|
|
|
|
+ public pointer: BABYLON.AbstractMesh;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates the controller
|
|
* Creates the controller
|
|
* @see https://doc.babylonjs.com/how_to/webxr
|
|
* @see https://doc.babylonjs.com/how_to/webxr
|
|
* @param scene the scene which the controller should be associated to
|
|
* @param scene the scene which the controller should be associated to
|
|
*/
|
|
*/
|
|
- constructor(scene: BABYLON.Scene){
|
|
|
|
|
|
+ constructor(scene: BABYLON.Scene) {
|
|
this.pointer = new BABYLON.AbstractMesh("controllerPointer", scene);
|
|
this.pointer = new BABYLON.AbstractMesh("controllerPointer", scene);
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Disposes of the object
|
|
* Disposes of the object
|
|
*/
|
|
*/
|
|
- dispose(){
|
|
|
|
- if(this.grip){
|
|
|
|
|
|
+ dispose() {
|
|
|
|
+ if (this.grip) {
|
|
this.grip.dispose();
|
|
this.grip.dispose();
|
|
}
|
|
}
|
|
this.pointer.dispose();
|
|
this.pointer.dispose();
|
|
@@ -38,41 +38,41 @@ module BABYLON {
|
|
/**
|
|
/**
|
|
* XR controllers being tracked
|
|
* XR controllers being tracked
|
|
*/
|
|
*/
|
|
- public controllers:Array<WebXRController> = []
|
|
|
|
|
|
+ public controllers: Array<WebXRController> = [];
|
|
private _tmpMatrix = new BABYLON.Matrix();
|
|
private _tmpMatrix = new BABYLON.Matrix();
|
|
- private _frameObserver:Nullable<Observer<any>>;
|
|
|
|
|
|
+ private _frameObserver: Nullable<Observer<any>>;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Initializes the WebXRInput
|
|
* Initializes the WebXRInput
|
|
* @param helper experience helper which the input should be created for
|
|
* @param helper experience helper which the input should be created for
|
|
*/
|
|
*/
|
|
public constructor(private helper: WebXRExperienceHelper) {
|
|
public constructor(private helper: WebXRExperienceHelper) {
|
|
- this._frameObserver = helper._sessionManager.onXRFrameObservable.add(()=>{
|
|
|
|
|
|
+ this._frameObserver = helper._sessionManager.onXRFrameObservable.add(() => {
|
|
if (!helper._sessionManager._currentXRFrame || !helper._sessionManager._currentXRFrame.getDevicePose) {
|
|
if (!helper._sessionManager._currentXRFrame || !helper._sessionManager._currentXRFrame.getDevicePose) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
var xrFrame = helper._sessionManager._currentXRFrame;
|
|
var xrFrame = helper._sessionManager._currentXRFrame;
|
|
- var inputSources = helper._sessionManager._xrSession.getInputSources()
|
|
|
|
|
|
+ var inputSources = helper._sessionManager._xrSession.getInputSources();
|
|
|
|
|
|
- inputSources.forEach((input, i)=>{
|
|
|
|
|
|
+ inputSources.forEach((input, i) => {
|
|
let inputPose = xrFrame.getInputPose(input, helper._sessionManager._frameOfReference);
|
|
let inputPose = xrFrame.getInputPose(input, helper._sessionManager._frameOfReference);
|
|
- if(inputPose){
|
|
|
|
- if(this.controllers.length <= i){
|
|
|
|
|
|
+ if (inputPose) {
|
|
|
|
+ if (this.controllers.length <= i) {
|
|
this.controllers.push(new WebXRController(helper.container.getScene()));
|
|
this.controllers.push(new WebXRController(helper.container.getScene()));
|
|
}
|
|
}
|
|
var controller = this.controllers[i];
|
|
var controller = this.controllers[i];
|
|
-
|
|
|
|
|
|
+
|
|
// Manage the grip if it exists
|
|
// Manage the grip if it exists
|
|
- if(inputPose.gripMatrix){
|
|
|
|
- if(!controller.grip){
|
|
|
|
|
|
+ if (inputPose.gripMatrix) {
|
|
|
|
+ if (!controller.grip) {
|
|
controller.grip = new BABYLON.AbstractMesh("controllerGrip", helper.container.getScene());
|
|
controller.grip = new BABYLON.AbstractMesh("controllerGrip", helper.container.getScene());
|
|
}
|
|
}
|
|
BABYLON.Matrix.FromFloat32ArrayToRefScaled(inputPose.gripMatrix, 0, 1, this._tmpMatrix);
|
|
BABYLON.Matrix.FromFloat32ArrayToRefScaled(inputPose.gripMatrix, 0, 1, this._tmpMatrix);
|
|
- if(!controller.grip.getScene().useRightHandedSystem){
|
|
|
|
|
|
+ if (!controller.grip.getScene().useRightHandedSystem) {
|
|
this._tmpMatrix.toggleModelMatrixHandInPlace();
|
|
this._tmpMatrix.toggleModelMatrixHandInPlace();
|
|
}
|
|
}
|
|
- if(!controller.grip.rotationQuaternion){
|
|
|
|
|
|
+ if (!controller.grip.rotationQuaternion) {
|
|
controller.grip.rotationQuaternion = new BABYLON.Quaternion();
|
|
controller.grip.rotationQuaternion = new BABYLON.Quaternion();
|
|
}
|
|
}
|
|
this._tmpMatrix.decompose(controller.grip.scaling, controller.grip.rotationQuaternion, controller.grip.position);
|
|
this._tmpMatrix.decompose(controller.grip.scaling, controller.grip.rotationQuaternion, controller.grip.position);
|
|
@@ -80,24 +80,24 @@ module BABYLON {
|
|
|
|
|
|
// Manager pointer of controller
|
|
// Manager pointer of controller
|
|
BABYLON.Matrix.FromFloat32ArrayToRefScaled(inputPose.targetRay.transformMatrix, 0, 1, this._tmpMatrix);
|
|
BABYLON.Matrix.FromFloat32ArrayToRefScaled(inputPose.targetRay.transformMatrix, 0, 1, this._tmpMatrix);
|
|
- if(!controller.pointer.getScene().useRightHandedSystem){
|
|
|
|
|
|
+ if (!controller.pointer.getScene().useRightHandedSystem) {
|
|
this._tmpMatrix.toggleModelMatrixHandInPlace();
|
|
this._tmpMatrix.toggleModelMatrixHandInPlace();
|
|
}
|
|
}
|
|
- if(!controller.pointer.rotationQuaternion){
|
|
|
|
|
|
+ if (!controller.pointer.rotationQuaternion) {
|
|
controller.pointer.rotationQuaternion = new BABYLON.Quaternion();
|
|
controller.pointer.rotationQuaternion = new BABYLON.Quaternion();
|
|
}
|
|
}
|
|
this._tmpMatrix.decompose(controller.pointer.scaling, controller.pointer.rotationQuaternion, controller.pointer.position);
|
|
this._tmpMatrix.decompose(controller.pointer.scaling, controller.pointer.rotationQuaternion, controller.pointer.position);
|
|
}
|
|
}
|
|
- })
|
|
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
+ });
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Disposes of the object
|
|
* Disposes of the object
|
|
*/
|
|
*/
|
|
public dispose() {
|
|
public dispose() {
|
|
- this.controllers.forEach((c)=>{
|
|
|
|
|
|
+ this.controllers.forEach((c) => {
|
|
c.dispose();
|
|
c.dispose();
|
|
- })
|
|
|
|
|
|
+ });
|
|
this.helper._sessionManager.onXRFrameObservable.remove(this._frameObserver);
|
|
this.helper._sessionManager.onXRFrameObservable.remove(this._frameObserver);
|
|
}
|
|
}
|
|
}
|
|
}
|