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 (LG_Path obj_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_filename, LG_Path obj_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 ( LG_Path  obj_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_path (user-provided LG_Path to the OBJ file) to set mesh->path and locate MTL file and textures

The MTL file is expected to be in the same dir as the OBJ file

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

Parameters
obj_pathUser-provided LG_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 or NULL on error

◆ lg_mtl_parser()

int lg_mtl_parser ( const char *  mtl_filename,
LG_Path  obj_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_filename'mtllib' tag value in OBJ file, ie name of MTL files - expected to be in the same dir as the OBJ file
obj_pathLG_Path to OBJ file
matPointer to an array of N_NEWMTL_USEMTL_TAGS_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
v1Pointer to first Vertex_uv_n
v2Pointer to 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