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.

85 lines
5.2 KiB

4 years ago
  1. # AR tracked image manager
  2. The tracked image manager is a type of [trackable manager](trackable-managers.md).
  3. ![AR tracked image manager](images/ar-tracked-image-manager.png "AR tracked image manager")
  4. The tracked image manager creates `GameObject`s for each detected image in the environment. Before an image can be detected, the manager must be instructed to look for a set of reference images compiled into a reference image library. It only detects images in this library.
  5. ## Reference library
  6. For instructions on how to create a reference image library in the Unity Editor, see documentation on the [Tracked Image Subsystem](http://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@latest?preview=1&subfolder=/manual/image-tracking.html).
  7. The reference image library can be set at runtime, but as long as the tracked image manager component is enabled, the reference image library must be non-null. You can set it via script with:
  8. ```csharp
  9. ARTrackedImageManager manager = ...;
  10. manager.referenceLibrary = myReferenceImageLibrary;
  11. ```
  12. You can set the reference image library to be either an `XRReferenceImageLibrary` or a `RuntimeReferenceImageLibrary`. You can only create an `XRReferenceImageLibrary` in the Editor, and you can't modify it at runtime. A `RuntimeReferenceImageLibrary` is the runtime representation of an `XRReferenceImageLibrary`. When you set the library to be an `XRReferenceImageLibrary`, the image tracking subsystem automatically converts it to a `RuntimeReferenceImageLibrary` for consumption.
  13. The actual image library data is provider-specific; refer to your provider's documentation for details.
  14. You can create a `RuntimeReferenceImageLibrary` from an `XRReferenceImageLibrary` with the [`ARTrackedImageManager.CreateRuntimeLibrary`](../api/UnityEngine.XR.ARFoundation.ARTrackedImageManager.html#UnityEngine_XR_ARFoundation_ARTrackedImageManager_CreateRuntimeLibrary_XRReferenceImageLibrary_) method:
  15. ```csharp
  16. XRReferenceImageLibrary serializedLibrary = ...
  17. RuntimeReferenceImageLibrary runtimeLibrary = trackedImageManager.CreateRuntimeLibrary(serializedLibrary);
  18. ```
  19. ## Adding new reference images at runtime
  20. Some subsystems might support image libraries that are modifiable at runtime. In this case, the subsystem produces a `RuntimeReferenceImageLibrary` that is a `MutableRuntimeReferenceImageLibrary`. To use it, you need to cast the `RuntimeReferenceImageLibrary` to a `MutableRuntimeReferenceImageLibrary`:
  21. ```csharp
  22. if (trackedImageManager.referenceLibrary is MutableRuntimeReferenceImageLibrary mutableLibrary)
  23. {
  24. // use the mutableLibrary
  25. }
  26. ```
  27. To create an empty library that you can add images to later, you can call `CreateRuntimeLibrary` without arguments:
  28. ```csharp
  29. var library = trackedImageManager.CreateRuntimeLibrary();
  30. if (library is MutableRuntimeReferenceImageLibrary mutableLibrary)
  31. {
  32. // add images to mutableLibrary
  33. }
  34. ```
  35. You can check whether a particular tracked image manager supports mutable libraries with its descriptor:
  36. ```csharp
  37. if (trackedImageManager.descriptor.supportsMutableLibrary)
  38. {
  39. // Mutable reference image libraries are supported
  40. }
  41. ```
  42. You can add images to mutable libraries allow images at any time. Adding an image can be computationally expensive, and might take a few frames to complete. The [Unity Job System](https://docs.unity3d.com/Manual/JobSystem.html) is used to process images asynchronously.
  43. To add an image to a `MutableRuntimeReferenceImageLibrary`, use the [`ScheduleAddImageJob`](../api/UnityEngine.XR.ARFoundation.MutableRuntimeReferenceImageLibraryExtensions.html#UnityEngine_XR_ARFoundation_MutableRuntimeReferenceImageLibraryExtensions_ScheduleAddImageJob_MutableRuntimeReferenceImageLibrary_Texture2D_System_String_System_Nullable_System_Single__JobHandle_) method. This returns a `JobHandle` that you can use to determine when the job is complete. You can safely discard this handle if you don't need to do this.
  44. Multiple add image jobs can be processed concurrently. Whether or not `MutableRuntimeReferenceImageLibrary` is currently in use for image tracking has no effect on this.
  45. ## Creating a manager at runtime
  46. When you add a component to an active `GameObject` at runtime, Unity immediately invokes its `OnEnable` method. However, the `ARTrackedImageManager` requires a non-null reference image library. If the reference image library is null when the `ARTrackedImageManager` is enabled, it will automatically disable itself.
  47. To add an `ARTrackedImageManager` at runtime, set its reference image library and then re-enable it:
  48. ```csharp
  49. var manager = gameObject.AddComponent<ARTrackedImageManager>();
  50. manager.referenceLibrary = myLibrary;
  51. manager.enabled = true;
  52. ```
  53. ## Maximum number of moving images
  54. Some providers can track moving images. This typically requires more CPU resources, so you can specify the number of moving images to track simultaneously. Check for support via the `SubsystemDescriptor` (`ARTrackedImageManager.descriptor`).
  55. ## Tracked image prefab
  56. This prefab is instantiated whenever an image from the reference image library is detected. The manager ensures the instantiated `GameObject` includes an `ARTrackedImage` component. You can get the reference image that was used to detect the `ARTrackedImage` with the `ARTrackedImage.referenceImage` property.