Why you should be learning to develop in Mixed Reality?

What is Mixed Reality (By The Way)?

Maybe, this term is unknown to you by its name but if you ever saw a Science Fiction movie you may saw an Augmented Reality sample. The straightforward way to define is the mixture of the real world with a virtual world, of course with an application in the middle which evaluates and shows information, characters, ads or whatever the app’s developer had imagined.

Augmented Reality blast Virtual Reality because with the first one you can interact with your environment and can move around it without losing the orientation; instead of travel to a entire new world and must stay in your initial place, if not you can inquire in the risk of walk over any real object because you are blind for the real world objects.

Mixed Reality is a platform brought by Microsoft which allows developers create application for a variety of Windows Mixed Reality headsets and motion controllers which are coming to market from HP, Lenovo, Dell, and Acer and, of course, HoloLens that is in the market from more than two years. This means that you can develop an application or game and it will be compatible with that devices which can use the Windows App Store.

Past

From more than a few years ago the “VR versus AR wars” take place. We’ve putted into the hard decision to choose between develop VR or AR applications. We had the major exponent of the VR with Oculus Rift and HTC Vive headsets. In the other hand, we had the HoloLens for the AR as the mayor exponent. But also, we could saw a great enthusiasm into the minor vendor market of headset with a few startups developing its own headsets.

Present

Nowadays, that wars may see over and the winner looks obvious if you consider the followings:

  • Apple announced the ARKit to all iOS devices a few months ago, and people went crazy making POCs with it. With ARKit you can scan your surroundings and find planes to place virtual objects.
  • Microsoft announced headset from other vendors (Acer and HP) become compatible with the Mixed Reality platform in the past Build. And that delete the major complain about the HoloLens: the high price and the lack of motion controllers.
  • Google announced a few days ago the ARCore. Basically, the same as ARKit, but to Android Devices. And I’m expecting the same madness as the ARKit and want to see what the people POC.

Future

Microsoft just announced that the Steam content will be compatible with the MR headset, Halo will land on the MR too, and the alliance with a lot of companies to create new content for the MR Platform.

Why we could choose to develop in MR Platform?

Microsoft has put a lot of effort and work in this platform. First, they released the HoloToolKit to ease the development for HoloLens in Unity3D and the Holographic Academy with consists in walk-through into how to program HoloLens’ capabilities when the device just was released.

A very few months ago, the HoloToolkit GitHub repository was renamed to MixedRealityToolkit_Unity (which now make a lot of sense) and the documentation also has changed to a modern layout. In that change, we may find the promise to get a more frequent update to the Unity3D’s asset to be aligned with the Unity3D versions (which has the official and the beta versions in parallels and latest version come to light every month).

Moreover, Microsoft released the MRDesignLabs_Unity GitHub repository short time ago to give developers samples, utilities and assets to ease the work and make the UI of the games and apps more consistent with the one Mixed Reality used in their OS.

Remember that the development of an application for the MR Platform is very easy with the pair Unity3D-Visual Studio and you don’t need to learn a new language so you can use your skills in C# or JavaScript to script you game. So the learning course may be shorten.

And finally, you must think in the future of the development. The Virtual/Augmented Reality is a trust in our living days. So, consider in the short term you may be requested to do a development into the new platform: Augmented Reality into a phone (using ARKit or ARCore) or into a Headset (VR or AR). Either the actual platform, you will probably use the same concepts and tools and only the final device will diverge.

How-To: Add an Outline effect when selecting a Hologram

Introduction

Some many times I want to inform the user what hologram she is selection. I found this very helpful (and free) asset that turn the hologram to a chosen color. So, the next thing to do is to make it enable when the user point to the hologram.

You can find the code made in this post in this GitHub repository.

