// private Guid cacheGuid = Guid.Empty; // // When indexes update, there are three likely scenarios: // // 1) ID has not changed. // // 2) ID has shifted by a few values due to sorting. // // 3) Content has been removed, and therefore there is no ID. // private int ReassociateContentID(int index, TrackableType markerType, string content) { // if (string.CompareOrdinal(ARToolKitAssetManager.AllMarkers[index], content) == 0) { // return index; // } else { // for (int i = 0; i < ARToolKitAssetManager. // } // } public override void OnInspectorGUI() { // Get the ARMarker that this panel will edit. ARTrackable arMarker = (ARTrackable)target; if (null == arMarker) { return; } // Attempt to load. Might not work out if e.g. for a single marker, pattern hasn't been // assigned yet, or for an NFT marker, dataset hasn't been specified. if (arMarker.UID == ARTrackable.NO_ID) { PluginFunctions.arwInitialiseAR(); arMarker.Load(); } // Check if a new image was dropped into the Project directory string path = Application.streamingAssetsPath + "/" + ARToolKitAssetManager.IMAGES_DIRECTORY_NAME; DirectoryInfo dir = new DirectoryInfo(path); FileInfo[] imageFileList = dir.GetFiles("*.jpg").Union(dir.GetFiles("*.jpeg")).ToArray(); if (imageFileList != null && ARToolKitAssetManager.Images != null && imageFileList.Length != ARToolKitAssetManager.Images.Length) { if (imageFileList.Length < ARToolKitAssetManager.Images.Length) { //An image was deleted from the file system so we might have an empty ARTrackable now ARController.Log("Warning: Trackable image removed. Please check all ARTrackables and make sure that they have an image assigned."); } //We found a new trackable in the file system or a trackable was removed lets reload the trackables. ARToolKitAssetManager.Reload(); } // Draw the drag n drop area DropAreaGUI(); int selectedMarker = ArrayUtility.IndexOf(ARToolKitAssetManager.AllMarkers, arMarker.EditorMarkerName); arMarker.EditorMarkerIndex = EditorGUILayout.Popup("Marker", selectedMarker, ARToolKitAssetManager.AllMarkers); bool newSelection = false; if (arMarker.EditorMarkerIndex < 0) { //An image was deleted from the file system so we have an empty ARTrackable now ARController.Log("Warning: Trackable image removed. Please check the ARTrackable and make sure that is has an image assigned."); return; } else { if (string.CompareOrdinal(arMarker.EditorMarkerName, ARToolKitAssetManager.AllMarkers[arMarker.EditorMarkerIndex]) != 0) { newSelection = true; arMarker.EditorMarkerName = ARToolKitAssetManager.AllMarkers[arMarker.EditorMarkerIndex]; } } ARTrackable.TrackableType markerType = DetermineTrackableType(arMarker.EditorMarkerIndex); if (arMarker.Type != markerType) { arMarker.ClearUnusedValues(); arMarker.Type = markerType; UpdatePatternDetectionMode(); } EditorGUILayout.LabelField("Type ", ARTrackable.TrackableTypeNames[arMarker.Type]); EditorGUILayout.LabelField("Unique ID", (arMarker.UID == ARTrackable.NO_ID ? "Not Loaded": arMarker.UID.ToString())); EditorGUILayout.BeginHorizontal(); // Draw all the marker images if (arMarker.Patterns != null) { for (int i = 0; i < arMarker.Patterns.Length; ++i) { EditorGUILayout.Separator(); GUILayout.Label(new GUIContent(string.Format("Pattern {0}, {1}m", i, arMarker.Patterns[i].width.ToString("n3")), arMarker.Patterns[i].texture), GUILayout.ExpandWidth(false)); // n3 -> 3 decimal places. } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); switch (arMarker.Type) { case ARTrackable.TrackableType.TwoD: if (newSelection) { arMarker.TwoDImageName = ARToolKitAssetManager.AllMarkers[arMarker.EditorMarkerIndex]; } float twoDImageHeight = EditorGUILayout.FloatField("Image height", arMarker.TwoDImageHeight); if (twoDImageHeight != arMarker.TwoDImageHeight) { EditorUtility.SetDirty(arMarker); arMarker.TwoDImageHeight = twoDImageHeight; } float width = 0.0f, height = 0.0f; int imageWidth = 0, imageHeight = 0; float[] transformation = new float[16]; if (PluginFunctions.arwGetTrackableAppearanceConfig(arMarker.UID, 0, transformation, out width, out height, out imageWidth, out imageHeight)) { Color32[] imagePixels = new Color32[imageWidth * imageHeight]; if (PluginFunctions.arwGetTrackableAppearanceImage(arMarker.UID, 0, imagePixels)) { //Set the texture with the trackable appearance. Texture2D texture = new Texture2D(imageWidth, imageHeight, TextureFormat.RGBA32, true); texture.SetPixels32(imagePixels); texture.Apply(); //Display label and texture to the user EditorGUILayout.BeginHorizontal(); GUILayout.Label("Trackable Appearance"); //Resize texture for viewport with max with and height GUILayout.Label(ARTrackableAppearanceScale.BilinearWithMaxSize(texture, 200, 200)); EditorGUILayout.EndHorizontal(); } } break; case ARTrackable.TrackableType.Square: if (newSelection) { arMarker.PatternContents = GetPatternContents(ARToolKitAssetManager.AllMarkers[arMarker.EditorMarkerIndex]); } arMarker.PatternWidth = EditorGUILayout.FloatField("Pattern Width (m)", arMarker.PatternWidth); arMarker.UseContPoseEstimation = EditorGUILayout.Toggle("Contstant Pose Estimation", arMarker.UseContPoseEstimation); break; case ARTrackable.TrackableType.SquareBarcode: if (newSelection) { string[] idArray = ARToolKitAssetManager.AllMarkers[arMarker.EditorMarkerIndex].Split(' '); arMarker.BarcodeID = int.Parse(idArray[idArray.Length - 1]); } arMarker.PatternWidth = EditorGUILayout.FloatField("Pattern Width (m)", arMarker.PatternWidth); arMarker.UseContPoseEstimation = EditorGUILayout.Toggle("Contstant Pose Estimation", arMarker.UseContPoseEstimation); break; case ARTrackable.TrackableType.Multimarker: if (newSelection) { arMarker.MultiConfigFile = ARToolKitAssetManager.AllMarkers[arMarker.EditorMarkerIndex]; } break; } EditorGUILayout.Separator(); arMarker.Filtered = EditorGUILayout.Toggle("Filter Pose", arMarker.Filtered); if (arMarker.Filtered) { arMarker.FilterSampleRate = EditorGUILayout.Slider("Sample Rate", arMarker.FilterSampleRate, 1.0f, 30.0f); arMarker.FilterCutoffFreq = EditorGUILayout.Slider("Cutoff Frequency", arMarker.FilterCutoffFreq, 1.0f, 30.0f); } if (arMarker.Type == ARTrackable.TrackableType.Square || arMarker.Type == ARTrackable.TrackableType.SquareBarcode || arMarker.Type == ARTrackable.TrackableType.Multimarker) { showGlobalSquareOptions = EditorGUILayout.Foldout(showGlobalSquareOptions, "Global Square Tracking Options"); if (showGlobalSquareOptions) { ARController.Instance.TemplateSize = EditorGUILayout.IntSlider("Template Size (bits)", ARController.Instance.TemplateSize, 16, 64); int currentTemplateCountMax = ARController.Instance.TemplateCountMax; int newTemplateCountMax = EditorGUILayout.IntField("Maximum Template Count", currentTemplateCountMax); if (newTemplateCountMax != currentTemplateCountMax && newTemplateCountMax > 0) { ARController.Instance.TemplateCountMax = newTemplateCountMax; } bool trackInColor = EditorGUILayout.Toggle("Track Templates in Color", ARController.Instance.trackTemplatesInColor); if (trackInColor != ARController.Instance.trackTemplatesInColor) { ARController.Instance.trackTemplatesInColor = trackInColor; UpdatePatternDetectionMode(); } ARController.Instance.BorderSize = UnityEngine.Mathf.Clamp(EditorGUILayout.FloatField("Border Size (%)", ARController.Instance.BorderSize), 0.0f, 0.5f); ARController.Instance.LabelingMode = (ARController.ARToolKitLabelingMode)EditorGUILayout.EnumPopup("Marker Border Color", ARController.Instance.LabelingMode); ARController.Instance.ImageProcMode = (ARController.ARToolKitImageProcMode)EditorGUILayout.EnumPopup("Image Processing Mode", ARController.Instance.ImageProcMode); } } var obj = new SerializedObject(arMarker); var prop = obj.FindProperty("eventReceivers"); EditorGUILayout.PropertyField(prop, new GUIContent("Event Receivers"), true); obj.ApplyModifiedProperties(); }