Kemena3D
Loading...
Searching...
No Matches
kemena::kAssetManager Class Reference

Central asset-loading and cache manager. More...

#include <kassetmanager.h>

Public Member Functions

 kAssetManager ()
 Constructs an empty asset manager with no loaded assets.
kString getFileExtension (const kString &fileName)
 Extracts the file extension from a path kString.
bool fileExists (const kString &fileName)
 Checks whether a file exists on disk.
kString getBaseDir (const kString &filePath)
 Returns the directory portion of a file path.
kString getBaseFilename (const kString &filePath)
 Returns the filename without directory or extension.
kString getExecDir ()
 Returns the directory containing the running executable.
kString popDir (const kString &filePath)
 Removes the last directory component from a path.
unsigned char * loadImageFromResource (const char *resourceName, int &width, int &height, int &channels)
 Loads an image from a Windows embedded resource into CPU memory.
kTexture2DloadTexture2D (const kString fileName, const kString textureName, const kTextureFormat format=kTextureFormat::TEX_FORMAT_SRGBA, const bool flipVertical=false, const bool keepData=false)
 Loads a 2D texture from a file on disk and uploads it to the GPU.
kTexture2DloadTexture2DFromMemory (const aiTexture *rawData, const kString textureName, const kTextureFormat format=kTextureFormat::TEX_FORMAT_SRGBA, const bool flipVertical=false, const bool keepData=false)
 Loads a 2D texture from an in-memory Assimp texture blob.
kTexture2DloadTexture2DFromResource (const kString resourceName, const kString textureName, const kTextureFormat format=kTextureFormat::TEX_FORMAT_SRGBA, const bool flipVertical=false, const bool keepData=false)
 Loads a 2D texture from a Windows embedded resource.
void saveTexture2D (kTexture2D *texture, const kString fileName, kString format)
 Saves a kTexture2D to disk using the specified image format.
kTextureCubeloadTextureCube (const kString fileNameRight, const kString fileNameLeft, const kString fileNameTop, const kString fileNameBottom, const kString fileNameFront, const kString fileNameBack, const kString textureName)
 Loads a cube-map texture from six individual face files.
kTextureCubeloadTextureCubeFromResource (const kString resRight, const kString resLeft, const kString resTop, const kString resBottom, const kString resFront, const kString resBack, const kString textureName)
 Loads a cube-map texture from six Windows embedded resources.
kMeshloadMesh (const kString fileName)
 Loads a mesh hierarchy from a file, using Assimp for 3D formats.
kMeshloadMeshFromResource (const kString resourceName, const kString extention)
 Loads a mesh from a Windows embedded resource.
kMeshloadMeshFileAssimp (const kString fileName)
 Loads a mesh file using the Assimp importer.
kMeshloadMeshResourceAssimp (const kString resourceName, const kString extention)
 Loads a mesh from an embedded resource using the Assimp importer.
kMeshprocessNode (aiNode *node, const aiScene *scene, kMesh *parent)
 Recursively converts an Assimp node into a kMesh hierarchy.
kMeshprocessMesh (aiMesh *mesh, const aiScene *scene)
 Converts a single Assimp mesh into a kMesh.
kMeshloadMeshGltf (const kString fileName)
 Loads a glTF or GLB file with tinygltf into a kMesh hierarchy.
void calculateNormal (float N[3], float v0[3], float v1[3], float v2[3])
 Computes the face normal for a triangle.
void normalizeVector (kVec3 &v)
 Normalises a kVec3 in-place.
void extractBoneWeightForVertices (kMesh *mesh, aiMesh *meshData, const aiScene *scene)
 Reads bone-weight data from an Assimp mesh and populates a kMesh.
void setVertexBoneData (kMesh *mesh, size_t vertexID, int boneID, float weight)
 Assigns one bone influence slot to a vertex (helper used during loading).
kShaderloadShaderFromFile (kString vertexShaderPath, kString fragmentShaderPath)
 Compiles a shader program from GLSL source files on disk.
kShaderloadShaderFromCode (kString vertexShaderCode, kString fragmentShaderCode)
 Compiles a shader program from inline GLSL source strings.
