devwiki:arfoundation

AR Foundation Setup - marker based

  • Package manager:
    • build setting: switch to target platform
    • install AR foundation + ARCore XR from Unity registry in Package Manager
    • build setting > Player setting:
      1. OpenGL before vulkan
      2. min api : android api level 26 (store 30)
      3. scripting backend: ILL2CPP
      4. uncheck armv7 and check arm64
      5. xr plug-in, check ARCore
    • create XR > AR session + AR session origin
    • asset > create XR > reference image library (to load marker image)
    • ar session origin > add component > ar tracked image manager
      • (put library there)

AR Foundation Setup - markerless

  • markerless means more task for phone to calculate
    • surface detection + motion tracking+ environment lighting
    • detection limitation:
      • surface w no texture, bad lighting, transparent and reflective surface, moving objects
  • build step:
    • build setting: switch to target platform
    • install AR foundation + ARCore XR from Unity registry in Package Manager
    • build setting > Player setting:
      1. OpenGL before vulkan
      2. min api : android api level 26 (store 30)
      3. scripting backend: ILL2CPP
      4. uncheck armv7 and check arm64
      5. xr plug-in, check ARCore
    • create XR > AR session + AR session origin
    • ar session origin > add component > ar plane manager
      1. outliner > create XR > AR Default Plane, put it prefab
      2. drag that plane prefab into AR Plane Manager (plane prefab)
      3. direction mode: horizontal
    • ar session origin > add component > ar raycast manager
    • ar session origin > add component > AR environment prob manager
    • (extra) Direction Light > add component > HDRLightEstimation.cs (put ar camera there)
      • then, at ar camera manager, light estimation : everything
    • (extra) ar session origin > add component > PlaceOnPlane.cs (place holderPrefab there, above raycast manager there)

in short:

  1. AR Session
  2. AR session origin (ar plane mgr < place prefab; ar raycast mgr; ar env prob mgr)
    1. ar camera
  3. light (hdrLightEmission)

extra interactive

  • package add: XR interactive toolkit (no for new input, go ahead for update)
  • root of interactive prefab root GameObject: - add
    • AR selection(mode:single/mult)/Translation/Rotation/Scale interactable component
      • (selection > put obj for selection visualizer)
      • [opt: use AR Select interactable – Single]
    • collider
  • base quad obj with new material (unlit/transparent > with texture)
  • Extra 2:
    • AR camera: > add AR gesture mgr
    • AR session: > add XR interaction mgr
    • AR session: > add AR placement interactable (put to place prefab there, select mode: single/multi)
      • [opt: use AR Placement interactable – Single]

AR Foundation Setup - markerless v2

  1. build setting: switch to target platform
    • building setting > player setting: other > input setting: both
  2. Package Manager from Unity registry : install (AR foundation) + (ARCore XR) + (XR interactive toolkit)
    • note: if xr interactive pop up, choose (no for new input, go ahead for xr update)
  3. build setting > Player setting - other settings:
    1. OpenGL before vulkan
    2. min api : android api level 26 (store 30)
    3. scripting backend: ILL2CPP
    4. uncheck armv7 and check arm64
    5. input: both (need to restart Unity)
    6. xr plug-in, check ARCore
  4. create XR > AR session + AR session origin
    1. ar session origin > add: ar plane manager
      1. outliner > create XR > AR Default Plane, put it prefab
      2. drag that plane prefab into AR Plane Manager (plane prefab)
      3. direction mode: horizontal
      4. drag that plane prefab into AR Plane Manager (plane prefab)
    2. ar session origin > add: ar raycast manager
    3. ar session origin > add: ar anchor manager
    4. ar session origin > add: AR environment prob manager
      1. (opt) HDRLightEstimation.cs into Directional Light, (put ar camera there); then, at AR camera manager, light estimation : everything
    5. AR camera: > add AR gesture interactor
    6. AR session: > add XR interaction mgr
    7. AR session: > add AR placement interactable [opt: use AR Placement interactable – Single] (put to place prefab there, select mode: single/multi)
  5. create GameObject Prefab
    1. root GameObject > - add: collider (if its children no collider)
    2. root GameObject > - add : AR selection interactable
      1. (opt) quad obj prefab with new material (unlit/transparent > with texture)
      2. put that selector prefab inside the GameObject prefab, hide, and drag it to selector indicator.
      3. alternative: [opt for single prefab case: ARSelectionInteractableAuto.cs];
    3. root GameObject > - add : Translation [opt: ARTranslationInteractableAnchor.cs]
    4. root GameObject > - add : Rotation/Scale interactable component
  6. create UI
    1. create canvas (1080×1920, scale with screen )
    2. image with moving sprite
      1. ctrl+6: animation panel, select the image, and create, and drag image seq into animation
      2. make the image not blocking user click, uncheck Image > Raycast Target
    3. (opt) UIManager script –> Canvas object
      • AR Camera → UIManager (AR Camera manager)
      • AR Session Origin → UIManager (Placement manager)
      • Plane vis prefab → Plane Prefab
      • Go To AR session > AR placement Interactable Single Anchor:
        • interactable events: add new, drag Canvas to object, and use PlacedObject() function as response
  7. prefab animation

AR GPS

  • import AR GSP package, right click add > AR GPS > Create basic scene structure
  • GSP stage object, uncheck “Use moving average”

UI Setup

  • image with moving sprite
    • ctrl+6: animation panel, select the image, and create, and drag image seq into animation
    • make the image not blocking user click, uncheck Image > Raycast Target

Hardware Debug

  • add package: android logcat
  • window > analysis > android logcat

Other related info

  • devwiki/arfoundation.txt
  • Last modified: 2022/05/24 12:10
  • by ying