Getting Started with ARCore Geospatial API & Unity

206.6K Views

June 06, 22

スライド概要

profile-image

可視化技術や人間計測/空間計測技術を活用した問題解決に関する研究開発。 ARコンテンツ作成勉強会(tryAR)を主催。

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

(ダウンロード不可)

関連スライド

各ページのテキスト
1.

Getting Started with ARCore Geospatial API

2.

Goal of This Tutorial Low Accuracy! Display Tracking Results Tracking accuracy check High Accuracy! CG display at specified latitude and longitude

3.

Download Sample Data https://github.com/TakashiYoshinaga/ARFukuoka/raw/main/GeospatialAPI_20220604/Smples.zip

4.

Tutorial Procedure p Creating a Unity Project p Installing AR Foundation and ARCore Extensions p Setting up a scene using the Geospatial API and ARCore/ARKit p Getting and displaying tracking information via Geospatial API p Application installation on smartphone p Display objects at specified latitude and longitude

5.

Tutorial Procedure p Creating a Unity Project p Installing AR Foundation and ARCore Extensions p Setting up a scene using the Geospatial API and ARCore/ARKit p Getting and displaying tracking information via Geospatial API p Application installation on smartphone p Display objects at specified latitude and longitude

6.

Launch Unity Hub Unity Hub

7.

Project Creation (1/6) ①Projects ②New Project

8.

Project Creation (2/6) Open Editor Version

9.

Project Creation (3/6) 2020.3.xxf1 This document assumes 2020.3.x for explanation.

10.

Project Creation (4/6) ①3D ②Project name ③ Storage location

11.

Project Creation (5/6) Create project

12.

Project Creation (6/6) When the Unity Editor appears, you are ready to go!

13.

Build Settings for Android/iOS (1/4) File

14.

Build Settings for Android/iOS (2/4) Build Settings

15.

Build Settings for Android/iOS (3/4) ①Select Android or iOS ②Switch Platform

16.

Build Settings for Android/iOS (4/4) Player Settings

17.

Build Settings for Android For Android

18.

Build Settings for Android (1/3) ①Other Settings ②Click Vulkan ③ Delete

19.

Build Settings for Android (2/3) ①Identification ②Minimum API Level ③ Select Android 7.0 ʻNougatʼ API Level 24

20.

Build Settings for Android (3/3) ①Configuration ②Scripting Backend ③Select IL2CPP ④Select ARM64

21.

Build Settings for iOS For iOS

22.

Build Settings for iOS ①Configuraton ② Set [Required for AR] for each Usage Description

23.

Tutorial Procedure p Creating a Unity Project p Installing AR Foundation and ARCore Extensions p Setting up a scene using the Geospatial API and ARCore/ARKit p Getting and displaying tracking information via Geospatial API p Application installation on smartphone p Display objects at specified latitude and longitude

24.

Prepare to download packages (1/3) Window

25.

Prepare to download packages (2/3) Package Manager

26.

Prepare to download packages (3/3) Select Unity Registry from Packages

27.

Installation of AR Foundation (1/2) Search AR

28.

Installation of AR Foundation (2/2) ①ARFoundation ② Install

29.

Install ARCore or ARKit ①Android: ARCore XR Plugin iOS: ARKit XR Plugin ② Install

30.

Installing ARCore Extensions (1/3) Click + [Note] ARFoundation and ARCore/ARKit are only tools to realize AR. The ARCore Extensions is necessary to use Geospatial API, which is the main topic of this article.

31.

Installing ARCore Extensions (2/3) Add package from git URL

32.

Installing ARCore Extensions (3/3) Search below https://github.com/google-ar/arcore-unity-extensions.git

33.

Note If the PC you are using is not configured for GitHub connection, an error will occur.

34.

Installation of ARCore Extensions (supplement) Access the ARCore Extensions repository https://github.com/google-ar/arcore-unity-extensions.git Click Releases

35.

Installation of ARCore Extensions (supplement) v.1.35.0 Scroll down a little

36.

Installation of ARCore Extensions (supplement) Assets Download arcore-unity-extensions-1.35.0.tgz

37.

Installation of ARCore Extensions (supplement) Move arcore-unity-extensions-1.35.0.tgz to the Packages folder in the folder of the project you have just created for this tutorial.

38.

Installation of ARCore Extensions (supplement) Add package from git tarball

39.

Installation of ARCore Extensions (supplement) Select arcore-unity-extentions

40.

End of supplementary information

41.

Confirmation of installation results Select In Project from Packages

42.

