博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Microsoft HoloLens开发入门
阅读量:6938 次
发布时间:2019-06-27

本文共 5864 字,大约阅读时间需要 19 分钟。

本帖最后由 geekli 于 2017-4-11 15:53 编辑

AR开发者交流群:605785368

AR开发者社区:

第一部分:开发要求
Hololens 运行与Win10,应用程序是与UWP(通用windows开发平台)构建的,开发Hololens 这样的全息体验对电脑的配置要求也是相当高的。

硬件配置:
1.64位Windows 10专业版,企业版或教育版(家庭版不支持Hyper-V)
2.64位CPU
3.8GB以上的RAM
4.在BIOS中,必须具备以下功能:
  • 硬件辅助虚拟化
  • 二级地址转换(SLAT)
  • 基于硬件的数据执行保护(DEP)
5.对于GPU,需DirectX 11.0或更高版本,WDDM 1.2驱动程序或更高版本
关于Hyper-V,它是微软的一款虚拟化产品,采用类似Vmware和Citrix开源Xen一样的基于hypervisor的技术。

第二部分:安装
1.启用虚拟化,即在PC上启用硬件虚拟化。

详细步骤请看:https://msdn.microsoft.com/library/windows/apps/jj863509(v=vs.105).aspx

2.启用Hyper-V

3.安装Visual Studio 2017Visual Studio 2015 

Update3https://developer.microsoft.com/en-us/windows/downloads

