1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/*This file defines some things that all igui stuff can do*/
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#include <irrlicht.h>
#include "igeneric.hpp"
#include "../gameparts.hpp"
#include <shared/lua_api/common.hpp>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
extern IrrlichtDevice* device;
/***
Get the position of a scene element.
@function iscenenode:getpos()
@treturn vector3d position The position this element is at
*/
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);
return 1;
}
/***
Set the position of a scene element.
@function iscenenode:setpos(vector3d)
@tparam vector3d position The position to set this element to
*/
int iscenesetpos(lua_State* L){//{node=ISceneNode},{x,y,z}
double x,y,z;
popvector3d(L,&x,&y,&z);//{node=ud_ISceneNode}
lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode
ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
i->setPosition(vector3df(x,y,z));
i->updateAbsolutePosition();
lua_pop(L,2);//
return 0;
}
/***
Set the rotation of a scene element.
@function iscenenode:getang()
@treturn angle3d The angle of this element
*/
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;
}
/***
Set the rotation of a scene element.
@function iscenenode:getang()
@tparam angle3d angle The angle to set this element to
*/
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;
}
/***
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){
int args = lua_gettop(L);
u32 layer = 0;
if(args == 3){
layer = lua_tonumber(L,-1);
lua_pop(L,1);
}
lua_getfield(L,-1,"texture");
ITexture *txt = (ITexture*)lua_touserdata(L,-1);//{node=ud_ISceneNode},{texture=ud_itexture},ud_itexture
lua_pop(L,2);//{node=ud_ISceneNode}
lua_getfield(L,-1,"node");
ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
lua_pop(L,2);//
i->setMaterialTexture(layer,txt);
return 0;
}
/***
Set the name of a scene element.
@function iscenenode:setname()
@tparam string name The name to give this scene element.
*/
//iscenesetname({node=ud_ISceneNode},str_name)
int iscenesetname(lua_State *L){
const char *name = lua_tostring(L,-1);
lua_pop(L,1);//{node=ud_ISceneNode}
lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode
ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
lua_pop(L,2);
i->setName((c8*)name);
return 0;
}
/***
Get the name of this scene element.
@function iscenenode:getname()
@tparam string name The name to give this scene element.
*/
//iscenesetname({node=ud_ISceneNode})
int iscenegetname(lua_State *L){
lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode
ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
lua_pop(L,2);
const char *name = i->getName();
lua_pushstring(L,name);
return 1;
}
/***
Set the scale of this scene element.
@function iscenenode:setscale({x,y,z})
@tparam vector3d scale The scale to give this scene element.
*/
//iscenesetscale({x,y,z})
int iscenesetscale(lua_State *L){
double x,y,z;
popvector3d(L,&x,&y,&z);
lua_getfield(L,-1,"node");
ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
lua_pop(L,2);
i->setScale(vector3df(x,y,z));
return 1;
}
/***
Sets the visibility of this scene element
@function iscenenode:setvisible(bool)
@tparam boolean visible Sets the visibility for this element
*/
//setvisible(true|false)
int iscenesetvisible(lua_State *L){
int visible = lua_toboolean(L,-1);
lua_pop(L,1);
lua_getfield(L, -1, "node");
ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode}, ud_ISceneNode
lua_pop(L,2);
i->setVisible(visible == 1);
return 0;
}
/***
Get the scale of this scene element.
@function iscenenode:getscale()
@treturn vector3d The scale scale of this element.
*/
//iscenegetscale()
int iscenegetscale(lua_State *L){
lua_getfield(L,-1,"node");
ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
lua_pop(L,2);
vector3df scale = i->getScale();
double x,y,z;
x = scale.X;
y = scale.Y;
z = scale.Z;
pushvector3d(L,x,y,z);
return 1;
}
/***
Get the scale of this scene element.
@function iscenenode:getscale()
@treturn vector3d The scale scale of this element.
*/
//iscenenode:remove()
int isceneremove(lua_State *L){
lua_getfield(L,-1,"node");
ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
lua_pop(L,2);
i->remove();
return 0;
}
/***
Sets the debug flag for this object
@function iscenenode:setDebugDataVisible(int flags)
*/
//iscenenode:setdebugflags({self},flags)
int iscenesetdebug(lua_State *L){
u32 flags = lua_tonumber(L,-1);
lua_getfield(L,-1,"node");
ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);
lua_pop(L,3);
i->setDebugDataVisible(flags);
return 0;
}
extern const luaL_Reg igeneric_m[] = {
{"getpos", iscenegetpos},
{"setpos", iscenesetpos},
{"getang", iscenegetangle},
{"setang", iscenesetangle},
{"setmaterialtexture", iscenesetmaterial},
{"getmaterial", iscenegetmaterial},
{"getmaterialcount", iscenegetmaterialcount},
{"setmaterialflag", iscenesetmaterialflag},
{"getname", iscenegetname},
{"setname", iscenesetname},
{"setscale", iscenesetscale},
{"getscale", iscenegetscale},
{"remove", isceneremove},
{"setvisible", iscenesetvisible},
{"setdebugflags", iscenesetdebug},
{0, 0},
};
|