public override bool MouseEventPointedVertex()
        {
            if (EditorInputManager.GetMouseButtonDown(0))
            {
                MeshMGMT.AssignSelected(PointedUv); //pointedUV.editedUV = meshMGMT.selectedUV.editedUV;
                _lastCalculatedUv = PointedUv.EditedUv;
                MeshMGMT.Dragging = true;
            }

            /*
             * if (EditorInputManager.GetMouseButtonDown(0))
             * {
             *  if ((meshMGMT.selectedUV != null) && (meshMGMT.pointedUV != null))
             *  {
             *      meshMGMT.pointedUV.editedUV = meshMGMT.selectedUV.editedUV;
             *      mesh.dirty = true;
             *  }
             * }
             *
             * if ((EditorInputManager.GetMouseButtonDown(1)) && (meshMGMT.pointedUV != null) && (UVnavigator.inst() != null))
             *  UVnavigator.inst().CenterOnUV(meshMGMT.pointedUV.editedUV);
             */
            /*
             * if (ProjectionUV && EditorInputManager.GetMouseButton(0)) {
             * Vector3 trgPos = meshMGMT.target.transform.position;
             * float portion = 1f / Mathf.Max(0.01f, MeshUVprojectionSize);
             *
             * Vector2 nuv = PosToUV((vertex.worldPos - trgPos) * portion);
             *
             * for (int i = 0; i < vertex.shared_v2s.Count; i++)
             *  vertex.shared_v2s[i][meshMGMT.editedUV] = nuv;
             * }
             */
            return(false);
        }
Exemple #2
0
        public override void AssignText(MarkerWithText markers, MeshPoint point)
        {
            var selected = MeshMGMT.GetSelectedVertex();

            if (point.vertices.Count > 1 || selected == point)
            {
                if (selected == point)
                {
                    markers.textm.text = (point.vertices.Count > 1) ? (
                        Path.Combine((point.vertices.IndexOf(MeshMGMT.SelectedUv) + 1).ToString(), point.vertices.Count +
                                     (point.smoothNormal ? "s" : ""))

                        ) : "";
                }
                else
                {
                    markers.textm.text = point.vertices.Count +
                                         (point.smoothNormal ? "s" : "");
                }
            }
            else
            {
                markers.textm.text = "";
            }
        }
        public override void AssignText(MarkerWithText markers, PainterMesh.MeshPoint point)
        {
            var vrt = MeshMGMT.GetSelectedVertex();

            if (point.vertices.Count > 1 || vrt == point)
            {
                var tex = MeshEditorManager.target.meshRenderer.sharedMaterial.mainTexture;

                if (vrt == point)
                {
                    var   text  = (point.vertices.Count > 1) ? ((point.vertices.IndexOf(MeshMGMT.SelectedUv) + 1) + "/" + point.vertices.Count + (point.smoothNormal ? "s" : "")) : "";
                    float tSize = !tex ? 128 : tex.width;
                    text += ("uv: " + (MeshMGMT.SelectedUv.EditedUv.x * tSize) + "," + (MeshMGMT.SelectedUv.EditedUv.y * tSize));
                    markers.textm.text = text;
                }
                else
                {
                    markers.textm.text = point.vertices.Count +
                                         (point.smoothNormal ? "s" : "");
                }
            }
            else
            {
                markers.textm.text = "";
            }
        }
Exemple #4
0
 public override void MouseEventPointedNothing()
 {
     if (EditorInputManager.GetMouseButtonDown(0))
     {
         MeshMGMT.AddPoint(MeshMGMT.onGridLocal);
     }
 }
Exemple #5
0
 public override void MouseEventPointedNothing()
 {
     if (_addToTrianglesAndLines && EditorInputManager.GetMouseButtonDown(0))
     {
         MeshMGMT.CreatePointAndFocus(MeshMGMT.onGridLocal);
     }
 }
Exemple #6
0
        public override void AssignText(MarkerWithText mrkr, MeshPoint vpoint)
        {
            var pvrt = MeshMGMT.GetSelectedVert();

            if ((vpoint.uvpoints.Count > 1) || (pvrt == vpoint))
            {
                Texture tex = MeshMGMT.target.meshRenderer.sharedMaterial.mainTexture;

                if (pvrt == vpoint)
                {
                    mrkr.textm.text = (vpoint.uvpoints.Count > 1) ? ((vpoint.uvpoints.IndexOf(MeshMGMT.SelectedUV) + 1).ToString() + "/" + vpoint.uvpoints.Count.ToString() +
                                                                     (vpoint.SmoothNormal ? "s" : "")) : "";
                    float tsize = tex == null ? 128 : tex.width;
                    mrkr.textm.text +=
                        ("uv: " + (MeshMGMT.SelectedUV.EditedUV.x * tsize) + "," + (MeshMGMT.SelectedUV.EditedUV.y * tsize));
                }
                else
                {
                    mrkr.textm.text = vpoint.uvpoints.Count.ToString() +
                                      (vpoint.SmoothNormal ? "s" : "");
                }
            }
            else
            {
                mrkr.textm.text = "";
            }
        }
        public override void OnDeSelectTool()
        {
            foreach (var v in EditedMesh.meshPoints)
            {
                v.CleanEmptyIndexes();
            }

            if (projectionUv)
            {
                MeshMGMT.Redraw();
            }
        }
        public override bool MouseEventPointedLine()
        {
            var a = PointedLine.points[0];
            var b = PointedLine.points[1];

            MeshMGMT.AssignSelected(
                Vector3.Distance(MeshMGMT.collisionPosLocal, a.LocalPos) <
                Vector3.Distance(MeshMGMT.collisionPosLocal, b.LocalPos)
                    ? EditedMesh.GetUvPointAFromLine(a.meshPoint, b.meshPoint)
                    : EditedMesh.GetUvPointAFromLine(b.meshPoint, a.meshPoint));

            return(false);
        }
