- audio: 更新 audio-system 方法文档 - components: 新增 audio-listener/audio-source 组件方法文档,新增 remove-component 方法 - core: 更新 filewriter, types 文档 - math: 更新 box 方法文档 - memory: 更新 proxy-allocator 文档 - resources: 更新 loader 和 texture 文档 - rhi: 更新 opengl 设备、shader、swap-chain 文档 - threading: 更新 mutex 和 task-system 文档
2.2 KiB
2.2 KiB
MaterialLoader
命名空间
XCEngine::Resources
类型
类 (Class)
描述
材质资源加载器,负责从磁盘加载 .mat、.material 和 .json 格式的材质资源文件。
概述
MaterialLoader 继承自 IResourceLoader,实现了材质资源的加载功能。它支持多种材质文件格式,能够解析材质文件中的 shader 引用并自动加载对应的 Shader 资源。加载过程中会提取材质的基本属性信息并创建 Material 对象。
公共方法
| 方法 | 签名 | 描述 |
|---|---|---|
| MaterialLoader | MaterialLoader() |
默认构造函数 |
| ~MaterialLoader | virtual ~MaterialLoader() |
析构函数 |
| GetResourceType | ResourceType GetResourceType() const |
返回资源类型为 Material |
| GetSupportedExtensions | Array<String> GetSupportedExtensions() const |
返回支持的扩展名列表 |
| CanLoad | bool CanLoad(const String& path) const |
检查给定路径是否可被加载 |
| Load | LoadResult Load(const String& path, const ImportSettings* settings = nullptr) |
加载指定路径的材质资源 |
| GetDefaultSettings | ImportSettings* GetDefaultSettings() const |
返回默认导入设置 |
使用示例
#include "Resources/MaterialLoader.h"
#include "Resources/ResourceManager.h"
using namespace XCEngine::Resources;
// 通过 ResourceManager 加载材质
auto materialHandle = ResourceManager::Get().Load<Material>("assets/materials/wood.mat");
if (materialHandle.IsValid()) {
Material* material = materialHandle.Get();
// 使用材质...
}
// 直接使用 MaterialLoader
MaterialLoader loader;
LoadResult result = loader.Load("assets/materials/wood.material");
if (result.IsSuccess()) {
Material* material = static_cast<Material*>(result.GetResource());
// 使用材质...
}