diff options
| author | jussi | 2022-05-25 21:52:36 +0300 |
|---|---|---|
| committer | jussi | 2022-05-25 21:52:36 +0300 |
| commit | 06f99406824b8bb03db17029279a0d139808cf6c (patch) | |
| tree | c0d8e4ae8b234c95a669fe609a7039cb07ada94b | |
| parent | 44e8b06603d91d398c0955f34da33d0242b7551a (diff) | |
| download | reilua-enhanced-06f99406824b8bb03db17029279a0d139808cf6c.tar.gz reilua-enhanced-06f99406824b8bb03db17029279a0d139808cf6c.tar.bz2 reilua-enhanced-06f99406824b8bb03db17029279a0d139808cf6c.zip | |
Rest of mesh management functions.
| -rw-r--r-- | API.md | 36 | ||||
| -rw-r--r-- | README.md | 14 | ||||
| -rw-r--r-- | devnotes | 1 | ||||
| -rw-r--r-- | examples/.gitignore | 1 | ||||
| -rw-r--r-- | examples/resources/images/LICENCE | 11 | ||||
| -rw-r--r-- | examples/resources/images/arcade_platformerV2.png | bin | 0 -> 37323 bytes | |||
| -rw-r--r-- | examples/resources/lib/vector2.lua | 2 | ||||
| -rw-r--r-- | examples/resources/lib/vector3.lua | 2 | ||||
| -rw-r--r-- | include/lua_core.h | 1 | ||||
| -rw-r--r-- | include/models.h | 4 | ||||
| -rw-r--r-- | src/lua_core.c | 26 | ||||
| -rw-r--r-- | src/models.c | 105 |
12 files changed, 186 insertions, 17 deletions
@@ -3297,6 +3297,42 @@ NOTE: Currently only works on custom mesh --- +> success = RL_ExportMesh( Mesh mesh, string fileName ) + +Export mesh data to file, returns true on success + +- Failure return false +- Success return true + +--- + +> boundingBox = RL_GetMeshBoundingBox( Mesh mesh ) + +Compute mesh bounding box limits + +- Failure return false +- Success return BoundingBox + +--- + +> success = RL_GenMeshTangents( Mesh mesh ) + +Compute mesh tangents + +- Failure return false +- Success return true + +--- + +> success = RL_GenMeshBinormals( Mesh mesh ) + +Compute mesh binormals + +- Failure return false +- Success return true + +--- + ## Models - Material --- @@ -12,24 +12,20 @@ Reilua means fair in finnish. ReiLua is WIP and some planned raylib functionality is still missing but it already has over 400 functions and should include all functions to make most 2d and 3d games. Current Raylib version 4.0.0. +Included submodules. + +* Raygui +* Raymath + List of some MISSING features that are planned to be included. For specific function, check API. * Core * VR stereo config functions for VR simulator * Textures * Texture update functions -* Text - * Some font loading/unloading functions * Audio * Wave * AudioStream management functions -* Mesh - * Some mesh management functions - -Submodules. - -* Raygui ( Done ) -* Raymath ( Done ) ## Usage @@ -3,7 +3,6 @@ Current { Backlog { * Text - * More Font loading/unloading functions * Codepoints * String management. At least TextSplit. * Audio diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..a1bb56d --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1 @@ +platformer
\ No newline at end of file diff --git a/examples/resources/images/LICENCE b/examples/resources/images/LICENCE index fca0d39..ce0f32f 100644 --- a/examples/resources/images/LICENCE +++ b/examples/resources/images/LICENCE @@ -1,5 +1,6 @@ -Resource Author Licence Source -tiles.png Chris Hamons (maintainer) CC0 https://opengameart.org/content/dungeon-crawl-32x32-tiles -apple.png Jussi Viitala CC0 -grass.png Jussi Viitala CC0 -snake.png Jussi Viitala CC0
\ No newline at end of file +Resource Author Licence Source +tiles.png Chris Hamons (maintainer) CC0 https://opengameart.org/content/dungeon-crawl-32x32-tiles +arcade_platformerV2.png GrafxKid CC0 https://opengameart.org/content/arcade-platformer-assets +apple.png Jussi Viitala CC0 +grass.png Jussi Viitala CC0 +snake.png Jussi Viitala CC0 diff --git a/examples/resources/images/arcade_platformerV2.png b/examples/resources/images/arcade_platformerV2.png Binary files differnew file mode 100644 index 0000000..1a529d2 --- /dev/null +++ b/examples/resources/images/arcade_platformerV2.png diff --git a/examples/resources/lib/vector2.lua b/examples/resources/lib/vector2.lua index 305f483..862718f 100644 --- a/examples/resources/lib/vector2.lua +++ b/examples/resources/lib/vector2.lua @@ -45,6 +45,8 @@ Vector2.meta = { function Vector2:new( x, y ) if type( x ) == "table" then x, y = table.unpack( x ) + elseif type( x ) == "nil" then + x, y = 0, 0 end local o = { diff --git a/examples/resources/lib/vector3.lua b/examples/resources/lib/vector3.lua index b0f1be9..bf3e4a7 100644 --- a/examples/resources/lib/vector3.lua +++ b/examples/resources/lib/vector3.lua @@ -59,6 +59,8 @@ end function Vector3:set( x, y, z ) if type( x ) == "table" then x, y, z = table.unpack( x ) + elseif type( x ) == "nil" then + x, y, z = 0, 0, 0 end self.x = x diff --git a/include/lua_core.h b/include/lua_core.h index 2cd120e..58b84d2 100644 --- a/include/lua_core.h +++ b/include/lua_core.h @@ -27,5 +27,6 @@ void uluaPushQuaternion( lua_State *L, Quaternion quaternion ); void uluaPushMatrix( lua_State *L, Matrix matrix ); void uluaPushRay( lua_State *L, Ray ray ); void uluaPushRayCollision( lua_State *L, RayCollision rayCol ); +void uluaPushBoundingBox( lua_State *L, BoundingBox box ); int uluaGetTableLen( lua_State *L ); diff --git a/include/models.h b/include/models.h index 15dae09..3e1d63e 100644 --- a/include/models.h +++ b/include/models.h @@ -35,6 +35,10 @@ int lmodelsUnloadMesh( lua_State *L ); int lmodelsDrawMesh( lua_State *L ); int lmodelsDrawMeshInstanced( lua_State *L ); int lmodelsSetMeshColor( lua_State *L ); +int lmodelsExportMesh( lua_State *L ); +int lmodelsGetMeshBoundingBox( lua_State *L ); +int lmodelsGenMeshTangents( lua_State *L ); +int lmodelsGenMeshBinormals( lua_State *L ); /* Material. */ int lmodelsLoadMaterialDefault( lua_State *L ); int lmodelsCreateMaterial( lua_State *L ); diff --git a/src/lua_core.c b/src/lua_core.c index 9a61120..f109f1b 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -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 ); diff --git a/src/models.c b/src/models.c index 0ae7805..2ae4de6 100644 --- a/src/models.c +++ b/src/models.c @@ -1375,6 +1375,108 @@ int lmodelsSetMeshColor( lua_State *L ) { } /* +> 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 ); |
