Esempio n. 1
0
    /// <summary>
    /// Takes a given GameObject to add a new ImageTargetBehaviour to. This new Behaviour is associated with the given ImageTarget
    /// </summary>
    public ImageTargetBehaviour FindOrCreateImageTargetBehaviourForTrackable(ImageTarget trackable, GameObject gameObject, DataSet dataSet)
    {
        DataSetTrackableBehaviour trackableBehaviour = gameObject.GetComponent <DataSetTrackableBehaviour>();

        // add an ImageTargetBehaviour if none is attached yet
        if (trackableBehaviour == null)
        {
            trackableBehaviour = gameObject.AddComponent <ImageTargetBehaviour>();
            ((IEditorTrackableBehaviour)trackableBehaviour).SetInitializedInEditor(true);
        }

        // configure the new ImageTargetBehaviour instance:
        if (!(trackableBehaviour is ImageTargetBehaviour))
        {
            Debug.LogError(
                string.Format("DataSet.CreateTrackable: Trackable of type ImageTarget was created, but behaviour of type {0} was provided!",
                              trackableBehaviour.GetType()));
            return(null);
        }

        IEditorImageTargetBehaviour editorImgTargetBehaviour = (ImageTargetBehaviour)trackableBehaviour;

        if (dataSet != null)
        {
            editorImgTargetBehaviour.SetDataSetPath(dataSet.Path);
        }
        editorImgTargetBehaviour.SetImageTargetType(trackable.ImageTargetType);
        editorImgTargetBehaviour.SetNameForTrackable(trackable.Name);
        editorImgTargetBehaviour.InitializeImageTarget(trackable);

        mTrackableBehaviours[trackable.ID] = trackableBehaviour;

        return(trackableBehaviour as ImageTargetBehaviour);
    }
 public override void ApplyDataSetProperties()
 {
     if (QCARUtilities.GetPrefabType(base.mTarget) != PrefabType.Prefab)
     {
         ConfigData.ImageTargetData   data;
         ImageTargetAbstractBehaviour mTarget    = (ImageTargetAbstractBehaviour)base.mTarget;
         IEditorImageTargetBehaviour  behaviour2 = mTarget;
         if (this.TrackableInDataSet(behaviour2.TrackableName, behaviour2.DataSetName))
         {
             ConfigDataManager.Instance.GetConfigData(behaviour2.DataSetName).GetImageTarget(behaviour2.TrackableName, out data);
         }
         else if (behaviour2.ImageTargetType != ImageTargetType.PREDEFINED)
         {
             data = QCARUtilities.CreateDefaultImageTarget();
         }
         else
         {
             ConfigDataManager.Instance.GetConfigData("--- EMPTY ---").GetImageTarget("--- EMPTY ---", out data);
             behaviour2.SetDataSetPath("--- EMPTY ---");
             behaviour2.SetNameForTrackable("--- EMPTY ---");
         }
         ImageTargetEditor.UpdateScale(mTarget, data.size);
         ImageTargetEditor.UpdateVirtualButtons(mTarget, data.virtualButtons.ToArray());
     }
 }
    public void OnEnable()
    {
        ImageTargetAbstractBehaviour target = (ImageTargetAbstractBehaviour)base.target;

        if (QCARUtilities.GetPrefabType(target) != PrefabType.Prefab)
        {
            if (!SceneManager.Instance.SceneInitialized)
            {
                SceneManager.Instance.InitScene();
            }
            IEditorImageTargetBehaviour it = target;
            if (!it.InitializedInEditor && !EditorApplication.isPlaying)
            {
                ConfigData.ImageTargetData data;
                ConfigDataManager.Instance.GetConfigData("--- EMPTY ---").GetImageTarget("--- EMPTY ---", out data);
                UpdateAspectRatio(target, data.size);
                UpdateScale(target, data.size);
                UpdateMaterial(target);
                it.SetDataSetPath("--- EMPTY ---");
                it.SetNameForTrackable("--- EMPTY ---");
                it.SetInitializedInEditor(true);
            }
            else if (!EditorApplication.isPlaying)
            {
                CheckMesh(it);
            }
            it.SetPreviousScale(target.transform.localScale);
        }
    }
