Ejemplo n.º 1
0
        /// <summary>
        /// Draws the controls for controlling the comparison module for a particular editor
        /// </summary>
        /// <param name="editor">The editor that the controls are being draw inside.</param>
        void DrawCompareControls(Editor editor)
        {
            // Comparing only works with a single data object, so don't show the compare controls unless this is a Proxy
            if (((MARSEntity)editor.target).GetComponent <Proxy>() == null)
            {
                return;
            }

            if (m_CompareDataModule == null)
            {
                return;
            }

            GUILayout.Space(6f);

            m_CurrentEditor = editor;

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("Compare Tool", MarsEditorGUI.Styles.LabelLeftAligned);

                if (m_CompareDataModule.IsComparing)
                {
                    if (GUILayout.Button(styles.includeAllButtonContent, MarsEditorGUI.Styles.MiniFontButton))
                    {
                        if (EditorUtility.DisplayDialog(k_ModifyConditionActionMessage, k_AreYouSureMessage, k_ConfirmActionMessage, k_CancelActionMessage))
                        {
                            m_CompareDataModule.IncludeAll();
                            Undo.IncrementCurrentGroup();
                            m_SimulatedObjectsManager.DirtySimulatableScene();
                        }
                    }

                    if (GUILayout.Button(styles.optimizeAllButtonContent, MarsEditorGUI.Styles.MiniFontButton))
                    {
                        if (EditorUtility.DisplayDialog(k_ModifyConditionActionMessage, k_AreYouSureMessage, k_ConfirmActionMessage, k_CancelActionMessage))
                        {
                            m_CompareDataModule.OptimizeAll();
                            Undo.IncrementCurrentGroup();
                            m_SimulatedObjectsManager.DirtySimulatableScene();
                        }
                    }

                    if (GUILayout.Button(styles.stopComparingButtonContent, MarsEditorGUI.Styles.MiniFontButton))
                    {
                        ToolManager.RestorePreviousPersistentTool();
                    }
                }
                else
                {
                    if (GUILayout.Button(styles.startComparingButtonContent, MarsEditorGUI.Styles.MiniFontButton))
                    {
                        ToolManager.SetActiveTool <MarsCompareTool>();
                    }
                }
            }
        }
Ejemplo n.º 2
0
    public void CutTool_CutUsing3NewVerticesNoLoop_TestInsertionTypes_TestCreates2Faces()
    {
        CutTool tool = ScriptableObject.CreateInstance <CutTool>();

        ToolManager.SetActiveTool(tool);

        int  originalFaceCount = m_PBMesh.faces.Count;
        Face face = m_PBMesh.faces[0];

        Assume.That(face, Is.Not.Null);

        Vertex[] vertices    = m_PBMesh.GetVertices();
        var      faceIndexes = face.distinctIndexes;

        Assume.That(faceIndexes.Count, Is.EqualTo(4));

        Vector3 pos_a = Math.Average(new Vector3[] { vertices[faceIndexes[0]].position, vertices[faceIndexes[1]].position, vertices[faceIndexes[2]].position });
        Vector3 pos_b = Math.Average(new Vector3[] { vertices[faceIndexes[1]].position, vertices[faceIndexes[2]].position, vertices[faceIndexes[3]].position });
        Vector3 pos_c = Math.Average(new Vector3[] { vertices[faceIndexes[0]].position, vertices[faceIndexes[1]].position, vertices[faceIndexes[3]].position });

        //Creating a first new vertex
        tool.UpdateCurrentPosition(face, pos_a, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.NewVertex));

        //Insert first vertex to the path
        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(1));
        //No connection is created yet
        Assert.That(tool.m_MeshConnections.Count, Is.EqualTo(0));

        //Creating a second new vertex
        tool.UpdateCurrentPosition(face, pos_b, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.NewVertex));

        //Insert 2nd point to the path
        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(2));
        //Check that the created path is connected twice to the containing face
        Assert.That(tool.m_MeshConnections.Count, Is.EqualTo(2));

        //Creating a third new vertex
        tool.UpdateCurrentPosition(face, pos_c, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.NewVertex));

        //Insert 3rd point to the path
        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(3));
        //Check that the created path is connected twice to the containing face
        Assert.That(tool.m_MeshConnections.Count, Is.EqualTo(2));

        ActionResult result = tool.DoCut();

        Assert.That(result.status, Is.EqualTo(ActionResult.Success.status));
        Assert.That(m_PBMesh.faces.Count, Is.EqualTo(originalFaceCount - 1 /*removed face*/ + 2 /*added faces*/));

        Object.DestroyImmediate(tool);
    }
