在 Oculus 浏览器中通过 GamePad API 访问 Oculus Go 控制器? [英] Access Oculus Go Controller via GamePad API in Oculus Browser?

查看:32
本文介绍了在 Oculus 浏览器中通过 GamePad API 访问 Oculus Go 控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的新 Oculus Go 中测试我的几个 Three.js 应用程序.我想知道是否可以仅使用 GamePad API 来访问控制器,现在似乎在主要浏览器中可用.

I'm testing out a couple of my three.js apps in my new Oculus Go. I'm wondering if it's possible to access the controller just using the GamePad API that seems to be available today with the major browsers.

查看 Oculus 文档,似乎可以通过 Unity 自带的 OVRManager 或通过 UnReal Blueprints 来完成.但我正在努力避免另一条学习曲线,并在可以避免的情况下扩大我的应用程序.

Looking at the Oculus documentation, it seems like it can be done through the OVRManager that comes with Unity, or through UnReal Blueprints. But I'm trying to avoid another learning curve, as well as bulking up my apps if I can avoid it.

作为 VR 的新手,似乎最有利的方式是通过使用 Gamepad API 执行类似的操作(这里面的内容还不是工作代码,但我正在尝试在这种方法的问题上,除了在我进入 VR 模式时破坏应用程序之外,目前没有任何结果):

As a newbie to VR, it seems the most favorable way to proceed would simply be with using the Gamepad API by doing something like this (the guts of this isn't working code just yet, but I'm trying to get at the problem with this sort of approach, and no results so far other than breaking the app when I go into VR mode):

var gamePadState = {
  lastButtons: {},
  lastAxes: {}
};

function onGamePad(){

    Array.prototype.forEach.call( navigator.getGamepads(), function (activePad, padIndex){
      if ( activePad.connected ) {
        if (activePad.id.includes("Oculus Go")) {
          // Process buttons and axes for the Gear VR touch panel
          activePad.buttons.forEach( function ( gamepadButton, buttonIndex ){
            if ( buttonIndex === 0 && gamepadButton.pressed && !lastButtons[buttonIndex]){
              // Handle tap
              dollyCam.translateZ( -0.01 );
            }
            gamePadState.lastButtons[buttonIndex] = gamepadButton.pressed;
          });

          activePad.axes.forEach( function (axisValue, axisIndex ) {
            if (axisIndex === 0 && axisValue < 0 && lastAxes[axisIndex] >= 0 ){
              // Handle swipe right
            } else if (axisIndex === 0 && axisValue > 0 && lastAxes[axisIndex] <= 0) {
              // Handle swipe left
            } else if (axisIndex === 1 && axisValue < 0 && lastAxes[axisIndex] >= 0) {
              // Handle swipe up
            } else if (axisIndex === 1 && axisValue > 0 && lastAxes[axisIndex] <= 0) {
              // Handle swipe down
            }
            gamePadState.lastAxes[axisIndex] = axisValue;
          });
        } else {
          // This is a connected Bluetooth gamepad which you may want to support in your VR experience
        }
      }
    });

}

另一个更窄的问题中,我提出了这个问题主题,我被建议在我的应用程序中创建一个 Unity 构建以获得我想要的结果,这似乎既是额外的学习曲线,又增加了我的开销.如果需要,我会这样做,但如果我不这样做,我宁愿不这样做.

In another, narrower question I posed on this topic, I was advised to create a Unity build in my app to get the results I wanted, which seems like both an additional learning curve, plus bulking up my overhead. I'll do it if I have to, but I'd rather not, if I don't.

最终,我希望能够使用如下逻辑支持大多数主要"控制器:

Ultimately I'd like to be able to support most of the "major" controllers using logic like this:

onGamePad( event ){

    var gamePads = navigator.getGamepads();

    if ( gamePads && gamePads.length > 0 && event.isSomeGamePadEventOfSomeSort ){
        for ( var p = 0; p < gamePads.length; p ++ ){
            if ( gamePads[ p ].id.includes( "Oculus Go" ) ){
                // process buttons and axes for the Oculus Go Controller here
                if ( event[ some property... gamePad?? ].id.includes( "Oculus Go" ) && event[ some property... gamePad?? ].button.pressed === someIndex ){
                    doSomething();              
                }
            }
            else if ( gamePads[ p ].id.includes( "Oculus Gear VR" ){
                // Process buttons and axes for the Oculus Gear VR Controller here...
            }
        }
    }

}

但出于测试目的,我会很感激现在让 Oculus Go 控制器运行起来.

But for testing purposes I'd be grateful just to get the Oculus Go controller going for now.

那么...是否可以通过 Gamepad API 访问 Oculus Go 控制器,以及如何访问设备属性,例如按钮、轴和方向以及相关的游戏手柄事件?

So... Is it possible to access the Oculus Go controller via the Gamepad API, and how can I access the device properties such as buttons, axes and orientation, and related gamepad events?

谢谢.

推荐答案

当然,您可以直接使用 Gamepad API,而无需求助于 Unity.几个月前我写了自己的 Oculus Go controller 并且它需要的代码比您想象的要少得多.由于我的代码已在 GitHub 上免费提供,因此我不会将其复制到此站点.

Of course you can use the Gamepad API directly without recourse to Unity. Some months ago I wrote my own Oculus Go controller and it takes far less code than you'd think. Since my code is already freely available on GitHub, I'm not copying it to this site.

这篇关于在 Oculus 浏览器中通过 GamePad API 访问 Oculus Go 控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