当前位置:网站首页>Arfoundation starts from scratch 8-geospatial API (geospatial) development
Arfoundation starts from scratch 8-geospatial API (geospatial) development
2022-07-29 05:16:00 【suelee_ hm】
ARCore Geospatial API For developers Live View Underlying technology , Including large-scale cloud anchor function , And global visual positioning system (VPS) Access rights of , Can be used to develop multi person shared AR application .
The technology is based on Google Earth 3D Model data and street view image data , The principle is to convert tens of billions of street view images into support VPS Positioning of the 3D Point cloud , A total of trillions of 3D data . In less than a second , According to 3D Location of point cloud data positioning equipment And direction .
Project sample source code :
https://github.com/sueleeyu/ar-geospatial
One 、 Create project engineering and installation ARCore Extensions software package
See :
https://blog.csdn.net/weixin_40239288/article/details/125328974
Two 、 Set up google cloud project
Use a visual positioning system (VPS), You need to associate a Google Cloud project , And in time Google Cloud In the project Enable ARCore API, newly build Google Cloud project :
1. visit :https://console.cloud.google.com/projectcreate, New projects .
2. Click create to create a new one :
3. Select... From the sidebar menu API And the service - library :
4. Input ARCore API And search for
5. Click Select ARCore API
6. Click enable
7. Enter the following page
3、 ... and 、 Set authorization
After the application needs authorization , To call Geospatial API, Whether the authorization has key authorization and API Key authorization , It is recommended to use keyless authorization .
Realization API Key authorization :
1. go to Cloud Console Medium API And the service → The credentials panel , choice Create credentials , Then select from the drop-down menu API secret key :
Copy the key after creation :
Copy the key
2. stay Unity in , go to Edit > Project Settings > XR > ARCore Extensions. Android Authentiation Strategy Drop down menu , choice API Key
3. stay Android API Key Field , Paste from Google Cloud Platform To obtain the API secret key , And check the Optional Features The next two are to be used API Check box :
Authorization complete . Next, enable Geospatial API.
Four 、 Enable Geospatial API
1.Assets Choose ARCoreExtensionsConfig Script object , And then in Inspector Window , The drop-down Geospatial Mode choice Enabled.
5、 ... and 、 Write a script
1. mount AREarth Manager, choice Hierarchy-AR Session Origin-Add Component-AR Earth Manager:
2.Hierarchy-‘+’-Create Empty, Name it GeospatialController;Assets-Scripts Right click New GeospatialController.cs, Drag to GeospatialController object :
To obtain position :
The main functions are update() To realize :
1. Judge and check equipment compatibility , call :
EarthManager.IsGeospatialModeSupported(GeospatialMode.Enabled);
Need to return FeatureSupported.Supported Only then can .
2. Check the tracking status
var earthTrackingState = EarthManager.EarthTrackingState;
Only when the earthTrackingState==rackingState.Tracking when , Geospatial values are valid . As shown below :
var earthTrackingState = EarthManager.EarthTrackingState;
if (earthTrackingState == TrackingState.Tracking)
{
// Values obtained by the Geospatial API are valid as long as
// earthTrackingState is TrackingState.Tracking.
// Use Geospatial APIs in this block.
}
3. Get camera geospatial pose .REarthManager Manage camera geospatial posture , When TrackingState by Tracking when , request Camera position and direction relative to the earth :
var earthTrackingState = EarthManager.EarthTrackingState;
if (earthTrackingState == TrackingState.Tracking)
{
// camera_geospatial_pose contains geodetic location, rotation, and
// confidences values.
var cameraGeospatialPose = EarthManager.CameraGeospatialPose;
}
cameraGeospatialPose It contains the information of geospatial posture :
a. Position in latitude and longitude . Besides , It also provides an estimate of the accuracy of the location information .
b. At an altitude of , And the estimation of altitude .
c. Direction 、 Approximate value of the direction the device is facing , And an estimate of the accuracy of the course .
Place geospatial anchors :
Use ARAnchorManagerExtensions in ARAnchorManager.AddAnchor establish ARGeospatialAnchor, To anchor the content to the specified geographic coordinates .
When positioning the anchor point relative to the position and direction of the earth , Latitude and longitude are determined by WGS84 standard Definition , The altitude value is determined by WGS84 The height of the ellipsoid ( In meters ) Definition . Identity rotation takes place with the anchor facing , send X+ Point East ,Y+ Point up , Away from the center of the earth ,Z+ Point south .
private bool PlaceGeospatialAnchor(GeospatialAnchorHistory history)
{
Quaternion quaternion =
Quaternion.AngleAxis(180f - (float)history.Heading, Vector3.up);
var anchor = AnchorManager.AddAnchor(
history.Latitude, history.Longitude, history.Altitude, quaternion);
if (anchor != null)
{
GameObject anchorGO = Instantiate(GeospatialPrefab, anchor.transform);
_anchorObjects.Add(anchorGO);
return true;
}
return false;
}
Be careful : It is not supported in the north pole or the South Pole (90 Degree or -90 degree ) Create anchors inside . If you try to use such anchors ,AnchorManager.AddAnchor Returns the null.
Calculate the altitude [Geospatial file ]:
Getting the altitude at which the anchor is placed is a bit tricky . You must compare the altitude of the equipment location with Geospatial API Compare the altitude of . There are two ways to determine the altitude :
If the location of the anchor point is close to the user , Please consider using an altitude similar to the altitude of the equipment .
otherwise , Please consider starting from Google Get the altitude value from the height of the map .
Using the camera GeospatialPose The altitude of
You may only need to use from AREarthManager.CameraGeospatialPose Obtained altitude , Without cross checking from other sources ( Such as Maps API) The data of , Maybe enough . See above Get the camera geospatial position and direction .
If you can get the position posture in advance by observing the local position by yourself , You can use this data to cross check the GeospatialPose.
from Google Map the altitude
GeospatialPose For reporting WGS84 The altitude above the ellipsoid ( In meters ). Your application needs to GeospatialPose.Altitude The value of is compared with the altitude of the equipment location , To determine the exact altitude of the anchor .
You can use Google Map Get latitude and longitude . Please be sure to close first “ Earth view ”, The method is to navigate to the layer > more , Then uncheck the earth view check box in the lower left corner of the screen . This will be enforced 2D visual angle , And eliminate the angle 3D Possible errors caused by view .
After determining latitude and longitude , Please use Elevation API according to EGM96 Specification acquisition height . You must put the Maps API EGM96 Altitude is converted to WGS84, Talent and GeospatialPose Compare the altitude . See include both command line and HTML Interface GeoidEval Transformation tool .Maps API Use it out of the box WGS84 The specification reports latitude and longitude .
6、 ... and 、UI And interface
1. establish ARView Panel, Click on ‘+’-UI-Panel, Name it ARView,remove component Image and Canvas Renderer
2.ARView Next right click New InfoPanel
Set the properties as follows :
3.InfoPanel Under the new Text, name InfoText, Set up :
4.ARView Under the new Panel, name SnackBar, Set up :
5.SnackBar Under the new Text, name DebugText, Set up :
6.SnackBar Under the new Text, name SnackBarText, Set up :
7. SnackBar Under the new Button, name SetAnchorButton, Set up :
SetAnchorButton-Text:
8. SnackBar Under the new Button, name ClearAllButton, Set up :
ClearAllButton-Text:
9.Canvas Right click -UI-Panel, name PrivacyPrompt,PrivacyPrompt Next right click New Panel, name FullscreenBackground, Set up :
10. PrivacyPrompt Next right click New Panel, name PrivacyContent, Set up :
PrivacyContent Under the new Panel, name PrivacyPromptBackground, Set up :
PrivacyContent Under the new Panel, name Information Panel, Set up :
11. Information Panel Under the new Text, name Title Text, Set up :
Information Panel Under the new Panel, name Text Area, Set up :
Text Area Under the new Text, name Information Text, Set up :
Information Text Under the new Button, name URL Button, Delete URL Button Next Text, Set up :
Start Button Set up click event , call GeospatialController. OnLearnMoreClicked ():
Information Panel Under the new Button, name Start Button, Set up :
Start Button Set up click event , call GeospatialController. OnGetStartedClicked():
7、 ... and 、 Packaging operation
7、 ... and 、 common problem
1. Use ARCore Extension API Example program :Window-Package Manager-ARCore Extensions-Samples, Click on Import Button to import the sample code to be used .
2. error CS0234: Namespace “UnityEditor” Type or namespace name... Does not exist in “iOS”:
solve : install UnitySetup-iOS-Support-for-Editor-2020.2.6f1.
8、 ... and 、 reference
1. Unity api:
Unity - Manual: Unity User Manual 2021.3 (LTS)
2. Geospatial file :
Use ARCore Geospatial API Create a global scale immersive AR Experience | Google Developers
3.Google AR:
https://github.com/google-ar
https://github.com/google-ar/arcore-unity-extensions
4. The sample source code of this project :
边栏推荐
- How to add traffic statistics codes to the legendary Development Zone website
- ARFoundation从零开始3-创建ARFoundation项目
- Legend how to configure multiple versions of wechat updates on one server
- Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
- Mysql的自连接和联合查询
- Northeast University Data Science Foundation (matlab) - Notes
- About realizing page Jump of website in Servlet
- Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function
- [wechat applet] swiper slides the page, and the left and right sides of the slider show part of the front and back, showing part of the front and back
- Diagram of odoo development tutorial
猜你喜欢
< El table column> place multiple pictures
How does word view document modification traces? How word views document modification traces
SM整合原来这么简单,步骤清晰(详细)
Glory 2023 push, push code ambubk
玩家访问网站自动弹窗加QQ群方法以及详细代码
【2022新生学习】第三周要点
力扣------对奇偶下标分别排序
pytorch学习笔记
Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function
Solve the warning prompt of MySQL mapping file
随机推荐
JS (foreach) return cannot end the function solution
JS daily question (12)
[config] configure array parameters
Use annotation test in idea
scikit-learn——机器学习应用开发的步骤和理解
AttributeError: ‘module‘ object has no attribute ‘create_connection‘
< El table column> place multiple pictures
Spark的算子操作列表
Force deduction ----- sort odd and even subscripts respectively
虚拟偶像的歌声原来是这样生成的!
Jackson解析JSON详细教程
The method and detailed code of automatically pop-up and QQ group when players visit the website
[file download] easyexcel quick start
How to add a map to the legendary server
How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally
2021-10-23
深度学习刷SOTA的一堆trick
Open the tutorial of adding and modifying automatically playing music on the open zone website
office2010每次打开都要配置进度怎么解决?
pytorch学习笔记