private void DrawPredefinedTargetInsprectorUI(IEditorImageTargetBehaviour itb, bool typeChanged)
 {
     if (typeChanged)
     {
         UpdateMaterial(itb);
     }
     if (ConfigDataManager.Instance.NumConfigDataObjects > 1)
     {
         string[] configDataNames = new string[ConfigDataManager.Instance.NumConfigDataObjects];
         ConfigDataManager.Instance.GetConfigDataNames(configDataNames);
         int indexFromString = QCARUtilities.GetIndexFromString(itb.DataSetName, configDataNames);
         if (indexFromString < 0)
         {
             indexFromString = 0;
         }
         int        index       = EditorGUILayout.Popup("Data Set", indexFromString, configDataNames, new GUILayoutOption[0]);
         string     dataSetName = configDataNames[index];
         ConfigData configData  = ConfigDataManager.Instance.GetConfigData(dataSetName);
         string[]   arrayToFill = new string[configData.NumImageTargets];
         configData.CopyImageTargetNames(arrayToFill, 0);
         int selectedIndex = QCARUtilities.GetIndexFromString(itb.TrackableName, arrayToFill);
         if (selectedIndex < 0)
         {
             selectedIndex = 0;
         }
         if (index != indexFromString)
         {
             selectedIndex = 0;
         }
         int   num5  = EditorGUILayout.Popup("Image Target", selectedIndex, arrayToFill, new GUILayoutOption[0]);
         float width = EditorGUILayout.FloatField("Width", itb.GetSize().x, new GUILayoutOption[0]);
         if (width != itb.GetSize().x)
         {
             itb.SetWidth(width);
         }
         float height = EditorGUILayout.FloatField("Height ", itb.GetSize().y, new GUILayoutOption[0]);
         if (height != itb.GetSize().y)
         {
             itb.SetHeight(height);
         }
         itb.SetExtendedTracking(EditorGUILayout.Toggle("Extended tracking", itb.ExtendedTracking, new GUILayoutOption[0]));
         itb.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", itb.PreserveChildSize, new GUILayoutOption[0]));
         if ((arrayToFill.Length > 0) && (((index != indexFromString) || (num5 != selectedIndex)) || typeChanged))
         {
             ConfigData.ImageTargetData data2;
             itb.SetDataSetPath("QCAR/" + configDataNames[index] + ".xml");
             string name = arrayToFill[num5];
             itb.SetNameForTrackable(name);
             configData.GetImageTarget(itb.TrackableName, out data2);
             UpdateAspectRatio(itb, data2.size);
             UpdateScale(itb, data2.size);
             UpdateMaterial(itb);
         }
     }
     else if (GUILayout.Button("No targets defined. Press here for target creation!", new GUILayoutOption[0]))
     {
         SceneManager.Instance.GoToTargetManagerPage();
     }
 }
Пример #2
0
    public string[] GetImageTargetNames(string dataSetName)
    {
        ConfigData configData = ConfigDataManager.Instance.GetConfigData(dataSetName);

        string[] arrayToFill = new string[configData.NumImageTargets + 1];
        arrayToFill[0] = "--- EMPTY ---";
        configData.CopyImageTargetNames(arrayToFill, 1);
        return(arrayToFill);
    }
Пример #3
0
    public string[] GetImageTargetNames(string dataSetName)
    {
        ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(dataSetName);

        string[] itNames = new string[dataSetData.NumImageTargets + 1];
        itNames[0] = QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME;
        dataSetData.CopyImageTargetNames(itNames, 1);
        return(itNames);
    }
Пример #4
0
 private static string GetLatestITName(ConfigData backlog)
 {
     if (backlog == null)
     {
         return(null);
     }
     string[] arrayToFill = new string[backlog.NumImageTargets];
     try
     {
         backlog.CopyImageTargetNames(arrayToFill, 0);
     }
     catch
     {
         return(null);
     }
     return(arrayToFill[backlog.NumImageTargets - 1]);
 }
