VR开发之VRTK插件使用(一)

  最近在做VR的开发工作,因此在这里记录一下自己关于VR开发的经验。

  目前,VR开发基本是使用了VRTK插件来做,方便快捷,可以省不少功夫,而且VRTK本身也包含了很多例子供我们参考学习,这是一大福音。

  先放链接,这是VRTK的官网 https://vrtoolkit.readme.io/docs/summary

  关于VRTK的插件,我们可以从上述网站中直接下载,导入到工程里面使用;如果是用Unity来开发,也可以在资源商店里面去下载插件。

  下面进入正题,第一次做VR开发,首要目标当然是:在头盔里能看到我们的场景。

  如果我们想要省事,可以按照VRTK的例子程序,直接搬过来使用就可以达到目标;如果不嫌麻烦,我们可以参照官方文档还有例子程序,一步步实现目标。现在我们就不嫌麻烦的,来看看怎么一步步实现目标。

  假设我们用Unity开发。首先,我们要导入VRTK的插件,这没什么好说。

  1. 新建一个空的对象,这里命名为【VRTK】,把VRTK_SDK Manager脚本拖过去;

  2. 在该对象下再建一个子对象,根据我们使用的VR设备,赋予它相应的脚本。这一步,在官网有详细的指导,我们来看一下。

  

USING VRTK IN YOUR OWN PROJECT

  • Download or clone vrtk.
  • Import the Assets/VRTK folder into your Unity project.
  • Add the VRTK_SDKManager script to a GameObject in the scene.

扫描二维码关注公众号,回复: 2172311 查看本文章

The SDK Manager handles setting up everything to use the various supported SDKs via VRTK_SDKSetups. To use a VR SDK the following steps are needed:

  • Download and import the SDK into the project.
  • Create a new empty game object.
    • Add VRTK_SDKSetup to it.
    • Add the VR SDK's game objects (e.g. the Camera Rig) as children.
    • On the SDK Setup set the SDK Selection to the respective VR SDK.
    • Make sure all the Object References are set correctly by Auto Populate or set them manually.
  • On the SDK Manager under Setups add a new slot and select the SDK Setup for that slot.

Repeat the steps above to add additional SDK Setups to the SDK Manager.

If the Auto Load setting on the SDK Manager is enabled the SDK Setups are automatically loaded in the order they appear in the list:

  • The first Setup that is usable (i.e. initializable without errors and the HMD is connected) will be used.
  • If a Setup can't be used the next one will be tried instead.
  • If no Setup is usable VR support is disabled.

The SDK Manager allows switching the used SDK Setup at runtime. To add a simple overlay GUI to do so add the SDKSetupSwitcher prefab from VRTK/Prefabs to the scene.

Read the rest of this document for more detailed instructions on how to set up and use the supported VR SDKs.

VR Simulator

Instructions for using the VR Simulator

  • Follow the initial steps above by adding the VRSimulatorCameraRig prefab from VRTK/Prefabs as a child of the SDK Setup game object.
  • Use the Left Alt to switch between mouse look and move a hand.
  • Press Tab to switch between left/right hands.
  • Hold Left Shift to change from translation to rotation for the hands.
  • Hold Left Ctrl to switch between X/Y and X/Z axis.
  • Additional button mappings can be found on SDK_InputSimulator on the prefab.
  • All button mappings can be remapped using the inspector on the prefab.

SteamVR

Instructions for using SteamVR

  • Import the SteamVR Plugin from the Unity Asset Store.
  • Follow the initial steps above by adding the [CameraRig] prefab from the plugin as a child of the SDK Setup game object.

Oculus

Instructions for using Oculus Utilities

  • Download the Oculus Utilities from the Oculus developer website.
  • Import the .unitypackage.
  • Follow the initial steps above by adding the OVRCameraRig prefab from the Utilities as a child of the SDK Setup game object.
  • On the OVRCameraRig in the scene find the OVRManager and set its Tracking Origin Type to Floor Level.
  这里我只截取了部分文档,可以看到,针对不同的VR设备,我们需要绑定不同的脚本,如此才能正确的使用我们的设备。
   这里,我使用的设备是HTC 的VIVE,所以使用的是SteamVR,则命名对象为SteamVR。并按照文档所说的,添加SteamVR插件里的CameraRig和SteamVR预制体,并设置好子物体SteamVR下的VRTK_SDK Setup脚本的相关属性,可以参照VRTK的例子来设置。

  3. 把VRTK预制的SDKSetupSwitch作为【VRTK】的子对象,拖入场景中

  4.设置【VRTK】,设置脚本VRTK_SDK Manager的Setup属性快,在Auto Load 下面,添加SteamVR 引用。

  到此,我们运行程序,如果没有意外,在VR头盔就可以看到我们的设计场景了。

猜你喜欢

转载自blog.csdn.net/lwsas1/article/details/78222485