lua_Mesh.cpp 42 KB

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