© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
C. CoutinhoUnity® Virtual Reality Development with VRTK4https://doi.org/10.1007/978-1-4842-7933-5_5

5. Setting Up VRTK’s Camera Rigs

Christopher Coutinho1  
(1)
GameWorks, Mumbai, Maharashtra, India
 

You might have noticed that the demo scene provided has no camera in it. In this chapter, we will begin setting up our VRTK Camera Rig with several camera prefabs. We will first set up a Unity XR Camera Rig, which can be thought of as a universal camera that will work with HTC Vive and Oculus headsets. Next, we will implement the Oculus Camera Rig, which explicitly uses the Oculus Integration SDK you downloaded. This Oculus Camera Rig will work exclusively with the Oculus headset. We will then put in place a specialized Spatial Simulator rig, which VRTK provides to enable you to run your VR projects within Unity’s editor. Next, we will set up the Tracked Alias prefab, which can represent any XR hardware. All of this is made available via Tilia packages within the “Packages” folder. Finally, we will go on to test your VR scene using the Spatial Simulator as well as your VR headset.

Setting Up Individual Camera Rigs

Let’s first set up the individual Camera Rigs within the Demo scene. We’ll begin by creating a new empty game object at the root of your Demo scene. Name this game object “[VRTK_SETUP]” and reset its transform. Then, add another empty game object as this object’s child. Name this child game object “[VRTK_CAMERA_RIGS_SETUP].” All the Camera Rig prefabs you add to your Demo scene will reside as children within this child game object.

Change the Transform Position values for this [VRTK_CAMERA_RIGS_SETUP] game object to: X = -12.75; Y = 0; and Z = -6. Then, change the Transform Rotation values for this game object to: X = 0; Y = 0; and Z = 0.

These values will ensure that you are facing forward within your VR world.

Setting Up the Unity XR Camera Rig

With your [VRTK_CAMERA_RIGS_SETUP] game object selected in the hierarchy, navigate to the Project tab and expand the “Packages” folder. Then, navigate to the “Tilia Camera Rigs, Unity XR” package folder and expand it until you reach its “Prefabs” folder. In the right pane, you will see the Camera Rigs, Unity XR prefab. Drag and drop this prefab onto the [VRTK_CAMERA_RIGS_SETUP] game object in the hierarchy, making it a child, as shown in Figure 5-1. Your Demo scene now finally has its first camera in it.
Figure 5-1

Setting up Camera Rigs in Unity XR

Setting Up the Oculus Camera Rig

With your [VRTK_CAMERA_RIGS_SETUP] game object selected in the hierarchy, navigate to the Project tab and expand the “Packages” folder. Then, navigate to the “Tilia SDK, Oculus Integration, Unity” package folder and expand it until you reach its prefabs folder. In the right pane, you’ll notice the Camera Rigs, Oculus Integration prefab. Drag and drop this prefab onto the [VRTK_CAMERA_RIGS_SETUP] game object selected in the hierarchy, making it a child, as shown in Figure 5-2. To accommodate this Camera Rig, Oculus Integration prefab, we downloaded version 29 of the Oculus Integration SDK from the Unity asset store.
Figure 5-2

Setting up Camera Rigs Oculus integration

Setting Up the Spatial Simulator

The Spatial Simulator allows you to run your VR project within Unity’s editor itself without the need to mount your headset each time you want to perform a test run. It uses the standard keyboard and mouse input to function. An exciting aspect of the Spatial Simulator is that it even works with an Xbox controller. By connecting an Xbox controller to your computer, you can have all the basic VR controller functionality available to you for testing within Unity’s editor. This makes debugging your VR project a whole lot easier.

With your [VRTK_CAMERA_RIGS_SETUP] game object still selected in the hierarchy and with the “Packages” folder expanded, navigate to the “Tilia Camera Rigs, Spatial Simulator, Unity” package folder and expand it until you reach its “Prefabs” folder. In the right pane, you’ll notice the Camera Rigs, Spatial Simulator prefab. Drag and drop this prefab onto the [VRTK_CAMERA_RIGS_SETUP] game object in the hierarchy, making it a child, as shown in Figure 5-3.
Figure 5-3

