Upload
others
View
12
Download
1
Embed Size (px)
Citation preview
de:code 2019 CM03
Azure Spatial Anchors を使用した
iOS ARKitアプリケーション開発入門
日本マイクロソフト
マイクロソフトテクノロジーセンター
鈴木敦史
ベストカラアゲニスト
xR (VR/AR/MR) アンバサダー
有野 いく
今日の内容
Azure Spatial Anchors の機能と仕組みを理解
活用シナリオ
サンプルアプリの開発方法
Mixed Reality の全体像
マルチユーザーで
コンテンツを共有ウェイファインディング
コンテンツを
永続的に保持
Azure Spatial Anchors の特徴
対応デバイス
https://docs.microsoft.com
/ja-jp/azure/spatial-anchors/
開発環境
事前準備 (開発環境の確認)
Unity 2018.3
XCode 10.1
CocoaPods をインストール[コンソール] sudo gem install cocoapods
Git をインストール[コンソール] /usr/bin/ruby -e "$(curl -fsSL
https://raw.githubusercontent.com/Ho
mebrew/install/master/install)"
[コンソール] brew install git
Visual Studio インストール(ASP.NET および Web の開発)
.NET Core 2.2 SDK(https://dotnet.microsoft.com/download)
※ Visual Studio 2019 : v2.2.300
Visual Studio 2017 : v2.2.107
GitHubから azure-spatial-anchors-sample リポジトリを複製(https://github.com/Azure/azure-spatial-anchors-samples)
git clone https://github.com/Azure/azure-spatial-anchors-samples.git
クローンしたサンプルの
SharingServiceSample¥SharingService.sln
をVisual Studioで開く
ソリューション エクスプローラーで、
SharingService¥Startup.cs を開く
#define INMEMORY_DEMO をコメントアウト
ファイルを保存
ファイルの先頭にある #define INMEMORY_DEMO を見つけ、その行をコメントアウト
ソリューション エクスプローラーで、
SharingService¥appsettings.json を開く
StorageConnectionString の値にコピーした接続文
字列を入力
ソリューション エクスプローラーで、
SharingService¥global.json を開く
version の値をインストールした .NET Core SDK の
バージョンに合わせて変更
ソリューション エクスプローラーで、
SharingService プロジェクトを右クリックし、
[発行] をクリック
サブスクリプションとリソースグループで検索して、
作成した Web アプリを選択して [OK] をクリック
MacでUnityを起動
クローンしたサンプルの unity フォルダー内の
プロジェクトを開く
[ファイル]-[ビルド設定] を選択して[ビルド設定] を開く
[プラットフォーム] セクションで、[iOS] を選択
[Switch Platform] を選択して、
プラットフォームを [iOS] に変更
[ビルド設定] ウィンドウを閉じる
Unity ARKit Plugin バージョン 2.0.0 をダウンロードして解凍https://bitbucket.org/Unity-Technologies/unity-arkit-plugin/get/v2.0.0.zip
解凍したAssets フォルダーの内容を、
Unityで開いたサンプルの Assets フォルダーにコピー
[Project] ウィンドウで
Assets/AzureSpatialAnchorsPlugin/Examples/Scenes に移動し、
AzureSpatialAnchorsLocalSharedDemo.unity を開く
[Project] ウィンドウで
Assets/AzureSpatialAnchorsPlugin/Examples/Resources に移動し、
AzureSpatialAnchorsDemoConfig を選択
[Inspector] ウィンドウのSpatial Anchors Account Key と Spatial
Anchors Account Id に、保存しておいた Spatial Anchor Account の
「Account Key」
「Account ID」
を入力
[Inspector] ウィンドウのBase Sharing Url に保存しておいた
「Webアプリ(Sharing Service)」のUrlを入力
入力したUrlの
index.html を api/anchors に変更
例)
https://<app_name>.azurewebsites.net/api/anchors
[File]-[Save]を選択してシーンを保存
[ファイル]-[ビルド設定] を選択
[Scenes In Build] で、
AzureSpatialAnchorsPlugin/Examples/AzureSpatialAnchorsLocalS
haredDemo シーンの横にチェック マークを付けて、他のすべてのシーンの
チェック マークをクリア
[Build] をクリック
ダイアログに Xcode プロジェクトをエクスポートするフォルダー名を入力して
[Save] をクリック
ターミナルで、Xcode プロジェクトをエクスポートしたフォルダーに移動
以下のコマンドを実行
bash
pod install --repo-update
以下のコマンドで Xcode プロジェクトを開く
bash
open ./Unity-iPhone.xcworkspace
iOS デバイスを接続
ルートの Unity-iPhone ノードを選択
[Signing]で、[Automatically manage signing]にチェックを入れる
エラーが消えない場合は、Teamで [Add an Account]をクリックして
アカウントを追加
Bundle Identifier を変更
[Build and then run the current scheme] をクリック
エラーが表示された場合、iOS デバイスで[一般]-[デバイス管理]で
追加したアカウントを承認
処理の流れ
Mobile
HoloLens
Client Azure Spatial Anchors
App Service Cosmos DB
Sharing service
1) セッションの初期化
2) クラウド空間アンカーの作成
3) クラウド空間アンカーを見つける
1. Save anchor
2. Get anchor ID back
3. Save anchor ID
in database
4. Get IDs from
database
5. Locate anchors by ID
6. Get anchors back
Mobile
HoloLens
Client Azure Spatial Anchors
App Service Cosmos DB
Sharing service
1) セッションの初期化
C#
CloudSpatialAnchorSession cloudSession;// In your view handlerthis.cloudSession = new CloudSpatialAnchorSession();
セッションの初期化
C#
this.cloudSession.Configuration.AccountKey = @"MyAccountKey";
アカウント キー
C#
this.cloudSession.Configuration.AccessToken = @"MyAccessToken";
アクセス トークン
C#
this.arkitSession = UnityARSessionNativeInterface.GetARSessionNativeInterface();this.cloudSession.Session = this.arkitSession.GetNativeSessionPtr();
this.cloudSession.Start();
セッションの設定
C#
UnityARSessionNativeInterface.ARFrameUpdatedEvent +=UnityARSessionNativeInterface_ARFrameUpdatedEvent;
void UnityARSessionNativeInterface_ARFrameUpdatedEvent(UnityARCamera camera){
this.cloudSession.ProcessFrame(this.arkitSession.GetNativeFramePtr());}
セッションにフレームを提供
Mobile
HoloLens
Client Azure Spatial Anchors
App Service Cosmos DB
Sharing service
2) クラウド空間アンカーの作成
1. Save anchor
2. Get anchor ID back
3. Save anchor ID
in database
C#
Vector3 hitPosition = new Vector3();var screenPosition = Camera.main.ScreenToViewportPoint(new Vector3(0.5f, 0.5f));ARPoint point = new ARPoint{
x = screenPosition.x,y = screenPosition.y
};var hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane |ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent);
if (hitResults.Count > 0){
ARHitTestResult hitResult = hitResults[0];hitPosition = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
}
クラウド空間アンカーの作成
C#
Quaternion rotation = Quaternion.AngleAxis(0, Vector3.up);this.localAnchor =
GameObject.Instantiate(/* some prefab */, hitPosition, rotation);this.localAnchor.AddARAnchor();
CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();cloudAnchor.LocalAnchor = this.localAnchor.GetNativeAnchorPointer();await this.cloudSession.CreateAnchorAsync(cloudAnchor);this.feedback = $"Created a cloud anchor with ID={cloudAnchor.Identifier}");
クラウド空間アンカーの作成 ~つづき
C#
SessionStatus value = await this.cloudSession.GetSessionStatusAsync();if (value.RecommendedForCreateProgress < 1.0f) return;// Issue the creation request ...
セッションステータスの取得 Sharing service
Azure Spatial Anchors
Mobile
HoloLens
Client Azure Spatial Anchors
App Service Cosmos DB
Sharing service3) クラウド空間アンカーを見つける
4. Get IDs from
database
5. Locate anchors by ID
6. Get anchors back
C#
AnchorLocateCriteria criteria = new AnchorLocateCriteria();criteria.Identifiers = new string[] { @"id1", @"id2", @"id3" };this.cloudSession.CreateWatcher(criteria);this.cloudSession.AnchorLocated +=
(object sender, AnchorLocatedEventArgs args) =>{
switch (args.Status){
case LocateAnchorStatus.Located:CloudSpatialAnchor foundAnchor = args.Anchor;break;
case LocateAnchorStatus.AlreadyTracked:break;
case LocateAnchorStatus.NotLocatedAnchorDoesNotExist:break;
case LocateAnchorStatus.NotLocated:break;
}}
クラウド空間アンカーを見つける
Sharing service
Azure Spatial Anchors
Azure Spatial Anchors
iPad で背景にカメラ画像が表示されない
[Assets](資産) -> [Re-import all] (すべて再インポート)
空間がスキャンできない
特徴的な環境を作る (物が置かれていた方がスキャンしやすい)
アンカーの精度をあげたい
必要に応じてマーカーの利用を検討する
Tips & Tricks
サンプル
リソース
【チュートリアル】
Azure Cosmos DB バックエンドを使用してセッションやデバイス間で Azure Spatial Anchors を共有する
https://docs.microsoft.com/ja-jp/azure/spatial-anchors/tutorials/tutorial-use-cosmos-db-to-store-anchors
【サンプル】
https://github.com/Azure/azure-spatial-anchors-samples
【FAQ】
https://docs.microsoft.com/ja-jp/azure/spatial-anchors/spatial-anchor-faq
© 2018 Microsoft Corporation. All rights reserved.
本情報の内容(添付文書、リンク先などを含む)は、作成日時点でのものであり、予告なく変更される場合があります。
© 2019 Microsoft Corporation. All rights reserved.
本情報の内容 (添付文書、リンク先などを含む) は、de:code 2019 開催日 (2019年5月29~30日) 時点のものであり、予告なく変更される場合があります。
本コンテンツの著作権、および本コンテンツ中に出てくる商標権、団体名、ロゴ、製品、サービスなどはそれぞれ、各権利保有者に帰属します。