diff options
| -rw-r--r-- | API.md | 56 | ||||
| -rw-r--r-- | ReiLua_API.lua | 48 | ||||
| -rw-r--r-- | changelog | 3 | ||||
| -rw-r--r-- | devnotes | 4 | ||||
| -rw-r--r-- | examples/bunnymark/main.lua | 3 | ||||
| -rw-r--r-- | examples/lightmap/main.lua | 1 | ||||
| -rw-r--r-- | include/models.h | 6 | ||||
| -rw-r--r-- | src/lua_core.c | 11 | ||||
| -rw-r--r-- | src/models.c | 200 |
9 files changed, 320 insertions, 12 deletions
@@ -673,7 +673,7 @@ NPATCH_THREE_PATCH_VERTICAL NPATCH_THREE_PATCH_HORIZONTAL -## Globals - TextureModes +## Globals - TextureTypes TEXTURE_TYPE_TEXTURE @@ -4379,6 +4379,60 @@ Set shader for material --- +> success = RL.SetMaterialParams( Material material, float{} params ) + +Set material generic parameters ( if required ) + +- Failure return false +- Success return true + +--- + +> texture = RL.GetMaterialTexture( Material material, int mapType ) + +Get texture from material map type. Returns -1 if no texture. + +- Failure return false +- Success return int + +--- + +> color = RL.GetMaterialColor( Material material, int mapType ) + +Get color from material map type. + +- Failure return false +- Success return Color + +--- + +> value = RL.GetMaterialValue( Material material, int mapType ) + +Get color from material map type. + +- Failure return false +- Success return float + +--- + +> shader = RL.GetMaterialShader( Material material ) + +Get material shader. Returns -1 if no shader. + +- Failure return false +- Success return int + +--- + +> params = RL.GetMaterialParams( Material material ) + +Get material parameters. + +- Failure return false +- Success return float{} + +--- + ## Models - Model --- diff --git a/ReiLua_API.lua b/ReiLua_API.lua index d850b65..0ace7f4 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -379,7 +379,7 @@ RL.NPATCH_NINE_PATCH=0 RL.NPATCH_THREE_PATCH_VERTICAL=1 RL.NPATCH_THREE_PATCH_HORIZONTAL=2 --- Globals - TextureModes +-- Globals - TextureTypes RL.TEXTURE_TYPE_TEXTURE=0 RL.TEXTURE_TYPE_RENDER_TEXTURE=1 @@ -3408,6 +3408,52 @@ function RL.SetMaterialValue( material, mapType, value ) end ---@return any success function RL.SetMaterialShader( material, shader ) end +---Set material generic parameters ( if required ) +---- Failure return false +---- Success return true +---@param material any +---@param params any +---@return any success +function RL.SetMaterialParams( material, params ) end + +---Get texture from material map type. Returns -1 if no texture. +---- Failure return false +---- Success return int +---@param material any +---@param mapType integer +---@return any texture +function RL.GetMaterialTexture( material, mapType ) end + +---Get color from material map type. +---- Failure return false +---- Success return Color +---@param material any +---@param mapType integer +---@return any color +function RL.GetMaterialColor( material, mapType ) end + +---Get color from material map type. +---- Failure return false +---- Success return float +---@param material any +---@param mapType integer +---@return any value +function RL.GetMaterialValue( material, mapType ) end + +---Get material shader. Returns -1 if no shader. +---- Failure return false +---- Success return int +---@param material any +---@return any shader +function RL.GetMaterialShader( material ) end + +---Get material parameters. +---- Failure return false +---- Success return float{} +---@param material any +---@return any params +function RL.GetMaterialParams( material ) end + -- Models - Model ---Load model from files ( Meshes and materials ) @@ -12,6 +12,7 @@ KEY CHANGES: - ADDED: Raygui wrapper lib. - CHANGED: Can now have multiple Music objects like other Raylib objects instead of just one. - CHANGED: Texture now can be either Texture or RenderTexture. No need to change texture source anymore. + - ADDED: Material getter functions. Detailed changes: - FIXED: uluaGetRay was looking for integers instead of tables. @@ -71,6 +72,8 @@ Detailed changes: - ADDED: DrawBillboardPro - ADDED: rlGetVersion - ADDED: More rlgl General render state functions. + - ADDED: GetMaterialTexture, GetMaterialColor, GetMaterialValue and GetMaterialShader + - ADDED: SetMaterialParams and GetMaterialParams ------------------------------------------------------------------------ Release: ReiLua version 0.4.0 Using Raylib 4.2 @@ -34,3 +34,7 @@ Backlog { * UpdateMesh * LoadModelFromMesh } + +Bugs { + * CameraLib. Lateral movement is slower if looking down or up. +}
\ No newline at end of file diff --git a/examples/bunnymark/main.lua b/examples/bunnymark/main.lua index 06ab5d6..8274327 100644 --- a/examples/bunnymark/main.lua +++ b/examples/bunnymark/main.lua @@ -71,7 +71,8 @@ end function RL.draw() RL.ClearBackground( RL.RAYWHITE ) - for _, bunny in ipairs( bunnies ) do + for i = 1, #bunnies do + local bunny = bunnies[i] -- NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), -- a draw call is launched and buffer starts being filled again; -- before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... diff --git a/examples/lightmap/main.lua b/examples/lightmap/main.lua index 9dc5609..11cd632 100644 --- a/examples/lightmap/main.lua +++ b/examples/lightmap/main.lua @@ -77,7 +77,6 @@ function RL.init() }, } material = RL.CreateMaterial( materialData ) - matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) ) end diff --git a/include/models.h b/include/models.h index d8e3b14..5d9ea23 100644 --- a/include/models.h +++ b/include/models.h @@ -53,6 +53,12 @@ int lmodelsSetMaterialTexture( lua_State *L ); int lmodelsSetMaterialColor( lua_State *L ); int lmodelsSetMaterialValue( lua_State *L ); int lmodelsSetMaterialShader( lua_State *L ); +int lmodelsSetMaterialParams( lua_State *L ); +int lmodelsGetMaterialTexture( lua_State *L ); +int lmodelsGetMaterialColor( lua_State *L ); +int lmodelsGetMaterialValue( lua_State *L ); +int lmodelsGetMaterialShader( lua_State *L ); +int lmodelsGetMaterialParams( lua_State *L ); /* Model. */ int lmodelsLoadModel( lua_State *L ); int lmodelsLoadModelFromMesh( lua_State *L ); diff --git a/src/lua_core.c b/src/lua_core.c index 5b51114..a65c95a 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -17,21 +17,18 @@ static void assignGlobalInt( int value, const char *name ) { lua_State *L = state->luaState; lua_pushinteger( L, value ); - // lua_setglobal( L, name ); lua_setfield( L, -2, name ); } static void assignGlobalFloat( float value, const char *name ) { lua_State *L = state->luaState; lua_pushnumber( L, value ); - // lua_setglobal( L, name ); lua_setfield( L, -2, name ); } static void assignGlobalColor( Color color, const char *name ) { lua_State *L = state->luaState; uluaPushColor( L, color ); - // lua_setglobal( L, name ); lua_setfield( L, -2, name ); } @@ -368,7 +365,7 @@ void defineGlobals() { assignGlobalInt( NPATCH_NINE_PATCH, "NPATCH_NINE_PATCH" ); assignGlobalInt( NPATCH_THREE_PATCH_VERTICAL, "NPATCH_THREE_PATCH_VERTICAL" ); assignGlobalInt( NPATCH_THREE_PATCH_HORIZONTAL, "NPATCH_THREE_PATCH_HORIZONTAL" ); - /* TextureModes */ + /* TextureTypes */ assignGlobalInt( TEXTURE_TYPE_TEXTURE, "TEXTURE_TYPE_TEXTURE" ); assignGlobalInt( TEXTURE_TYPE_RENDER_TEXTURE, "TEXTURE_TYPE_RENDER_TEXTURE" ); /* Colors */ @@ -1088,6 +1085,12 @@ void luaRegister() { assingGlobalFunction( "SetMaterialColor", lmodelsSetMaterialColor ); assingGlobalFunction( "SetMaterialValue", lmodelsSetMaterialValue ); assingGlobalFunction( "SetMaterialShader", lmodelsSetMaterialShader ); + assingGlobalFunction( "SetMaterialParams", lmodelsSetMaterialParams ); + assingGlobalFunction( "GetMaterialTexture", lmodelsGetMaterialTexture ); + assingGlobalFunction( "GetMaterialColor", lmodelsGetMaterialColor ); + assingGlobalFunction( "GetMaterialValue", lmodelsGetMaterialValue ); + assingGlobalFunction( "GetMaterialShader", lmodelsGetMaterialShader ); + assingGlobalFunction( "GetMaterialParams", lmodelsGetMaterialParams ); /* Model. */ assingGlobalFunction( "LoadModel", lmodelsLoadModel ); assingGlobalFunction( "LoadModelFromMesh", lmodelsLoadModelFromMesh ); diff --git a/src/models.c b/src/models.c index 26e7e72..30bf73c 100644 --- a/src/models.c +++ b/src/models.c @@ -1768,7 +1768,6 @@ int lmodelsSetMaterialTexture( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - SetMaterialTexture( state->materials[ materialId ], mapType, *texturesGetSourceTexture( texId ) ); lua_pushboolean( L, true ); @@ -1797,7 +1796,6 @@ int lmodelsSetMaterialColor( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - state->materials[ materialId ]->maps[ mapType ].color = color; lua_pushboolean( L, true ); @@ -1826,7 +1824,6 @@ int lmodelsSetMaterialValue( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - state->materials[ materialId ]->maps[ mapType ].value = value; lua_pushboolean( L, true ); @@ -1854,7 +1851,6 @@ int lmodelsSetMaterialShader( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - state->materials[ materialId ]->shader = *state->shaders[ shaderId ]; lua_pushboolean( L, true ); @@ -1862,6 +1858,202 @@ int lmodelsSetMaterialShader( lua_State *L ) { } /* +> success = RL.SetMaterialParams( Material material, float{} params ) + +Set material generic parameters ( if required ) + +- Failure return false +- Success return true +*/ +int lmodelsSetMaterialParams( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetMaterialParams( Material material, float{} params )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t len = uluaGetTableLen( L ); + size_t materialId = lua_tointeger( L, 1 ); + + if ( !validMaterial( materialId ) ) { + lua_pushboolean( L, false ); + return 1; + } + float params[ len ]; + + int t = lua_gettop( L ); + int i = 0; + lua_pushnil( L ); + + while ( lua_next( L, t ) != 0 ) { + params[i] = lua_tonumber( L, -1 ); + i++; + lua_pop( L, 1 ); + } + int paramCount = ( len > 4 ) ? 4 : len; + + for ( int i = 0; i < paramCount; i++ ) { + state->materials[ materialId ]->params[i] = params[i]; + } + lua_pushboolean( L, true ); + + return 1; +} + +/* +> texture = RL.GetMaterialTexture( Material material, int mapType ) + +Get texture from material map type. Returns -1 if no texture. + +- Failure return false +- Success return int +*/ +int lmodelsGetMaterialTexture( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMaterialTexture( Material material, int mapType )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t materialId = lua_tointeger( L, 1 ); + int mapType = lua_tointeger( L, 2 ); + + if ( !validMaterial( materialId ) ) { + lua_pushboolean( L, false ); + return 1; + } + /* Check what ReiLua texture has same openGL texture and return that. */ + for ( int i = 0; i < state->textureCount; i++ ) { + if ( state->textures[i]->type == TEXTURE_TYPE_TEXTURE + && state->textures[i]->texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) { + lua_pushinteger( L, i ); + return 1; + } + else if ( state->textures[i]->type == TEXTURE_TYPE_RENDER_TEXTURE + && state->textures[i]->renderTexture.texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) { + lua_pushinteger( L, i ); + return 1; + } + } + lua_pushinteger( L, -1 ); + + return 1; +} + +/* +> color = RL.GetMaterialColor( Material material, int mapType ) + +Get color from material map type. + +- Failure return false +- Success return Color +*/ +int lmodelsGetMaterialColor( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMaterialColor( Material material, int mapType )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t materialId = lua_tointeger( L, 1 ); + int mapType = lua_tointeger( L, 2 ); + + if ( !validMaterial( materialId ) ) { + lua_pushboolean( L, false ); + return 1; + } + uluaPushColor( L, state->materials[ materialId ]->maps[ mapType ].color ); + + return 1; +} + +/* +> value = RL.GetMaterialValue( Material material, int mapType ) + +Get color from material map type. + +- Failure return false +- Success return float +*/ +int lmodelsGetMaterialValue( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMaterialValue( Material material, int mapType )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t materialId = lua_tointeger( L, 1 ); + int mapType = lua_tointeger( L, 2 ); + + if ( !validMaterial( materialId ) ) { + lua_pushboolean( L, false ); + return 1; + } + lua_pushnumber( L, state->materials[ materialId ]->maps[ mapType ].value ); + + return 1; +} + +/* +> shader = RL.GetMaterialShader( Material material ) + +Get material shader. Returns -1 if no shader. + +- Failure return false +- Success return int +*/ +int lmodelsGetMaterialShader( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMaterialShader( Material material )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t materialId = lua_tointeger( L, 1 ); + + if ( !validMaterial( materialId ) ) { + lua_pushboolean( L, false ); + return 1; + } + /* Look for shader that has same shader program id. */ + for ( int i = 0; i < state->shaderCount; i++ ) { + if ( state->shaders[i]->id == state->materials[ materialId ]->shader.id ) { + lua_pushinteger( L, i ); + return 1; + } + } + lua_pushinteger( L, -1 ); + + return 1; +} + +/* +> params = RL.GetMaterialParams( Material material ) + +Get material parameters. + +- Failure return false +- Success return float{} +*/ +int lmodelsGetMaterialParams( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMaterialParams( Material material )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t materialId = lua_tointeger( L, 1 ); + + if ( !validMaterial( materialId ) ) { + lua_pushboolean( L, false ); + return 1; + } + Vector4 params = { + state->materials[ materialId ]->params[0], + state->materials[ materialId ]->params[1], + state->materials[ materialId ]->params[2], + state->materials[ materialId ]->params[3] + }; + uluaPushVector4( L, params ); + + return 1; +} + +/* ## Models - Model */ |