Setting up Camera Rigs Spatial Simulator

Setting Up the Tracked Alias

As discussed later in this chapter, the Tracked Alias is a generic Camera Rig representing XR hardware. It is also the last Camera Rig prefab you need to attach to your [VRTK_CAMERA_RIGS_SETUP] game object as its child. With this game object still selected in the hierarchy and the “Packages” folder expanded, locate the “Tilia Camera Rigs, Tracked Alias, Unity” package folder and expand it until you reach its “Prefabs” folder. In the right pane, you’ll notice the Camera Rigs, Tracked Alias prefab.

Drag and drop this prefab onto the [VRTK_CAMERA_RIGS_SETUP] game object in the hierarchy, making it a child, as shown in Figure 5-4.
Figure 5-4

Setting up the Camera Rigs, Tracked Alias prefab

The Camera Rigs prefabs previously discussed can also be accessed via Unity’s main menu by going to Game Object ➤ Tilia ➤ Prefabs ➤ Camera Rigs. There, you’ll find all the prefabs that you just set up, and you could have set them up using this menu option, too.

Note

For the Camera Rigs, in the Tracked Alias Facade component of the Tracked Alias game object in the hierarchy, you may find that the Tracked Alias Settings, Elements property isn’t visible in the Inspector. If this is the case, you need to shut down Unity entirely and restart it, and this property will then become visible. This uncanny behavior doesn’t happen when using version 2019.4.x of Unity LTS. It seems to only be an oddity with version 2020.3. x of Unity LTS. Any time you find VRTK component properties missing, you’ll need to restart Unity.

Configuring the VRTK’s Tracked Alias

The Tracked Alias is a sort of generic Camera Rig that can represent any type of hardware. An Oculus Camera Rig, Steam VR Camera Rig, Unity XR Camera Rig, or a Spatial Simulator Camera Rig can all be hooked up to a Tracked Alias. If you activate the Camera Rig you want to use, you can leave the rest to the Tracked Alias. From then on, whatever you need to do, you can do it against this Tracked Alias. This way, you don’t need to worry about the different Camera Rigs you have in your scene and how you should handle them. The Tracked Alias allows you to track any active valid SDK Camera Rig that has been included within the Elements list of the Tracked Alias settings, which is essentially a list of Camera Rigs within your scene. Thus, you can track any active Camera Rig in your scene that has been hooked up to the Tracked Alias without being explicitly tied to it.

Hooking Camera Rigs to the Tracked Alias

In the [VRTK_CAMERA_RIGS_SETUP] game object in the hierarchy, select its child game object, Camera Rigs, Tracked Alias. Within the Inspector, ensure that its Tracked Alias Facade component has been expanded. Locate the Tracked Alias, Elements, Size property (zero by default) within this component. This property is shown in Figure 5-5. Note that this is the property I was referring to in the Note as potentially not being visible, explaining that if you restart Unity, it will resurface.
Figure 5-5

Camera Rigs hooked up to the Tracked Alias

Change the value of this Size property to 3, as you have three Camera Rigs available for your use in the form of element slots. Drag and drop the Camera Rigs, Unity XR game object from the hierarchy into the newly created Element 0 slot of the Tracked Alias Settings property. Next, drag and drop the Camera Rigs, Oculus Integration game object into the Element 2 slot of the Tracked Alias Settings property. Then, drag and drop the Camera Rigs, Spatial Simulator game object into the Element 3 slot of the Tracked Alias Settings property. Now your Tracked Alias Settings will have three cameras listed, any of which your Tracked Alias can now utilize. However, you need to ensure that you keep just one Camera Rig active from within the [VRTK_CAMERA_RIGS_SETUP] game object in the hierarchy. The active Camera Rig is the one that the Tracked Alias will use. Figure 5-5 shows the Tracked Alias Facade component, with its Tracked Alias Settings property values.

Test using the Spatial Simulator

Now that your Tracked Alias has been set up, it’s time for you to test your scene within Unity’s editor using the Camera Rigs, Spatial Simulator. As mentioned earlier, you first need to ensure that you have just one Camera Rig active in the hierarchy. The Camera Rigs, Spatial Simulator should be the active Camera Rig, as you’ll be testing using Unity’s editor.

