높이 맵을 받아 입력을 기반으로 한 단일 등각 투영을 만드는 함수를 만들려고합니다. 큐브의 꼭대기를 쉽게 표현할 수있는 삼각형을 만들도록 만들었지 만, 큐브의 측면을 내려가는 것은 내가 문제가있는 것처럼 보입니다. 이 기능은 완료되지 않은 상태로 끝나기 전에 문제가 발생하여 두 면만 만듭니다.유니티 메쉬 삼각형이 뒤집혀졌습니다.
기본적으로 어떤 일이 벌어지고있는 것은 삼각형이 뒤집혀 있고 다른 것들은 그렇지 않다는 것입니다. 이유는 모르겠습니다. 두 삼각형이 같은 방향을 향하게하는면이 있고 다른면은 사각형의 두 번째면이 보이기 만하면 삼각형 중 하나가 보일 수 있습니다.
메쉬의 한면에서 다른면으로 이어지는 사각형을 만드는 경우도 있습니다.
저는 메시와 3D가 일반적으로 새롭습니다. 나는 또한 내가 UV를 매핑하는 방식이 완전히 잘못되었다는 것을 확신하지만, 그것은 나중에 나올 무언가이다.
public static MeshData generateIsoMesh(float [,] heightMap, int heightMax, AnimationCurve heightCurve)
{
int height = heightMap.GetLength(0);
int width = heightMap.GetLength(1);
int triangleNum = 0;
int blockHeight = 0 ;
int nextHeight = 0;
int heightDif = 0;
List<Vector3> vecList = new List<Vector3>();
List<int> triangleList = new List<int>();
List<Vector2> uvList = new List<Vector2>();
for (int y = 0; y < height; y ++)
{
for (int x = 0; x < width; x ++)
{
blockHeight = ((int)(heightMap[x, y]*10)) * heightMax;
vecList.Add(new Vector3(x, blockHeight , y));
vecList.Add(new Vector3(x, blockHeight, y+ 1));
vecList.Add(new Vector3(x+1, blockHeight, y+1));
vecList.Add(new Vector3(x + 1, blockHeight, y));
uvList.Add(new Vector2(x/(float)width, y/(float)height));
uvList.Add(new Vector2(x/(float)width, y/(float)height));
uvList.Add(new Vector2(x/(float)width, y/(float)height));
uvList.Add(new Vector2(x/(float)width, y/(float)height));
if ((x < width-1) && (y < height-1))
{
triangleList.Add(triangleNum);
triangleList.Add(triangleNum + 1);
triangleList.Add(triangleNum + 2);
triangleList.Add(triangleNum);
triangleList.Add(triangleNum + 2);
triangleList.Add(triangleNum + 3);
triangleNum += 4;
}
if (x < width-1 && x > 3 && x > 0)
{
nextHeight = ((int)(heightMap[x+1,y]*10)) * heightMax;
heightDif = (nextHeight - blockHeight)/heightMax;
if (heightDif > 0)
{
for (int z = 0; z < heightDif; z ++)
{
uvList.Add(new Vector2(x/(float)width, y/(float)height));
uvList.Add(new Vector2(x/(float)width, y/(float)height));
vecList.Add(new Vector3(x + 1, blockHeight - (1 + z), y));
vecList.Add(new Vector3(x + 1, blockHeight - (1 + z), y + 1));
triangleList.Add(triangleNum - 1);
triangleList.Add(triangleNum - 2);
triangleList.Add(triangleNum + 1);
triangleList.Add(triangleNum - 1);
triangleList.Add(triangleNum + 1);
triangleList.Add(triangleNum );
triangleNum += 4;
}
}
else if (heightDif < 0)
{
;
}
}
}
}
출력 메시 : 및 http://imageshack.com/a/img924/9072/HdrZFm.png
모든 당신의 도움을 주셔서 감사 코드
을 단계를 수행하는 루프없이 동일한 메쉬. https://imageshack.us/i/poHdrZFmp