Ejemplo n.º 3
0
    public void CutTool_EdgeToEdgeCut_TestInsertOnEdge_TestCreatesTwoFaces()
    {
        CutTool tool = ScriptableObject.CreateInstance <CutTool>();

        ToolManager.SetActiveTool(tool);

        int  originalFaceCount = m_PBMesh.faces.Count;
        Face face = m_PBMesh.faces[0];

        Assert.That(face, Is.Not.Null);

        Vertex[] vertices    = m_PBMesh.GetVertices();
        var      faceIndexes = face.distinctIndexes;

        Assert.That(faceIndexes.Count, Is.EqualTo(4));

        Vector3 pos_a = Math.Average(new Vector3[] { vertices[faceIndexes[0]].position, vertices[faceIndexes[1]].position });
        Vector3 pos_b = Math.Average(new Vector3[] { vertices[faceIndexes[2]].position, vertices[faceIndexes[3]].position });

        tool.UpdateCurrentPosition(face, pos_a, Vector3.up);
        Assert.That(tool.m_TargetFace, Is.Null);
        Assert.That(tool.m_CurrentFace, Is.EqualTo(face));
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.AddedOnEdge));

        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(1));
        Assert.That(tool.m_TargetFace, Is.EqualTo(face));
        Assert.That(tool.m_MeshConnections.Count, Is.EqualTo(0));

        tool.UpdateCurrentPosition(face, pos_b, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.NewVertex));

        tool.m_SnappingPoint = true;
        tool.UpdateCurrentPosition(face, pos_b, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.AddedOnEdge));

        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(2));

        ActionResult result = tool.DoCut();

        Assert.That(result.status, Is.EqualTo(ActionResult.Success.status));
        Assert.That(m_PBMesh.faces.Count, Is.EqualTo(originalFaceCount - 1 /*removed face*/ + 2 /*added faces*/));

        Object.DestroyImmediate(tool);
    }
Ejemplo n.º 4
0
        protected void DoEditButton <U>(GUIContent icon, string label) where U : PathEditorTool <T>
        {
            const float kButtonWidth  = 33;
            const float kButtonHeight = 23;
            const float k_SpaceBetweenLabelAndButton = 5;
            var         buttonStyle = new GUIStyle("EditModeSingleButton");

            var rect       = EditorGUILayout.GetControlRect(true, kButtonHeight, buttonStyle);
            var buttonRect = new Rect(rect.xMin + EditorGUIUtility.labelWidth, rect.yMin, kButtonWidth, kButtonHeight);

            var labelContent = new GUIContent(label);
            var labelSize    = GUI.skin.label.CalcSize(labelContent);

            var labelRect = new Rect(
                buttonRect.xMax + k_SpaceBetweenLabelAndButton,
                rect.yMin + (rect.height - labelSize.y) * .5f,
                labelSize.x,
                rect.height);

            using (new EditorGUI.DisabledGroupScope(!EditorToolManager.IsAvailable <U>()))
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var isActive = GUI.Toggle(buttonRect, EditorToolManager.IsActiveTool <U>(), icon, buttonStyle);

                    GUI.Label(labelRect, label);

                    if (check.changed)
                    {
                        if (isActive)
                        {
                            ToolManager.SetActiveTool <U>();
                        }
                        else
                        {
                            ToolManager.RestorePreviousTool();
                        }
                    }
                }
            }
        }