From within the [VRTK_CAMERA_RIGS_SETUP] game object in the hierarchy, select the Camera Rigs located above the Spatial Simulator, Camera Rigs, Unity XR, and Camera Rigs, Oculus Integration. Within the Inspector, uncheck the box to deactivate both of these Camera Rigs. Ensure that the only active Camera Rigs are the CameraRigs.SpatialSimulator and the Camera Rigs.Tracked Alias, as shown in Figure 5-6.
Figure 5-6

Camera Rigs deactivated in the hierarchy to playtest scene in Unity’s editor

Now hit the Play button within Unity’s editor toolbar and wait a couple of seconds for your playable scene to load within Unity’s editor. Once your playable scene is up and running, you can use your mouse to rotate yourself about as well as look up and down. The yellow and red pins represent your simulated left and right controllers. Pressing number two on the keyboard will activate the movement and rotation of your left controller pin. Pressing number three will activate the movement and rotation of your right controller pin . Pressing number one will deactivate the movement and rotation of both the simulated left and right controllers. It will instead activate the movement and rotation of the simulated play area . To enable yourself to move within your VR world , you need to ensure that you have first exited the left or right controller movement and rotation mode by pressing number one on the keyboard. Now you can use the W, A, S, and D keys on your keyboard to move about within your VR world.

Universal Camera Rig

You can think of the Unity XR Camera Rig as a universal Camera Rig that you can use with your HTC Vive and Oculus headsets. If you’re developing for Steam VR devices, such as the HTC Vive, you can only use the Camera Rigs, Unity XR setup. On the other hand, if you’re developing solely for Oculus devices, such as the Oculus Rift or the Oculus Quest, you would be better off using the Camera Rigs, Oculus Integration setup. Note that you can use your Oculus headset with the Camera Rigs, Unity XR setup, too. However, you can’t use your HTC Vive headset with the Camera Rigs, Oculus Integration setup.

Configuring the Oculus OVR Camera Rig

The child game object, OVR Camera Rig , within the Camera Rigs, Oculus Integration game object, requires one of its property values to be changed. To do so, select and expand the Camera Rigs, Oculus Integration game object in the hierarchy from within the [VRTK_CAMERA_RIGS_SETUP] game object. Now select its OVR Camera Rig child object, and in the Inspector, ensure that its OVR Manager component is expanded. Locate the Tracking Section, within which you’ll find the property Tracking Origin Type. By default, this property has been set to Eye Level. Change the property to Floor Level using the drop-down beside the property.

Testing Spatial Movement Using a VR Headset

Now it’s time to test out spatial movement within your VR world using your VR headset. If you’re using an Oculus headset, you can deactivate Camera Rigs, Unity XR in the hierarchy and instead activate Camera Rigs, Oculus Integration. On the other hand, if you’re using an HTC Vive headset, you need to ensure that Camera Rigs, Oculus Integration has been deactivated and Camera Rigs, Unity XR has been activated. Always ensure that only one Camera Rig is active in the hierarchy. As you’ll be testing with your VR headset, only one Camera Rig can be active in the hierarchy, so you’ll need to deactivate the Camera Rigs, Spatial Simulator. As discussed earlier, this simulator is only used when you want to playtest within Unity’s editor.

Hit the Play button and mount your VR headset. You’ll now be able to look around your VR world and you’ll also be able to physically move within it, constrained to the limits of your Chaperone or Guardian boundary setup. You don’t have your controllers set up yet, so there isn’t much to do other than walk around.

Summary

In this chapter, we went over how to set up the VRTK’s Camera Rigs. We looked at about the different types of Camera Rigs that the VRTK provides you with that are accessible via its Tilia packages. We then went about setting up each of these individual Camera Rigs. You learned about the Tracked Alias into which all your Camera Rigs are hooked up. You also learned about the Spatial Simulator and how it can be used for playtesting within Unity’s editor. We went on to playtest the VR scene within Unity’s editor using the Spatial Simulator. You learned about the universal Camera Rig that the VRTK has made available to you. We then configured the Oculus OVR Camera Rig, and finally tested spatial movement within our VR world using the VR headset.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.44.23