Files
XCEngine/docs/api/resources/mesh/set-index-data.md

45 lines
1006 B
Markdown
Raw Normal View History

2026-03-20 02:35:35 +08:00
# Mesh::SetIndexData
```cpp
void SetIndexData(const void* data, size_t size, Core::uint32 indexCount, bool use32Bit);
```
设置网格的索引数据。此方法会复制传入的数据到内部缓冲区。
**参数:**
- `data` - 索引数据指针,不能为 nullptr
- `size` - 索引数据总字节数
- `indexCount` - 索引数量
- `use32Bit` - 是否使用 32 位索引false 则使用 16 位索引
**返回:** 无
**异常:** 无
**线程安全:** ❌
**复杂度:** O(n) - n 为索引数据大小
**示例:**
```cpp
#include "XCEngine/Resources/Mesh.h"
using namespace XCEngine::Resources;
Mesh mesh;
mesh.SetVertexData(...);
// 使用 16 位索引(最多 65536 个顶点)
uint16_t indices16[6] = {0, 1, 2, 0, 2, 3};
mesh.SetIndexData(indices16, sizeof(indices16), 6, false);
// 或使用 32 位索引
uint32_t indices32[6] = {0, 1, 2, 0, 2, 3};
mesh.SetIndexData(indices32, sizeof(indices32), 6, true);
```
## 相关文档
- [类总览](mesh.md) - 返回类总览