SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
16 KiB

4 years ago
  1. # About AR Foundation
  2. AR Foundation allows you to work with augmented reality platforms in a multi-platform way within Unity. This package presents an interface for Unity developers to use, but doesn't implement any AR features itself. To use AR Foundation on a target device, you also need a separate package for that platform (for example, `ARKit XR Plugin` on iOS or `ARCore XR Plugin` on Android).
  3. AR Foundation is a set of `MonoBehaviour`s and APIs for dealing with devices that support the following concepts:
  4. - World tracking: track the device's position and orientation in physical space.
  5. - Plane detection: detect horizontal and vertical surfaces.
  6. - Point clouds, also known as feature points.
  7. - Anchor: an arbitrary position and orientation that the device tracks.
  8. - Light estimation: estimates for average color temperature and brightness in physical space.
  9. - Environment probe: a means for generating a cube map to represent a particular area of the physical environment.
  10. - Face tracking: detect and track human faces.
  11. - Image tracking: detect and track 2D images.
  12. If you are migrating from AR Foundation 1.0, see the [Migration Guide](migration-guide.md).
  13. ## Subsystems
  14. AR Foundation is built on subsystems. A **subsystem** is a platform-agnostic interface for surfacing different types of information. The AR-related subsystems are defined in the [`AR Subsystems`](https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@latest?preview=1&subfolder=/manual/) package and use the namespace `UnityEngine.XR.ARSubsystems`. You will occasionally need to interact with the types in the AR Subsystems package.
  15. Each subsystem handles specific functionality. For example, `XRPlaneSubsystem` provides the plane detection interface.
  16. ### Providers
  17. A **provider** is a concrete implementation of a subsystem. For example, the `ARCore XR Plugin` package contains the ARCore implementation for many of the AR subsystems.
  18. Because different providers have varying support for specific features, each subsystem also has a descriptor that indicates which specific subsystem features it supports. For example, the `XRPlaneSubsystemDescriptor` contains properties indicating whether it supports horizontal or vertical plane detection.
  19. Each individual provider determines how to implement each subsystem. In general, they wrap that platform's native SDK (for example, ARKit on iOS and ARCore on Android).
  20. # Installing AR Foundation
  21. To install this package, follow the instructions in the [Package Manager documentation](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@latest/index.html).
  22. Subsystems are implemented in other packages. To use AR Foundation, you must also install at least one of these platform-specific AR packages from the Package Manager window (menu: **Window > Package Manager**):
  23. - ARKit XR Plugin
  24. - ARCore XR Plugin
  25. # Glossary
  26. | **Term** | **Description** |
  27. |-|-|
  28. | **Tracking** | The AR device's ability to determine its relative position and orientation in the physical world. If the environment is too dark, for example, the device might "lose tracking", which means it can no longer accurately report its position. |
  29. | **Trackable** | A real-world feature, such as a planar surface, that the AR device tracks and/or detects. |
  30. | **Feature Point** | A specific point in a point cloud. An AR device uses the device’s camera and image analysis to track specific points in the world, and uses these points to build a map of its environment. These are usually high-frequency elements, such as a knot in a wood-grain surface.|
  31. | **Session** | An AR instance. |
  32. | **Session Space** | The coordinate system relative to the beginning of the AR session. For example, session space (0, 0, 0) refers to the position at which the AR session was created. An AR device typically reports trackables and tracking information relative to its session origin.|
  33. # Using AR Foundation
  34. ## Samples
  35. For examples, see the [ARFoundation Samples](https://github.com/Unity-Technologies/arfoundation-samples) GitHub repository.
  36. ## Basic setup
  37. A basic AR scene hierarchy looks like this:
  38. ![Scene graph](images/simple_scene_graph.png "Scene graph")
  39. To create these scenes automatically, right-click in the scene hierarchy, and select **XR > AR Session** or **XR > AR Session Origin** from the context menu.
  40. ![Context menu](images/gameobject_context_menu.png "Context menu")
  41. The required components are explained in more detail below.
  42. ### ARSession
  43. An AR scene should include an `ARSession` component. The AR Session controls the lifecycle of an AR experience by enabling or disabling AR on the target platform. The `ARSession` can be on any `GameObject`.
  44. ![ARSession component](images/ar-session.png "ARSession component")
  45. When you disable the `ARSession`, the system no longer tracks features in its environment, but if you enable it at a later time, the system will attempt to recover and maintain previously-detected features.
  46. If you enable the **Attempt Update** option, the device tries to install AR software if possible. Support for this feature is platform-dependent.
  47. **Note:** An AR session is a global construct. An `ARSession` component manages this global session, so multiple `ARSession` components will all try to manage the same global session.
  48. #### Checking for device support
  49. Some platforms might support a limited subset of devices. On these platforms, your application needs to be able to detect support for AR Foundation so it can provide an alternative experience when AR is not supported.
  50. The `ARSession` component has a static coroutine that you can use to determine whether AR is supported at runtime:
  51. ```csharp
  52. public class MyComponent {
  53. [SerializeField] ARSession m_Session;
  54. IEnumerator Start() {
  55. if ((ARSession.state == ARSessionState.None ||)
  56. (ARSession.state == ARSessionState.CheckingAvailability))
  57. {
  58. yield return ARSession.CheckAvailability();
  59. }
  60. if (ARSession.state == ARSessionState.Unsupported)
  61. {
  62. // Start some fallback experience for unsupported devices
  63. }
  64. else
  65. {
  66. // Start the AR session
  67. m_Session.enabled = true;
  68. }
  69. }
  70. }
  71. ```
  72. #### Session state
  73. To determine the current state of the session (for example, whether the device is supported, if AR software is being installed, and whether the session is working), use `ARSession.state`. You can also subscribe to an event when the session state changes: `ARSession.stateChanged`.
  74. |`ARSessionState`|**Description**|
  75. |-|-|
  76. |`None`|The AR System has not been initialized and availability is unknown.|
  77. |`Unsupported`|The current device doesn't support AR.|
  78. |`CheckingAvailability`|The system is checking the availability of AR on the current device.|
  79. |`NeedsInstall`|The current device supports AR, but AR support requires additional software to be installed.|
  80. |`Installing`|AR software is being installed.|
  81. |`Ready`|AR is supported and ready.|
  82. |`SessionInitialized`|An AR session is initializing (that is, starting up). This usually means AR is working, but hasn't gathered enough information about the environment.|
  83. |`SessionTracking`|An AR session is running and is tracking (that is, the device is able to determine its position and orientation in the world).|
  84. ### ARSessionOrigin
  85. ![AR session origin](images/ar-session-origin.png "AR Session Origin")
  86. The purpose of the `ARSessionOrigin` is to transform trackable features, such as planar surfaces and feature points, into their final position, orientation, and scale in the Unity Scene. Because AR devices provide their data in "session space", which is an unscaled space relative to the beginning of the AR session, the `ARSessionOrigin` performs the appropriate transformation into Unity space.
  87. This concept is similar to the difference between "model" or "local" space and world space when working with other Assets in Unity. For instance, if you import a house Asset from a DCC tool, the door's position is relative to the modeler's origin. This is commonly called "model space" or "local space". When Unity instantiates it, it also has a world space that's relative to Unity's origin.
  88. Likewise, trackables that an AR device produces, such as planes, are provided in "session space", relative to the device's coordinate system. When instantiated in Unity as `GameObject`s, they also have a world space. In order to instantiate them in the correct place, AR Foundation needs to know where the session origin should be in the Unity scene.
  89. `ARSessionOrigin` also allows you to scale virtual content and apply an offset to the AR Camera. If you're scaling or offsetting the `ARSessionOrigin`, then its AR Camera should be a child of the `ARSessionOrigin`. Because the AR Camera is session-driven, this setup allows the AR Camera and detected trackables to move together.
  90. #### Scale
  91. To apply scale to the `ARSessionOrigin`, set its `transform`'s scale. This has the effect of scaling all the data coming from the device, including the AR Camera's position and any detected trackables. Larger values make AR content appear smaller. For example, a scale of 10 would make your content appear 10 times smaller, while 0.1 would make your content appear 10 times larger.
  92. ### Tracked Pose Driver
  93. The AR Camera, which will be used to render any trackables you wish to visualize, should be parented to the `ARSessionOrigin`'s `GameObject`. The AR Camera should also have a `TrackedPoseDriver` component on it to drive the AR Camera’s local position and orientation according to the device's tracking information. This setup allows the AR Camera’s local space to match the AR "session space".
  94. ![Tracked Pose Driver](images/tracked-pose-driver.png "Tracked Pose Driver")
  95. ### AR Camera manager
  96. The `ARCameraManager` enables features for the AR Camera, including the management of the device camera textures and the properties that set the light estimation modes.
  97. ![AR Camera Manager](images/ar-camera-manager.png "AR Camera Manager")
  98. | **Setting** | **Function** |
  99. |-|-|
  100. | **Focus Mode** | Can be *Auto* or *Fixed*. *Auto* enables the hardware Camera's automatic focus mode, while *Fixed* disables it (the focus is fixed and doesn't change automatically). |
  101. | **Light Estimation** | Can be *Disabled* or *Ambient intensity*. If not disabled, this instructs the platform to produce light estimation information. This estimates the average light intensity and color in the physical environment and can affect performance, so disable it if your application doesn't use it.|
  102. ### AR Camera background
  103. If you want the video feed from the device camera to show up as the rendered background of the scene at runtime, you need to add an `ARCameraBackground` component to a Camera. Otherwise, the background at runtime will come from the `Camera.clearFlags` setting. The `ARCameraBackground` component subscribes to AR Camera events and renders the AR Camera texture to the screen (that is, the background texture from the device camera must be rendered for each frame). This is not required, but common for AR apps.
  104. ![AR Camera Background](images/ar-camera-background.png "AR Camera Background")
  105. The `Custom Material` property is optional, and typically you don't need to set it. The platform-specific packages that Unity provides, such as ARCore and ARKit, contain their own shaders for background rendering.
  106. If `Use Custom Material` is `true`, the `ARCameraBackground` uses the `Material` you specify for background rendering.
  107. If you have exactly one `ARSessionOrigin`, you only need to add the `ARCameraBackground` to that Camera. If you have multiple `ARSessionOrigin`s (for example, to selectively render different content at different scales), you should use separate Cameras for each `ARSessionOrigin` and a separate, single AR Camera for the `ARCameraBackground`.
  108. #### Configuring ARCameraBackground with the Universal Render Pipeline (URP)
  109. Please refer to [this additional documentation to configure an AR Foundation project with a URP](ar-camera-background-with-scriptable-render-pipeline.md).
  110. #### Copying the Camera Texture to a Render Texture when accessing the camera image on the GPU
  111. Camera Textures are likely [external Textures](https://docs.unity3d.com/ScriptReference/Texture2D.CreateExternalTexture.html) and might not last beyond a frame boundary. It can be useful to copy the Camera image to a [Render Texture](https://docs.unity3d.com/Manual/class-RenderTexture.html) to persist it or process it further. The following code blits the Camera image to a Render Texture of your choice:
  112. ```csharp
  113. Graphics.Blit(null, m_MyRenderTexture, m_ARBackgroundCamera.material);
  114. ```
  115. ### Accessing the Camera Image on the CPU
  116. See documentation on [camera images](cpu-camera-image.md).
  117. ### AR input manager
  118. This component is required to enable world tracking. Without it, the Tracked Pose Driver can't acquire a pose for the device.
  119. This component can be anywhere in your Scene, but you shouldn't have more than one.
  120. ![AR Input Manager](images/ar-input-manager.png "AR Input Manager")
  121. ### Trackable managers
  122. See documentation on [trackable managers](trackable-managers.md).
  123. ### Visualizing trackables
  124. Trackable components don't do anything on their own; they just contain data associated with each trackable. There are many ways to visualize trackables, so AR Foundation includes some visualizers that you can use for debugging or as a starting point to create a visualizer suitable for your application.
  125. ## Ray casting
  126. Also known as hit testing, ray casting allows you to determine where a ray (defined by an origin and direction) intersects with a trackable. The current ray cast interface only tests against planes and points in the point cloud. The ray casting interface is similar to the one in the Unity Physics module, but since AR trackables may not necessarily have a presence in the physics world, AR Foundation provides a separate interface.
  127. To perform a ray cast, add an `ARRaycastManager` to the same `GameObject` as the `ARSessionOrigin`.
  128. ![AR Raycast Manager](images/ar-raycast-manager.png "AR Raycast Manager")
  129. There are two ray casting methods on the `ARRaycastManager`:
  130. ```csharp
  131. public bool Raycast(Vector2 screenPoint, List<ARRaycastHit> hitResults, TrackableType trackableTypeMask = TrackableType.All);
  132. public bool Raycast(Ray ray, List<ARRaycastHit> hitResults, TrackableType trackableTypeMask = TrackableType.All, float pointCloudRaycastAngleInDegrees = 5f);
  133. ```
  134. The first method takes a two-dimensional position on the screen. You can, for example, pass a touch position directly:
  135. ```csharp
  136. var raycastManager = GetComponent<ARRaycastManager>();
  137. raycastManager.Raycast(Input.GetTouch(0).position, ...);
  138. ```
  139. The second method takes an arbitrary `Ray` (a position and direction).
  140. The following table summarizes the other parameters:
  141. | **Parameter** | **Description** |
  142. |-|-|
  143. | `hitResults` | The results for both methods are stored in this `List`, which must not be `null`. This lets you reuse the same `List` object to avoid garbage-collected allocations. |
  144. | `trackableTypeMask` | The type(s) of trackable(s) to hit test against. This is a flag, so multiple types can be bitwise OR'd together, for example, `TrackableType.PlaneWithinPolygon` &#124; `FeaturePoint` |
  145. # Technical details
  146. ## Requirements
  147. This version of AR Foundation is compatible with the following versions of the Unity Editor:
  148. * 2019.2 and later
  149. ## Known limitations
  150. AR Foundation includes the following known limitations:
  151. * No known issues
  152. ## Document revision history
  153. |Date|Reason|
  154. |---|---|
  155. |April 18, 2019|Update documentation to include new features (environment probes, image tracking, face tracking, object tracking).|
  156. |March 4, 2019|Update documentation to reflect 2.0.0 changes.|
  157. |November 15, 2018|Face Tracking added.|
  158. |July 25, 2018|Update `ARCameraBackground` image and description following refactor.<br/>Add howto section for blitting the camera image to a render texture.|
  159. |July 16, 2018|Additional explanation for `ARSessionOrigin`|
  160. |June 14, 2018|Update `ARSessionOrigin` photos|
  161. |June 12, 2018|Update `ARPlaneMeshVisualizer` and `ARPointCloudMeshVisualizer` with additional debug recommendations and standards.|
  162. |June 7, 2018|Remove known issue.|
  163. |June 6, 2018|Update ARSession image.|
  164. |April 25, 2018|Updated docs and screen shots after package rename.|
  165. |April 19, 2018|Updated screen shots and information after code changes. Added section on `ARBackgroundRenderer` component. |
  166. |April 10, 2018|Document created.|