Exemple #9
0
        public override bool MouseEventPointedLine()
        {
            Vertex a = PointedLine.pnts[0];
            Vertex b = PointedLine.pnts[1];

            if (Vector3.Distance(MeshMGMT.collisionPosLocal, a.Pos) < Vector3.Distance(MeshMGMT.collisionPosLocal, b.Pos))
            {
                MeshMGMT.AssignSelected(EditedMesh.GetUVpointAFromLine(a.meshPoint, b.meshPoint));
            }
            else
            {
                MeshMGMT.AssignSelected(EditedMesh.GetUVpointAFromLine(b.meshPoint, a.meshPoint));
            }

            return(false);
        }
Exemple #10
0
        public override void KeysEventPointedLine()
        {
            if ((KeyCode.Backspace.IsDown()))
            {
                Vertex a = PointedLine.pnts[0];
                Vertex b = PointedLine.pnts[1];

                if (!EditorInputManager.getControlKey())
                {
                    MeshMGMT.SwapLine(a.meshPoint, b.meshPoint);
                }
                else
                {
                    MeshMGMT.DeleteLine(PointedLine);
                }

                EditedMesh.Dirty = true;
            }
        }
Exemple #11
0
        public override void AssignText(MarkerWithText mrkr, MeshPoint vpoint)
        {
            var pvrt = MeshMGMT.GetSelectedVert();

            if ((vpoint.uvpoints.Count > 1) || (pvrt == vpoint))
            {
                //Texture tex = meshMGMT.target.GetTextureOnMaterial();//meshRenderer.sharedMaterial.mainTexture;

                if (pvrt == vpoint)
                {
                    mrkr.textm.text = (vpoint.uvpoints.Count > 1) ? ((vpoint.uvpoints.IndexOf(MeshMGMT.SelectedUV) + 1).ToString() + "/" + vpoint.uvpoints.Count.ToString() +
                                                                     (vpoint.SmoothNormal ? "s" : "")) : "";
                }
                else
                {
                    mrkr.textm.text = vpoint.uvpoints.Count.ToString() +
                                      (vpoint.SmoothNormal ? "s" : "");
                }
            }
            else
            {
                mrkr.textm.text = "";
            }
        }
Exemple #12
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;
            }
        }
Exemple #13
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;
        }
Exemple #14
0
    public void UpdatePositions()
    {
        MeshManager m   = MeshMGMT;
        var         cfg = TexMGMTdata;

        if (cfg == null)
        {
            return;
        }

        bool showGrid = m.target.NeedsGrid() || TexMGMT.focusedPainter.NeedsGrid();

        SetEnabled(showGrid, cfg.SnapToGrid && showGrid);

        if (!showGrid)
        {
            return;
        }

        if (cfg.SnapToGridSize <= 0)
        {
            cfg.SnapToGridSize = 1;
        }

        switch (g_side)
        {
        case Gridside.xy: rendy.transform.rotation = zgrid; break;

        case Gridside.xz: rendy.transform.rotation = ygrid; break;

        case Gridside.zy: rendy.transform.rotation = xgrid; break;
        }

        xzPlane.distance = -onGridPos.y;
        xyPlane.distance = -onGridPos.z;
        zyPlane.distance = -onGridPos.x;

        Vector3 hit = Vector3.zero;

        switch (g_side)
        {
        case Gridside.xy:   hit = MouseToPlane(xyPlane);           break;

        case Gridside.xz:   hit = MouseToPlane(xzPlane);           break;

        case Gridside.zy:   hit = MouseToPlane(zyPlane);           break;
        }

        if (cfg.SnapToGrid)
        {
            hit = MyMath.RoundDiv(hit, cfg.SnapToGridSize);
        }

        if (hit != Vector3.zero)
        {
            switch (g_side)
            {
            case Gridside.xy:

                onGridPos.x = hit.x;
                onGridPos.y = hit.y;

                break;

            case Gridside.xz:
                onGridPos.x = hit.x;
                onGridPos.z = hit.z;
                break;

            case Gridside.zy:

                onGridPos.z = hit.z;
                onGridPos.y = hit.y;
                break;
            }
        }

        transform.position = onGridPos + Vector3.one * 0.01f;

        Shader.SetGlobalVector("_GridDotPosition", new Vector4(onGridPos.x, onGridPos.y, onGridPos.z));

        dot.transform.rotation = gameObject.TryGetCameraTransform().rotation;

        Transform cam = gameObject.TryGetCameraTransform();

        float dist = Mathf.Max(0.1f, (cam.position - transform.position).magnitude * 2);

        dot.transform.localScale   = Vector3.one * (dist / 64f);
        rendy.transform.localScale = new Vector3(dist, dist, dist);

        float dx = 0;
        float dy = 0;

        if (g_side != Gridside.zy)
        {
            dx = (transform.position.x);
        }
        else
        {
            dx = (-transform.position.z);
        }

        if (g_side != Gridside.xz)
        {
            dy = (transform.position.y);
        }
        else
        {
            dy = (transform.position.z);
        }

        float scale = 8;

        if (!cfg.SnapToGrid)
        {
            scale = Mathf.Max(1, Mathf.ClosestPowerOfTwo((int)(dist / 8)));
        }
        else
        {
            scale = cfg.SnapToGridSize;
        }

        dx -= Mathf.Round(dx / scale) * scale;
        dy -= Mathf.Round(dy / scale) * scale;
        rendy.sharedMaterial.SetFloat("_dx", dx / dist);
        rendy.sharedMaterial.SetFloat("_dy", dy / dist);
        rendy.sharedMaterial.SetFloat("_Size", dist / scale);

        if (MeshMGMT.target != null)
        {
            MeshMGMT.UpdateLocalSpaceV3s();
        }
    }
