예제 #1
0
    private void copyToStreamingAssets(String path)
    {
        String fileName    = path.Substring(path.LastIndexOf('/') + 1);
        String destination = Application.streamingAssetsPath + "/" + ARToolKitAssetManager.IMAGES_DIRECTORY_NAME + "/" + fileName;

        //Check type of file to be .jpg or .jpeg
        if (fileName.Contains(".jpg") || fileName.Contains(".jpeg"))
        {
            ARController.Log("Copy image from: " + path + " to: " + destination);
            if (!File.Exists(destination))
            {
                FileUtil.CopyFileOrDirectory(path, destination);
                AssetDatabase.Refresh();
                ARToolKitAssetManager.Reload();
            }
            else
            {
                Debug.logger.Log(LogType.Error, "File with name: " + fileName + " already exists at destination: " + destination);
            }
        }
        else
        {
            //Dropped file is not a valid format print a warning\
            Debug.logger.Log(LogType.Warning, "<color=red>Item with invalid extension dropped. Only .jpg and .jpeg allowed.</color>");
        }
    }
예제 #2
0
    private static ARTrackable.TrackableType DetermineTrackableType(int markerIndex)
    {
        int start = ARToolKitAssetManager.Images.Length;

        if (markerIndex < start)
        {
            return(ARTrackable.TrackableType.TwoD);
        }
        start += ARToolKitAssetManager.PatternMarkers.Length;
        if (markerIndex < start)
        {
            return(ARTrackable.TrackableType.Square);
        }
        start += ARToolKitAssetManager.Multimarkers.Length;
        if (markerIndex < start)
        {
            return(ARTrackable.TrackableType.Multimarker);
        }
        ARController arController = ARController.Instance;

        start += ARToolKitAssetManager.GetBarcodeList(arController.MatrixCodeType).Length;
        if (markerIndex < start)
        {
            return(ARTrackable.TrackableType.SquareBarcode);
        }
        // Default. Harmless out of range.
        return(ARTrackable.TrackableType.Square);
    }
