Exemplo n.º 1
0
        protected void SelectFaceByRect(bool laser)
        {
            Vector2D        minV      = GraphicResearchHuiZhao.Vector2D.Min(mouseDownPos, mouseCurrPos);
            Vector2D        size      = GraphicResearchHuiZhao.Vector2D.Max(mouseDownPos, mouseCurrPos) - minV;
            CRectangle      rect      = new CRectangle((int)minV.x, (int)minV.y, (int)size.x, (int)size.y);
            CRectangle      viewport  = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh         m         = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;


            for (int i = 0; i < m.Faces.Count; i++)
            {
                Vector3D v1 = projector.Project(m.Faces[i].GetVertex(0).Traits.Position);
                Vector3D v2 = projector.Project(m.Faces[i].GetVertex(1).Traits.Position);
                Vector3D v3 = projector.Project(m.Faces[i].GetVertex(2).Traits.Position);

                if (viewport.Contains((int)v1.x, (int)v1.y) && viewport.Contains((int)v2.x, (int)v2.y) && viewport.Contains((int)v3.x, (int)v3.y))
                {
                    bool flag = rect.Contains((int)v1.x, (int)v1.y) && rect.Contains((int)v2.x, (int)v2.y) && rect.Contains((int)v3.x, (int)v3.y);

                    laser = ToolLaser();
                    flag &= (laser || projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z >= eps);

                    m.Faces[i].Traits.SelectedFlag = ToolKey(m.Faces[i].Traits.SelectedFlag, flag);
                }
            }
        }
Exemplo n.º 2
0
        protected void SelectFaceByCircle(bool laser)
        {
            double          radius    = (mouseDownPos - mouseCurrPos).Length() / 2;
            Vector2D        center    = mouseDownPos + (mouseCurrPos - mouseDownPos) / 2;
            CRectangle      viewport  = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh         m         = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;


            for (int i = 0; i < m.Faces.Count; i++)
            {
                Vector3D v1 = projector.Project(m.Faces[i].GetVertex(0).Traits.Position);
                Vector3D v2 = projector.Project(m.Faces[i].GetVertex(1).Traits.Position);
                Vector3D v3 = projector.Project(m.Faces[i].GetVertex(2).Traits.Position);

                Vector2D u1 = new Vector2D(v1.x, v1.y);
                Vector2D u2 = new Vector2D(v2.x, v2.y);
                Vector2D u3 = new Vector2D(v3.x, v3.y);

                if (viewport.Contains((int)v1.x, (int)v1.y) && viewport.Contains((int)v2.x, (int)v2.y) && viewport.Contains((int)v3.x, (int)v3.y))
                {
                    bool flag = (u1 - center).Length() <= radius && (u2 - center).Length() <= radius && (u3 - center).Length() <= radius;

                    laser = ToolLaser();
                    flag &= (laser || projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z >= eps);

                    m.Faces[i].Traits.SelectedFlag = ToolKey(m.Faces[i].Traits.SelectedFlag, flag);
                }
            }
        }
Exemplo n.º 3
0
        protected int SelectEdgeByPoint(bool laser)
        {
            CRectangle      viewport  = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh         m         = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;

            double minDis   = double.MaxValue;
            int    minIndex = -1;

            for (int i = 0; i < m.Edges.Count; i++)
            {
                Vector3D v1 = projector.Project(m.Edges[i].Vertex0.Traits.Position);
                Vector3D v2 = projector.Project(m.Edges[i].Vertex1.Traits.Position);

                Vector2D u1 = new  Vector2D(v1.x, v1.y);
                Vector2D u2 = new  Vector2D(v2.x, v2.y);

                if (!viewport.Contains((int)v1.x, (int)v1.y) && !viewport.Contains((int)v2.x, (int)v2.y))
                {
                    continue;
                }

                //if (!laser&& projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z < eps ) continue;


                double dis = (u1 - mouseCurrPos).Length() + (u2 - mouseCurrPos).Length();
                if (dis < minDis)
                {
                    minIndex = i;
                    minDis   = dis;
                }
            }
            if (minIndex == -1)
            {
                return(minIndex);
            }


            if (key == EnumKey.Shift)
            {
                m.Edges[minIndex].Traits.SelectedFlag = (byte)1;
            }
            else if (key == EnumKey.Ctrl)
            {
                m.Edges[minIndex].Traits.SelectedFlag = (byte)0;
            }
            else
            {
                for (int i = 0; i < m.Edges.Count; i++)
                {
                    m.Edges[i].Traits.SelectedFlag = (byte)0;
                }


                m.Edges[minIndex].Traits.SelectedFlag = (byte)1;
            }
            return(minIndex);
        }
