Example #1
0
 /// <summary>
 /// 清空鼠标当前经过的目标
 /// </summary>
 private void ClearHoverTarget()
 {
     if (_currentHoverTriangle != null)
     {
         _currentHoverTriangle = null;
     }
 }
Example #2
0
        /// <summary>
        /// 截获鼠标当前经过的目标
        /// </summary>
        private void CaptureHoverTarget()
        {
            if (Event.current.type == EventType.MouseMove)
            {
                RaycastHit hit;
                if (Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out hit))
                {
                    if (hit.triangleIndex >= 0 && hit.triangleIndex < _meshMaker.Triangles.Count)
                    {
                        _currentHoverTriangle = _meshMaker.Triangles[hit.triangleIndex];
                        if (_currentEditMode == EditMode.Face && _currentHoverTriangle == _currentCheckedTriangle)
                        {
                            ClearHoverTarget();
                        }
                    }
                    else
                    {
                        ClearHoverTarget();
                    }
                }
                else
                {
                    ClearHoverTarget();
                }
            }
            else if (Event.current.type == EventType.MouseDown)
            {
                ClearHoverTarget();
            }

            ShowHoverTarget();
        }
Example #3
0
 /// <summary>
 /// 清空鼠标当前选中的目标
 /// </summary>
 private void ClearCheckedTarget()
 {
     if (_currentCheckedTriangle != null)
     {
         _currentCheckedTriangle = null;
     }
     if (_currentCheckedEdge != null)
     {
         _currentCheckedEdge = null;
     }
     if (_currentCheckedVertex != null)
     {
         _currentCheckedVertex = null;
     }
 }
Example #4
0
        /// <summary>
        /// 截获鼠标当前选中的目标
        /// </summary>
        private void CaptureCheckedTarget()
        {
            if (!_secondaryHandle && Event.current.button == 1 && Event.current.isMouse && Event.current.type == EventType.MouseDown)
            {
                RaycastHit hit;
                if (Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out hit))
                {
                    if (hit.triangleIndex >= 0 && hit.triangleIndex < _meshMaker.Triangles.Count)
                    {
                        _currentCheckedTriangle = _meshMaker.Triangles[hit.triangleIndex];
                    }
                    else
                    {
                        ClearCheckedTarget();
                    }
                }
                else
                {
                    ClearCheckedTarget();
                }

                if (_currentCheckedTriangle != null)
                {
                    switch (_currentEditMode)
                    {
                    case EditMode.Vertex:
                        _currentCheckedVertex = _currentCheckedTriangle.GetVertexByClick(hit.point);
                        break;

                    case EditMode.Edge:
                        _currentCheckedEdge = _currentCheckedTriangle.GetEdgeByClick(hit.point);
                        SetEditEdge();
                        break;

                    case EditMode.Face:
                        SetEditTriangle();
                        break;
                    }
                }
            }

            Selection.activeObject = _meshMaker.gameObject;

            ShowCheckedTarget();
        }
Example #5
0
        /// <summary>
        /// 鼠标点击,获取距离鼠标最近的边
        /// </summary>
        public static MeshMakerEdge GetEdgeByClick(this MeshMakerTriangle triangle, Vector3 clickPoint)
        {
            float distance1 = HandleUtility.DistancePointLine(clickPoint, triangle.Edge1.Vertex1.Vertex, triangle.Edge1.Vertex2.Vertex);
            float distance2 = HandleUtility.DistancePointLine(clickPoint, triangle.Edge2.Vertex1.Vertex, triangle.Edge2.Vertex2.Vertex);
            float distance3 = HandleUtility.DistancePointLine(clickPoint, triangle.Edge3.Vertex1.Vertex, triangle.Edge3.Vertex2.Vertex);

            if (distance1 < distance2 && distance1 < distance3)
            {
                return(triangle.Edge1);
            }
            if (distance2 < distance1 && distance2 < distance3)
            {
                return(triangle.Edge2);
            }
            if (distance3 < distance1 && distance3 < distance2)
            {
                return(triangle.Edge3);
            }
            return(triangle.Edge1);
        }
Example #6
0
        /// <summary>
        /// 鼠标点击,获取距离鼠标最近的顶点
        /// </summary>
        public static MeshMakerVertex GetVertexByClick(this MeshMakerTriangle triangle, Vector3 clickPoint)
        {
            float distance1 = Vector3.Distance(triangle.Vertex1.Vertex, clickPoint);
            float distance2 = Vector3.Distance(triangle.Vertex2.Vertex, clickPoint);
            float distance3 = Vector3.Distance(triangle.Vertex3.Vertex, clickPoint);

            if (distance1 < distance2 && distance1 < distance3)
            {
                return(triangle.Vertex1);
            }
            if (distance2 < distance1 && distance2 < distance3)
            {
                return(triangle.Vertex2);
            }
            if (distance3 < distance1 && distance3 < distance2)
            {
                return(triangle.Vertex3);
            }
            return(triangle.Vertex1);
        }
