Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
결과 시험하기
SurfaceTool 클래스와 유사합니다. 각 정점별 속성(예: 일반, UV, 색상)을 설정한 다음 정점을 추가하면 속성이 캡처됩니다.
SurfaceTool은 index() 및 ``generate_normals()``와 같은 몇 가지 유용한 도우미 기능도 제공합니다.
각 정점이 추가되기 전에 속성이 추가됩니다.
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.set_normal() # Overwritten by normal below.
st.set_normal() # Added to next vertex.
st.set_color() # Added to next vertex.
st.add_vertex() # Captures normal and color above.
st.set_normal() # Normal never added to a vertex.
st.SetNormal(); // Overwritten by normal below.
st.SetNormal(); // Added to next vertex.
st.SetColor(); // Added to next vertex.
st.AddVertex(); // Captures normal and color above.
st.SetNormal(); // Normal never added to a vertex.
:ref:`SurfaceTool <class_surfacetool>`을 사용하여 지오메트리 생성을 마쳤으면 ``commit()``를 호출하여 메시 생성을 완료합니다. :ref:`ArrayMesh <class_ArrayMesh>`가 ``commit()``로 전달되면 ArrayMesh의 끝에 새 표면이 추가됩니다. 아무것도 전달되지 않으면 ``commit()``는 ArrayMesh를 반환합니다.
# Add surface to existing ArrayMesh.
st.commit(mesh)
# -- Or Alternatively --
# Create new ArrayMesh.
var mesh = st.commit()
st.Commit(mesh);
// Or:
var mesh = st.Commit();
어떻게 작동하는 지의 예제입니다:
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
# Prepare attributes for add_vertex.
st.set_normal(Vector3(0, 0, 1))
st.set_uv(Vector2(0, 0))
# Call last for each vertex, adds the above attributes.
st.add_vertex(Vector3(-1, -1, 0))
st.set_normal(Vector3(0, 0, 1))
st.set_uv(Vector2(0, 1))
st.add_vertex(Vector3(-1, 1, 0))
st.set_normal(Vector3(0, 0, 1))
st.set_uv(Vector2(1, 1))
st.add_vertex(Vector3(1, 1, 0))
# Commit to a mesh.
var mesh = st.commit()
var st = new SurfaceTool();
st.Begin(Mesh.PrimitiveType.Triangles);
// Prepare attributes for AddVertex.
st.SetNormal(new Vector3(0, 0, 1));
st.SetUV(new Vector2(0, 0));
// Call last for each vertex, adds the above attributes.
st.AddVertex(new Vector3(-1, -1, 0));
st.SetNormal(new Vector3(0, 0, 1));
st.SetUV(new Vector2(0, 1));
st.AddVertex(new Vector3(-1, 1, 0));
st.SetNormal(new Vector3(0, 0, 1));
st.SetUV(new Vector2(1, 1));
st.AddVertex(new Vector3(1, 1, 0));
// Commit to a mesh.
var mesh = st.Commit();
선택적으로 ``add_index()``를 호출하고 인덱스 배열에 정점을 수동으로 추가하거나 ``index()``를 한 번 호출하여 인덱스 배열을 추가할 수 있습니다. 그러면 인덱스 배열이 자동으로 생성되고 정점 배열이 축소되어 중복 정점이 제거됩니다.
# Suppose we have a quad defined by 6 vertices as follows
st.add_vertex(Vector3(-1, 1, 0))
st.add_vertex(Vector3(1, 1, 0))
st.add_vertex(Vector3(-1, -1, 0))
st.add_vertex(Vector3(1, 1, 0))
st.add_vertex(Vector3(1, -1, 0))
st.add_vertex(Vector3(-1, -1, 0))
# We can make the quad more efficient by using an index array and only utilizing 4 vertices:
st.add_vertex(Vector3(-1, 1, 0))
st.add_vertex(Vector3(1, 1, 0))
st.add_vertex(Vector3(-1, -1, 0))
st.add_vertex(Vector3(1, -1, 0))
# Creates a quad from four corner vertices.
# add_index() can be called before or after add_vertex()
# since it's not an attribute of a vertex itself.
st.add_index(0)
st.add_index(1)
st.add_index(2)
st.add_index(1)
st.add_index(3)
st.add_index(2)
# Alternatively we can use ``st.index()`` which will create the quad for us and remove the duplicate vertices
st.index()
// Suppose we have a quad defined by 6 vertices as follows.
st.AddVertex(new Vector3(-1, 1, 0));
st.AddVertex(new Vector3(1, 1, 0));
st.AddVertex(new Vector3(-1, -1, 0));
st.AddVertex(new Vector3(1, 1, 0));
st.AddVertex(new Vector3(1, -1, 0));
st.AddVertex(new Vector3(-1, -1, 0));
// We can make the quad more efficient by using an index array and only utilizing 4 vertices:
st.AddVertex(new Vector3(-1, -1, 0));
st.AddVertex(new Vector3(1, 1, 0));
st.AddVertex(new Vector3(-1, -1, 0));
st.AddVertex(new Vector3(1, 1, 0));
// Creates a quad from four corner vertices.
// AddIndex does not need to be called before AddVertex.
st.AddIndex(0);
st.AddIndex(1);
st.AddIndex(2);
st.AddIndex(1);
st.AddIndex(3);
st.AddIndex(2);
// Alternatively we can use `st.Index()` which will create the quad for us and remove the duplicate vertices.
st.Index();
마찬가지로, 인덱스 배열이 있지만 각 정점을 고유하게 하려는 경우(예: 정점별 대신 면별로 고유한 법선 또는 색상을 사용하려는 경우) ``deindex()``를 호출할 수 있습니다.
st.deindex()
st.Deindex();
사용자 정의 법선을 직접 추가하지 않는 경우 generate_normals()``를 사용하여 추가할 수 있습니다. 이는 형상을 생성한 후 ``commit() 또는 ``commit_to_arrays()``를 사용하여 메시를 커밋하기 전에 호출해야 합니다. ``generate_normals(true)``를 호출하면 결과 법선이 반전됩니다. 참고로 ``generate_normals()``는 기본 유형이 ``Mesh.PRIMITIVE_TRIANGLES``로 설정된 경우에만 작동합니다.
생성된 메시에서 노멀 매핑이나 기타 재질 속성이 깨져 보이는 것을 볼 수 있습니다. 그 이유는 노멀 매핑에서는 메쉬에 노멀*과 별개인 *접선 기능이 **필요**하기 때문입니다. 사용자 정의 접선을 수동으로 추가하거나 ``generate_tangents()``를 사용하여 자동으로 생성할 수 있습니다. 이 방법을 사용하려면 각 정점에 UV와 법선이 이미 설정되어 있어야 합니다.
st.generate_normals()
st.generate_tangents()
st.commit(mesh)
st.GenerateNormals();
st.GenerateTangents();
기본적으로 법선을 생성할 때 정점별로 계산됩니다(즉, "부드러운 법선"이 됩니다). 편평한 정점 법선(즉, 면당 단일 법선 벡터)을 원하는 경우 정점을 추가할 때 ``add_smooth_group(i)``를 호출하세요. 여기서 ``i``는 정점당 고유 번호입니다. 형상을 작성하는 동안 ``add_smooth_group()``를 호출해야 합니다. ``add_vertex()``로 전화하기 전에.