kShaderloadShaderFromResource (kString vertexShaderName, kString fragmentShaderName)
 Compiles a shader program from Windows embedded resources.
kShaderloadGlslFromResource (kString resourceName)
 Compiles a combined GLSL shader from a Windows embedded resource. The resource must contain the vertex shader source, then the literal line "// --- FRAGMENT ---", then the fragment shader source.
kMaterialcreateMaterial (kShader *shader)
 Creates a new material with a pre-assigned shader.
kSkeletalAnimationloadAnimation (const kString fileName, kMesh *mesh)
 Loads a skeletal animation from a file for a given mesh.

Detailed Description

Central asset-loading and cache manager.

Provides helpers for common filesystem operations and factory methods for textures (2D and cube-map), meshes (via Assimp), shader programs, materials, and skeletal animations. All loaded assets are tracked internally; call the appropriate delete methods when assets are no longer needed.

Constructor & Destructor Documentation

◆ kAssetManager()

kemena::kAssetManager::kAssetManager ( )

Constructs an empty asset manager with no loaded assets.

Member Function Documentation

◆ calculateNormal()

void kemena::kAssetManager::calculateNormal ( float N[3],
float v0[3],
float v1[3],
float v2[3] )

Computes the face normal for a triangle.

Parameters
NOutput: normalised face normal.
v0First vertex position.
v1Second vertex position.
v2Third vertex position.

◆ createMaterial()

kMaterial * kemena::kAssetManager::createMaterial ( kShader * shader)

Creates a new material with a pre-assigned shader.

Parameters
shaderCompiled shader to attach to the material.
Returns
Heap-allocated kMaterial; caller takes ownership.

◆ extractBoneWeightForVertices()

void kemena::kAssetManager::extractBoneWeightForVertices ( kMesh * mesh,
aiMesh * meshData,
const aiScene * scene )

Reads bone-weight data from an Assimp mesh and populates a kMesh.

Parameters
meshDestination kMesh.
meshDataSource Assimp mesh.
sceneParent Assimp scene.

◆ fileExists()

bool kemena::kAssetManager::fileExists ( const kString & fileName)

Checks whether a file exists on disk.

Parameters
fileNameAbsolute or relative file path.
Returns
true if the file is accessible.

◆ getBaseDir()

kString kemena::kAssetManager::getBaseDir ( const kString & filePath)

Returns the directory portion of a file path.

Parameters
filePathFull file path.
Returns
Directory path with trailing separator.

◆ getBaseFilename()

kString kemena::kAssetManager::getBaseFilename ( const kString & filePath)

Returns the filename without directory or extension.

Parameters
filePathFull file path.
Returns
Bare filename stem.

◆ getExecDir()

kString kemena::kAssetManager::getExecDir ( )

Returns the directory containing the running executable.

Returns
Executable directory with trailing separator.

◆ getFileExtension()

kString kemena::kAssetManager::getFileExtension ( const kString & fileName)

Extracts the file extension from a path kString.

Parameters
fileNameFile path or name.
Returns
Lower-case extension without the leading dot.

◆ loadAnimation()

kSkeletalAnimation * kemena::kAssetManager::loadAnimation ( const kString fileName,
kMesh * mesh )

Loads a skeletal animation from a file for a given mesh.

Parameters
fileNamePath to the animation file.
meshMesh whose bone map is used to bind the animation.
Returns
Heap-allocated kAnimation; caller takes ownership.

◆ loadGlslFromResource()

kShader * kemena::kAssetManager::loadGlslFromResource ( kString resourceName)

Compiles a combined GLSL shader from a Windows embedded resource. The resource must contain the vertex shader source, then the literal line "// --- FRAGMENT ---", then the fragment shader source.

Parameters
resourceNameRC resource name for the combined .glsl source.
Returns
Heap-allocated kShader; caller takes ownership.

◆ loadImageFromResource()

unsigned char * kemena::kAssetManager::loadImageFromResource ( const char * resourceName,
int & width,
int & height,
int & channels )

Loads an image from a Windows embedded resource into CPU memory.

