Gama C Library
Gama C API Documentation
gltf.h File Reference

Implements a glTF 3D model file loader. More...

#include <stdio.h>
#include <string.h>
#include "mesh.h"
#include "position.h"
#include "../../cgltf.h"

Go to the source code of this file.

Macros

#define GM_DYN_ARRAY_INIT_CAP   256
#define GM_DYN_ARRAY_APPEND(arr, count, capacity, item)
#define CGLTF_IMPLEMENTATION

Functions

int gm3_gltf_load (gm3Mesh *mesh, const char *path)
 Loads a glTF 3D model from a file.
int gmd_gltf_print (const char *path)
 Prints a diagnostic overview of a glTF file to the console.

Detailed Description

Implements a glTF 3D model file loader.

This file provides functionality to parse glTF (.gltf, .glb) files and load their geometric and material data into a gm3Mesh structure. It uses the cgltf library for core glTF parsing.

Macro Definition Documentation

◆ CGLTF_IMPLEMENTATION

#define CGLTF_IMPLEMENTATION

◆ GM_DYN_ARRAY_APPEND

#define GM_DYN_ARRAY_APPEND ( arr,
count,
capacity,
item )
Value:
do { \
if ((count) >= (capacity)) { \
(capacity) = (capacity) == 0 ? GM_DYN_ARRAY_INIT_CAP : (capacity)*2; \
(arr) = realloc((arr), (capacity) * sizeof(*(arr))); \
} \
(arr)[(count)++] = (item); \
} while (0)
#define GM_DYN_ARRAY_INIT_CAP
Definition gltf.h:20
void * realloc(void *ptr, size_t size)
Custom implementation of realloc for memory allocated by malloc (this custom version).
Definition malloc.h:236

◆ GM_DYN_ARRAY_INIT_CAP

#define GM_DYN_ARRAY_INIT_CAP   256

Function Documentation

◆ gm3_gltf_load()

int gm3_gltf_load ( gm3Mesh * mesh,
const char * path )

Loads a glTF 3D model from a file.

Loads a glTF 3D model from a file into a gm3Mesh structure.

Parameters
meshA pointer to the gm3Mesh structure to populate.
pathThe file path to the glTF model (.gltf or .glb).
Returns
0 on success, -1 on failure.

This function parses the glTF file, including geometric data (vertices, normals, texture coordinates), material properties, and textures. It dynamically allocates memory for the mesh components as it encounters them.

Parameters
meshA pointer to the gm3Mesh structure to populate.
pathThe file path to the glTF model (.gltf or .glb).
Returns
0 on success, -1 on file parsing or loading failure.

◆ gmd_gltf_print()

int gmd_gltf_print ( const char * path)

Prints a diagnostic overview of a glTF file to the console.

Parameters
pathThe file path to the glTF model (.gltf or .glb).
Returns
0 on success, -1 on failure.