public void TagPolyVerts(DPoly dp)
 {
     for (int i = 0; i < dp.vert.Count; i++)
     {
         vert_info[dp.vert[i]].tag = true;
     }
 }
Ejemplo n.º 2
0
        public void PolysTriangulateFan(bool mark_them = false)
        {
            List <DPoly> polys = GetMarkedPolys();

            for (int i = 0; i < polys.Count; i++)
            {
                // Add the center as a vert
                int     center_vert = vertex.Count;
                Vector3 center_pos  = polys[i].FindCenter(this);
                Vector2 center_uv   = polys[i].FindUVCenter();
                AddVertexEditor(center_pos, false);

                // Create a new triangle for each vert
                List <int> vrts = new List <int>();
                for (int j = 0; j < polys[i].vert.Count; j++)
                {
                    vrts.Clear();
                    vrts.Add(center_vert);
                    vrts.Add(polys[i].vert[j]);
                    vrts.Add(polys[i].vert[(j + 1) % polys[i].vert.Count]);
                    DPoly dp = new DPoly(vrts, polys[i].tex_index, this, false);
                    dp.tex_uv[0] = center_uv;
                    dp.tex_uv[1] = polys[i].tex_uv[j];
                    dp.tex_uv[2] = polys[i].tex_uv[(j + 1) % polys[i].vert.Count];
                    dp.marked    = mark_them;
                    polygon.Add(dp);
                }
            }

            // Remove the old polys
            for (int i = 0; i < polys.Count; i++)
            {
                polygon.Remove(polys[i]);
            }
        }
        public void CopyPolygonSameVerts(DPoly src_dp)
        {
            DPoly new_dp = new DPoly(src_dp);

            polygon.Add(new_dp);
            new_dp.marked = src_dp.marked;
        }
