酱学堂|Hololens 开发入门(hololens开发教程)

开发要求

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上启用硬件虚拟化。

酱学堂|Hololens 开发入门(hololens开发教程)

详细步骤请看:

https://msdn.microsoft.com/library/windows/apps/jj863509(v=vs.105).aspx

2.启用Hyper-V

3.安装Visual Studio 2017或Visual Studio 2015 Update3(https://developer.microsoft.com/en-us/windows/downloads)

酱学堂|Hololens 开发入门(hololens开发教程)

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

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

关于详细的安装视频,可以看看老外的这个教程:

不过不知道什么原因,视频腾讯过不了所以大家可以在优酷看,或者点击阅读原文

视频:

http://v.youku.com/v_show/id_XMTUzMjQ2Nzk0MA==.html

第三部分:关于Hololens 模拟器

HoloLens模拟器允许你在没有Hololens的情况下在PC上测试全息应用程序,并附带Hololens开发工具集。仿真器使用Hyper-V虚拟机。

关于输入:

酱学堂|Hololens 开发入门(hololens开发教程)

  1. 向前,向后,向左和向右走 – 使用键盘上的W,A,S和D键或Xbox控制器上的左键。

  2. 查找向上,向下,向左和向右 – 单击并拖动鼠标,使用键盘上的箭头键或Xbox控制器上的右键。

  3. 空气敲击手势 – 右键单击鼠标,按键盘上的Enter键,或使用Xbox控制器上的A按钮。

  4. 绽放手势 – 按键盘上的Windows键或F2键,或按Xbox控制器上的B按钮。手动移动滚动 – 按住Alt键,按住鼠标右键,向上/向下拖动鼠标,或者在Xbox控制器中按住右侧触发器和A按钮,向上和向下移动右侧手柄。

关于工具栏:

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

  • 关闭:关闭模拟器。

  • 最小化:最小化仿真器窗口。

  • 人工输入:鼠标和键盘用于模拟模拟器的人工输入。

  • 键盘和鼠标输入:键盘和鼠标输入直接传递到HoloLens操作系统作为键盘和鼠标事件,就像连接了蓝牙键盘和鼠标一样。

  • 适合屏幕:适合模拟器屏幕。

  • 缩放:使仿真器越来越大。

  • 帮助:打开模拟器帮助。

  • 打开设备门户:在仿真器中打开HoloLens OS的Windows设备门户。

  • 工具:打开“ 其他工具 ”窗格。

开发—-Hello,HoloLens!

首先我们在unity中新建一个项目,接着添加一个简单的3D模型进行测试,比如:

酱学堂|Hololens 开发入门(hololens开发教程)

酱学堂|Hololens 开发入门(hololens开发教程)

接着部署Windows Store

酱学堂|Hololens 开发入门(hololens开发教程)

酱学堂|Hololens 开发入门(hololens开发教程)

接着,点击Build,生成VS项目:

酱学堂|Hololens 开发入门(hololens开发教程)

启动VS:

酱学堂|Hololens 开发入门(hololens开发教程)

酱学堂|Hololens 开发入门(hololens开发教程)

一般默认情况下,从Unity导出的UWP应用程序在任何Windows 10设备上运行。由于HoloLens是不同的,应用程序应该利用仅在HoloLens上可用的功能。为此,您需要在Visual Studio TargetDeviceFamily中的Package.appxmanifest文件中设置为“Windows.Holographic” ,如下:

酱学堂|Hololens 开发入门(hololens开发教程)

接下来,就可以运行啦:

酱学堂|Hololens 开发入门(hololens开发教程)

酱学堂|Hololens 开发入门(hololens开发教程)

第五部分:输入事件总结

1

GAZE凝视操作

酱学堂|Hololens 开发入门(hololens开发教程)

在Hololens中,使用的是用户的头部位置与方向来gaze,而不是眼睛。

示例代码(PS:核心在于RayCast):

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();

}

// 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

手势输入

酱学堂|Hololens 开发入门(hololens开发教程)

示例代码:

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();

}

}

}

Update方法会持续检查是否有任何对象被注视并将对象设置为焦点,以便在点击时向对象发送一个轻击的事件。GestureRecognizer负责识别用户的手势。

3

语音输入

酱学堂|Hololens 开发入门(hololens开发教程)

示例代码:

using System.Collections.Generic;

using System.Linq;

using UnityEngine;

using UnityEngine.Windows.Speech;

public class SpeechManager : MonoBehaviour

