Ejemplo n.º 1
0
        public PainterMesh.MeshPoint InsertIntoTriangle(PainterMesh.Triangle a, Vector3 pos)
        {
            // Debug.Log("Inserting into triangle");
            var newVrt = new PainterMesh.MeshPoint(a.vertexes[0].meshPoint, pos);

            var w = a.DistanceToWeight(pos);

            var newV20 = a.vertexes[0].GetUv(0) * w.x + a.vertexes[1].GetUv(0) * w.y + a.vertexes[2].GetUv(0) * w.z;
            var newV21 = a.vertexes[0].GetUv(1) * w.x + a.vertexes[1].GetUv(1) * w.y + a.vertexes[2].GetUv(1) * w.z;

            var newUv = new PainterMesh.Vertex(newVrt, newV20, newV21);

            a.AssignWeightedData(newUv, w);

            meshPoints.Add(newVrt);

            var b = new PainterMesh.Triangle(a.vertexes).CopySettingsFrom(a);
            var c = new PainterMesh.Triangle(a.vertexes).CopySettingsFrom(a);

            a.Replace(0, newUv); //uvpnts[0] = newUV;
            b.Replace(1, newUv); // uvpnts[1] = newUV;
            c.Replace(2, newUv); // uvpnts[2] = newUV;

            triangles.Add(b);
            triangles.Add(c);


            if (Cfg.pixelPerfectMeshEditing)
            {
                newVrt.PixPerfect();
            }

            Dirty = true;
            return(newVrt);
        }
Ejemplo n.º 2
0
        public void MakeTriangleVertUnique(PainterMesh.Triangle tris, PainterMesh.Vertex pnt)
        {
            if (pnt.triangles.Count == 1)
            {
                return;
            }

            var nuv = new PainterMesh.Vertex(pnt.meshPoint, pnt);

            tris.Replace(pnt, nuv);

            Dirty = true;
        }
Ejemplo n.º 3
0
        public PainterMesh.MeshPoint InsertIntoLine(PainterMesh.MeshPoint a, PainterMesh.MeshPoint b, Vector3 pos)
        {
            var dstA = Vector3.Distance(pos, a.localPos);
            var dstB = Vector3.Distance(pos, b.localPos);


            var sum = dstA + dstB;

            float weightA = dstB / sum;
            float weightB = dstA / sum;

            pos = (a.localPos * dstB + b.localPos * dstA) / sum;

            var newVrt = new PainterMesh.MeshPoint(a, pos);

            meshPoints.Add(newVrt);

            var pointTris = a.Triangles();

            for (int i = 0; i < pointTris.Count; i++)
            {
                var tr = pointTris[i];

                if (!tr.Includes(b))
                {
                    continue;
                }

                var auv     = tr.GetByVertex(a);
                var buv     = tr.GetByVertex(b);
                var splitUv = tr.GetNotOneOf(a, b);


                if (auv == null || buv == null)
                {
                    Debug.LogError("Didn't found a uv");
                    continue;
                }

                //  var uv = (auv.GetUv(0) * weightA + buv.GetUv(0) * weightA);
                // var uv1 = (auv.GetUv(1) * weightA + buv.GetUv(1) * weightA);

                // Vertex newUv = null;

                //               if (Cfg.newVerticesUnique || newVrt.vertices.IsNullOrEmpty())
                //                 newUv = new Vertex(newVrt);

                /*else
                 * {
                 *  foreach (var t in newVrt.vertices)
                 *      if (t.SameUv(uv, uv1))
                 *          newUv = t;
                 * }*/

                //if (newUv == null)
                PainterMesh.Vertex newUv = new PainterMesh.Vertex(newVrt);


                tr.AssignWeightedData(newUv, tr.DistanceToWeight(pos));


                var trb = new PainterMesh.Triangle(tr.vertexes).CopySettingsFrom(tr);
                triangles.Add(trb);
                tr.Replace(auv, newUv);

                if (Cfg.newVerticesUnique)
                {
                    var split = new PainterMesh.Vertex(splitUv);
                    trb.Replace(splitUv, split);
                    var newB = new PainterMesh.Vertex(newUv);
                    trb.Replace(buv, newB);
                }
                else
                {
                    trb.Replace(buv, newUv);
                }
            }

            Dirty = true;

            if (Cfg.pixelPerfectMeshEditing)
            {
                newVrt.PixPerfect();
            }

            return(newVrt);
        }