© Rakesh Baruah 2020
R. BaruahVirtual Reality with VRTK4 https://doi.org/10.1007/978-1-4842-5488-2_1

1. Setup

Rakesh Baruah1 
(1)
Brookfield, WI, USA
 

To begin developing immersive experiences with Unity and VRTK, we must first download and install the required tools. These tools include: Unity, an integrated development environment (IDE), and Git for either Windows or Mac.

I’m not going to lie to you: Setting all of this up might not be easy. There are many steps, and many points at which something could go wrong. I will try to be as agnostic in regard to platform as I can, but I am accustomed to developing with Unity on a PC running Windows 10. Unity is cross-platform, though, for both your development environment as well as deployments. Both Windows and MacOS are supported. To be certain that I provide you with the most accurate depiction of what I know and have learned, I will refrain from speculating about what you might encounter in your environment. At the same time, I will do my best to anticipate errors you might receive while downloading, installing, and running your program.

With all that said, the resources available online for the tools we need to run Unity and VRTK on our machines are abundant. All that you require to find the answers you might need is enough information to know the question you want to ask. It is with that axiom in mind, the standard operating procedure of the developer’s secret weapon—Google—that I relay to you what I know. VR and the tools for its creation like VRTK are a bleeding-edge medium. As such, unknowns, hiccups, and missteps abound. I will do my best to make the trial by fire as illuminating as it will be hot.

In this chapter you will learn how to do the following:
  • Download and install Unity.

  • Download and install an IDE.

  • Download and install Git.

  • Clone the VRTK GitHub repository.

  • Set up the Unity Editor for a VR project.

  • Run the VRTK sample scene in Unity.

Downloading and Installing Unity

Let us begin. Unity is a robust 3D engine that provides an interface to create many kinds of experiences. Because of its versatility, Unity can demand significant resources from your local machine. Before downloading and trying to install Unity on your computer, confirm that your system meets the minimum standards for Unity development. As of this writing, the most recent version of Unity to have been released is Unity 2019.3 (August 28, 2019). The Unity web site also allows the download of its Unity Hub application, which makes it easier for developers to manage installs, licenses, and projects. I, personally, use Unity Hub, but foregoing the Hub for just a Unity installation will not impair your ability to follow along with the text. Next I provide the system requirements listed by Unity on its web site. Check the most recent requirements to confirm your computer’s setup will work with the version of Unity or Unity Hub you download and install.

System Requirements for Unity Development

The following are the system requirements:
  • OS: Windows 7 SP1+, 8, or 10, 64-bit versions only; MacOS 10.12+.

  • Server versions of Windows and OS X are not tested.

  • CPU: SSE2 instruction set support.

  • GPU: Graphics card with DX10 (shader model 4.0) capabilities.

The rest depends primarily on the complexity of your projects.

Additional Platform Development Requirements

Additional requirements are as follows:
  • iOS: Mac computer running minimum MacOS 10.12.6 and Xcode 9.4 or higher.

  • Android: Android SDK and Java Development Kit (JDK); IL2CPP scripting back end requires Android Native Development Kit (NDK).

  • Universal Windows Platform: Windows 10 (64-bit), Visual Studio 2015 with C++ Tools component or later and Windows 10 SDK.

From the Unity web site you can download a free version of the application for beginners. To use VRTK with Unity you must run a version of Unity no earlier than version 2018.

The Code Editor, an Integrated Development Environment

Although Unity is an interface that allows easy, direct creation of VR experiences, it still requires the use of a third-party IDE. As you will learn, Unity allows us to write scripts to perform actions in our Unity program. For Unity to read these scripts, we must provide it with an IDE, or code editor. I like to think of an IDE as a word-processing application like Microsoft Word. An IDE simply provides us a place to write and store our code. Because we write Unity code in a programming language called C#, we cannot use a word processor that only understands human language syntax. A key difference between an IDE and a word processor is the IDE’s inclusion of a compiler. A compiler translates the C# code we write in our IDE into the machine code computers understand.

