lua_Mesh.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Mesh.h"
  4. #include "Base.h"
  5. #include "Effect.h"
  6. #include "Game.h"
  7. #include "Material.h"
  8. #include "Mesh.h"
  9. #include "MeshPart.h"
  10. #include "Model.h"
  11. #include "Ref.h"
  12. #include "lua_MeshIndexFormat.h"
  13. #include "lua_MeshPrimitiveType.h"
  14. namespace gameplay
  15. {
  16. void luaRegister_Mesh()
  17. {
  18. ScriptController* sc = ScriptController::getInstance();
  19. const luaL_Reg lua_members[] =
  20. {
  21. {"addPart", lua_Mesh_addPart},
  22. {"addRef", lua_Mesh_addRef},
  23. {"getBoundingBox", lua_Mesh_getBoundingBox},
  24. {"getBoundingSphere", lua_Mesh_getBoundingSphere},
  25. {"getPart", lua_Mesh_getPart},
  26. {"getPartCount", lua_Mesh_getPartCount},
  27. {"getPrimitiveType", lua_Mesh_getPrimitiveType},
  28. {"getRefCount", lua_Mesh_getRefCount},
  29. {"getUrl", lua_Mesh_getUrl},
  30. {"getVertexBuffer", lua_Mesh_getVertexBuffer},
  31. {"getVertexCount", lua_Mesh_getVertexCount},
  32. {"getVertexFormat", lua_Mesh_getVertexFormat},
  33. {"getVertexSize", lua_Mesh_getVertexSize},
  34. {"isDynamic", lua_Mesh_isDynamic},
  35. {"release", lua_Mesh_release},
  36. {"setBoundingBox", lua_Mesh_setBoundingBox},
  37. {"setBoundingSphere", lua_Mesh_setBoundingSphere},
  38. {"setPrimitiveType", lua_Mesh_setPrimitiveType},
  39. {"setVertexData", lua_Mesh_setVertexData},
  40. {NULL, NULL}
  41. };
  42. const luaL_Reg lua_statics[] =
  43. {
  44. {"createBoundingBox", lua_Mesh_static_createBoundingBox},
  45. {"createLines", lua_Mesh_static_createLines},
  46. {"createMesh", lua_Mesh_static_createMesh},
  47. {"createQuad", lua_Mesh_static_createQuad},
  48. {"createQuadFullscreen", lua_Mesh_static_createQuadFullscreen},
  49. {NULL, NULL}
  50. };
  51. std::vector<std::string> scopePath;
  52. sc->registerClass("Mesh", lua_members, NULL, lua_Mesh__gc, lua_statics, scopePath);
  53. }
  54. static Mesh* getInstance(lua_State* state)
  55. {
  56. void* userdata = luaL_checkudata(state, 1, "Mesh");
  57. luaL_argcheck(state, userdata != NULL, 1, "'Mesh' expected.");
  58. return (Mesh*)((ScriptController::LuaObject*)userdata)->instance;
  59. }
  60. int lua_Mesh__gc(lua_State* state)
  61. {
  62. // Get the number of parameters.
  63. int paramCount = lua_gettop(state);
  64. // Attempt to match the parameters to a valid binding.
  65. switch (paramCount)
  66. {
  67. case 1:
  68. {
  69. if ((lua_type(state, 1) == LUA_TUSERDATA))
  70. {
  71. void* userdata = luaL_checkudata(state, 1, "Mesh");
  72. luaL_argcheck(state, userdata != NULL, 1, "'Mesh' expected.");
  73. ScriptController::LuaObject* object = (ScriptController::LuaObject*)userdata;
  74. if (object->owns)
  75. {
  76. Mesh* instance = (Mesh*)object->instance;
  77. SAFE_RELEASE(instance);
  78. }
  79. return 0;
  80. }
  81. else
  82. {
  83. lua_pushstring(state, "lua_Mesh__gc - Failed to match the given parameters to a valid function signature.");
  84. lua_error(state);
  85. }
  86. break;
  87. }
  88. default:
  89. {
  90. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  91. lua_error(state);
  92. break;
  93. }
  94. }
  95. return 0;
  96. }
  97. int lua_Mesh_addPart(lua_State* state)
  98. {
  99. // Get the number of parameters.
  100. int paramCount = lua_gettop(state);
  101. // Attempt to match the parameters to a valid binding.
  102. switch (paramCount)
  103. {
  104. case 4:
  105. {
  106. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  107. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  108. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  109. lua_type(state, 4) == LUA_TNUMBER)
  110. {
  111. // Get parameter 1 off the stack.
  112. Mesh::PrimitiveType param1 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  113. // Get parameter 2 off the stack.
  114. Mesh::IndexFormat param2 = (Mesh::IndexFormat)lua_enumFromString_MeshIndexFormat(luaL_checkstring(state, 3));
  115. // Get parameter 3 off the stack.
  116. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  117. Mesh* instance = getInstance(state);
  118. void* returnPtr = (void*)instance->addPart(param1, param2, param3);
  119. if (returnPtr)
  120. {
  121. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  122. object->instance = returnPtr;
  123. object->owns = false;
  124. luaL_getmetatable(state, "MeshPart");
  125. lua_setmetatable(state, -2);
  126. }
  127. else
  128. {
  129. lua_pushnil(state);
  130. }
  131. return 1;
  132. }
  133. else
  134. {
  135. lua_pushstring(state, "lua_Mesh_addPart - Failed to match the given parameters to a valid function signature.");
  136. lua_error(state);
  137. }
  138. break;
  139. }
  140. case 5:
  141. {
  142. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  143. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  144. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  145. lua_type(state, 4) == LUA_TNUMBER &&
  146. lua_type(state, 5) == LUA_TBOOLEAN)
  147. {
  148. // Get parameter 1 off the stack.
  149. Mesh::PrimitiveType param1 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  150. // Get parameter 2 off the stack.
  151. Mesh::IndexFormat param2 = (Mesh::IndexFormat)lua_enumFromString_MeshIndexFormat(luaL_checkstring(state, 3));
  152. // Get parameter 3 off the stack.
  153. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  154. // Get parameter 4 off the stack.
  155. bool param4 = ScriptController::luaCheckBool(state, 5);
  156. Mesh* instance = getInstance(state);
  157. void* returnPtr = (void*)instance->addPart(param1, param2, param3, param4);
  158. if (returnPtr)
  159. {
  160. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  161. object->instance = returnPtr;
  162. object->owns = false;
  163. luaL_getmetatable(state, "MeshPart");
  164. lua_setmetatable(state, -2);
  165. }
  166. else
  167. {
  168. lua_pushnil(state);
  169. }
  170. return 1;
  171. }
  172. else
  173. {
  174. lua_pushstring(state, "lua_Mesh_addPart - Failed to match the given parameters to a valid function signature.");
  175. lua_error(state);
  176. }
  177. break;
  178. }
  179. default:
  180. {
  181. lua_pushstring(state, "Invalid number of parameters (expected 4 or 5).");
  182. lua_error(state);
  183. break;
  184. }
  185. }
  186. return 0;
  187. }
  188. int lua_Mesh_addRef(lua_State* state)
  189. {
  190. // Get the number of parameters.
  191. int paramCount = lua_gettop(state);
  192. // Attempt to match the parameters to a valid binding.
  193. switch (paramCount)
  194. {
  195. case 1:
  196. {
  197. if ((lua_type(state, 1) == LUA_TUSERDATA))
  198. {
  199. Mesh* instance = getInstance(state);
  200. instance->addRef();
  201. return 0;
  202. }
  203. else
  204. {
  205. lua_pushstring(state, "lua_Mesh_addRef - Failed to match the given parameters to a valid function signature.");
  206. lua_error(state);
  207. }
  208. break;
  209. }
  210. default:
  211. {
  212. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  213. lua_error(state);
  214. break;
  215. }
  216. }
  217. return 0;
  218. }
  219. int lua_Mesh_getBoundingBox(lua_State* state)
  220. {
  221. // Get the number of parameters.
  222. int paramCount = lua_gettop(state);
  223. // Attempt to match the parameters to a valid binding.
  224. switch (paramCount)
  225. {
  226. case 1:
  227. {
  228. if ((lua_type(state, 1) == LUA_TUSERDATA))
  229. {
  230. Mesh* instance = getInstance(state);
  231. void* returnPtr = (void*)&(instance->getBoundingBox());
  232. if (returnPtr)
  233. {
  234. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  235. object->instance = returnPtr;
  236. object->owns = false;
  237. luaL_getmetatable(state, "BoundingBox");
  238. lua_setmetatable(state, -2);
  239. }
  240. else
  241. {
  242. lua_pushnil(state);
  243. }
  244. return 1;
  245. }
  246. else
  247. {
  248. lua_pushstring(state, "lua_Mesh_getBoundingBox - Failed to match the given parameters to a valid function signature.");
  249. lua_error(state);
  250. }
  251. break;
  252. }
  253. default:
  254. {
  255. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  256. lua_error(state);
  257. break;
  258. }
  259. }
  260. return 0;
  261. }
  262. int lua_Mesh_getBoundingSphere(lua_State* state)
  263. {
  264. // Get the number of parameters.
  265. int paramCount = lua_gettop(state);
  266. // Attempt to match the parameters to a valid binding.
  267. switch (paramCount)
  268. {
  269. case 1:
  270. {
  271. if ((lua_type(state, 1) == LUA_TUSERDATA))
  272. {
  273. Mesh* instance = getInstance(state);
  274. void* returnPtr = (void*)&(instance->getBoundingSphere());
  275. if (returnPtr)
  276. {
  277. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  278. object->instance = returnPtr;
  279. object->owns = false;
  280. luaL_getmetatable(state, "BoundingSphere");
  281. lua_setmetatable(state, -2);
  282. }
  283. else
  284. {
  285. lua_pushnil(state);
  286. }
  287. return 1;
  288. }
  289. else
  290. {
  291. lua_pushstring(state, "lua_Mesh_getBoundingSphere - Failed to match the given parameters to a valid function signature.");
  292. lua_error(state);
  293. }
  294. break;
  295. }
  296. default:
  297. {
  298. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  299. lua_error(state);
  300. break;
  301. }
  302. }
  303. return 0;
  304. }
  305. int lua_Mesh_getPart(lua_State* state)
  306. {
  307. // Get the number of parameters.
  308. int paramCount = lua_gettop(state);
  309. // Attempt to match the parameters to a valid binding.
  310. switch (paramCount)
  311. {
  312. case 2:
  313. {
  314. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  315. lua_type(state, 2) == LUA_TNUMBER)
  316. {
  317. // Get parameter 1 off the stack.
  318. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  319. Mesh* instance = getInstance(state);
  320. void* returnPtr = (void*)instance->getPart(param1);
  321. if (returnPtr)
  322. {
  323. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  324. object->instance = returnPtr;
  325. object->owns = false;
  326. luaL_getmetatable(state, "MeshPart");
  327. lua_setmetatable(state, -2);
  328. }
  329. else
  330. {
  331. lua_pushnil(state);
  332. }
  333. return 1;
  334. }
  335. else
  336. {
  337. lua_pushstring(state, "lua_Mesh_getPart - Failed to match the given parameters to a valid function signature.");
  338. lua_error(state);
  339. }
  340. break;
  341. }
  342. default:
  343. {
  344. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  345. lua_error(state);
  346. break;
  347. }
  348. }
  349. return 0;
  350. }
  351. int lua_Mesh_getPartCount(lua_State* state)
  352. {
  353. // Get the number of parameters.
  354. int paramCount = lua_gettop(state);
  355. // Attempt to match the parameters to a valid binding.
  356. switch (paramCount)
  357. {
  358. case 1:
  359. {
  360. if ((lua_type(state, 1) == LUA_TUSERDATA))
  361. {
  362. Mesh* instance = getInstance(state);
  363. unsigned int result = instance->getPartCount();
  364. // Push the return value onto the stack.
  365. lua_pushunsigned(state, result);
  366. return 1;
  367. }
  368. else
  369. {
  370. lua_pushstring(state, "lua_Mesh_getPartCount - Failed to match the given parameters to a valid function signature.");
  371. lua_error(state);
  372. }
  373. break;
  374. }
  375. default:
  376. {
  377. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  378. lua_error(state);
  379. break;
  380. }
  381. }
  382. return 0;
  383. }
  384. int lua_Mesh_getPrimitiveType(lua_State* state)
  385. {
  386. // Get the number of parameters.
  387. int paramCount = lua_gettop(state);
  388. // Attempt to match the parameters to a valid binding.
  389. switch (paramCount)
  390. {
  391. case 1:
  392. {
  393. if ((lua_type(state, 1) == LUA_TUSERDATA))
  394. {
  395. Mesh* instance = getInstance(state);
  396. Mesh::PrimitiveType result = instance->getPrimitiveType();
  397. // Push the return value onto the stack.
  398. lua_pushstring(state, lua_stringFromEnum_MeshPrimitiveType(result));
  399. return 1;
  400. }
  401. else
  402. {
  403. lua_pushstring(state, "lua_Mesh_getPrimitiveType - Failed to match the given parameters to a valid function signature.");
  404. lua_error(state);
  405. }
  406. break;
  407. }
  408. default:
  409. {
  410. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  411. lua_error(state);
  412. break;
  413. }
  414. }
  415. return 0;
  416. }
  417. int lua_Mesh_getRefCount(lua_State* state)
  418. {
  419. // Get the number of parameters.
  420. int paramCount = lua_gettop(state);
  421. // Attempt to match the parameters to a valid binding.
  422. switch (paramCount)
  423. {
  424. case 1:
  425. {
  426. if ((lua_type(state, 1) == LUA_TUSERDATA))
  427. {
  428. Mesh* instance = getInstance(state);
  429. unsigned int result = instance->getRefCount();
  430. // Push the return value onto the stack.
  431. lua_pushunsigned(state, result);
  432. return 1;
  433. }
  434. else
  435. {
  436. lua_pushstring(state, "lua_Mesh_getRefCount - Failed to match the given parameters to a valid function signature.");
  437. lua_error(state);
  438. }
  439. break;
  440. }
  441. default:
  442. {
  443. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  444. lua_error(state);
  445. break;
  446. }
  447. }
  448. return 0;
  449. }
  450. int lua_Mesh_getUrl(lua_State* state)
  451. {
  452. // Get the number of parameters.
  453. int paramCount = lua_gettop(state);
  454. // Attempt to match the parameters to a valid binding.
  455. switch (paramCount)
  456. {
  457. case 1:
  458. {
  459. if ((lua_type(state, 1) == LUA_TUSERDATA))
  460. {
  461. Mesh* instance = getInstance(state);
  462. const char* result = instance->getUrl();
  463. // Push the return value onto the stack.
  464. lua_pushstring(state, result);
  465. return 1;
  466. }
  467. else
  468. {
  469. lua_pushstring(state, "lua_Mesh_getUrl - Failed to match the given parameters to a valid function signature.");
  470. lua_error(state);
  471. }
  472. break;
  473. }
  474. default:
  475. {
  476. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  477. lua_error(state);
  478. break;
  479. }
  480. }
  481. return 0;
  482. }
  483. int lua_Mesh_getVertexBuffer(lua_State* state)
  484. {
  485. // Get the number of parameters.
  486. int paramCount = lua_gettop(state);
  487. // Attempt to match the parameters to a valid binding.
  488. switch (paramCount)
  489. {
  490. case 1:
  491. {
  492. if ((lua_type(state, 1) == LUA_TUSERDATA))
  493. {
  494. Mesh* instance = getInstance(state);
  495. void* returnPtr = (void*)new GLuint(instance->getVertexBuffer());
  496. if (returnPtr)
  497. {
  498. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  499. object->instance = returnPtr;
  500. object->owns = true;
  501. luaL_getmetatable(state, "GLuint");
  502. lua_setmetatable(state, -2);
  503. }
  504. else
  505. {
  506. lua_pushnil(state);
  507. }
  508. return 1;
  509. }
  510. else
  511. {
  512. lua_pushstring(state, "lua_Mesh_getVertexBuffer - Failed to match the given parameters to a valid function signature.");
  513. lua_error(state);
  514. }
  515. break;
  516. }
  517. default:
  518. {
  519. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  520. lua_error(state);
  521. break;
  522. }
  523. }
  524. return 0;
  525. }
  526. int lua_Mesh_getVertexCount(lua_State* state)
  527. {
  528. // Get the number of parameters.
  529. int paramCount = lua_gettop(state);
  530. // Attempt to match the parameters to a valid binding.
  531. switch (paramCount)
  532. {
  533. case 1:
  534. {
  535. if ((lua_type(state, 1) == LUA_TUSERDATA))
  536. {
  537. Mesh* instance = getInstance(state);
  538. unsigned int result = instance->getVertexCount();
  539. // Push the return value onto the stack.
  540. lua_pushunsigned(state, result);
  541. return 1;
  542. }
  543. else
  544. {
  545. lua_pushstring(state, "lua_Mesh_getVertexCount - Failed to match the given parameters to a valid function signature.");
  546. lua_error(state);
  547. }
  548. break;
  549. }
  550. default:
  551. {
  552. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  553. lua_error(state);
  554. break;
  555. }
  556. }
  557. return 0;
  558. }
  559. int lua_Mesh_getVertexFormat(lua_State* state)
  560. {
  561. // Get the number of parameters.
  562. int paramCount = lua_gettop(state);
  563. // Attempt to match the parameters to a valid binding.
  564. switch (paramCount)
  565. {
  566. case 1:
  567. {
  568. if ((lua_type(state, 1) == LUA_TUSERDATA))
  569. {
  570. Mesh* instance = getInstance(state);
  571. void* returnPtr = (void*)&(instance->getVertexFormat());
  572. if (returnPtr)
  573. {
  574. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  575. object->instance = returnPtr;
  576. object->owns = false;
  577. luaL_getmetatable(state, "VertexFormat");
  578. lua_setmetatable(state, -2);
  579. }
  580. else
  581. {
  582. lua_pushnil(state);
  583. }
  584. return 1;
  585. }
  586. else
  587. {
  588. lua_pushstring(state, "lua_Mesh_getVertexFormat - Failed to match the given parameters to a valid function signature.");
  589. lua_error(state);
  590. }
  591. break;
  592. }
  593. default:
  594. {
  595. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  596. lua_error(state);
  597. break;
  598. }
  599. }
  600. return 0;
  601. }
  602. int lua_Mesh_getVertexSize(lua_State* state)
  603. {
  604. // Get the number of parameters.
  605. int paramCount = lua_gettop(state);
  606. // Attempt to match the parameters to a valid binding.
  607. switch (paramCount)
  608. {
  609. case 1:
  610. {
  611. if ((lua_type(state, 1) == LUA_TUSERDATA))
  612. {
  613. Mesh* instance = getInstance(state);
  614. unsigned int result = instance->getVertexSize();
  615. // Push the return value onto the stack.
  616. lua_pushunsigned(state, result);
  617. return 1;
  618. }
  619. else
  620. {
  621. lua_pushstring(state, "lua_Mesh_getVertexSize - Failed to match the given parameters to a valid function signature.");
  622. lua_error(state);
  623. }
  624. break;
  625. }
  626. default:
  627. {
  628. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  629. lua_error(state);
  630. break;
  631. }
  632. }
  633. return 0;
  634. }
  635. int lua_Mesh_isDynamic(lua_State* state)
  636. {
  637. // Get the number of parameters.
  638. int paramCount = lua_gettop(state);
  639. // Attempt to match the parameters to a valid binding.
  640. switch (paramCount)
  641. {
  642. case 1:
  643. {
  644. if ((lua_type(state, 1) == LUA_TUSERDATA))
  645. {
  646. Mesh* instance = getInstance(state);
  647. bool result = instance->isDynamic();
  648. // Push the return value onto the stack.
  649. lua_pushboolean(state, result);
  650. return 1;
  651. }
  652. else
  653. {
  654. lua_pushstring(state, "lua_Mesh_isDynamic - Failed to match the given parameters to a valid function signature.");
  655. lua_error(state);
  656. }
  657. break;
  658. }
  659. default:
  660. {
  661. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  662. lua_error(state);
  663. break;
  664. }
  665. }
  666. return 0;
  667. }
  668. int lua_Mesh_release(lua_State* state)
  669. {
  670. // Get the number of parameters.
  671. int paramCount = lua_gettop(state);
  672. // Attempt to match the parameters to a valid binding.
  673. switch (paramCount)
  674. {
  675. case 1:
  676. {
  677. if ((lua_type(state, 1) == LUA_TUSERDATA))
  678. {
  679. Mesh* instance = getInstance(state);
  680. instance->release();
  681. return 0;
  682. }
  683. else
  684. {
  685. lua_pushstring(state, "lua_Mesh_release - Failed to match the given parameters to a valid function signature.");
  686. lua_error(state);
  687. }
  688. break;
  689. }
  690. default:
  691. {
  692. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  693. lua_error(state);
  694. break;
  695. }
  696. }
  697. return 0;
  698. }
  699. int lua_Mesh_setBoundingBox(lua_State* state)
  700. {
  701. // Get the number of parameters.
  702. int paramCount = lua_gettop(state);
  703. // Attempt to match the parameters to a valid binding.
  704. switch (paramCount)
  705. {
  706. case 2:
  707. {
  708. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  709. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  710. {
  711. // Get parameter 1 off the stack.
  712. BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
  713. Mesh* instance = getInstance(state);
  714. instance->setBoundingBox(*param1);
  715. return 0;
  716. }
  717. else
  718. {
  719. lua_pushstring(state, "lua_Mesh_setBoundingBox - Failed to match the given parameters to a valid function signature.");
  720. lua_error(state);
  721. }
  722. break;
  723. }
  724. default:
  725. {
  726. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  727. lua_error(state);
  728. break;
  729. }
  730. }
  731. return 0;
  732. }
  733. int lua_Mesh_setBoundingSphere(lua_State* state)
  734. {
  735. // Get the number of parameters.
  736. int paramCount = lua_gettop(state);
  737. // Attempt to match the parameters to a valid binding.
  738. switch (paramCount)
  739. {
  740. case 2:
  741. {
  742. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  743. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  744. {
  745. // Get parameter 1 off the stack.
  746. BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
  747. Mesh* instance = getInstance(state);
  748. instance->setBoundingSphere(*param1);
  749. return 0;
  750. }
  751. else
  752. {
  753. lua_pushstring(state, "lua_Mesh_setBoundingSphere - Failed to match the given parameters to a valid function signature.");
  754. lua_error(state);
  755. }
  756. break;
  757. }
  758. default:
  759. {
  760. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  761. lua_error(state);
  762. break;
  763. }
  764. }
  765. return 0;
  766. }
  767. int lua_Mesh_setPrimitiveType(lua_State* state)
  768. {
  769. // Get the number of parameters.
  770. int paramCount = lua_gettop(state);
  771. // Attempt to match the parameters to a valid binding.
  772. switch (paramCount)
  773. {
  774. case 2:
  775. {
  776. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  777. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  778. {
  779. // Get parameter 1 off the stack.
  780. Mesh::PrimitiveType param1 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  781. Mesh* instance = getInstance(state);
  782. instance->setPrimitiveType(param1);
  783. return 0;
  784. }
  785. else
  786. {
  787. lua_pushstring(state, "lua_Mesh_setPrimitiveType - Failed to match the given parameters to a valid function signature.");
  788. lua_error(state);
  789. }
  790. break;
  791. }
  792. default:
  793. {
  794. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  795. lua_error(state);
  796. break;
  797. }
  798. }
  799. return 0;
  800. }
  801. int lua_Mesh_setVertexData(lua_State* state)
  802. {
  803. // Get the number of parameters.
  804. int paramCount = lua_gettop(state);
  805. // Attempt to match the parameters to a valid binding.
  806. switch (paramCount)
  807. {
  808. case 2:
  809. {
  810. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  811. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
  812. {
  813. // Get parameter 1 off the stack.
  814. float* param1 = ScriptController::getInstance()->getFloatPointer(2);
  815. Mesh* instance = getInstance(state);
  816. instance->setVertexData(param1);
  817. return 0;
  818. }
  819. else
  820. {
  821. lua_pushstring(state, "lua_Mesh_setVertexData - Failed to match the given parameters to a valid function signature.");
  822. lua_error(state);
  823. }
  824. break;
  825. }
  826. case 3:
  827. {
  828. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  829. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
  830. lua_type(state, 3) == LUA_TNUMBER)
  831. {
  832. // Get parameter 1 off the stack.
  833. float* param1 = ScriptController::getInstance()->getFloatPointer(2);
  834. // Get parameter 2 off the stack.
  835. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  836. Mesh* instance = getInstance(state);
  837. instance->setVertexData(param1, param2);
  838. return 0;
  839. }
  840. else
  841. {
  842. lua_pushstring(state, "lua_Mesh_setVertexData - Failed to match the given parameters to a valid function signature.");
  843. lua_error(state);
  844. }
  845. break;
  846. }
  847. case 4:
  848. {
  849. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  850. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
  851. lua_type(state, 3) == LUA_TNUMBER &&
  852. lua_type(state, 4) == LUA_TNUMBER)
  853. {
  854. // Get parameter 1 off the stack.
  855. float* param1 = ScriptController::getInstance()->getFloatPointer(2);
  856. // Get parameter 2 off the stack.
  857. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  858. // Get parameter 3 off the stack.
  859. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  860. Mesh* instance = getInstance(state);
  861. instance->setVertexData(param1, param2, param3);
  862. return 0;
  863. }
  864. else
  865. {
  866. lua_pushstring(state, "lua_Mesh_setVertexData - Failed to match the given parameters to a valid function signature.");
  867. lua_error(state);
  868. }
  869. break;
  870. }
  871. default:
  872. {
  873. lua_pushstring(state, "Invalid number of parameters (expected 2, 3 or 4).");
  874. lua_error(state);
  875. break;
  876. }
  877. }
  878. return 0;
  879. }
  880. int lua_Mesh_static_createBoundingBox(lua_State* state)
  881. {
  882. // Get the number of parameters.
  883. int paramCount = lua_gettop(state);
  884. // Attempt to match the parameters to a valid binding.
  885. switch (paramCount)
  886. {
  887. case 1:
  888. {
  889. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  890. {
  891. // Get parameter 1 off the stack.
  892. BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(1, "BoundingBox", true);
  893. void* returnPtr = (void*)Mesh::createBoundingBox(*param1);
  894. if (returnPtr)
  895. {
  896. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  897. object->instance = returnPtr;
  898. object->owns = false;
  899. luaL_getmetatable(state, "Mesh");
  900. lua_setmetatable(state, -2);
  901. }
  902. else
  903. {
  904. lua_pushnil(state);
  905. }
  906. return 1;
  907. }
  908. else
  909. {
  910. lua_pushstring(state, "lua_Mesh_static_createBoundingBox - Failed to match the given parameters to a valid function signature.");
  911. lua_error(state);
  912. }
  913. break;
  914. }
  915. default:
  916. {
  917. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  918. lua_error(state);
  919. break;
  920. }
  921. }
  922. return 0;
  923. }
  924. int lua_Mesh_static_createLines(lua_State* state)
  925. {
  926. // Get the number of parameters.
  927. int paramCount = lua_gettop(state);
  928. // Attempt to match the parameters to a valid binding.
  929. switch (paramCount)
  930. {
  931. case 2:
  932. {
  933. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  934. lua_type(state, 2) == LUA_TNUMBER)
  935. {
  936. // Get parameter 1 off the stack.
  937. Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", false);
  938. // Get parameter 2 off the stack.
  939. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  940. void* returnPtr = (void*)Mesh::createLines(param1, param2);
  941. if (returnPtr)
  942. {
  943. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  944. object->instance = returnPtr;
  945. object->owns = false;
  946. luaL_getmetatable(state, "Mesh");
  947. lua_setmetatable(state, -2);
  948. }
  949. else
  950. {
  951. lua_pushnil(state);
  952. }
  953. return 1;
  954. }
  955. else
  956. {
  957. lua_pushstring(state, "lua_Mesh_static_createLines - Failed to match the given parameters to a valid function signature.");
  958. lua_error(state);
  959. }
  960. break;
  961. }
  962. default:
  963. {
  964. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  965. lua_error(state);
  966. break;
  967. }
  968. }
  969. return 0;
  970. }
  971. int lua_Mesh_static_createMesh(lua_State* state)
  972. {
  973. // Get the number of parameters.
  974. int paramCount = lua_gettop(state);
  975. // Attempt to match the parameters to a valid binding.
  976. switch (paramCount)
  977. {
  978. case 2:
  979. {
  980. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  981. lua_type(state, 2) == LUA_TNUMBER)
  982. {
  983. // Get parameter 1 off the stack.
  984. VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
  985. // Get parameter 2 off the stack.
  986. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  987. void* returnPtr = (void*)Mesh::createMesh(*param1, param2);
  988. if (returnPtr)
  989. {
  990. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  991. object->instance = returnPtr;
  992. object->owns = false;
  993. luaL_getmetatable(state, "Mesh");
  994. lua_setmetatable(state, -2);
  995. }
  996. else
  997. {
  998. lua_pushnil(state);
  999. }
  1000. return 1;
  1001. }
  1002. else
  1003. {
  1004. lua_pushstring(state, "lua_Mesh_static_createMesh - Failed to match the given parameters to a valid function signature.");
  1005. lua_error(state);
  1006. }
  1007. break;
  1008. }
  1009. case 3:
  1010. {
  1011. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  1012. lua_type(state, 2) == LUA_TNUMBER &&
  1013. lua_type(state, 3) == LUA_TBOOLEAN)
  1014. {
  1015. // Get parameter 1 off the stack.
  1016. VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
  1017. // Get parameter 2 off the stack.
  1018. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  1019. // Get parameter 3 off the stack.
  1020. bool param3 = ScriptController::luaCheckBool(state, 3);
  1021. void* returnPtr = (void*)Mesh::createMesh(*param1, param2, param3);
  1022. if (returnPtr)
  1023. {
  1024. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  1025. object->instance = returnPtr;
  1026. object->owns = false;
  1027. luaL_getmetatable(state, "Mesh");
  1028. lua_setmetatable(state, -2);
  1029. }
  1030. else
  1031. {
  1032. lua_pushnil(state);
  1033. }
  1034. return 1;
  1035. }
  1036. else
  1037. {
  1038. lua_pushstring(state, "lua_Mesh_static_createMesh - Failed to match the given parameters to a valid function signature.");
  1039. lua_error(state);
  1040. }
  1041. break;
  1042. }
  1043. default:
  1044. {
  1045. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  1046. lua_error(state);
  1047. break;
  1048. }
  1049. }
  1050. return 0;
  1051. }
  1052. int lua_Mesh_static_createQuad(lua_State* state)
  1053. {
  1054. // Get the number of parameters.
  1055. int paramCount = lua_gettop(state);
  1056. // Attempt to match the parameters to a valid binding.
  1057. switch (paramCount)
  1058. {
  1059. case 4:
  1060. {
  1061. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  1062. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  1063. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
  1064. (lua_type(state, 4) == LUA_TUSERDATA || lua_type(state, 4) == LUA_TNIL))
  1065. {
  1066. // Get parameter 1 off the stack.
  1067. Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
  1068. // Get parameter 2 off the stack.
  1069. Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
  1070. // Get parameter 3 off the stack.
  1071. Vector3* param3 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
  1072. // Get parameter 4 off the stack.
  1073. Vector3* param4 = ScriptController::getInstance()->getObjectPointer<Vector3>(4, "Vector3", true);
  1074. void* returnPtr = (void*)Mesh::createQuad(*param1, *param2, *param3, *param4);
  1075. if (returnPtr)
  1076. {
  1077. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  1078. object->instance = returnPtr;
  1079. object->owns = false;
  1080. luaL_getmetatable(state, "Mesh");
  1081. lua_setmetatable(state, -2);
  1082. }
  1083. else
  1084. {
  1085. lua_pushnil(state);
  1086. }
  1087. return 1;
  1088. }
  1089. else if (lua_type(state, 1) == LUA_TNUMBER &&
  1090. lua_type(state, 2) == LUA_TNUMBER &&
  1091. lua_type(state, 3) == LUA_TNUMBER &&
  1092. lua_type(state, 4) == LUA_TNUMBER)
  1093. {
  1094. // Get parameter 1 off the stack.
  1095. float param1 = (float)luaL_checknumber(state, 1);
  1096. // Get parameter 2 off the stack.
  1097. float param2 = (float)luaL_checknumber(state, 2);
  1098. // Get parameter 3 off the stack.
  1099. float param3 = (float)luaL_checknumber(state, 3);
  1100. // Get parameter 4 off the stack.
  1101. float param4 = (float)luaL_checknumber(state, 4);
  1102. void* returnPtr = (void*)Mesh::createQuad(param1, param2, param3, param4);
  1103. if (returnPtr)
  1104. {
  1105. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  1106. object->instance = returnPtr;
  1107. object->owns = false;
  1108. luaL_getmetatable(state, "Mesh");
  1109. lua_setmetatable(state, -2);
  1110. }
  1111. else
  1112. {
  1113. lua_pushnil(state);
  1114. }
  1115. return 1;
  1116. }
  1117. else
  1118. {
  1119. lua_pushstring(state, "lua_Mesh_static_createQuad - Failed to match the given parameters to a valid function signature.");
  1120. lua_error(state);
  1121. }
  1122. break;
  1123. }
  1124. default:
  1125. {
  1126. lua_pushstring(state, "Invalid number of parameters (expected 4).");
  1127. lua_error(state);
  1128. break;
  1129. }
  1130. }
  1131. return 0;
  1132. }
  1133. int lua_Mesh_static_createQuadFullscreen(lua_State* state)
  1134. {
  1135. // Get the number of parameters.
  1136. int paramCount = lua_gettop(state);
  1137. // Attempt to match the parameters to a valid binding.
  1138. switch (paramCount)
  1139. {
  1140. case 0:
  1141. {
  1142. void* returnPtr = (void*)Mesh::createQuadFullscreen();
  1143. if (returnPtr)
  1144. {
  1145. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  1146. object->instance = returnPtr;
  1147. object->owns = false;
  1148. luaL_getmetatable(state, "Mesh");
  1149. lua_setmetatable(state, -2);
  1150. }
  1151. else
  1152. {
  1153. lua_pushnil(state);
  1154. }
  1155. return 1;
  1156. break;
  1157. }
  1158. default:
  1159. {
  1160. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  1161. lua_error(state);
  1162. break;
  1163. }
  1164. }
  1165. return 0;
  1166. }
  1167. }