diff options
Diffstat (limited to 'src/client/lua_api/scene/igeneric.cpp')
| -rw-r--r-- | src/client/lua_api/scene/igeneric.cpp | 72 |
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}, |
