Planeを使用するよりも、自分でメッシュを作成したほうが頂点配列を自分で指定できるため使いやすいと思います。
Meshクラスのverticesプロパティに頂点配列を設定することができるため、CSVファイルの並びをそのまま適応できます。
下記のサンプルを参考にしてみたください。
サンプルではCSVファイルからではなく、固定配列データから頂点データを取得しています。
public static class FieldData
{
public static float[,] HeightList = new float[,]
{
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,2,3,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,2,2,2,1,0,0,0,0,0,0,0,0,5,0,0,0,0},
{0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0},
{0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
};
public static int Depth
{
get { return HeightList.GetLength( 0 ); }
}
public static int Width
{
get { return HeightList.GetLength( 1 ); }
}
}
public class TestMesh : MonoBehaviour
{
private MeshFilter m_meshFilter;
void Awake()
{
gameObject.AddComponent< MeshRenderer >();
m_meshFilter = gameObject.AddComponent< MeshFilter >();
}
void Start()
{
var mesh = new Mesh();
var vertices = MakeVertices();
var indices = MakeIndices();
mesh.vertices = vertices;
mesh.SetIndices( indices, MeshTopology.Quads, 0 );
mesh.name = "TestMesh";
m_meshFilter.mesh = mesh;
}
Vector3[] MakeVertices()
{
int width = FieldData.Width;
int depth = FieldData.Depth;
var heightList = FieldData.HeightList;
var vertices = new Vector3[ width * depth ];
for( int i = 0; i < depth; ++i )
{
for( int j = 0; j < width; ++j )
{
int index = i * width + j;
vertices[ index ] = new Vector3( i, heightList[i,j], j );
}
}
return vertices;
}
int[] MakeIndices()
{
int width = FieldData.Width;
int depth = FieldData.Depth;
int meshSize = ( width - 1 ) * ( depth - 1 );
int[] indices = new int[ meshSize * 4 ];
int indicesIndex = 0;
for( int i = 0; i < depth - 1; ++i )
{
for( int j = 0; j < width - 1; ++j )
{
int index = i * width + j;
indices[ indicesIndex++ ] = index + width;
indices[ indicesIndex++ ] = index;
indices[ indicesIndex++ ] = index + 1;
indices[ indicesIndex++ ] = index + width + 1;
}
}
return indices;
}
}
上記のTestMeshコンポーネントをGameObjectに付けると以下のようなメッシュが作成されます。
