Files
XCEngine/docs/api/resources/mesh-loader/methods/load.md

56 lines
1.6 KiB
Markdown
Raw Normal View History

2026-03-20 02:35:35 +08:00
# MeshLoader::Load
## 方法签名
```cpp
LoadResult Load(const Containers::String& path, const ImportSettings* settings = nullptr) override;
```
## 详细描述
加载指定路径的网格资源文件。加载过程包括:
1. 提取文件扩展名并转换为小写
2. 验证文件格式是否支持
3. 读取文件数据到内存
4. 创建 `Mesh` 对象并设置基本信息路径、名称、GUID
5. 设置内存占用大小
当前实现专注于文件读取和基础资源创建框架,具体网格顶点数据、索引数据的解析由 `Mesh` 类在后续流程中完成。`settings` 参数当前未使用。
## 参数
| 参数 | 类型 | 默认值 | 描述 |
|------|------|--------|------|
| path | `const Containers::String&` | - | 网格文件路径 |
| settings | `const ImportSettings*` | `nullptr` | 导入设置(当前未使用) |
## 返回值
`LoadResult` - 加载结果对象,包含成功加载的 `Mesh` 指针或错误信息
## 示例
```cpp
#include "Resources/MeshLoader.h"
using namespace XCEngine::Resources;
MeshLoader loader;
LoadResult result = loader.Load("assets/models/player.fbx");
if (result.IsSuccess()) {
Mesh* mesh = static_cast<Mesh*>(result.GetResource());
printf("Loaded mesh: %s, GUID: %s, Size: %zu bytes\n",
mesh->m_name.CStr(),
mesh->m_guid.ToString().CStr(),
mesh->m_memorySize);
} else {
printf("Failed to load mesh: %s\n", result.GetError().CStr());
}
```
### 错误情况
- 不支持的文件格式:返回 `"Unsupported mesh format: <extension>"`
- 文件读取失败:返回 `"Failed to read file: <path>"`