Exemplo n.º 4
0
        protected int SelectVertexByPoint(bool laser)
        {
            CRectangle      viewport  = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            double          eps       = ToolSetting.ToolsSetting.DepthTolerance;
            double          minDis    = double.MaxValue;
            int             minIndex  = -1;

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                Vector3D v = projector.Project(mesh.Vertices[i].Traits.Position);
                Vector2D u = new  Vector2D(v.x, v.y);
                if (!viewport.Contains((int)v.x, (int)v.y))
                {
                    continue;
                }
                if (!laser && projector.GetDepthValue((int)v.x,
                                                      (int)v.y) - v.z < eps)
                {
                    continue;
                }
                double dis = (u - mouseCurrPos).Length();
                if (dis < minDis)
                {
                    minIndex = i;
                    minDis   = dis;
                }
            }
            if (minIndex == -1)
            {
                return(minIndex);
            }
            if (key == EnumKey.Shift)
            {
                mesh.Vertices[minIndex].Traits.SelectedFlag = (byte)1;
            }
            else if (key == EnumKey.Ctrl)
            {
                mesh.Vertices[minIndex].Traits.SelectedFlag = (byte)0;
            }
            else
            {
                for (int i = 0; i < mesh.Vertices.Count; i++)
                {
                    mesh.Vertices[i].Traits.SelectedFlag = (byte)0;
                }

                mesh.Vertices[minIndex].Traits.SelectedFlag = (byte)1;
            }
            return(minIndex);
        }
Exemplo n.º 5
0
        protected int SelectVertexByPoint(bool laser)
        {
            CRectangle viewport = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();  
            double eps = ToolSetting.ToolsSetting.DepthTolerance; 
            double minDis = double.MaxValue;
            int minIndex = -1;
            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                Vector3D v = projector.Project(mesh.Vertices[i].Traits.Position);
                Vector2D u = new  Vector2D(v.x, v.y);
                if (!viewport.Contains((int)v.x, (int)v.y)) continue;
                if (!laser && projector.GetDepthValue((int)v.x, 
                               (int)v.y) - v.z < eps) continue; 
                double dis = (u - mouseCurrPos).Length();
                if (dis < minDis)
                {
                    minIndex = i;
                    minDis = dis;
                }
            }
            if (minIndex == -1) return minIndex; 
            if (key == EnumKey.Shift)
                mesh.Vertices[minIndex].Traits.SelectedFlag = (byte)1;
            else if (key == EnumKey.Ctrl)
                mesh.Vertices[minIndex].Traits.SelectedFlag = (byte)0;
            else
            {

                for (int i = 0; i < mesh.Vertices.Count; i++)
                { 
                    mesh.Vertices[i].Traits.SelectedFlag = (byte)0; 
                } 

                mesh.Vertices[minIndex].Traits.SelectedFlag = (byte)1;
            }  
            return minIndex;
        }
Exemplo n.º 6
0
        protected void SelectVertexByCircle(bool laser)
        {
            double          radius    = (mouseDownPos - mouseCurrPos).Length() / 2;
            Vector2D        center    = mouseDownPos + (mouseCurrPos - mouseDownPos) / 2;
            CRectangle      viewport  = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            double          eps       = ToolSetting.ToolsSetting.DepthTolerance;

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                Vector3D v = projector.Project(mesh.Vertices[i].Traits.Position);
                Vector2D u = new Vector2D(v.x, v.y);
                if (viewport.Contains((int)v.x, (int)v.y))
                {
                    bool flag = (u - center).Length() <= radius;
                    laser = ToolLaser();
                    flag &= (laser ||
                             projector.GetDepthValue((int)v.x, (int)v.y) - v.z >= eps);
                    mesh.Vertices[i].Traits.SelectedFlag =
                        ToolKey(mesh.Vertices[i].Traits.SelectedFlag, flag);
                }
            }
        }
