LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_obj_parser.c File Reference

Functions

LG_Meshlg_obj2vbo (const char *obj_full_path, 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, const char *obj_full_path, LG_Material *mat[])
 
int lg_vertex_cmp (Vertex_uv_n *v1, Vertex_uv_n *v2, zboolean tex_coords, zboolean normals)
 
zboolean lg_objparser_check_consistency ()
 

Detailed Description

=== The Wawefront OBJ file parser ===

Function Documentation

◆ lg_obj2vbo()

LG_Mesh * lg_obj2vbo ( const char *  obj_full_path,
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 obj_full_path (user-provided full path to the OBJ file) to set mesh->full_path and locate MTL file and textures

Doesn't close the stream, you'll have to do it yourself after the func returns

Parameters
obj_full_pathUser-provided full path to the OBJ file
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,
const char *  obj_full_path,
LG_Material mat[] 
)

Parse a MTL file

Get (materials) names and associated textures referenced by 'map_K' tags

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

Parameters
mtl_file'mtllib' tag value in OBJ file, ie name of MTL files
obj_full_pathFull path to OBJ file
matAddress of an array of N_MAT_MAX pointers to LG_Material structs
Returns
Num of texture references ('map_K') 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_objparser_check_consistency()

zboolean lg_objparser_check_consistency ( )

Only for init-time checking

Returns
LG_OK if OK, LG_ERROR on error