aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/scene/igeneric.cpp
diff options
context:
space:
mode:
authorAlexander <alex@cogarr.net>2020-06-29 15:29:03 -0400
committerAlexander <alex@cogarr.net>2020-06-29 15:29:03 -0400
commit80789508b9655d25629223b9dcc84b4cfb77ce45 (patch)
tree37e140e532af61c1ca4699c8b6254cf2cb07ed02 /src/client/lua_api/scene/igeneric.cpp
parent44a1421c393632978d59c0698a93ae22243b97e9 (diff)
downloadbrokengine-80789508b9655d25629223b9dcc84b4cfb77ce45.tar.gz
brokengine-80789508b9655d25629223b9dcc84b4cfb77ce45.tar.bz2
brokengine-80789508b9655d25629223b9dcc84b4cfb77ce45.zip
Updates for mdoc
Also more tests
Diffstat (limited to 'src/client/lua_api/scene/igeneric.cpp')
-rw-r--r--src/client/lua_api/scene/igeneric.cpp72
1 files changed, 65 insertions, 7 deletions
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
index dcac022..a0c33b3 100644
--- a/src/client/lua_api/scene/igeneric.cpp
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -14,14 +14,8 @@ using namespace core;
using namespace scene;
using namespace video;
-/***
-@classmod iscenenode
-*/
-
extern IrrlichtDevice* device;
-
-
/***
Get the position of a scene element.
@function iscenenode:getpos()
@@ -82,13 +76,74 @@ int iscenesetangle(lua_State* L){//{node=ud_ISceneNode},{x,y,z}
}
/***
+Gets the material of a scene element.
+To check if to materials are equal, compare their .texture fields, these hold
+a light userdata.
+@function iscenenode:getmaterial()
+@treturn smaterial The material that was applied to this node
+*/
+//iscenenode:getmaterial({node=ud_ISceneNode},texture_number=0) :: {texture=ud_itexture}
+int iscenegetmaterial(lua_State *L){
+ int args = lua_gettop(L);
+ u32 layer = 0;
+ if(args == 2){
+ layer = lua_tonumber(L,-1);
+ lua_pop(L,1);
+ }
+ lua_getfield(L,-1,"node");
+ ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);
+ lua_pop(L,2);//
+ SMaterial mat = i->getMaterial(layer);
+ ITexture *tex = mat.getTexture(0);
+ printf("got texutre:%p\n",(void*)tex);
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,tex);//{},ud_texture
+ lua_setfield(L,-2,"texture");//{material}
+ luaL_getmetatable(L,"video.smaterial");//{material},{material_m}
+ lua_setmetatable(L,-2);//{material}
+ return 1;
+}
+
+/***
+Gets the number of materials on a scene node.
+@function iscenenode:getmaterialcount()
+@treturn number The number of materials on this node
+*/
+//iscenenode:getmaterialcount()
+int iscenegetmaterialcount(lua_State *L){
+ lua_getfield(L,-1,"node");
+ ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);
+ lua_pop(L,2);//
+ u32 count = i->getMaterialCount();
+ lua_pushnumber(L,count);
+ return 1;
+}
+
+/***
+Sets a flag on the material
+@function iscenenode:setmaterialflag(flag,on)
+@tparam number flag The flag to modify
+@tparam boolean on Should the flag be set
+*/
+//iscenenode:setmaterialflag(flag,on)
+int iscenesetmaterialflag(lua_State *L){
+ int on = lua_toboolean(L,-1);
+ E_MATERIAL_FLAG flag = (E_MATERIAL_FLAG)lua_tonumber(L,-2);
+ lua_pop(L,2);
+ lua_getfield(L,-1,"node");
+ ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);
+ lua_pop(L,2);//
+ i->setMaterialFlag(flag,on == 1);
+ return 0;
+}
+
+/***
Set the mateiral of a scene element.
@function iscenenode:setmaterial()
@tparam texture texture The texture to apply to this material
*/
//iscenesetmaterialtexture({node=ud_ISceneNode},{texture=ud_itexture},texture_number=0)
int iscenesetmaterial(lua_State *L){
- printf("Calling generic iscenesetmaterial function\n");
int args = lua_gettop(L);
u32 layer = 0;
if(args == 3){
@@ -220,6 +275,9 @@ extern const luaL_reg igeneric_m[] = {
{"getang", iscenegetangle},
{"setang", iscenesetangle},
{"setmaterialtexture", iscenesetmaterial},
+ {"getmaterial", iscenegetmaterial},
+ {"getmaterialcount", iscenegetmaterialcount},
+ {"setmaterialflag", iscenesetmaterialflag},
{"getname", iscenegetname},
{"setname", iscenesetname},
{"setscale", iscenesetscale},