Пример #1
0
        public MeshPoint InsertIntoTriangle(Triangle a, Vector3 pos)
        {
            // Debug.Log("Inserting into triangle");
            var newVrt = new 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 Vertex(newVrt, newV20, newV21);

            a.AssignWeightedData(newUv, w);

            meshPoints.Add(newVrt);

            var b = new Triangle(a.vertexes).CopySettingsFrom(a);
            var c = new 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);
        }
Пример #2
0
        public MeshPoint InsertIntoTriangleUniqueVertices(Triangle a, Vector3 localPos)
        {
            var newVrt = new MeshPoint(localPos);

            meshPoints.Add(newVrt);

            var newUv = new Vertex[3]; // (newVrt);

            var w = a.DistanceToWeight(localPos);

            //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;
            //Color col = a.uvpnts[0]._color * w.x + a.uvpnts[1]._color * w.y + a.uvpnts[2]._color * w.z;
            for (var i = 0; i < 3; i++)
            {
                newUv[i] = new Vertex(newVrt);//, newV20, newV21);
                a.AssignWeightedData(newUv[i], w);
            }

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

            a.vertexes[0] = newUv[0];
            b.vertexes[1] = newUv[1];
            c.vertexes[2] = newUv[2];

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

            a.MakeTriangleVertexUnique(a.vertexes[1]);
            b.MakeTriangleVertexUnique(b.vertexes[2]);
            c.MakeTriangleVertexUnique(c.vertexes[0]);


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

            Dirty = true;
            return(newVrt);
        }
Пример #3
0
        public MeshPoint CreatePointAndFocus(Vector3 pos)
        {
            var hold = new MeshPoint(pos, true);

            new Vertex(hold);

            editedMesh.meshPoints.Add(hold);

            if (!EditorInputManager.Control)
            {
                EditedMesh.AddToTrisSet(hold.vertices[0]);
            }

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

            GridNavigator.collisionPos = pos;

            UpdateLocalSpaceMousePosition();

            return(hold);
        }
Пример #4
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(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);
        }