Esempio n. 1
0
        public Vector3 HalfVectorToB(LineData other)
        {
            LineData LineA = this;
            LineData LineB = other;

            if (other.pnts[1] == pnts[0])
            {
                LineA = other;
                LineB = this;
            }

            Vector3 a = LineA.pnts[0].Pos - LineA.pnts[1].Pos;
            Vector3 b = LineB.pnts[1].Pos - LineB.pnts[0].Pos;


            Vector2 fromVector2 = GridNavigator.Inst().InPlaneVector(a);
            Vector2 toVector2   = GridNavigator.Inst().InPlaneVector(b);


            Vector2 mid = (fromVector2.normalized + toVector2.normalized).normalized;

            Vector3 cross = Vector3.Cross(fromVector2, toVector2);

            if (cross.z > 0)
            {
                mid = -mid;
            }



            return(GridNavigator.Inst().PlaneToWorldVector(mid).normalized);
        }
Esempio n. 2
0
        void ProcessPointOnALine(Vertex a, Vertex b, Triangle t)
        {
            if (EditorInputManager.GetMouseButtonDown(1))
            {
                SelectedLine = new LineData(t, a, b);
                UpdateLocalSpaceV3s();
            }

            PointedLine = new LineData(t, new Vertex[] { a, b });
        }
Esempio n. 3
0
        public LineData[] GetLinesFor(Vertex pnt)
        {
            LineData[] ld = new LineData[2];
            int        no = NumberOf(pnt);

            ld[0] = new LineData(this, new Vertex[] { vertexes[no], vertexes[(no + 1) % 3] });
            ld[1] = new LineData(this, new Vertex[] { vertexes[(no + 2) % 3], vertexes[no] });

            return(ld);
        }
Esempio n. 4
0
        public void DeleteLine(LineData ld)
        {
            NullPoinedSelected();

            edMesh.RemoveLine(ld);

            if (IsInTrisSet(ld.pnts[0]) || IsInTrisSet(ld.pnts[1]))
            {
                TrisVerts = 0;
            }
        }
Esempio n. 5
0
        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType() != typeof(LineData))
            {
                return(false);
            }

            LineData ld = (LineData)obj;

            return((ld.pnts[0].meshPoint == pnts[0].meshPoint && ld.pnts[1].meshPoint == pnts[1].meshPoint) ||
                   (ld.pnts[0].meshPoint == pnts[1].meshPoint && ld.pnts[1].meshPoint == pnts[0].meshPoint));
        }
Esempio n. 6
0
        public Vertex GetNotOneIn(LineData l)
        {
            for (int i = 0; i < 3; i++)
            {
                if ((vertexes[i].meshPoint != l.pnts[0].meshPoint) && (vertexes[i].meshPoint != l.pnts[1].meshPoint))
                {
                    return(vertexes[i]);
                }
            }

            return(vertexes[0]);
        }
Esempio n. 7
0
        public int GetIndexOfNoOneIn(LineData l)
        {
            for (int i = 0; i < 3; i++)
            {
                if ((vertexes[i].meshPoint != l.pnts[0].meshPoint) && (vertexes[i].meshPoint != l.pnts[1].meshPoint))
                {
                    return(i);
                }
            }

            return(0);
        }
Esempio n. 8
0
        public void RemoveLine(LineData ld)
        {
            Vertex a = ld.pnts[0];
            Vertex b = ld.pnts[1];

            for (int i = 0; i < triangles.Count; i++)
            {
                if (triangles[i].Includes(a.meshPoint, b.meshPoint))
                {
                    triangles.Remove(triangles[i]);
                    i--;
                }
            }
        }
Esempio n. 9
0
        public void GiveLineUniqueVerticles_RefreshTrisListing(LineData ld)
        {
            List <Triangle> trs = ld.GetAllTriangles_USES_Tris_Listing();

            if (trs.Count != 2)
            {
                return;
            }

            ld.pnts[0].meshPoint.SmoothNormal = true;
            ld.pnts[1].meshPoint.SmoothNormal = true;

            trs[0].GiveUniqueVerticesAgainst(trs[1]);
            RefresVerticleTrisList();
        }
