![]() |
Skylicht Engine
|
Singleton class for loading, caching, exporting, and managing materials in Skylicht-Engine. More...
#include <Material/CMaterialManager.h>
Public Member Functions | |
| CMaterialManager () | |
| Constructor. | |
| virtual | ~CMaterialManager () |
| Destructor. Releases all loaded and generated materials. | |
| bool | isMaterialLoaded (const char *filename) |
| Check if a material file has already been loaded and cached. | |
| void | releaseAllMaterials () |
| Release all loaded and generated materials from memory. | |
| void | releaseAllMaterials (const char *package) |
| Release all materials that belong to a specific package. | |
| ArrayMaterial & | loadMaterial (const char *filename, bool loadTexture, const std::vector< std::string > &textureFolders) |
| Load a material file (.mat or .xml), parse its contents, and return the loaded materials. Materials are cached by filename and loaded only once. | |
| void | unloadMaterial (const char *filename) |
| Unload and release all materials loaded from a specific file. | |
| CMaterial * | createAndAddMaterial (ArrayMaterial &materials) |
| Create a new material and add it to the given material array. | |
| void | replaceTexture (ITexture *oldTexture, ITexture *newTexture) |
| Replace all occurrences of an old texture with a new texture in all managed materials. | |
| void | removeAndDeleteMaterial (ArrayMaterial &materials, CMaterial *material) |
| Delete a material from the given material array and also from the internal cache if present. | |
| void | saveMaterial (const ArrayMaterial &materials, const char *filename) |
| Save a set of materials to a material file, serializing their parameters, textures, and properties. | |
| void | exportMaterial (CEntityPrefab *prefab, const char *filename) |
| Export materials from a prefab (e.g., from a model) to a material file. Extracts shader, texture, and uniform information from the prefab's mesh data. | |
| ArrayMaterial | initDefaultMaterial (CEntityPrefab *prefab) |
| Initialize default materials for all meshes in a prefab, creating and assigning basic material data. Useful for generating materials directly from model data. | |
Static Public Member Functions | |
| static std::vector< std::string > | getMaterialExts () |
| Get the list of supported material file extensions. | |
| static bool | isMaterialExt (const char *ext) |
| Check if the given extension is a valid material file extension. | |
Protected Attributes | |
| std::map< std::string, ArrayMaterial > | m_materials |
| Map of loaded materials by filename. | |
| ArrayMaterial | m_listGenerateMaterials |
| List of generated materials not bound to a file. | |
Singleton class for loading, caching, exporting, and managing materials in Skylicht-Engine.
Provides functions to load materials from files, manage their lifetimes, export and save materials, replace textures, and initialize default materials from prefabs.
Example usage:
| CMaterial * Skylicht::CMaterialManager::createAndAddMaterial | ( | ArrayMaterial & | materials | ) |
Create a new material and add it to the given material array.
| materials | ArrayMaterial to add the new material to. |
| void Skylicht::CMaterialManager::exportMaterial | ( | CEntityPrefab * | prefab, |
| const char * | filename ) |
Export materials from a prefab (e.g., from a model) to a material file. Extracts shader, texture, and uniform information from the prefab's mesh data.
| prefab | Pointer to the prefab containing mesh and material data. |
| filename | Path to material file to write. |
|
static |
Get the list of supported material file extensions.
| ArrayMaterial Skylicht::CMaterialManager::initDefaultMaterial | ( | CEntityPrefab * | prefab | ) |
Initialize default materials for all meshes in a prefab, creating and assigning basic material data. Useful for generating materials directly from model data.
| prefab | Pointer to the prefab. |
|
static |
Check if the given extension is a valid material file extension.
| ext | Extension string (without dot). |
| bool Skylicht::CMaterialManager::isMaterialLoaded | ( | const char * | filename | ) |
Check if a material file has already been loaded and cached.
| filename | Path to material file. |
| ArrayMaterial & Skylicht::CMaterialManager::loadMaterial | ( | const char * | filename, |
| bool | loadTexture, | ||
| const std::vector< std::string > & | textureFolders ) |
Load a material file (.mat or .xml), parse its contents, and return the loaded materials. Materials are cached by filename and loaded only once.
| filename | Path to material file. |
| loadTexture | If true, loads textures referenced in material. |
| textureFolders | Additional folders to search for textures. |
| void Skylicht::CMaterialManager::releaseAllMaterials | ( | const char * | package | ) |
Release all materials that belong to a specific package.
| package | The package name to match. |
| void Skylicht::CMaterialManager::removeAndDeleteMaterial | ( | ArrayMaterial & | materials, |
| CMaterial * | material ) |
Delete a material from the given material array and also from the internal cache if present.
| materials | ArrayMaterial containing the material. |
| material | Pointer to the material to delete. |
Replace all occurrences of an old texture with a new texture in all managed materials.
| oldTexture | Pointer to the old texture. |
| newTexture | Pointer to the new texture. |
| void Skylicht::CMaterialManager::saveMaterial | ( | const ArrayMaterial & | materials, |
| const char * | filename ) |
Save a set of materials to a material file, serializing their parameters, textures, and properties.
| materials | ArrayMaterial to save. |
| filename | Path to material file to write. |
| void Skylicht::CMaterialManager::unloadMaterial | ( | const char * | filename | ) |
Unload and release all materials loaded from a specific file.
| filename | Path to material file. |