Пример #5
0
    // Lets the user choose a Image Target from a drop down list. Image Target
    // must be defined in the "config.xml" file.
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        ImageTargetBehaviour itb = (ImageTargetBehaviour)target;

        if (QCARUtilities.GetPrefabType(itb) == PrefabType.Prefab)
        {
            GUILayout.Label("You can't choose a target for a prefab.");
        }
        else if (ConfigDataManager.Instance.NumConfigDataObjects > 1) //< "> 1" because we ignore the default dataset.
        {
            // Draw list for choosing a data set.
            string[] dataSetList = new string[ConfigDataManager.Instance.NumConfigDataObjects];
            ConfigDataManager.Instance.GetConfigDataNames(dataSetList);
            int currentDataSetIndex = QCARUtilities.GetIndexFromString(itb.DataSetName, dataSetList);

            // If name is not in array we automatically choose default name;
            if (currentDataSetIndex < 0)
            {
                currentDataSetIndex = 0;
            }

            int newDataSetIndex = EditorGUILayout.Popup("Data Set",
                                                        currentDataSetIndex,
                                                        dataSetList);

            string chosenDataSet = dataSetList[newDataSetIndex];

            ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(chosenDataSet);

            // Draw list for choosing a Trackable.
            string[] namesList = new string[dataSetData.NumImageTargets];
            dataSetData.CopyImageTargetNames(namesList, 0);
            int currentTrackableIndex =
                QCARUtilities.GetIndexFromString(itb.TrackableName, namesList);

            // If name is not in array we automatically choose default name;
            if (currentTrackableIndex < 0)
            {
                currentTrackableIndex = 0;
            }

            // Reset name index if a new data set has been chosen.
            if (newDataSetIndex != currentDataSetIndex)
            {
                currentTrackableIndex = 0;
            }

            int newTrackableIndex = EditorGUILayout.Popup("Image Target",
                                                          currentTrackableIndex,
                                                          namesList);

            // Draw check box to de-/activate "preserve child size" mode.
            itb.mPreserveChildSize =
                EditorGUILayout.Toggle("Preserve child size",
                                       itb.mPreserveChildSize);

            if (namesList.Length > 0)
            {
                if (newDataSetIndex != currentDataSetIndex || newTrackableIndex != currentTrackableIndex)
                {
                    itb.DataSetPath =
                        "QCAR/" + dataSetList[newDataSetIndex] + ".xml";

                    itb.DataSetStorageType =
                        DataSet.StorageType.STORAGE_APPRESOURCE;

                    itb.TrackableName = namesList[newTrackableIndex];

                    ConfigData.ImageTarget itConfig;

                    dataSetData.GetImageTarget(itb.TrackableName, out itConfig);

                    // Update the aspect ratio and mesh used for visualisation:
                    UpdateAspectRatio(itb, itConfig.size);

                    // Update the material:
                    UpdateMaterial(itb);
                }
            }
        }
        else
        {
            if (GUILayout.Button("No targets defined. Press here for target " +
                                 "creation!"))
            {
                SceneManager.Instance.GoToARPage();
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(itb);

            SceneManager.Instance.SceneUpdated();
        }
    }
