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

Implements a Wavefront OBJ 3D model file loader. More...

#include <ctype.h>
#include <float.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mesh.h"
#include "mtl.h"
#include "position.h"

Go to the source code of this file.

Data Structures

struct  gm3ObjLine

Functions

int gm3_obj_parse_next_line (char **end, gm3ObjLine *ln)
int gm3_obj_parse (char *content, gm3ObjLine **result, size_t *n_lines)
int32_t gm3_obj_load (gm3Mesh *m, const char *path, const char *dir)
 Loads a Wavefront OBJ 3D model from a file into a gm3Mesh structure.

Detailed Description

Implements a Wavefront OBJ 3D model file loader.

This file provides functionality to parse .obj files and load their geometric and material data into a gm3Mesh structure. It also handles the parsing of associated .mtl files indirectly via mtl.h.

Function Documentation

◆ gm3_obj_load()

int32_t gm3_obj_load ( gm3Mesh * m,
const char * path,
const char * dir )

Loads a Wavefront OBJ 3D model from a file into a gm3Mesh structure.

This function parses the .obj file, including vertices, normals, texture coordinates, and faces. It also loads associated .mtl material libraries. The gm3Mesh will be populated with all the data.

Parameters
mA pointer to the gm3Mesh structure to populate.
pathThe file path to the .obj model.
dirThe directory containing the .obj file, used for resolving relative .mtl paths.
Returns
0 on success, -1 on file reading or parsing failure, or a negative value from gm3_mtl_load on material loading failure.

◆ gm3_obj_parse()

int gm3_obj_parse ( char * content,
gm3ObjLine ** result,
size_t * n_lines )

◆ gm3_obj_parse_next_line()

int gm3_obj_parse_next_line ( char ** end,
gm3ObjLine * ln )