3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Unity】NRSDKのエミュレーターサンプルを動かしてみる【Nreal】

Last updated at Posted at 2020-07-23

はじめに

今回は、NRSDKを使い、UnityEditor上でサンプルシーンを動作させます。
非常に簡単なので、Nreal本体を持っていない方でも体験可能なものとなっております。

早速始めましょう。

使用環境

Windows10 Home 64bit
Unity2018.4.20.f1
NrealSDK 1.3.0

1.NRSDKをUnityにインポートする

Nreal公式HP(https://developer.nreal.ai/) からアカウント作成後、ダウンロード可能です。
ダウンロードしたSDKのUnityPackageをUnityにインポートしましょう。

インポートができたらAssets直下に「NRSDK」というファイルが配置されます。

2.エミュレーターのサンプルシーンを開く

エミュレーターのサンプルシーンは「Nreal/Emulator/Scene」にあります。
・TrackableImageEmulator
  マーカー画像を認識するサンプル
・TrackablePlaneEmulator
  平面検知した面を認識するサンプル

どちらかお好きなシーンを開きましょう。

3.UnityEditorでPlayを押して、動作を確認する

実行すると、マーカーや平面にCubeが表示されると思います。

以下、操作方法

移動
前:W
後:S
左:A
右:D

Nrealのコントローラー
上:右クリック
中:左クリック
下:スクロールクリック

マーカー画像認識、平面検知について

ちなみに、**どのようにマーカー画像や平面を認識してるのか?**と考えると思います。
エミュレーターでは、以下のメソッドで判定しているようです。

つまり、 「マーカー認識と言ってもマーカーの特徴点を取り、解析を行っている」のではなく、
「カメラが画面内にある時にマーカーのセンター座標にオブジェクトを表示する」という感じでしょうか。

       public bool IsInGameView(Vector3 worldPos)
        {
            if (centerCam == null) centerCam = GameObject.Find("CenterCamera").GetComponent<Camera>();
            Transform camTransform = centerCam.transform;
            Vector2 viewPos = centerCam.WorldToViewportPoint(worldPos);
            Vector3 dir = (worldPos - camTransform.position).normalized;
            float dot = Vector3.Dot(camTransform.forward, dir);
            if (dot > 0 && viewPos.x >= 0 && viewPos.x <= 1 && viewPos.y >= 0 && viewPos.y <= 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
}

おわりに

サンプルシーンが用意されていたため、比較的容易に体験できました。
今後もNrealの理解を深めていこうと思います。

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?