58 lines
1.3 KiB
Markdown
58 lines
1.3 KiB
Markdown
|
|
# Mesh::SetVertexData
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
void SetVertexData(const void* data, size_t size, Core::uint32 vertexCount,
|
||
|
|
Core::uint32 vertexStride, VertexAttribute attributes);
|
||
|
|
```
|
||
|
|
|
||
|
|
设置网格的顶点数据。此方法会复制传入的数据到内部缓冲区。
|
||
|
|
|
||
|
|
**参数:**
|
||
|
|
- `data` - 顶点数据指针,不能为 nullptr
|
||
|
|
- `size` - 顶点数据总字节数
|
||
|
|
- `vertexCount` - 顶点数量
|
||
|
|
- `vertexStride` - 单个顶点的字节大小
|
||
|
|
- `attributes` - 顶点属性标志,指定数据包含哪些顶点通道
|
||
|
|
|
||
|
|
**返回:** 无
|
||
|
|
|
||
|
|
**异常:** 无
|
||
|
|
|
||
|
|
**线程安全:** ❌
|
||
|
|
|
||
|
|
**复杂度:** O(n) - n 为顶点数据大小
|
||
|
|
|
||
|
|
**示例:**
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
#include "XCEngine/Resources/Mesh.h"
|
||
|
|
|
||
|
|
using namespace XCEngine::Resources;
|
||
|
|
|
||
|
|
struct Vertex {
|
||
|
|
float position[3];
|
||
|
|
float normal[3];
|
||
|
|
float uv[2];
|
||
|
|
};
|
||
|
|
|
||
|
|
Vertex vertices[4] = {
|
||
|
|
{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
|
||
|
|
{{ 0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
|
||
|
|
{{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
|
||
|
|
{{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}}
|
||
|
|
};
|
||
|
|
|
||
|
|
Mesh mesh;
|
||
|
|
mesh.SetVertexData(
|
||
|
|
vertices,
|
||
|
|
sizeof(vertices),
|
||
|
|
4,
|
||
|
|
sizeof(Vertex),
|
||
|
|
VertexAttribute::Position | VertexAttribute::Normal | VertexAttribute::UV0
|
||
|
|
);
|
||
|
|
```
|
||
|
|
|
||
|
|
## 相关文档
|
||
|
|
|
||
|
|
- [类总览](mesh.md) - 返回类总览
|