If you ask a dozen Unity developers from around the world their preferred IDE to use with Unity, you’ll get a dozen answers. The only right answer is the one that is right for you. Unfortunately, finding an IDE that interacts IDE-ally (code editor pun!) with your peccadillos is a product of taste, time, and experience. To jump-start things, however, I offer you two of the most common code editors Unity developers tend to choose for their creative process. If you will use Unity on a Windows machine then I recommend Microsoft Visual Studio Community Edition, which is an optional install within the Unity Installer. As a Windows 10 developer, I personally prefer the Microsoft Visual Studio IDE, which has been updated to a 2019 edition called VS 2019. Visual Studio is a fully loaded code editor that can create enterprise-level applications. However, it is a large install with demands on your computer’s hardware. Its power might be excessive for a developer interested only in creating Unity applications. Another popular choice for a code editor to use with Unity is the lightweight Visual Studio Code, commonly called VS Code. It shares many similarities with its older sibling, Visual Studio, yet its smaller footprint and cross-platform compatibility make it popular among Mac developers and creators operating streamlined machines. Both code editors are available for free online. The free version of Visual Studio is its Community Edition.

The download addresses for Visual Studio and VS Code lead to both detailed requirements for your system and installation instructions for use with Unity. These IDEs are not the only options available to you to create VR experiences in Unity. They are, however, the most popular and therefore most helpfully discussed in online forums.

Downloading and Installing Git

The third application we must download to make full use of Unity and VRTK is called Git. Git is a free and open source distributed version control software. It allows for the sharing of code online. Downloading Git for your operating system allows you to connect to code repositories other developers have set up to share their code. I like to think of Git as a Google Drive or DropBox for code. Software packages are too large and unwieldy to share as attachments to e-mails or as single documents in a shared folder. Git enables us to clone people’s projects so that we can manipulate and run their code on our local machine. For the purposes of the exercises in this book, we will use Git and its Git Bash feature to download the VRTK files required for integration into Unity. Information for downloading, installing, and setting up Git for Windows and Mac OS can be found here:

Once you’ve downloaded and set up the necessary applications to begin developing immersive experiences in Unity and VRTK, meet me in the next section where we will test whether or not everything is ready and up to code (get it?).

Setting Up Unity and VRTK

When Unity, an IDE, and Git are set up on our local computers, we are finally able to create a Unity project and install VRTK. Bookmark this section, as it will be a valuable resource during your immersion into Unity and VRTK. You might find yourself referring to it often. To install VRTK into a Unity 3D project, follow these steps:
  1. 1.

    Open Unity and create a new 3D project.

     
  2. 2.
    Select the default layout of the Unity application by selecting Main Menu ➤ Window ➤ Layout ➤ Default (Figure 1-1).
    ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig1_HTML.jpg
    Figure 1-1

    Select the Unity Default layout

     
  3. 3.
    In Unity, navigate to Main Menu ➤ Edit ➤ Project Settings (Figure 1-2).
    ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig2_HTML.jpg
    Figure 1-2

    Select the Project Settings for the Unity project

     
  4. 4.
    In the Project Settings dialog box, navigate to the left-hand tab titled Player (Figure 1-3).
    ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig3_HTML.jpg
    Figure 1-3

    The Player tab on the Project Settings dialog box houses VR-related properties in a Unity project

     
  5. 5.

    Near the bottom of the Player tab, click the XR tab.

     
  6. 6.
    Select the Virtual Reality Supported check box (Figure 1-4).
    • Your installation of Unity might show additional parameters for your project’s XR Settings. For example, your installation might show a check box to create support for Vuforia Augmented Reality or other head-mounted displays.
      ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig4_HTML.jpg
      Figure 1-4

      XR settings can be found on the Player tab in the Project Settings dialog box

     
  7. 7.
    Navigate to Main Menu ➤ Window ➤ Package Manager (Figure 1-5).
    ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig5_HTML.jpg
    Figure 1-5

    Access the Unity Package Manager

     
  8. 8.
    Near the bottom of the left-hand column in the Unity Package Manager locate the XR Legacy Input Helpers tab (Figure 1-6).
    ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig6_HTML.jpg
    Figure 1-6

    The XR Legacy Input Helpers provide a connection between VRTK and versions of Unity after 2018

     
  9. 9.
    On the Legacy XR Inputs tab, click Install.
    • You might see a button to Update or Remove components in your Package Manager window. Whatever your scenario, confirm your project contains the most recent version of Unity’s XR Legacy Input Helpers.

     

