![]() |
LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
|
Functions | |
| LG_Mesh * | lg_mesh_load (const char *file_name, LG_LoadMesh_Flags flags) |
| LG_Mesh * | lg_mesh_new_from_objfile (const char *file_name, zboolean invert_z, zboolean normalize_xyz, zboolean horiz_center, zboolean vert_center, zboolean vert_bottom) |
| LG_Mesh * | lg_mesh_new_from_fbxfile (const char *file_name, zboolean invert_z, zboolean normalize_xyz, zboolean horiz_center, zboolean vert_center, zboolean vert_bottom) |
| void | lg_mesh_free (LG_Mesh *mesh) |
| void | lg_mesh_info (LG_Mesh *mesh) |
| int | lg_obj_file_save_to_cache (void *asset_buf, const char *file_name, size_t size, size_t *written_size) |
| void * | lg_obj_file_open_from_cache (const char *file_name) |
| int | lg_vbo_save_to_file (const char *file_name, LG_Mesh *mesh) |
| int | lg_vbo_save_to_file_in_cache (const char *file_name, LG_Mesh *mesh) |
| int | lg_vbo_load_from_file (const char *file_name, LG_Mesh **mesh) |
| int | lg_vbo_load_from_file_in_cache (const char *file_name, LG_Mesh **mesh) |
| int | lg_mesh_reload_mats (LG_Mesh *mesh) |
| LG_LoadMesh_Flags | lg_loadmesh_flags (zboolean force_reload, zboolean invert_z, zboolean normalize_xyz, zboolean horiz_center, zboolean vert_center, zboolean vert_bottom) |
This module deals with meshes, ie data that will feed VBOs and IBOs for fast and efficient drawing.
You can/should only use this func to load meshes:
and you can/should only use this func when done with a mesh:
and just ignore the details.
(Use everything here only if you know what you're doing).
| LG_Mesh* lg_mesh_load | ( | const char * | file_name, |
| LG_LoadMesh_Flags | flags | ||
| ) |
Load OBJ or VBO &co.
=== THIS IS THE NEW ENTRY POINT FOR LOADING MESHES (OBJ, FBX, VBO, IBO, INFO) AND THE ONLY FUNC YOU NEED TO CALL ===
We use the following sequence:
On Android, OBJ files are cached as well
| file_name | Name of OBJ or VBO &co files (= VBO, IBO, and INFO binaries) - only BASENAME is required |
| flags | Apply to mesh: force_reload, invert_z, normalize_xyz, horiz_center, vert_center, vert_bottom |
| LG_Mesh* lg_mesh_new_from_objfile | ( | const char * | file_name, |
| zboolean | invert_z, | ||
| zboolean | normalize_xyz, | ||
| zboolean | horiz_center, | ||
| zboolean | vert_center, | ||
| zboolean | vert_bottom | ||
| ) |
Create mesh from OBJ file.
Read data from WAVEFRONT OBJ files: vertex/index values for v (coords), vt (texture coords), vn (normals), f (triangular faces), mtllib, usemtl (materials/textures stuff), plus newmtl, and map_K* (in MTL files).
Other data is ignored so far.
=== WARNING: MESHES MUST BE PURE-TRIANGULAR ===
Will create a Vertex_uv_n VBO (see lg_vertex.h).
| file_name | OBJ file name - only BASENAME is required |
| invert_z | Invert z spatial coord - should be set to TRUE if mesh uses RH coords sys, FALSE if mesh uses LH coords sys |
| normalize_xyz | Normalize spatial coords |
| horiz_center | Center mesh horizontally |
| vert_center | Center mesh vertically, if vert_bottom is not set |
| vert_bottom | Set mesh origin vertically at bottom, override vert_center |
| LG_Mesh* lg_mesh_new_from_fbxfile | ( | const char * | file_name, |
| zboolean | invert_z, | ||
| zboolean | normalize_xyz, | ||
| zboolean | horiz_center, | ||
| zboolean | vert_center, | ||
| zboolean | vert_bottom | ||
| ) |
Create mesh from FBX file.
| file_name | FBX file name - only BASENAME is required |
| invert_z | Invert z spatial coord - should be set to TRUE if mesh uses RH coords sys, FALSE if mesh uses LH coords sys |
| normalize_xyz | Normalize spatial coords |
| horiz_center | Center mesh horizontally |
| vert_center | Center mesh vertically, if vert_bottom is not set |
| vert_bottom | Set mesh origin vertically at bottom, override vert_center |
| void lg_mesh_free | ( | LG_Mesh * | mesh | ) |
Free mesh.
| mesh |
| int lg_obj_file_save_to_cache | ( | void * | asset_buf, |
| const char * | file_name, | ||
| size_t | size, | ||
| size_t * | written_size | ||
| ) |
Save OBJ file to cache.
| asset_buf | Mem buffer |
| file_name | OBJ file name - only BASENAME is required |
| size | |
| written_size |
| void* lg_obj_file_open_from_cache | ( | const char * | file_name | ) |
Open OBJ file from cache.
NOTE: this func is meant to be used with lg_obj2vbo().
| file_name | The OBJ file name |
| int lg_vbo_save_to_file | ( | const char * | file_name, |
| LG_Mesh * | mesh | ||
| ) |
Save mesh VBO and IBO in binary format, plus LG_Mesh struct instance as INFO -> file_name.obj.vbo, file_name.obj.ibo, and file_name.obj.info. Don't add suffix LG_MESH_INFO_EXT, LG_MESH_VBO_EXT, LG_MESH_IBO_EXT to path, as it's done automagically. Only the basename of path is used. All binary files are saved in the assets vbo folder.
| file_name | OBJ file name - only BASENAME is required |
| mesh | Pointer to a LG_Mesh |
| int lg_vbo_save_to_file_in_cache | ( | const char * | file_name, |
| LG_Mesh * | mesh | ||
| ) |
Save mesh VBO and IBO in binary format, plus LG_Mesh struct instance as INFO -> file_name.obj.vbo, file_name.obj.ibo, and file_name.obj.info. Don't add suffix LG_MESH_INFO_EXT, LG_MESH_VBO_EXT, LG_MESH_IBO_EXT to path, as it's done automagically. Only the basename of path is used. All binary files are saved in the cache/vbo folder.
| file_name | OBJ file name - only BASENAME is required |
| mesh | Pointer to a LG_Mesh |
| int lg_vbo_load_from_file | ( | const char * | file_name, |
| LG_Mesh ** | mesh | ||
| ) |
Same as above but for reading binary files in the assets vbo folder.
| file_name | OBJ file name - only BASENAME is required |
| mesh | Pointer to an array of pointers to LG_Mesh |
| int lg_vbo_load_from_file_in_cache | ( | const char * | file_name, |
| LG_Mesh ** | mesh | ||
| ) |
Same as above but for reading binary files in the vbo_cache folder.
| file_name | OBJ file name - only BASENAME is required |
| mesh | Pointer to an array of pointers to LG_Mesh |
| int lg_mesh_reload_mats | ( | LG_Mesh * | mesh | ) |
Reload materials textures correctly, when mesh is loaded from cache.
| mesh | Pointer to a LG_Mesh |
| LG_LoadMesh_Flags lg_loadmesh_flags | ( | zboolean | force_reload, |
| zboolean | invert_z, | ||
| zboolean | normalize_xyz, | ||
| zboolean | horiz_center, | ||
| zboolean | vert_center, | ||
| zboolean | vert_bottom | ||
| ) |
Mesh loading flags.
See lg_load_vbo().
You can use these helper, which are all set to TRUE:
| force_reload | Force (re)loading and (re)parsing of the OBJ file |
| invert_z | Invert z spatial coord - should be set to TRUE if mesh uses RH coords sys, FALSE if mesh uses LH coords sys |
| normalize_xyz | |
| horiz_center | |
| vert_center | Center mesh vertically, if vert_bottom is not set |
| vert_bottom | Set mesh origin vertically at bottom, override vert_center |