0 – Setup of the new project

  1. Start Unity3D and create a new project named something like OutlineSelect.
    create-project
  2. Import the HoloToolkit Asset (Assets -> Import Package -> Custom Package). If you didn’t download, you can do it from here. Click Import when the popup appears showing the resources to import.
  3. Delete the Main Camera and Directional Light GameObjects in the Hierarchy view.
  4. Add the HoloLensCamera and the InputManager prefabs from the HoloToolkit\Input\Prefab folder and to the same with DefaultCursor prefab from the HoloToolkit\Input\Prefab\Cursor folder.
  5. Save the scene and choose a name of your like (i.e. General).
  6. Configure your Scene (HoloToolkit menu > Configure > Apply HoloLens Scene Settings), Project (HoloToolkit menu > Configure > Apply HoloLens Project Settings) and Capabilities (HoloToolkit menu > Configure > Apply HoloLens Capability Settings) as it comes click Apply. Next, configure the Capabilities (HoloToolkit menu > Configure > Apply HoloLens Capability Settings).

1. Import your holograms

  1. In this example, I will use this asset package with some fast food objects. Import the assets you want to use and place in your scene some instance of the GameObjects you want to use.
  2. You may setup your layout similar to the following image.
    scene-layout
  3. Select each GameObject in the Hierarchy View and next add the Box Collider Component in the Inspector View.
  4. Keep the GameObject selected, and add the Outline component and deselect the enable check.
    gameobject-components

2. Implement the Outline Asset

  1. Go to the Asset Store view and search for Outline Effect assets and import it.
  2. Select the HololensCamera GameObject and add the Outline Effect component. This component allows you to select the colors which will turn your holograms. In this example, this default settings will be fine.hololens-camera-outline-effect

3. Code the magic

  1. Create a script named OutlineOnSelect and attach it to each GameObject which have the Outline component.
  2. Open the just created script in Visual Studio and place the code you can find abode. In this code, we detect the selected GameObject using a RayCast and gets the GameObject the user is pointing with the gaze. Next, we validate that the user is selecting the another GameObject than before, disable the Outline component and enable in the new selected one.
private GameObject FocusedObject;

