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); }
public PainterMesh.MeshPoint InsertIntoTriangleUniqueVertices(PainterMesh.Triangle a, Vector3 localPos) { var newVrt = new PainterMesh.MeshPoint(a.vertexes[0].meshPoint, localPos); meshPoints.Add(newVrt); var newUv = new PainterMesh.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 PainterMesh.Vertex(newVrt);//, newV20, newV21); a.AssignWeightedData(newUv[i], w); } var b = new PainterMesh.Triangle(a.vertexes).CopySettingsFrom(a); var c = new PainterMesh.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); }
public PainterMesh.MeshPoint CreatePointAndFocus(Vector3 pos) { var hold = new PainterMesh.MeshPoint(pos, true); new PainterMesh.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); }
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); }