Esempio n. 10
0
 public bool Includes(LineData ld) => (Includes(ld.pnts[0].meshPoint) && (Includes(ld.pnts[1].meshPoint)));
Esempio n. 11
0
 public void ClearLastPointed()
 {
     LastFramePointedUV   = null;
     LastFramePointedLine = null;
     LastFramePointedTris = null;
 }
Esempio n. 12
0
 public void SetLastPointed(LineData l)
 {
     ClearLastPointed();
     LastFramePointedLine = l;
 }
Esempio n. 13
0
        public static void PutEdgeOnLine(LineData ld)
        {
            var vrtA = ld.pnts[0].meshPoint;
            var vrtB = ld.pnts[1].meshPoint;

            var tris = ld.GetAllTriangles_USES_Tris_Listing();

            foreach (var t in tris)
            {
                t.edgeWeight[t.GetIndexOfNoOneIn(ld)] = ShiftInvertedVelue;// true;
            }
            float edValA = ShiftInvertedVelue;
            float edValB = ShiftInvertedVelue;

            if (editingFlexibleEdge)
            {
                foreach (var uv in vrtA.uvpoints)
                {
                    foreach (var t in uv.tris)
                    {
                        var opposite = t.NumberOf(uv);
                        for (int i = 0; i < 3; i++)
                        {
                            if (opposite != i)
                            {
                                edValA = Mathf.Max(edValA, t.edgeWeight[i]);
                            }
                        }
                    }
                }

                foreach (var uv in vrtB.uvpoints)
                {
                    foreach (var t in uv.tris)
                    {
                        var opposite = t.NumberOf(uv);
                        for (int i = 0; i < 3; i++)
                        {
                            if (opposite != i)
                            {
                                edValB = Mathf.Max(edValB, t.edgeWeight[i]);
                            }
                        }
                    }
                }
            }

            vrtA.edgeStrength = edValA;
            vrtB.edgeStrength = edValB;

            if (AlsoDoColor)
            {
                var col = GlobalBrush.colorLinear.ToGamma();
                foreach (Vertex uvi in vrtA.uvpoints)
                {
                    GlobalBrush.mask.Transfer(ref uvi._color, col);
                }
                foreach (Vertex uvi in vrtB.uvpoints)
                {
                    GlobalBrush.mask.Transfer(ref uvi._color, col);
                }
            }

            MeshMGMT.edMesh.Dirty = true;
        }