Пример #6
0
    private void DrawPredefinedTargetInsprectorUI(IEditorImageTargetBehaviour itb, bool typeChanged)
    {
        if (typeChanged)
        {
            UpdateMaterial(itb);
        }

        if (ConfigDataManager.Instance.NumConfigDataObjects > 1) //< "> 1" because we ignore the default dataset.
        {
            // Draw list for choosing a data set.
            string[] dataSetList = new string[ConfigDataManager.Instance.NumConfigDataObjects];
            ConfigDataManager.Instance.GetConfigDataNames(dataSetList);
            int currentDataSetIndex = QCARUtilities.GetIndexFromString(itb.DataSetName, dataSetList);

            // If name is not in array we automatically choose default name;
            if (currentDataSetIndex < 0)
            {
                currentDataSetIndex = 0;
            }

            int newDataSetIndex = EditorGUILayout.Popup("Data Set",
                                                        currentDataSetIndex,
                                                        dataSetList);

            string chosenDataSet = dataSetList[newDataSetIndex];

            ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(chosenDataSet);

            // Draw list for choosing a Trackable
            int      targetCount = dataSetData.NumImageTargets;
            string[] namesList   = new string[targetCount];
            dataSetData.CopyImageTargetNames(namesList, 0);

            // get the current index
            int currentTrackableIndex = QCARUtilities.GetIndexFromString(itb.TrackableName, namesList);

            // If name is not in array we automatically choose default name;
            if (currentTrackableIndex < 0)
            {
                currentTrackableIndex = 0;
            }

            // Reset name index if a new data set has been chosen.
            if (newDataSetIndex != currentDataSetIndex)
            {
                currentTrackableIndex = 0;
            }

            int newTrackableIndex = EditorGUILayout.Popup("Image Target",
                                                          currentTrackableIndex,
                                                          namesList);

            // Draw check box to de-/activate "preserve child size" mode.
            itb.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", itb.PreserveChildSize));

            if (namesList.Length > 0)
            {
                if (newDataSetIndex != currentDataSetIndex || newTrackableIndex != currentTrackableIndex || typeChanged)
                {
                    itb.SetDataSetPath("QCAR/" + dataSetList[newDataSetIndex] + ".xml");

                    string selectedString = namesList[newTrackableIndex];

                    ConfigData.ImageTargetData itConfig;
                    itb.SetNameForTrackable(selectedString);
                    dataSetData.GetImageTarget(itb.TrackableName, out itConfig);

                    // Update the aspect ratio and mesh used for visualisation:
                    UpdateAspectRatio(itb, itConfig.size);

                    // Update the material:
                    UpdateMaterial(itb);
                }
            }
        }
        else
        {
            if (GUILayout.Button("No targets defined. Press here for target " +
                                 "creation!"))
            {
                SceneManager.Instance.GoToARPage();
            }
        }
    }
Пример #7
0
    // Returns the name of the Image Target that has been parsed the latest.
    // Returns null if no Image Target has been parsed yet.
    private static string GetLatestITName(ConfigData backlog)
    {
        if (backlog == null)
            return null;

        string[] itNames = new string[backlog.NumImageTargets];
        try
        {
            backlog.CopyImageTargetNames(itNames, 0);
        }
        catch
        {
            return null;
        }

        return itNames[backlog.NumImageTargets - 1];
    }