Exemplo n.º 7
0
        protected void SelectVertexByRect(bool laser)
        {
            Vector2D   minV = Vector2D.Min(mouseDownPos, mouseCurrPos);
            Vector2D   size = Vector2D.Max(mouseDownPos, mouseCurrPos) - minV;
            CRectangle rect = new CRectangle((int)minV.x, (int)minV.y,
                                             (int)size.x, (int)size.y);
            CRectangle      viewport  = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            double          eps       = ToolSetting.ToolsSetting.DepthTolerance;

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                Vector3D v = projector.Project(mesh.Vertices[i].Traits.Position);
                if (viewport.Contains((int)v.x, (int)v.y))
                {
                    bool flag = rect.Contains((int)v.x, (int)v.y);
                    laser = ToolLaser();
                    flag &= (laser || projector.GetDepthValue((int)v.x,
                                                              (int)v.y) - v.z >= eps);
                    mesh.Vertices[i].Traits.SelectedFlag =
                        ToolKey(mesh.Vertices[i].Traits.SelectedFlag, flag);
                }
            }
        }
Exemplo n.º 8
0
        public bool StartMoving()
        {
            // find closest selected vertex
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh         m         = this.mesh;

            CRectangle viewport = new CRectangle(0, 0, Width, Height);
            double     eps      = ToolSetting.ToolsSetting.DepthTolerance;
            double     minDis   = double.MaxValue;
            int        minIndex = -1;

            for (int i = 0; i < m.Vertices.Count; i++)
            {
                if (m.Vertices[i].Traits.SelectedFlag == 0)
                {
                    continue;
                }

                Vector3D v3d = projector.Project(m.Vertices[i].Traits.Position);
                Vector2D v   = new Vector2D(v3d.x, v3d.y);

                if (!viewport.Contains((int)v.x, (int)v.y))
                {
                    continue;
                }
                if (projector.GetDepthValue((int)v.x, (int)v.y) - v3d.z < eps)
                {
                    continue;
                }

                double dis = (v - mouseDownPos).Length();
                if (dis < minDis)
                {
                    minDis   = dis;
                    minIndex = i;
                }
            }

            if (minIndex == -1)
            {
                handleIndex = null;
                oldHandlePos.Clear();
                return(false);
            }

            // find boundary box
            int flag = m.Vertices[minIndex].Traits.SelectedFlag;

            handleIndex.Clear();
            oldHandlePos.Clear();

            Vector3D c = new Vector3D(0, 0, 0);

            for (int i = 0; i < m.Vertices.Count; i++)
            {
                if (m.Vertices[i].Traits.SelectedFlag == flag)
                {
                    Vector3D p = new Vector3D(m.Vertices[i].Traits.Position.x, m.Vertices[i].Traits.Position.y, m.Vertices[i].Traits.Position.z);
                    handleIndex.Add(i);
                    oldHandlePos.Add(p);
                    c += p;
                }
            }

            c              /= (double)handleIndex.Count;
            handleCenter    = new Vector4D(c, 0);
            projectedCenter = projector.Project(handleCenter.x, handleCenter.y, handleCenter.z);
            return(true);
        }