Esempio n. 14
0
        public void QUICK_G_Functions()
        {
            var pointedTris = MeshMGMT.PointedTris;
            var pointedLine = MeshMGMT.PointedLine;
            var pointedUV   = MeshMGMT.PointedUV;

            switch (QuickMeshFunctionsExtensions.current)
            {
            case QuickMeshFunctions.DeleteTrianglesFully:
                if ((Input.GetKey(KeyCode.G)) && (pointedTris != null))
                {
                    foreach (Vertex uv in pointedTris.vertexes)
                    {
                        if ((uv.meshPoint.uvpoints.Count == 1) && (uv.tris.Count == 1))
                        {
                            EditedMesh.meshPoints.Remove(uv.meshPoint);
                        }
                    }

                    EditedMesh.triangles.Remove(pointedTris);

                    /*pointedTris = null;
                    *  pointedUV = null;
                    *  selectedUV = null;
                    *  pointedLine = null;*/
                    EditedMesh.Dirty = true;
                }
                break;

            case QuickMeshFunctions.Line_Center_Vertex_Add:
                if ((Input.GetKeyDown(KeyCode.G)) && (pointedLine != null))
                {
                    Vector3 tmp = pointedLine.pnts[0].Pos;
                    tmp += (pointedLine.pnts[1].Pos - pointedLine.pnts[0].Pos) / 2;
                    EditedMesh.InsertIntoLine(pointedLine.pnts[0].meshPoint, pointedLine.pnts[1].meshPoint, tmp);
                }
                break;

            case QuickMeshFunctions.TrisColorForBorderDetection:
                if (Input.GetKeyDown(KeyCode.G))
                {
                    Debug.Log("Pointed Line null: " + (pointedLine == null));

                    if (pointedTris != null)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            pointedTris.vertexes[i].tmpMark = false;
                        }
                        bool[]  found = new bool[3];
                        Color[] cols  = new Color[3];
                        cols[0] = new Color(0, 1, 1, 1);
                        cols[1] = new Color(1, 0, 1, 1);
                        cols[2] = new Color(1, 1, 0, 1);

                        for (int j = 0; j < 3; j++)
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                if ((!found[j]) && (pointedTris.vertexes[i]._color == cols[j]))
                                {
                                    pointedTris.vertexes[i].tmpMark = true;
                                    found[j] = true;
                                }
                            }
                        }

                        for (int j = 0; j < 3; j++)
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                if ((!found[j]) && (!pointedTris.vertexes[i].tmpMark))
                                {
                                    pointedTris.vertexes[i].tmpMark = true;
                                    pointedTris.vertexes[i]._color  = cols[j];
                                    found[j] = true;
                                }
                            }
                        }


                        EditedMesh.Dirty = true;
                    }
                    else if (pointedLine != null)
                    {
                        Vertex a        = pointedLine.pnts[0];
                        Vertex b        = pointedLine.pnts[1];
                        Vertex lessTris = (a.tris.Count < b.tris.Count) ? a : b;

                        if ((a._color.r > 0.9f) && (b._color.r > 0.9f))
                        {
                            lessTris._color.r = 0;
                        }
                        else if ((a._color.g > 0.9f) && (b._color.g > 0.9f))
                        {
                            lessTris._color.g = 0;
                        }
                        else if ((a._color.b > 0.9f) && (b._color.b > 0.9f))
                        {
                            lessTris._color.b = 0;
                        }

                        EditedMesh.Dirty = true;
                    }
                }
                break;

            case QuickMeshFunctions.Path:
                // if (selectedLine != null)
                //   VertexLine(selectedLine.pnts[0].vert, selectedLine.pnts[1].vert, new Color(0.7f, 0.8f, 0.5f, 1));
                if (Input.GetKeyDown(KeyCode.G))
                {
                    if (updated)
                    {
                        ExtendPath();
                    }
                    else
                    {
                        SetPathStart();
                    }
                }



                break;

            case QuickMeshFunctions.MakeOutline:
                if ((Input.GetKeyDown(KeyCode.G)) && (pointedUV != null))
                {
                    //	_Mesh.RefresVerticleTrisList();
                    List <LineData> AllLines = pointedUV.meshPoint.GetAllLines_USES_Tris_Listing();


                    int        linesFound = 0;
                    LineData[] lines      = new LineData[2];


                    for (int i = 0; i < AllLines.Count; i++)
                    {
                        if (AllLines[i].trianglesCount == 0)
                        {
                            if (linesFound < 2)
                            {
                                lines[linesFound] = AllLines[i];
                            }
                            else
                            {
                                return;
                            }
                            linesFound++;
                        }
                    }

                    if (linesFound == 2)
                    {
                        Vector3 norm = lines[0].HalfVectorToB(lines[1]);

                        MeshPoint hold = new MeshPoint(pointedUV.Pos);

                        if (MeshMGMT.SelectedUV != null)
                        {
                            new Vertex(hold, MeshMGMT.SelectedUV.GetUV(0), MeshMGMT.SelectedUV.GetUV(1));
                        }
                        else
                        {
                            new Vertex(hold);
                        }

                        MeshMGMT.edMesh.meshPoints.Add(hold);
                        MeshMGMT.MoveVertexToGrid(hold);
                        hold.localPos += norm * outlineWidth;

                        Vertex[] tri = new Vertex[3];

                        for (int i = 0; i < 2; i++)
                        {
                            tri[0] = hold.uvpoints[0];
                            tri[1] = lines[i].pnts[1];
                            tri[2] = lines[i].pnts[0];

                            MeshMGMT.edMesh.triangles.Add(new Triangle(tri));
                        }

                        MeshMGMT.edMesh.Dirty = true;
                    }
                }

                break;
            }
        }