Пример #8
0
    // This method reads a config.xml file at the given path and fills the
    // ConfigData object with the data.
    public bool structToFile(string configXMLPath, ConfigData configData)
    {
        // If there are no trackables in the data set we don't write a config file.
        if (configData.NumTrackables <= 0)
            return false;

        XmlWriterSettings configWriterSettings = new XmlWriterSettings();
        configWriterSettings.Indent = true;
        using (XmlWriter configWriter =
            XmlWriter.Create(configXMLPath, configWriterSettings))
        {
            configWriter.WriteStartDocument();

            configWriter.WriteStartElement("QCARConfig");
            configWriter.WriteAttributeString("xmlns", "xsi", null,
                "http://www.w3.org/2001/XMLSchema-instance");
            configWriter.WriteAttributeString("xsi",
                "noNamespaceSchemaLocation", null, "qcar_config.xsd");

            configWriter.WriteStartElement("Tracking");

            // Writing Image Target elements into config.xml file.
            string[] imageTargetNames = new string[configData.NumImageTargets];
            configData.CopyImageTargetNames(imageTargetNames, 0);
            for (int i = 0; i < imageTargetNames.Length; ++i)
            {
                ConfigData.ImageTarget it;

                configData.GetImageTarget(imageTargetNames[i], out it);

                configWriter.WriteStartElement("ImageTarget");
                string imageTargetSize = it.size.x.ToString() + " " +
                                         it.size.y.ToString();
                configWriter.WriteAttributeString("size", imageTargetSize);
                configWriter.WriteAttributeString("name", imageTargetNames[i]);

                // Writing Virtual Button elements into config.xml file per
                // Image Target.
                List<ConfigData.VirtualButton> vbs = it.virtualButtons;
                for (int j = 0; j < vbs.Count; j++)
                {
                    configWriter.WriteStartElement("VirtualButton");
                    configWriter.WriteAttributeString("name", vbs[j].name);
                    string virtualButtonRectangle =
                        vbs[j].rectangle.x.ToString() + " " +
                        vbs[j].rectangle.y.ToString() + " " +
                        vbs[j].rectangle.z.ToString() + " " +
                        vbs[j].rectangle.w.ToString();
                    configWriter.WriteAttributeString("rectangle",
                        virtualButtonRectangle);
                    if (vbs[j].enabled)
                        configWriter.WriteAttributeString("enabled",
                                                          "true");
                    else
                        configWriter.WriteAttributeString("enabled",
                                                          "false");
                    if (vbs[j].sensitivity ==
                        VirtualButtonBehaviour.Sensitivity.LOW)
                        configWriter.WriteAttributeString("sensitivity",
                                                          "low");
                    else if (vbs[j].sensitivity ==
                        VirtualButtonBehaviour.Sensitivity.MEDIUM)
                        configWriter.WriteAttributeString("sensitivity",
                                                          "medium");
                    else if (vbs[j].sensitivity ==
                        VirtualButtonBehaviour.Sensitivity.HIGH)
                        configWriter.WriteAttributeString("sensitivity",
                                                          "high");
                    configWriter.WriteEndElement(); // VirtualButton
                }
                configWriter.WriteEndElement(); // ImageTarget
            }

            // Writing Multi Target elements into config.xml file
            string[] multiTargetNames = new string[configData.NumMultiTargets];
            configData.CopyMultiTargetNames(multiTargetNames, 0);
            for (int i = 0; i < multiTargetNames.Length; i++)
            {
                ConfigData.MultiTarget mt;

                configData.GetMultiTarget(multiTargetNames[i], out mt);

                configWriter.WriteStartElement("MultiTarget");
                configWriter.WriteAttributeString("name", multiTargetNames[i]);

                // Writing Multi Target Part elements into config.xml file
                List<ConfigData.MultiTargetPart> prts = mt.parts;
                for (int j = 0; j < prts.Count; j++)
                {
                    configWriter.WriteStartElement("Part");
                    configWriter.WriteAttributeString("name", prts[j].name);
                    string multiTargetTranslation =
                        prts[j].translation.x.ToString() + " " +
                        prts[j].translation.z.ToString() + " " +
                        prts[j].translation.y.ToString();
                    configWriter.WriteAttributeString("translation",
                                                      multiTargetTranslation);
                    float rotationAngle;
                    Vector3 rotationAxis;
                    prts[j].rotation.ToAngleAxis(out rotationAngle,
                                                 out rotationAxis);
                    string multiTargetRotation =
                        "AD: " +
                        (-rotationAxis.x).ToString() + " " +
                        (-rotationAxis.z).ToString() + " " +
                        rotationAxis.y.ToString() + " " +
                        rotationAngle.ToString();
                    configWriter.WriteAttributeString("rotation",
                        multiTargetRotation);
                    configWriter.WriteEndElement(); // Part
                }

                configWriter.WriteEndElement(); // MultiTarget
            }

            configWriter.WriteEndElement(); // Tracking

            configWriter.WriteEndElement(); // QCARConfig

            configWriter.WriteEndDocument();
        }

        return true;
    }
