summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2023-12-07 22:38:13 +0200
committerjussi2023-12-07 22:38:13 +0200
commiteb7873be2be3d0ac4808c7416b190888a0e94145 (patch)
tree31fef2d03e258c998a810d802345bcf55332bf06
parent6ecbbcc282bb25fae4bcd2e9f394adb74ac60ae7 (diff)
downloadreilua-enhanced-eb7873be2be3d0ac4808c7416b190888a0e94145.tar.gz
reilua-enhanced-eb7873be2be3d0ac4808c7416b190888a0e94145.tar.bz2
reilua-enhanced-eb7873be2be3d0ac4808c7416b190888a0e94145.zip
More Model management functions, BoneInfo and Transform.
-rw-r--r--API.md107
-rw-r--r--ReiLua_API.lua89
-rw-r--r--changelog3
-rw-r--r--devnotes9
-rw-r--r--docgen.lua4
-rw-r--r--include/lua_core.h5
-rw-r--r--include/models.h12
-rw-r--r--src/lua_core.c169
-rw-r--r--src/models.c222
9 files changed, 590 insertions, 30 deletions
diff --git a/API.md b/API.md
index 99e6035..66c7827 100644
--- a/API.md
+++ b/API.md
@@ -221,6 +221,18 @@ GlyphInfo, font characters glyphs info
---
+> BoneInfo = { name = string[32], parent = int }
+
+Bone, skeletal animation bone
+
+---
+
+> Transform = { translation = Vector3, rotation = Quaternion, scale = Vector3 }
+
+Transform, vertex transformation data
+
+---
+
> Wave = Userdata
Wave, audio wave data
@@ -2977,7 +2989,7 @@ GL_COMPUTE_SHADER
---
-## Defines - RLGL GlVersion
+## Defines - RLGL GL blending factors
> RL_ZERO = 0
GL_ZERO
@@ -6585,9 +6597,24 @@ Compute model bounding box limits (considers all meshes)
---
+> RL.SetModelTransform( Model model, Matrix transform )
+
+Set model transform matrix
+
+---
+
+> success = RL.SetModelMesh( Model model, int meshId, Mesh mesh )
+
+Get model mesh. Return as lightuserdata
+
+- Failure return false
+- Success return true
+
+---
+
> success = RL.SetModelMaterial( Model model, int modelMaterialId, Material material )
-Copies material to model material. (Model material is the material id in models.)
+Copies material to model material
- Failure return false
- Success return true
@@ -6600,9 +6627,21 @@ Set material for a mesh (Mesh and material on this model)
---
-> RL.SetModelTransform( Model model, Matrix transform )
+> success = RL.SetModelBone( Model model, int boneId, BoneInfo bone )
-Set model transform matrix
+Set model bone information (skeleton)
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL.SetModelBindPose( Model model, int boneId, Transform pose )
+
+Set model bones base transformation (pose)
+
+- Failure return false
+- Success return true
---
@@ -6614,6 +6653,66 @@ Get model transform matrix
---
+> meshCount = RL.GetModelMeshCount( Model model )
+
+Get model number of meshes
+
+- Success return int
+
+---
+
+> meshCount = RL.GetModelMaterialCount( Model model )
+
+Get model number of materials
+
+- Success return int
+
+---
+
+> mesh = RL.GetModelMesh( Model model, int meshId )
+
+Get model mesh. Return as lightuserdata
+
+- Failure return nil
+- Success return Mesh
+
+---
+
+> material = RL.GetModelMaterial( Model model, int materialId )
+
+Get model material. Return as lightuserdata
+
+- Failure return nil
+- Success return Material
+
+---
+
+> boneCount = RL.GetModelBoneCount( Model model )
+
+Get model number of bones
+
+- Success return int
+
+---
+
+> bone = RL.GetModelBone( Model model, int boneId )
+
+Get model bones information (skeleton)
+
+- Failure return nil
+- Success return BoneInfo
+
+---
+
+> pose = RL.GetModelBindPose( Model model, int boneId )
+
+Get models bones base transformation (pose)
+
+- Failure return nil
+- Success return Transform
+
+---
+
## Models - Model drawing functions
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 73217f9..2c02e30 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -1034,7 +1034,7 @@ RL.RL_VERTEX_SHADER=35633
---GL_COMPUTE_SHADER
RL.RL_COMPUTE_SHADER=37305
--- Defines - RLGL GlVersion
+-- Defines - RLGL GL blending factors
---GL_ZERO
RL.RL_ZERO=0
@@ -3995,7 +3995,22 @@ function RL.UnloadModel( model ) end
---@return any boundingBox
function RL.GetModelBoundingBox( model ) end
----Copies material to model material. (Model material is the material id in models.)
+---Set model transform matrix
+---@param model any
+---@param transform table
+---@return any RL.SetModelTransform
+function RL.SetModelTransform( model, transform ) end
+
+---Get model mesh. Return as lightuserdata
+---- Failure return false
+---- Success return true
+---@param model any
+---@param meshId integer
+---@param mesh any
+---@return any success
+function RL.SetModelMesh( model, meshId, mesh ) end
+
+---Copies material to model material
---- Failure return false
---- Success return true
---@param model any
@@ -4011,11 +4026,23 @@ function RL.SetModelMaterial( model, modelMaterialId, material ) end
---@return any RL.SetModelMeshMaterial
function RL.SetModelMeshMaterial( model, meshId, materialId ) end
----Set model transform matrix
+---Set model bone information (skeleton)
+---- Failure return false
+---- Success return true
---@param model any
----@param transform table
----@return any RL.SetModelTransform
-function RL.SetModelTransform( model, transform ) end
+---@param boneId integer
+---@param bone any
+---@return any success
+function RL.SetModelBone( model, boneId, bone ) end
+
+---Set model bones base transformation (pose)
+---- Failure return false
+---- Success return true
+---@param model any
+---@param boneId integer
+---@param pose any
+---@return any success
+function RL.SetModelBindPose( model, boneId, pose ) end
---Get model transform matrix
---- Success return Matrix
@@ -4023,6 +4050,56 @@ function RL.SetModelTransform( model, transform ) end
---@return any transform
function RL.GetModelTransform( model ) end
+---Get model number of meshes
+---- Success return int
+---@param model any
+---@return any meshCount
+function RL.GetModelMeshCount( model ) end
+
+---Get model number of materials
+---- Success return int
+---@param model any
+---@return any meshCount
+function RL.GetModelMaterialCount( model ) end
+
+---Get model mesh. Return as lightuserdata
+---- Failure return nil
+---- Success return Mesh
+---@param model any
+---@param meshId integer
+---@return any mesh
+function RL.GetModelMesh( model, meshId ) end
+
+---Get model material. Return as lightuserdata
+---- Failure return nil
+---- Success return Material
+---@param model any
+---@param materialId integer
+---@return any material
+function RL.GetModelMaterial( model, materialId ) end
+
+---Get model number of bones
+---- Success return int
+---@param model any
+---@return any boneCount
+function RL.GetModelBoneCount( model ) end
+
+---Get model bones information (skeleton)
+---- Failure return nil
+---- Success return BoneInfo
+---@param model any
+---@param boneId integer
+---@return any bone
+function RL.GetModelBone( model, boneId ) end
+
+---Get models bones base transformation (pose)
+---- Failure return nil
+---- Success return Transform
+---@param model any
+---@param boneId integer
+---@return any pose
+function RL.GetModelBindPose( model, boneId ) end
+
-- Models - Model drawing functions
---Draw a model (With texture if set)
diff --git a/changelog b/changelog
index e00d32e..eaeaa2c 100644
--- a/changelog
+++ b/changelog
@@ -20,6 +20,7 @@ KEY CHANGES:
- CHANGE: Raygui wrapper library is now object based. Possible to have multiple separated gui systems.
- ADDED: Raygui wrapper library disabled and styles for each element.
- ADDED: Files management functions.
+ - ADDED: More Model management functions.
DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
@@ -39,6 +40,8 @@ DETAILED CHANGES:
- ADDED: GetTextureDefault.
- CHANGE: Renamed Files management functions to Files system functions as in raylib.
- CHANGE: Renamed ExportBufferAsCode to ExportDataAsCode.
+ - ADDED: BoneInfo.
+ - ADDED: Transform.
------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5
diff --git a/devnotes b/devnotes
index 1d9999e..85bd550 100644
--- a/devnotes
+++ b/devnotes
@@ -5,7 +5,7 @@ Backlog {
* Raygui lib
* Check if could remove flickering from changing draw order by making queue for order changing and only
change them after everything is drawn.
- * Platform desktop SDL.
+ * Platform desktop SDL
* Text input not working on gui. Could this be Raylib issue?
* Haptic functions.
* Text
@@ -16,12 +16,10 @@ Backlog {
* GenImageFontAtlas.
* Audio
* AudioStream.
- * Models
- * More Model management functions. Get mesh and material etc.
- * BoneInfo.
- * LoadMaterialsFromModel (Could then for example edit and set back to model).
* Core
* Automation events functionality.
+ * Models
+ * More Animation management functions.
* Examples
* Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads.
@@ -40,4 +38,5 @@ Needs Testing {
* rlUpdateTexture
* rlReadTexturePixels
* rlReadScreenPixels
+ * SetModelMesh Test unloading for double free or other errors.
}
diff --git a/docgen.lua b/docgen.lua
index 7f4f892..f152463 100644
--- a/docgen.lua
+++ b/docgen.lua
@@ -223,6 +223,10 @@ apiFile:write( "\n> BoundingBox = { { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } } or {
BoundingBox\n\n---\n" )
apiFile:write( "\n> GlyphInfo = { value = int, offsetX = int, offsetY = int, advanceX = int, image = Image }\n\
GlyphInfo, font characters glyphs info\n\n---\n" )
+apiFile:write( "\n> BoneInfo = { name = string[32], parent = int }\n\
+Bone, skeletal animation bone\n\n---\n" )
+apiFile:write( "\n> Transform = { translation = Vector3, rotation = Quaternion, scale = Vector3 }\n\
+Transform, vertex transformation data\n\n---\n" )
apiFile:write( "\n> Wave = Userdata\n\
Wave, audio wave data\n\n---\n" )
apiFile:write( "\n> Sound = Userdata\n\
diff --git a/include/lua_core.h b/include/lua_core.h
index b1bc016..df3f1d6 100644
--- a/include/lua_core.h
+++ b/include/lua_core.h
@@ -45,6 +45,9 @@ Matrix uluaGetMatrix( lua_State *L, int index );
BoundingBox uluaGetBoundingBox( lua_State *L, int index );
Ray uluaGetRay( lua_State *L, int index );
NPatchInfo uluaGetNPatchInfo( lua_State *L, int index );
+GlyphInfo uluaGetGlyphInfo( lua_State *L, int index );
+BoneInfo uluaGetBoneInfo( lua_State *L, int index );
+Transform uluaGetTransform( lua_State *L, int index );
Buffer* uluaGetBuffer( lua_State *L, int index );
Image* uluaGetImage( lua_State *L, int index );
Texture* uluaGetTexture( lua_State *L, int index );
@@ -73,6 +76,8 @@ void uluaPushRay( lua_State *L, Ray ray );
void uluaPushRayCollision( lua_State *L, RayCollision rayCol );
void uluaPushBoundingBox( lua_State *L, BoundingBox box );
void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyphInfo, Image *image );
+void uluaPushBoneInfo( lua_State *L, BoneInfo boneInfo );
+void uluaPushTransform( lua_State *L, Transform transform );
void uluaPushBuffer( lua_State *L, Buffer buffer );
void uluaPushImage( lua_State *L, Image image );
void uluaPushTexture( lua_State *L, Texture texture );
diff --git a/include/models.h b/include/models.h
index 39e1da7..33fb291 100644
--- a/include/models.h
+++ b/include/models.h
@@ -33,10 +33,20 @@ int lmodelsLoadModelFromMesh( lua_State *L );
int lmodelsIsModelReady( lua_State *L );
int lmodelsUnloadModel( lua_State *L );
int lmodelsGetModelBoundingBox( lua_State *L );
+int lmodelsSetModelTransform( lua_State *L );
+int lmodelsSetModelMesh( lua_State *L );
int lmodelsSetModelMaterial( lua_State *L );
int lmodelsSetModelMeshMaterial( lua_State *L );
-int lmodelsSetModelTransform( lua_State *L );
+int lmodelsSetModelBone( lua_State *L );
+int lmodelsSetModelBindPose( lua_State *L );
int lmodelsGetModelTransform( lua_State *L );
+int lmodelsGetModelMeshCount( lua_State *L );
+int lmodelsGetModelMaterialCount( lua_State *L );
+int lmodelsGetModelMesh( lua_State *L );
+int lmodelsGetModelMaterial( lua_State *L );
+int lmodelsGetModelBoneCount( lua_State *L );
+int lmodelsGetModelBone( lua_State *L );
+int lmodelsGetModelBindPose( lua_State *L );
/* Model drawing functions. */
int lmodelsDrawModel( lua_State *L );
int lmodelsDrawModelEx( lua_State *L );
diff --git a/src/lua_core.c b/src/lua_core.c
index acd4ac7..3bfce93 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -845,7 +845,7 @@ static void defineGlobals() {
assignGlobalInt( RL_FRAGMENT_SHADER, "RL_FRAGMENT_SHADER" ); // GL_FRAGMENT_SHADER
assignGlobalInt( RL_VERTEX_SHADER, "RL_VERTEX_SHADER" ); // GL_VERTEX_SHADER
assignGlobalInt( RL_COMPUTE_SHADER, "RL_COMPUTE_SHADER" ); // GL_COMPUTE_SHADER
- /* RLGL GlVersion */
+ /* RLGL GL blending factors */
assignGlobalInt( RL_ZERO, "RL_ZERO" ); // GL_ZERO
assignGlobalInt( RL_ONE, "RL_ONE" ); // GL_ONE
assignGlobalInt( RL_SRC_COLOR, "RL_SRC_COLOR" ); // GL_SRC_COLOR
@@ -1586,10 +1586,20 @@ void luaRegister() {
assingGlobalFunction( "IsModelReady", lmodelsIsModelReady );
assingGlobalFunction( "UnloadModel", lmodelsUnloadModel );
assingGlobalFunction( "GetModelBoundingBox", lmodelsGetModelBoundingBox );
+ assingGlobalFunction( "SetModelTransform", lmodelsSetModelTransform );
+ assingGlobalFunction( "SetModelMesh", lmodelsSetModelMesh );
assingGlobalFunction( "SetModelMaterial", lmodelsSetModelMaterial );
assingGlobalFunction( "SetModelMeshMaterial", lmodelsSetModelMeshMaterial );
- assingGlobalFunction( "SetModelTransform", lmodelsSetModelTransform );
+ assingGlobalFunction( "SetModelBone", lmodelsSetModelBone );
+ assingGlobalFunction( "SetModelBindPose", lmodelsSetModelBindPose );
assingGlobalFunction( "GetModelTransform", lmodelsGetModelTransform );
+ assingGlobalFunction( "GetModelMeshCount", lmodelsGetModelMeshCount );
+ assingGlobalFunction( "GetModelMaterialCount", lmodelsGetModelMaterialCount );
+ assingGlobalFunction( "GetModelMesh", lmodelsGetModelMesh );
+ assingGlobalFunction( "GetModelMaterial", lmodelsGetModelMaterial );
+ assingGlobalFunction( "GetModelBoneCount", lmodelsGetModelBoneCount );
+ assingGlobalFunction( "GetModelBone", lmodelsGetModelBone );
+ assingGlobalFunction( "GetModelBindPose", lmodelsGetModelBindPose );
/* Model drawing functions. */
assingGlobalFunction( "DrawModel", lmodelsDrawModel );
assingGlobalFunction( "DrawModelEx", lmodelsDrawModelEx );
@@ -2481,7 +2491,6 @@ BoundingBox uluaGetBoundingBox( lua_State *L, int index ) {
lua_pop( L, 1 );
}
}
-
return box;
}
@@ -2518,7 +2527,6 @@ Ray uluaGetRay( lua_State *L, int index ) {
lua_pop( L, 1 );
}
}
-
return ray;
}
@@ -2581,6 +2589,139 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L, int index ) {
return npatch;
}
+GlyphInfo uluaGetGlyphInfo( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
+ GlyphInfo glyph = { 0 };
+
+ int t = index, i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ /* Do not check type since there should be table and ints. */
+ if ( lua_isnumber( L, -2 ) ) {
+ switch ( i ) {
+ case 0:
+ glyph.value = lua_tointeger( L, -1 );
+ break;
+ case 1:
+ glyph.offsetX = lua_tointeger( L, -1 );
+ break;
+ case 2:
+ glyph.offsetY = lua_tointeger( L, -1 );
+ break;
+ case 3:
+ glyph.advanceX = lua_tointeger( L, -1 );
+ break;
+ case 4:
+ glyph.image = *uluaGetImage( L, lua_gettop( L ) );
+ break;
+ default:
+ break;
+ }
+ }
+ else if ( lua_isstring( L, -2 ) ) {
+ if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.value = lua_tointeger( L, -1 );
+ }
+ else if ( strcmp( "offsetX", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.offsetX = lua_tointeger( L, -1 );
+ }
+ else if ( strcmp( "offsetY", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.offsetY = lua_tointeger( L, -1 );
+ }
+ else if ( strcmp( "advanceX", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.advanceX = lua_tointeger( L, -1 );
+ }
+ else if ( strcmp( "image", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.image = *uluaGetImage( L, lua_gettop( L ) );
+ }
+ }
+ i++;
+ lua_pop( L, 1 );
+ }
+ return glyph;
+}
+
+BoneInfo uluaGetBoneInfo( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
+ BoneInfo bone = { 0 };
+
+ int t = index, i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ /* Do not check type since there should be table and ints. */
+ if ( lua_isnumber( L, -2 ) ) {
+ switch ( i ) {
+ case 0:
+ strncpy( bone.name, lua_tostring( L, lua_gettop( L ) ), 32 );
+ break;
+ case 1:
+ bone.parent = lua_tointeger( L, -1 );
+ break;
+ default:
+ break;
+ }
+ }
+ else if ( lua_istable( L, -1 ) ) {
+ if ( lua_isstring( L, -2 ) ) {
+ if ( strcmp( "name", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ strncpy( bone.name, lua_tostring( L, lua_gettop( L ) ), 32 );
+ }
+ else if ( strcmp( "parent", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ bone.parent = lua_tointeger( L, -1 );
+ }
+ }
+ i++;
+ lua_pop( L, 1 );
+ }
+ }
+ return bone;
+}
+
+Transform uluaGetTransform( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
+ Transform transform = { 0 };
+
+ int t = index, i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ /* Do not check type since there should be table and ints. */
+ if ( lua_isnumber( L, -2 ) ) {
+ switch ( i ) {
+ case 0:
+ transform.translation = uluaGetVector3( L, lua_gettop( L ) );
+ break;
+ case 1:
+ transform.rotation = uluaGetQuaternion( L, lua_gettop( L ) );
+ break;
+ case 2:
+ transform.scale = uluaGetVector3( L, lua_gettop( L ) );
+ break;
+ default:
+ break;
+ }
+ }
+ else if ( lua_istable( L, -1 ) ) {
+ if ( lua_isstring( L, -2 ) ) {
+ if ( strcmp( "translation", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ transform.translation = uluaGetVector3( L, lua_gettop( L ) );
+ }
+ else if ( strcmp( "rotation", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ transform.rotation = uluaGetQuaternion( L, lua_gettop( L ) );
+ }
+ else if ( strcmp( "scale", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ transform.scale = uluaGetVector3( L, lua_gettop( L ) );
+ }
+ }
+ i++;
+ lua_pop( L, 1 );
+ }
+ }
+ return transform;
+}
+
Buffer* uluaGetBuffer( lua_State *L, int index ) {
if ( lua_islightuserdata( L, index ) ) {
return (Buffer*)lua_touserdata( L, index );
@@ -2866,7 +3007,7 @@ void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
}
void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyphInfo, Image *image ) {
- lua_createtable( L, 4, 0 );
+ lua_createtable( L, 5, 0 );
lua_pushinteger( L, glyphInfo.value );
lua_setfield( L, -2, "value" );
lua_pushinteger( L, glyphInfo.offsetX );
@@ -2879,6 +3020,24 @@ void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyphInfo, Image *image ) {
lua_setfield( L, -2, "image" );
}
+void uluaPushBoneInfo( lua_State *L, BoneInfo boneInfo ) {
+ lua_createtable( L, 2, 0 );
+ lua_pushstring( L, boneInfo.name );
+ lua_setfield( L, -2, "name" );
+ lua_pushinteger( L, boneInfo.parent );
+ lua_setfield( L, -2, "parent" );
+}
+
+void uluaPushTransform( lua_State *L, Transform transform ) {
+ lua_createtable( L, 3, 0 );
+ uluaPushVector3( L, transform.translation );
+ lua_setfield( L, -2, "name" );
+ uluaPushQuaternion( L, transform.rotation );
+ lua_setfield( L, -2, "rotation" );
+ uluaPushVector3( L, transform.scale );
+ lua_setfield( L, -2, "scale" );
+}
+
void uluaPushBuffer( lua_State *L, Buffer buffer ) {
if ( buffer.size == 0 ) {
buffer.data = NULL;
diff --git a/src/models.c b/src/models.c
index eb4b978..7efee95 100644
--- a/src/models.c
+++ b/src/models.c
@@ -573,9 +573,48 @@ int lmodelsGetModelBoundingBox( lua_State *L ) {
}
/*
+> RL.SetModelTransform( Model model, Matrix transform )
+
+Set model transform matrix
+*/
+int lmodelsSetModelTransform( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+ Matrix transform = uluaGetMatrix( L, 2 );
+
+ model->transform = transform;
+
+ return 0;
+}
+
+/*
+> success = RL.SetModelMesh( Model model, int meshId, Mesh mesh )
+
+Get model mesh. Return as lightuserdata
+
+- Failure return false
+- Success return true
+*/
+int lmodelsSetModelMesh( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+ int meshId = luaL_checkinteger( L, 2 );
+ Mesh *mesh = uluaGetMesh( L, 3 );
+
+ if ( 0 <= meshId && meshId < model->meshCount ) {
+ // TODO Test if mesh should be copied instead. Is there issues with unloading.
+ model->meshes[ meshId ] = *mesh;
+ lua_pushboolean( L, true );
+ }
+ else {
+ TraceLog( LOG_WARNING, "MeshId %d out of bounds", meshId );
+ lua_pushboolean( L, false );
+ }
+ return 1;
+}
+
+/*
> success = RL.SetModelMaterial( Model model, int modelMaterialId, Material material )
-Copies material to model material. (Model material is the material id in models.)
+Copies material to model material
- Failure return false
- Success return true
@@ -585,8 +624,6 @@ int lmodelsSetModelMaterial( lua_State *L ) {
int modelMaterialId = luaL_checkinteger( L, 2 );
Material *material = uluaGetMaterial( L, 3 );
- //TODO Could maybe return old shader and textures for storage or get garbage collected?
-
if ( 0 <= modelMaterialId && modelMaterialId < model->materialCount ) {
/* Copy material data instead of using pointer. Pointer would result in double free error. */
model->materials[ modelMaterialId ].shader = material->shader;
@@ -630,17 +667,51 @@ int lmodelsSetModelMeshMaterial( lua_State *L ) {
}
/*
-> RL.SetModelTransform( Model model, Matrix transform )
+> success = RL.SetModelBone( Model model, int boneId, BoneInfo bone )
-Set model transform matrix
+Set model bone information (skeleton)
+
+- Failure return false
+- Success return true
*/
-int lmodelsSetModelTransform( lua_State *L ) {
+int lmodelsSetModelBone( lua_State *L ) {
Model *model = uluaGetModel( L, 1 );
- Matrix transform = uluaGetMatrix( L, 2 );
+ int boneId = luaL_checkinteger( L, 2 );
+ BoneInfo bone = uluaGetBoneInfo( L, 3 );
- model->transform = transform;
+ if ( 0 <= boneId && boneId < model->boneCount ) {
+ model->bones[ boneId ] = bone;
+ lua_pushboolean( L, true );
+ }
+ else {
+ TraceLog( LOG_WARNING, "boneId %d out of bounds", boneId );
+ lua_pushboolean( L, false );
+ }
+ return 1;
+}
- return 0;
+/*
+> success = RL.SetModelBindPose( Model model, int boneId, Transform pose )
+
+Set model bones base transformation (pose)
+
+- Failure return false
+- Success return true
+*/
+int lmodelsSetModelBindPose( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+ int boneId = luaL_checkinteger( L, 2 );
+ Transform pose = uluaGetTransform( L, 3 );
+
+ if ( 0 <= boneId && boneId < model->boneCount ) {
+ model->bindPose[ boneId ] = pose;
+ lua_pushboolean( L, true );
+ }
+ else {
+ TraceLog( LOG_WARNING, "boneId %d out of bounds", boneId );
+ lua_pushboolean( L, false );
+ }
+ return 1;
}
/*
@@ -659,6 +730,139 @@ int lmodelsGetModelTransform( lua_State *L ) {
}
/*
+> meshCount = RL.GetModelMeshCount( Model model )
+
+Get model number of meshes
+
+- Success return int
+*/
+int lmodelsGetModelMeshCount( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+
+ lua_pushinteger( L, model->meshCount );
+
+ return 1;
+}
+
+/*
+> meshCount = RL.GetModelMaterialCount( Model model )
+
+Get model number of materials
+
+- Success return int
+*/
+int lmodelsGetModelMaterialCount( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+
+ lua_pushinteger( L, model->materialCount );
+
+ return 1;
+}
+
+/*
+> mesh = RL.GetModelMesh( Model model, int meshId )
+
+Get model mesh. Return as lightuserdata
+
+- Failure return nil
+- Success return Mesh
+*/
+int lmodelsGetModelMesh( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+ int meshId = luaL_checkinteger( L, 2 );
+
+ if ( 0 <= meshId && meshId < model->meshCount ) {
+ lua_pushlightuserdata( L, &model->meshes[ meshId ] );
+ }
+ else {
+ TraceLog( LOG_WARNING, "MeshId %d out of bounds", meshId );
+ lua_pushnil( L );
+ }
+ return 1;
+}
+
+/*
+> material = RL.GetModelMaterial( Model model, int materialId )
+
+Get model material. Return as lightuserdata
+
+- Failure return nil
+- Success return Material
+*/
+int lmodelsGetModelMaterial( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+ int materialId = luaL_checkinteger( L, 2 );
+
+ if ( 0 <= materialId && materialId < model->materialCount ) {
+ lua_pushlightuserdata( L, &model->materials[ materialId ] );
+ }
+ else {
+ TraceLog( LOG_WARNING, "MaterialId %d out of bounds", materialId );
+ lua_pushnil( L );
+ }
+ return 1;
+}
+
+/*
+> boneCount = RL.GetModelBoneCount( Model model )
+
+Get model number of bones
+
+- Success return int
+*/
+int lmodelsGetModelBoneCount( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+
+ lua_pushinteger( L, model->boneCount );
+
+ return 1;
+}
+
+/*
+> bone = RL.GetModelBone( Model model, int boneId )
+
+Get model bones information (skeleton)
+
+- Failure return nil
+- Success return BoneInfo
+*/
+int lmodelsGetModelBone( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+ int boneId = luaL_checkinteger( L, 2 );
+
+ if ( 0 <= boneId && boneId < model->boneCount ) {
+ uluaPushBoneInfo( L, model->bones[ boneId ] );
+ }
+ else {
+ TraceLog( LOG_WARNING, "BoneId %d out of bounds", boneId );
+ lua_pushnil( L );
+ }
+ return 1;
+}
+
+/*
+> pose = RL.GetModelBindPose( Model model, int boneId )
+
+Get models bones base transformation (pose)
+
+- Failure return nil
+- Success return Transform
+*/
+int lmodelsGetModelBindPose( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+ int boneId = luaL_checkinteger( L, 2 );
+
+ if ( 0 <= boneId && boneId < model->boneCount ) {
+ uluaPushTransform( L, model->bindPose[ boneId ] );
+ }
+ else {
+ TraceLog( LOG_WARNING, "BoneId %d out of bounds", boneId );
+ lua_pushnil( L );
+ }
+ return 1;
+}
+
+/*
## Models - Model drawing functions
*/