LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
All Data Structures Files Functions Variables
lg_obj_parser.c File Reference

Functions

LG_Meshlg_obj2vbo (const char *mesh_name, FILE *stream, zboolean invert_z, zboolean normalize_xyz, zboolean horiz_center, zboolean vert_center, zboolean vert_bottom)
 
int lg_mtl_parser (const char *mtl_file, LG_Material *mat[])
 
int lg_vertex_cmp (Vertex_uv_n *v1, Vertex_uv_n *v2, zboolean tex_coords, zboolean normals)
 
void lg_vbo_and_ibo_info (Vertex_uv_n *vbo_data, uint32_t *ibo_data, uint32_t vbo_size, uint32_t ibo_size, lg_vertex_type vertex_type, int n_lines_max)
 
void lg_vb_info (Vertex *vb_data, uint32_t vb_size, int n_lines_max, const char *line_start, zboolean is_triangle_mesh)
 
void lg_vb_rgba_info (Vertex_rgba *vb_data, uint32_t vb_size, int n_lines_max, const char *line_start, zboolean is_triangle_mesh)
 
zboolean lg_objparser_check_consistency ()
 

Detailed Description

=== The Wawefront OBJ file parser ===

Function Documentation

◆ lg_obj2vbo()

LG_Mesh* lg_obj2vbo ( const char *  mesh_name,
FILE *  stream,
zboolean  invert_z,
zboolean  normalize_xyz,
zboolean  horiz_center,
zboolean  vert_center,
zboolean  vert_bottom 
)

Parse a readable stream (an opened OBJ file) and create the mesh VBO and IBO

Will create a Vertex_uv_n VBO (see lg_vertex.h)

We use the full path of the obj file only to set mesh->name but it's not used anywhere else, as the file is already opened (saying that to avoid any possible confusion)

Parameters
mesh_nameOBJ file name
streamAn open stream of the obj file
invert_zInvert z spatial coord (left_handed vs right_handed coords sys) - STILL EXPERIMENTAL
normalize_xyzNormalize spatial coords
horiz_centerCenter mesh horizontally
vert_centerCenter mesh vertically, if vert_bottom is not set
vert_bottomSet mesh origin vertically at bottom, override vert_center
Returns
The new mesh

◆ lg_mtl_parser()

int lg_mtl_parser ( const char *  mtl_file,
LG_Material mat[] 
)

Parse a MTL file

Get materials names and associated textures

Don't set indice (it's done later)

Parameters
mtl_fileMTL file name
texAddress of an array of N_MAX_MAT_PER_OBJ pointers to LG_Material structs
Returns
Num of texture materials found if OK, -1 on error

◆ lg_vertex_cmp()

int lg_vertex_cmp ( Vertex_uv_n v1,
Vertex_uv_n v2,
zboolean  tex_coords,
zboolean  normals 
)

Compare two vertices

FIXME: should use adaptative epsilon or another better way of comparison.

Parameters
v1Addr of first Vertex_uv_n
v2Addr of second Vertex_uv_n
tex_coordsAlso compare texture coords
normalsAlso compare normals
Returns
0 if vertices are equal, -1 otherwise

◆ lg_vbo_and_ibo_info()

void lg_vbo_and_ibo_info ( Vertex_uv_n vbo_data,
uint32_t *  ibo_data,
uint32_t  vbo_size,
uint32_t  ibo_size,
lg_vertex_type  vertex_type,
int  n_lines_max 
)

Print out nicely VBO and IBO (arrays of Vertex_uv_n and uint32_t)

vertex_type is one of lg_vertex_type: WITH_COORDS_ONLY, WITH_TEXCOORDS, WITH_NORMALS, WITH_TEXCOORDS_AND_NORMALS

Parameters
vbo_dataPointer to (Vertex_uv_n) VBO with interleaved vertex data - sizeof(Vertex_uv_n) = 24
ibo_dataPointer to (uint32_t) IBO, indices start at 0, sizeof(uint32_t) = 4
vbo_sizeVBO size (uint32_t)
ibo_sizeIBO size uint32_t
vertex_typeA lg_vertex_type, see above
n_lines_maxPrint out up to n_lines_max lines

◆ lg_vb_info()

void lg_vb_info ( Vertex vb_data,
uint32_t  vb_size,
int  n_lines_max,
const char *  line_start,
zboolean  is_triangle_mesh 
)

Print out nicely a Vertex (ie spatial coords only) buffer info

v[1/2/3] applies only for triangle meshes

Parameters
vb_dataPointer to a Vertex buffer
vb_sizeBuffer size (uint32_t)
n_lines_maxPrint out up to n_lines_max lines
line_startString starting each line
is_triangle_mesh

◆ lg_vb_rgba_info()

void lg_vb_rgba_info ( Vertex_rgba vb_data,
uint32_t  vb_size,
int  n_lines_max,
const char *  line_start,
zboolean  is_triangle_mesh 
)

Print out nicely a Vertex_rgba (ie spatial coords + RGBA color) buffer info, actually spatial coords info ONLY

v[1/2/3] applies only for triangle meshes

Parameters
vb_dataPointer to a Vertex_rgba buffer
vb_sizeBuffer size (uint32_t)
n_lines_maxPrint out up to n_lines_max lines
line_startString starting each line
is_triangle_mesh

◆ lg_objparser_check_consistency()

zboolean lg_objparser_check_consistency ( )

Only for init-time checking

Returns
LG_OK if OK, LG_ERROR on error