Jump to content

New Gamepad Changes


MackeyK24
 Share

Recommended Posts

Hey @davrous I just tried to pull the preview release and 'BABYLON.Gamepads no longer there. I see all kind of work you have done to create all those 'Controllers' as well.

My question is how to use the 'Regular Gamepads' and I would love some info on those other new controllers so I can add support for those in the toolkit :)

I currently create gamepads like this the following but that won't work anymore... can you please show me how:

if (gamepads == null) {
   gamepads = new BABYLON.Gamepads<BABYLON.Gamepad>((pad: BABYLON.Gamepad) => { inputGamepadConnected(pad); });
}

Or anyone who knows about the new Gamepad Changes :)

Edit... I see a GamepadManager class... but there is no 'OnGamepadConnected'  handler like you used to pass to BABYLON.Gamepads... Without having to CHANGE TOO MUCH code in the toolkit, I am still gonna need that event.... Unless the whole connection thing has changed... Dunno what it supposed to be doing

Link to comment
Share on other sites

I guess the GameManager is the new class and you would use like this:

BABYLON.SceneManager.gamepads = new BABYLON.GamepadManager();
BABYLON.SceneManager.gamepads.onGamepadConnectedObservable.add(BABYLON.SceneManager.inputGamepadConnected)

 and my on connected like this:

private static inputGamepadConnected(pad: BABYLON.Gamepad, state:BABYLON.EventState) {
    if (pad.index === 0) {
        BABYLON.SceneManager.gamepad = pad;
        BABYLON.Tools.Log("Gamepad Connected: " + BABYLON.SceneManager.gamepad.id);
        if ((<string>BABYLON.SceneManager.gamepad.id).search("Xbox 360") !== -1 || (<string>BABYLON.SceneManager.gamepad.id).search("Xbox One") !== -1 || (<string>BABYLON.SceneManager.gamepad.id).search("xinput") !== -1) {
            BABYLON.SceneManager.gamepadType = BABYLON.GamepadType.Xbox360;
            var xbox360Pad: BABYLON.Xbox360Pad = BABYLON.SceneManager.gamepad as BABYLON.Xbox360Pad;
            xbox360Pad.onbuttonup(BABYLON.SceneManager.inputButtonUpHandler);
            xbox360Pad.onbuttondown(BABYLON.SceneManager.inputButtonDownHandler);
            xbox360Pad.onleftstickchanged(BABYLON.SceneManager.inputLeftStickHandler);
            xbox360Pad.onrightstickchanged(BABYLON.SceneManager.inputRightStickHandler);
            xbox360Pad.ondpadup(BABYLON.SceneManager.inputXboxDPadUpHandler);
            xbox360Pad.ondpaddown(BABYLON.SceneManager.inputXboxDPadDownHandler);
            xbox360Pad.onlefttriggerchanged(BABYLON.SceneManager.inputXboxLeftTriggerHandler);
            xbox360Pad.onrighttriggerchanged(BABYLON.SceneManager.inputXboxRightTriggerHandler);
        } else {
            BABYLON.SceneManager.gamepadType = BABYLON.GamepadType.Generic;
            var genericPad: BABYLON.GenericPad = BABYLON.SceneManager.gamepad as BABYLON.GenericPad;
            genericPad.onbuttonup(BABYLON.SceneManager.inputButtonUpHandler);
            genericPad.onbuttondown(BABYLON.SceneManager.inputButtonDownHandler);
            genericPad.onleftstickchanged(BABYLON.SceneManager.inputLeftStickHandler);
            genericPad.onrightstickchanged(BABYLON.SceneManager.inputRightStickHandler);
        }
        if (BABYLON.SceneManager.gamepadConnected != null) {
            BABYLON.SceneManager.gamepadConnected(BABYLON.SceneManager.gamepad, BABYLON.SceneManager.gamepadType);
        }
    }
}

 

I am assuming that is the proper usage of the new BABYLON.GamepadManager class instead of the previous BABYLON.Gamepads

@davrous is that right ???

 

Link to comment
Share on other sites

FYI... @davrous  You had fixed the issue on chrome with the BABYLON.Gamepads where a page refresh would not cause an additional GamePad Connected event...

 

