aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/scene
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/lua_api/scene')
-rw-r--r--src/client/lua_api/scene/icamera.cpp76
-rw-r--r--src/client/lua_api/scene/icamera.hpp2
-rw-r--r--src/client/lua_api/scene/icube.cpp68
-rw-r--r--src/client/lua_api/scene/icube.hpp11
-rw-r--r--src/client/lua_api/scene/igeneric.cpp80
-rw-r--r--src/client/lua_api/scene/igeneric.hpp3
-rw-r--r--src/client/lua_api/scene/ilight.cpp96
-rw-r--r--src/client/lua_api/scene/ilight.hpp2
-rw-r--r--src/client/lua_api/scene/imesh.cpp162
-rw-r--r--src/client/lua_api/scene/imesh.hpp5
10 files changed, 281 insertions, 224 deletions
diff --git a/src/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp
index 14f9283..3c5e2b0 100644
--- a/src/client/lua_api/scene/icamera.cpp
+++ b/src/client/lua_api/scene/icamera.cpp
@@ -21,7 +21,6 @@ using namespace core;
extern IrrlichtDevice* device;
-
static LISceneNode* checkiscenecamera(lua_State* L, int index){
void* ud = luaL_checkudata(L,index,"scene.iscenecamera");
luaL_argcheck(L,ud != NULL, index, "'scene.iscenecamera' expected");
@@ -46,49 +45,51 @@ static LISceneNode* checkismayacamera(lua_State* L){
*/
static int newiscenemayacamera(lua_State* L){
- printf("createing maya camera!\n");
- ISceneManager* smgr = device->getSceneManager();
- ICameraSceneNode* cam = smgr->addCameraSceneNodeMaya();
- printf("cam is %p",cam);
- LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
-
- //Set it's metatable
- luaL_getmetatable(L, "scene.iscenemayacamera");
- lua_setmetatable(L, -2);
-
- //Create the struct
- lcam->n = cam;
- lcam->funcmap = hashmap_new();
- lcam->type = "iscenemayacamera";
-
- //Free up anything made in this function
- //free(label);
-
- //Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
- return 1;
+ printf("createing maya camera!\n");
+ ISceneManager* smgr = device->getSceneManager();
+ ICameraSceneNode* cam = smgr->addCameraSceneNodeMaya();
+ printf("cam is %p",cam);
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,cam);
+ lua_setfield(L,-2,"node");
+ //LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
+ //int tref = luaL_ref(L,LUA_REGISTRYINDEX);
+
+ //Set it's metatable
+ luaL_getmetatable(L, "scene.iscenemayacamera");
+ lua_setmetatable(L, -2);
+
+ //Create the struct
+ //lcam->n = cam;
+ //lcam->funcmap = hashmap_new();
+ //lcam->type = "iscenemayacamera";
+
+ //Free up anything made in this function
+ //free(label);
+
+ //Put it on top and return it
+ //lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
+ return 1;
}
// ifpscamera.new()
static int newiscenefpscamera(lua_State* L){//
ISceneManager* smgr = device->getSceneManager();
ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
- LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));//userdata_scenenode
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);//
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//userdata_scenenode
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,cam);//{},ud_cam
+ lua_setfield(L,-2,"node");
+ //LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));//userdata_scenenode
//Set it's metatable
luaL_getmetatable(L, "scene.ifpscamera");//userdata_scenenode,scene.ifpscamera
lua_setmetatable(L, -2);//userdata_scenenode
//Create the struct
- lcam->n = cam;
- lcam->funcmap = hashmap_new();
- lcam->type = "iscenefpscamera";
+ //lcam->n = cam;
+ //lcam->funcmap = hashmap_new();
+ //lcam->type = "iscenefpscamera";
- //Put it on top and return it
- //lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
return 1;
}
@@ -154,9 +155,10 @@ static int newiscenecamera(lua_State* L){
}
static const luaL_reg icamera_m[] = {
- {"getpos", iscenegetpos},
- {"setpos", iscenesetpos},
-// {"remove", removeiguielement},
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+ {"getangle", iscenegetangle},
+ {"setangle", iscenesetangle},
{0, 0},
};
@@ -168,8 +170,7 @@ static const luaL_reg ifpscamera_m[] = {
{0,0},
};
-void icamera_register(lua_State* L, IrrlichtDevice* d){
- device = d;
+void icamera_register(lua_State* L){
luaL_newmetatable(L, "scene.icamera");//scene.icamera
lua_newtable(L);//scene.icamera, {}
@@ -180,6 +181,7 @@ void icamera_register(lua_State* L, IrrlichtDevice* d){
luaL_newmetatable(L, "scene.imayacamera");//scene.imayacamera
lua_newtable(L);//scene.imayascamera,{}
luaL_register(L,NULL,imayacamera_m);//scene.imayascamera,{}
+ luaL_register(L,NULL,icamera_m);//scene.imayascamera,{}
lua_setfield(L,-2,"__index");//scene.imayascamera
lua_pop(L,1);//
@@ -198,5 +200,5 @@ void icamera_register(lua_State* L, IrrlichtDevice* d){
lua_pushcfunction(L,newiscenemayacamera);//{},newiscenemayacamera()
lua_setfield(L,-2,"newmayacamera");//{}
printf("\"scene\" was set!\n");
- //lua_pop(L,1);
+ lua_pop(L,1);//
}
diff --git a/src/client/lua_api/scene/icamera.hpp b/src/client/lua_api/scene/icamera.hpp
index 38874e3..ada1e98 100644
--- a/src/client/lua_api/scene/icamera.hpp
+++ b/src/client/lua_api/scene/icamera.hpp
@@ -8,4 +8,4 @@ extern "C" {
}
#include <irrlicht.h>
-void icamera_register(lua_State* L, irr::IrrlichtDevice* d);
+void icamera_register(lua_State* L);
diff --git a/src/client/lua_api/scene/icube.cpp b/src/client/lua_api/scene/icube.cpp
new file mode 100644
index 0000000..d18db2a
--- /dev/null
+++ b/src/client/lua_api/scene/icube.cpp
@@ -0,0 +1,68 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+extern IrrlichtDevice* device;
+
+using namespace irr;
+
+// {} :: scene.newcube(num_size, {v3 pos})
+int newiscenecube(lua_StatE* L){//num_size, {v3 pos}
+ double x,y,z;
+ popvector3d(L,&x, &y, &z);//num_size
+ double size = lua_tonumber(L,-1);//num_size
+ lua_pop(L,1);//
+ IMeshSceneNode* n = device->getSceneManager()->addCubeSceneNode(size,0,-1,core::vector3df(x,y,z));
+
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,n);//{},ud_node
+ lua_setfield(L,-2,"node");//{}
+
+ luaL_getmetatable(L,"scene.inode");//{},sene.inode
+ lua_setmetatable(L,-2);
+
+ return 1;
+}
+
+static const luaL_reg iscenenode_m[] = {
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+// {"remove", removeiguielement},
+ {0, 0},
+};
+
+void icube_register(lua_State* L){
+
+ luaL_newmetatable(L, "scene.icamera");//scene.icamera
+ lua_newtable(L);//scene.icamera, {}
+ luaL_register(L,NULL,icamera_m);//scene.icamera, {}
+ lua_setfield(L,-2,"__index");//scene.icamera
+ lua_pop(L,1);//
+
+ luaL_newmetatable(L, "scene.imayacamera");//scene.imayacamera
+ lua_newtable(L);//scene.imayascamera,{}
+ luaL_register(L,NULL,imayacamera_m);//scene.imayascamera,{}
+ lua_setfield(L,-2,"__index");//scene.imayascamera
+ lua_pop(L,1);//
+
+ luaL_newmetatable(L,"scene.ifpscamera");//scene.ifpscamera
+ lua_newtable(L);//scene.ifpscamera, {}
+ luaL_register(L,NULL,ifpscamera_m);//scene.ifpscamera,{}
+ luaL_register(L,NULL,icamera_m);//scene.ifpscamera,{}
+ lua_setfield(L,-2,"__index");//scene.ifpscamera
+ lua_pop(L,1);//
+
+ lua_getglobal(L,"scene");//{}
+ lua_pushcfunction(L,newiscenecamera);//{},newiscenecamera()
+ lua_setfield(L,-2,"newcamera");//{}
+ lua_pushcfunction(L,newiscenefpscamera);//{},newiscenefpscamera()
+ lua_setfield(L,-2,"newfpscamera");//{}
+ lua_pushcfunction(L,newiscenemayacamera);//{},newiscenemayacamera()
+ lua_setfield(L,-2,"newmayacamera");//{}
+ printf("\"scene\" was set!\n");
+ //lua_pop(L,1);
+}
diff --git a/src/client/lua_api/scene/icube.hpp b/src/client/lua_api/scene/icube.hpp
new file mode 100644
index 0000000..ffb4d3b
--- /dev/null
+++ b/src/client/lua_api/scene/icube.hpp
@@ -0,0 +1,11 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+void icube_register(lua_State* L);
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
index fc32e83..0d061d2 100644
--- a/src/client/lua_api/scene/igeneric.cpp
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -7,6 +7,7 @@ extern "C" {
#include <irrlicht.h>
#include "igeneric.hpp"
#include "../gameparts.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace core;
@@ -15,63 +16,57 @@ using namespace video;
extern IrrlichtDevice* device;
+/*
static LISceneNode* toiscenenode(lua_State* L, int index){
LISceneNode* ret = (LISceneNode*)lua_touserdata(L,index);
if(ret == NULL)
luaL_typerror(L,index,"LISceneNode");
return ret;
}
+*/
-int iscenegetpos(lua_State* L){
- ISceneNode* i = toiscenenode(L,1)->n;
+int iscenegetpos(lua_State* L){//{node=ud_IMeshSceneNode}
+ lua_getfield(L,-1,"node");//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
vector3df pos = i->getAbsolutePosition();
+ lua_pop(L,2);
+ pushvector3d(L,pos.X,pos.Y,pos.Z);
- lua_createtable(L,3,0);
-
- lua_pushnumber(L,1);
- lua_pushnumber(L,pos.X);
- lua_settable(L,-3);
-
- lua_pushnumber(L,2);
- lua_pushnumber(L,pos.Y);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushnumber(L,3);
- lua_pushnumber(L,pos.Z);
- lua_settable(L,-3);
-
+int iscenesetpos(lua_State* L){//{node=ud_IMeshSceneNode},{x,y,z}
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);//{node=ud_IMeshSceneNode}
+ lua_getfield(L,-1,"node");//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
+ i->setPosition(vector3df(x,y,z));
+ i->updateAbsolutePosition();
+ vector3df pos = i->getAbsolutePosition();
+ printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z);
+ lua_pop(L,2);//
+ return 0;
+}
+
+int iscenegetangle(lua_State* L){//{node=ud-IMeshSceneNode}
+ lua_getfield(L,-1,"node");
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);
+ irr::core::vector3df ang = i->getRotation();
+ pushvector3d(L,ang.X, ang.Y, ang.Z);
return 1;
}
-int iscenesetpos(lua_State* L){
-
- ISceneNode* i = toiscenenode(L,1)->n;
-
- lua_pushnumber(L,1);
- lua_gettable(L,-2);
- f32 x = (f32)lua_tonumber(L,-1);
- lua_pop(L,1);
-
- lua_pushnumber(L,2);
- lua_gettable(L,-2);
- f32 y = (f32)lua_tonumber(L,-1);
- lua_pop(L,1);
-
- lua_pushnumber(L,3);
- lua_gettable(L,-2);
- f32 z = (f32)lua_tonumber(L,-1);
- lua_pop(L,1);
-
- printf("Trying to set pos of %p to %f %f %f",i,x,y,z);
-
- i->setPosition(vector3df(x,y,z));
- i->updateAbsolutePosition();
- vector3df pos = i->getAbsolutePosition();
- printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z);
-
- return 0;
+int iscenesetangle(lua_State* L){//{node=ud_ISceneNode},{x,y,z}
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);
+ lua_getfield(L,-1,"node");
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);
+ irr::core::vector3df ang = irr::core::vector3df(x,y,z);
+ i->setRotation(ang);
+ return 0;
}
+/*
int iscenesetmaterial(lua_State* L){
ISceneNode* i = toiscenenode(L,1)->n;
const char* s = luaL_optstring(L,2,"error.png");
@@ -81,3 +76,4 @@ int iscenesetmaterial(lua_State* L){
return 0;
}
+*/
diff --git a/src/client/lua_api/scene/igeneric.hpp b/src/client/lua_api/scene/igeneric.hpp
index 85a9d3e..c60b169 100644
--- a/src/client/lua_api/scene/igeneric.hpp
+++ b/src/client/lua_api/scene/igeneric.hpp
@@ -11,6 +11,9 @@ extern "C" {
int iscenegetpos(lua_State* L);
int iscenesetpos(lua_State* L);
+int iscenegetangle(lua_State* L);
+int iscenesetangle(lua_State* L);
+
int iscenesetmaterial(lua_State* L);
diff --git a/src/client/lua_api/scene/ilight.cpp b/src/client/lua_api/scene/ilight.cpp
index 2511999..451280a 100644
--- a/src/client/lua_api/scene/ilight.cpp
+++ b/src/client/lua_api/scene/ilight.cpp
@@ -14,6 +14,7 @@ extern "C" {
#include "../gameparts.hpp"
#include "ilight.hpp"
#include "igeneric.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace scene;
@@ -31,100 +32,49 @@ static LISceneNode* checkilight(lua_State* L){
return checkiscenelight(L,1);
}
-//iscenelight.new(Vector position, parrent = nil)
+//{} :: scene.newlight(radius, {v3 position})
static int newiscenelight(lua_State* L){
printf("Createing light!\n");
- int nargs = lua_gettop(L);
- //lua_pop(L,1);
- // float radius = 100;
- // if(nargs == 2){
- // radius = luaL_optnumber(L,2,100);
- // }
- float radius = lua_tonumber(L,-1);
- printf("radius was %f\n" ,radius);
- lua_pop(L,1);
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);//radius
+ double radius = lua_tonumber(L,-1);
+ lua_pop(L,1);//
- //The position of the light
- lua_pushnumber(L,1);
- lua_gettable(L,-2);
- float x = lua_tonumber(L,-1);
- printf("got x: %f\n",x);
- lua_pop(L,1);
- lua_pushnumber(L,2);
- lua_gettable(L,-2);
- float y = lua_tonumber(L,-1);
- lua_pop(L,1);
- lua_pushnumber(L,3);
- lua_gettable(L,-2);
- float z = lua_tonumber(L,-1);
- lua_pop(L,1);
- printf("Found position for light: %f %f %f\n",x,y,z);
-
//Create the mesh
ISceneManager* smgr = device->getSceneManager();
ILightSceneNode* light = smgr->addLightSceneNode(0,vector3df(x,y,z),video::SColor(1.0f,1.0f,1.0f,1.0f),(f32)radius,(s32)-1);
- printf("Registered the light!\n");
-
- //Register it's callback
- //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent);
//Create it's lua representation
- LISceneNode* lnode = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
- //iguielements[lcam] = tref;
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object.
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,light);
+ lua_setfield(L,-2,"node");
//Set it's metatable
luaL_getmetatable(L, "scene.imesh");
lua_setmetatable(L, -2);
- lnode->n = light;
- lnode->funcmap = hashmap_new();
- lnode->type = "ilight";
-
- //Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
return 1;
}
-static const luaL_reg icamera_f[] = {
- {"new", newiscenelight},
-// {"gethandeler", guigethandeler},
-// {"sethandeler", guisethandeler},
- {0,0},
-};
-
-static const luaL_reg icamera_m[] = {
- {"getpos", iscenegetpos},
- {"setpos", iscenesetpos},
-// {"move", moveiguielement},
-// {"settext", setiguitext},
-// {"remove", removeiguielement},
- {0, 0},
+static const luaL_reg ilight_m[] = {
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+ {0, 0},
};
-int ilight_register(lua_State* L, IrrlichtDevice* d){
-
- device = d;
-
- printf("ilight registered\n");
+void ilight_register(lua_State* L){
- luaL_newmetatable(L, "scene.ilight");
+ lua_getglobal(L,"scene");//{scene}
+ lua_pushcfunction(L,newiscenelight);//{scene},newiscenelight()
+ lua_setfield(L,-2,"newlight");//{scene}
- luaL_register(L,"ilight",icamera_f);
+ lua_pop(L,1);//
- lua_pushstring(L,"__index");
- lua_pushstring(L,"gethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ luaL_newmetatable(L,"scene.ilight");//scene.ilight
+ lua_newtable(L);//scene.ilight,{}
+ luaL_register(L, NULL, ilight_m);//scene.ilight,{}
+ lua_setfield(L,-2,"__index");//scene.ilight
- lua_pushstring(L,"__newindex");
- lua_pushstring(L,"sethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
-
- luaL_register(L, NULL, icamera_m);
-
- return 1;
+ lua_pop(L,1);
}
diff --git a/src/client/lua_api/scene/ilight.hpp b/src/client/lua_api/scene/ilight.hpp
index 87d2841..af9c084 100644
--- a/src/client/lua_api/scene/ilight.hpp
+++ b/src/client/lua_api/scene/ilight.hpp
@@ -8,4 +8,4 @@ extern "C" {
}
#include <irrlicht.h>
-int ilight_register(lua_State* L, irr::IrrlichtDevice* d);
+void ilight_register(lua_State* L);
diff --git a/src/client/lua_api/scene/imesh.cpp b/src/client/lua_api/scene/imesh.cpp
index 1a1c28b..3f3ae24 100644
--- a/src/client/lua_api/scene/imesh.cpp
+++ b/src/client/lua_api/scene/imesh.cpp
@@ -14,6 +14,7 @@ extern "C" {
#include "../gameparts.hpp"
#include "imesh.hpp"
#include "igeneric.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace scene;
@@ -22,7 +23,6 @@ using namespace video;
extern IrrlichtDevice* device;
-
static LISceneNode* checkismesh(lua_State* L, int index){
void* ud = luaL_checkudata(L,index,"scene.imesh");
luaL_argcheck(L,ud != NULL, index, "'scene.imesh' expected");
@@ -35,83 +35,107 @@ static LISceneNode* checkismesh(lua_State* L){
}
*/
-static int newiscenemesh(lua_State* L){
- printf("Createing mesh!\n");
- int nargs = lua_gettop(L);
- if(nargs != 1){
- printf("Incorrect # of args to create a mesh!");
- }
- //The model for the mesh
- const char* modelpath = luaL_optstring(L,1,"error");
-
- //Create the mesh
- ISceneManager* smgr = device->getSceneManager();
- IAnimatedMesh* amesh = smgr->getMesh(modelpath);
- IAnimatedMeshSceneNode* mesh = smgr->addAnimatedMeshSceneNode( amesh );
- mesh->setMaterialFlag(EMF_GOURAUD_SHADING,true);
- printf("Registered the mesh!\n");
-
- //Register it's callback
- //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent);
-
- //Create it's lua representation
- LISceneNode* lmesh = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
- //iguielements[lcam] = tref;
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object.
-
- //Set it's metatable
- luaL_getmetatable(L, "scene.imesh");
- lua_setmetatable(L, -2);
-
- //Create the struct
- lmesh->n = mesh;
- lmesh->funcmap = hashmap_new();
- lmesh->type = "imesh";
-
- //Free up anything made in this function
- //free(label);
-
- //Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
- return 1;
+//{} :: scene.newmesh("/path/to/model")
+static int newiscenemesh(lua_State* L){//"path/to"
+
+ printf("Createing mesh!\n");
+ int nargs = lua_gettop(L);
+ if(nargs != 1){
+ lua_pushfstring(L,"scene.newmesh got %d arguments, expecting 1",nargs);
+ lua_error(L);
+ }
+ //The model for the mesh
+ const char* modelpath = luaL_optstring(L,1,"error");//"path/to"
+ lua_pop(L,1);//
+
+ //Create the mesh
+ ISceneManager* smgr = device->getSceneManager();
+ IAnimatedMesh* amesh = smgr->getMesh(modelpath);
+ IAnimatedMeshSceneNode* mesh = smgr->addAnimatedMeshSceneNode( amesh );
+ mesh->setMaterialFlag(EMF_GOURAUD_SHADING,true);
+ printf("Registered the mesh!\n");
+
+ lua_newtable(L);//{}
+ luaL_getmetatable(L,"scene.imesh");//{},scene.imesh
+ lua_setmetatable(L,-2);//{}
+
+ lua_pushlightuserdata(L,mesh);//{},ud_mesh
+ lua_setfield(L,-2,"node");//{}
+
+ return 1;
}
-static const luaL_reg imesh_f[] = {
- {"new", newiscenemesh},
-// {"gethandeler", guigethandeler},
-// {"sethandeler", guisethandeler},
- {0,0},
-};
+// ud_node :: ({v3 size}, {v3 origin})
+void makenewiscenecube(lua_State* L){
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);//{v3 size}
+ double sx,sy,sz;
+ popvector3d(L,&sx,&sy,&sz);//{}
+ IMeshSceneNode* n = device->getSceneManager()->addCubeSceneNode(10,0,-1,core::vector3df(x,y,z),core::vector3df(0,0,0),core::vector3df(sx,sy,sz));
+ lua_pushlightuserdata(L,n);
+}
-static const luaL_reg imesh_m[] = {
- {"setMaterial", iscenesetmaterial},
- {"getpos", iscenegetpos},
- {"setpos", iscenesetpos},
-// {"settext", setiguitext},
-// {"remove", removeiguielement},
- {0, 0},
-};
+// {} :: scene.newcube({v3 size}, {v3 origin})
+int newiscenecube(lua_State* L){//{v3 size}, {v3 origin}
+ makenewiscenecube(L);//ud_node
+ ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_node
+ lua_pop(L,1);//
+ lua_newtable(L);//{}
+ luaL_getmetatable(L,"scene.icube");//{},scene.icube
+ lua_setmetatable(L,-2);//{}
-int imesh_register(lua_State* L, IrrlichtDevice* d){
+ lua_pushlightuserdata(L,n);//{},ud_mesh
+ lua_setfield(L,-2,"node");//{}
- device = d;
+ return 1;
+}
- luaL_newmetatable(L, "scene.imesh");
+// self:setMaterial("path/to/material")
+int iscenesetmaterial(lua_State* L){//self,"path/to"
+ ISceneNode* node = (IMeshSceneNode*)lua_touserdata(L,-2);
+ const char* s = lua_tostring(L,-1);
+ //ISceneNode* i = toiscenenode(L,1)->n;
+ //const char* s = luaL_optstring(L,2,"error.png");
+ //printf("Setting material to %s",s);
- luaL_register(L,"imesh",imesh_f);
+ IVideoDriver* driver = device->getVideoDriver();
+ node->setMaterialTexture(0, driver->getTexture(s));
- lua_pushstring(L,"__index");
- lua_pushstring(L,"gethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ lua_pop(L,2);
+ return 0;
+}
- lua_pushstring(L,"__newindex");
- lua_pushstring(L,"sethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+static const luaL_reg imesh_m[] = {
+ {"setMaterial", iscenesetmaterial},
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+ // {"remove", removeiguielement},
+ {0, 0},
+};
+
+static const luaL_reg icube_m[] = {
+ {0,0},
+};
- luaL_register(L, NULL, imesh_m);
+void imesh_register(lua_State* L){
+
+ luaL_newmetatable(L, "scene.imesh");//scene.icamera
+ lua_newtable(L);//scene.icamera,{}
+ luaL_register(L,NULL,imesh_m);//scene.icamera,{}
+ lua_setfield(L,-2,"__index");//scene.icamera
+ lua_pop(L,1);//
+
+ luaL_newmetatable(L,"scene.icube");//scene.icube
+ lua_newtable(L);//scene.icube, {}
+ luaL_register(L,NULL,imesh_m);//scene.icube,{}
+ luaL_register(L,NULL,icube_m);//scene.icube,{}
+ lua_setfield(L,-2,"__index");//scene.icube
+ lua_pop(L,1);//
+
+ lua_getglobal(L,"scene");
+ lua_pushcfunction(L,newiscenemesh);
+ lua_setfield(L,-2,"newmesh");
+ lua_pushcfunction(L,newiscenecube);
+ lua_setfield(L,-2,"newcube");
- return 1;
}
diff --git a/src/client/lua_api/scene/imesh.hpp b/src/client/lua_api/scene/imesh.hpp
index bd33c07..925f12e 100644
--- a/src/client/lua_api/scene/imesh.hpp
+++ b/src/client/lua_api/scene/imesh.hpp
@@ -8,4 +8,7 @@ extern "C" {
}
#include <irrlicht.h>
-int imesh_register(lua_State* L, irr::IrrlichtDevice* d);
+
+void makenewiscenecube(lua_State* L);
+int newiscenecube(lua_State* L);//{v3 size}, {v3 origin}, mass
+void imesh_register(lua_State* L);