Esempio n. 4
0
    // This method updates the respective Trackable appearance (e.g.
    // aspect ratio and texture) with data set data.
    public override void ApplyDataSetAppearance()
    {
        // Prefabs should not be changed
        if (QCARUtilities.GetPrefabType(mTarget) == PrefabType.Prefab)
        {
            return;
        }

        // Update the aspect ratio, visualization and scale of the target:
        IEditorImageTargetBehaviour itb = (ImageTargetBehaviour)mTarget;

        ConfigData.ImageTargetData itConfig;
        if (TrackableInDataSet(itb.TrackableName, itb.DataSetName))
        {
            ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(itb.DataSetName);
            dataSetData.GetImageTarget(itb.TrackableName, out itConfig);
        }
        else if (itb.ImageTargetType != ImageTargetType.PREDEFINED)
        {
            itConfig = QCARUtilities.CreateDefaultImageTarget();
        }
        else
        {
            // If the Trackable has been removed from the data set we reset it to default.
            ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(QCARUtilities.GlobalVars.DEFAULT_DATA_SET_NAME);
            dataSetData.GetImageTarget(QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME, out itConfig);
            itb.SetDataSetPath(QCARUtilities.GlobalVars.DEFAULT_DATA_SET_NAME);
            itb.SetNameForTrackable(QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME);
        }

        ImageTargetEditor.UpdateAspectRatio(itb, itConfig.size);
        ImageTargetEditor.UpdateMaterial(itb);
    }
Esempio n. 5
0
    internal ImageTargetAbstractBehaviour FindOrCreateImageTargetBehaviourForTrackable(ImageTarget trackable, GameObject gameObject, DataSet dataSet)
    {
        DataSetTrackableBehaviour component = gameObject.GetComponent <DataSetTrackableBehaviour>();

        if (component == null)
        {
            component = BehaviourComponentFactory.Instance.AddImageTargetBehaviour(gameObject);
            ((IEditorTrackableBehaviour)component).SetInitializedInEditor(true);
        }
        if (!(component is ImageTargetAbstractBehaviour))
        {
            Debug.LogError(string.Format("DataSet.CreateTrackable: Trackable of type ImageTarget was created, but behaviour of type {0} was provided!", component.GetType()));
            return(null);
        }
        IEditorImageTargetBehaviour behaviour2 = (ImageTargetAbstractBehaviour)component;

        if (dataSet != null)
        {
            behaviour2.SetDataSetPath(dataSet.Path);
        }
        behaviour2.SetImageTargetType(trackable.ImageTargetType);
        behaviour2.SetNameForTrackable(trackable.Name);
        behaviour2.InitializeImageTarget(trackable);
        this.mTrackableBehaviours[trackable.ID] = component;
        return(component as ImageTargetAbstractBehaviour);
    }
 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();
     }
 }
