LoginSignup
20
16

More than 5 years have passed since last update.

ARCoreをためしてみた

Last updated at Posted at 2017-08-31

概要

この記事古いです、今はPreview2がでているのでこちらを参考してください
https://qiita.com/taptappun/items/a5337d29a43d5d673c7f

ARCoreを以下に沿って試した、軽くソースを見たまとめ
特にエラーもなく動作した
https://developers.google.com/ar/develop/unity/getting-started

詳細

動作端末

  • Pixel/Pixel XL
  • Galaxy S8

https://developers.google.com/ar/discover/#supported_devices
今回はPixel XLを利用

動作対象OS

  • Android7.0以上
    8.0でも一応動いた

開発環境

環境構築手順

基本的にgetting-started通りでOK
1. Unityダウンロード後install
  - デフォルトのままインストールすればOKのはず、Androidが対象となっているかだけ見たほうがいいかも
2. ARCore SDK for Unity import
  - ダウンロードしてきたARCore SDK for Unityをimport
  - Unity開いて対象ファイル実行すればimportされる
3. File > BuildSettingsをひらき、Androidを選択しswitch Platform押下
スクリーンショット 2017-08-31 12.56.38.png
4. Player Settings押下、以下のように設定
  - Multithread Renderingをoffにする
  スクリーンショット 2017-08-31 12.45.12.png
  - Package Nameをcom.example.helloARにする(デフォルトじゃなければなんでもいい)、Minimum API LevelをAPI Level 24に、Target API LevelをAPI Level 24以上に
  スクリーンショット 2017-08-31 12.45.02.png
  - 一番下にあるxR SettingsのTango SupportedをONに
 スクリーンショット 2017-08-31 12.45.27.png
5. デバイスにCoreAR動作に必要なapk install
  - apkをダウンロード、インストール
  https://github.com/google-ar/arcore-android-sdk/releases/download/sdk-preview/arcore-preview.apk
  - apkのインストール方法がわからない人は以下を参照
    https://developer.android.com/studio/debug/dev-options.html#enable
    https://developer.android.com/studio/debug/dev-options.html#debugging

動作した感じ

https://youtu.be/IL4iMZfGFSA
ARKitと同じイメージ、平面を認識して、そこにものを置ける

コードを軽く読んだ感じ

PointCloudを軽く読んで見た


        public void Update()
        {
            // Do not update if ARCore is not tracking.
            if (Frame.TrackingState != FrameTrackingState.Tracking)
            {
                return;
            }

Frameの中に現在のTrackingの状態が入っている、その状態によって処理を振り分ける
https://developers.google.com/ar/reference/unity/class/google-a-r-core/frame

例えばPointCloudをUpdate契機で取得して、今保持しているものよりTimeStampが新しければ置き換える的なことをする


            // Fill in the data to draw the point cloud.
            PointCloud pointcloud = Frame.PointCloud;
            if (pointcloud.PointCount > 0 && pointcloud.Timestamp > m_lastPointCloudTimestamp)
            {
                // Copy the point cloud points for mesh verticies.
                for (int i = 0; i < pointcloud.PointCount; i++)
                {
                    m_points[i] = pointcloud.GetPoint(i);
                }

                // Update the mesh indicies array.
                int[] indices = new int[pointcloud.PointCount];
                for (int i = 0; i < pointcloud.PointCount; i++)
                {
                    indices[i] = i;
                }

                m_mesh.Clear();
                m_mesh.vertices = m_points;
                m_mesh.SetIndices(indices, MeshTopology.Points, 0);
                m_lastPointCloudTimestamp = pointcloud.Timestamp;
            }

調査進めたら加筆するかも

参考リンク集

20
16
2

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
20
16