Unity를 공부하며 Mesh 에대하여 제가 이해한 내용을 정리하였습니다.

 

Mesh

메시를 생성하거나 수정할 수 있는 클래스입니다.
메시에는 정점과 여러 삼각형 배열이 포함되어 있습니다.개념적으로 모든 정점 데이터는 동일한 크기의 별도 배열에 저장됩니다. 

 

Unity 에서의 mesh 란 쉽게 설명하여 3d 객체를 그릴때 기본이 되는 점(vertices), 선(triangles), 면(uv)을 가지고 다면체 도형입니다.

 

 


 

Mesh.vertices - 점

 

Unity - Scripting API: Mesh.vertices

The number of vertices in the Mesh is changed by assigning a vertex array with a different number of vertices. If you resize the vertex array then all other vertex attributes (normals, colors, tangents, UVs) are automatically resized too. RecalculateBounds

docs.unity3d.com

 

정점 위치의 복사본을 반환하거나 새 정점 위치 배열을 할당합니다.

메쉬의 정점 수는 정점 개수가 다른 정점 배열을 할당하여 변경됩니다.

정점 배열의 크기를 조정하면 다른 모든 정점 속성(법선, 색상, 접선, UV)도 자동으로 크기가 조정됩니다. 정점을 설정할 때 메시에 정점이 할당되지 않은 경우 RecalculateBounds가 자동으로 호출됩니다.

이 메서드는 월드 공간이 아닌 로컬 공간의 정점을 반환합니다.

 

3d 객체를 그릴때의 정점.

 

mesh.vertices = new Vector3[]{
	new Vector3(0,0,0),
	new Vector3(0,0,1),
	new Vector3(1,0,0)
};

 


 

Mesh.triangles - 선

 

Unity - Scripting API: Mesh.triangles

The array is a list of triangles that contains indices into the vertex array. The size of the triangle array must always be a multiple of 3. Vertices can be shared by simply indexing into the same vertex. If the Mesh contains multiple sub-meshes (Materials

docs.unity3d.com

메시의 모든 삼각형을 포함하는 배열입니다.

배열은 정점 배열에 대한 인덱스를 포함하는 삼각형 목록입니다. 삼각형 배열의 크기는 항상 3의 배수여야 합니다. 동일한 꼭지점을 인덱싱하는 것만으로 꼭지점을 공유할 수 있습니다. 메시에 여러 하위 메시(재질)가 포함된 경우 삼각형 목록에는 모든 하위 메시에 속하는 모든 삼각형이 포함됩니다. 이 함수를 사용하여 삼각형 배열을 할당하면 subMeshCount가 1로 설정됩니다. 여러 개의 하위 메시를 갖고 싶다면 subMeshCount  SetTriangles를 사용하세요 .

 

점을 연결할수있는 선이 되는 변수

 

mesh.triangles = new int[]{
    0,1,2
};

 

 


 

Mesh.uv - 면

 

Unity - Scripting API: Mesh.uv

This channel is also commonly called "UV0". It maps to the shader semantic `TEXCOORD0`. When you call Mesh.HasVertexAttribute, this channel corresponds to VertexAttribute.TexCoord0. By default, Unity uses this channel to store UVs for commonly used texture

docs.unity3d.com

첫 번째 채널의 텍스처 좌표(UV)입니다. 기본적으로 Unity는 이 채널을 사용하여 일반적으로 사용되는 텍스처(확산 맵, 반사 맵 등)에 대한 UV를 저장합니다. Unity는 UV를 0-1 공간에 저장합니다. [0,0]은 텍스처의 왼쪽 하단 모서리를 나타내고 [1,1]은 오른쪽 상단을 나타냅니다. 값은 고정되지 않습니다. 필요한 경우 0 미만 및 1 이상의 값을 사용할 수 있습니다.

 

정점과 동일한 지점의 텍스쳐의 좌표.

 

mesh.uv = new Vector2[]{
    new Vector2(0,0),
    new Vector2(0,1),
    new Vector2(1,0),
};

 

+ Recent posts