ImageTrackerGlobalSettings.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace Imagine.WebAR{
  6. [System.Serializable]
  7. public class ImageTargetInfo
  8. {
  9. public string id;
  10. public Texture2D texture;
  11. }
  12. [System.Serializable]
  13. public class TrackerSettings
  14. {
  15. [Tooltip("Allows tracking multiple image targets simultaneously (Experimental)")]
  16. [SerializeField] public int maxSimultaneousTargets = 1;
  17. //public enum TrackingQuality { SPEED_OVER_QUALITY, BALANCED, QUALITY_OVER_SPEED };
  18. //[SerializeField] public TrackingQuality trackingQuality = TrackingQuality.BALANCED;
  19. public enum FrameRate { FR_30_FPS = 30, FR_60FPS = -1};
  20. [SerializeField] public FrameRate targetFrameRate = FrameRate.FR_30_FPS;
  21. [SerializeField] public AdvancedSettings advancedSettings;
  22. [SerializeField] [Space] public bool useExtraSmoothing = false;
  23. [SerializeField] [Range(1f, 20)] public float smoothenFactor = 10;
  24. [Tooltip("If enabled, you can display imageTarget feature points by pressing 'I' in desktop browser")]
  25. [Space][SerializeField] public bool debugMode = false;
  26. public string Serialize() {
  27. var json = "{";
  28. json += "\"MAX_SIMULTANEOUS_TRACK\":" + maxSimultaneousTargets + ",";
  29. json += "\"FRAMERATE\":" + (int)targetFrameRate + ",";
  30. json += "\"MAX_AREA\":" + Mathf.RoundToInt(advancedSettings.maxFrameArea * 1000) + ",";
  31. json += "\"MAX_PIXELS\":" + Mathf.RoundToInt(advancedSettings.maxFrameLength) + ",";
  32. json += "\"TRACK_TARGET_MATCH_COUNT\":" + advancedSettings.trackedPoints + ",";
  33. json += "\"POSE_CORRECTION_INTERVAL\":" + advancedSettings.poseCorrectionInterval + ",";
  34. json += "\"DETECT_INTERVAL\":" + advancedSettings.detectInterval + ",";
  35. json += "\"DETECTABILITY\":" + advancedSettings.detectability.ToStringInvariantCulture() + ",";
  36. json += "\"DETECT_ZONE\":\"" + advancedSettings.detectZone + "\"";
  37. json += "}";
  38. return json;
  39. }
  40. }
  41. [System.Serializable]
  42. public class AdvancedSettings
  43. {
  44. [Tooltip("Higher values will increase accuracy, but decreases frame rate")]
  45. [SerializeField][Range(240, 500)]
  46. public int maxFrameLength = 450;
  47. [Tooltip("Higher values will make the image easily detected, but induces a short lag/delay")]
  48. [SerializeField] [Range(24, 80)] public float maxFrameArea = 80;
  49. [Tooltip("Higher values will improve stability, but decreases frame rate")]
  50. [SerializeField] [Range(16, 80)] public int trackedPoints = 80;
  51. [Tooltip("Lower values will be resistant to skewing, but introduces jitter")]
  52. [SerializeField] [Range(200, 3000)] public int poseCorrectionInterval = 1500;
  53. [Space]
  54. [Tooltip("Lower intervals will speed up detection, especially on multiple targets, but significantly decreases frame rate. Value in millisecods")]
  55. [SerializeField] [Range(50, 1000)] public int detectInterval = 200;
  56. [Tooltip("Higher values will help weaker image targets to get detected, but decreases fps")]
  57. [SerializeField] [Range(0.4f, 1)] public float detectability = 0.5f;
  58. public enum DetectZone {WIDE, NARROW};
  59. [Tooltip("WIDE - Recommended for strong targets, focuses detection on large image details\n\nNARROW - Recommended for weaker targets or when using a small frameSize(eg. 300px), focuses detection on small image details")]
  60. [SerializeField] public DetectZone detectZone = DetectZone.WIDE;
  61. }
  62. //[CreateAssetMenu(menuName = "Imagine WebAR/Image Tracker Global Settings", order = 1300)]
  63. public class ImageTrackerGlobalSettings : ScriptableObject
  64. {
  65. [SerializeField] public List<ImageTargetInfo> imageTargetInfos;
  66. [SerializeField] public List<TrackerSettingsTemplateSO> settingsTemplates;
  67. private static ImageTrackerGlobalSettings _instance;
  68. public static ImageTrackerGlobalSettings Instance
  69. {
  70. get
  71. {
  72. if(_instance == null)
  73. {
  74. _instance = Resources.Load<ImageTrackerGlobalSettings>("ImageTrackerGlobalSettings");
  75. }
  76. return _instance;
  77. }
  78. }
  79. }
  80. }