Ejemplo n.º 4
0
        // Can you combine this poly with the passed in one
        public static bool CanCombinePolys(DPoly p1, DPoly p2, DMesh dm)
        {
            // First check for two shared verts
            int count = 0;

            for (int i = 0; i < p1.num_verts; i++)
            {
                for (int j = 0; j < p2.num_verts; j++)
                {
                    if (p1.vert[i] == p2.vert[j])
                    {
                        count += 1;
                    }
                }
            }

            if (count != 2)
            {
                return(false);
            }

            // Check for normals that align
            Vector3 n1 = CalculatePolyNormal(p1, dm);
            Vector3 n2 = CalculatePolyNormal(p2, dm);

            if (Vector3.Dot(n1, n2) >= 0.995f)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void BuildMarkedGeometry()
        {
            GL.PushMatrix();
            GL.DeleteLists(GL_MARKED, 1);
            GL.NewList(GL_MARKED, ListMode.Compile);

            {
                for (int i = 0; i < editor.m_dmesh.polygon.Count; i++)
                {
                    DPoly dp = editor.m_dmesh.polygon[i];
                    if (dp.marked)
                    {
                        GL.Begin(PrimitiveType.Polygon);
                        GL.Color3(C_marked);
                        CreatePolygon(dp, editor.m_dmesh);
                        GL.End();
                    }
                }

                // Verts
                GL.Begin(PrimitiveType.Points);
                GL.Color3(C_marked);
                for (int i = 0; i < editor.m_dmesh.vertex.Count; i++)
                {
                    if (editor.m_dmesh.vert_info[i].marked)
                    {
                        CreateVertexPoint(editor.m_dmesh.vertex[i]);
                    }
                }
                GL.End();
            }

            GL.EndList();
            GL.PopMatrix();
        }
Ejemplo n.º 6
0
        public void PolysTriangulateVert(bool mark_them = false)
        {
            List <DPoly> polys = GetMarkedPolys();

            for (int i = 0; i < polys.Count; i++)
            {
                // Create a new triangle for each vert - 2
                List <int> vrts = new List <int>();
                for (int j = 1; j < polys[i].vert.Count - 1; j++)
                {
                    vrts.Clear();
                    vrts.Add(polys[i].vert[0]);
                    vrts.Add(polys[i].vert[j]);
                    vrts.Add(polys[i].vert[j + 1]);
                    DPoly dp = new DPoly(vrts, polys[i].tex_index, this, false);
                    dp.tex_uv[0] = polys[i].tex_uv[0];
                    dp.tex_uv[1] = polys[i].tex_uv[j];
                    dp.tex_uv[2] = polys[i].tex_uv[j + 1];
                    dp.marked    = mark_them;
                    polygon.Add(dp);
                }
            }

            // Remove the old polys
            for (int i = 0; i < polys.Count; i++)
            {
                polygon.Remove(polys[i]);
            }
        }
Ejemplo n.º 7
0
		public void CreatePolygon(DPoly poly, DMesh mesh)
		{
			for (int i = 0; i < poly.num_verts; i++) {
				GL.TexCoord2(poly.tex_uv[i]);
				GL.Normal3(poly.normal[i]);
				GL.Vertex3(mesh.vertex[poly.vert[i]]);
			}
		}
Ejemplo n.º 8
0
        public static Vector3 CalculatePolyNormal(DPoly p, DMesh dm)
        {
            Vector3 n = Vector3.Zero;

            n = Utility.FindNormal(dm.vertex[p.vert[0]], dm.vertex[p.vert[1]], dm.vertex[p.vert[2]]);

            return(n);
        }
Ejemplo n.º 9
0
		public void CreateVertNormals(DPoly poly, DMesh mesh)
		{
			Vector3 v;
			for (int i = 0; i < poly.num_verts; i++) {
				v = mesh.vertex[poly.vert[i]];
				CreateLine(v, v + poly.normal[i] * 0.1f);
			}
		}
        public void CopyMarkedPolys(DMesh src, bool all = false, bool tag_new = false)
        {
            // Tag all the src verts in marked polys
            List <int> old_vert_index = new List <int>();
            List <int> new_vert_index = new List <int>();

            src.TagAllVerts(false);
            ClearAllMarkedPoly();

            foreach (DPoly dp in src.polygon)
            {
                if (dp.marked || all)
                {
                    for (int i = 0; i < dp.num_verts; i++)
                    {
                        src.vert_info[dp.vert[i]].tag = true;
                    }
                }
            }

            // Copy all tagged verts to me
            // - And create lists for conversion
            for (int i = 0; i < src.vertex.Count; i++)
            {
                if (src.vert_info[i].tag)
                {
                    old_vert_index.Add(i);
                    new_vert_index.Add(vertex.Count);
                    vertex.Add(src.vertex[i]);
                    vert_info.Add(new DVert());
                }
            }

            // Copy all marked polys to me (converting vert idxs in process)
            foreach (DPoly old_dp in src.polygon)
            {
                if (old_dp.marked || all)
                {
                    DPoly new_dp = new DPoly(old_dp);
                    polygon.Add(new_dp);
                    new_dp.marked = true;
                    new_dp.tag    = tag_new;
                    for (int i = 0; i < new_dp.num_verts; i++)
                    {
                        int old_index = new_dp.vert[i];
                        old_index = FindIdxInList(old_index, old_vert_index);
                        if (old_index > -1 && old_index < new_vert_index.Count)
                        {
                            new_dp.vert[i] = new_vert_index[old_index];
                        }
                        else
                        {
                            Utility.DebugPopup("This is bad, copy-paste failed", "ERROR!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public void ConvertTrisToPolysRaw()
 {
     polygon.Clear();
     foreach (DTriangle t in triangle)
     {
         DPoly p = new DPoly(t);
         polygon.Add(p);
     }
 }
Ejemplo n.º 12
0
        public void ExtrudeMarkedVerts(float dist)
        {
            List <int> verts = GetMarkedVerts();

            if (verts.Count > 1)
            {
                ClearAllMarkedPoly();

                // Figure out which direction to go (lesser of X/Y/Z)
                Vector3 min, max;
                GetVertBounds(verts, out min, out max);
                Vector3 diff        = max - min;
                Vector3 extrude_vec = (max.Y < 0f ? -Vector3.UnitY :  Vector3.UnitY);
                if (diff.X < diff.Y && diff.X < diff.Z)
                {
                    extrude_vec = (max.X < 0f ? -Vector3.UnitX : Vector3.UnitX);
                }
                else if (diff.Z < diff.Y && diff.Z < diff.X)
                {
                    extrude_vec = (max.X < 0f ? -Vector3.UnitZ : Vector3.UnitZ);
                }
                extrude_vec *= dist;

                int first_vert = vertex.Count;
                // Create the new verts in the extrude direction
                foreach (int idx in verts)
                {
                    AddVertexEditor(vertex[idx] + extrude_vec);
                }

                // Create a new polygon for each vert except the last
                List <int> v_list = new List <int>();
                for (int i = 0; i < verts.Count - 1; i++)
                {
                    v_list.Clear();
                    v_list.Add(verts[i]);
                    v_list.Add(verts[(i + 1)]);
                    v_list.Add(first_vert + (i + 1));
                    v_list.Add(first_vert + i);
                    DPoly new_poly = new DPoly(v_list, -1, this);
                    new_poly.marked = true;
                    polygon.Add(new_poly);
                }

                // Unmarked the old verts and mark the new ones
                for (int i = 0; i < verts.Count; i++)
                {
                    vert_info[verts[i]].marked       = false;
                    vert_info[first_vert + i].marked = true;
                }
            }
            else
            {
                editor.AddOutputText("Must mark at least two verts to extrude");
            }
        }
Ejemplo n.º 13
0
        public void ReverseWindingOrder()
        {
            DPoly flip_tri = new DPoly(this);

            ClearLists();
            for (int i = 0; i < num_verts; i++)
            {
                vert.Add(flip_tri.vert[num_verts - 1 - i]);
                normal.Add(flip_tri.normal[num_verts - 1 - i]);
                tex_uv.Add(flip_tri.tex_uv[num_verts - 1 - i]);
            }
        }
Ejemplo n.º 14
0
        public int FindSharedVertNotThisOne(DPoly dp, int idx)
        {
            for (int i = 0; i < num_verts; i++)
            {
                if (dp.vert.Contains(vert[i]) && vert[i] != idx)
                {
                    return(vert[i]);
                }
            }

            return(-1);
        }
Ejemplo n.º 15
0
        public void UVAlignToPoly()
        {
            if (selected_poly > -1)
            {
                TagAllPolys(false);

                DPoly dp = polygon[selected_poly];
                dp.tag = true;

                UVAlignAdjacentMarkedPolys(dp);
            }
        }
Ejemplo n.º 16
0
        public bool SharesAllVerts(DPoly dp)
        {
            for (int i = 0; i < dp.num_verts; i++)
            {
                if (!vert.Contains(dp.vert[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 17
0
        public void CreatePolyFromVerts(int v_start, int v_end)
        {
            List <int> v_idx = new List <int>();

            for (int i = v_start; i < v_end; i++)
            {
                v_idx.Add(i);
            }
            DPoly poly = new DPoly(v_idx, -1, this);

            poly.marked = true;
            polygon.Add(poly);
            num_marked_polys += 1;
        }
Ejemplo n.º 18
0
        public bool SharesSomeVerts(DPoly dp)
        {
            int count = 0;

            for (int i = 0; i < dp.num_verts; i++)
            {
                if (vert.Contains(dp.vert[i]))
                {
                    count += 1;
                }
            }

            return(count >= 1);
        }
Ejemplo n.º 19
0
        public void SplitPolygonByVerts(DPoly dp, int verts0, int verts1)
        {
            // Get the two sets of verts (those after v0, those after v1)
            List <int> verts_after0 = dp.GetVertsStartUpTo(verts0, verts1);
            List <int> verts_after1 = dp.GetVertsStartUpTo(verts1, verts0);

            // Then make a new polygon copy
            int new_poly_idx = polygon.Count;

            CopyPolygonSameVerts(dp);

            // Remove unneeded verts from both
            dp.RemoveVertList(verts_after0);
            polygon[new_poly_idx].RemoveVertList(verts_after1);
        }
Ejemplo n.º 20
0
        public void CreateTriFromVerts(int v1, int v2, int v3, bool marked = true)
        {
            List <int> v_idx = new List <int>();

            v_idx.Add(v1);
            v_idx.Add(v2);
            v_idx.Add(v3);
            DPoly poly = new DPoly(v_idx, -1, this);

            if (marked)
            {
                poly.marked       = true;
                num_marked_polys += 1;
            }
            polygon.Add(poly);
        }
Ejemplo n.º 21
0
        public void MarkDuplicatePolys()
        {
            TagAllPolys(false);
            ClearAllMarkedPoly();

            for (int i = 0; i < polygon.Count; i++)
            {
                for (int j = i + 1; j < polygon.Count; j++)
                {
                    if (DPoly.HasThreeOrMoreCloseVerts(polygon[i], polygon[j], this))
                    {
                        polygon[i].marked = true;
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public DPoly(DPoly src)
        {
            num_verts = src.num_verts;
            ClearLists();
            for (int i = 0; i < num_verts; i++)
            {
                vert.Add(src.vert[i]);
                normal.Add(src.normal[i]);
                tex_uv.Add(src.tex_uv[i]);
            }

            tex_index = src.tex_index;
            flags     = src.flags;
            smoothing = src.smoothing;
            marked    = src.marked;
        }
        public void BuildSelectedGeometry()
        {
            GL.PushMatrix();
            GL.DeleteLists(GL_SELECT, 1);
            GL.NewList(GL_SELECT, ListMode.Compile);

            {
                GL.Begin(PrimitiveType.Polygon);
                int idx = editor.m_dmesh.selected_poly;
                if (idx > -1 && idx < editor.m_dmesh.polygon.Count)
                {
                    DPoly dp = editor.m_dmesh.polygon[idx];
                    if (editor.m_edit_mode == EditMode.POLY)
                    {
                        GL.Color3(dp.marked ? C_select_marked_main : C_select_main);
                    }
                    else
                    {
                        GL.Color3(dp.marked ? C_select_marked : C_select);
                    }
                    CreatePolygon(dp, editor.m_dmesh);
                }
                GL.End();

                // Verts
                GL.Begin(PrimitiveType.Points);
                idx = editor.m_dmesh.selected_vert;
                if (idx > -1 && idx < editor.m_dmesh.vertex.Count)
                {
                    Vector3 v  = editor.m_dmesh.vertex[idx];
                    DVert   dv = editor.m_dmesh.vert_info[idx];
                    if (editor.m_edit_mode == EditMode.VERT)
                    {
                        GL.Color3(dv.marked ? C_select_marked_main : C_select_main);
                    }
                    else
                    {
                        GL.Color3(dv.marked ? C_select_marked : C_select);
                    }
                    CreateVertexPoint(v);
                }
                GL.End();
            }

            GL.EndList();
            GL.PopMatrix();
        }
Ejemplo n.º 24
0
        // Recursive alignment
        public void UVAlignAdjacentMarkedPolys(DPoly dp)
        {
            List <DPoly> poly_list = GetMarkedPolys();

            for (int i = 0; i < poly_list.Count; i++)
            {
                if (!poly_list[i].tag)
                {
                    if (DPoly.HasTwoOrMoreSharedVerts(dp, poly_list[i]))
                    {
                        poly_list[i].tag = true;
                        poly_list[i].UVAlignToPoly(dp, this);
                        UVAlignAdjacentMarkedPolys(poly_list[i]);
                    }
                }
            }
        }
        public void MaybeCutPolygon(GLView view, bool dont_cut = false)
        {
            if (m_dmesh.selected_poly > -1 && m_dmesh.selected_poly < m_dmesh.polygon.Count)
            {
                DPoly dp = m_dmesh.polygon[m_dmesh.selected_poly];
                SaveStateForUndo("Maybe cut polygon");
                Vector3 pos = ScreenToWorldPos(view.m_mouse_pos, view, false);

                if (m_cut_poly_state == 0)
                {
                    m_cut_polyvert_start = dp.GetClosestEdgeFV(view, m_dmesh, pos, -1, true);
                    m_cut_poly_state     = 1;
                }
                else
                {
                    m_cut_polyvert_end = dp.GetClosestEdgeFV(view, m_dmesh, pos, m_cut_polyvert_start);

                    int v1 = dp.vert[m_cut_polyvert_start];
                    int v2 = dp.vert[(m_cut_polyvert_start + 1) % dp.num_verts];
                    int v3 = dp.vert[m_cut_polyvert_end];
                    int v4 = dp.vert[(m_cut_polyvert_end + 1) % dp.num_verts];

                    // Add the verts
                    DPoly.AddedVert = -1;
                    dp.MaybeAddVertBetween(v1, v2, m_dmesh);
                    int new_v0 = DPoly.AddedVert;
                    DPoly.AddedVert = -1;
                    dp.MaybeAddVertBetween(v3, v4, m_dmesh);
                    int new_v1 = DPoly.AddedVert;

                    m_cut_poly_state = 0;

                    if (!dont_cut)
                    {
                        m_dmesh.SplitPolygonByVerts(dp, new_v0, new_v1);
                    }

                    AddOutputText("Cut a polygon");
                }
                RefreshGeometry(true);
            }
            else
            {
                AddOutputText("Select a polygon to cut");
            }
        }
Ejemplo n.º 26
0
        public static bool HasThreeOrMoreCloseVerts(DPoly p1, DPoly p2, DMesh dm)
        {
            int count = 0;

            for (int i = 0; i < p1.num_verts; i++)
            {
                for (int j = 0; j < p2.num_verts; j++)
                {
                    if (Utility.AlmostOverlapping(dm.vertex[p1.vert[i]], dm.vertex[p2.vert[j]]))
                    {
                        count += 1;
                    }
                }
            }

            return(count >= 3);
        }
Ejemplo n.º 27
0
        public static bool HasTwoOrMoreSharedVerts(DPoly p1, DPoly p2)
        {
            int count = 0;

            for (int i = 0; i < p1.num_verts; i++)
            {
                for (int j = 0; j < p2.num_verts; j++)
                {
                    if (p1.vert[i] == p2.vert[j])
                    {
                        count += 1;
                    }
                }
            }

            return(count >= 2);
        }
Ejemplo n.º 28
0
 public void SmoothSharedVerts(DPoly dp)
 {
     should_normalize    = true;
     dp.should_normalize = true;
     for (int i = 0; i < num_verts; i++)
     {
         for (int j = 0; j < dp.num_verts; j++)
         {
             // Verts match
             if (vert[i] == dp.vert[j])
             {
                 // Add the normals, these will get normalized after all are smoothed
                 normal[i]    += dp.face_normal;
                 dp.normal[j] += face_normal;
             }
         }
     }
 }
Ejemplo n.º 29
0
        public void CreateQuadFromVerts(int v1, int v2, int v3, int v4, bool marked = true, bool tagged = false)
        {
            List <int> v_idx = new List <int>();

            v_idx.Add(v1);
            v_idx.Add(v2);
            v_idx.Add(v3);
            v_idx.Add(v4);
            DPoly poly = new DPoly(v_idx, -1, this);

            poly.tag = tagged;
            if (marked)
            {
                poly.marked       = true;
                num_marked_polys += 1;
            }
            polygon.Add(poly);
        }
Ejemplo n.º 30
0
        public void DeserializePolys(JObject root)
        {
            // Just initialize vert info
            for (int i = 0; i < vertex.Count; i++)
            {
                DVert d_vert = new DVert();
                vert_info.Add(d_vert);
            }

            JObject j_polys = root["polys"].GetObject();

            foreach (var kvp in j_polys)
            {
                JObject j_poly = kvp.Value.GetObject();
                DPoly   d_poly = new DPoly(j_poly);
                polygon.Add(d_poly);
            }
        }