ARCore, AR platform for Android, was announced from Google at the end of August.
As written on the following site, ARCore can track position and orientation of smartphone without using marker detection, and can detect horizontal plane such as floor or table.
However, due to only one provided sample, in case of creating contents expressing falling object staying on the floor, some programming skill is required.
(as of 2017/9/19)
So this article introduces how to create AR content wich interacting horizontal plane and object with editing basic sample.
My development environment items are the following;
- Unity 2017.2 Beta 11
- Android SDK version 7.0(API Level 24)
- Visual Studio 2017
- SDK Preview for Unity
- ARCoreService downloaded to Galaxy S8 G950FD
*Please see official tutorial if you want to know more detail.[Link]
Next, setting up project.
1) Start Unity and create project.
2) Add SDK (arcore-unity-sdk-preview.unitypackage) with double-click.
3) Open Project tab.
4) Open [GoogleARCore]-> [HelloARExample]-> [Scenes].
5) Double-click HelloAR (It will be editted later in this article.)
Following, execute referring after “Configure the build settings” on official tutorial, and confirm execution on your device.
At first, add collider to floor object for collision detection.
1) Open [GoogleARCore]-> [HelloARExample]-> [Prehabs].
2) Click TrackedPlaneVisualizer.
*This is used for receiving latest information of the boundary points of floor for visualization.
3) Click [Add Component] in Inspector.
4) Click [Physics]-> [MeshCollider] .
Following, edit script.
5) Open [GoogleARCore]-> [HelloARExample]-> [Scripts].
6) Open TrackedPlaneVisualizer.cs.
*Script includes description of plane visualization procedure.
7) Please see _UpdateMeshWithCurrentTrackedPlane method
Easy to understand with reading source cord well, with this method, creating aggregate of triangles using polygon approximated plane bounding points (point O-3 of the following figure), and pasting mesh-like texture and realize visualization.
For shading mesh boundary, also creating inner points (point 4-7 of the following figure) and changing transmittance from outside to inside.
* Actually not always square.
Apart from details, because plain approximated to aggregate of triangles with this method, if reflecting this shape information to collider, collision with virtual object and plane on a floor and so on, can be expressed. Specifically, just add two code lines to UpdateMeshWithCurrentTrackedPlane method referring to the following.
*For successful execution, required to substitute null for sharedMesh in collider tentatively.
Following, flying cube with screen tap. By the way, for movement at screen tap written in HelloARController.es in this sample, edit it.
8) Open [GoogleARCore]-> [HelloARExample]-> [Scripts].
9) Open HelloARController.cs.
10) Comment out or delete Update method.
11) Copy and paste the following code Instead.
Different parts from original are latter half of Update method and after tap description.
Originally, placing Andy (mascot of Android) in position, instead, after creating cube of GameObject (cube) for replacing that, flying with AddForce.
You can create AR contents to drop object on the horizontal plane which was detected with ARCore, by editing official sample project. You can use the similar souce code written by other developer if you'd like realize collision bettween virtual object and holizontal plane.
I hope this article helps you understand how to use official project :)