Example #7
0
        /// <summary>
        /// 为所有面执行分割操作,条件是该面包含顶点vertex1和vertex2,并以新的顶点newVertex作为分割之后的顶点
        /// </summary>
        public static void SegmentationTriangle(this List <MeshMakerTriangle> triangles, MeshMakerVertex vertex1, MeshMakerVertex vertex2, MeshMakerVertex newVertex)
        {
            List <MeshMakerTriangle> newTriangles = new List <MeshMakerTriangle>();

            for (int i = 0; i < triangles.Count; i++)
            {
                if ((triangles[i].Vertex1 == vertex1 || triangles[i].Vertex1 == vertex2) && (triangles[i].Vertex2 == vertex1 || triangles[i].Vertex2 == vertex2))
                {
                    MeshMakerTriangle mmt1 = new MeshMakerTriangle(0, ref triangles[i].Vertex1, ref newVertex, ref triangles[i].Vertex3);
                    MeshMakerTriangle mmt2 = new MeshMakerTriangle(0, ref newVertex, ref triangles[i].Vertex2, ref triangles[i].Vertex3);
                    triangles.RemoveAt(i);
                    newTriangles.Add(mmt1);
                    newTriangles.Add(mmt2);
                    i--;
                }
                else if ((triangles[i].Vertex2 == vertex1 || triangles[i].Vertex2 == vertex2) && (triangles[i].Vertex3 == vertex1 || triangles[i].Vertex3 == vertex2))
                {
                    MeshMakerTriangle mmt1 = new MeshMakerTriangle(0, ref triangles[i].Vertex1, ref triangles[i].Vertex2, ref newVertex);
                    MeshMakerTriangle mmt2 = new MeshMakerTriangle(0, ref triangles[i].Vertex1, ref newVertex, ref triangles[i].Vertex3);
                    triangles.RemoveAt(i);
                    newTriangles.Add(mmt1);
                    newTriangles.Add(mmt2);
                    i--;
                }
                else if ((triangles[i].Vertex1 == vertex1 || triangles[i].Vertex1 == vertex2) && (triangles[i].Vertex3 == vertex1 || triangles[i].Vertex3 == vertex2))
                {
                    MeshMakerTriangle mmt1 = new MeshMakerTriangle(0, ref triangles[i].Vertex1, ref triangles[i].Vertex2, ref newVertex);
                    MeshMakerTriangle mmt2 = new MeshMakerTriangle(0, ref newVertex, ref triangles[i].Vertex2, ref triangles[i].Vertex3);
                    triangles.RemoveAt(i);
                    newTriangles.Add(mmt1);
                    newTriangles.Add(mmt2);
                    i--;
                }
            }
            triangles.AddRange(newTriangles);
        }
Example #8
0
        private void Init()
        {
            _meshMaker = target as MeshMaker;
            if (_meshMaker == null || EditorApplication.isPlaying)
            {
                return;
            }

            TransformChange(_meshMaker);
            _currentHoverTriangle   = null;
            _currentCheckedTriangle = null;
            _currentCheckedVertex   = null;
            _currentCheckedEdge     = null;
            _currentHandleTool      = HandleTool.None;
            _currentEditMode        = EditMode.Vertex;

            _currentEditTriangle = new GameObject("Triangle");
            _currentEditTriangle.transform.SetParent(_meshMaker.Target.transform);
            _currentEditTriangle.hideFlags = HideFlags.HideInHierarchy;
            _currentEditTriangleVertex1    = new GameObject("Vertex1");
            _currentEditTriangleVertex1.transform.SetParent(_currentEditTriangle.transform);
            _currentEditTriangleVertex1.hideFlags = HideFlags.HideInHierarchy;
            _currentEditTriangleVertex2           = new GameObject("Vertex2");
            _currentEditTriangleVertex2.transform.SetParent(_currentEditTriangle.transform);
            _currentEditTriangleVertex2.hideFlags = HideFlags.HideInHierarchy;
            _currentEditTriangleVertex3           = new GameObject("Vertex3");
            _currentEditTriangleVertex3.transform.SetParent(_currentEditTriangle.transform);
            _currentEditTriangleVertex3.hideFlags = HideFlags.HideInHierarchy;

            _currentEditEdge = new GameObject("Edge");
            _currentEditEdge.transform.SetParent(_meshMaker.Target.transform);
            _currentEditEdge.hideFlags = HideFlags.HideInHierarchy;
            _currentEditEdgeVertex1    = new GameObject("Vertex1");
            _currentEditEdgeVertex1.transform.SetParent(_currentEditEdge.transform);
            _currentEditEdgeVertex1.hideFlags = HideFlags.HideInHierarchy;
            _currentEditEdgeVertex2           = new GameObject("Vertex2");
            _currentEditEdgeVertex2.transform.SetParent(_currentEditEdge.transform);
            _currentEditEdgeVertex2.hideFlags = HideFlags.HideInHierarchy;

            if (_vertexButtonContent == null)
            {
                Texture2D t2d = AssetDatabase.LoadAssetAtPath("Assets/ComDevelop/MeshEditor/MeshMaker/Editor/Texture/Vertex.png", typeof(Texture2D)) as Texture2D;
                _vertexButtonContent = new GUIContent("", t2d, "Vertex Edit Mode");
            }
            if (_edgeButtonContent == null)
            {
                Texture2D t2d = AssetDatabase.LoadAssetAtPath("Assets/ComDevelop/MeshEditor/MeshMaker/Editor/Texture/Edge.png", typeof(Texture2D)) as Texture2D;
                _edgeButtonContent = new GUIContent("", t2d, "Edge Edit Mode");
            }
            if (_faceButtonContent == null)
            {
                Texture2D t2d = AssetDatabase.LoadAssetAtPath("Assets/ComDevelop/MeshEditor/MeshMaker/Editor/Texture/Face.png", typeof(Texture2D)) as Texture2D;
                _faceButtonContent = new GUIContent("", t2d, "Face Edit Mode");
            }
            if (_noneButtonContent == null)
            {
                Texture2D t2d = AssetDatabase.LoadAssetAtPath("Assets/ComDevelop/MeshEditor/MeshMaker/Editor/Texture/None.png", typeof(Texture2D)) as Texture2D;
                _noneButtonContent = new GUIContent("", t2d, "None Edit Mode");
            }
            _secondaryHandle        = false;
            _secondaryHandleMode    = SecondaryHandleMode.None;
            _sceneCamera            = SceneView.lastActiveSceneView.camera;
            Undo.undoRedoPerformed += OnRecord;
        }