Version: 2023.1

Mesh.SetIndices

切换到手册
public void SetIndices (int[] indices, MeshTopology topology, int submesh, bool calculateBounds= true, int baseVertex= 0);
public void SetIndices (List<int> indices, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (ushort[] indices, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (List<ushort> indices, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (NativeArray<T> indices, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);

参数

indices 定义网格面的索引的数组。
topology 网格的拓扑,例如:三角形、线条、四边形、点等。请参阅 MeshTopology
submesh 要修改的子网格。
calculateBounds Calculate the bounding box of the sub-mesh after setting the indices. Unity does this by default. Use false when you want to use the existing bounding box and reduce the CPU cost of setting the indices.
baseVertex 添加到所有顶点索引的可选顶点偏移。

描述

为子网格设置索引缓冲区。

子网格表示使用单个 Material 渲染的三角形(或具有不同 MeshTopology 的索引)的列表。当网格与具有多个材质的 Renderer 一起使用时,应确保每个材质有一个子网格。

SetTrianglestriangles 始终将网格设置为由三角形的面 组成。使用 SetIndices 可创建由线条或点组成的网格。

The baseVertex argument can be used to achieve meshes that are larger than 65536 vertices while using 16 bit index buffers, as long as each sub-mesh index fits within its own 65535 value range. For example, if the index buffer that is passed to SetIndices contains indices 10,11,12 and baseVertex is set to 100000, then effectively vertices 100010, 100011 and 100012 will be used for rendering.

Note that meshes use 16-bit indexFormat by default, i.e. the maximum value supported in the index buffer is 65535 (even when using int[] input data). In order to use larger index buffer values, you should first set the indexFormat to IndexFormat.UInt32.

Call Mesh.RecalculateBounds after updating all sub-meshes if you want to update the Mesh's bounding box.

See Also: subMeshCount, MeshTopology, indexFormat.


public void SetIndices (int[] indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (List<int> indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (ushort[] indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (List<ushort> indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (NativeArray<T> indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);

参数

indices 定义网格面的索引的数组。
indicesStart 要从输入数组采用的第一个元素的索引。
indicesLength 要从输入数组采用的元素数。
topology 网格的拓扑,例如:三角形、线条、四边形、点等。请参阅 MeshTopology
submesh 要修改的子网格。
calculateBounds Calculate the bounding box of the sub-mesh after setting the indices. Unity does this by default. Use false when you want to use the existing bounding box and reduce the CPU cost of setting the indices.
baseVertex 添加到所有顶点索引的可选顶点偏移。

描述

使用输入数组的一部分设置子网格的索引缓冲区。

此方法的行为方式如同调用 SetIndices,所使用的数组为整个数组的一个切片(从 indicesStart 索引开始,长度为给定的 indicesLength 长度)。生成的子网格会具有 indicesLength 数量的顶点索引。