Confirmation of installation results You can find ARCore Extensions

43.

Get a sample of GeospatialAPI ①ARCore Extensions ②Samples ③ Import Geospatial Sample

44.

Note Might have errors in environments that do not have the iOS build option installed.

45.

Resolving iOS-related errors (Supplemental) You may get a red text error.

46.

Resolving iOS-related errors (Supplemental) Samples -> ARCore Extensions ->1.35.0 ->GeospatialSample ->Scripts

47.

Resolving iOS-related errors (Supplemental) Delete Editor

48.

Resolving iOS-related errors (Supplemental) Console If the error disappears after clicking Clear, OK.

49.

Resolving iOS-related errors (Supplemental) Display Project tab

50.

End of supplementary information

51.

Installation of ARCore Extensions is complete! Close Package Manager

52.

Next, configure the tools you have installed so far for use in this project.

53.

ARCore or ARKit Usage Settings (1/4) ① Edit ② Project Settings

54.

ARCore or ARKit Usage Settings (2/4) XR Plug-in Management

55.

ARCore or ARKit Usage Settings (3/4) For Android Turn on ARCore

56.

ARCore or ARKit Usage Settings (4/4) For iOS Turn on ARKit

57.

ARCore Extensions Usage Settings (1/6) ARCore Extensions

58.

ARCore Extensions Usage Settings (2/6) [For iOS] Check the iOS Support Enabled checkbox

59.

ARCore Extensions Usage Settings (3/6) Notice the item drop-down for Android or iOS

60.

ARCore Extensions Usage Settings (4/6) Select APIKey from the drop-down menu

61.

ARCore Extensions Usage Settings (5/6) API Key input pre-created in Google Cloud ※ See [Set up a Google Cloud Project] of the official website for how to create an API Key.[Link]

62.

ARCore Extensions Usage Settings (6/6) Turn on Geospatial

63.

ARCore Extensions usage setup completed! Close Project Settings

64.

Tutorial Procedure p Creating a Unity Project p Installing AR Foundation and ARCore Extensions p Setting up a scene using the Geospatial API and ARCore/ARKit p Getting and displaying tracking information via Geospatial API p Application installation on smartphone p Display objects at specified latitude and longitude

65.

Creating a scene (1/4) File

66.

Creating a scene (2/4) Save As...

67.

Creating a scene (3/4) Sample Save

68.

Creating a scene (4/4) Assets Sample should be added

69.

First, set up ARFoundation to realize AR experience in this scene (*GeospatialAPI will appear a little later)

70.

Setting up AR Foundation (1/7) Delete MainCamera

71.

Setting up AR Foundation (2/7) Right-click on a blank space in Hierarchy with nothing selected.

72.

Setting up AR Foundation (3/7) ①XR ②AR Session Origin

73.

Setting up AR Foundation (4/7) AR Session Origin should appear

74.

Setting up AR Foundation (5/7) Right-click on a blank space in Hierarchy with nothing selected.

75.

Setting up AR Foundation (6/7) ①XR ②AR Session

76.

Setting up AR Foundation (7/7) AR Session should appear

77.

Prepare to use Anchor, which ties an object to be displayed in AR to a specific location. The ability to align when looking there again even if the tracking is lost. Even if the CG placed at the specified latitude and longitude is lost, it will come back!

78.

Setting up AR Anchor Manager (1/3) ①AR SessionOrigin ②Add Component

79.

Setting up AR Anchor Manager (2/3) ①Search AR ②AR Anchor Manager

80.

Setting up AR Anchor Manager (3/3) ARAnchorManager should be added

81.

Enable the results of position and direction estimation by Geospatial API to be used in this scene

82.

Setting up AR Earth Manager (1/3) ①AR SessionOrigin ②Add Component

83.

Setting up AR Earth Manager (2/3) ①Search AR Earth ②AR Earth Manager

84.

Setting up AR Earth Manager (3/3) AREarthManager should be added

85.

Using the Geospatial API also requires permission to access location information, etc. But… You don't want to write the Permission-related details, do you?

86.

Take advantage of official scripts for easy setup!

87.

Adding a object to set up permission (1/2) Right-click on a blank space in Hierarchy with nothing selected.

88.

Adding a object to set up permission (2/2) ②AR Extensions ①XR

89.

Permission-related script settings (1/9) ARCore Extensions In this area, you can pass the following script that is running in this scene and it will do the Permission-related settings. ・ARSession ・ARSessionOrigin ・ARCameraManager ・ARCoreExtensionConfiguration

