53 lines
1.0 KiB
Markdown
53 lines
1.0 KiB
Markdown
# Mesh::AddSection
|
||
|
||
```cpp
|
||
void AddSection(const MeshSection& section);
|
||
```
|
||
|
||
添加一个网格分段(Submesh)。网格分段用于将一个网格分割成多个部分,每个部分可以有不同的材质。
|
||
|
||
**参数:**
|
||
- `section` - 网格分段结构,包含顶点和索引范围以及材质 ID
|
||
|
||
**返回:** 无
|
||
|
||
**异常:** 无
|
||
|
||
**线程安全:** ❌
|
||
|
||
**复杂度:** O(1) 均摊
|
||
|
||
**示例:**
|
||
|
||
```cpp
|
||
#include "XCEngine/Resources/Mesh.h"
|
||
|
||
using namespace XCEngine::Resources;
|
||
|
||
Mesh mesh;
|
||
mesh.SetVertexData(...);
|
||
mesh.SetIndexData(...);
|
||
|
||
// 添加第一个分段(使用材质 0)
|
||
MeshSection section1;
|
||
section1.baseVertex = 0;
|
||
section1.vertexCount = 4;
|
||
section1.startIndex = 0;
|
||
section1.indexCount = 6;
|
||
section1.materialID = 0;
|
||
mesh.AddSection(section1);
|
||
|
||
// 添加第二个分段(使用材质 1)
|
||
MeshSection section2;
|
||
section2.baseVertex = 4;
|
||
section2.vertexCount = 4;
|
||
section2.startIndex = 6;
|
||
section2.indexCount = 6;
|
||
section2.materialID = 1;
|
||
mesh.AddSection(section2);
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [类总览](mesh.md) - 返回类总览
|