The new BABYLON.GamepadManager seems to have the same issue again... If you start a new browser session the gamepad works fine... if you refresh the page the gamepad DOES NOT WORK... because the onGamepadConnected Event is not firing for page refreshes... Can you please look at this issue when you can :)

 

Link to comment
Share on other sites

Hello, so you don't have to instantiate the gamepadManager. It is already hosted on the scene: scene.gamepadManager

So to get your gamepadConnected event, you just need:

    scene.gamepadManager.onGamepadConnectedObservable.add(function(pad) {
        alert("gamepad connected");
    })

 

Regarding the page reload: you will not receive a gamepad connected because the gamepads are already connected. You just need to query the one you want with scene.gamepadManager.getGamepadByType:

https://www.babylonjs-playground.com/#ULL4ER#1

Link to comment
Share on other sites

22 minutes ago, Deltakosh said:

Hello, so you don't have to instantiate the gamepadManager. It is already hosted on the scene: scene.gamepadManager

So to get your gamepadConnected event, you just need:


    scene.gamepadManager.onGamepadConnectedObservable.add(function(pad) {
        alert("gamepad connected");
    })

 

Regarding the page reload: you will not receive a gamepad connected because the gamepads are already connected. You just need to query the one you want with scene.gamepadManager.getGamepadByType:

https://www.babylonjs-playground.com/#ULL4ER#1

 But I don't know the type... I wanna re-connect the FIRST gamepad connected I guess...

When the game page first loads I get the event so I use the whatever gamepad connected ... I don't know its type... on refresh I still would not know the type since it really reloading the page... I cannot STORE the type of the previous connected gamepad because the page reloaded... Can we add a getGamepadByIndex(0) or something like that to gibe me this FIRST (and should be only) gamepad connected ???

 

EDIT:

I guess I can just check EVERYTHING LIKE SO:

 

BABYLON.SceneManager.gamepads.onGamepadConnectedObservable.add(BABYLON.SceneManager.inputGamepadConnected)
var xbox:BABYLON.Gamepad = BABYLON.SceneManager.gamepads.getGamepadByType(BABYLON.Gamepad.XBOX);
if (xbox != null) BABYLON.SceneManager.inputGamepadConnected(xbox, null);
var generic:BABYLON.Gamepad = BABYLON.SceneManager.gamepads.getGamepadByType(BABYLON.Gamepad.GENERIC);
if (generic != null) BABYLON.SceneManager.inputGamepadConnected(generic, null);

 

Link to comment
Share on other sites

  • 3 months later...

Hi all,

I'm trying to use the oculus controllers without having a vr camera.

As indicated in this doc : https://doc.babylonjs.com/how_to/webvr_camera it seems to be possible but the method used is obsolete ( see below ).

I tried to add this code

scene.gamepadManager.onGamepadConnectedObservable.add(function(pad) {
        alert("gamepad connected");
    })

to handle the connection but the alert is never called.

Can you show me how to use the new gamepadManager in this scenario ?

Thanks in advance

 

 

Quote

 

Controllers without WebVR camera

The controllers can also be initialized without using a WebVR camera, which means - you can use them to control your regular WebGL game or 3D application.

To do that, simply initialize the Gamepads Class:



new BABYLON.Gamepads((gp) => {
    if (gp.type === BABYLON.Gamepad.POSE_ENABLED) {
        // Do something with the controller!
    }
});

 

 

 

 

Link to comment
Share on other sites

My idea was to be able to do some object manipulations without having to put the headset on. It’s horrible to swap between VR and desktop mode often ( especially when you wear glasses like me ). So if there is an easy patch I can do locally It would be wonderful. BTW do you want me to delete my other thread ?

Link to comment
Share on other sites

What about getting positions when you have your controllers where they normally are and then swapping that in when in standard mode (maybe in update () replace when null with those values)?

Like you could emulate in the spec if position wasn't available:

https://immersive-web.github.io/webvr/spec/1.1/#vrpose-attributes

Might as well leave the other one open - hopefully there is a better way.

Link to comment
Share on other sites

Hi again,

I investigated and finally babylon's code is ok ! The positions are updated. My problem was stupid : when you don't put the oculus on your head, the headset enter in a kind of sleep mode.

In this "sleep mode" , the positions of the pads are not updated ( only their rotation ) if you wake up the headset ( by touching/moving it only), the pad positions are back !

Sorry for the inconvenience.

 

Meyer

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...