90.

Permission-related script settings (2/9) of Sessoin

91.

Permission-related script settings (3/9) Scene AR Session [Explanation] The ARSession script is attached to the AR Session object in this scene (in the Hierarchy)

92.

Permission-related script settings (4/9) of SessoinOrigin

93.

Permission-related script settings (5/9) Scene AR Session Origin

94.

Permission-related script settings (6/9) of CameraManager

95.

Permission-related script settings (7/9) Scene AR Camera

96.

Permission-related script settings (8/9) of ARCoreExtensionsConfig

97.

Permission-related script settings (9/9) Scene GeospatialConfig

98.

Permission setup completed! Allocation completed (CameraConfigFilter is not required)

99.

現状確認 AR Earth Manager It is possible to obtain the terminal support status, the success or failure of Geospatial API initialization, and the results of position and orientation estimation. Permission setting is done by Extensions. However, it is available only when tracking by GeospatialAPI has started. Start tracking by script!

100.

Aside: Official Sample There is a scene in the official sample to learn the steps from initialization to Geospatial API utilization.

101.

Aside: Official Sample Samples ->ARCore Extensions ->1.35.0 ->Geospatial Sample

102.

Aside: Official Sample Scripts GeospatialController

103.

Aside: Official Sample The GeospatialController script contains code for initialization, position acquisition, and saving and reproducing object placement. However, both initialization and data utilization are described together, making it difficult to reuse for other purposes

104.

I have prepared a script that isolates only the initialization code to start tracking. Aside from the details, let’s use it now!

105.

Importing sample assets (1/3) ①Samples Folder ②Double click AR_Fukuoka.unitypackage

106.

Importing sample assets (2/3) Import

107.

Importing sample assets (3/3) AR_Fukuoka should be added

108.

Creating an object to start tracking (1/3) Right-click on a blank space in Hierarchy with nothing selected.

109.

Creating an object to start tracking (2/3) CreateEmpty

110.

Creating an object to start tracking (3/3) ①GameObject ②Change name to VPS_Demo

111.

Add tracking start script (1/7) ①Assets -> AR_Fukuoka ->Scripts ②See VpsInitializer (Do not click it)

112.

Add tracking start script (2/7) VPS Demo Drag & drop VpsInitializer into Inspector of VPS_Demo

113.

Add tracking start script (3/7) VPS Visualizer should be added

114.

Add tracking start script (4/7) of EarthManager

115.

Add tracking start script (5/7) Scene AR Session Origin

116.

Add tracking start script (6/7) of ARCoreExtensions

117.

Add tracking start script (7/7) Scene AR Core Extensions

118.

Tutorial Procedure p Creating a Unity Project p Installing AR Foundation and ARCore Extensions p Setting up a scene using the Geospatial API and ARCore/ARKit p Getting and displaying tracking information via Geospatial API p Application installation on smartphone p Display objects at specified latitude and longitude

119.

Added tracking results display script (1/4) ①Assets -> AR_Fukuoka ->Scripts ②See SampleScript (Do not click it)

120.

Added tracking results display script (2/4) VPS_Demo

121.

Added tracking results display script (3/4) Drag & Drop SampleScript into Inspector of VPS_Demo

122.

Added tracking results display script (4/4) SampleScript should be added Double click to open script file

123.

Script to display tracking results (1/4) Add a description in advance to the empty script generated by Unity to use the following functions ・ ARCoreExtensions ・ ARFoundation

124.

