MackeyK24 Posted September 10, 2017 Share Posted September 10, 2017 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 Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted September 10, 2017 Author Share Posted September 10, 2017 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 ??? Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted September 10, 2017 Author Share Posted September 10, 2017 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 Quote Link to comment Share on other sites More sharing options...
davrous Posted September 11, 2017 Share Posted September 11, 2017 Adding @Deltakosh who had refactored the gamepad logic. I haven't run my previous tests on it yet on my side. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 11, 2017 Share Posted September 11, 2017 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 Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted September 11, 2017 Author Share Posted September 11, 2017 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); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 11, 2017 Share Posted September 11, 2017 Sure. I also added a gamepadManager.gamepads which is just the list of already connected gamepads Available with next commit Quote Link to comment Share on other sites More sharing options...
Meyer Posted January 10, 2018 Share Posted January 10, 2018 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! } }); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 10, 2018 Share Posted January 10, 2018 Unfortunately, the WebVR spec states that controllers must be added to the active gamepad list only when in VR mode Quote Link to comment Share on other sites More sharing options...
Meyer Posted January 11, 2018 Share Posted January 11, 2018 Thanks. FYI, just calling scene.createDefaultVRExperience(); fixed my problem even if I'am not in VR Mode. I got the callback, I got the rotations but the position vector for the controllers is not updated and stay null. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 11, 2018 Share Posted January 11, 2018 Not all controllers have a position. What controller are you using? Quote Link to comment Share on other sites More sharing options...
Meyer Posted January 11, 2018 Share Posted January 11, 2018 Oculus controllers. They have position when I enter un VR mode. Their meshes move/translate in VR mode, they only rotate in standard mode Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 11, 2018 Share Posted January 11, 2018 Positions are relative to VR headset, so doesn't make sense to me in standard mode. I don't think that breaks the spec. I don't have an Oculus device. edit: I see you started another thread. this should probably continue there. Quote Link to comment Share on other sites More sharing options...
Meyer Posted January 11, 2018 Share Posted January 11, 2018 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 ? Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 11, 2018 Share Posted January 11, 2018 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. Quote Link to comment Share on other sites More sharing options...
Meyer Posted January 12, 2018 Share Posted January 12, 2018 Hi, I'm new to babylonjs/Webvr so, to be honest, I do not really understand what you suggest me to do. But I will investigate ;-) Thanks for your help ! Have a nice day Quote Link to comment Share on other sites More sharing options...
Meyer Posted January 12, 2018 Share Posted January 12, 2018 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 Wingnut and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.