示例#1
0
 public MeshMakerTriangle(int id, ref MeshMakerVertex vertex1, ref MeshMakerVertex vertex2, ref MeshMakerVertex vertex3)
 {
     ID      = id;
     Vertex1 = vertex1;
     Vertex2 = vertex2;
     Vertex3 = vertex3;
     RefreshEdge();
 }
示例#2
0
 /// <summary>
 /// 为所有面执行移除操作,条件是该面包含顶点vertex
 /// </summary>
 public static void RemoveByVertex(this List <MeshMakerTriangle> triangles, MeshMakerVertex vertex)
 {
     for (int i = 0; i < triangles.Count; i++)
     {
         if (triangles[i].Vertex1 == vertex || triangles[i].Vertex2 == vertex || triangles[i].Vertex3 == vertex)
         {
             triangles.RemoveAt(i);
             i--;
         }
     }
 }
示例#3
0
 /// <summary>
 /// 判断vertex1和vertex2是否相连,也就是判断是否存在于同一面中
 /// </summary>
 public static bool IsConnected(this List <MeshMakerTriangle> triangles, MeshMakerVertex vertex1, MeshMakerVertex vertex2)
 {
     for (int i = 0; i < triangles.Count; i++)
     {
         if ((triangles[i].Vertex1 == vertex1 || triangles[i].Vertex2 == vertex1 || triangles[i].Vertex3 == vertex1) &&
             (triangles[i].Vertex1 == vertex2 || triangles[i].Vertex2 == vertex2 || triangles[i].Vertex3 == vertex2))
         {
             return(true);
         }
     }
     return(false);
 }
示例#4
0
 /// <summary>
 /// 清空鼠标当前选中的目标
 /// </summary>
 private void ClearCheckedTarget()
 {
     if (_currentCheckedTriangle != null)
     {
         _currentCheckedTriangle = null;
     }
     if (_currentCheckedEdge != null)
     {
         _currentCheckedEdge = null;
     }
     if (_currentCheckedVertex != null)
     {
         _currentCheckedVertex = null;
     }
 }
示例#5
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();
        }
示例#6
0
 /// <summary>
 /// 为所有面执行替换操作,将旧的顶点oldVertex替换为新的顶点newVertex
 /// </summary>
 public static void ReplaceVertex(this List <MeshMakerTriangle> triangles, MeshMakerVertex oldVertex, MeshMakerVertex newVertex)
 {
     for (int i = 0; i < triangles.Count; i++)
     {
         if (triangles[i].Vertex1 == oldVertex)
         {
             triangles[i].Vertex1 = newVertex;
             triangles[i].RefreshEdge();
         }
         else if (triangles[i].Vertex2 == oldVertex)
         {
             triangles[i].Vertex2 = newVertex;
             triangles[i].RefreshEdge();
         }
         else if (triangles[i].Vertex3 == oldVertex)
         {
             triangles[i].Vertex3 = newVertex;
             triangles[i].RefreshEdge();
         }
     }
 }
示例#7
0
 public MeshMakerEdge(ref MeshMakerVertex vertex1, ref MeshMakerVertex vertex2)
 {
     Vertex1 = vertex1;
     Vertex2 = vertex2;
 }
示例#8
0
        /// <summary>
        /// 高级编辑模式
        /// </summary>
        private void SecondaryHandle()
        {
            if (_secondaryHandle)
            {
                #region 顶点模式
                if (_currentEditMode == EditMode.Vertex && _currentCheckedVertex != null)
                {
                    switch (_secondaryHandleMode)
                    {
                    case SecondaryHandleMode.Delete:
                        _meshMaker.Vertexs.Remove(_currentCheckedVertex);
                        _meshMaker.Vertexs.RefreshID();
                        _meshMaker.Triangles.RemoveByVertex(_currentCheckedVertex);
                        _meshMaker.Triangles.RefreshID();
                        _meshMaker.GenerateMesh();
                        _currentCheckedVertex = null;
                        StopSecondaryHandle();
                        break;

                    case SecondaryHandleMode.Welding:
                        Vector3 wv = _meshMaker.ScreenToWorldPointInScene(_sceneCamera, Event.current.mousePosition, _currentCheckedVertex.Vertex);
                        Handles.DrawDottedLine(_currentCheckedVertex.Vertex, wv, 0.2f);
                        Handles.Label(wv, "   请选择焊接目标");
                        if (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)
                                {
                                    MeshMakerVertex mmv = _meshMaker.Triangles[hit.triangleIndex].GetVertexByClick(hit.point);

                                    if (mmv != _currentCheckedVertex)
                                    {
                                        _meshMaker.Vertexs.Remove(_currentCheckedVertex);
                                        _meshMaker.Vertexs.RefreshID();
                                        _meshMaker.Triangles.RemoveByVertexs(_currentCheckedVertex, mmv);
                                        _meshMaker.Triangles.ReplaceVertex(_currentCheckedVertex, mmv);
                                        _meshMaker.Triangles.RefreshID();
                                        _meshMaker.GenerateMesh();
                                        _currentCheckedVertex = null;
                                    }
                                }
                            }
                            StopSecondaryHandle();
                        }
                        break;

                    case SecondaryHandleMode.Clone:
                        Vector3 cv = _meshMaker.ScreenToWorldPointInScene(_sceneCamera, Event.current.mousePosition, _currentCheckedVertex.Vertex);
                        Handles.DrawDottedLine(_currentCheckedVertex.Vertex, cv, 0.2f);
                        Handles.Label(cv, "   请选择参照目标");
                        if (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)
                                {
                                    MeshMakerVertex mmv = _meshMaker.Triangles[hit.triangleIndex].GetVertexByClick(hit.point);

                                    if (mmv != _currentCheckedVertex && _meshMaker.Triangles.IsConnected(_currentCheckedVertex, mmv))
                                    {
                                        Vector3         vertex = Vector3.Lerp(_currentCheckedVertex.Vertex, mmv.Vertex, 0.5f);
                                        Vector2         uv     = Vector2.Lerp(_currentCheckedVertex.UV, mmv.UV, 0.5f);
                                        MeshMakerVertex newMmv = new MeshMakerVertex(0, vertex, uv, _currentCheckedVertex.Normal, new List <int>());

                                        _meshMaker.Vertexs.Add(newMmv);
                                        _meshMaker.Vertexs.RefreshID();
                                        _meshMaker.Triangles.SegmentationTriangle(mmv, _currentCheckedVertex, newMmv);
                                        _meshMaker.Triangles.RefreshID();
                                        _meshMaker.GenerateMesh();
                                        _currentCheckedVertex = null;
                                    }
                                }
                            }
                            StopSecondaryHandle();
                        }
                        break;
                    }
                }
                #endregion
            }
        }
示例#9
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;
        }
示例#10
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);
        }