Exemple #15
0
        public void UpdatePositions()
        {
            var m   = MeshMGMT;
            var cfg = TexMgmtData;

            if (!cfg)
            {
                return;
            }

            var showGrid = MeshEditorManager.target.NeedsGrid() || TexMGMT.FocusedPainter.NeedsGrid();

            SetEnabled(showGrid, cfg.snapToGrid && showGrid);

            if (!showGrid)
            {
                return;
            }

            if (cfg.gridSize <= 0)
            {
                cfg.gridSize = 1;
            }

            switch (gSide)
            {
            case Gridside.xy:
                rendy.transform.rotation = ZGrid;
                break;

            case Gridside.xz:
                rendy.transform.rotation = YGrid;
                break;

            case Gridside.zy:
                rendy.transform.rotation = XGrid;
                break;
            }

            _xzPlane.distance = -onGridPos.y;
            _xyPlane.distance = -onGridPos.z;
            _zyPlane.distance = -onGridPos.x;

            var hit = Vector3.zero;

            switch (gSide)
            {
            case Gridside.xy:
                hit = MouseToPlane(_xyPlane);
                break;

            case Gridside.xz:
                hit = MouseToPlane(_xzPlane);
                break;

            case Gridside.zy:
                hit = MouseToPlane(_zyPlane);
                break;
            }

            if (cfg.snapToGrid)
            {
                hit = QcMath.RoundDiv(hit, cfg.gridSize);
            }

            if (hit != Vector3.zero)
            {
                switch (gSide)
                {
                case Gridside.xy:

                    onGridPos.x = hit.x;
                    onGridPos.y = hit.y;

                    break;

                case Gridside.xz:
                    onGridPos.x = hit.x;
                    onGridPos.z = hit.z;
                    break;

                case Gridside.zy:

                    onGridPos.z = hit.z;
                    onGridPos.y = hit.y;
                    break;
                }
            }

            var tf    = transform;
            var dotTf = dot.transform;
            var rndTf = rendy.transform;

            tf.position = onGridPos + Vector3.one * 0.01f;

            var position = tf.position;

            _dotPositionProperty.GlobalValue = new Vector4(onGridPos.x, onGridPos.y, onGridPos.z);

            dotTf.rotation = CurrentViewTransform().rotation;

            var cam = CurrentViewTransform();

            var dist = Mathf.Max(0.1f, (cam.position - position).magnitude * 2);

            dotTf.localScale = Vector3.one * (dist / 64f);
            rndTf.localScale = new Vector3(dist, dist, dist);

            float scale = !cfg.snapToGrid ? Mathf.Max(1, Mathf.ClosestPowerOfTwo((int)(dist / 8))) : cfg.gridSize;

            var dx = gSide != Gridside.zy ? position.x : -position.z;

            var dy = gSide != Gridside.xz ? position.y : position.z;

            dx -= Mathf.Round(dx / scale) * scale;
            dy -= Mathf.Round(dy / scale) * scale;

            var mat = rendy.sharedMaterial;

            mat.Set(_dxProp, dx / dist)
            .Set(_dyProp, dy / dist)
            .Set(_sizeProp, dist / scale);

            if (MeshEditorManager.target)
            {
                MeshMGMT.UpdateLocalSpaceMousePosition();
            }
        }