![]() |
LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
|
Functions | |
LG_Mesh * | lg_load_vbo (const char *path, zboolean force_reload_obj, zboolean invert_z, zboolean do_normalize_xyz, zboolean do_horiz_center, zboolean do_vert_center, zboolean do_vert_bottom) |
LG_Mesh * | lg_mesh_new_from_objfile (const char *path, zboolean invert_z, zboolean do_normalize_xyz, zboolean do_horiz_center, zboolean do_vert_center, zboolean do_vert_bottom) |
LG_Mesh * | lg_mesh_new_from_fbxfile (const char *path, zboolean invert_z, zboolean do_normalize_xyz, zboolean do_horiz_center, zboolean do_vert_center, zboolean do_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 *path, LG_Mesh *mesh) |
int | lg_vbo_load_from_file (const char *path, LG_Mesh **mesh) |
int | lg_mesh_reload_mats (LG_Mesh *mesh) |
This module deals with meshes, ie data that will feed VBOs and IBOs for fast and efficient drawing.
=== MESHES MUST BE PURE-TRIANGULAR ===
Using MeshLab filters: remeshing, simplification and reconstruction turn into a pure-triangle mesh Also: normals, curvatures and orientation transform: translate, center, set origin -> center on layer bbox normals, curvatures and orientation transform: scale, normalize -> scale to unit bbox
At the moment, read only a limited set of 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).
Will create a Vertex_uv_n VBO (see lg_vertex.h).
You can/should only use this func to load meshes:
LG_Mesh *lg_load_vbo(const char *path, zboolean force_reload_obj, zboolean do_normalize_xyz, zboolean do_horiz_center, zboolean do_vert_center)
and you can/should only use this func when done with a mesh:
void lg_mesh_free(LG_Mesh *)
and just ignore the details.
(Use everything here only if you know what you're doing).
LG_Mesh* lg_load_vbo | ( | const char * | path, |
zboolean | force_reload_obj, | ||
zboolean | invert_z, | ||
zboolean | do_normalize_xyz, | ||
zboolean | do_horiz_center, | ||
zboolean | do_vert_center, | ||
zboolean | do_vert_bottom | ||
) |
Load VBO &co
=== This is the entry point for loading meshes (obj, vbo, ibo) ===
We use a cache mechanism:
All mesh data is saved
On Android, obj files are cached as well
-> Should use:
Refactoring the I/O API -> assets dir and writable dir ? lg_io.c/h ? No, probably just need to better doc everything
path | Path to OBJ file |
force_reload_obj | Force (re)loading and (re)parsing 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 |
do_normalize_xyz | |
do_horiz_center | |
do_vert_center | Center mesh vertically, if do_vert_bottom is not set |
do_vert_bottom | Set mesh origin vertically at bottom, override do_vert_center |
LG_Mesh* lg_mesh_new_from_objfile | ( | const char * | path, |
zboolean | invert_z, | ||
zboolean | do_normalize_xyz, | ||
zboolean | do_horiz_center, | ||
zboolean | do_vert_center, | ||
zboolean | do_vert_bottom | ||
) |
Create mesh from obj file
path | OBJ file name |
invert_z | Invert z spatial coord - should be set to TRUE if mesh uses RH coords sys, FALSE if mesh uses LH coords sys |
do_normalize_xyz | Normalize spatial coords |
do_horiz_center | Center mesh horizontally |
do_vert_center | Center mesh vertically, if do_vert_bottom is not set |
do_vert_bottom | Set mesh origin vertically at bottom, override do_vert_center |
LG_Mesh* lg_mesh_new_from_fbxfile | ( | const char * | path, |
zboolean | invert_z, | ||
zboolean | do_normalize_xyz, | ||
zboolean | do_horiz_center, | ||
zboolean | do_vert_center, | ||
zboolean | do_vert_bottom | ||
) |
Create mesh from fbx file
path | FBX file name |
invert_z | Invert z spatial coord - should be set to TRUE if mesh uses RH coords sys, FALSE if mesh uses LH coords sys |
do_normalize_xyz | Normalize spatial coords |
do_horiz_center | Center mesh horizontally |
do_vert_center | Center mesh vertically, if do_vert_bottom is not set |
do_vert_bottom | Set mesh origin vertically at bottom, override do_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 | ? |
file_name | ? |
size | ? |
written_size | ? |
void* lg_obj_file_open_from_cache | ( | const char * | file_name | ) |
Load obj file from cache
file_name | The OBJ file name |
int lg_vbo_save_to_file | ( | const char * | path, |
LG_Mesh * | mesh | ||
) |
Actually save mesh with VBO and IBO in binary form, so should find a more accurate name. Don't add suffix LG_MESH_INFO_EXT, LG_MESH_VBO_EXT, LG_MESH_IBO_EXT to path, it's done automagically. Only the basename of path is used. All binary files are saved in the cache.
path | Path to OBJ file |
mesh | Pointer to a LG_Mesh |
int lg_vbo_load_from_file | ( | const char * | path, |
LG_Mesh ** | mesh | ||
) |
Same as above but for reading binary files
path | Path to OBJ file |
mesh | Pointer to an array of pointers to LG_Mesh |