예제 #3
0
    public override void OnInspectorGUI()
    {
        ARController arController = (ARController)target;

        if (arController == null)
        {
            return;
        }

        EditorGUILayout.LabelField("Version", "ARToolKit " + arController.Version);

        EditorGUILayout.Separator();
        if (cameras == null)
        {
            cameras = ARToolKitAssetManager.GetCameras();
        }
        cameraCount = (cameras == null ? 0 : cameras.Length);

        if (!arController.VideoIsStereo)
        {
            if (cameraCount <= 0)
            {
                arController.videoCparamOverride0 = false;
            }
            EditorGUI.BeginDisabledGroup(cameraCount <= 0);
            arController.videoCparamOverride0 = !EditorGUILayout.Toggle("Use automatic camera parameters", !arController.videoCparamOverride0);
            EditorGUI.EndDisabledGroup();
            if (!arController.videoCparamOverride0)
            {
                arController.videoCParamName0 = "";
            }
            else
            {
                arController.EditorCameraIndex = EditorGUILayout.Popup("Camera Parameter", Math.Min(cameraCount - 1, arController.EditorCameraIndex), cameras);
                if (string.Compare(cameras[arController.EditorCameraIndex], arController.videoCParamName0, StringComparison.Ordinal) != 0)
                {
                    arController.videoCParamName0 = cameras[arController.EditorCameraIndex];
                }
            }
            if (cameraCount <= 0)
            {
                EditorGUILayout.HelpBox("No camera parameters found.", MessageType.Info);
            }
        }
        else
        {
            if (cameraCount <= 0)
            {
                arController.videoCparamOverride0 = false;
            }
            EditorGUI.BeginDisabledGroup(cameraCount <= 0);
            arController.videoCparamOverride0 = !EditorGUILayout.Toggle("Use automatic camera parameters (L)", !arController.videoCparamOverride0);
            EditorGUI.EndDisabledGroup();
            if (!arController.videoCparamOverride0)
            {
                arController.videoCParamName0 = "";
            }
            else
            {
                arController.EditorCameraIndex = EditorGUILayout.Popup("Camera Parameter (L)", Math.Min(cameraCount - 1, arController.EditorCameraIndex), cameras);
                if (string.Compare(cameras[arController.EditorCameraIndex], arController.videoCParamName0, StringComparison.Ordinal) != 0)
                {
                    arController.videoCParamName0 = cameras[arController.EditorCameraIndex];
                }
            }
            if (cameraCount <= 0)
            {
                arController.videoCparamOverride1 = false;
            }
            EditorGUI.BeginDisabledGroup(cameraCount <= 0);
            arController.videoCparamOverride1 = !EditorGUILayout.Toggle("Use automatic camera parameters (R)", !arController.videoCparamOverride1);
            EditorGUI.EndDisabledGroup();
            if (!arController.videoCparamOverride1)
            {
                arController.videoCParamName1 = "";
            }
            else
            {
                arController.EditorCameraIndexR = EditorGUILayout.Popup("Camera Parameter (R)", Math.Max(cameraCount - 1, arController.EditorCameraIndexR), cameras);
                if (string.Compare(cameras[arController.EditorCameraIndexR], arController.videoCParamName1, StringComparison.Ordinal) != 0)
                {
                    arController.videoCParamName1 = cameras[arController.EditorCameraIndexR];
                }
            }
            if (cameraCount <= 0)
            {
                EditorGUILayout.HelpBox("No camera parameters found.", MessageType.Info);
            }
        }

        showVideoConfiguration = EditorGUILayout.Foldout(showVideoConfiguration, "Video Configuration");
        if (showVideoConfiguration)
        {
            if (!arController.VideoIsStereo)
            {
                arController.videoConfigurationAndroid0      = EditorGUILayout.TextField("Android", arController.videoConfigurationAndroid0);
                arController.videoConfigurationiOS0          = EditorGUILayout.TextField("iOS", arController.videoConfigurationiOS0);
                arController.videoConfigurationLinux0        = EditorGUILayout.TextField("Linux", arController.videoConfigurationLinux0);
                arController.videoConfigurationMacOSX0       = EditorGUILayout.TextField("macOS", arController.videoConfigurationMacOSX0);
                arController.videoConfigurationWindows0      = EditorGUILayout.TextField("Windows", arController.videoConfigurationWindows0);
                arController.videoConfigurationWindowsStore0 = EditorGUILayout.TextField("Windows Store", arController.videoConfigurationWindowsStore0);
            }
            else
            {
                arController.videoConfigurationAndroid0      = EditorGUILayout.TextField("Android (L)", arController.videoConfigurationAndroid0);
                arController.videoConfigurationAndroid1      = EditorGUILayout.TextField("Android (R)", arController.videoConfigurationAndroid1);
                arController.videoConfigurationiOS0          = EditorGUILayout.TextField("iOS (L)", arController.videoConfigurationiOS0);
                arController.videoConfigurationiOS1          = EditorGUILayout.TextField("iOS (R)", arController.videoConfigurationiOS1);
                arController.videoConfigurationLinux0        = EditorGUILayout.TextField("Linux (L)", arController.videoConfigurationLinux0);
                arController.videoConfigurationLinux1        = EditorGUILayout.TextField("Linux (R)", arController.videoConfigurationLinux1);
                arController.videoConfigurationMacOSX0       = EditorGUILayout.TextField("macOS (L)", arController.videoConfigurationMacOSX0);
                arController.videoConfigurationMacOSX1       = EditorGUILayout.TextField("macOS (R)", arController.videoConfigurationMacOSX1);
                arController.videoConfigurationWindows0      = EditorGUILayout.TextField("Windows (L)", arController.videoConfigurationWindows0);
                arController.videoConfigurationWindows1      = EditorGUILayout.TextField("Windows (R)", arController.videoConfigurationWindows1);
                arController.videoConfigurationWindowsStore0 = EditorGUILayout.TextField("Windows Store (L)", arController.videoConfigurationWindowsStore0);
                arController.videoConfigurationWindowsStore1 = EditorGUILayout.TextField("Windows Store (R)", arController.videoConfigurationWindowsStore1);
            }
            arController.VideoIsStereo = EditorGUILayout.Toggle("Stereo Video Input", arController.VideoIsStereo);
            EditorGUILayout.HelpBox("Check this option if you plan to use two cameras to track the environment. This is not stereoscopic rendering. Note: You will have to configure both left (L) and right (R) cameras separately.", MessageType.Info);
        }

        showVideoOptions = EditorGUILayout.Foldout(showVideoOptions, "Video Background");
        if (showVideoOptions)
        {
            arController.BackgroundLayer0 = EditorGUILayout.LayerField("Background Layer", arController.BackgroundLayer0);

            ContentMode currentContentMode = arController.ContentMode;
            ContentMode newContentMode     = (ContentMode)EditorGUILayout.EnumPopup("Content Mode", currentContentMode);
            if (newContentMode != currentContentMode)
            {
                arController.ContentMode = newContentMode;
            }
            arController.ContentRotate90 = EditorGUILayout.Toggle("Rotate 90° Clockwise", arController.ContentRotate90);
            arController.ContentFlipV    = EditorGUILayout.Toggle("Flip Vertically", arController.ContentFlipV);
            arController.ContentFlipH    = EditorGUILayout.Toggle("Flip Horizontally", arController.ContentFlipH);
        }

        showTwoDTrackingOptions = EditorGUILayout.Foldout(showTwoDTrackingOptions, "2D Tracking Options");
        if (showTwoDTrackingOptions)
        {
            int[]    values = { 1, 2, 3, 4, 5, 6, 7, 8 };
            String[] names  = { "1", "2", "3", "4", "5", "6", "7", "8" };
            arController.TwoDTrackerMaxMarkerCount = EditorGUILayout.IntPopup("Maximum simultaneous trackers:", arController.TwoDTrackerMaxMarkerCount, names, values);
        }

        showSquareTrackingOptions = EditorGUILayout.Foldout(showSquareTrackingOptions, "Square Tracking Options");
        if (showSquareTrackingOptions)
        {
            // Threshold mode selection
            ARController.ARToolKitThresholdMode currentThreshMode = arController.VideoThresholdMode;
            ARController.ARToolKitThresholdMode newThreshMode     = (ARController.ARToolKitThresholdMode)EditorGUILayout.EnumPopup("Mode", currentThreshMode);
            if (newThreshMode != currentThreshMode)
            {
                arController.VideoThresholdMode = newThreshMode;
            }
            EditorGUILayout.HelpBox(ARController.ThresholdModeDescriptions[newThreshMode], MessageType.Info);

            // Show threshold slider only in manual or bracketing modes.
            if (newThreshMode == ARController.ARToolKitThresholdMode.Manual || newThreshMode == ARController.ARToolKitThresholdMode.Bracketing)
            {
                int currentThreshold = arController.VideoThreshold;
                int newThreshold     = EditorGUILayout.IntSlider("Threshold", currentThreshold, 0, 255);
                if (newThreshold != currentThreshold)
                {
                    arController.VideoThreshold = newThreshold;
                }
            }
        }

        showApplicationOptions = EditorGUILayout.Foldout(showApplicationOptions, "Additional Options");
        if (showApplicationOptions)
        {
            arController.AutoStartAR = EditorGUILayout.Toggle("Auto-Start AR.", arController.AutoStartAR);
            if (arController.AutoStartAR)
            {
                EditorGUILayout.HelpBox("ARController.StartAR() will be called during MonoBehavior.Start().", MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("ARController.StartAR() will not be called during MonoBehavior.Start(); you must call it yourself.", MessageType.Warning);
            }

            arController.QuitOnEscOrBack = EditorGUILayout.Toggle("Quit on [Esc].", arController.QuitOnEscOrBack);
            if (arController.QuitOnEscOrBack)
            {
                EditorGUILayout.HelpBox("The [esc] key (Windows, macOS) or the [Back] button (Android) will quit the app.", MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("The [esc] key (Windows, macOS) or the [Back] button (Android) will be ignored.", MessageType.Warning);
            }

            arController.LogLevel = (ARController.AR_LOG_LEVEL)EditorGUILayout.EnumPopup("Native Log Level", arController.LogLevel);
        }
    }
예제 #4
0
//	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();
    }