Example #1
0
        private void checkSelect()
        {
            if (selecting)
            {
                Vector2 m = getMouseOnViewPort();
                if (!m.Equals(new Vector2(sx1, sy1)))
                {
                    // select group of vertices
                    float minx   = Math.Min(sx1, m.X);
                    float miny   = Math.Min(sy1, m.Y);
                    float width  = Math.Abs(sx1 - m.X);
                    float height = Math.Abs(sy1 - m.Y);

                    foreach (ModelContainer con in draw)
                    {
                        foreach (NUD.Mesh mesh in con.nud.meshes)
                        {
                            foreach (NUD.Polygon poly in mesh.Nodes)
                            {
                                //if (!poly.IsSelected && !mesh.IsSelected) continue;
                                int i = 0;
                                foreach (NUD.Vertex v in poly.vertices)
                                {
                                    poly.selectedVerts[i] = 0;
                                    Vector3 n = getScreenPoint(v.pos);
                                    if (n.X >= minx && n.Y >= miny && n.X <= minx + width && n.Y <= miny + height)
                                    {
                                        poly.selectedVerts[i] = 1;
                                    }
                                    i++;
                                }
                            }
                        }
                    }
                }
                else
                {
                    // single vertex
                    Ray     r     = RenderTools.createRay(view, getMouseOnViewPort());
                    Vector3 close = Vector3.Zero;
                    foreach (ModelContainer con in draw)
                    {
                        foreach (NUD.Mesh mesh in con.nud.meshes)
                        {
                            foreach (NUD.Polygon poly in mesh.Nodes)
                            {
                                //if (!poly.IsSelected && !mesh.IsSelected) continue;
                                int i = 0;
                                foreach (NUD.Vertex v in poly.vertices)
                                {
                                    if (!poly.IsSelected)
                                    {
                                        continue;
                                    }
                                    if (r.TrySphereHit(v.pos, 0.2f, out close))
                                    {
                                        poly.selectedVerts[i] = 1;
                                    }
                                    i++;
                                }
                            }
                        }
                    }
                }

                vertexTool.refresh();
                selecting = false;
            }
        }
Example #2
0
        private void checkSelect()
        {
            if (CurrentMode == Mode.Selection)
            {
                Vector2 m = GetMouseOnViewport();
                if (!m.Equals(new Vector2(sx1, sy1)))
                {
                    // select group of vertices
                    float minx   = Math.Min(sx1, m.X);
                    float miny   = Math.Min(sy1, m.Y);
                    float width  = Math.Abs(sx1 - m.X);
                    float height = Math.Abs(sy1 - m.Y);

                    foreach (TreeNode node in draw)
                    {
                        if (!(node is ModelContainer))
                        {
                            continue;
                        }
                        ModelContainer con = (ModelContainer)node;
                        foreach (NUD.Mesh mesh in con.NUD.Nodes)
                        {
                            foreach (NUD.Polygon poly in mesh.Nodes)
                            {
                                //if (!poly.IsSelected && !mesh.IsSelected) continue;
                                int i = 0;
                                foreach (NUD.Vertex v in poly.vertices)
                                {
                                    if (!OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.ControlLeft))
                                    {
                                        poly.selectedVerts[i] = 0;
                                    }
                                    Vector3 n = getScreenPoint(v.pos);
                                    if (n.X >= minx && n.Y >= miny && n.X <= minx + width && n.Y <= miny + height)
                                    {
                                        poly.selectedVerts[i] = 1;
                                    }
                                    i++;
                                }
                            }
                        }
                    }
                }
                else
                {
                    // single vertex
                    // Selects the closest vertex
                    Ray     r     = RenderTools.createRay(Camera.getMVPMatrix(), GetMouseOnViewport());
                    Vector3 close = Vector3.Zero;
                    foreach (TreeNode node in draw)
                    {
                        if (!(node is ModelContainer))
                        {
                            continue;
                        }
                        ModelContainer con    = (ModelContainer)node;
                        NUD.Polygon    Close  = null;
                        int            index  = 0;
                        double         mindis = 999;
                        foreach (NUD.Mesh mesh in con.NUD.Nodes)
                        {
                            foreach (NUD.Polygon poly in mesh.Nodes)
                            {
                                //if (!poly.IsSelected && !mesh.IsSelected) continue;
                                int i = 0;
                                foreach (NUD.Vertex v in poly.vertices)
                                {
                                    //if (!poly.IsSelected) continue;
                                    if (!OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.ControlLeft))
                                    {
                                        poly.selectedVerts[i] = 0;
                                    }

                                    if (r.TrySphereHit(v.pos, 0.2f, out close))
                                    {
                                        double dis = r.Distance(close);
                                        if (dis < mindis)
                                        {
                                            mindis = dis;
                                            Close  = poly;
                                            index  = i;
                                        }
                                    }
                                    i++;
                                }
                            }
                        }
                        if (Close != null)
                        {
                            Close.selectedVerts[index] = 1;
                        }
                    }
                }

                VertexTool.vertexListBox.BeginUpdate();
                VertexTool.vertexListBox.Items.Clear();
                foreach (TreeNode node in draw)
                {
                    if (!(node is ModelContainer))
                    {
                        continue;
                    }
                    ModelContainer con = (ModelContainer)node;
                    foreach (NUD.Mesh mesh in con.NUD.Nodes)
                    {
                        foreach (NUD.Polygon poly in mesh.Nodes)
                        {
                            int i = 0;
                            foreach (NUD.Vertex v in poly.vertices)
                            {
                                if (poly.selectedVerts[i++] == 1)
                                {
                                    VertexTool.vertexListBox.Items.Add(v);
                                }
                            }
                        }
                    }
                }
                VertexTool.vertexListBox.EndUpdate();
                CurrentMode = Mode.Normal;
            }
        }