Esempio n. 7
0
    private ImageTargetAbstractBehaviour CreateImageTargetBehaviour(ImageTarget imageTarget)
    {
        GameObject gameObject = new GameObject();
        ImageTargetAbstractBehaviour behaviour  = BehaviourComponentFactory.Instance.AddImageTargetBehaviour(gameObject);
        IEditorImageTargetBehaviour  behaviour2 = behaviour;

        Debug.Log(string.Concat(new object[] { "Creating Image Target with values: \n ID:           ", imageTarget.ID, "\n Name:         ", imageTarget.Name, "\n Path:         ", behaviour2.DataSetPath, "\n Size:         ", imageTarget.GetSize().x, "x", imageTarget.GetSize().y }));
        behaviour2.SetNameForTrackable(imageTarget.Name);
        behaviour2.SetDataSetPath(behaviour2.DataSetPath);
        Vector2 size = imageTarget.GetSize();
        float   x    = Mathf.Max(size.x, size.y);

        behaviour2.transform.localScale = new Vector3(x, x, x);
        behaviour2.CorrectScale();
        behaviour2.SetAspectRatio(size.y / size.x);
        behaviour2.InitializeImageTarget(imageTarget);
        return(behaviour);
    }
    // Initializes the Image Target when it is drag-dropped into the scene.
    public void OnEnable()
    {
        ImageTargetBehaviour itb = (ImageTargetBehaviour)target;

        // We don't want to initialize if this is a prefab.
        if (QCARUtilities.GetPrefabType(itb) == PrefabType.Prefab)
        {
            return;
        }

        // Make sure the scene and config.xml file are synchronized.
        if (!SceneManager.Instance.SceneInitialized)
        {
            SceneManager.Instance.InitScene();
        }

        IEditorImageTargetBehaviour editorItb = itb;

        // Only setup target if it has not been set up previously.
        if (!editorItb.InitializedInEditor && !EditorApplication.isPlaying)
        {
            ConfigData.ImageTargetData itConfig;

            ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(QCARUtilities.GlobalVars.DEFAULT_DATA_SET_NAME);
            dataSetData.GetImageTarget(QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME, out itConfig);

            UpdateAspectRatio(itb, itConfig.size);
            UpdateScale(itb, itConfig.size);
            UpdateMaterial(itb);
            editorItb.SetDataSetPath(QCARUtilities.GlobalVars.DEFAULT_DATA_SET_NAME);
            editorItb.SetNameForTrackable(QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME);
            editorItb.SetInitializedInEditor(true);
        }
        else if (!EditorApplication.isPlaying)
        {
            CheckMesh(editorItb);
        }

        // Cache the current scale of the target:
        editorItb.SetPreviousScale(itb.transform.localScale);
    }
Esempio n. 9
0
    private ImageTargetBehaviour CreateImageTargetBehaviour(ImageTarget imageTarget)
    {
        GameObject           imageTargetObject = new GameObject();
        ImageTargetBehaviour newITB            =
            imageTargetObject.AddComponent <ImageTargetBehaviour>();

        IEditorImageTargetBehaviour newEditorITB = newITB;

        Debug.Log("Creating Image Target with values: " +
                  "\n ID:           " + imageTarget.ID +
                  "\n Name:         " + imageTarget.Name +
                  "\n Path:         " + newEditorITB.DataSetPath +
                  "\n Size:         " + imageTarget.GetSize().x + "x" + imageTarget.GetSize().y);

        // Set Image Target attributes.
        newEditorITB.SetNameForTrackable(imageTarget.Name);
        newEditorITB.SetDataSetPath(newEditorITB.DataSetPath);
        newEditorITB.transform.localScale = new Vector3(imageTarget.GetSize().x, 1.0f, imageTarget.GetSize().y);
        newEditorITB.CorrectScale();
        newEditorITB.SetAspectRatio(imageTarget.GetSize()[1] / imageTarget.GetSize()[0]);
        newEditorITB.InitializeImageTarget(imageTarget);

        return(newITB);
    }
 public override void ApplyDataSetAppearance()
 {
     if (QCARUtilities.GetPrefabType(base.mTarget) != PrefabType.Prefab)
     {
         ConfigData.ImageTargetData  data;
         IEditorImageTargetBehaviour mTarget = (ImageTargetAbstractBehaviour)base.mTarget;
         if (this.TrackableInDataSet(mTarget.TrackableName, mTarget.DataSetName))
         {
             ConfigDataManager.Instance.GetConfigData(mTarget.DataSetName).GetImageTarget(mTarget.TrackableName, out data);
         }
         else if (mTarget.ImageTargetType != ImageTargetType.PREDEFINED)
         {
             data = QCARUtilities.CreateDefaultImageTarget();
         }
         else
         {
             ConfigDataManager.Instance.GetConfigData("--- EMPTY ---").GetImageTarget("--- EMPTY ---", out data);
             mTarget.SetDataSetPath("--- EMPTY ---");
             mTarget.SetNameForTrackable("--- EMPTY ---");
         }
         ImageTargetEditor.UpdateAspectRatio(mTarget, data.size);
         ImageTargetEditor.UpdateMaterial(mTarget);
     }
 }
Esempio n. 11
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();
            }
        }
    }
Esempio n. 12
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();
            }
        }
    }