Installing VRTK

Finally, we need to install VRTK into our Unity project. To accomplish this, we must clone the VRTK Git repository into the Assets folder of our Unity project. Follow these steps to do this:
  1. 1.
    In the default Unity layout the Project window is a hierarchy of your project’s folders at the bottom left of the application. From the Project window navigate to the Assets folder in your operating system’s Finder or File Explorer. A simple way to do this is to right-click the Assets folder in the Unity Project window and select Show in Explorer or Finder (Figure 1-7), depending on whether you use Windows or Mac OS, respectively.
    ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig7_HTML.jpg
    Figure 1-7

    Open the Assets folder in Windows Explorer

     
  2. 2.

    From File Explorer, double-click the Assets folder to open it.

     
  3. 3.
    Right-click or Crtl+click in the Assets folder and select Git Bash here (Figure 1-8). If this option does not appear in the shortcut menu, then refer to the resources for installing Git on your operating system.
    ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig8_HTML.jpg
    Figure 1-8

    Open Git Bash in the Assets folder from Windows Explorer

     
  4. 4.

    A Git Bash command prompt / terminal window opens.

     
  5. 5.

    Enter the following text into the Bash and press Enter (Figure 1-9):

     
git clone --recurse-submodules https://github.com/ExtendRealityLtd/VRTK.git
../images/488645_1_En_1_Chapter/488645_1_En_1_Fig9_HTML.jpg
Figure 1-9

Cloning into the VRTK GitHub repository from the Git Bash terminal

  1. 6.

    In the Bash, type cd VRTK and then press Enter.

     
  2. 7.

    Enter the following text into the Bash and press Enter (Figure 1-10):

     
../images/488645_1_En_1_Chapter/488645_1_En_1_Fig10_HTML.jpg
Figure 1-10

This is an example from the Git Bash terminal on Windows 10 of completing the VRTK GitHub repo clone