Exemplo n.º 9
0
        public bool StartMoving()
        {
            // find closest selected vertex
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh m = this.mesh;

            CRectangle viewport = new CRectangle(0, 0, Width, Height);
            double eps = ToolSetting.ToolsSetting.DepthTolerance;
            double minDis = double.MaxValue;
            int minIndex = -1;

            for (int i = 0; i < m.Vertices.Count; i++)
            {
                if (m.Vertices[i].Traits.SelectedFlag == 0) continue;

                Vector3D v3d = projector.Project(m.Vertices[i].Traits.Position);
                Vector2D v = new Vector2D(v3d.x, v3d.y);

                if (!viewport.Contains((int)v.x, (int)v.y)) continue;
                if (projector.GetDepthValue((int)v.x, (int)v.y) - v3d.z < eps) continue;

                double dis = (v - mouseDownPos).Length();
                if (dis < minDis)
                {
                    minDis = dis;
                    minIndex = i;
                }
            }

            if (minIndex == -1)
            {
                handleIndex = null;
                oldHandlePos.Clear();
                return false;
            }

            // find boundary box
            int flag = m.Vertices[minIndex].Traits.SelectedFlag;
            if (handleIndex == null)
                return false;
            handleIndex.Clear();
            oldHandlePos.Clear();

            Vector3D c = new Vector3D(0, 0, 0);
            for (int i = 0; i < m.Vertices.Count; i++)
                if (m.Vertices[i].Traits.SelectedFlag == flag)
                {
                    Vector3D p = new Vector3D(m.Vertices[i].Traits.Position.x, m.Vertices[i].Traits.Position.y, m.Vertices[i].Traits.Position.z);
                    handleIndex.Add(i);
                    oldHandlePos.Add(p);
                    c += p;
                }

            c /= (double)handleIndex.Count;
            handleCenter = new Vector4D(c, 0);
            projectedCenter = projector.Project(handleCenter.x, handleCenter.y, handleCenter.z);
            return true;

        }
Exemplo n.º 10
0
        protected int SelectEdgeByPoint(bool laser)
        {
            CRectangle viewport = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh m = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;

            double minDis = double.MaxValue;
            int minIndex = -1;
            for (int i = 0; i < m.Edges.Count; i++)
            {
                Vector3D v1 = projector.Project(m.Edges[i].Vertex0.Traits.Position);
                Vector3D v2 = projector.Project(m.Edges[i].Vertex1.Traits.Position);

                Vector2D u1 = new  Vector2D(v1.x, v1.y);
                Vector2D u2 = new  Vector2D(v2.x, v2.y);

                if (!viewport.Contains((int)v1.x, (int)v1.y) && !viewport.Contains((int)v2.x, (int)v2.y)) continue;

                //if (!laser&& projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z < eps ) continue;


                double dis = (u1 - mouseCurrPos).Length() + (u2 - mouseCurrPos).Length();
                if (dis < minDis)
                {
                    minIndex = i;
                    minDis = dis;
                }
            }
            if (minIndex == -1)
                return minIndex;


            if (key == EnumKey.Shift)
            {
                m.Edges[minIndex].Traits.SelectedFlag = (byte)1;
                
            }
            else if (key == EnumKey.Ctrl)
                m.Edges[minIndex].Traits.SelectedFlag = (byte)0;
            else
            {

                for (int i = 0; i < m.Edges.Count; i++)
                { 
                    m.Edges[i].Traits.SelectedFlag = (byte)0; 
                }


                m.Edges[minIndex].Traits.SelectedFlag = (byte)1;
            }
            return minIndex;
        }
