How to get button input of oculus quest

Hi,

I tried WebVR function for Oculus Quest. The displayed two controllers is Oculus Touch. These were well tracked.

But when I tried “onAAAStateChangedObservable” to get button input, just one pull of
left controller stick(red square in the below picture) generates over hundreds log per seconds.

All other buttons in both controllers has the same problem.

I think the problem includes two possible cases. One is failure of my code, the other is current babylon.js is not available for button input of Oculus Quest.

Here is my source code.

var canvas = document.getElementById("renderCanvas");

        var createScene = function () {
            var scene = new BABYLON.Scene(engine);
            scene.debugLayer.show();
            var camera = new BABYLON.ArcRotateCamera('MainCamera1', 0, 0, 3, BABYLON.Vector3(0, 1.2, 0), scene, true);
            camera.position = new BABYLON.Vector3(0, 1.2, -1.1);
            camera.attachControl(canvas, true);
            camera.inputs.attached.mousewheel.detachControl(canvas);
            
            var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
            var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
        
            //for VR
            var vrHelper = scene.createDefaultVRExperience();
            vrHelper.currentVRCamera.position.y = 300;


            const leftHand = BABYLON.Mesh.CreateBox("",0.1, scene);
            leftHand.scaling.z = 2;
            leftHand.isVisible =false;
        
            const rightHand = BABYLON.Mesh.CreateBox("",0.1, scene);
            rightHand.scaling.z = 2;
            rightHand.isVisible =false;

            scene.onBeforeRenderObservable.add(()=>{
                if(vrHelper.webVRCamera.leftController){
                    leftHand.position = vrHelper.webVRCamera.leftController.devicePosition.clone();
                    leftHand.rotationQuaternion = vrHelper.webVRCamera.leftController.deviceRotationQuaternion.clone();
                    vrHelper.webVRCamera.leftController.onPadStateChangedObservable.add(function (stateObject) {
                        console.error("left Pad state fn is called but not pushed"); 
                        console.log(stateObject);
                    });
                if(vrHelper.webVRCamera.rightController){
                    rightHand.position = vrHelper.webVRCamera.rightController.devicePosition.clone();
                    rightHand.rotationQuaternion = vrHelper.webVRCamera.rightController.deviceRotationQuaternion.clone();
                }
            });

      
            return scene;
};

Any comments will be helpful for me.

I solved it by myself. My miss coding caused the problem.

I can get all key input of Oculus Quest controller. I’ll post a blog about basic controller input and provide the code to playground if need.

Thanks!

2 Likes

Great to hear that it works, looking forward to the post and playground example.

Thanks for your comment .

A simple example is here.

I’ll modify my code and try to make it for playground.

Sorry for my late.

I set my code on playground. Try this with your oculus quest.

https://playground.babylonjs.com/#0IBX3Y#1

Usage : Press left/right controller of Oculus Quest. Scale of linked sphere or box is bigger

Hi,
I tried this code on the oculus quest 2 but it doesn’t work at all.
Any idea ?
M

@Michel_Winter

Hi Michel,
The PG is based on WebVR.

WebVR is deprecated and will soon end its life in most if not all browsers. It is highly recommended to port all WebVR implementations to WebXR.

Ref : WebXR | Babylon.js Documentation (babylonjs.com)

I recommend to use WebXR. Here is a similar sample PG based on WebXR. It works on my Quest2.

WebXR_motion controller input | Babylon.js Playground (babylonjs.com)

FYI
WebXR Controllers Support | Babylon.js Documentation (babylonjs.com)

I hope it would be useful for you.

Thank you very much.
I had not found these pages.
The example given almost works :slight_smile: The joysticks are still associated with the movement of the camera, but this already helps me a lot.

1 Like

I’m glad to hear that.
Yes, I can not resolve joystick synchronization yet. I’ll update it if I find how to solve it.