Script to display tracking results (2/4) public class SampleScript : MonoBehaviour { //Tracking information using GeospatialAPI public AREarthManager EarthManager; //GeospatialAPI and ARCore initialization and results public VpsInitializer Initializer; //UI for displaying results public Text OutputText; void Start() { } void Update() { } } 01.txt

125.
[beta]
Script to display tracking results (3/4)
void Update()
{
string status = "";
//If initialization fails or you do not want to track, do nothing and return
if ( ! Initializer.IsReady ||
EarthManager.EarthTrackingState != TrackingState.Tracking)
{
return;
}
//Get tracking results
GeospatialPose pose = EarthManager.CameraGeospatialPose;
//Show results
ShowTrackingInfo(status, pose);
}
void ShowTrackingInfo(string status, GeospatialPose pose)
{
//Displays lat, lng, alt and their precision
}

02.txt

126.
[beta]
Script to display tracking results (4/4)
void ShowTrackingInfo(string status, GeospatialPose pose)
{
OutputText.text = string.Format(
"Latitude/Longitude: {0}°, {1}°¥n" +
"Horizontal Accuracy: {2}m¥n" +
"Altitude: {3}m¥n" +
"Vertical Accuracy: {4}m¥n" +
"Heading: {5}°¥n" +
"Heading Accuracy: {6} °¥n" +
"{7} ¥n"
,
pose.Latitude.ToString("F6"), //{0}
pose.Longitude.ToString("F6"), //{1}
pose.HorizontalAccuracy.ToString("F6"), //{2}
pose.Altitude.ToString("F2"), //{3}
pose.VerticalAccuracy.ToString("F2"), //{4}
pose.EunRotation.ToString("F1"), //{5}
pose.OrientationYawAccuracy.ToString("F1"), //{6}
status //{7}
);
}

03.txt

127.

Ctrl/Command + S to save script

128.

Mapping scripts to variables (1/4) VPS Demo of ARCoreExtensions

129.

Mapping scripts to variables (2/4) Scene AR Session Origin

130.

Mapping scripts to variables (3/4) Initializer

131.

Mapping scripts to variables (4/4) Scene VPS_Demo

132.

Add UI for display (1/3) ①Assets -> AR_Fukuoka ②See Canvas

133.

Add UI for display (2/3) Drag & Drop Canvas into Hierarchy

134.

Add UI for display (3/3) Open Canvas Confirm that TrackingMonitorText

135.

Mapping scripts to variables (1/2) Click VPS Demo of OutputText

136.

Mapping scripts to variables (2/2) Scene TrackingMonitorText

137.

Tutorial Procedure p Creating a Unity Project p Installing AR Foundation and ARCore Extensions p Setting up a scene using the Geospatial API and ARCore/ARKit p Getting and displaying tracking information via Geospatial API p Application installation on smartphone p Display objects at specified latitude and longitude

138.

For Android

139.

実機インストール for Android Connect ARCore device and PC with USB cable

140.

Install for Android File

141.

Install for Android Build And Run

142.

Install for Android Name(e.g. test) Save

143.

For iOS

144.

Install for iOS File

145.

Install for iOS Build Settings...

146.

Install for iOS Build

147.

Install for iOS Create new folder

148.

実機インストール for iOS Set folder name (e.g. build) Create

149.

Install for iOS Choose

150.

Install for iOS Open build folder

151.

Install for iOS Unity-iPhone.xcworkspaceを開く

152.

Install for iOS Unity-iPhone Setting & Capabilities

153.

Install for iOS Automatically manage signing Select your team

154.

Install for iOS Connect iOS device and PC with USB cable

155.

Install for iOS Select a device

156.

Install for iOS Click

157.

Android and iOS

158.

Result

159.

Tutorial Procedure p Creating a Unity Project p Installing AR Foundation and ARCore Extensions p Setting up a scene using the Geospatial API and ARCore/ARKit p Getting and displaying tracking information via Geospatial API p Application installation on smartphone p Display objects at specified latitude and longitude

160.

Development Policies pSpecify latitude, longitude, and height in advance and display objects at those locations • Check position and orientation accuracy every frame • Make objects appear when position and orientation are more accurate. Lat・Lng Matching AR

161.

Development Policies pSpecify latitude, longitude, and height in advance and display objects at those locations • Check position and orientation accuracy every frame • Make objects appear when position and orientation are more accurate. Lat・Lng Matching AR

162.

Discrimination of tracking accuracy (1/3) public class SampleScript : MonoBehaviour { //Tracking information using GeospatialAPI public AREarthManager EarthManager; //GeospatialAPI and ARCore initialization and results public VpsInitializer Initializer; //UI for displaying results public Text OutputText; //Allowable accuracy of azimuth public double HeadingThreshold = 25; //Allowable accuracy of horizontal position public double HorizontalThreshold = 20; } void Start(){ } void Update(){ /*略*/ } 04.txt

163.
[beta]
Discrimination of tracking accuracy (2/3)
void Update()
{
string status = "";
// If initialization fails or tracking is not done, do nothing and return
if ( ! Initializer.IsReady ||
EarthManager.EarthTrackingState != TrackingState.Tracking)
{
return;
}
// Get tracking results
GeospatialPose pose = EarthManager.CameraGeospatialPose;
// Describe here the behavior according to tracking accuracy

}

//Show result
ShowTrackingInfo(status, pose);

164.
[beta]
Discrimination of tracking accuracy (3/3)
// Get tracking results
GeospatialPose pose = EarthManager.CameraGeospatialPose;
// Tracking accuracy is worse than the threshold (larger value)
if (pose.OrientationYawAccuracy > HeadingThreshold ||
pose.HorizontalAccuracy > HorizontalThreshold)
{
status = "Low Tracking accuracy ";
}
else //許容誤差以内の場合
{
status = "High Tracking Accuracy ";
}
//結果を表⽰
ShowTrackingInfo(status, pose);

05.txt

165.

Result Accuracy is displayed as good or bad.

166.

Development Policies pSpecify latitude, longitude, and height in advance and display objects at those locations • Check position and orientation accuracy every frame • Make objects appear when position and orientation are more accurate. Lat・Lng Matching AR

167.

指定した位置にオブジェクトを出現 (1/3) public class SampleScript : MonoBehaviour { public AREarthManager EarthManager; //GeospatialAPIを⽤いたトラッキング情報 public VpsInitializer Initializer; //GeospatialAPIとARCoreの初期化と結果 public Text OutputText; //結果表⽰⽤のUI public double HeadingThreshold = 25; //位置・⽅位の許容精度 public double HorizontalThreshold = 20; public double Latitude; // Latitude to place the object public double Longitude; // Longitude to place the object public double Altitude; // Height to place the object public double Heading; // Object orientation (North=0°) public GameObject ContentPrefab; // Original data of display object GameObject displayObject; // Actual object to be displayed public ARAnchorManager AnchorManager; // Used to create anchors } void Start(){ } void Update(){/*略*/ } 06.txt

168.
[beta]
指定した位置にオブジェクトを出現 (2/3)
// Get tracking results
GeospatialPose pose = EarthManager.CameraGeospatialPose;
if (pose.HeadingAccuracy > HeadingThreshold ||
pose.HorizontalAccuracy > HorizontalThreshold)
{
status = "Low Tracking accuracy ";
}
else
{
status = "High Tracking accuracy ";
if (displayObject == null)
{
}

}

//結果を表⽰
ShowTrackingInfo(status, pose);

07.txt

169.
[beta]
指定した位置にオブジェクトを出現 (3/3)
if (displayObject == null)
{
// Height of the phone - 1.5m to be approximately the height of the ground
Altitude = pose.Altitude - 1.5f;
// Angle correction (because the Anchor generation function assumes South=0)
Quaternion quaternion = Quaternion.AngleAxis(180f - (float)Heading, Vector3.up);
// Create anchors at specified position and orientation.
ARGeospatialAnchor anchor
= AnchorManager.AddAnchor(Latitude, Longitude, Altitude, quaternion);

}

//If you want to use the height of the terrain (Terrain) provided
//by the API instead of Altitude, use the following
/*ARGeospatialAnchor anchor
= AnchorManager.ResolveAnchorOnTerrain(Latitude, Longitude, 0, quaternion);*/
// Materialize the object if the anchor is correctly created
if (anchor != null)
{
08.txt
displayObject = Instantiate(ContentPrefab, anchor.transform);
}

170.

Development Policies pSpecify latitude, longitude, and height in advance and display objects at those locations • Check position and orientation accuracy every frame • Make objects appear when position and orientation are more accurate. Lat・Lng Matching AR

171.

Specify latitude and longitude VPS Demo Specify latitude and longitude

172.

Open Google Map

173.

Specify latitude and longitude (1/5) Right-click on the location where you want to place the object.

174.

Specify latitude and longitude (2/5) Click on latitude and longitude to copy to clipboard

175.

Specify latitude and longitude (3/5) Pasete Latitude and Longitude

176.

Specify latitude and longitude (4/5) Altitude is not necessary this time because it is written in a script.

177.

Specify latitude and longitude (5/5) Heading is set to 0 (=northward)

178.

Registering Display Objects (1/2) ①Assets -> AR_Fukuoka ->Content ② Find ARPrefab (Do not click it)

179.

Registering Display Objects (2/2) VPS Demo AR PrefabをContentPrefab にドラッグ&ドロップ

180.

Registering AnchorManager (1/2) of AnchorManager

181.

Registering AnchorManager (2/2) Scene AR Session Origin

182.

Result Object appears at specified position

183.

Completed!

184.

ARCore Geospatial API official page For more information on the API, check out the official page!https://developers.google.com/ar/develop/geospatial

185.

Sample Project for This Tutorial https://github.com/TakashiYoshinaga/ GeospatialAPI-Unity-StarterKit

186.

Follow Me • Twitter: @Tks_Yoshinaga • LinkedIn: https://www.linkedin.com/in/tks-yoshinaga/