Esempio n. 1
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]);
                    }
                }
            }
        }
Esempio n. 2
0
        public void CombineTwoPolys()
        {
            UpdateMarkedCounts();
            if (num_marked_polys == 2)
            {
                List <DPoly> polys = GetMarkedPolys();

                if (DPoly.HasTwoOrMoreSharedVerts(polys[0], polys[1]))
                {
                    if (Vector3.Dot(DPoly.CalculatePolyNormal(polys[0], this), DPoly.CalculatePolyNormal(polys[1], this)) > 0.8f)
                    {
                        // Align the UVs
                        polys[1].UVAlignToPoly(polys[0], this);

                        // Add verts from c_polys[1] to c_polys[0]
                        for (int i = 0; i < polys[1].num_verts; i++)
                        {
                            if (!polys[0].vert.Contains(polys[1].vert[i]))
                            {
                                polys[0].AddVert(polys[1].vert[i], polys[1].normal[i], polys[1].tex_uv[i]);
                            }
                        }

                        // Sort the verts in c_polys[0]
                        polys[0].ReSortVerts(this);

                        // Delete c_polys[1]
                        polygon.Remove(polys[1]);
                    }
                    else
                    {
                        editor.AddOutputText("Polys aren't planar enough, cannot combine");
                    }
                }
                else
                {
                    editor.AddOutputText("Polys don't share two verts, cannot combine");
                }
            }
            else
            {
                editor.AddOutputText("Must mark exactly two polys to combine");
            }
        }
Esempio n. 3
0
        public void SwitchTriEdge()
        {
            List <DPoly> polys = GetMarkedPolys();

            if (polys.Count == 2 && polys[0].num_verts == 3 && polys[1].num_verts == 3)
            {
                if (DPoly.HasTwoOrMoreSharedVerts(polys[0], polys[1]))
                {
                    List <int> vrts = new List <int>();

                    // Save off an unshared vert index
                    int unshared_vert = polys[0].vert[0];
                    for (int i = 0; i < 3; i++)
                    {
                        if (polys[1].vert.Contains(polys[0].vert[i]))
                        {
                            unshared_vert = polys[0].vert[i];
                        }
                    }

                    // Combine the two polygons
                    CombineTwoPolys();

                    // Shift the vert order by 1 (maybe) to ensure that when you triangulate the polygon, it is split the other way)
                    polys = GetMarkedPolys();
                    polys[0].MaybeShiftVerts(unshared_vert);

                    // Triangulate and mark the polygons
                    PolysTriangulateVert(true);
                }
                else
                {
                    editor.AddOutputText("Polys don't share two verts, cannot switch edge");
                }
            }
            else
            {
                editor.AddOutputText("Must mark two triangles");
            }
        }
        public void TagCoplanarConnectedPolys(DPoly p, float angle_tol, bool recursive = false)
        {
            float angle;

            for (int i = 0; i < polygon.Count; i++)
            {
                if (!polygon[i].tag)
                {
                    if (DPoly.HasTwoOrMoreSharedVerts(polygon[i], p))
                    {
                        angle = Vector3.CalculateAngle(DPoly.CalculatePolyNormal(polygon[i], this), DPoly.CalculatePolyNormal(p, this));
                        if (angle <= angle_tol)
                        {
                            polygon[i].tag = true;
                            if (recursive)
                            {
                                TagCoplanarConnectedPolys(polygon[i], angle_tol, true);
                            }
                        }
                    }
                }
            }
        }