1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

HoloLnens 2の視線インタラクションで外部センサを用いてクリックする

1
Last updated at Posted at 2025-12-23

はじめに

きょうすけです。HoloLens 2を使ってインタラクションの研究をしている大学院生です。
この記事はIwaken Lab. Advent Calendar 2025の24日目の記事となります。メリークリスマス🌲

やりたいこと

HoloLens2は視線を使ったインタラクション(ボタンのクリックなど)ができます。

このインタラクションでは視線でカーソルを合わせて、そのターゲットを見続ける(ドウェル)ことでボタンを選択します。
このドウェルの部分をセンサで代替しようというのが今回のテーマです。

前提条件

Unity+MRTK環境で作業します。
また、センサ値はArduinoからWebSocket経由でHoloLens 2に送られてくるものとします。(これのやり方は要望があれば記事化します)

やり方

「取得したセンサ値が一定値を超えればクリックする」という処理はMRTK環境だとinteractableを中心に構築するとよいです。

今回は「カーソルが当たっている(フォーカスしている)ボタンをクリックする」という処理を書きたいのでinteractableOnFocusReceiverを使います。
以下ではフォーカスした時にinteractableがついているボタンオブジェクトを取得し、フォーカス外れた時に取得したオブジェクトから参照を外してnullにしています。

focus.cs
public void Start()
{
    _onFocusReceiver = interactable.GetReceiver<InteractableOnFocusReceiver>();
    
    _onFocusReceiver.OnFocusOn.AddListener(OnFocusEnter);
    _onFocusReceiver.OnFocusOff.AddListener(OnFocusExit);
}

private void OnFocusEnter()
{
    Debug.Log("OnFocusEnter");
    _target = interactable.gameObject;
    Debug.Log(_target.name);
}

private void OnFocusExit()
{
    Debug.Log("OnFocusExit");
    _target = null;
}

以上の処理を図にするとこんな感じ。
画像1.png

後はセンサ値がしきい値を超えた時に、_targetがnullでなければintaractableのクリック処理を発火させるだけです。
ここではセンサ値sensorが100を超えたらクリックしています。

focus.cs
private void Update()
{
    if (!_target) return;
    if (sensor > 100)
    {
        interactable.OnClick.Invoke();
    }
}

終わりに

大学院生の間に結構HoloLens 2を触っていたのでHoloLens 2(というかUWP)の良くないところにも気付きつつ、色々なことができるHMDだなと愛着が湧いてる次第です。
HoloLens 3出てほしいですね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?