Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting Started with ARCore 1.7

Getting Started with ARCore 1.7

Tutorial of basic usage of ARCore 1.7

TakashiYoshinaga

March 08, 2019
Tweet

More Decks by TakashiYoshinaga

Other Decks in Technology

Transcript

  1. Name: Takashi Yoshinaga Affiliation: Institute of Systems,Information Technologies and Nanotechnologies

    Field of work: Application of AR for med. and edu. SNS: Twitter -> @Tks_Yoshinaga LinkedIn -> tks-yoshinaga
  2. ARCore 【Features】 (1) Motion Tracking for realize marker less AR.

    (2) Light Estimation which can estimate light strength and color. (3) Environmental Understanding to recognize floor and wall. (4) Augmented Image to recognize predefined image marker. (5) Cloud Anchor for sharing AR experience among multiple users. (6) Augmented Faces to recognize face & pose estimation.
  3. Today’s Tutorial 【Features】 (1) Motion Tracking for realize marker less

    AR. (2) Light Estimation which can estimate light strength and color. (3) Environmental Understanding to recognize floor and wall. (4) Augmented Image to recognize predefined image marker. (5) Cloud Anchor for sharing AR experience among multiple users. (6) Augmented Faces to recognize face & pose estimation.
  4. See also below if you want to know Augmented Image

    and Cloud Anchor. https://speakerdeck.com/takashiyoshin aga/lets-start-ar-with-arcore-and-unity
  5. Today’s Tutorial ① Superimposing CG ② Plane Detection and Placing

    CG ③ 3D Drawing with Motion Tracking ④ How to Use Augmented Faces
  6. Preparation • Unity2017.4.15 or later • ARCore SDK 1.7 https://github.com/google-ar/arcore-

    unity-sdk/releases/tag/v1.7.0 • Sample http://arfukuoka.lolipop.jp/arcore_pan asonic/sample.zip
  7. Creating Unity Project (2/2) Click Create Project button after inputting

    project name. 3D Project Name Save Directory Create Project
  8. Putting a Virtual Object (1/2) ①GoogleARCore → Examples → Common

    → Prefabs ② Andy Green Diffuse ③Drag & Drop
  9. Putting a Virtual Object (2/2) ①AndyGreenDiffuse ※Origin of the CG

    is position of smartphone when application was launched ②Put Andy in front of user. Position (x,y,z)=(0,0,0.5)[m]
  10. Save the Project ①New Folder ③Open Sample1 folder and save

    as sample1 ④Save After this operation the content can be saved with Ctrl + S ②Name new folder as Sample1
  11. Visualization of Detected Planes (4/4) ①GoogleARCore → Examples → Common

    → Prefabs ③DetectedPlaneVisualizer ②Controller ④Drag & Drop to Detected Plane Prefab
  12. Script using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleARCore; public

    class PutScript : MonoBehaviour { public GameObject andy; //Variable to handle CG(Andy) void Start () { } void Update () { //(1) Detect tap. //(2) Transform 2D position to 3D position of real world. //(3) Put Andy there. } }
  13. Script void Update () { //Return if screen touch is

    not detected if (Input.touchCount < 1 ){ return; } Touch touch = Input.GetTouch(0); //Return if touch state is not swipe. if (touch.phase != TouchPhase.Moved ){ return;} //Calculate touched position of detected plane. TrackableHit hit; TrackableHitFlags filter = TrackableHitFlags.PlaneWithinPolygon; if (Frame.Raycast(touch.position.x, touch.position.y, filter, out hit)) { //Move Andy to pointed position. (Next page) } } touch.position hit
  14. Script if (Frame.Raycast(touch.position.x, touch.position.y, filter, out hit)) { // If

    pointed trackable is plane if (hit.Trackable is DetectedPlane ) { //Set the position and the angle of Andy andy.transform.position = hit.Pose.position; andy.transform.rotation = hit.Pose.rotation; andy.transform.Rotate(0, 180, 0, Space.Self); //Set the anchor to fix Andy object to real space. var anchor = hit.Trackable.CreateAnchor(hit.Pose); andy.transform.parent = anchor.transform; } }
  15. Run & Confirm You can place Andy on the touched

    position of a detected plane.
  16. Drawing 3D Line with TrailRenderer Search “trail” 【Trail Renderer】 ▪Material

    Drag & Drop NewMaterial into Element0 ▪Time Change to Infinity ▪MinVertexDistance 0.03 ▪Width 0.01 Double click Trail Renderer
  17. Script using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleARCore; public

    class DrawScript : MonoBehaviour { public GameObject obj; //Template of trail drawing object GameObject drawObj; // Object used for actual trail drawing void Start () { } void Update () { //Detect Tap //Instantiate drawing object when screen touch is started. //Draw trail line while user touching screen. } }
  18. Script void Update () { if (Input.touchCount == 1) {

    //Calculate relative position from camera. 0 0 0.1 [m] Vector3 p = Camera.main.transform.TransformPoint(0,0,0.1f); //Touch is started if ( Input.GetTouch(0).phase == TouchPhase.Began) { drawObj = GameObject.Instantiate(obj, p, Quaternion.identity); } //While touching. else if (Input.GetTouch(0).phase == TouchPhase.Stationary){ drawObj.transform.position = p; } } }
  19. Enable Deleting Line List<GameObject> lines = new List<GameObject>(); void Update

    () { if (Input.touchCount == 1) {//カメラ手前10cmの位置を取得 Vector3 p = Camera.main.transform.TransformPoint(0,0,0.1f);//タ if ( Input.GetTouch(0).phase == TouchPhase.Began) { drawObj = GameObject.Instantiate(obj, p, Quaternion.identity); GameObject tmp = GameObject.Instantiate(obj, p, Quaternion.identity); lines.Add(tmp); drawObj = tmp; } //押下中 else if (Input.GetTouch(0).phase == TouchPhase.Stationary){ drawObj.transform.position = p; } } }
  20. Enable Deleting Line void Update () { if (Input.touchCount ==

    1) { //Code for writing trail lines./カメラ手前10cmの位置を取得 } else if (Input.touchCount == 2) { if (Input.GetTouch(0).phase == TouchPhase.Ended) { for(int i = 0; i < lines.Count; i++) { Destroy(lines[i]); lines[i] = null; } lines.Clear(); } } }
  21. Lines will be deleted when you tap a screen of

    smartphone with two fingers!
  22. Applying a Texture Image to Material ②Texture ※You can use

    image with alpha channel by choosing Transparent ①Unlit
  23. Using Position of Face Parts FOREHEAD_LEFT FOREHEAD_RIGHT NOSE_TIP 3 parts,

    named FOREHEAD_LEFT/RIGHT & NOSE_TIP, are available in SDK.
  24. Using Position of Face Parts Add sphere as child of

    FOREHEAD_RIGHT and LEFT by the same procedure