Unity's OpenXR+XR Interaction Toolkit connected to HTC Vive

I. Introduction

At present, the most popular device in the field of VR is HTC VIVE. In the past, when connecting to the HTC VIVE device on the Unity side, it was connected through SteamVR+VRTK. However, with the version upgrade of Unity and the popularity of the OpenXR standard, coupled with the gradual increase of VR devices. The way of SteamVR+VRTK can no longer better meet everyone's needs.

What I will share with you today is how to access VR through the OpenXR standard based on Unity2020 or Unity2021. It can be adapted to all VR devices at the same time, including HTC ViVE, Pico, Occlus, etc. In the future, no matter what the device is, as long as the API conforms to the OpenXR standard , we can access it through Unity's OpenXR method, and the access process is very simple, and it is simpler and more convenient to use than the previous SteamVR+VRTK method, which can be said to serve multiple purposes.

2. What is OpenXR

OpenXR aims to standardize specifications between devices and applications on various VR/AR platforms. It was formulated by the Khronos Group , an organization of VR/AR related companies. Microsoft, HTC, Valve and many other companies participated.

1. Background of the emergence of OpenXR

With the upsurge of VR and AR, more and more software companies have begun to enter this field, and more and more VR/AR devices have appeared at the same time. To use different SDKs for application development. In the absence of cross-platform standards, high development costs will certainly restrain the growth of the market. As shown in the diagram below:
insert image description here
The OpenXR Working Group believes we can help address these issues through standardization. Standards will allow app developers to spend more time creating amazing experiences and less time making experiences work on countless hardware combinations. It will also enable device vendors to offer more content on their platforms and will future-proof their investments.

2. Khronos Group

The Khronos Group team was established in January 2000 by a number of internationally renowned multimedia industry leaders including 3Dlabs, ATI, Discreet, Evans & Sutherland, Intel, Nvidia, SGI and Sun Microsystems, and is committed to developing the application of open standards Program interface API to realize rich media creation on various platforms and terminal devices.
OpenXR provides cross-platform, high-performance direct access to various XR device runtimes across multiple platforms.
OpenXR enables applications and engines (including WebXR) to run on any system that exposes an OpenXR API.
insert image description here
All in all, OpenXR is an important milestone in the field of VR. This API will allow games and other applications to run easily on various hardware platforms without the need for a proprietary SDK.

3. Unity access process

We can use the VR template that comes with UnityHub to create a project. Here I complete the configuration of the VR project step by step by creating an empty 3D project, and finally adapt to the VR project of HTC Vive.

1. Create 3D project

Create a 3D empty project, or a 3D (URL) empty project, because 2021 actually officially recommends building a rendering pipeline using URL, so we might as well just do it in one step.
insert image description here

2.Install XR Plugin Manager

Open the Edit->ProjectSettings-> XR Plugin Management panel, and then click Install XR Plugin Management to install the XR Plugin.
insert image description here
After the XR Plugin is installed, as shown in the figure below:
insert image description here
Check OpenXR, it will prompt that the OpenXR plug-in needs to use the new Input System system, and the project creation When using the old input system by default, you need to restart the Unity editor to upgrade the input system to the new Input System. As shown in the figure below:
insert image description here
After restarting the Unity editor, we will find an OpenXR submenu under XR Plugin Management.
We add several necessary configurations for developing HTC Vive under his Interaction Profiles. As shown in the figure below:
Here we need to explain that we can add any profile for any device we want to be compatible with. I use HTCVive. In theory, I should only add the HTC profile, but it seems to be a little problem. When I add Oculus After Touch Controller Profile the problem is solved.
The settings of Render Mode can be changed according to requirements. I usually change the Single Pass Instanced in Render Mode to Multi Pass. Multi Pass will render the scene twice and display it in two eyes respectively. Although the performance of this rendering method will be worse, it has high compatibility.
insert image description here

3. Import the plug-in XR Interaction Toolkit

Open PackageManager, then click Unity Registry, search for the plug-in XR Interaction Toolkit, and click Install to install.
Select the latest version to install. After installation. If the version displayed is not the latest when we install, we can install by name, click the "+" sign in the upper left corner, and select Install package by name. Then enter: com.unity.xr.interaction.toolkit to import the latest version.
insert image description here

4. Import Sample

Import the Starter Assets package in Sample. It contains some things related to Preset and Input System.
Import the XR Device Simulator package in Sample, which contains the things that the XR simulator should close first.
After importing, it looks like the following figure:
insert image description here

5. Add Preset

We select Starter Assets, then select the Presets marked in the figure below, and click the Add To ActionBasedContinuousMoveProvider default button on the Inspector panel.
This function is convenient for us to quickly and automatically add a certain operation configuration to the object. No need to manually configure one by one. As shown in the figure below:
Refer to the official document
insert image description here and take the Preset configuration prepared for us in Starter Assets, which can greatly simplify our subsequent development work. Therefore, the same is true for other Presets, we can click the Add button in the Inspector panel.

6. Set the Filter of PresetManager

We click Edit -> Project Settings -> Preset Manager: We see the several Presets just added, we just set the name of the object for its Filter, for example, XRI Default Right Controller corresponds to Right. XRI Default Left Controller is Left.
insert image description here
The role of Filter
Controller generally refers to the handle, XR Interaction Toolkit provides the ActionBasedController script to track the gesture of the handle and handle the input action of the handle. Let’s take a look at what this script looks like in the Inspector panel [in fact, it will be displayed as XR Controller (Action-based) in the panel]
insert image description here
We can see that there are a large number of handle actions in the control script of the handle above, such as selecting, taking , click the UI, etc., corresponding to the Input operations of each Reference, such as trigger button, grab button, etc., which are configured in XRI Default Input Actions.
insert image description here
The purpose of configuring the Filter is that after adding the Controller script, there is no need to manually specify the Preset, and the system will automatically identify the corresponding left-hand or right-hand Preset according to the Filter. If you don't set the Filter, of course, you can also manually specify the Preset of the left and right hands

4. Run Demo

1. Official demo

Unity provides us with a demo of XR Interaction Toolkit, we can run the test directly and learn how to modify the VR scene according to the demo
insert image description here

2. Custom Demo

Next, we don't use the official scene, we customize the scene, and then add VR-related scripts and run it.

1. Create a scene

We create a simple scene, add the ground, and add a few simple boxes as environments.

2. Add XR Origin

XR Origin is our VR controller, which includes the control of VR headset and VR controller. We can right-click to create it in the scene, as shown in the figure below: After creation, as shown in the figure below: We can see that there is an
insert image description here
extra
insert image description here
XR Interaction Mangaer, and an XR Origin
XR Origin also includes Camera Offset and the following two handle controls.
We can see that the created Hand Controller has automatically created the XR Controller (Action-Based) script for us, and automatically bound all the action presets of the left hand for us. This is because we added the controller's Preset and set the Filter earlier.

Ok, now you can run it in the emulator and try it out. As shown in the figure below:
insert image description here
the panel in the lower left corner is the XR Device Simulator panel, which is used for the simulation of VR control in the Unity editor.

Guess you like

Origin blog.csdn.net/qq563129582/article/details/130211641