Пример #9
0
    // This method takes a configData object and creates a config.xml file at
    // the given path out of it.
    public bool structToFile(string configXMLPath, ConfigData configData)
    {
        // If there are no trackables in the data set we don't write a config file.
        if ((configData == null) || (configData.NumTrackables <= 0))
        {
            return(false);
        }

        XmlWriterSettings configWriterSettings = new XmlWriterSettings();

        configWriterSettings.Indent = true;
        using (XmlWriter configWriter =
                   XmlWriter.Create(configXMLPath, configWriterSettings))
        {
            configWriter.WriteStartDocument();

            configWriter.WriteStartElement("QCARConfig");
            configWriter.WriteAttributeString("xmlns", "xsi", null,
                                              "http://www.w3.org/2001/XMLSchema-instance");
            configWriter.WriteAttributeString("xsi",
                                              "noNamespaceSchemaLocation", null, "qcar_config.xsd");

            configWriter.WriteStartElement("Tracking");

            // Writing Image Target elements into config.xml file.
            string[] imageTargetNames = new string[configData.NumImageTargets];
            configData.CopyImageTargetNames(imageTargetNames, 0);
            for (int i = 0; i < imageTargetNames.Length; ++i)
            {
                ConfigData.ImageTargetData it;

                configData.GetImageTarget(imageTargetNames[i], out it);

                configWriter.WriteStartElement("ImageTarget");
                string imageTargetSize = it.size.x.ToString() + " " +
                                         it.size.y.ToString();
                configWriter.WriteAttributeString("size", imageTargetSize);
                configWriter.WriteAttributeString("name", imageTargetNames[i]);

                // Writing Virtual Button elements into config.xml file per
                // Image Target.
                List <ConfigData.VirtualButtonData> vbs = it.virtualButtons;
                for (int j = 0; j < vbs.Count; j++)
                {
                    configWriter.WriteStartElement("VirtualButton");
                    configWriter.WriteAttributeString("name", vbs[j].name);
                    string virtualButtonRectangle =
                        vbs[j].rectangle.x.ToString() + " " +
                        vbs[j].rectangle.y.ToString() + " " +
                        vbs[j].rectangle.z.ToString() + " " +
                        vbs[j].rectangle.w.ToString();
                    configWriter.WriteAttributeString("rectangle",
                                                      virtualButtonRectangle);
                    if (vbs[j].enabled)
                    {
                        configWriter.WriteAttributeString("enabled",
                                                          "true");
                    }
                    else
                    {
                        configWriter.WriteAttributeString("enabled",
                                                          "false");
                    }
                    if (vbs[j].sensitivity ==
                        VirtualButton.Sensitivity.LOW)
                    {
                        configWriter.WriteAttributeString("sensitivity",
                                                          "low");
                    }
                    else if (vbs[j].sensitivity ==
                             VirtualButton.Sensitivity.MEDIUM)
                    {
                        configWriter.WriteAttributeString("sensitivity",
                                                          "medium");
                    }
                    else if (vbs[j].sensitivity ==
                             VirtualButton.Sensitivity.HIGH)
                    {
                        configWriter.WriteAttributeString("sensitivity",
                                                          "high");
                    }
                    configWriter.WriteEndElement(); // VirtualButton
                }
                configWriter.WriteEndElement();     // ImageTarget
            }

            // Writing Multi Target elements into config.xml file
            string[] multiTargetNames = new string[configData.NumMultiTargets];
            configData.CopyMultiTargetNames(multiTargetNames, 0);
            for (int i = 0; i < multiTargetNames.Length; i++)
            {
                ConfigData.MultiTargetData mt;

                configData.GetMultiTarget(multiTargetNames[i], out mt);

                configWriter.WriteStartElement("MultiTarget");
                configWriter.WriteAttributeString("name", multiTargetNames[i]);

                // Writing Multi Target Part elements into config.xml file
                List <ConfigData.MultiTargetPartData> prts = mt.parts;
                for (int j = 0; j < prts.Count; j++)
                {
                    configWriter.WriteStartElement("Part");
                    configWriter.WriteAttributeString("name", prts[j].name);
                    string multiTargetTranslation =
                        prts[j].translation.x.ToString() + " " +
                        prts[j].translation.z.ToString() + " " +
                        prts[j].translation.y.ToString();
                    configWriter.WriteAttributeString("translation",
                                                      multiTargetTranslation);
                    float   rotationAngle;
                    Vector3 rotationAxis;
                    prts[j].rotation.ToAngleAxis(out rotationAngle,
                                                 out rotationAxis);
                    string multiTargetRotation =
                        "AD: " +
                        (-rotationAxis.x).ToString() + " " +
                        (-rotationAxis.z).ToString() + " " +
                        rotationAxis.y.ToString() + " " +
                        rotationAngle.ToString();
                    configWriter.WriteAttributeString("rotation",
                                                      multiTargetRotation);
                    configWriter.WriteEndElement(); // Part
                }

                configWriter.WriteEndElement(); // MultiTarget
            }

            configWriter.WriteEndElement(); // Tracking

            configWriter.WriteEndElement(); // QCARConfig

            configWriter.WriteEndDocument();
        }

        return(true);
    }
