Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Mesh.GetTriangles

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public method GetTriangles(submesh: int): int[];
public int[] GetTriangles(int submesh);
public method GetTriangles(submesh: int, applyBaseVertex: bool = true): int[];
public int[] GetTriangles(int submesh, bool applyBaseVertex = true);
public method GetTriangles(triangles: List<int>, submesh: int, applyBaseVertex: bool = true): void;
public void GetTriangles(List<int> triangles, int submesh, bool applyBaseVertex = true);
public method GetTriangles(triangles: List<int>, submesh: int): void;
public void GetTriangles(List<int> triangles, int submesh);

Parameters

trianglesA list of vertex indices to populate.
submeshThe sub mesh on this instance. See subMeshCount.
applyBaseVertexTrue (default) value will apply base vertex offset to returned indices.

Description

Gets the triangle list for the specified sub mesh on this instance.

Each element value in the returned triangle list refers to a vertex index, which can be used to index into the results of other accessors like vertices and GetVertices. It will return indices in multiples of three.

A sub mesh is simply a separate triangle list. When the mesh is rendered using multiple materials, you should ensure that there is one sub mesh per Material.

Call the method overload with a List<int> parameter if you control the life cycle of the index buffer and wish to avoid allocation of a new array with every access.

See Also: subMeshCount.