gltf-loader
Header: kmsroots/gltf-loader.h
Table of contents (click to go)
Macros
Enums
Unions
Structs
Functions
Function Pointers
API Documentation
kmr_gltf_loader_file
kmr_gltf_loader_file_create_info
kmr_gltf_loader_file_create
-
struct kmr_gltf_loader_file *kmr_gltf_loader_file_create(struct kmr_gltf_loader_file_create_info *gltfFileInfo);
This function is used to parse and load gltf files content into memory.
- Parameters:
- gltfFileInfoMust pass a pointer to a
structkmr_gltf_loader_file_create_info - Returns:
- on success: Pointer to a
structkmr_gltf_loader_fileon failure: NULL
kmr_gltf_loader_file_destroy
-
void kmr_gltf_loader_file_destroy(struct kmr_gltf_loader_file *gltfFile);
Frees any allocated memory and closes FD’s (if open) created after
kmr_gltf_loader_file_create()call.- Parameters:
- gltfFilePointer to a valid
structkmr_gltf_loader_file
/* Free'd members with fd's closed */ struct kmr_gltf_loader_file { cgltf_data *gltfData; }
kmr_gltf_loader_mesh_vertex_data
-
struct kmr_gltf_loader_mesh_vertex_data
-
Struct member order is arbitrary. SHOULD NOT BE USED DIRECTLY. Advise to create second stack buffer and copy data over to it. Members populated with vertices from GLTF file buffer.
kmr_gltf_loader_mesh_data
-
struct kmr_gltf_loader_mesh_data
-
uint32_t firstIndex;
-
uint32_t *indexBufferData;
-
uint32_t indexBufferDataCount;
-
uint32_t indexBufferDataSize;
-
struct kmr_gltf_loader_mesh_vertex_data *vertexBufferData;
-
uint32_t vertexBufferDataCount;
-
uint32_t vertexBufferDataSize;
firstIndex- Array index within the index buffer. Calculated in
kmr_gltf_loader_mesh_create()firstIndex = firstIndex + bufferElementCount (GLTF file accessor[index].count).Can be used by the application to fill in vkCmdDrawIndexed(3) function. indexBufferData- Buffer of index data belonging to mesh populated from GLTF file buffer at
indexBufferDataCount- Amount of elements in
indexBufferDataarray. indexBufferDataSize- The total size in bytes of the
indexBufferDataarray. vertexBufferData- Pointer to a buffer containing position vertices, normal,texture coordinates, and color populated from GLTF file buffer at
vertexBufferDataCount- Amount of elements in
vertexBufferDataarray. vertexBufferDataSize- The total size in bytes of the
vertexBufferDataarray.
-
uint32_t firstIndex;
kmr_gltf_loader_mesh
-
struct kmr_gltf_loader_mesh
-
uint16_t bufferIndex;
-
struct kmr_gltf_loader_mesh_data *meshData;
-
uint16_t meshDataCount;
bufferIndex- The index in the “buffers” (json key) array of give GLTF file.
meshData- Pointer to an array of
structkmr_gltf_loader_mesh_datastoring all important data related to each mesh. meshDataCount- Amount of meshes associated with a
bufferIndex.The array size ofmeshDataarray.
-
uint16_t bufferIndex;
kmr_gltf_loader_mesh_create_info
-
struct kmr_gltf_loader_mesh_create_info
-
struct kmr_gltf_loader_file *gltfFile;
-
uint16_t bufferIndex;
gltfFile- Must pass a valid pointer to a
structkmr_gltf_loader_filefor cgltf_datagltfDatamember bufferIndex- Index of buffer in GLTF file “buffers” (json key) array
-
struct kmr_gltf_loader_file *gltfFile;
kmr_gltf_loader_mesh_create
-
struct kmr_gltf_loader_mesh *kmr_gltf_loader_mesh_create(struct kmr_gltf_loader_mesh_create_info *meshInfo);
Function loops through all meshes and finds the associated accessor->buffer view for a given buffer at
bufferIndex. After retrieves all information required to understand the contents of the multiple sections in the buffer. The function then creates multiple meshes with appropriate data (structkmr_gltf_loader_mesh_data) so the application only need to call function and create their vertex buffer + index buffer array’s based upon what’s already populated. Converts GLTF buffer to a buffer that Vulkan can understand seperating each buffer, by their mesh index in GLTF file “meshes” (json key) array.- Parameters:
- meshInfoMust pass a pointer to a
structkmr_gltf_loader_mesh_create_info - Returns:
- on success: pointer to a
structkmr_gltf_loader_meshon failure: NULL
kmr_gltf_loader_mesh_destroy
-
void kmr_gltf_loader_mesh_destroy(struct kmr_gltf_loader_mesh *mesh);
Frees any allocated memory and closes FD’s (if open) created after
kmr_gltf_loader_mesh_create()call.- Parameters:
- meshPointer to a valid
structkmr_gltf_loader_mesh
/* Free'd members with fd's closed */ struct kmr_gltf_loader_mesh { struct kmr_gltf_loader_mesh_data { uint32_t *indexBufferData; struct kmr_gltf_loader_mesh_vertex_data *vertexBufferData; } struct kmr_gltf_loader_mesh_data *meshData; }
kmr_gltf_loader_texture_image
-
struct kmr_gltf_loader_texture_image
-
imageCount- Amount of images associated with a given GLTF file
totalBufferSize- Collective size of each image associated with a given GLTF file.Best utilized when creating single VkBuffer.
imageData- Pointer to an array of image metadata and pixel buffer.
kmr_gltf_loader_texture_image_create_info
-
struct kmr_gltf_loader_texture_image_create_info
-
struct kmr_gltf_loader_file *gltfFile;
-
const char *directory;
gltfFile- Must pass a valid pointer to
structkmr_gltf_loader_fileforcgltf_datagltfDatamember. directory- Must pass a pointer to a string detailing the directory ofwhere all images are stored. Absolute path to a file that residesin the same directory as the images will work too.
-
struct kmr_gltf_loader_file *gltfFile;
kmr_gltf_loader_texture_image_create
-
struct kmr_gltf_loader_texture_image *kmr_gltf_loader_texture_image_create(struct kmr_gltf_loader_texture_image_create_info *textureImageInfo);
Function Loads all images associated with gltf file into memory.
- Parameters:
- textureImageInfoMust pass a pointer to a
structkmr_gltf_loader_texture_image_create_info - Returns:
- on success: pointer to a
structkmr_gltf_loader_texture_imageon failure: NULL
kmr_gltf_loader_texture_image_destroy
-
void kmr_gltf_loader_texture_image_destroy(struct kmr_gltf_loader_texture_image *textureImage);
Frees any allocated memory and closes FD’s (if open) created after
kmr_gltf_loader_texture_image_create()call.- Parameters:
- textureImagePointer to a valid
structkmr_gltf_loader_texture_image
/* Free'd members with fd's closed */ struct kmr_gltf_loader_mesh { struct kmr_gltf_loader_mesh_data { uint32_t *indexBufferData; struct kmr_gltf_loader_mesh_vertex_data *vertexBufferData; } struct kmr_gltf_loader_mesh_data *meshData; }
kmr_gltf_loader_cgltf_texture_transform
-
struct kmr_gltf_loader_cgltf_texture_transform
-
More information can be found at KHR_texture_transform.
kmr_gltf_loader_cgltf_texture_view
-
struct kmr_gltf_loader_cgltf_texture_view
-
uint32_t textureIndex;
-
uint32_t imageIndex;
-
float scale;
-
struct kmr_gltf_loader_cgltf_texture_transform textureTransform;
textureIndex- Index in “textures” (json key) GLTF file array.
imageIndex- Index in “images” (json key) GTLF file array that belongsto the texture at
textureIndex. scale- The scalar parameter applied to each vector of the texture.
textureTransform- Contains data regarding texture coordinate scale factor, rotation inradians, & offset from origin.
-
uint32_t textureIndex;
kmr_gltf_loader_cgltf_pbr_metallic_roughness
-
struct kmr_gltf_loader_cgltf_pbr_metallic_roughness
-
struct kmr_gltf_loader_cgltf_texture_view baseColorTexture;
-
struct kmr_gltf_loader_cgltf_texture_view metallicRoughnessTexture;
-
float baseColorFactor[4];
-
float metallicFactor;
-
float roughnessFactor;
baseColorTexture- The main texture to be applied on an object and metadatain relates to texture.
metallicRoughnessTexture- Textures for metalness and roughness properties are packed togetherin a single texture (image). Used for readability letting theapplication writer know we are acquring texture->imageassociated with GLTF file
metallicRoughnessTexture.
Bellow define the metallic-roughness material model
baseColorFactor- The “main” color of the object surface (RBGA).
metallicFactor- Describes how much the reflective behavior of the material resemblesthat of a metal. Values range from 0.0 (non-metal) to 1.0 (metal).
roughnessFactor- Indicating how rough the surface is, affecting the light scattering.Values range from 0.0 (smooth) to 1.0 (rough).
-
struct kmr_gltf_loader_cgltf_texture_view baseColorTexture;
kmr_gltf_loader_material_data
-
struct kmr_gltf_loader_material_data
-
uint32_t meshIndex;
-
char *materialName;
-
struct kmr_gltf_loader_cgltf_pbr_metallic_roughness pbrMetallicRoughness;
-
struct kmr_gltf_loader_cgltf_texture_view normalTexture;
-
struct kmr_gltf_loader_cgltf_texture_view occlusionTexture;
More information can be found at GLTF 2.0 Reference Guide.
meshIndex- Index in “meshes” (json key) array of GLTF file that material belongs to.
materialName- Name given to material block contained in GLTF file.
pbrMetallicRoughness- “Physically-Based Rendering Metallic Roughness Model” - Allows renderers todisplay objects with a realistic appearance under different lighting conditions.Stores required data for PBR.
normalTexture- Stores a given texture tangent-space normal data,that will be applied to the normals of the coordinates.
occlusionTexture- Stores data about areas of a surface that are occluded from light,and thus rendered darker.
-
uint32_t meshIndex;
kmr_gltf_loader_material
-
struct kmr_gltf_loader_material
-
struct kmr_gltf_loader_material_data *materialData;
-
uint16_t materialDataCount;
materialData- Pointer to an array of
structkmr_gltf_loader_material_data. materialDataCount- Amount of elements in
materialDataarray.
-
struct kmr_gltf_loader_material_data *materialData;
kmr_gltf_loader_material_create_info
-
struct kmr_gltf_loader_material_create_info
-
struct kmr_gltf_loader_file *gltfFile;
gltfFile- Must pass a valid pointer to a
structkmr_gltf_loader_filefor cgltf_datagltfDatamember.
-
struct kmr_gltf_loader_file *gltfFile;
kmr_gltf_loader_material_create
-
struct kmr_gltf_loader_material *kmr_gltf_loader_material_create(struct kmr_gltf_loader_material_create_info *materialInfo);
Function Loads necessary material information associated with gltf file into memory.
- Parameters:
- materialInfoMust pass a pointer to a
structkmr_gltf_loader_material_create_infoi - Returns:
- on success: pointer to a
structkmr_gltf_loader_materialon failure: NULL
kmr_gltf_loader_material_destroy
-
void kmr_gltf_loader_material_destroy(struct kmr_gltf_loader_material *material);
Frees any allocated memory and closes FD’s (if open) created after
kmr_gltf_loader_material_create()call.- Parameters:
- materialPointer to a valid
structkmr_gltf_loader_material
/* Free'd members with fd's closed */ struct kmr_gltf_loader_material { struct kmr_gltf_loader_material_data { char *materialName; } struct kmr_gltf_loader_material_data *materialData; }
kmr_gltf_loader_gltf_object_type
-
enum kmr_gltf_loader_gltf_object_type
-
KMR_GLTF_LOADER_GLTF_NODE
-
KMR_GLTF_LOADER_GLTF_MESH
-
KMR_GLTF_LOADER_GLTF_SKIN
-
KMR_GLTF_LOADER_GLTF_CAMERA
Options used by
kmr_gltf_loader_node_dataKMR_GLTF_LOADER_GLTF_NODE- Value set to
0x0001 KMR_GLTF_LOADER_GLTF_MESH- Value set to
0x0002 KMR_GLTF_LOADER_GLTF_SKIN- Value set to
0x0003 KMR_GLTF_LOADER_GLTF_CAMERA- Value set to
0x0004
-
KMR_GLTF_LOADER_GLTF_NODE
kmr_gltf_loader_node_data
-
struct kmr_gltf_loader_node_data
-
enum kmr_gltf_loader_gltf_object_type objectType;
-
uint32_t objectIndex;
-
uint32_t nodeIndex;
-
uint32_t parentNodeIndex;
-
float matrixTransform[4][4];
objectType- Type of GLTF object that attached to node
objectIndex- The index in GLTF file “Insert Object Name” array. If
objectTypeis amesh this index is the index in the GLTF file “meshes” (json key) array. nodeIndex- Index in the GLTF file “nodes” (json key) array for child node.
parentNodeIndex- Index in the GLTF file “nodes” array (json key) for parent node.
matrixTransform- If matrix property not already defined. Value is T * R * S.T - translationR - RotationS - scaleFinal matrix transform is(identity matrix * TRS parent matrix) * (identity matrix * TRS child matrix)
-
enum kmr_gltf_loader_gltf_object_type objectType;
kmr_gltf_loader_node
-
struct kmr_gltf_loader_node
-
struct kmr_gltf_loader_node_data *nodeData;
-
uint32_t nodeDataCount;
nodeData- Pointer to an array of
structkmr_gltf_loader_node_data nodeDataCount- Amount of elements in
nodeDataarray.
-
struct kmr_gltf_loader_node_data *nodeData;
kmr_gltf_loader_node_create_info
-
struct kmr_gltf_loader_node_create_info
-
struct kmr_gltf_loader_file *gltfFile;
-
uint32_t sceneIndex;
gltfFile- Must pass a valid pointer to a
structkmr_gltf_loader_filefor cgltf_datagltfDatamember. sceneIndex- Index in GLTF file “scenes” (json key) array.
-
struct kmr_gltf_loader_file *gltfFile;
kmr_gltf_loader_node_create
-
struct kmr_gltf_loader_node *kmr_gltf_loader_node_create(struct kmr_gltf_loader_node_create_info *nodeInfo);
Calculates final translation * rotatation * scale matrix for all nodes associated with a scene. Along with final matrix transform data, function also returns the parent and child index in the GLTF file object “nodes” array, the type of node/object (i.e “mesh,skin,camera,etc…”), and the index of that object in the GLTF file “Insert Object Name” array.
- Parameters:
- nodeInfoMust pass a pointer to a
structkmr_gltf_loader_node_create_info - Returns:
- on success: pointer to a
structkmr_gltf_loader_nodeon failure: NULL
kmr_gltf_loader_node_destroy
-
void kmr_gltf_loader_node_destroy(struct kmr_gltf_loader_node *node);
Frees any allocated memory and closes FD’s (if open) created after
kmr_gltf_loader_node_create()call.- Parameters:
- nodePointer to a valid
structkmr_gltf_loader_node
/* Free'd members with fd's closed */ struct kmr_gltf_loader_node { struct kmr_gltf_loader_node_data *nodeData; }
kmr_gltf_loader_node_display_matrix_transform
-
void kmr_gltf_loader_node_display_matrix_transform(struct kmr_gltf_loader_node *node);
Prints out matrix transform for each node in
structkmr_gltf_loader_node{nodeData}.- Parameters:
- nodeMust pass a pointer to a
structkmr_gltf_loader_node