Parameters
resourceNameResource identifier kString.
widthReceives the image width in pixels.
heightReceives the image height in pixels.
channelsReceives the number of colour channels.
Returns
Heap-allocated pixel data; caller must free with stbi_image_free.

◆ loadMesh()

kMesh * kemena::kAssetManager::loadMesh ( const kString fileName)

Loads a mesh hierarchy from a file, using Assimp for 3D formats.

Parameters
fileNamePath to the mesh file.
Returns
Root kMesh of the loaded hierarchy; caller takes ownership.

◆ loadMeshFileAssimp()

kMesh * kemena::kAssetManager::loadMeshFileAssimp ( const kString fileName)

Loads a mesh file using the Assimp importer.

Parameters
fileNamePath to the asset file.
Returns
Root kMesh; caller takes ownership.

◆ loadMeshFromResource()

kMesh * kemena::kAssetManager::loadMeshFromResource ( const kString resourceName,
const kString extention )

Loads a mesh from a Windows embedded resource.

Parameters
resourceNameResource identifier kString.
extentionFile extension hint for Assimp (e.g. ".fbx").
Returns
Root kMesh; caller takes ownership.

◆ loadMeshGltf()

kMesh * kemena::kAssetManager::loadMeshGltf ( const kString fileName)

Loads a glTF or GLB file with tinygltf into a kMesh hierarchy.

Always available — this is the only importer in slim runtime builds (KEMENA_NO_ASSIMP). When Assimp is included, this method is still defined so callers can opt into the lighter loader explicitly.

Parameters
fileNamePath to a .gltf or .glb asset.
Returns
Root kMesh, or nullptr on failure.

◆ loadMeshResourceAssimp()

kMesh * kemena::kAssetManager::loadMeshResourceAssimp ( const kString resourceName,
const kString extention )

Loads a mesh from an embedded resource using the Assimp importer.

Parameters
resourceNameResource identifier kString.
extentionFile extension hint.
Returns
Root kMesh; caller takes ownership.

◆ loadShaderFromCode()

kShader * kemena::kAssetManager::loadShaderFromCode ( kString vertexShaderCode,
kString fragmentShaderCode )

Compiles a shader program from inline GLSL source strings.

Parameters
vertexShaderCodeVertex shader GLSL source.
fragmentShaderCodeFragment shader GLSL source.
Returns
Heap-allocated kShader; caller takes ownership.

◆ loadShaderFromFile()

kShader * kemena::kAssetManager::loadShaderFromFile ( kString vertexShaderPath,
kString fragmentShaderPath )

Compiles a shader program from GLSL source files on disk.

Parameters
vertexShaderPathPath to the vertex shader source.
fragmentShaderPathPath to the fragment shader source.
Returns
Heap-allocated kShader; caller takes ownership.

◆ loadShaderFromResource()

kShader * kemena::kAssetManager::loadShaderFromResource ( kString vertexShaderName,
kString fragmentShaderName )

Compiles a shader program from Windows embedded resources.

Parameters
vertexShaderNameResource name for the vertex shader.
fragmentShaderNameResource name for the fragment shader.
Returns
Heap-allocated kShader; caller takes ownership.

◆ loadTexture2D()

kTexture2D * kemena::kAssetManager::loadTexture2D ( const kString fileName,
const kString textureName,
const kTextureFormat format = kTextureFormat::TEX_FORMAT_SRGBA,
const bool flipVertical = false,
const bool keepData = false )

Loads a 2D texture from a file on disk and uploads it to the GPU.

Parameters
fileNamePath to the image file.
textureNameGLSL sampler uniform name.
formatDesired GPU format (default SRGBA).
flipVerticalFlip the image vertically before upload.
keepDataRetain CPU-side pixel data after upload.
Returns
Heap-allocated kTexture2D; caller takes ownership.

◆ loadTexture2DFromMemory()

kTexture2D * kemena::kAssetManager::loadTexture2DFromMemory ( const aiTexture * rawData,
const kString textureName,
const kTextureFormat format = kTextureFormat::TEX_FORMAT_SRGBA,
const bool flipVertical = false,
const bool keepData = false )

