Friday, May 26, 2017

DeveloLens 2 - HoloToolkit-Unity Init

Developing with HoloToolkit-Unity


You built a neat 3D model in Unity and deployed it to your HoloLens, but it just floats somewhere in the distance with no clue it's supposed to be an augmented reality app. How do you put that model on your couch? How do you hang it from your ceiling? How do you make that character talk when you tap him?

Init


Let's get you setup. You can download theHoloToolkit-Unity-vx.x.x.x.unitypackage from their releases page, import said package into Unity and profit. But this is only the dependencies you'll need for actually publishing. For us, school is in session and we need all the sources. 


You can also download the zip from the releases page. But if you want to stay up to date and you have Git installed already, I recommend cloning the repository.




This gives us access to the all the content in the Assets folder, which contains a very important Examples folder.

From this point, you can either copy the folders you want into your project or you can create a custom package out of them for fun and profit. You can open the project in Unity and use the export function


to select relevant folders you'd like to reuse. The HoloToolkit folder is the only folder your project needs, but we will be including the Examples and Tests folders for learning purposes.


Now you're a HoloToolkit distribution boss with ready access to all the goods. Import this package into your project and you are good to go.


Settings


After adding HoloToolkit-Unity to your project you will notice a handy menu option that shows up in Unity. Instead of having to worry about searching every nook and cranny of Unity to set the necessary requirements for a HoloLens app, you are able to check off these requirements with a few menu selections. 




Keep in mind, after setting the project settings option you will be asked to reload the project. Also remember you only need to check off the capabilities options that your app will actually need. So if you're doing spatial mapping, you'll need the spatial perception capability among some other capabilities.

Examples


There is so much functionality in this project that even covering it briefly would be a lengthy process. The Examples folder contains scenes that cover common scenarios using multiple functionalities. The Tests folder contains scenes that portray a single functionality. 


Keep in mind the folder structure and naming is bound to change. But the following pieces are fundamental and it's doubtful they're going anywhere. 

There's a few common functions that help with development that are worth explaining.

Cursor

There are several cursors available to us here, but loading the test scene HoloToolkit-Tests\Input\Scenes\Cursor.unity will show you how to use a cursor prefab and related scripts necessary to add a cursor to your HoloLens application and understand the input it provides from the user. The pleasant surprise is being able to simulate user input while debugging in Unity! 


Attached to the InputManager > EditorHandsInput game object you'll find the Manual Hand Control script. This class allows for manually controlling simulated hands while running inside an editor. You hold 'Shift' to enable moving the user's hand and pressing 'Space' will simulate a tap. The ManualHandControl class is destroyed when it detects that it's not running inside the Unity editor.


Spatial Mapping


You may already be aware of how spatial mapping and understanding works on HoloLens, but working with it in Unity is key to streamlining your development experience. I won't get into working with these scenes yet, but there is another big helper here that more developers should be aware of. 

If you've been inside the Device portal, you've probably already noticed that you can save a model of the room your HoloLens is scanning at the time.


So go ahead and do that one time, I'll wait until you get back...

Okay, you didn't go do that, and that's fine because HoloToolkit provides you with a couple models of rooms with different characteristics (and scanned better than you would anyways). There is a prefab located in HoloToolkit-Tests\SpatialMapping\Prefabs\ which has a nice room attached already. 



You can also find meshes of a few different rooms in the sibling folder Meshes to see how your project fairs in different environments. Pretty cool, huh? Not unless you have something do with it?

Go ahead and load the scene at HoloToolkit-Tests\SpatialMapping\Scenes\PlaneFinding.unity for a look at how these models can be used in Unity to prevent you from having to do an actual deployment to see how your application deals with a dynamic environment.

The PlaneFinding scene uses the built in room model. But the other scenes in this folder show how you would use the SpatialMapping prefab to load whatever room model you make or find. In these other scenes you select the SpatialMapping prefab to load any room model into the ObjectSurfaceObserver script. 


Now you may want to record your room and load it into one of these test scenes just to see how easy it is.


No comments:

Post a Comment