Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::CMaterialManager Class Reference

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.
CMaterialcreateAndAddMaterial (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.

Detailed Description

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:

std::vector<std::string> textureFolders;
ArrayMaterial material = CMaterialManager::getInstance()->loadMaterial("SampleAnimations/HeroArtwork/Hero.mat", true, textureFolders);

Member Function Documentation

◆ createAndAddMaterial()

CMaterial * Skylicht::CMaterialManager::createAndAddMaterial ( ArrayMaterial & materials)

Create a new material and add it to the given material array.

Parameters
materialsArrayMaterial to add the new material to.
Returns
Pointer to the newly created material.

◆ exportMaterial()

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.

Parameters
prefabPointer to the prefab containing mesh and material data.
filenamePath to material file to write.

◆ getMaterialExts()

std::vector< std::string > Skylicht::CMaterialManager::getMaterialExts ( )
static

Get the list of supported material file extensions.

Returns
Vector of supported extensions (e.g., "xml", "mat").

◆ initDefaultMaterial()

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.

Parameters
prefabPointer to the prefab.
Returns
ArrayMaterial containing created materials.

◆ isMaterialExt()

bool Skylicht::CMaterialManager::isMaterialExt ( const char * ext)
static

Check if the given extension is a valid material file extension.

Parameters
extExtension string (without dot).
Returns
True if supported, false otherwise.

◆ isMaterialLoaded()

bool Skylicht::CMaterialManager::isMaterialLoaded ( const char * filename)

Check if a material file has already been loaded and cached.

Parameters
filenamePath to material file.
Returns
True if material is loaded, false otherwise.

◆ loadMaterial()

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.

Parameters
filenamePath to material file.
loadTextureIf true, loads textures referenced in material.
textureFoldersAdditional folders to search for textures.
Returns
Reference to ArrayMaterial containing loaded materials.

◆ releaseAllMaterials()

void Skylicht::CMaterialManager::releaseAllMaterials ( const char * package)

Release all materials that belong to a specific package.

Parameters
packageThe package name to match.

◆ removeAndDeleteMaterial()

void Skylicht::CMaterialManager::removeAndDeleteMaterial ( ArrayMaterial & materials,
CMaterial * material )

Delete a material from the given material array and also from the internal cache if present.

Parameters
materialsArrayMaterial containing the material.
materialPointer to the material to delete.

◆ replaceTexture()

void Skylicht::CMaterialManager::replaceTexture ( ITexture * oldTexture,
ITexture * newTexture )

Replace all occurrences of an old texture with a new texture in all managed materials.

Parameters
oldTexturePointer to the old texture.
newTexturePointer to the new texture.

◆ saveMaterial()

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.

Parameters
materialsArrayMaterial to save.
filenamePath to material file to write.

◆ unloadMaterial()

void Skylicht::CMaterialManager::unloadMaterial ( const char * filename)

Unload and release all materials loaded from a specific file.

Parameters
filenamePath to material file.

The documentation for this class was generated from the following file: