Example #1
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 editable
        if (QCARUtilities.GetPrefabType(mTarget) == PrefabType.Prefab)
        {
            return;
        }

        IEditorCylinderTargetBehaviour ctb = (CylinderTargetBehaviour)mTarget;

        ConfigData.CylinderTargetData ctConfig;
        if (TrackableInDataSet(ctb.TrackableName, ctb.DataSetName))
        {
            ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(ctb.DataSetName);
            dataSetData.GetCylinderTarget(ctb.TrackableName, out ctConfig);
        }
        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.GetCylinderTarget(QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME, out ctConfig);
            ctb.SetDataSetPath(QCARUtilities.GlobalVars.DEFAULT_DATA_SET_NAME);
            ctb.SetNameForTrackable(QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME);
        }

        //update geometry based on properties from dataset
        CylinderTargetEditor.UpdateAspectRatio(ctb, ctConfig);
    }
    private CylinderTargetBehaviour CreateCylinderTargetBehaviour(CylinderTarget cylinderTarget)
    {
        GameObject cylinderTargetObject = new GameObject();
        CylinderTargetBehaviour newCTB  =
            cylinderTargetObject.AddComponent <CylinderTargetBehaviour>();

        IEditorCylinderTargetBehaviour newEditorCTB = newCTB;

        Debug.Log("Creating Cylinder Target with values: " +
                  "\n ID:           " + cylinderTarget.ID +
                  "\n Name:         " + cylinderTarget.Name +
                  "\n Path:         " + newEditorCTB.DataSetPath +
                  "\n Side Length:  " + cylinderTarget.GetSideLength() +
                  "\n Top Diameter: " + cylinderTarget.GetTopDiameter() +
                  "\n Bottom Diam.: " + cylinderTarget.GetBottomDiameter());


        // Set Cylinder Target attributes.
        newEditorCTB.SetNameForTrackable(cylinderTarget.Name);
        newEditorCTB.SetDataSetPath(newEditorCTB.DataSetPath);
        var sidelength = cylinderTarget.GetSideLength();

        newEditorCTB.transform.localScale = new Vector3(sidelength, sidelength, sidelength);
        newEditorCTB.CorrectScale();
        newEditorCTB.SetAspectRatio(cylinderTarget.GetTopDiameter() / sidelength,
                                    cylinderTarget.GetBottomDiameter() / sidelength);
        newEditorCTB.InitializeCylinderTarget(cylinderTarget);
        return(newCTB);
    }
Example #3
0
    public void OnEnable()
    {
        CylinderTargetAbstractBehaviour target = (CylinderTargetAbstractBehaviour)base.target;

        if (QCARUtilities.GetPrefabType(target) != PrefabType.Prefab)
        {
            if (!SceneManager.Instance.SceneInitialized)
            {
                SceneManager.Instance.InitScene();
            }
            IEditorCylinderTargetBehaviour ct = target;
            if (!ct.InitializedInEditor && !EditorApplication.isPlaying)
            {
                ConfigData.CylinderTargetData data;
                ConfigDataManager.Instance.GetConfigData("--- EMPTY ---").GetCylinderTarget("--- EMPTY ---", out data);
                ct.SetDataSetPath("--- EMPTY ---");
                ct.SetNameForTrackable("--- EMPTY ---");
                UpdateAspectRatio(ct, data);
                UpdateScale(ct, data.sideLength);
                ct.SetInitializedInEditor(true);
            }
            else if (!EditorApplication.isPlaying)
            {
                CheckMesh(ct);
            }
            ct.SetPreviousScale(target.transform.localScale);
        }
    }
Example #4
0
    private CylinderTargetAbstractBehaviour CreateCylinderTargetBehaviour(CylinderTarget cylinderTarget)
    {
        GameObject gameObject = new GameObject();
        CylinderTargetAbstractBehaviour behaviour  = BehaviourComponentFactory.Instance.AddCylinderTargetBehaviour(gameObject);
        IEditorCylinderTargetBehaviour  behaviour2 = behaviour;

        Debug.Log(string.Concat(new object[] { "Creating Cylinder Target with values: \n ID:           ", cylinderTarget.ID, "\n Name:         ", cylinderTarget.Name, "\n Path:         ", behaviour2.DataSetPath, "\n Side Length:  ", cylinderTarget.GetSideLength(), "\n Top Diameter: ", cylinderTarget.GetTopDiameter(), "\n Bottom Diam.: ", cylinderTarget.GetBottomDiameter() }));
        behaviour2.SetNameForTrackable(cylinderTarget.Name);
        behaviour2.SetDataSetPath(behaviour2.DataSetPath);
        float sideLength = cylinderTarget.GetSideLength();

        behaviour2.transform.localScale = new Vector3(sideLength, sideLength, sideLength);
        behaviour2.CorrectScale();
        behaviour2.SetAspectRatio(cylinderTarget.GetTopDiameter() / sideLength, cylinderTarget.GetBottomDiameter() / sideLength);
        behaviour2.InitializeCylinderTarget(cylinderTarget);
        return(behaviour);
    }
Example #5
0
 public override void ApplyDataSetProperties()
 {
     if (QCARUtilities.GetPrefabType(base.mTarget) != PrefabType.Prefab)
     {
         ConfigData.CylinderTargetData  data;
         IEditorCylinderTargetBehaviour mTarget = (CylinderTargetAbstractBehaviour)base.mTarget;
         if (this.TrackableInDataSet(mTarget.TrackableName, mTarget.DataSetName))
         {
             ConfigDataManager.Instance.GetConfigData(mTarget.DataSetName).GetCylinderTarget(mTarget.TrackableName, out data);
         }
         else
         {
             ConfigDataManager.Instance.GetConfigData("--- EMPTY ---").GetCylinderTarget("--- EMPTY ---", out data);
             mTarget.SetDataSetPath("--- EMPTY ---");
             mTarget.SetNameForTrackable("--- EMPTY ---");
         }
         CylinderTargetEditor.UpdateScale(mTarget, data.sideLength);
     }
 }
    // Initializes the Cylinder Target when it is drag-dropped into the scene.
    public void OnEnable()
    {
        var ctb = (CylinderTargetBehaviour)target;

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

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

        IEditorCylinderTargetBehaviour editorCtb = ctb;

        // Only setup target if it has not been set up previously.
        if (!editorCtb.InitializedInEditor && !EditorApplication.isPlaying)
        {
            ConfigData.CylinderTargetData ctConfig;

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

            editorCtb.SetDataSetPath(QCARUtilities.GlobalVars.DEFAULT_DATA_SET_NAME);
            editorCtb.SetNameForTrackable(QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME);

            UpdateAspectRatio(editorCtb, ctConfig);
            UpdateScale(editorCtb, ctConfig.sideLength);
            editorCtb.SetInitializedInEditor(true);
        }
        else if (!EditorApplication.isPlaying)
        {
            CheckMesh(editorCtb);
        }

        // Cache the current scale of the target:
        editorCtb.SetPreviousScale(ctb.transform.localScale);
    }
    // Lets the user choose a Cylinder Target from a drop down list. Cylinder Target
    // must be defined in the "config.xml" file.
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        DrawDefaultInspector();

        CylinderTargetBehaviour        ctb       = (CylinderTargetBehaviour)target;
        IEditorCylinderTargetBehaviour editorCtb = ctb;

        if (QCARUtilities.GetPrefabType(ctb) ==
            PrefabType.Prefab)
        {
            GUILayout.Label("You can't choose a target for a prefab.");
        }
        else if (ConfigDataManager.Instance.NumConfigDataObjects > 1)
        {
            // Draw list for choosing a data set.
            string[] dataSetList = new string[ConfigDataManager.Instance.NumConfigDataObjects];
            ConfigDataManager.Instance.GetConfigDataNames(dataSetList);
            int currentDataSetIndex =
                QCARUtilities.GetIndexFromString(editorCtb.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.NumCylinderTargets];
            dataSetData.CopyCylinderTargetNames(namesList, 0);
            int currentTrackableIndex =
                QCARUtilities.GetIndexFromString(editorCtb.TrackableName, namesList);

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

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

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

                    editorCtb.SetNameForTrackable(namesList[newTrackableIndex]);


                    ConfigData.CylinderTargetData ctConfig;
                    dataSetData.GetCylinderTarget(ctb.TrackableName, out ctConfig);

                    //geometry has to be updated when a new target has been selected
                    UpdateAspectRatio(editorCtb, ctConfig);
                    UpdateScale(editorCtb, ctConfig.sideLength);
                }
            }

            //Expose editors for setting sideLength and diameterss
            //these values are not really stored, but instead the scale-factor is updated
            var sideLength = EditorGUILayout.FloatField("Side Length", ctb.SideLength);
            if (sideLength != ctb.SideLength)
            {
                ctb.SetSideLength(sideLength);
            }

            float topDiameter = EditorGUILayout.FloatField("Top Diameter ", ctb.TopDiameter);
            if (topDiameter != ctb.TopDiameter)
            {
                ctb.SetTopDiameter(topDiameter);
            }

            float bottomDiameter = EditorGUILayout.FloatField("Bottom Diameter", ctb.BottomDiameter);
            if (bottomDiameter != ctb.BottomDiameter)
            {
                ctb.SetBottomDiameter(bottomDiameter);
            }

            // Draw check box to de-/activate "preserve child size" mode.
            editorCtb.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", editorCtb.PreserveChildSize));
        }
        else
        {
            if (GUILayout.Button("No targets defined. Press here for target " +
                                 "creation!"))
            {
                SceneManager.Instance.GoToTargetManagerPage();
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(ctb);
            SceneManager.Instance.SceneUpdated();
        }
    }
