docs: update resources API docs
This commit is contained in:
59
docs/api/resources/mesh-loader/index.md
Normal file
59
docs/api/resources/mesh-loader/index.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# MeshLoader
|
||||
|
||||
## 命名空间
|
||||
|
||||
`XCEngine::Resources`
|
||||
|
||||
## 类型
|
||||
|
||||
类 (Class)
|
||||
|
||||
## 描述
|
||||
|
||||
网格资源加载器,负责从磁盘加载 `.fbx`、`.obj`、`.gltf`、`.glb`、`.dae` 和 `.stl` 格式的网格资源文件。
|
||||
|
||||
## 概述
|
||||
|
||||
`MeshLoader` 继承自 `IResourceLoader`,实现了网格资源的加载功能。它支持多种主流 3D 模型文件格式,能够读取文件数据并创建 `Mesh` 对象。加载过程中会提取资源的基本信息(路径、名称、GUID)并设置内存占用。当前实现专注于文件读取和基础资源创建,具体网格数据解析由 `Mesh` 类完成。
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 签名 | 描述 |
|
||||
|------|------|------|
|
||||
| [MeshLoader](methods/constructor.md) | `MeshLoader()` | 默认构造函数 |
|
||||
| [~MeshLoader](methods/destructor.md) | `virtual ~MeshLoader()` | 析构函数 |
|
||||
| [GetResourceType](methods/get-resource-type.md) | `ResourceType GetResourceType() const` | 返回资源类型为 Mesh |
|
||||
| [GetSupportedExtensions](methods/get-supported-extensions.md) | `Array<String> GetSupportedExtensions() const` | 返回支持的扩展名列表 |
|
||||
| [CanLoad](methods/can-load.md) | `bool CanLoad(const String& path) const` | 检查给定路径是否可被加载 |
|
||||
| [Load](methods/load.md) | `LoadResult Load(const String& path, const ImportSettings* settings = nullptr)` | 加载指定路径的网格资源 |
|
||||
| [GetDefaultSettings](methods/get-default-settings.md) | `ImportSettings* GetDefaultSettings() const` | 返回默认导入设置 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/MeshLoader.h"
|
||||
#include "Resources/ResourceManager.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
// 通过 ResourceManager 加载网格
|
||||
auto meshHandle = ResourceManager::Get().Load<Mesh>("assets/models/player.fbx");
|
||||
if (meshHandle.IsValid()) {
|
||||
Mesh* mesh = meshHandle.Get();
|
||||
// 使用网格...
|
||||
}
|
||||
|
||||
// 直接使用 MeshLoader
|
||||
MeshLoader loader;
|
||||
LoadResult result = loader.Load("assets/models/player.obj");
|
||||
if (result.IsSuccess()) {
|
||||
Mesh* mesh = static_cast<Mesh*>(result.GetResource());
|
||||
// 使用网格...
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Mesh](../mesh/mesh.md)
|
||||
- [IResourceLoader](../iloader/iloader.md)
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md)
|
||||
36
docs/api/resources/mesh-loader/methods/can-load.md
Normal file
36
docs/api/resources/mesh-loader/methods/can-load.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# MeshLoader::CanLoad
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
bool CanLoad(const Containers::String& path) const override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
检查给定路径的文件是否可以被该加载器加载。方法通过提取文件扩展名并转换为小写后进行匹配判断。支持的文件格式包括:fbx、obj、gltf、glb、dae、stl。
|
||||
|
||||
## 参数
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| path | `const Containers::String&` | 文件路径 |
|
||||
|
||||
## 返回值
|
||||
|
||||
`bool` - 如果文件扩展名在支持列表中返回 `true`,否则返回 `false`
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/MeshLoader.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
MeshLoader loader;
|
||||
|
||||
bool canLoadFbx = loader.CanLoad("assets/models/player.fbx"); // true
|
||||
bool canLoadObj = loader.CanLoad("assets/models/cube.obj"); // true
|
||||
bool canLoadPng = loader.CanLoad("assets/textures/wood.png"); // false
|
||||
bool canLoadUnknown = loader.CanLoad("assets/data/model.xyz"); // false
|
||||
```
|
||||
29
docs/api/resources/mesh-loader/methods/constructor.md
Normal file
29
docs/api/resources/mesh-loader/methods/constructor.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# MeshLoader::MeshLoader
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
MeshLoader();
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
默认构造函数,使用默认行为构造 `MeshLoader` 对象。该构造函数不执行任何特殊初始化操作。
|
||||
|
||||
## 参数
|
||||
|
||||
无
|
||||
|
||||
## 返回值
|
||||
|
||||
无
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/MeshLoader.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
MeshLoader loader;
|
||||
```
|
||||
29
docs/api/resources/mesh-loader/methods/destructor.md
Normal file
29
docs/api/resources/mesh-loader/methods/destructor.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# MeshLoader::~MeshLoader
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
virtual ~MeshLoader() override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
析构函数,用于销毁 `MeshLoader` 对象。该析构函数不执行任何特殊清理操作。
|
||||
|
||||
## 参数
|
||||
|
||||
无
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/MeshLoader.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
{
|
||||
MeshLoader loader;
|
||||
// 使用 loader...
|
||||
}
|
||||
// loader 在此自动销毁
|
||||
```
|
||||
@@ -0,0 +1,31 @@
|
||||
# MeshLoader::GetDefaultSettings
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
ImportSettings* GetDefaultSettings() const override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
返回网格资源的默认导入设置。当前实现返回 `nullptr`,表示 `MeshLoader` 不使用导入设置。
|
||||
|
||||
## 参数
|
||||
|
||||
无
|
||||
|
||||
## 返回值
|
||||
|
||||
`ImportSettings*` - 返回 `nullptr`
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/MeshLoader.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
MeshLoader loader;
|
||||
ImportSettings* settings = loader.GetDefaultSettings();
|
||||
// settings == nullptr
|
||||
```
|
||||
31
docs/api/resources/mesh-loader/methods/get-resource-type.md
Normal file
31
docs/api/resources/mesh-loader/methods/get-resource-type.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# MeshLoader::GetResourceType
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
ResourceType GetResourceType() const override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
返回该加载器处理的资源类型。此方法标识 `MeshLoader` 负责加载 `Mesh` 类型的资源。
|
||||
|
||||
## 参数
|
||||
|
||||
无
|
||||
|
||||
## 返回值
|
||||
|
||||
`ResourceType` - 返回 `ResourceType::Mesh`,表示该加载器用于加载网格资源
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/MeshLoader.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
MeshLoader loader;
|
||||
ResourceType type = loader.GetResourceType();
|
||||
// type == ResourceType::Mesh
|
||||
```
|
||||
@@ -0,0 +1,46 @@
|
||||
# MeshLoader::GetSupportedExtensions
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
Containers::Array<Containers::String> GetSupportedExtensions() const override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
返回该加载器支持的文件扩展名列表。`MeshLoader` 支持六种主流 3D 模型文件格式:
|
||||
- `.fbx` - Autodesk FBX 格式
|
||||
- `.obj` - Wavefront OBJ 格式
|
||||
- `.gltf` - GL Transmission Format
|
||||
- `.glb` - GL Binary 格式
|
||||
- `.dae` - COLLADA 格式
|
||||
- `.stl` - STereoLithography 格式
|
||||
|
||||
## 参数
|
||||
|
||||
无
|
||||
|
||||
## 返回值
|
||||
|
||||
`Containers::Array<Containers::String>` - 支持的扩展名数组
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/MeshLoader.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
MeshLoader loader;
|
||||
auto extensions = loader.GetSupportedExtensions();
|
||||
for (const auto& ext : extensions) {
|
||||
printf("Supported extension: %s\n", ext.CStr());
|
||||
}
|
||||
// Output:
|
||||
// Supported extension: fbx
|
||||
// Supported extension: obj
|
||||
// Supported extension: gltf
|
||||
// Supported extension: glb
|
||||
// Supported extension: dae
|
||||
// Supported extension: stl
|
||||
```
|
||||
55
docs/api/resources/mesh-loader/methods/load.md
Normal file
55
docs/api/resources/mesh-loader/methods/load.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# 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>"`
|
||||
Reference in New Issue
Block a user