Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MR: Preparing and Uploading Holograms Into Azure

DZone's Guide to

MR: Preparing and Uploading Holograms Into Azure

Continuing on with this series of MR assets and the cloud, we'll see how to upload holograms into Azure blog storage so they can be used later.

· IoT Zone ·
Free Resource

In my series about remote assets, there’s one major thing left: how to use remote assets that can be used as holograms in your mixed reality app. I will do this in two posts:

  1. Prepare for usage and actual upload
  2. Use and download.

And this is, as you guessed, the first post.

Asset Bundles

A Unity asset bundle is usually used to create downloadable content for games, or assets that are specific to a platform or game level, so the user does not have to download everything at once. This enhances startup time, but also saves on (initial) bandwidth and local storage. Also, you can update part of the app without actually requiring the user to download a completely new app. There are some limitations, but we will get to that.

General Set Up

We want to create an app that downloads assets that it does not initially have included in it. But a Unity project is what we need to actually build the asset bundles. So we need two projects: The actual app that will run, and a ‘builder’ project. That project – which I not completely correctly called SceneBuilder: – you can find here. I will show you how to prepare an asset bundle that contains a complete scene, and one that only contains a single prefab.

The SceneBuilder contains everything a normal Unity app does: scenes, assets, scripts, the works. And something extra. But first, our runtime app is going to use the Mixed Reality Toolkit, some stuff from the Mixed Reality Toolkit Samples, LeanTween, and my own extensions. I kind of threw it all in because why not. It also contains three scenes in the root.

  • Main (which is empty and not used)
  • BuildScene (a rather dark scene that contains a house from the Low Poly Buildings Lite package, and nothing else)
  • PrefabScene (which contains what seems to be a normal Mixed Reality app, as well an airplane called “Nathalie Aguilera Boing 747” (I assume “Boing” should be “Boeing”, and the model is actually a Boeing 737 but whatever – it’s a nice low poly model)

imageimage

The most important thing is the AssetBundle Browser. This is a piece of code provided by Unity to make building asset bundles a lot easier. You can find the AssetBundle Browser in folder “UnityEngine.AssetBundles” under “Assets. You can download the latest version from Unity’s GitHub repo. It comes with a whole load, but basically, you only need everything that’s under UnityEngine.AssetBundles/Editor/AssetBundleBrowser. This you plonk in your SceneBuilder project’s Asset folder.

imageThe BuildScene

If you open the BuildScene first, you will see there’s actually very little in it. An empty ‘SceneHolder’ object, and a “Suburb House 1” prefab in it. The lack of lighting also makes the scene rather dark. This has a reason: We are going to add this scene to another scene later, and we don’t want all kinds of duplicate stuff like lighting, Mixed Reality toolkit managers, etc. – coming into our existing app. So almost everything is deleted. But to that Prefab, one thing is added: the Horizontal Animator behavior (that debuted in this article).imageThis is a very simple behavior that will make the house spin around every five seconds. Nothing special – this is to prove a point later.

If you play the scene, you will actually see the house spinning in the scene. The Game window will be black, only saying “Display 1 No cameras rendering”, which is correct, as I deleted everything but the asset we are going to build and upload, so there’s even no camera to show anything.

Build the BuildScene Asset Bundle

First order of business – build the UWP app as if you are going to create an actual Mixed Reality app for HoloLens and/or an immersive headset out of the SceneBuilder. If you don’t, the AssetBundle browser will kick off that process, and if there’s a syntax error or whatever – its modal build window will get stuck, blocking Unity – and the only way out is killing it in the Task manager.

Click Window/AssetBundle Browser and you will see this:

image

I already pre-defined some stuff for you. What I basically did was, in an emtpy AssetBundle browser, drag the BuildScene into the empty screen:

Untitled

And the AssetBundle Browser then adds everything it needs automatically. Click the tab “Build” and make sure the settings are the same as what you see here. Pay particular attention to the build target. That should be WSAPlayer, because that’s the target we use in the app that will download the assets.

Untitled

Hit the ugly wide “Build” button and wait until the build completes. If it all works out, you will see four files in SceneBuilder\AssetBundles\WSAPlayer:

  • buildscene
  • buildscene.manifest
  • WSAPlayer
  • WSAPlayer.manifest

Only those were there all along, as I checked the folder with these files in GitHub. But go ahead, delete the files manually, you will see they are re-created. You will see they are all only 1 KB, except for buildscene – that’s 59 KB.

The PrefabScene

This looks more like a normal scene: It has everything in it you would expect in there and the airplane.

image

imageIf you hit the play button in this scene, the airplane will move around in a way that makes you happy you are not aboard it, due to a behavior called “Move Around”. This script sits in “Assets/App/Scripts” and is nothing more than a start method that creates a group of points relative to the start position and moves it around using LeanTween:

void Start()
{
    var points = new List<Vector3>();
    points.Add(gameObject.transform.position);
    points.Add(gameObject.transform.position);
    points.Add(gameObject.transform.position + new Vector3(0,0,1));
    points.Add(gameObject.transform.position + new Vector3(1,0,1));
    points.Add(gameObject.transform.position + new Vector3(-1,0,1));
    points.Add(gameObject.transform.position + new Vector3(-1,1,1));
    points.Add(gameObject.transform.position);
    points.Add(gameObject.transform.position);

    LeanTween.moveSpline(gameObject, points.ToArray(), 3).setLoopClamp();
}


But this script will later cause us some trouble, as we will see in the next post (also to prove a point). I created a prefab of this airplane with its attached behavior in Assets/App/Prefabs. Open the AssetBundle Brower again, drag this prefab onto the left pane of the dialog like this:

Untitled

UntitledOnly this creates an impossibly long name, so simply right-click on the name and rename it to “airplane”. Select the “Build” tab again, hit the wide Build button again, wait a while.

If everything went according to plan, SceneBuilder\AssetBundles\WSAPlayer should now contain two extra files:

  • airplane
  • airplane.manfest

The manifest file is once again 1 KB, airplane itself should be 87 KB

Uploading to Azure

This is the easiest part. Use the Azure Storage Explorer:

Untitled

Simply drag your the airplane and buildscene (you don’t need anything else) into a blob container of any old storage account. The right-click on a file, select “Get Shared Access Signature”, and click “Create”, but not before paying close attention to the date/time range, particularly the start date and time

image

The Azure Storage explorer tends to generate a start time some time (1.5 hours or so) in the future, and if you use the resulting URL right away, it won’t work. Believe me – been there, done that, and I am glad no one could hear me. So dial back the start time to the present or a little bit in the past, then create the URL, then save it. Do this for both the airplane and the buildscene file. We will need them in the next post to actually download and use them.

Conclusion

We have built two assets and uploaded them to Azure without writing any code – only a little code to make the airplane move, but that was not part of the build/upload procedure. Of course, you can write the code to build asset bundles yourself, but I am  lazy  smart and tend to use what I can  steal  borrow from the internet. This was almost all point-and-click, but next time we will see more code. For the impatient, the whole finished project can be found here.

Topics:
hologram ,iot ,mixed reality ,unity ,azure blob storage ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}