Hololens学习——HelloProject100

本文仅供学习使用,官方文档戳这里


这篇教程告诉开发者如何使用Unity快速创建一个HoloLens项目,所有涉及的一些配置。重点是unity的导出设置和导出后的VisualStudio项目的一些设置。


Chapter 1 - Createa New Project

To build an app with Unity, you first needto create a project. A project is a folder that holds all assets you importfrom digital content creation tools such as Maya, Max Cinema 4D or Photoshop,all code you create with Visual Studio or your favorite code editor, and anynumber of content files that Unity creates as you compose scenes, animationsand other Unity asset types in the editor.

To build and deploy UWP apps, Unity canexport the project as a Visual Studio solution that will contain all necessaryasset and code files.

1.       Start Unity

2.       Select New

3.       Enter a projectname (e.g. "MixedRealityIntroduction")

4.       Enter a locationto save your project

5.       Ensure the 3D toggleis selected

6.       Select Createproject

Congrats, you are all setup to get startedwith your mixed reality customizations now.

 

 

Chapter 2 - Setupthe Camera

The Unity Main Camera handles headtracking and stereoscopic rendering. There are a few changes to make to theMain Camera to use it with mixed reality.

1.       Select File >New Scene

First, it will be easier to lay out yourapp if you imagine the starting position of the user as (X: 0, Y:0, Z: 0). Since the Main Camera is tracking movement of the user'shead, the starting position of the user can be set by setting the startingposition of the Main Camera.

1.       Select MainCamera in the Hierarchy panel

2.       In the Inspector panel,find the Transform component and change the Position from(X: 0, Y: 1, Z: -10) to (X: 0, Y:0, Z: 0)

Second, the default Camera backgroundneeds some thought.

For HoloLens applications, the real worldshould appear behind everything the camera renders, not a Skybox texture.

1.       With the MainCamera still selected in the Hierarchy panel, findthe Camera component in the Inspector paneland change the Clear Flags dropdown fromSkybox to SolidColor.

2.       Select the Background colorpicker and change the RGBA values to (0, 0, 0, 0)

修改相机的ClearFlags及颜色为了让背景色透明,以现实为背景。

For mixed reality applications targeted tooccluded displays, we can use the default Skybox texture that Unity provides.

1.       With the MainCamera still selected in the Hierarchy panel, findthe Camera component in the Inspector paneland keep the Clear Flags dropdown to Skybox.

Third, let us consider the near clip planein Unity and prevent holograms from being rendered too close to the users eyesas a user approaches a hologram or a hologram approaches a user.

For HoloLens applications, the near clipplane can be set to the HoloLens recommended 0.85meters.

1.       With the MainCamera still selected in the Hierarchy panel, findthe Camera component in the Inspector paneland change the Near Clip Plane field from the default 0.3 tothe HoloLens recommended 0.85.

For mixed reality applications targeted tooccluded displays, we can use the default setting that Unity provides.

1.       With the MainCamera still selected in the Hierarchy panel, findthe Camera component in the Inspector paneland keep the Near Clip Plane field to the default0.3.

Finally, let us save our progress so far.To save the scene changes, select File > Save Scene As, name thescene Main, and select Save.

Chapter 3 - Setupthe Project Settings

In this chapter, we will set some Unityproject settings that help us target the Windows Holographic SDK fordevelopment. We will also set some quality settings for our application.Finally, we will ensure our build targets are set to Windows Store.

Unity performance and quality settings


Unity quality settings for HoloLens

Sincemaintaining high framerate on HoloLens is so important, we want the qualitysettings tuned for fastest performance. For more detailed performanceinformation, Performance recommendations for Unity.

1.       Select Edit> Project Settings > Quality

2.       Select the dropdown underthe Windows Store logo and select Fastest. You'llknow the setting is applied correctly when the box in the Windows Store columnand Fastest row is green.

Hololens配置大概在千元机中间,所以需要选择更快的渲染质量

For mixed reality applications targeted tooccluded displays, you can leave the quality settings to its default values.

Target Windows Holographic SDK

Target Windows Holographic SDK

Weneed to let Unity know that the app we are trying to export should create aholographic view instead of a 2D view. We do this by enabling Virtual Realitysupport on Unity targeting the Windows Holographic SDK.

1.       Select Edit> Project Settings > Player

2.       In the Inspector panelclick on the Windows Store tab

3.       Expand the OtherSettings group.

4.       In the Rendering section,check the Virtual Reality Supported checkbox to add a new VirtualReality SDKs list and confirm "Windows Holographic" islisted as a supported SDK.

Awesome job on getting all the projectsettings applied. Next, let us add a hologram!

