Microsoft released the official Hololens SDK a few days ago and I published an introduction to Hololens that went viral. Today, we’ll dive into Hololens Development using the Emulator. I’ll show you how you can build your first Hololens project using Visual Studio and Unity3D.
Prerequisites
Before writing any code, please ensure that your computer meets the minimum requirements have successfully installed the SDK.
Your computer should meet the following specifications:
- 64-bit Windows 10 Pro, Enterprise, or Education (The Home edition does not support Hyper-V)
- 64-bit CPU
- 8 GB of RAM or more
- In the BIOS, the following features must be supported and enabled:
- Hardware-assisted virtualization
- Second Level Address Translation (SLAT)
- Hardware-based Data Execution Prevention (DEP)
- GPU (The emulator might work with an unsupported GPU, but will be significantly slower)
- DirectX 11.0 or later
- WDDM 1.2 driver or later
Important! You need to have hardware virtualization enabled in your PC. To enable hardware virtualization, follow these instructions (yes, you’ll have to modify your BIOS settings).
Step 0 – Install the SDK
To install the SDK, you need to go through the following steps:
Read my step-by-step guide to installing the Hololens SDK.
Step 1 – Create a New Unity Project
Since everything is set, let’s start doing some cool stuff. So, launch Unity Technical Preview (5.4.0b10) and create a new project. Specify a name and a location. Be sure to select 3D. Then, hit Create project.
Unity is an amazing and easy-to-use game engine with a powerful 3D editor. It was originally developed as a utility for creating games fast, but now it’s used in business apps, too.
Unity offers a free and a paid subscription. In the following screenshots, I’m using the paid subscription, however, you do not need the paid plan to develop your Hololens apps. The free version would do the job just fine.
Step 1 – Configure the Main Camera
After you create your project, Unity presents you with an empty 3D view. This is the Unity Editor. Notice the following panels:
- The Game panel shows how your game will be rendered.
- The Scene panel shows the elements you have placed within the 3D world. You can interact with this panel and rearrange the visual elements.
- The Hierarchy panel lists the visual elements of your Scene.
- The Inspector panel shows the properties of the selected element.
In a holographic app, the Main Camera element is your point of view (your eyes). This is why you need to set its position to zero. Select the Main Camera element and set the X, Y, and Z values of the Position property to zero.
Step 2 – Clear the Background
The Hololens world is, well, the physical world. The sensor lets you project 3D elements within the physical space. As a result, you need to have a transparent background for your app.
To create a transparent background, set the value of the Clear Flags property to Solid Color. Additionally, set the Background property to [0, 0, 0, 0] or #00000000 (Hex and RGBA value for “transparent”).
Step 3 – Add some 3D elements
Now, let’s add our first 3D objects to our scene. Under the Hierarchy panel, select Create → 3D Object → Cube. This will add a cube to the scene. Use the Position
, Rotation
, and Scale
properties to play with the cube. The Z value of the Position
property indicates how far the object will be placed. Select a positive number to place the object in front of you. For example, if you set the Z
value to “2
”, the cube will be positioned 2 meters in front of you.
Step 4 – Deploy
You can add more elements into your scene and create your own virtual 3D world. When you are finished, you’ll need to deploy your app and test it using the Emulator. Unity supports a variety of deployment targets. However, Hololens is only compatible with the Windows Store deployment platform. Windows Store is the newest set of Microsoft APIs. To deploy for Windows Store, click File → Build Settings. The following popup window appears.
Build Settings
- First, you need to Add Open Scenes. This will ask you to save your current scene and include it in the build.
- Then, select Windows Store as a build platform.
- In the SDK option, choose Universal 10.
- In the UWP Build Type, choose D3D.
- Check the Unity C# Projects for debugging.
Player Settings
After specifying the build platform, you need to select the Windows Store capabilities of your app. Click Player Settings. The Inspector panel will show you some options. Select the green Windows Store logo and find the Capabilities list. The following elements should be checked, no matter what:
SpatialPerception
Microphone
InternetClient
SpatialPerception
indicates that your app will be capable of using the spatial mapping features. Microphone indicates that your app will be capable of using voice (Cortana) as an input. Finally, InternetClient
indicates that your app will need network connectivity. Since the emulator is running as a Virtual Machine, you need to check this option, even if your app is not making any use of the Internet. If you do not check this option, you’ll see an error after you deploy your app!
Finally, click Build.
Unity will ask you to specify a folder for your build. Create a new empty folder anywhere in your computer and click Select Folder. This will generate a Visual Studio solution file.
Step 5 – Launch Visual Studio
It may take a few minutes for Unity to create the Visual Studio solution. After the process is done, open the folder you created and double-click the .sln file to launch Visual Studio.
Step 6 – Run
Visual Studio has packed the binaries and created a project bundle you can later submit to the Windows Store. To run your app, you need to modify the following parameters from the primary command bar:
- Select Release as your target.
- Select x86 as your architecture.
- Select Hololens Emulator as your device.
This is it! Click the green button or select Debug → Start without debugging.
Step 7 – Enjoy!
We did it! Hololens Emulator should launch after a while (it may take up to 15 minutes, though, so please be patient). After the Emulator is launched, you’ll be able to see your cube and interact with it. Try rotating your view using the mouse and arrow keys. Hit the Enter or Space button to select something. The Emulator is like your field-of-view. The tiny circle is where you point.
If you hit the Start key, the Emulator will show you the Hololens Start screen. Feel free to navigate across the apps (arrow keys + Enter). I selected the Edge app. It even has a virtual keyboard!
That’s my website as a hologram! Pretty cool, huh?!
So, this is it for now. During the next few days, we’ll use Unity to create more complex apps and tutorials.
‘Till the next time, stay tuned and share this article with your fellow-developers.
The post Getting Started with Hololens and Unity3D appeared first on Vangos Pterneas.