4

我正在尝试使用 React VR 创建一个 Web 应用程序并使用 Samsung Gear VR 运行它。

在我的场景中处于 VR 模式时,我看不到默认的白点(VR 指针)。因此,诸如“onInput”和“onClick”之类的方法不起作用。如果我在 VR 模式之外查看相同的场景,即使使用 Gear VR 中提供的浏览器,相同的方法也能正常工作。

我错过了什么吗?在 Gear VR 的 VR 模式下如何访问这些方法?

在普通网络浏览器中运行良好的示例代码(包括 Gear VR 中的那个),但在我使用 VR 时却不行。

<Text
    style={{
        // backgroundColor: '#777879',
        fontSize: 0.2,
        transform: [{translate: [0, 0, -5]}],
        color: this.state.textColor
    }}
    onEnter={() => this.setState({textColor: 'gold'})}
    onExit={() => this.setState({textColor: 'white'})}>
    This text will turn gold when you look at it.
</Text>
4

1 回答 1

6

您需要添加一个光线投射器:

为此,您需要执行以下操作:

在您的项目中,转到<project root>/vr/client.js. 就在init方法之前,添加一个SimpleRaycaster常量。

const SimpleRaycaster = {
    getType: () => "simple",
    getRayOrigin: () => [0, 0, 0],
    getRayDirection: () => [0, 0, -1],
    drawsCursor: () => true
};

function init(bundle, parent, options) {

//...

然后,在该init方法中,设置 cursorVisibility: visibleraycaster 并将其添加到 的数组中raycasters

function init(bundle, parent, options) {
  const vr = new VRInstance(bundle, 'Example', parent, {
      raycasters: [
          SimpleRaycaster // Add SimpleRaycaster to the options
      ],
      cursorVisibility: "visible", // Add cursorVisibility
      enableHotReload: true,
    ...options,
  });
  vr.render = function() {
    // Any custom behavior you want to perform on each frame goes here
  };
  // Begin the animation loop
  vr.start();
  return vr;
}

window.ReactVR = {init};

就是这样。现在您的视图中间应该有一个白点。

于 2017-07-06T12:30:52.600 回答