// Update is called once per frame
 void Update()
 {
 // Figure out which hologram is focused this frame.
 GameObject oldFocusObject = FocusedObject;

// Do a raycast into the world based on the user's
 // head position and orientation.
 var headPosition = Camera.main.transform.position;
 var gazeDirection = Camera.main.transform.forward;

RaycastHit hitInfo;
 if (Physics.Raycast(headPosition, gazeDirection, out hitInfo))
 {
 // If the raycast hit a hologram, use that as the focused object.
 FocusedObject = hitInfo.collider.gameObject;
 }
 else
 {
 // If the raycast did not hit a hologram, clear the focused object.
 FocusedObject = null;
 }

if (FocusedObject != oldFocusObject)
 {
 // Deselect the old selected GameObject is not null
 if (oldFocusObject != null)
 {
 var outlineComponent = oldFocusObject.GetComponent<Outline>();
 if (outlineComponent != null)
 {
 outlineComponent.enabled = false;
 }
 }

// Select the selected GameObject is not null
 if (FocusedObject != null)
 {
 var outlineComponent = oldFocusObject.GetComponent<Outline>();
 if (outlineComponent != null)
 {
 outlineComponent.enabled = true;
 }
 }
 }

4. Build and Test

  1. Save your scene and Build your project (File > Build Settings) to test on the HoloLens Device or Emulator. Remember to include the active scene as usual.HoloLensBuiltOptions
  2. Open the generated project in Visual Studio. Remember to change the configuration to x86. Build and deploy to your Hololens Device or Emulator.You can find a gif showing our code in action.
    OutlineSelected

Edit on: 07/15/2017

I found a clear way to accomplish this post. I found the IFocusable interface.  Basically this interface has two method (OnFocusEnter and OnFocusExit) where you can enable and disable the Outline component.

You can find the final code bellow and in the repository.

using cakeslice;
using HoloToolkit.Unity.InputModule;
using UnityEngine;

public class OutlineOnSelect : MonoBehaviour, IFocusable
{
 private Outline outlineComponent;

void Start()
 {
 this.outlineComponent = this.GetComponent<Outline>();

// Disable the component on start. 
 OnFocusExit(); 
 }

public void OnFocusEnter()
 {
 if (this.outlineComponent != null)
 {
 this.outlineComponent.enabled = true;
 }
 }

public void OnFocusExit()
 {
 if (this.outlineComponent != null)
 {
 this.outlineComponent.enabled = false;
 }
 }
}

The life after the NETConfAR’17.

For those who didn’t know, I talked in the NETConfAR a few days ago bringing a workshop about Hololens.

Since organizer’s had confirmed me as a speaker, I keep some thoughts to follow:

  1. Made an app to show Hololens parts and capabilities.
  2. Make the workshop the most interactive possible to don’t get bore the attendances.
  3. Try to make exercises that shows the main Hololens’ capabilities

Continue reading The life after the NETConfAR’17.

How-To: Use Cortana to speak in your HoloLens

In this post, we will see how to use the recently added component TextToSpeechManager from the HoloToolKit to use Cortana to speak to the user.

We will do a simple sample app that will speak to us when we click on a Hologram. This is a very simplistic but powerful sample to show this capability that was introduced in the version 1.5.7.0 of the HoloToolKit.

You can access the final project in this GitHub repository.

Shall we code?

Continue reading How-To: Use Cortana to speak in your HoloLens

How-To: Create an image recognition app with Vuforia

Image recognition and interpretation is a very requested task into modern application. Either you want to identify a specific image or object or either you want to interpret what the users get in front their smartphone camera.

A technology that is becoming more and more popular among developers with this task is Vuforia. This framework can recognize a specific image and track it while the image is in the scene. And, of course, you can handle that and do almost anything. The same goes to Custom 3D object, Cylinders, boxes, etc.

Moreover, Vuforia is widely accepted because we can use it with almost any device, from older and cheap Android smartphone to the most recent VR/AR/MX devices. In this post, we will use the Vuforia capabilities from Unity3D because it is also multi-platform.

You can access this final project code in github repo.

Prerequisites

First, we need to download Unity3D from here. You may try the personal (and free) plan. In the meantime, it is installing, review What is Unity3D.

When installing Unity, be sure to install the Windows Store platform, and the .Net Scripting Backend

What is Unity3d?

Unity3D is a videogame engine, which have support for 3D and 2D games. It has physics, collision, light and much more to use. It has a very simple but powerful IDE and we can include scripts in JavaScript or C#.

Unity3D have a great and complete community with great tutorials with various levels of knowledge.

We can use the built-in editor to code or any version of Visual Studio. If we install the Visual Studio Tools for Unity, we can attach it to Unity and debug our code. Additionally, you can run your game inside Unity3D to test and debug your game.

We can generate the output for Windows, Linux, MacOS, many mobile OS (Android, iOS, BlackBerry, etc.) and finally, we also can create executable for Xbox, Xii and PS3/PS4/PSP platforms.

We also have an enormous, great integrated, Assets Store (paid and free) to don’t need to design buildings, characters, effects, code, and all we can need.

What is Vuforia?

Basically, Vuforia is a framework for image and object recognition and tracking. It has a developer portal where we can upload images to a database that later can be used for tracking other images and objects.

Shall we code?

Step 1: Setup Vuforia Database

  1. Download from here the latest Vuforia SDK for Unity.
  2. Navigate to the Vuforia Developer Portal, Log in or Register (if this is your first time). And click on the Develop top section and next click on the License Manager and click on the Add License Key button. Licenses will determine your final target for your project. By now, we will choose the Development option. Complete with an Application Name like VuforiaImageSample.

    Vuforia-AddLicenseKey
    Add Vuforia’s License Key
  3. Confirm your choice and notice your Usage Quotes.
  4. Click on the name of the recent created License. And save the License Key for later usage.
  5. Now, let’s create our database to upload our image. Click on the Target Manager on the top sub-menu. And then click on the Create Database button. Choose a Database name (like VuforiaImageDataBase) and select Device as Database Type. Accept to dialog clicking on the Create button. Vuforia-CreateDatabase
  6. Now, we will need an image to upload. Take in consideration that you can upload any image that you want, but you must think that Vuforia will works better with a high quality and contrasted image. For our sample, we will choose this Octocat image.
  7. To finally upload our image that will be recognized, click on the Add Target button. And a popup like the next image open. Choose the Single Image as the Type, pick up the image you want to upload and enter the Width for the image. This is not the image width, instead is a relative unity which allow to scale in relation with others image you have in the same Database. At this moment, we don’t plan to have another image so let’s enter 50. Click on the Add button to process to upload the image.Vuforia-AddImageTarget
  8. Al most finish here. Now you should see a grid with the image and the most important here is the Rating. Higher Rating make easier to detect the image. Click on the Download Database button and a new popup will show. Choose Unity Editor and click on the Download button and save the given file.Vuforia-DownloadDatabase

Step 2: Create Unity3D project and import Vuforia asset

  1. Now, we need a new Unity3D project. So, let’s create one starting Unity3D and click on the New button. Complete the project name with any of yours choose, VuforiaImageSample may be a good one, and a location folder as you consider best.
  2. Import the Vuforia SDK. Go to the menu Asserts -> Import Package -> Custom Package and locate the .unitypackage file you have downloaded in the previous step. After a few moments, a dialog will show to confirm the import process. Click on the Import button.
  3. We will do the same with the Vuforia Database we downloaded at last in the previous step.
  4. Now, let’s do some magic here. In the Hierarchy tab delete the Main camera component. On the Project tab, navigate to the Vuforia\Prefab folder and drag the ARCamera component to the Hierarchy tab. This component will be the camera which your app will constantly scan and trying to identify your image. With the ARCamera selected, go to the Inspector tab and click on the Open Vuforia configuration. Paste your App License Key you have saved from last step. Unity-VuforiaAppLicenseKey
  5. Locate the Datasets node and ensure the Load is checked and next, check the child Activate. This tells to Vuforia to load and activate the Database when the scene starts. Otherwise, we need to load and activate programmatically.
  6. Go back to the Vuforia\Prefab folder in the Project tab and drag the ImageTarget component to the Hierarchy tab. This component is the responsible for recognizing your image from what the ARCamera capture. Maintain selected this component and go to the Inspector tab and Upload images to a database that later can be used for tracking other images and objects. After that you should note that the ImageTarget is bigger than before. It was scaled to the magic number you entered in the Width image when uploaded. Unity-ImageTargetDatabaseNow, you can say that you have an AR app that recognize an image. But if you run the app in Unity3D it will route to your Webcam (if there is one) and however you show the image or not, nothing happens. More specific, you can see if the image is recognized or not.
  7. First, you will put a basic 3D object as a flag to get notice if the image was or not recognized. Ensure the ImageTarget is still selected and go to the GameObject -> 3D Object -> Cube menu this should add a cube as a child of your ImageTarget. Now, play around with the Transform properties of the cube to accurate to your image. I set the properties as you can see in the next image.Unity-ImageTargetCube
  8. Now, you can play the project and show to the camera the image you upload. You can print the image or load from another device as a smartphone. Unity-ImageRecognized

Amazing, huh? You may notice that this would be confusing but once you have done this a few times, it’s become very easy to do.

Notice the Vuforia word and logo. That is because you are using a Development License. This will be removed if you use a paid License Key.

Ensure to save the scene you are working with any name you desired, it not important to what we are doing here the name chosen.

Step 3: More 3D Models

Now, let make it a bit more pretty. Let’s change the boring cube to something more adequate to the image we are tracking. However, the Unity3D’s Asset Store has a lot of material you can import without exit the app, sometimes you can find what you really need. So, I have found a better 3D model to use, the Octocat itself (thanks sillyking for this model). Sadly, to be enabled to download the model you must register.

  1. Go back to Unity3D and click on the Assets -> Import new Asset menu. Pick up the octocat.obj file from the twice zipped file.
  2. Delete the ugly cube and drag the Octocat model as a child of the ImageTarget.
  3. In the Project tab, navigate to the Assets\Editor\QCAR\ImageTargetTexture\\ and select the image that is there. In the Inspector tab, change texture type to sprite and click apply. Now, you can see the original image you have uploaded and recognizing. With that in mind, you can set the transform properties of the Octocat 3D object as you want to base on the right image position. You may use the same position info as I:Unity-PositionOctocatModel
  4. Try to play again and show you image to your cam. Moreover, to see the 3D model in the Game tab, we can see it show/hide likely the same in the Scene tab. Unity-ImageTarget3DModel.png

Step 4: Deploy to Android

You can deploy this application to many-many platforms. First, deploy to an Android device (you can choose to deploy to an iOS device, too). You may not have the required Unity3D package for that platform. In that case, Unity3D will display a button to download what is necessary and you only need to install it.

  1. Go to the File -> Build Settings. In the platform list, select the Android one and click on the Switch platform button.
  2. Click on the Player Settings, which will open the properties of the Android application.
  3. Click on the Add Open Scenes button to include the scene you have been working out in the application.Unity-BuildAndroid
  4. Click on the Player Settings button and a new tab should appear. Search the section Other Settings and then the subsection Identification. Change the Package Name to something with the format: com... Ensure to save your scene after you made the change. This is required to identify your application property.
  5. Click on the Build button and you will be prompted to save the .apk that will be generated. Choose any folder of your convenience and accept.
  6. Now, you can copy the file to your device and run it native.Android-Octocat.png

Step 5: Deploy to HoloLens

To Deploy to HoloLens, you should do several tweaks to your project.

  1. Select ImageTarget component and Check the Enable Extended Tracking property.
  2. Download HoloToolkit Package. HoloToolkit is a set of utilities for Unity3D development for HoloLens. It has a cool samples and Prefabs to import (We will see in next posts).
    Unity-HoloLensConfiguration-EnableExtendedTracking
  3. Go to the menu Asserts -> Import Package -> Custom Package and pick the .unitypackage file you have just downloaded. When a dialog with the details of the files that will be imported is shown, click on Import.
  4. In the Project tab, locate the Assets\HoloToolkit\Input\Prefabs\HoloLensCamera.prefab and drag to the Hierarchy tab.
  5. Select the ARCamera component in the Hierarchy tab and at Inspector Tab set the Central Anchor point to HoloLensCamera component. Unity-HoloLensConfiguration-SetHoloLensCamera
  6. You may noticed already that HoloToolkit  has added a new menu name HoloToolkit (D’oh!) in Unity3D.  Inside this menu there is a sub-menu that will Configure some parts to enabled to work or work fine in side HoloLens. Click Apply HoloLens Scene Settings and a popup should be displayed. Ensure all checks are checked and click Apply. Save your scene.Unity-ApplyHoloLensSceneSettings
  7. Next, do the same with the Apply HoloLens Capability Settings. Save your scene. Unity-ApplyHoloLensCapabilitySettings
  8. Do the same with the Apply HoloLens Project Settings. This popup will requires reload your entire project to force new settings take effect. Unity-ApplyHoloLensProjectSettings
  9. You may do an extra-check for the AppKey and the Load Database and Activate on the VuforiaConfiguration.
  10. Save your scene, before continuing.
  11. Finally, go back to the Build window and click the Build button and choose a directory where you would like to export the project.
  12. Once the build process has ended, open the .sln in the folder you set with Visual Studio. Change the Configuration Setting from ARM to x86 and now you can deploy to your HoloLens or run in the HoloLens Emulator.

Conclusion

In this post, Upload images to a database that later can be used for tracking other images and objects. Moreover, we imported to Unity3D and setup the ARCamera and ImageTarget component. And we imported an external 3D model to our scene. At the end, we build the project for different platform. And we didn’t make a single line of code!

We will continue in a next post showing how to recognize multiple images and how to distinguish each one showing different 3D models or specific data.

How to register a VSTS Extension

Register as a Publisher

  1. Login here. If you were not registered, a pop up like this will appears:

welcome

Create the extension web app

  1. Start by creating the web app with the page that will be your hub.
  2. In Visual Studio, create a new website.new-web-site
  3. Use the ASP.NET Empty Web Site templateempty-web-site
  4. Get the Client SDK VSS.SDK.js file and add it to your web app.
  • You can use the ‘npm install’ command to retrieve the SDK: npm install vss-web-extension-sdk.
  • Or you can reference this script.
  1. Create an HTML page that host your code and reference the VSS.SDK.js file.
  2. Ensure the SSL is enabled in the website project.

Create the extension manifest

The extension manifest tells Visual Studio Team Services about your extension.

  1. Create a JSON file (vss-extension.json, for example) in the home directory of your web app to describe your extension.manifest1
  2. Add your contribution.
  3. Add the files that you want to include in your package: i.e. your HTML page, your scripts, the SDK script and your logo.

Package your app

Extensions are packaged as VSIX 2.0 compatible VSIX files. To upload your extension, you need to package it as a VSIX 2.0 compatible VSIX file. Microsoft provides a cross-platform command line interface (CLI) to package (and also publish) your extension.

  1. If you don’t have it, get the TFS Cross Platform Command Line Interface (tfx-cli) using npm.

npm i -g tfx-cli

  1. Package your extension in a .vsix file. (open a command prompt in the web app folder). This command is same when you need to re-generate the package due an update.

tfx extension create –manifest-globs vss-extension.json

Publish your extension

To upload an extension to the Marketplace (you need to be registered as a publisher as previously seen):

  1. Navigate to the Visual Studio Marketplace Publishing Portal.
  2. Find the Upload new extension button, navigate to your packaged VSIX file, and select upload.
  3. After a quick validation, your extension will appear in the extensions list:published-extension

Share

At this point, your extension is not visible to any accounts and cannot be installed until you share it.

Before an extension can be installed into a Visual Studio Team Services account, it must be shared with that account. Sharing is a requirement during development and testing of an extension, as it is the only way to run an extension.

To share an extension so it can be installed:

  1. Click an extension from the list of displayed items
  2. Click the Share button
  3. Specify the name of the Visual Studio Team Services account to make this extension visible to. For example, to make an extension visible to the sw-testing.visualstudio.com account, specify sw-testing.

Install

  1. From your Team Services account home page, select the Marketplace icon in the top right corner and choose “Manage Extensions”:
    install-access
  2. Find the extension under the Shared with this account category:
    extension-installed
  3. Click the card to open the item in the Marketplace
  4. From the item’s details page, click the Install button
  5. Choose the account you shared the extension with and proceed through the installation process.
  6. Now you can test your extension in VSTS.

At this point, your extension is only visible to the shared Visual Studio Team Service Account.

Upload an updated extension’s

  1. Increment the version in the extension’s manifest.
  2. Generate the new VSIX file that contains the incremented version number.
  3. Click an extension from the list of displayed items
  4. Right-click and select Update.
  5. Browse to the VSIX for your extension and upload it.

The updated version of your extension is automatically installed to accounts that have it already installed. New accounts where the extension is installed in the future also receive the latest version.

Read more:

First blog post

In this, first post. I would like to commit me self to make an effort to not abandon this blog.

I created this blog, because I like to share my experiences with others peoples around.

A little about me: I like technology and try early things. A few month ago I changed my work to a fascinating company that works in latest Microsoft technology. So, I love it. So in this blog space I will share my vivid work-life.

Ideas and improvements are always welcomed.