Пример #10
0
    public bool structToFile(string configXMLPath, ConfigData configData)
    {
        if ((configData == null) || (configData.NumTrackables <= 0))
        {
            return(false);
        }
        XmlWriterSettings settings = new XmlWriterSettings {
            Indent = true
        };

        using (XmlWriter writer = XmlWriter.Create(configXMLPath, settings))
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("QCARConfig");
            writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
            writer.WriteAttributeString("xsi", "noNamespaceSchemaLocation", null, "qcar_config.xsd");
            writer.WriteStartElement("Tracking");
            string[] arrayToFill = new string[configData.NumImageTargets];
            configData.CopyImageTargetNames(arrayToFill, 0);
            for (int i = 0; i < arrayToFill.Length; i++)
            {
                ConfigData.ImageTargetData data;
                configData.GetImageTarget(arrayToFill[i], out data);
                writer.WriteStartElement("ImageTarget");
                string str = data.size.x.ToString() + " " + data.size.y.ToString();
                writer.WriteAttributeString("size", str);
                writer.WriteAttributeString("name", arrayToFill[i]);
                List <ConfigData.VirtualButtonData> virtualButtons = data.virtualButtons;
                for (int k = 0; k < virtualButtons.Count; k++)
                {
                    writer.WriteStartElement("VirtualButton");
                    writer.WriteAttributeString("name", virtualButtons[k].name);
                    string str2 = virtualButtons[k].rectangle.x.ToString() + " " + virtualButtons[k].rectangle.y.ToString() + " " + virtualButtons[k].rectangle.z.ToString() + " " + virtualButtons[k].rectangle.w.ToString();
                    writer.WriteAttributeString("rectangle", str2);
                    if (virtualButtons[k].enabled)
                    {
                        writer.WriteAttributeString("enabled", "true");
                    }
                    else
                    {
                        writer.WriteAttributeString("enabled", "false");
                    }
                    if (virtualButtons[k].sensitivity == VirtualButton.Sensitivity.LOW)
                    {
                        writer.WriteAttributeString("sensitivity", "low");
                    }
                    else if (virtualButtons[k].sensitivity == VirtualButton.Sensitivity.MEDIUM)
                    {
                        writer.WriteAttributeString("sensitivity", "medium");
                    }
                    else if (virtualButtons[k].sensitivity == VirtualButton.Sensitivity.HIGH)
                    {
                        writer.WriteAttributeString("sensitivity", "high");
                    }
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            string[] strArray2 = new string[configData.NumMultiTargets];
            configData.CopyMultiTargetNames(strArray2, 0);
            for (int j = 0; j < strArray2.Length; j++)
            {
                ConfigData.MultiTargetData data2;
                configData.GetMultiTarget(strArray2[j], out data2);
                writer.WriteStartElement("MultiTarget");
                writer.WriteAttributeString("name", strArray2[j]);
                List <ConfigData.MultiTargetPartData> parts = data2.parts;
                for (int m = 0; m < parts.Count; m++)
                {
                    float   num5;
                    Vector3 vector;
                    writer.WriteStartElement("Part");
                    writer.WriteAttributeString("name", parts[m].name);
                    string str3 = parts[m].translation.x.ToString() + " " + parts[m].translation.z.ToString() + " " + parts[m].translation.y.ToString();
                    writer.WriteAttributeString("translation", str3);
                    parts[m].rotation.ToAngleAxis(out num5, out vector);
                    string[] strArray5 = new string[] { "AD: ", (-vector.x).ToString(), " ", (-vector.z).ToString(), " ", vector.y.ToString(), " ", num5.ToString() };
                    string   str4      = string.Concat(strArray5);
                    writer.WriteAttributeString("rotation", str4);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
        return(true);
    }