Esempio n. 15
0
        void ExtendPath()
        {
            var selectedLine = MeshMGMT.SelectedLine;
            var mm           = MeshMGMT;

            if (updated == false)
            {
                return;
            }
            if (selectedLine == null)
            {
                updated = false; return;
            }

            MeshMGMT.UpdateLocalSpaceV3s();

            Vector3 previousCenterPos = selectedLine.pnts[0].Pos;

            Vector3 previousAB = selectedLine.pnts[1].Pos - selectedLine.pnts[0].Pos;

            previousCenterPos += (previousAB / 2);



            Vector3 vector   = mm.onGridLocal - previousCenterPos;
            float   distance = vector.magnitude;

            MeshPoint a = new MeshPoint(selectedLine.pnts[0].Pos);
            MeshPoint b = new MeshPoint(selectedLine.pnts[1].Pos);

            EditedMesh.meshPoints.Add(a);
            EditedMesh.meshPoints.Add(b);

            Vertex aUV = new Vertex(a, selectedLine.pnts[0].EditedUV + uvChangeSpeed * distance);
            Vertex bUV = new Vertex(b, selectedLine.pnts[1].EditedUV + uvChangeSpeed * distance);



            EditedMesh.triangles.Add(new Triangle(new Vertex[] { selectedLine.pnts[0], bUV, selectedLine.pnts[1] }));
            Triangle headTris = new Triangle(new Vertex[] { selectedLine.pnts[0], aUV, bUV });

            EditedMesh.triangles.Add(headTris);

            //

            switch (mode)
            {
            case GtoolPathConfig.ToPlanePerpendicular:
                //vector = previousCenterPos.DistanceV3To(ptdPos);

                a.localPos = mm.onGridLocal;
                b.localPos = mm.onGridLocal;


                Vector3 cross = Vector3.Cross(vector, GridNavigator.Inst().GetGridPerpendicularVector()).normalized *width / 2;
                a.localPos += cross;
                b.localPos += -cross;



                break;

            case GtoolPathConfig.Rotate:
                // Vector3 ab = a.pos.DistanceV3To(b.pos).normalized * gtoolPath.width;

                a.localPos = mm.onGridLocal;
                b.localPos = mm.onGridLocal;



                Quaternion rot   = Quaternion.FromToRotation(previousAB, vector);
                Vector3    rotv3 = (rot * vector).normalized * width / 2;
                a.localPos += rotv3;
                b.localPos += -rotv3;


                break;

            case GtoolPathConfig.AsPrevious:
                a.localPos += vector;
                b.localPos += vector;
                break;
            }

            PrevDirection = vector;

            selectedLine = new LineData(headTris, aUV, bUV);

            mm.edMesh.Dirty = true;
        }
Esempio n. 16
0
 public bool SameVerticles(LineData other) => (((other.pnts[0].meshPoint == pnts[0].meshPoint) && (other.pnts[1].meshPoint == pnts[1].meshPoint)) ||
                                               ((other.pnts[0].meshPoint == pnts[1].meshPoint) && (other.pnts[1].meshPoint == pnts[0].meshPoint)));
Esempio n. 17
0
 public static bool Contains(this List <MeshPoint> lst, LineData ld) => lst.Contains(ld.pnts[0].meshPoint) && lst.Contains(ld.pnts[1].meshPoint);