User Tools

Site Tools


getting_started

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
getting_started [2023/01/23 15:38] – created nkassaigetting_started [2023/02/21 09:00] (current) nkassai
Line 3: Line 3:
 **Author:** <Nathan Kassai> Email: <kassan@unlv.nevada.edu> <!-- replace with your email address --> **Author:** <Nathan Kassai> Email: <kassan@unlv.nevada.edu> <!-- replace with your email address -->
 \\ \\
-**Date:** Last modified on <01/23/2023>+**Date:** Last modified on <01/29/2023>
 \\ \\
-**Keywords:** <Virtual Reality, Tutorial, Step-by-Step>+**Keywords:** <Unity, Tutorial, Step-by-Step>
 \\ \\
  
Line 12: Line 12:
 This first section of this Unity crash course involves the following: This first section of this Unity crash course involves the following:
   * Brief introduction to Unity    * Brief introduction to Unity 
-  * Unity's core purpose and its alternative uses 
   * Installing Unity    * Installing Unity 
 +  * Installing Visual Studio
   * Understanding the layout and some key terminology   * Understanding the layout and some key terminology
   * Writing our first "Hello World" script   * Writing our first "Hello World" script
 +  * Final Words 
 +  * Refresher Questions
  
 ===== Prerequisites ===== ===== Prerequisites =====
Line 23: Line 24:
 ^ Minimum Requirements      ^ Windows                                          | macOS                                               | Linux                                                                    | ^ Minimum Requirements      ^ Windows                                          | macOS                                               | Linux                                                                    |
 | Operating System Version  | Windows 7, and Windows 10 (64-bit version only)  | High Sierra 10.13+                                  | Ubuntu 16.04, Ubuntu 18.04, and CentOS 7                                 | | Operating System Version  | Windows 7, and Windows 10 (64-bit version only)  | High Sierra 10.13+                                  | Ubuntu 16.04, Ubuntu 18.04, and CentOS 7                                 |
-| CPU                       | 6-Core                                           | x64 architecture with SSE2 instruction set support  | x64 architecture with SSE2 instruction set support                       |+| CPU                       | 6-Core CPU                                           | x64 architecture with SSE2 instruction set support  | x64 architecture with SSE2 instruction set support                       |
 | Graphics API              | DX10, DX11, and DX12-Capable GPUs                | Metal-capable Intel and AMD GPUs                    | OpenGL 3.2+ or Vulkan-capable, NVIDIA and AMD GPUs                       | | Graphics API              | DX10, DX11, and DX12-Capable GPUs                | Metal-capable Intel and AMD GPUs                    | OpenGL 3.2+ or Vulkan-capable, NVIDIA and AMD GPUs                       |
-| Additional Requirements   | Hardware vendor officialy supported drivers      | Apple officially supported drivers                  | NVIDIA official proprietary graphics driver or AMD Mesa graphics driver  |+| Additional Requirements   | Hardware vendor officially supported drivers      | Apple officially supported drivers                  | NVIDIA official proprietary graphics driver or AMD Mesa graphics driver
  
 +==== Brief introduction to Unity  ====
  