Example #8
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();
        base.DrawDefaultInspector();
        CylinderTargetAbstractBehaviour target = (CylinderTargetAbstractBehaviour)base.target;
        IEditorCylinderTargetBehaviour  ct     = target;

        if (QCARUtilities.GetPrefabType(target) == PrefabType.Prefab)
        {
            GUILayout.Label("You can't choose a target for a prefab.", new GUILayoutOption[0]);
        }
        else if (ConfigDataManager.Instance.NumConfigDataObjects > 1)
        {
            string[] configDataNames = new string[ConfigDataManager.Instance.NumConfigDataObjects];
            ConfigDataManager.Instance.GetConfigDataNames(configDataNames);
            int indexFromString = QCARUtilities.GetIndexFromString(ct.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.NumCylinderTargets];
            configData.CopyCylinderTargetNames(arrayToFill, 0);
            int selectedIndex = QCARUtilities.GetIndexFromString(ct.TrackableName, arrayToFill);
            if (selectedIndex < 0)
            {
                selectedIndex = 0;
            }
            int num4 = EditorGUILayout.Popup("Cylinder Target", selectedIndex, arrayToFill, new GUILayoutOption[0]);
            if ((arrayToFill.Length > 0) && ((index != indexFromString) || (num4 != selectedIndex)))
            {
                ConfigData.CylinderTargetData data2;
                ct.SetDataSetPath("QCAR/" + configDataNames[index] + ".xml");
                ct.SetNameForTrackable(arrayToFill[num4]);
                configData.GetCylinderTarget(target.TrackableName, out data2);
                UpdateAspectRatio(ct, data2);
                UpdateScale(ct, data2.sideLength);
            }
            float num5 = EditorGUILayout.FloatField("Side Length", target.SideLength, new GUILayoutOption[0]);
            if (num5 != target.SideLength)
            {
                target.SetSideLength(num5);
            }
            float num6 = EditorGUILayout.FloatField("Top Diameter ", target.TopDiameter, new GUILayoutOption[0]);
            if (num6 != target.TopDiameter)
            {
                target.SetTopDiameter(num6);
            }
            float num7 = EditorGUILayout.FloatField("Bottom Diameter", target.BottomDiameter, new GUILayoutOption[0]);
            if (num7 != target.BottomDiameter)
            {
                target.SetBottomDiameter(num7);
            }
            ct.SetExtendedTracking(EditorGUILayout.Toggle("Extended tracking", ct.ExtendedTracking, new GUILayoutOption[0]));
            ct.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", ct.PreserveChildSize, new GUILayoutOption[0]));
        }
        else if (GUILayout.Button("No targets defined. Press here for target creation!", new GUILayoutOption[0]))
        {
            SceneManager.Instance.GoToTargetManagerPage();
        }
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            SceneManager.Instance.SceneUpdated();
        }
    }