Chapter 4 - Createa Hologram

Creating a hologram in your Unity projectis just like creating any other object in Unity. Placing a hologram in front ofthe user is easy because Unity's coordinate system is mapped to the real world- where one meter in Unity is approximately one meter in the real world.

1.       In the top leftcorner of the Hierarchy panel, select the Create dropdownand choose 3D Object > Cube.

2.       Select the newlycreated Cube in the Hierarchy panel

3.       In the Inspector findthe Transform component and change Position to(X: 0, Y: 0, Z: 2). This positions thecube 2 meters in front of the user's starting position.

4.       In the Transform component,change Rotation to (X: 45, Y: 45, Z:45) and change Scale to (X: 0.25, Y: 0.25, Z:0.25). This scales the cube to 0.25 meters.

5.       To save the scenechanges, select File > Save Scene.

Chapter 5 - Verifyon device from Unity editor

Now that we have created our hologram, itis time to do a quick check in device. You can do this directly from within theUnity editor.

For HoloLens use Unity Remoting

1.       On your HoloLens,install and run the Holographic Remoting PlayerWindowsstore上下载,可以获取本机的ip地址), available from the Windows Store. Launchthe application on the device, and it will enter a waiting state and show theIP address of the device. Note down the IP.

2.       On yourdevelopment PC, in Unity, open Window > Holographic Emulation.

3.       Change EmulationMode from None to Remote to Device.

4.       In RemoteMachine, enter the IP address of your HoloLens noted earlier.

5.       Click Connect.

6.       Ensure the ConnectionStatus changes to green Connected.

7.       Now you can nowclick Play in the Unity editor.

You will now be able to see the hologramin device and in the editor. You can pause, inspect objects, and debug justlike you are running an app in the editor, because that’s essentially what’shappening, but with video, audio, and device input transmitted back and forthacross the network between the host machine and the device.

For other mixed reality supported headsets

1.       Connect theheadset to your development PC using the USB cable and the HDMI or display portcable.

2.       Launch the MixedReality Portal and ensure you have completed the first run experience.

3.       From Unity, youcan now press the Play button.

You will now be able to see the hologramrendering in your mixed reality headset and in the editor.

Chapter 6 - Buildand deploy to device from Visual Studio

We are now ready to compile our project toVisual Studio and deploy to our target device.

Export to the Visual Studio solution

1.       Open File> Build Settings window.

2.       Click AddOpen Scenes to add the scene.

3.       Change Platform to WindowsStore and click Switch Platform.

4.       In WindowsStore settings ensure, SDK is Universal 10.

5.       For Target device,leave to Any Device for occluded displays or switch to HoloLens.

6.       UWP Build Type should be D3D.

7.       UWP SDK could beleft at Latest installed.

8.       Check UnityC# Projects under Debugging.

9.       Click Build.

10.    In the fileexplorer, click New Folder and name the folder "App".

11.    With the App folderselected, click the Select Folder button.

12.    When Unity is donebuilding, a Windows File Explorer window will appear.

13.    Open the App folderin file explorer.

14.    Open the generatedVisual Studio solution (MixedRealityIntroduction.sln in this example)

 

 

Compile the Visual Studio solution

Finally, we will compile the exportedVisual Studio solution, deploy it, and try it out on the device.

1.       Using the top toolbarin Visual Studio, change the target from Debug to Release andfrom ARM to X86.

The instructions differ for deploying to adevice versus the emulator. Follow the instructions that match your setup.

Deploy to mixed reality device over Wi-Fi

1.       Click on the arrownext to the Local Machine button, and change the deploymenttarget to Remote Machine.

2.       Enter the IPaddress of your mixed reality device and change Authentication Mode toUniversal (Unencrypted Protocol) for HoloLens and Windows forother devices.

3.       Click Debug> Start without debugging.

For HoloLens, If this is the first time deploying toyour device, you will need to pair Using Visual Studio.

Deploy to mixed reality device over USB

Ensure you device is plugged in via theUSB cable.

链接USB数据线的,需要VisualStudio选择Device

1.       For HoloLens, click on thearrow next to the Local Machine button, and change thedeployment target to Device.

2.       For targetingoccluded devices attached to your PC, keep the setting to Local Machine.Ensure you have the Mixed Reality Portal running.

3.       Click Debug> Start without debugging.

Deploy to Emulator

1.       Click on the arrownext to the Device button, and from drop down select HoloLensEmulator.

2.       Click Debug> Start without debugging.

 




如有疑问,可以加我微信:GameDesigner_CJC,QQ:1115738177 促膝长谈!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值