git submodule init && git submodule update
  1. 8.

    Return to the Unity project where Unity will import and compile the new files. If you had difficulty executing any of the steps for cloning the VRTK application into your Unity project, then visit the VRTK GitHub page for more detailed instructions (https://github.com/ExtendRealityLtd/VRTK).

     
  2. 9.

    Finally, if Unity prompts you with a window asking if you’d like to Add VRTK Input Mappings, click the Add Input Mappings button to confirm (Figure 1-11). Because this step will become important for a future exercise in which we connect user actions to events in our VR scene, feel free to select the Do not prompt again check box.

     
../images/488645_1_En_1_Chapter/488645_1_En_1_Fig11_HTML.jpg
Figure 1-11

Clicking the Add Input Mappings button creates the input mappings required by VRTK

Running the Example Scene

When you are ready to proceed, run the VRTK example scene prepackaged with the application’s files. To do so, continue with the instructions provided by the VRTK GitHub page, which I’ve copied here:

  1. 1.
    Open the VRTK/Samples/Farm/Scenes/ExampleScene scene (Figure 1-12).
    ../images/488645_1_En_1_Chapter/488645_1_En_1_Fig12_HTML.jpg
    Figure 1-12

    VRTK provides a sample Unity scene to demonstrate its assets

     
  2. 2.

    Enable Maximize on Play in the Unity Game view control bar to ensure no performance issues are caused by the Unity Editor overhead.

     
  3. 3.

    Play the scene in the Unity Editor (Ctrl+P).

     
  4. 4.

    The scene should automatically play within any Unity-supported XR hardware.

     
  5. 5.

    Explore the farmyard and enjoy!

     
If you’ve successfully set up Unity and installed VRTK, then the example scene included with the VRTK files should look similar to Figure 1-13. If your scene appears different, check the version number of VRTK you have installed. Because you are likely using a more recent version than me at the time this book was written, any distinctions between your example scene and mine could be a result of VRTK updates since its version 4 release in March 2019.
../images/488645_1_En_1_Chapter/488645_1_En_1_Fig13_HTML.jpg
Figure 1-13

Running the VRTK example scene in your Unity project verifies that that setup is complete

Help! I Got Too Many Error Messages!

If, while trying to run the VRTK example scene in Unity, you received a number of error messages, congratulations! You’re officially on your way toward becoming a VR developer. Errors are frustrating, I know. Believe me, I know. But errors are also opportunities to learn more about what is broken, why it is broken, and, most important, how to fix it. An example of one error you received might appear something like this:

XR: OpenVR Error! OpenVR failed initialization: Installation path could not be located!

The solution to this error is to download Steam and SteamVR on your computer, as OpenVR requires both to function. You can read more about Unity’s requirements to run OpenVR in the online Unity documentation at https://docs.unity3d.com/Manual/VRDevices-OpenVR.html.

An example of another error you might have received could appear something like this:

XR: OpenVR Error! Hmd Not Found Presence Failed!

The solution to this error is to confirm that your head-mounted display (HMD) is connected to your computer and that its drivers are up to date.

As many possible errors exist as there are VR systems supported by Unity, at least. MacOS and Windows, too, not to mention the specifics of your personal installation of an operating system, can affect Unity’s performance on your machine. The best path toward solutions, in my experience, is to first reference the official Unity XR resources at https://docs.unity3d.com/Manual/XR.html.

Second, check the documentation for your specific VR system. OpenVR and Oculus, for example, both have Unity integration packages available to download. Developing for mobile VR devices might require installing tools unique to Android. Later in this book, in the chapters addressing user input, we dive more deeply into VR SDKs and integration packages. In addition to the link for Unity’s OpenVR resources included earlier, here are more for Unity’s use with other VR systems:

Oculus: https://docs.unity3d.com/Manual/VRDevices-Oculus.html

Google VR: https://docs.unity3d.com/Manual/googlevr_sdk_overview.html

Windows Mixed Reality: https://docs.unity3d.com/Manual/wmr_sdk_overview.html

Finally, although OpenVR is supported on both Windows and MacOS platforms, running OpenVR on a machine with MacOS has its own hardware requirements:

Unity OpenVR on a macOS requires the Metal graphics and 64bit application target, OpenGL is not supported.

OpenVR supports macOS 10.11.6 or later, but is optimized for macOS 10.13 High Sierra or later. (Unity Manual, https://docs.unity3d.com/Manual/VRDevices-OpenVR.html)

If you received any of the errors I mentioned or others that I did not, please do not be discouraged. I cannot emphasize enough how common feelings of frustration are during this process. If you feel overwhelmed, walk away from the computer and forget about this book for a few hours or even a day. My journey into VR programming has taught me the following lessons.

The Internet is an amazing resource for helping you find others who have experienced the same challenges you face and details of how they overcame them.

The unconscious mind untangles knots without our knowing and may be best left to its own timeline for problem solving.

Endeavor on. Improvement is promised. Knowledge is guaranteed.

While playing VRTK’s example farm scene you will notice a user interface that allows you to toggle between a UnityXRCameraRig and a SimulatedCameraRig. In the next chapter we will learn the difference between these virtual cameras and how to incorporate them into an original scene of our own design.

Summary

If you’ve reached this portion of the chapter, it likely means you’ve successfully set up Unity, Git, and VRTK on your computer. That is no small achievement. I’m sure you experienced challenges, frustration, and in some cases, anger. Congratulations on seeing your way through!

Because VRTK version 4, Unity version 2019, Visual Studio 2019, and VR as a medium, as a whole, are so relatively new in the world of creative development, errors will abound; irritation will mount; and exhaustion will threaten. As a predominantly self-taught VR developer, I know these experiences intimately. However, it is no secret that there has been no greater time in human history to become an engineer of imagination. The tools, although at times buggy, exist, and the creative minds behind their design and execution have done much to pave the road ahead for us well. Yes, things might get bumpy, but the path forward, blazed by pioneers a generation before, is real, and you are on it. By completing this chapter you have proven to yourself that you are ready for the next step.

In this chapter you learned that the fundamental tools for VR development we will need are Unity, an IDE, Git, and VRTK. You learned how to download, install, and set up these tools on your local machine. You cloned a GitHub repository into a machine on your computer, and you ran the VRTK example scene to test whether you set up your tools correctly.

In the next chapter we begin creating a virtual scene of our own design using the tools we have set up on our machines. Because an immersive experience serves as a window into another world, we will begin our first scene with an introduction to virtual cameras in the VR development pipeline.

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

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