LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_obj_parser.c File Reference

Functions

LG_Meshlg_obj2vbo (const char *mesh_name, FILE *stream, zboolean do_normalize_xyz)
 
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  do_normalize_xyz 
)

Parse a readable stream (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
do_normalize_xyz(self-explanatory enough)
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

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_max(not sure - read the src)

◆ 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_max(not sure - read the src)
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_max(not sure - read the src)
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