Creating Your First Hologram with Unity
by Allen Taylor
This post explores the Unity/Visual Studio development environment by creating a very simple hologram. Although that may seem like a simple task with the powerful tools we have at our disposal, it is fairly complicated. A sequence of steps must be executed in a precise order. If you miss one or mix up the order, you will be left staring at a cryptic error message, scratching your head.
Make sure you have the right equipment, configured in the right way
An old saying goes, “The right tools for the right job.” This is especially true if you are in the early days of developing holographic applications for the Microsoft HoloLens. If you don’t have the right tools, your apps will never get to first base. If you have the right tools, but don’t apply them in the right way, you’ll never get to second. If you want to round third and cross the plate ahead of the throw from the outfield, you will need to have the right tools, apply them in the right way, and do it in the right order.
The right tools include the following:
- A PC with at least 8 GB of RAM
- DirectX 11 or above video card support
- Windows 10 Pro or Enterprise
- Hyper-V support in your PC
- Unity 5.4 or above with holographic support
- Visual Studio Community 2015, Update 2 or above
Applying the right tools in the right way is sometimes not all that obvious a task. That is why carefully following the steps in this book or in online tutorials is critical to success. Since many of the steps depend on the steps that have gone before, applying them in the right order is also important.
Considering all the places where a slight misstep could lead to failure, when you make it through the entire process, don your HoloLens, and actually view a hologram that you have created, sitting there in all its 3-D glory, it is an occasion for major rejoicing.
Create a new project in Unity
Here’s the step-by-step procedure to follow:
- Launch Unity.
- From the window shown below, select New.
- Enter a project name, such as FirstHologram.
- Enter a location in which to save your project.
- Ensure that the 3D toggle switch position is selected, rather than the 2D position.
- Click on the Create Project button.
Place the camera
All holograms that you create will be located at a position relative to the main camera. The main camera is at the position of the person wearing the HoloLens.
- Select Main Camera in the Hierarchy panel and then look at the Inspector panel, shown below.
- Note in the Transform section of the Inspector that the position of the main camera shows it to be at x = 0, Y = 1, and Z = -10.
- Note that the values for Rotation are X = 0, Y = 0, and Z = 0, and the values for Scale are 1, 1, and 1.
We now need to change some of these values, as follows:
- In the Transform section of the Inspector, change the Position coordinates from 0, 1, -10, to 0, 0, 0.
- In the Camera section of the Inspector, change the “Clear Flags” dropdown from Skybox to Solid Color.
- Click in the Background area to display the Color window, and then change the RGBA values to 0, 0, 0, 0. Having all zeros means that no light will be painted in the background area. The background will be the real world of whatever room you are in.
- Change the Clipping Planes Near value from 0.3 to 0.85. This will prevent holograms from rendering too close to the user’s eyes.
Here’s the Inspector panel at this point.
Create a hologram
Now that the Unity environment is set up, we can create a hologram.
- In the top-left corner of the Hierarchy panel, click on the Create button, and from the menu that drops down, choose 3D Object and then Cylinder.
- Select the newly created cylinder in the Hierarchy panel.
- In the Inspector, change Position to x = 0, Y = 0, Z = 2. This will position the hologram two meters in front of the user’s starting position.
- Change Rotation to X = 30, Y = 30, Z = 30 and scale to X =.25, Y = .25, and Z = .25. This gives the cylinder a dimension of .25 meters along each axis.
- Click the Play button (a right-pointing triangle) above the Scene panel to change to Scene mode and view the cylinder you have created, shown below.
- Click the Play button again to exit Scene mode.
- Save the scene by selecting File > Save Scene, naming the scene, and then clicking Save again.
This article is excerpted from the book Develop HoloLens Apps Now, by Allen Taylor, a Most Viewed Writer on HoloLens on Quora.com, and author of more than 40 books. Meet Allen at the Windows Holographic User Group Redmond (WinHUGR) meeting on January 11, at 6pm. Details at http://bit.ly/2iMpLml