{

KeywordRecognizer keywordRecognizer = null;

Dictionarykeywords = new Dictionary();

// 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

.音频输入

酱学堂|Hololens 开发入门(hololens开发教程)

示例代码:

using UnityEngine;

public class SphereSounds : MonoBehaviour

{

AudioSource audioSource = null;

AudioClip impactClip = null;

AudioClip rollingClip = null;

bool rolling = false;

void Start()

{

// Add an AudioSource component and set up some defaults

audioSource = gameObject.AddComponent();

audioSource.playOnAwake = false;

audioSource.spatialize = true;

audioSource.spatialBlend = 1.0f;

audioSource.dopplerLevel = 0.0f;

audioSource.rolloffMode = AudioRolloffMode.Custom;

// Load the Sphere sounds from the Resources folder

impactClip = Resources.Load(\”Impact\”);

rollingClip = Resources.Load(\”Rolling\”);

}

// Occurs when this object starts colliding with another object

void OnCollisionEnter(Collision collision)

{

// Play an impact sound if the sphere impacts strongly enough.

if (collision.relativeVelocity.magnitude >= 0.1f)

{

audioSource.clip = impactClip;

audioSource.Play();

}

}

// Occurs each frame that this object continues to collide with another object

void OnCollisionStay(Collision collision)

{

Rigidbody rigid = this.gameObject.GetComponent();

// Play a rolling sound if the sphere is rolling fast enough.

if (!rolling && rigid.velocity.magnitude >= 0.01f)

{

rolling = true;

audioSource.clip = rollingClip;

audioSource.Play();

}

// Stop the rolling sound if rolling slows down.

else if (rolling && rigid.velocity.magnitude < 0.01f)

{

rolling = false;

audioSource.Stop();

}

}

// Occurs when this object stops colliding with another object

void OnCollisionExit(Collision collision)

{

// Stop the rolling sound if the object falls off and stops colliding.

if (rolling)

{

rolling = false;

audioSource.Stop();

}

}

}

OnCollisionEnter,OnCollisionStay而OnCollisionExit事件确定何时开始播放音频剪辑,是否继续音频剪辑以及何时停止播放音频剪辑。

AR酱原创,转载务必注明

微信号AR酱(ARchan_TT)

AR酱官网:www.arjiang.com

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

(0)
上一篇 2024年5月3日 上午8:05
下一篇 2024年5月3日 上午8:17

相关推荐

  • 大学生课外科研项目设计类大学生课外科研项目设计类

    大学生课外科研项目设计 随着现代教育的不断发展,大学生的课外时间变得越来越充足,因此,设计一些有趣的、有意义的、具有挑战性的课外科研项目成为了许多大学生的兴趣爱好。本文将介绍一些大…

    科研百科 2024年9月3日
    5
  • 学生科研项目临床申请书

    学生科研项目临床申请书 尊敬的评审专家: 我是一名年轻的医学僧,目前正在参与一项学生科研项目。该项目旨在探索一种新型的治疗方案,以提高患者的生存质量和生活质量。在这个项目中,我将会…

    科研百科 2025年5月9日
    3
  • NFT数字藏品交易系统平台开发方案(nft 数字藏品)

    数字藏品是基于区块链技术(境内联盟链)记账的具有一定收藏价值的数字化商品。数字藏品不同于境外容易形成空气币的代币、虚拟币等,它有真实商品价值背书。 数字藏品经营是电商平台逻辑,而不…

    科研百科 2024年5月1日
    54
  • 科研项目不缴纳社保

    科研项目不缴纳社保: 近年来,随着科技的不断发展,科研项目已经成为社会发展的重要推动力量。但是,在享受这些科技发展带来的成果的同时,科研项目的参与者也需要面对一些困难。其中,科研项…

    科研百科 2025年2月27日
    9
  • Strawberry Perl安装

    Strawberry Perl是一款功能强大且易于使用的Perl脚本语言编译器,它可以帮助开发人员快速构建和测试 Perl 脚本。Strawberry Perl 可以在大多数操作系…

    科研百科 2024年10月14日
    79
  • 做科研项目挣钱多吗知乎

    做科研项目挣钱多吗?这是一个非常具有争议性的问题。在回答这个问题之前,我们需要明确一下科研项目的挣钱方式。 科研项目的挣钱方式通常有以下几种: 1. 项目收益:科研项目通常会产生一…

    科研百科 2025年5月2日
    9
  • 知网不能查科研项目

    知网不能查科研项目 随着科技的不断发展,数字化已经成为我们日常生活的一部分。其中,知识共享平台知网(维普中文期刊全文数据库)成为了学术研究领域的重要资源。然而,随着知网的普及和使用…

    科研百科 2025年4月11日
    4
  • app软件制作开发报价

    在当今数字化时代,移动应用程序(App)已经成为人们生活中不可或缺的一部分。无论是购物、社交、娱乐还是工作,App都为我们提供了便利和娱乐。然而,对于许多企业和个人而言,制作和开发…

    科研百科 2024年2月24日
    110
  • 嵊州协同办公系统

    嵊州协同办公系统: 让办公更高效 随着数字化时代的到来,协同办公系统成为了现代企业不可或缺的一部分。嵊州协同办公系统则是嵊州地区一家知名互联网公司为了提升企业工作效率而开发的一款高…

    科研百科 2025年1月7日
    4
  • 软件项目管理系统软件开发方案(软件项目管理系统软件开发)

    软件项目管理系统软件开发软件项目管理系统软件开发数码产品开发今日头条用户在 APP平台上发布的《软件开发类应用商店下载(APP)》,在 软件系统中购买了12 种软件,其中有 【产品…

    科研百科 2024年5月19日
    39