Rest of mesh management functions.

This commit is contained in:
jussi
2022-05-25 21:52:36 +03:00
parent 44e8b06603
commit 06f9940682
12 changed files with 186 additions and 17 deletions

View File

@@ -781,6 +781,10 @@ void luaRegister() {
lua_register( L, "RL_DrawMesh", lmodelsDrawMesh );
lua_register( L, "RL_DrawMeshInstanced", lmodelsDrawMeshInstanced );
lua_register( L, "RL_SetMeshColor", lmodelsSetMeshColor );
lua_register( L, "RL_ExportMesh", lmodelsExportMesh );
lua_register( L, "RL_GetMeshBoundingBox", lmodelsGetMeshBoundingBox );
lua_register( L, "RL_GenMeshTangents", lmodelsGenMeshTangents );
lua_register( L, "RL_GenMeshBinormals", lmodelsGenMeshBinormals );
/* Material. */
lua_register( L, "RL_LoadMaterialDefault", lmodelsLoadMaterialDefault );
lua_register( L, "RL_CreateMaterial", lmodelsCreateMaterial );
@@ -1626,6 +1630,28 @@ void uluaPushRayCollision( lua_State *L, RayCollision rayCol ) {
lua_setfield( L, -2, "normal" );
}
void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
lua_createtable( L, 2, 0 );
lua_createtable( L, 3, 0 );
lua_pushnumber( L, box.min.x );
lua_rawseti( L, -2, 1 );
lua_pushnumber( L, box.min.y );
lua_rawseti( L, -2, 2 );
lua_pushnumber( L, box.min.z );
lua_rawseti( L, -2, 3 );
lua_rawseti( L, -2, 1 );
lua_createtable( L, 3, 0 );
lua_pushnumber( L, box.max.x );
lua_rawseti( L, -2, 1 );
lua_pushnumber( L, box.max.y );
lua_rawseti( L, -2, 2 );
lua_pushnumber( L, box.max.z );
lua_rawseti( L, -2, 3 );
lua_rawseti( L, -2, 2 );
}
int uluaGetTableLen( lua_State *L ) {
int t = lua_gettop( L ), i = 0;
lua_pushnil( L );

View File

@@ -1374,6 +1374,108 @@ int lmodelsSetMeshColor( lua_State *L ) {
return 1;
}
/*
> success = RL_ExportMesh( Mesh mesh, string fileName )
Export mesh data to file, returns true on success
- Failure return false
- Success return true
*/
int lmodelsExportMesh( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ExportMesh( Mesh mesh, string fileName )" );
lua_pushboolean( L, false );
return 1;
}
size_t meshId = lua_tointeger( L, -2 );
if ( !validMesh( meshId ) ) {
lua_pushboolean( L, false );
return 1;
}
lua_pushboolean( L, ExportMesh( *state->meshes[ meshId ], lua_tostring( L, -1 ) ) );
return 1;
}
/*
> boundingBox = RL_GetMeshBoundingBox( Mesh mesh )
Compute mesh bounding box limits
- Failure return false
- Success return BoundingBox
*/
int lmodelsGetMeshBoundingBox( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetMeshBoundingBox( Mesh mesh )" );
lua_pushboolean( L, false );
return 1;
}
size_t meshId = lua_tointeger( L, -1 );
if ( !validMesh( meshId ) ) {
lua_pushboolean( L, false );
return 1;
}
uluaPushBoundingBox( L, GetMeshBoundingBox( *state->meshes[ meshId ] ) );
return 1;
}
/*
> success = RL_GenMeshTangents( Mesh mesh )
Compute mesh tangents
- Failure return false
- Success return true
*/
int lmodelsGenMeshTangents( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GenMeshTangents( Mesh mesh )" );
lua_pushboolean( L, false );
return 1;
}
size_t meshId = lua_tointeger( L, -1 );
if ( !validMesh( meshId ) ) {
lua_pushboolean( L, false );
return 1;
}
GenMeshTangents( state->meshes[ meshId ] );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_GenMeshBinormals( Mesh mesh )
Compute mesh binormals
- Failure return false
- Success return true
*/
int lmodelsGenMeshBinormals( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GenMeshBinormals( Mesh mesh )" );
lua_pushboolean( L, false );
return 1;
}
size_t meshId = lua_tointeger( L, -1 );
if ( !validMesh( meshId ) ) {
lua_pushboolean( L, false );
return 1;
}
GenMeshBinormals( state->meshes[ meshId ] );
lua_pushboolean( L, true );
return 1;
}
/*
## Models - Material
*/
@@ -1544,8 +1646,7 @@ int lmodelsSetMaterialTexture( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
// SetMaterialTexture( state->materials[ lua_tointeger( L, -3 ) ], lua_tointeger( L, -2 ), *state->textures[ lua_tointeger( L, -1 ) ] );
SetMaterialTexture( state->materials[ materialId ], lua_tointeger( L, -2 ), *texturesGetSourceTexture( texId ) );
lua_pushboolean( L, true );