示例#1
0
        public MeshPoint InsertIntoLine(MeshPoint a, 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 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)
                Vertex newUv = new Vertex(newVrt);


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


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

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

            Dirty = true;

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

            return(newVrt);
        }