Exemplo n.º 11
0
        protected int SelectFaceByPoint(bool laser)
        {
            CRectangle viewport = new CRectangle(0, 0,  Width,  Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh m = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;

            bool isInFace = false;
            int minIndex = -1;
            for (int i = 0; i < m.Faces.Count; i++)
            {

                Vector3D v1 = projector.Project(m.Faces[i].GetVertex(0).Traits.Position);
                Vector3D v2 = projector.Project(m.Faces[i].GetVertex(1).Traits.Position);
                Vector3D v3 = projector.Project(m.Faces[i].GetVertex(2).Traits.Position);


                Vector2D u1 = new GraphicResearchHuiZhao.Vector2D(v1.x, v1.y);
                Vector2D u2 = new GraphicResearchHuiZhao.Vector2D(v2.x, v2.y);
                Vector2D u3 = new GraphicResearchHuiZhao.Vector2D(v3.x, v3.y);

                if (!viewport.Contains((int)v1.x, (int)v1.y) && !viewport.Contains((int)v2.x, (int)v2.y) && !viewport.Contains((int)v2.x, (int)v2.y)) continue;

                //  if (!laser && projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z < eps) continue;
                //isInFace=PointinTriangle(u1,u2,u3,mouseCurrPos);
                isInFace = IsInTriangle(u1, u2, u3, mouseCurrPos);
                if (isInFace)
                {
                    minIndex = i;
                }


            }
            if (minIndex == -1) return minIndex;



            if (key == EnumKey.Shift)
                m.Faces[minIndex].Traits.SelectedFlag = (byte)1;
            else if (key == EnumKey.Ctrl)
                m.Faces[minIndex].Traits.SelectedFlag = (byte)0;
            else
            {

                for (int i = 0; i < m.Faces.Count; i++)
                {

                    m.Faces[i].Traits.SelectedFlag = (byte)0;

                }


                m.Faces[minIndex].Traits.SelectedFlag = (byte)1;
            }
            return minIndex;
        }
Exemplo n.º 12
0
 protected void SelectVertexByRect(bool laser)
 {
     Vector2D minV =  Vector2D.Min(mouseDownPos, mouseCurrPos);
     Vector2D size =  Vector2D.Max(mouseDownPos, mouseCurrPos) - minV;
     CRectangle rect = new CRectangle((int)minV.x, (int)minV.y, 
                                       (int)size.x, (int)size.y);
     CRectangle viewport = new CRectangle(0, 0, Width, Height); 
     OpenGLProjector projector = new OpenGLProjector();  
     double eps = ToolSetting.ToolsSetting.DepthTolerance;  
     for (int i = 0; i < mesh.Vertices.Count; i++)
     {
         Vector3D v = projector.Project(mesh.Vertices[i].Traits.Position);
         if (viewport.Contains((int)v.x, (int)v.y))
         {
             bool flag = rect.Contains((int)v.x, (int)v.y); 
             laser = ToolLaser();
             flag &= (laser || projector.GetDepthValue((int)v.x, 
                                        (int)v.y) - v.z >= eps);
             mesh.Vertices[i].Traits.SelectedFlag = 
                 ToolKey(mesh.Vertices[i].Traits.SelectedFlag,flag);
            
         }
     } 
 }
Exemplo n.º 13
0
        protected void SelectFaceByRect(bool laser)
        {
            Vector2D minV = GraphicResearchHuiZhao.Vector2D.Min(mouseDownPos, mouseCurrPos);
            Vector2D size = GraphicResearchHuiZhao.Vector2D.Max(mouseDownPos, mouseCurrPos) - minV;
            CRectangle rect = new CRectangle((int)minV.x, (int)minV.y, (int)size.x, (int)size.y);
            CRectangle viewport = new CRectangle(0, 0,  Width,  Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh m = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;


            for (int i = 0; i < m.Faces.Count; i++)
            {

                Vector3D v1 = projector.Project(m.Faces[i].GetVertex(0).Traits.Position);
                Vector3D v2 = projector.Project(m.Faces[i].GetVertex(1).Traits.Position);
                Vector3D v3 = projector.Project(m.Faces[i].GetVertex(2).Traits.Position);

                if (viewport.Contains((int)v1.x, (int)v1.y) && viewport.Contains((int)v2.x, (int)v2.y) && viewport.Contains((int)v3.x, (int)v3.y))
                {
                    bool flag = rect.Contains((int)v1.x, (int)v1.y) && rect.Contains((int)v2.x, (int)v2.y) && rect.Contains((int)v3.x, (int)v3.y);

                    laser = ToolLaser();
                    flag &= (laser || projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z >= eps);

                    m.Faces[i].Traits.SelectedFlag = ToolKey(m.Faces[i].Traits.SelectedFlag,flag);
                     

                }
            }
        }
Exemplo n.º 14
0
        protected void SelectFaceByCircle(bool laser)
        {

            double radius = (mouseDownPos - mouseCurrPos).Length() / 2;
            Vector2D center = mouseDownPos + (mouseCurrPos - mouseDownPos) / 2;
            CRectangle viewport = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh m = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;


            for (int i = 0; i < m.Faces.Count; i++)
            {

                Vector3D v1 = projector.Project(m.Faces[i].GetVertex(0).Traits.Position);
                Vector3D v2 = projector.Project(m.Faces[i].GetVertex(1).Traits.Position);
                Vector3D v3 = projector.Project(m.Faces[i].GetVertex(2).Traits.Position);

                Vector2D u1 = new Vector2D(v1.x, v1.y);
                Vector2D u2 = new Vector2D(v2.x, v2.y);
                Vector2D u3 = new Vector2D(v3.x, v3.y);

                if (viewport.Contains((int)v1.x, (int)v1.y) && viewport.Contains((int)v2.x, (int)v2.y) && viewport.Contains((int)v3.x, (int)v3.y))
                {
                    bool flag = (u1 - center).Length() <= radius && (u2 - center).Length() <= radius && (u3 - center).Length() <= radius;

                    laser = ToolLaser();
                    flag &= (laser || projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z >= eps);

                    m.Faces[i].Traits.SelectedFlag=ToolKey(m.Faces[i].Traits.SelectedFlag, flag);
                     

                }
            }
                

            
        }
Exemplo n.º 15
0
        protected void SelectVertexByCircle(bool laser)
        { 
            double radius = (mouseDownPos - mouseCurrPos).Length()/2;
            Vector2D center = mouseDownPos+(mouseCurrPos - mouseDownPos) / 2;
            CRectangle viewport = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();  
            double eps = ToolSetting.ToolsSetting.DepthTolerance; 

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                Vector3D v = projector.Project(mesh.Vertices[i].Traits.Position);
                Vector2D u = new Vector2D(v.x, v.y);
                if (viewport.Contains((int)v.x, (int)v.y))
                {
                    bool flag = (u - center).Length() <= radius; 
                    laser = ToolLaser();
                    flag &= (laser || 
                        projector.GetDepthValue((int)v.x, (int)v.y) - v.z >= eps);
                    mesh.Vertices[i].Traits.SelectedFlag = 
                        ToolKey(mesh.Vertices[i].Traits.SelectedFlag,flag);

                }
            } 
        }
Exemplo n.º 16
0
        protected int SelectFaceByPoint(bool laser)
        {
            CRectangle      viewport  = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh         m         = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;

            bool isInFace = false;
            int  minIndex = -1;

            for (int i = 0; i < m.Faces.Count; i++)
            {
                Vector3D v1 = projector.Project(m.Faces[i].GetVertex(0).Traits.Position);
                Vector3D v2 = projector.Project(m.Faces[i].GetVertex(1).Traits.Position);
                Vector3D v3 = projector.Project(m.Faces[i].GetVertex(2).Traits.Position);


                Vector2D u1 = new GraphicResearchHuiZhao.Vector2D(v1.x, v1.y);
                Vector2D u2 = new GraphicResearchHuiZhao.Vector2D(v2.x, v2.y);
                Vector2D u3 = new GraphicResearchHuiZhao.Vector2D(v3.x, v3.y);

                if (!viewport.Contains((int)v1.x, (int)v1.y) && !viewport.Contains((int)v2.x, (int)v2.y) && !viewport.Contains((int)v2.x, (int)v2.y))
                {
                    continue;
                }

                //  if (!laser && projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z < eps) continue;
                //isInFace=PointinTriangle(u1,u2,u3,mouseCurrPos);
                isInFace = IsInTriangle(u1, u2, u3, mouseCurrPos);
                if (isInFace)
                {
                    minIndex = i;
                }
            }
            if (minIndex == -1)
            {
                return(minIndex);
            }



            if (key == EnumKey.Shift)
            {
                m.Faces[minIndex].Traits.SelectedFlag = (byte)1;
            }
            else if (key == EnumKey.Ctrl)
            {
                m.Faces[minIndex].Traits.SelectedFlag = (byte)0;
            }
            else
            {
                for (int i = 0; i < m.Faces.Count; i++)
                {
                    m.Faces[i].Traits.SelectedFlag = (byte)0;
                }


                m.Faces[minIndex].Traits.SelectedFlag = (byte)1;
            }
            return(minIndex);
        }