-This tutorial's goal is to teach you how to set up the Varjo XR3 HeadsetVarjo Base, and how to get the headset working in Unity. The rest of this tutorial is presented as follows+On June 8th, 2005, the popular game engine we all know and love today, Unity, was released. Originally, Unity was solely designed to be just a game engine; a collection of tools, libraries, and assets to prototype a 2D/3D game. Why as a roboticist then would you benefit from learning Unity?  Well, over the course of its existence, Unity expanded from a mere game engine to a platform capable of virtually anything! Virtual/Augmented reality applications, generating 3D visualization tools, film production, generating browser/console applications, touch screen applications, and more recently, robotic simulations and teleoperation!  
-  * Hardware + 
-  * Connections +In this crash course, I plan on teaching you the basics of Unity: understanding how Unity works, learning how to write scripts to implement custom behaviors, general terminology, etc. With these basics, by the end of the coursewe will then learn how to send joint data to a robotic arm using ROS!    
-  * Software (get local copy of varjo base) + 
-  * Varjo Base +Without further adolet us begin with the installation process. 
-  * Connecting the Varjo XR3 to Unity + 
-  * Final Words+ 
 +====== Installing Unity ====== 
 + 
 +First things first, download Unity Hub [[https://unity.com/download|here]] and click on Download for Windows. 
 + 
 + 
 +{{ :unitydownloads.png?nolink&800 |}} 
 + 
 + 
 +After downloading, run the executable to install the Unity Hub. Once the installation has finished, you should see the following: 
 + 
 +{{ :unityhub.png?nolink&800 |}} 
 + 
 +Once you have reached this page, you may either login with the DASL Unity account, or you may choose to make your own.  
 + 
 +After logging in, it will ask if you would like to install the latest Unity editor. Press **Skip Installation** (we will be downloading an earlier Unity Editor version). Finally, Unity will ask you to activate a personal license, press **Agree and Get Personal Edition License**. 
 + 
 +Once you have finalized the Unity Hub installation, you should see this page.   
 + 
 +{{ :unityhubmain.png?nolink&800 |}} 
 + 
 +As previously mentioned, this is known as the **Unity Hub**. The Unity Hub is where you are able to manage all of your created projects, as well as install versions of the Unity Editor. The **Unity Editor** is where we actually create our applications. **We cannot create a project in Unity if we do not have a Unity Editor!**, so, lets us install a 2020+ version.  
 + 
 +To do so, click on Install Editor located at the center of the Unity Hub. Once pressed, scroll down to the Long Term Support (LTS) section and click install on the 2020.3.44f1 Unity Editor version.  
 +After pressing install, it gives you options to install additional packages. For now, we do not need any of these packages, we will just press install (this can take 10-20 minutes). 
 + 
 +{{ :unityeditorinstall.png?nolink&800 |}} 
 + 
 +After the installation has completed, switch over to the Projects tab and press New Project. 
 + 
 +{{ :unityprojects.png?nolink&800 |}} 
 + 
 +The template that we will be using for this project is **3D Core**! Press the core tab and press 3D Core as seen here. Once you select it, give your project a name, and choose where you would like this project to be stored. Once you have done that, press create project. 
 + 
 + 
 +{{ :unitycreateproject.png?nolink&800 |}} 
 + 
 +Once it has loaded, you should see this screen: 
 + 
 + 
 +{{ :unityscenebare.png?nolink&800 |}} 
 + 
 +Now that Unity has been fully installed, it's time we take a look at the layout of Unity. 
 +===== Installing Visual Studio ===== 
 + 
 +Before we continue, let us install Visual Studio which we will be using to write our scripts with. 
 + 
 +First, click [[https://visualstudio.microsoft.com/downloads/|here]] to install Visual Studio (make sure to click on community).  
 + 
 +Once it gets to this page, scroll all the way down until you see **Game Development**, then select Game Development with Unity. After that, hit install. 
 + 
 + 
 +===== Understanding the Layout and Some Key Terminology ===== 
 + 
 + 
 +Congrats! You've loaded up into your first project. Now, before we do anything else, let's talk about what is currently on screen. 
 + 
 +{{ :unityscene.png?nolink&800 |}} 
 + 
 + 
 +  **Scene Window**: In this center rectangle, we have the Scene Window. This gives us a view as to what is located inside this current Unity Scene. For instance, as we add to this scene later on, you can visualize what you're adding through this window. If you wanted to see what the player sees, click on the tab right next to Scene. 
 +  **Hierarchy**: On the left side, you can see two objects, Main Camera, and Directional Light. What the Unity Hierarchy does is neatly organizes all of your **Game Objects** in one area. Every object added to this scene will show up in the Hierarchy.  
 +  **Inspector**: Right now, the inspector is empty; let's change that! Click on the Main Camera, and watch the inspector fill up with information. The inspector allows you to monitor what **Components** are added to each of your game objects. 
 +  **Project Management**: Down below, we have the project manager. This area is simply used to store and access all assets added to your Unity project! Those assets could be music files, 3D models, images, materials, etc.  
 +  **Play, Pause, and Step**: When you would like to test your game, you must press the Play button. To stop, press the play button once more. To pause your game, press the pause button. If you would like to move frame by frame, press the step button.  
 +  - **Tool Bar**: Looking at the top left, we have the tool bar. Starting from left to right we have the: 
 +       * Hand Tool - Moves the scene camera around to help you get a better view of the area 
 +       * Move Tool - Moves any object currently selected in the Hierarchy 
 +       * Rotate Tool - Rotates any object currently selected in the Hierarchy 
 +       * Scale Tool - Changes the size of an object 
 +       * Rectangle Tool - Scale tool, but applies a rectangular scale to the object 
 +       * Multi Tool - Combination of scale, move, and rotate tool 
 +       * Editor Tool - Allows you to edit certain components of game objects 
 + 
 +Now, I have highlighted some keywords in the above section, **Game Object** and **Component**. Let us define what those actually mean in Unity
 + 
 +You can think of a **Game Object** as a container and by default, these containers are empty. This container could be anything: a cube that could be moved by the player, a video that plays on a TV, maybe it could be the player, etc. What we need to do as developers is to fill those containers with behaviors.  
 +Say we wanted a cube to simply fall down and hit the floor. Well, we would need to fill that container with the following behaviors: 
 +  * A script to visualize the cube 
 +  * A script which allows the cube to experience free fall 
 +  * A script which detects that the cube has collided with something 
 + 
 +The proper term for these special types of scripts are called **Components**.  
 +A component is a script that contains some sort of behavior for a game object. Previously while we were looking at the inspector for the Main Camera, we saw two components: Camera and Audio Listener. These two components are scripts written by Unity developers that allow us to define what a Camera is! Thankfully, Unity provides a large number of components free to use without having to code!  
 + 
 +Let's try and get a cube to fall! To do this, we must first add the cube game object to the Hierarchy. To do so, bring your mouse to the Hierarchy, right-click, hover over 3D object, and then select Cube.  
 + 
 +{{ :addcubetoscene.png?nolink&800 |}}
  
-==== Hardware ==== +Once the cube spawns inclick on it in the Hierarchy. As you can see in the inspector, there are different components that define what makes up this cube.  
-To complete this tutorialyou'll need the following items (shown in image below from left to right)+If you were to hit play now, nothing happens; the cube stays suspended in the air.  
-I've also included amazon links to purchase any missing cable:+Well, let's fix that by adding a new component to our cube called, **Rigid Body**. This allows our game object to experience external forces (including gravity!). To do so, go to the inspector and click on **Add Component**; a text box will appear with a large list of components. Type in Rigid Body and hit enter (or click on it) to add it to the Cube. 
  
-  * **A** Varjo XR3 Headset (1) (Approximately $7050 as of 1/20/2023) +{{ :addrigidbody.png?nolink&800 |}}
-  * **B** Display Cable (2) [[https://www.amazon.com/StarTech-com-DisplayPort-Cable-Latches-Short/dp/B003OCRWBQ/ref=sr_1_3?crid=3UTTWSMT2LDPB&keywords=short%2Bdisplay%2Bcable&qid=1674242183&sprefix=short%2Bdisplay%2Bcable%2Caps%2C113&sr=8-3&th=1|DisplayPort Cables]] +
-  * **C** USB 3.0 Cable (2) [[https://www.amazon.com/Besgoods-2-Pack-1-5Ft-Braided-Super/dp/B075CZ6Z8T/ref=sr_1_4?crid=2XB7I5TRM85W4&keywords=usb+3.0+a+to+a+short&qid=1674242311&sprefix=usb+3.0+a+to+a+shor%2Caps%2C127&sr=8-4|USB 3.0 Cables]] +
-  * **D** Link Box (1) (If missing, please email me so that I may locate it, or get in contact with Varjo Support for a replacement) +
-  * **E** 12V 3.0A AC Adapter (1) (barrel jack type) +
  
-{{:xr3_components.jpg?nolink&600|}}+Now, hit play again, and watch as the cube falls forever
  
 +Go ahead and spend some time playing with the other components and add other game objects to the scene! 
  
-==== Connections ====+As I mentioned previously, Unity Devs added a large number of components to streamline developing various applications. However, what if we wanted to add a custom behavior? One that isn't defined by Unity? For instance, what if I wanted to have the cube stop moving if it hit a certain height, or maybe I want the player to control the gravity with a slider, or maybe for every space bar press, a new cube spawns from a random height? This is where programming comes in!
  
-This section gives step-by-step instructions along with photos to ensure you make the proper connections to your link box+Unity's scripting language is C# (don't worry, you do not have to have previous C# experience for this course)So, let us create a script and write our very first component!
  
-**Step 1** +Before we do thatlet's get Visual Studio connected with our Unity project!  
-Grab the two long USB-C cables from the headset and connect them to their respective slots on the Link Box (connect A to AB to B). +
-{{:link_connections_a_b_new.jpg?nolink&500|}}+
  
-**Step 2** +To do so, go to the top left of Unity, select the Edit tab, and hit preferences
-Connect the two USB 3.0 Cables from the back of the link box to two available USB 3.0 slots on your PC+
  
 +{{ :preferencestab.png?nolink&800 |}}
  
-**Step 3**  +Next, hit the External Tools tab, scroll down to External Script Editor, hit the drop-down, and select Visual Studio.
-Connect the two Display Cables from the back of the link box to two available DisplayPort slots on your PC+
  
-**Step 4** +{{ :externaltoolssection.png?nolink&800 |}}
-Once everything is properly connected to the link box, grab the 12v 3.0A AC Adapter, and connect it to the link box (connection is found on the side with the two USB 3.0 and DisplayPort cables), and connect the AC Adapter to an available wall outlet. +
-{{:power_connection_linkbox.jpg?nolink&600|}}+
  
-The headset is now powered on! Time to install/run the necessary software.+Once that has been updated, we are now ready to write our first script!
  
-==== Software ==== 
  
-To get the headset running, you must install Varjo Base! Go to the following link:+=====  Writing Our First "Hello World" Script =====
  
-https://account.varjo.com/login+All we need to do to create our first script is to right-click in our project management area, create, and then C# script
  
-And login to DASL’s Varjo Base Account (For security purposes, the account information will only be provided in the labAccount information will be located in the VR area)+{{ :csharpscriptcreate.png?nolink&800 |}}
  
-Once you’ve logged inyou may hit download:+For this scriptcall it **HelloPrint**. 
  
-{{:varjo_base_install.png?nolink&800|}}+Next, double-click the HelloPrint script and wait for it to load in Visual StudioIt should look like this after it has loaded:
  
 +{{ :csharpcode.png?nolink&800 |}}
  
-After the executable has downloadedrun it, and follow through the installation process (Note: If it asks which headset you are usingspecify Varjo-XR3)+At first, it can be pretty intimidatingas there is already some code written for you without a clear reason why. For this tutorial, I will explain what each line does at a higher level, but next tutorialI will explain in depth what each line is actually doing. 
  
-==== Varjo Base ==== +  - These lines allow us to call C# and Unity functions to implement in our code. 
-Once the software has been installed properly, you should see the following: +  - This line defines a new Class called HelloPrint **Note: The name of this class MUST be the same as the file you createdif not, there will be errors when trying to apply this component to a game object.** Additionally, we are inheriting another class called MonoBehavior. Inheriting MonoBehavior makes this script become a component and gives us access to a plethora of functions that a component might need. **If you write a script and forget to inherit MonoBehavior, you would not be able to add it as a component.** 
-{{:varjobasesnip.png?nolink&800|}}+  - Start and Update are special types of functions. As seen by the comments, Start is a function that is called right before the first frame update. In other words, when you hit play, before the first frame is played, this function is called, and whatever code is inside it will run. However, this function is called once for every script that it is attached to. Update however is called once per frame. If your Unity scene is running at 60 FPS, this function and all code written inside it will be called 60 times per second
  
-Note: There are two types of tracking that the Varjo XR3 uses:+Let's add a line of code to the start function so that once we hit play on the Unity scene, the phrase, "Hello World!", will be displayed in the console. 
  
-  * Inside-Out Tracking +To do so, type in the following line in between the curly braces as seen below: 
-    * Utilizes the Front-facing cameras to draw virtual boundaries around the player +
-  * SteamVR +
-    * Utilizes HTC Vive 2.0 Base Stations to track the position of the headset  +
- **You can use either or, however, since our lab has Base Stations, we will use SteamVR**+
  
-To change the tracking type, go to Varjo Base, click on System, and under Headset Tracking, change it to SteamVR.+Debug.Log("Hello World!");
  
-  * Calibration with SteamVR will not be shown in this tutorial. Tutorial for any headset utilizing SteamVR will be shown here (Add link for SteamVR calibration).+{{ :debuglog.png?nolink&800 |}}
  
-==== Connecting the Varjo XR3 to Unity ==== +Once you do this, hit Ctrl + s to save your script, and head back over to your Unity scene. 
-In order to get our headset connected to Unity, we will require the following packages: +
-  * SteamVR +
-  * Varjo'Unity SDK+
  
-Before installing the above-mentioned packagesplease create new Unity 2020+ 3D project and name it **Varjo_XR3_Intro**+Now, if we hit play and switch over to the console tabwe can see that nothing printed out. Remember, this script is now component; in order for the script to run, we must add it to a pre-existing game object
  
-Once the project has opened, go to the Asset Storedownload SteamVR (if not already downloaded), and import it into your project+Let's add this to our cube. Click on our Cube in the inspectorpress Add Component, and type in the name of the script we just wrote **HelloPrint**, then press enter.
  
-Once SteamVR has finished installingyou may now install the Varjo SDK for Unity+Finallyswitch over to the console tab and hit play.
  
-Copy this Github linkhttps://github.com/varjocom/VarjoUnityXRPlugin.git+{{ :printhello.png?nolink&1000|}}
  
-Go back to Unity and press Window. Then scroll down to Package Manager.  
-When the package manager opens, press the top left (+) icon and select add package from git URL. Paste the above GitHub link into the text box and press add. 
  
-After a few minutes, the package should have installed the Varjo SDK into Unity! +Congratulations! You have written your first Script in Unity! 
  
-In the Asset section, search for the Player GameObject and drag it into the Hierarchy.+===== Final Words =====
  
-And finally, hit play and put on the headset!+I hope you're excited about this course in Unity as you will learn a great deal about the plethora of features that this platform has to offer (both in game development and especially in robotics/teleoperation). In the next session, we will talk a little bit more about the scripting language and go over some basic programming practices. 
  
-It will look bland since there isn't anything besides a camera and a bottomless void surrounding you, so feel free to add whatever you'd like to your scene to make it fun! I have installed a separate package that comes with a pre-configured scene from the Asset Store (called MidPoly Retro Rooms).  
  
-==== Final Words ====+===== Refresher Questions ===== 
 +At the end of each session, I like to ask questions to make sure you were able to understand all of the information provided. I'll either ask you to write a program that goes over what was taught in this session or simply ask true/false and or multiple-choice questions. **These are not homework assignments!**
  
-This tutorial's objective was to allow you to render your 3D environment into Virtual Reality Headset. Go ahead, play around with your environment! Add more objects to your scene and make it come to life!  +  - What is Game Object? 
-In the next tutorial, we will look at integrating another piece of tech into our Unity scene; the Quantum MetaGloves!+  - What is a Component? 
 +  - What is the difference between the Start and Update functions? 
 +  - What scripting language does Unity use? 
 +  - Write a script that will print "Hello!" on every frame.
  
 \\ \\
getting_started.1674517092.txt.gz · Last modified: by nkassai