Loads a 2D texture from an in-memory Assimp texture blob.

Parameters
rawDataAssimp embedded texture descriptor.
textureNameGLSL sampler uniform name.
formatDesired GPU format.
flipVerticalFlip vertically before upload.
keepDataRetain CPU-side pixel data.
Returns
Heap-allocated kTexture2D; caller takes ownership.

◆ loadTexture2DFromResource()

kTexture2D * kemena::kAssetManager::loadTexture2DFromResource ( const kString resourceName,
const kString textureName,
const kTextureFormat format = kTextureFormat::TEX_FORMAT_SRGBA,
const bool flipVertical = false,
const bool keepData = false )

Loads a 2D texture from a Windows embedded resource.

Parameters
resourceNameResource identifier kString.
textureNameGLSL sampler uniform name.
formatDesired GPU format.
flipVerticalFlip vertically before upload.
keepDataRetain CPU-side pixel data.
Returns
Heap-allocated kTexture2D; caller takes ownership.

◆ loadTextureCube()

kTextureCube * kemena::kAssetManager::loadTextureCube ( const kString fileNameRight,
const kString fileNameLeft,
const kString fileNameTop,
const kString fileNameBottom,
const kString fileNameFront,
const kString fileNameBack,
const kString textureName )

Loads a cube-map texture from six individual face files.

Parameters
fileNameRight+X face image path.
fileNameLeft-X face image path.
fileNameTop+Y face image path.
fileNameBottom-Y face image path.
fileNameFront+Z face image path.
fileNameBack-Z face image path.
textureNameGLSL samplerCube uniform name.
Returns
Heap-allocated kTextureCube; caller takes ownership.

◆ loadTextureCubeFromResource()

kTextureCube * kemena::kAssetManager::loadTextureCubeFromResource ( const kString resRight,
const kString resLeft,
const kString resTop,
const kString resBottom,
const kString resFront,
const kString resBack,
const kString textureName )

Loads a cube-map texture from six Windows embedded resources.

Parameters
resRight+X face resource name.
resLeft-X face resource name.
resTop+Y face resource name.
resBottom-Y face resource name.
resFront+Z face resource name.
resBack-Z face resource name.
textureNameGLSL samplerCube uniform name.
Returns
Heap-allocated kTextureCube; caller takes ownership.

◆ normalizeVector()

void kemena::kAssetManager::normalizeVector ( kVec3 & v)

Normalises a kVec3 in-place.

Parameters
vVector to normalise.

◆ popDir()

kString kemena::kAssetManager::popDir ( const kString & filePath)

Removes the last directory component from a path.

Parameters
filePathInput path.
Returns
Path with the last component removed.

◆ processMesh()

kMesh * kemena::kAssetManager::processMesh ( aiMesh * mesh,
const aiScene * scene )

Converts a single Assimp mesh into a kMesh.

Parameters
meshAssimp mesh descriptor.
sceneParent Assimp scene (for texture lookups).
Returns
Heap-allocated kMesh; caller takes ownership.

◆ processNode()

kMesh * kemena::kAssetManager::processNode ( aiNode * node,
const aiScene * scene,
kMesh * parent )

Recursively converts an Assimp node into a kMesh hierarchy.

Parameters
nodeAssimp node to process.
sceneParent Assimp scene.
parentParent kMesh node (nullptr for root).
Returns
kMesh node corresponding to node.

◆ saveTexture2D()

void kemena::kAssetManager::saveTexture2D ( kTexture2D * texture,
const kString fileName,
kString format )

Saves a kTexture2D to disk using the specified image format.

Parameters
textureSource texture with CPU-side pixel data retained.
fileNameOutput file path.
formatOutput format kString (e.g. "png", "jpg").

◆ setVertexBoneData()

void kemena::kAssetManager::setVertexBoneData ( kMesh * mesh,
size_t vertexID,
int boneID,
float weight )

Assigns one bone influence slot to a vertex (helper used during loading).

Parameters
meshTarget kMesh.
vertexIDZero-based vertex index.
boneIDBone palette index.
weightBlend weight.

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