Example #1
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;
            }
        }
Example #2
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;
        }