Mesh createMesh(List <Vector2d> vertices) { Mesh mesh = new Mesh();; mesh.name = name + "_mesh"; mesh.SetVertices(BlendWarp_Functions.list2dDoubleTo3dFloat(vertices)); mesh.SetIndices(BlendWarp_Functions.GridToTriangles(Data.RowCount, Data.ColCount), MeshTopology.Triangles, 0); mesh.SetUVs(0, BlendWarp_Functions.list2dDoubleToFloat(BlendWarp_Functions.createUVs(Data.RowCount, Data.ColCount, 1, 1))); GetComponent <MeshFilter>().mesh = mesh; mesh.RecalculateNormals(); mesh.RecalculateBounds(); mesh.RecalculateTangents(); #if UNITY_EDITOR if (Editor.exportsMesh) { if (!Directory.Exists(Application.dataPath + "/StreamingAssets")) { Directory.CreateDirectory(Application.dataPath + "/StreamingAssets"); } AssetDatabase.CreateAsset(mesh, "Assets/StreamingAssets/" + name + ".mesh"); AssetDatabase.SaveAssets(); } #endif return(mesh); }
public void attachMesh() { if (Data.Grid == null) { //creates mesh based rectangular grid vertices; Data.Grid = BlendWarp_Functions.createVerts(Data.RowCount, Data.ColCount, Data.Cols[Data.Cols.Count - 1], Data.Rows[Data.Rows.Count - 1]); } GetComponent <MeshFilter>().mesh = createMesh(Data.Grid); }
public void updateMesh() { currentMesh.SetVertices(BlendWarp_Functions.list2dDoubleTo3dFloat(Data.Grid)); currentMesh.RecalculateNormals(); currentMesh.RecalculateBounds(); }
void replacePoint(Vector2d add) { if (currentPoint == null) { return; } curPointPos = new Vector3d(curPointPos.x + add.x, curPointPos.y + add.y, curPointPos.z); updateCurPoint(); switch (BlendWarpManager.warpingMode) { case BlendWarpManager.WarpingMode.CornersRowCol_Move: { Vector2d[] srcCorners = new Vector2d[4]; srcCorners[0] = getPointFromGrid(0, 0); srcCorners[1] = getPointFromGrid(rowCounts - 1, colCounts - 1); srcCorners[2] = getPointFromGrid(rowCounts - 1, 0); srcCorners[3] = getPointFromGrid(0, colCounts - 1); setPointOnGrid(curRow, curCol, curPointPos); Vector2d[] dstCorners = new Vector2d[4]; dstCorners[0] = getPointFromGrid(0, 0); dstCorners[1] = getPointFromGrid(rowCounts - 1, colCounts - 1); dstCorners[2] = getPointFromGrid(rowCounts - 1, 0); dstCorners[3] = getPointFromGrid(0, colCounts - 1); //lineRenderers[curRow].SetPosition(curCol, currentPoint.transform.position); // lineRenderers[rowCounts + curCol].SetPosition(curRow, currentPoint.transform.position); //gantolebis amoxsna srcCorners gadadis dstCorners wveroebshi double[] matrix = new double[16]; Homography.FindHomography(ref srcCorners, ref dstCorners, ref matrix); for (int p = 0; p < rowCounts; p++) { for (int q = 0; q < colCounts; q++) { if ((p == 0 && q == 0) || (p == 0 && q == colCounts - 1) || (p == rowCounts - 1 && q == 0) || (p == rowCounts - 1 && q == colCounts - 1)) { continue; } Vector2d initialPos = getPointFromGrid(p, q); Vector2d posi = BlendWarp_Functions.TransformedPoint(initialPos, matrix); setPointOnGrid(p, q, posi); } } } break; case BlendWarpManager.WarpingMode.Row_Move: { for (int i = 0; i < colCounts; i++) { Vector2d posi = getPointFromGrid(curRow, i); posi = new Vector2d((posi.x + add.x), (posi.y + add.y)); setPointOnGrid(curRow, i, posi); } } break; case BlendWarpManager.WarpingMode.Col_Move: { for (int i = 0; i < rowCounts; i++) { Vector2d posi = getPointFromGrid(i, curCol); posi = new Vector2d((posi.x + add.x), (posi.y + add.y)); setPointOnGrid(i, curCol, posi); } } break; case BlendWarpManager.WarpingMode.SinglePoint_Move: { Vector2d posi = getPointFromGrid(curRow, curCol); posi = new Vector2d((posi.x + add.x), (posi.y + add.y)); setPointOnGrid(curRow, curCol, posi); } break; } updateMesh(); updateGrid(); }