4.安装HoloLens emulator(https://developer.microsoft.com/en-us/windows/mixed-reality/hololens_emulator_archive)

5.安装Unity (https://.com/cn/get-unity/download)

第三部分:关于Hololens 模拟器
HoloLens模拟器允许你在没有Hololens的情况下在PC上测试全息应用程序,并附带Hololens开发工具集。仿真器使用Hyper-V虚拟机。
关于输入:
  • 向前,向后,向左和向右走 - 使用键盘上的W,A,S和D键或Xbox控制器上的左键。
  • 查找向上,向下,向左和向右 - 单击并拖动鼠标,使用键盘上的箭头键或Xbox控制器上的右键。
  • 空气敲击手势 - 右键单击鼠标,按键盘上的Enter键,或使用Xbox控制器上的A按钮。
  • 绽放手势 - 按键盘上的Windows键或F2键,或按Xbox控制器上的B按钮。手动移动滚动 - 按住Alt键,按住鼠标右键,向上/向下拖动鼠标,或者在Xbox控制器中按住右侧触发器和A按钮,向上和向下移动右侧手柄。

关于工具栏:

在主窗口的右侧,您将找到仿真器工具栏。工具栏包含以下按钮:

  • 关闭:关闭模拟器。
  • 最小化:最小化仿真器窗口。
  • 人工输入:鼠标和键盘用于模拟模拟器的人工输入。
  • 键盘和鼠标输入:键盘和鼠标输入直接传递到HoloLens操作系统作为键盘和鼠标事件,就像连接了蓝牙键盘和鼠标一样。
  • 适合屏幕:适合模拟器屏幕。
  • 缩放:使仿真器越来越大。
  • 帮助:打开模拟器帮助。
  • 打开设备门户:在仿真器中打开HoloLens OS的Windows设备门户。
  • 工具:打开“ 其他工具 ”窗格。

第四部分:开发----Hello,HoloLens!
首先我们在unity中新建一个项目,接着添加一个简单的3D模型进行测试,比如:
接着部署Windows Store
接着,点击Build,生成VS项目:
启动VS:
一般默认情况下,从Unity导出的UWP应用程序在任何Windows 10设备上运行。由于HoloLens是不同的,应用程序应该利用仅在HoloLens上可用的功能。为此,您需要在Visual Studio TargetDeviceFamily中的Package.appxmanifest文件中设置为“Windows.Holographic” ,如下:
接下来,就可以运行啦:

第五部分:输入事件总结
1.GAZE凝视操作
在Hololens中,使用的是用户的头部位置与方向来gaze,而不是眼睛。
示例代码(PS:核心在于RayCast):
[C#]
纯文本查看
复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using
UnityEngine;
public
class
WorldCursor : MonoBehaviour
{
private
MeshRenderer meshRenderer;
// Use this for initialization
void
Start()
{
// Grab the mesh renderer that's on the same object as this script.
meshRenderer =
this
.gameObject.GetComponentInChildren<MeshRenderer>();
}
// Update is called once per frame
void
Update()
{
// 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...
// Display the cursor mesh.
meshRenderer.enabled =
true
;
// Move the cursor to the point where the raycast hit.
this
.transform.position = hitInfo.point;
// Rotate the cursor to hug the surface of the hologram.
this
.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
}
else
{
// If the raycast did not hit a hologram, hide the cursor mesh.
meshRenderer.enabled =
false
;
}
}
}
2.手势输入
[C#]
纯文本查看
复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using
UnityEngine;
using
UnityEngine.VR.WSA.Input;
public
class
GazeGestureManager : MonoBehaviour
{
public
static
GazeGestureManager Instance {
get
;
private
set
; }
// Represents the hologram that is currently being gazed at.
public
GameObject FocusedObject {
get
;
private
set
; }
GestureRecognizer recognizer;
// Use this for initialization
void
Start()
{
Instance =
this
;
// Set up a GestureRecognizer to detect Select gestures.
recognizer =
new
GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
// Send an OnSelect message to the focused object and its ancestors.
if
(FocusedObject !=
null
)
{
FocusedObject.SendMessageUpwards(
"OnSelect"
);
}
};
recognizer.StartCapturingGestures();
}
// 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 the focused object changed this frame,
// start detecting fresh gestures again.
if
(FocusedObject != oldFocusObject)
{
recognizer.CancelGestures();
recognizer.StartCapturingGestures();
}
}
}

3.语音输入

using System.Collections.Generic;

using System.Linq;

using UnityEngine;

using UnityEngine.Windows.Speech;

public class SpeechManager : MonoBehaviour

{

KeywordRecognizer keywordRecognizer = null;

Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();

// Use this for initialization

void Start()

{

keywords.Add("Reset world", () =>

{

// Call the OnReset method on every descendant object.

this.BroadcastMessage("OnReset");

});

keywords.Add("Drop Object", () =>

{

var focusObject = GazeGestureManager.Instance.FocusedObject;

if (focusObject != null)

{

// Call the OnDrop method on just the focused object.

focusObject.SendMessage("OnDrop");

}

});

// Tell the KeywordRecognizer about our keywords.

keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());

// Register a callback for the KeywordRecognizer and start recognizing!

keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;

keywordRecognizer.Start();

}

private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)

{

System.Action keywordAction;

if (keywords.TryGetValue(args.text, out keywordAction))

{

keywordAction.Invoke();

}

}

}

4.音频输入

转载地址:http://eginl.baihongyu.com/

你可能感兴趣的文章
各种大型网站技术架构
查看>>
MySQL + MHA + keepalive + VIP 高可用实验
查看>>
exchange2010 移动邮箱
查看>>
使用syslog-ng搭建日志服务器
查看>>
跨域 Cookie 实现单点登录
查看>>
Facade模式[fəˈsɑːd]
查看>>
PVS架构之VHD虚拟磁盘 二
查看>>
ECS centos6.5安装redis3.0.7单机版
查看>>
我的友情链接
查看>>
Linux下安装jdk报Permission denied以及chmod详解
查看>>
Python搭建环境
查看>>
Solr环境搭建及IK分词的集成及solrJ的调用(二)
查看>>
No code, no money; No defect, no job.
查看>>
NO3
查看>>
LVS--DR模型
查看>>
微信扫码支付
查看>>
CentOS7.0 下sphinx搭建
查看>>
在三台不同的CentOS 7主机上用rpm包快速部署LAMP
查看>>
网页制作设计师如何能说服客户让网站落地
查看>>
浅谈JNDI导入两个同名不同路径jar包的先后次序影响程序运行结果的问题
查看>>