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.cpp55
-rw-r--r--src/client/lua_api/scene/igeneric.cpp17
-rw-r--r--src/client/lua_api/scene/igeneric.hpp2
-rw-r--r--src/client/lua_api/scene/ilight.cpp130
-rw-r--r--src/client/lua_api/scene/ilight.hpp11
-rw-r--r--src/client/lua_api/scene/imesh.cpp90
6 files changed, 249 insertions, 56 deletions
diff --git a/src/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp
index ce54ef2..5a4e3a2 100644
--- a/src/client/lua_api/scene/icamera.cpp
+++ b/src/client/lua_api/scene/icamera.cpp
@@ -22,8 +22,8 @@ using namespace core;
extern IrrlichtDevice* device;
static LISceneNode* checkiscenecamera(lua_State* L, int index){
- void* ud = luaL_checkudata(L,index,"scene.icamera");
- luaL_argcheck(L,ud != NULL, index, "'scene.icamera' expected");
+ void* ud = luaL_checkudata(L,index,"scene.iscenecamera");
+ luaL_argcheck(L,ud != NULL, index, "'scene.iscenecamera' expected");
return (LISceneNode*) ud;
}
@@ -31,6 +31,42 @@ static LISceneNode* checkiscenecamera(lua_State* L){
return checkiscenecamera(L,1);
}
+static LISceneNode* checkismayacamera(lua_State* L, int index){
+ void* ud = luaL_checkudata(L,index,"scene.iscenemayacamera");
+ luaL_argcheck(L,ud != NULL, index, "'scene.iscenemayacamera' expected");
+ return (LISceneNode*) ud;
+}
+
+static LISceneNode* checkismayacamera(lua_State* L){
+ return checkismayacamera(L,1);
+}
+
+static int newiscenemayacamera(lua_State* L){
+ printf("createing maya camera!\n");
+ int nargs = lua_gettop(L);
+ 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;
+}
+
//iscenecamera.new(Vector position, Vector lookat, parrent)
static int newiscenecamera(lua_State* L){
printf("Createing camera!\n");
@@ -110,6 +146,15 @@ static const luaL_reg icamera_m[] = {
{0, 0},
};
+static const luaL_reg imayacamera_f[] = {
+ {"new", newiscenemayacamera},
+ {0,0},
+};
+
+static const luaL_reg imayacamera_m[] = {
+ {0,0},
+};
+
int icamera_register(lua_State* L, IrrlichtDevice* d){
device = d;
@@ -117,7 +162,6 @@ int icamera_register(lua_State* L, IrrlichtDevice* d){
printf("icamera registered\n");
luaL_newmetatable(L, "scene.icamera");
-
luaL_register(L,"icamera",icamera_f);
lua_pushstring(L,"__index");
@@ -131,6 +175,11 @@ int icamera_register(lua_State* L, IrrlichtDevice* d){
lua_settable(L,-4);
luaL_register(L, NULL, icamera_m);
+ //End of camera
+
+ //Start of maya camera
+ luaL_newmetatable(L,"scene.imayacamera");
+ luaL_register(L,"imayacamera",imayacamera_f);
return 1;
}
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
index 51aaf66..fc32e83 100644
--- a/src/client/lua_api/scene/igeneric.cpp
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -11,6 +11,9 @@ extern "C" {
using namespace irr;
using namespace core;
using namespace scene;
+using namespace video;
+
+extern IrrlichtDevice* device;
static LISceneNode* toiscenenode(lua_State* L, int index){
LISceneNode* ret = (LISceneNode*)lua_touserdata(L,index);
@@ -39,6 +42,7 @@ int iscenegetpos(lua_State* L){
return 1;
}
+
int iscenesetpos(lua_State* L){
ISceneNode* i = toiscenenode(L,1)->n;
@@ -65,6 +69,15 @@ int iscenesetpos(lua_State* L){
vector3df pos = i->getAbsolutePosition();
printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z);
-
- return 0;
+ return 0;
+}
+
+int iscenesetmaterial(lua_State* L){
+ ISceneNode* i = toiscenenode(L,1)->n;
+ const char* s = luaL_optstring(L,2,"error.png");
+ printf("Setting material to %s",s);
+ IVideoDriver* driver = device->getVideoDriver();
+ i->setMaterialTexture(0, driver->getTexture(s));
+
+ return 0;
}
diff --git a/src/client/lua_api/scene/igeneric.hpp b/src/client/lua_api/scene/igeneric.hpp
index 848709b..85a9d3e 100644
--- a/src/client/lua_api/scene/igeneric.hpp
+++ b/src/client/lua_api/scene/igeneric.hpp
@@ -12,4 +12,6 @@ extern "C" {
int iscenegetpos(lua_State* L);
int iscenesetpos(lua_State* L);
+int iscenesetmaterial(lua_State* L);
+
#endif
diff --git a/src/client/lua_api/scene/ilight.cpp b/src/client/lua_api/scene/ilight.cpp
new file mode 100644
index 0000000..df01dd3
--- /dev/null
+++ b/src/client/lua_api/scene/ilight.cpp
@@ -0,0 +1,130 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <vector>
+#include <memory>
+#include <map>
+#include <functional>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "../gameparts.hpp"
+#include "ilight.hpp"
+#include "igeneric.hpp"
+
+using namespace irr;
+using namespace scene;
+using namespace core;
+
+extern IrrlichtDevice* device;
+
+static LISceneNode* checkiscenelight(lua_State* L, int index){
+ void* ud = luaL_checkudata(L,index,"scene.ilight");
+ luaL_argcheck(L,ud != NULL, index, "'scene.ilight' expected");
+ return (LISceneNode*) ud;
+}
+
+static LISceneNode* checkilight(lua_State* L){
+ return checkiscenelight(L,1);
+}
+
+//iscenelight.new(Vector position, parrent = nil)
+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);
+
+ //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.
+
+ //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},
+};
+
+int ilight_register(lua_State* L, IrrlichtDevice* d){
+
+ device = d;
+
+ printf("icamera registered\n");
+
+ luaL_newmetatable(L, "scene.ilight");
+
+ luaL_register(L,"ilight",icamera_f);
+
+ lua_pushstring(L,"__index");
+ lua_pushstring(L,"gethandeler");
+ lua_gettable(L,-3);
+ lua_settable(L,-4);
+
+ lua_pushstring(L,"__newindex");
+ lua_pushstring(L,"sethandeler");
+ lua_gettable(L,-3);
+ lua_settable(L,-4);
+
+ luaL_register(L, NULL, icamera_m);
+
+ return 1;
+}
diff --git a/src/client/lua_api/scene/ilight.hpp b/src/client/lua_api/scene/ilight.hpp
new file mode 100644
index 0000000..87d2841
--- /dev/null
+++ b/src/client/lua_api/scene/ilight.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>
+
+int ilight_register(lua_State* L, irr::IrrlichtDevice* d);
diff --git a/src/client/lua_api/scene/imesh.cpp b/src/client/lua_api/scene/imesh.cpp
index c95366f..bbb0017 100644
--- a/src/client/lua_api/scene/imesh.cpp
+++ b/src/client/lua_api/scene/imesh.cpp
@@ -35,58 +35,46 @@ static LISceneNode* checkismesh(lua_State* L){
}
*/
-//iscenecamera.new(Vector position, Vector lookat, parrent)
static int newiscenemesh(lua_State* L){
- printf("Createing mesh!\n");
- int nargs = lua_gettop(L);
- if(nargs != 1){
+ 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 );
- 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;
-}
-
-/*mesh:setmaterial("string",layernum=0)*/
-static int setmaterial(lua_State* L){
- LISceneNode* n = checkismesh(L,1);
- //u32 layernum = luaL_optint(L,3,0);
- const char* matfile = luaL_optstring(L,2,"error.png");
- printf("Setting material on a %s",n->type);
- IVideoDriver* driver = device->getVideoDriver();
- n->n->setMaterialTexture( 0, driver->getTexture(matfile) );
- return 0;
+ }
+ //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;
}
static const luaL_reg imesh_f[] = {
@@ -97,7 +85,7 @@ static const luaL_reg imesh_f[] = {
};
static const luaL_reg imesh_m[] = {
- {"setMaterial", setmaterial},
+ {"setMaterial", iscenesetmaterial},
{"getpos", iscenegetpos},
{"setpos", iscenesetpos},
// {"settext", setiguitext},