|
Kemena3D
|
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. | |
| kTexture2D * | 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. | |
| kTexture2D * | 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. | |
| kTexture2D * | 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. | |
| void | saveTexture2D (kTexture2D *texture, const kString fileName, kString format) |
| Saves a kTexture2D to disk using the specified image format. | |
| kTextureCube * | 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. | |
| kTextureCube * | 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. | |
| kMesh * | loadMesh (const kString fileName) |
| Loads a mesh hierarchy from a file, using Assimp for 3D formats. | |
| kMesh * | loadMeshFromResource (const kString resourceName, const kString extention) |
| Loads a mesh from a Windows embedded resource. | |
| kMesh * | loadMeshFileAssimp (const kString fileName) |
| Loads a mesh file using the Assimp importer. | |
| kMesh * | loadMeshResourceAssimp (const kString resourceName, const kString extention) |
| Loads a mesh from an embedded resource using the Assimp importer. | |
| kMesh * | processNode (aiNode *node, const aiScene *scene, kMesh *parent) |
| Recursively converts an Assimp node into a kMesh hierarchy. | |
| kMesh * | processMesh (aiMesh *mesh, const aiScene *scene) |
| Converts a single Assimp mesh into a kMesh. | |
| kMesh * | loadMeshGltf (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). | |
| kShader * | loadShaderFromFile (kString vertexShaderPath, kString fragmentShaderPath) |
| Compiles a shader program from GLSL source files on disk. | |
| kShader * | loadShaderFromCode (kString vertexShaderCode, kString fragmentShaderCode) |
| Compiles a shader program from inline GLSL source strings. | |
| kShader * | loadShaderFromResource (kString vertexShaderName, kString fragmentShaderName) |
| Compiles a shader program from Windows embedded resources. | |
| kShader * | 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. | |
| kMaterial * | createMaterial (kShader *shader) |
| Creates a new material with a pre-assigned shader. | |
| kSkeletalAnimation * | loadAnimation (const kString fileName, kMesh *mesh) |
| Loads a skeletal animation from a file for a given mesh. | |
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.
| kemena::kAssetManager::kAssetManager | ( | ) |
Constructs an empty asset manager with no loaded assets.
| void kemena::kAssetManager::calculateNormal | ( | float | N[3], |
| float | v0[3], | ||
| float | v1[3], | ||
| float | v2[3] ) |
Computes the face normal for a triangle.
| N | Output: normalised face normal. |
| v0 | First vertex position. |
| v1 | Second vertex position. |
| v2 | Third vertex position. |
Creates a new material with a pre-assigned shader.
| shader | Compiled shader to attach to the material. |
| void kemena::kAssetManager::extractBoneWeightForVertices | ( | kMesh * | mesh, |
| aiMesh * | meshData, | ||
| const aiScene * | scene ) |
| bool kemena::kAssetManager::fileExists | ( | const kString & | fileName | ) |
Checks whether a file exists on disk.
| fileName | Absolute or relative file path. |
Returns the directory portion of a file path.
| filePath | Full file path. |
Returns the filename without directory or extension.
| filePath | Full file path. |
| kString kemena::kAssetManager::getExecDir | ( | ) |
Returns the directory containing the running executable.
Extracts the file extension from a path kString.
| fileName | File path or name. |
| kSkeletalAnimation * kemena::kAssetManager::loadAnimation | ( | const kString | fileName, |
| kMesh * | mesh ) |
Loads a skeletal animation from a file for a given mesh.
| fileName | Path to the animation file. |
| mesh | Mesh whose bone map is used to bind the animation. |
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.
| resourceName | RC resource name for the combined .glsl source. |
| 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.
| resourceName | Resource identifier kString. |
| width | Receives the image width in pixels. |
| height | Receives the image height in pixels. |
| channels | Receives the number of colour channels. |
Loads a mesh hierarchy from a file, using Assimp for 3D formats.
| fileName | Path to the mesh file. |
Loads a mesh file using the Assimp importer.
| fileName | Path to the asset file. |
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.
| fileName | Path to a .gltf or .glb asset. |
| kShader * kemena::kAssetManager::loadShaderFromCode | ( | kString | vertexShaderCode, |
| kString | fragmentShaderCode ) |
Compiles a shader program from inline GLSL source strings.
| vertexShaderCode | Vertex shader GLSL source. |
| fragmentShaderCode | Fragment shader GLSL source. |
| kShader * kemena::kAssetManager::loadShaderFromFile | ( | kString | vertexShaderPath, |
| kString | fragmentShaderPath ) |
Compiles a shader program from GLSL source files on disk.
| vertexShaderPath | Path to the vertex shader source. |
| fragmentShaderPath | Path to the fragment shader source. |
| kShader * kemena::kAssetManager::loadShaderFromResource | ( | kString | vertexShaderName, |
| kString | fragmentShaderName ) |
Compiles a shader program from Windows embedded resources.
| vertexShaderName | Resource name for the vertex shader. |
| fragmentShaderName | Resource name for the fragment shader. |
| 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.
| fileName | Path to the image file. |
| textureName | GLSL sampler uniform name. |
| format | Desired GPU format (default SRGBA). |
| flipVertical | Flip the image vertically before upload. |
| keepData | Retain CPU-side pixel data after upload. |
| 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.
| rawData | Assimp embedded texture descriptor. |
| textureName | GLSL sampler uniform name. |
| format | Desired GPU format. |
| flipVertical | Flip vertically before upload. |
| keepData | Retain CPU-side pixel data. |
| 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.
| resourceName | Resource identifier kString. |
| textureName | GLSL sampler uniform name. |
| format | Desired GPU format. |
| flipVertical | Flip vertically before upload. |
| keepData | Retain CPU-side pixel data. |
| 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.
| 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. |
| textureName | GLSL samplerCube uniform name. |
| 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.
| 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. |
| textureName | GLSL samplerCube uniform name. |
| void kemena::kAssetManager::normalizeVector | ( | kVec3 & | v | ) |
Normalises a kVec3 in-place.
| v | Vector to normalise. |
Removes the last directory component from a path.
| filePath | Input path. |
| kMesh * kemena::kAssetManager::processMesh | ( | aiMesh * | mesh, |
| const aiScene * | scene ) |
| void kemena::kAssetManager::saveTexture2D | ( | kTexture2D * | texture, |
| const kString | fileName, | ||
| kString | format ) |
Saves a kTexture2D to disk using the specified image format.
| texture | Source texture with CPU-side pixel data retained. |
| fileName | Output file path. |
| format | Output format kString (e.g. "png", "jpg"). |
| 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).
| mesh | Target kMesh. |
| vertexID | Zero-based vertex index. |
| boneID | Bone palette index. |
| weight | Blend weight. |