lua_Model.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Model.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "MeshPart.h"
  7. #include "Model.h"
  8. #include "Node.h"
  9. #include "Pass.h"
  10. #include "Ref.h"
  11. #include "Scene.h"
  12. #include "Technique.h"
  13. namespace gameplay
  14. {
  15. void luaRegister_Model()
  16. {
  17. const luaL_Reg lua_members[] =
  18. {
  19. {"addRef", lua_Model_addRef},
  20. {"draw", lua_Model_draw},
  21. {"getMaterial", lua_Model_getMaterial},
  22. {"getMesh", lua_Model_getMesh},
  23. {"getMeshPartCount", lua_Model_getMeshPartCount},
  24. {"getNode", lua_Model_getNode},
  25. {"getRefCount", lua_Model_getRefCount},
  26. {"getSkin", lua_Model_getSkin},
  27. {"hasMaterial", lua_Model_hasMaterial},
  28. {"isShadowCaster", lua_Model_isShadowCaster},
  29. {"isShadowReceiver", lua_Model_isShadowReceiver},
  30. {"release", lua_Model_release},
  31. {"setMaterial", lua_Model_setMaterial},
  32. {"setNode", lua_Model_setNode},
  33. {"setShadowCaster", lua_Model_setShadowCaster},
  34. {"setShadowReceiver", lua_Model_setShadowReceiver},
  35. {NULL, NULL}
  36. };
  37. const luaL_Reg lua_statics[] =
  38. {
  39. {"create", lua_Model_static_create},
  40. {NULL, NULL}
  41. };
  42. std::vector<std::string> scopePath;
  43. gameplay::ScriptUtil::registerClass("Model", lua_members, NULL, lua_Model__gc, lua_statics, scopePath);
  44. }
  45. static Model* getInstance(lua_State* state)
  46. {
  47. void* userdata = luaL_checkudata(state, 1, "Model");
  48. luaL_argcheck(state, userdata != NULL, 1, "'Model' expected.");
  49. return (Model*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  50. }
  51. int lua_Model__gc(lua_State* state)
  52. {
  53. // Get the number of parameters.
  54. int paramCount = lua_gettop(state);
  55. // Attempt to match the parameters to a valid binding.
  56. switch (paramCount)
  57. {
  58. case 1:
  59. {
  60. if ((lua_type(state, 1) == LUA_TUSERDATA))
  61. {
  62. void* userdata = luaL_checkudata(state, 1, "Model");
  63. luaL_argcheck(state, userdata != NULL, 1, "'Model' expected.");
  64. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  65. if (object->owns)
  66. {
  67. Model* instance = (Model*)object->instance;
  68. SAFE_RELEASE(instance);
  69. }
  70. return 0;
  71. }
  72. lua_pushstring(state, "lua_Model__gc - Failed to match the given parameters to a valid function signature.");
  73. lua_error(state);
  74. break;
  75. }
  76. default:
  77. {
  78. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  79. lua_error(state);
  80. break;
  81. }
  82. }
  83. return 0;
  84. }
  85. int lua_Model_addRef(lua_State* state)
  86. {
  87. // Get the number of parameters.
  88. int paramCount = lua_gettop(state);
  89. // Attempt to match the parameters to a valid binding.
  90. switch (paramCount)
  91. {
  92. case 1:
  93. {
  94. if ((lua_type(state, 1) == LUA_TUSERDATA))
  95. {
  96. Model* instance = getInstance(state);
  97. instance->addRef();
  98. return 0;
  99. }
  100. lua_pushstring(state, "lua_Model_addRef - Failed to match the given parameters to a valid function signature.");
  101. lua_error(state);
  102. break;
  103. }
  104. default:
  105. {
  106. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  107. lua_error(state);
  108. break;
  109. }
  110. }
  111. return 0;
  112. }
  113. int lua_Model_draw(lua_State* state)
  114. {
  115. // Get the number of parameters.
  116. int paramCount = lua_gettop(state);
  117. // Attempt to match the parameters to a valid binding.
  118. switch (paramCount)
  119. {
  120. case 1:
  121. {
  122. if ((lua_type(state, 1) == LUA_TUSERDATA))
  123. {
  124. Model* instance = getInstance(state);
  125. unsigned int result = instance->draw();
  126. // Push the return value onto the stack.
  127. lua_pushunsigned(state, result);
  128. return 1;
  129. }
  130. lua_pushstring(state, "lua_Model_draw - Failed to match the given parameters to a valid function signature.");
  131. lua_error(state);
  132. break;
  133. }
  134. case 2:
  135. {
  136. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  137. lua_type(state, 2) == LUA_TBOOLEAN)
  138. {
  139. // Get parameter 1 off the stack.
  140. bool param1 = gameplay::ScriptUtil::luaCheckBool(state, 2);
  141. Model* instance = getInstance(state);
  142. unsigned int result = instance->draw(param1);
  143. // Push the return value onto the stack.
  144. lua_pushunsigned(state, result);
  145. return 1;
  146. }
  147. lua_pushstring(state, "lua_Model_draw - Failed to match the given parameters to a valid function signature.");
  148. lua_error(state);
  149. break;
  150. }
  151. default:
  152. {
  153. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  154. lua_error(state);
  155. break;
  156. }
  157. }
  158. return 0;
  159. }
  160. int lua_Model_getMaterial(lua_State* state)
  161. {
  162. // Get the number of parameters.
  163. int paramCount = lua_gettop(state);
  164. // Attempt to match the parameters to a valid binding.
  165. switch (paramCount)
  166. {
  167. case 1:
  168. {
  169. if ((lua_type(state, 1) == LUA_TUSERDATA))
  170. {
  171. Model* instance = getInstance(state);
  172. void* returnPtr = (void*)instance->getMaterial();
  173. if (returnPtr)
  174. {
  175. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  176. object->instance = returnPtr;
  177. object->owns = false;
  178. luaL_getmetatable(state, "Material");
  179. lua_setmetatable(state, -2);
  180. }
  181. else
  182. {
  183. lua_pushnil(state);
  184. }
  185. return 1;
  186. }
  187. lua_pushstring(state, "lua_Model_getMaterial - Failed to match the given parameters to a valid function signature.");
  188. lua_error(state);
  189. break;
  190. }
  191. case 2:
  192. {
  193. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  194. lua_type(state, 2) == LUA_TNUMBER)
  195. {
  196. // Get parameter 1 off the stack.
  197. int param1 = (int)luaL_checkint(state, 2);
  198. Model* instance = getInstance(state);
  199. void* returnPtr = (void*)instance->getMaterial(param1);
  200. if (returnPtr)
  201. {
  202. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  203. object->instance = returnPtr;
  204. object->owns = false;
  205. luaL_getmetatable(state, "Material");
  206. lua_setmetatable(state, -2);
  207. }
  208. else
  209. {
  210. lua_pushnil(state);
  211. }
  212. return 1;
  213. }
  214. lua_pushstring(state, "lua_Model_getMaterial - Failed to match the given parameters to a valid function signature.");
  215. lua_error(state);
  216. break;
  217. }
  218. default:
  219. {
  220. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  221. lua_error(state);
  222. break;
  223. }
  224. }
  225. return 0;
  226. }
  227. int lua_Model_getMesh(lua_State* state)
  228. {
  229. // Get the number of parameters.
  230. int paramCount = lua_gettop(state);
  231. // Attempt to match the parameters to a valid binding.
  232. switch (paramCount)
  233. {
  234. case 1:
  235. {
  236. if ((lua_type(state, 1) == LUA_TUSERDATA))
  237. {
  238. Model* instance = getInstance(state);
  239. void* returnPtr = (void*)instance->getMesh();
  240. if (returnPtr)
  241. {
  242. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  243. object->instance = returnPtr;
  244. object->owns = false;
  245. luaL_getmetatable(state, "Mesh");
  246. lua_setmetatable(state, -2);
  247. }
  248. else
  249. {
  250. lua_pushnil(state);
  251. }
  252. return 1;
  253. }
  254. lua_pushstring(state, "lua_Model_getMesh - Failed to match the given parameters to a valid function signature.");
  255. lua_error(state);
  256. break;
  257. }
  258. default:
  259. {
  260. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  261. lua_error(state);
  262. break;
  263. }
  264. }
  265. return 0;
  266. }
  267. int lua_Model_getMeshPartCount(lua_State* state)
  268. {
  269. // Get the number of parameters.
  270. int paramCount = lua_gettop(state);
  271. // Attempt to match the parameters to a valid binding.
  272. switch (paramCount)
  273. {
  274. case 1:
  275. {
  276. if ((lua_type(state, 1) == LUA_TUSERDATA))
  277. {
  278. Model* instance = getInstance(state);
  279. unsigned int result = instance->getMeshPartCount();
  280. // Push the return value onto the stack.
  281. lua_pushunsigned(state, result);
  282. return 1;
  283. }
  284. lua_pushstring(state, "lua_Model_getMeshPartCount - Failed to match the given parameters to a valid function signature.");
  285. lua_error(state);
  286. break;
  287. }
  288. default:
  289. {
  290. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  291. lua_error(state);
  292. break;
  293. }
  294. }
  295. return 0;
  296. }
  297. int lua_Model_getNode(lua_State* state)
  298. {
  299. // Get the number of parameters.
  300. int paramCount = lua_gettop(state);
  301. // Attempt to match the parameters to a valid binding.
  302. switch (paramCount)
  303. {
  304. case 1:
  305. {
  306. if ((lua_type(state, 1) == LUA_TUSERDATA))
  307. {
  308. Model* instance = getInstance(state);
  309. void* returnPtr = (void*)instance->getNode();
  310. if (returnPtr)
  311. {
  312. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  313. object->instance = returnPtr;
  314. object->owns = false;
  315. luaL_getmetatable(state, "Node");
  316. lua_setmetatable(state, -2);
  317. }
  318. else
  319. {
  320. lua_pushnil(state);
  321. }
  322. return 1;
  323. }
  324. lua_pushstring(state, "lua_Model_getNode - Failed to match the given parameters to a valid function signature.");
  325. lua_error(state);
  326. break;
  327. }
  328. default:
  329. {
  330. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  331. lua_error(state);
  332. break;
  333. }
  334. }
  335. return 0;
  336. }
  337. int lua_Model_getRefCount(lua_State* state)
  338. {
  339. // Get the number of parameters.
  340. int paramCount = lua_gettop(state);
  341. // Attempt to match the parameters to a valid binding.
  342. switch (paramCount)
  343. {
  344. case 1:
  345. {
  346. if ((lua_type(state, 1) == LUA_TUSERDATA))
  347. {
  348. Model* instance = getInstance(state);
  349. unsigned int result = instance->getRefCount();
  350. // Push the return value onto the stack.
  351. lua_pushunsigned(state, result);
  352. return 1;
  353. }
  354. lua_pushstring(state, "lua_Model_getRefCount - Failed to match the given parameters to a valid function signature.");
  355. lua_error(state);
  356. break;
  357. }
  358. default:
  359. {
  360. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  361. lua_error(state);
  362. break;
  363. }
  364. }
  365. return 0;
  366. }
  367. int lua_Model_getSkin(lua_State* state)
  368. {
  369. // Get the number of parameters.
  370. int paramCount = lua_gettop(state);
  371. // Attempt to match the parameters to a valid binding.
  372. switch (paramCount)
  373. {
  374. case 1:
  375. {
  376. if ((lua_type(state, 1) == LUA_TUSERDATA))
  377. {
  378. Model* instance = getInstance(state);
  379. void* returnPtr = (void*)instance->getSkin();
  380. if (returnPtr)
  381. {
  382. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  383. object->instance = returnPtr;
  384. object->owns = false;
  385. luaL_getmetatable(state, "MeshSkin");
  386. lua_setmetatable(state, -2);
  387. }
  388. else
  389. {
  390. lua_pushnil(state);
  391. }
  392. return 1;
  393. }
  394. lua_pushstring(state, "lua_Model_getSkin - Failed to match the given parameters to a valid function signature.");
  395. lua_error(state);
  396. break;
  397. }
  398. default:
  399. {
  400. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  401. lua_error(state);
  402. break;
  403. }
  404. }
  405. return 0;
  406. }
  407. int lua_Model_hasMaterial(lua_State* state)
  408. {
  409. // Get the number of parameters.
  410. int paramCount = lua_gettop(state);
  411. // Attempt to match the parameters to a valid binding.
  412. switch (paramCount)
  413. {
  414. case 2:
  415. {
  416. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  417. lua_type(state, 2) == LUA_TNUMBER)
  418. {
  419. // Get parameter 1 off the stack.
  420. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  421. Model* instance = getInstance(state);
  422. bool result = instance->hasMaterial(param1);
  423. // Push the return value onto the stack.
  424. lua_pushboolean(state, result);
  425. return 1;
  426. }
  427. lua_pushstring(state, "lua_Model_hasMaterial - Failed to match the given parameters to a valid function signature.");
  428. lua_error(state);
  429. break;
  430. }
  431. default:
  432. {
  433. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  434. lua_error(state);
  435. break;
  436. }
  437. }
  438. return 0;
  439. }
  440. int lua_Model_isShadowCaster(lua_State* state)
  441. {
  442. // Get the number of parameters.
  443. int paramCount = lua_gettop(state);
  444. // Attempt to match the parameters to a valid binding.
  445. switch (paramCount)
  446. {
  447. case 1:
  448. {
  449. if ((lua_type(state, 1) == LUA_TUSERDATA))
  450. {
  451. Model* instance = getInstance(state);
  452. bool result = instance->isShadowCaster();
  453. // Push the return value onto the stack.
  454. lua_pushboolean(state, result);
  455. return 1;
  456. }
  457. lua_pushstring(state, "lua_Model_isShadowCaster - Failed to match the given parameters to a valid function signature.");
  458. lua_error(state);
  459. break;
  460. }
  461. default:
  462. {
  463. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  464. lua_error(state);
  465. break;
  466. }
  467. }
  468. return 0;
  469. }
  470. int lua_Model_isShadowReceiver(lua_State* state)
  471. {
  472. // Get the number of parameters.
  473. int paramCount = lua_gettop(state);
  474. // Attempt to match the parameters to a valid binding.
  475. switch (paramCount)
  476. {
  477. case 1:
  478. {
  479. if ((lua_type(state, 1) == LUA_TUSERDATA))
  480. {
  481. Model* instance = getInstance(state);
  482. bool result = instance->isShadowReceiver();
  483. // Push the return value onto the stack.
  484. lua_pushboolean(state, result);
  485. return 1;
  486. }
  487. lua_pushstring(state, "lua_Model_isShadowReceiver - Failed to match the given parameters to a valid function signature.");
  488. lua_error(state);
  489. break;
  490. }
  491. default:
  492. {
  493. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  494. lua_error(state);
  495. break;
  496. }
  497. }
  498. return 0;
  499. }
  500. int lua_Model_release(lua_State* state)
  501. {
  502. // Get the number of parameters.
  503. int paramCount = lua_gettop(state);
  504. // Attempt to match the parameters to a valid binding.
  505. switch (paramCount)
  506. {
  507. case 1:
  508. {
  509. if ((lua_type(state, 1) == LUA_TUSERDATA))
  510. {
  511. Model* instance = getInstance(state);
  512. instance->release();
  513. return 0;
  514. }
  515. lua_pushstring(state, "lua_Model_release - Failed to match the given parameters to a valid function signature.");
  516. lua_error(state);
  517. break;
  518. }
  519. default:
  520. {
  521. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  522. lua_error(state);
  523. break;
  524. }
  525. }
  526. return 0;
  527. }
  528. int lua_Model_setMaterial(lua_State* state)
  529. {
  530. // Get the number of parameters.
  531. int paramCount = lua_gettop(state);
  532. // Attempt to match the parameters to a valid binding.
  533. switch (paramCount)
  534. {
  535. case 2:
  536. {
  537. do
  538. {
  539. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  540. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  541. {
  542. // Get parameter 1 off the stack.
  543. bool param1Valid;
  544. gameplay::ScriptUtil::LuaArray<Material> param1 = gameplay::ScriptUtil::getObjectPointer<Material>(2, "Material", false, &param1Valid);
  545. if (!param1Valid)
  546. break;
  547. Model* instance = getInstance(state);
  548. instance->setMaterial(param1);
  549. return 0;
  550. }
  551. } while (0);
  552. do
  553. {
  554. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  555. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  556. {
  557. // Get parameter 1 off the stack.
  558. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  559. Model* instance = getInstance(state);
  560. void* returnPtr = (void*)instance->setMaterial(param1);
  561. if (returnPtr)
  562. {
  563. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  564. object->instance = returnPtr;
  565. object->owns = false;
  566. luaL_getmetatable(state, "Material");
  567. lua_setmetatable(state, -2);
  568. }
  569. else
  570. {
  571. lua_pushnil(state);
  572. }
  573. return 1;
  574. }
  575. } while (0);
  576. lua_pushstring(state, "lua_Model_setMaterial - Failed to match the given parameters to a valid function signature.");
  577. lua_error(state);
  578. break;
  579. }
  580. case 3:
  581. {
  582. do
  583. {
  584. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  585. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  586. lua_type(state, 3) == LUA_TNUMBER)
  587. {
  588. // Get parameter 1 off the stack.
  589. bool param1Valid;
  590. gameplay::ScriptUtil::LuaArray<Material> param1 = gameplay::ScriptUtil::getObjectPointer<Material>(2, "Material", false, &param1Valid);
  591. if (!param1Valid)
  592. break;
  593. // Get parameter 2 off the stack.
  594. int param2 = (int)luaL_checkint(state, 3);
  595. Model* instance = getInstance(state);
  596. instance->setMaterial(param1, param2);
  597. return 0;
  598. }
  599. } while (0);
  600. do
  601. {
  602. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  603. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  604. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  605. {
  606. // Get parameter 1 off the stack.
  607. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  608. // Get parameter 2 off the stack.
  609. const char* param2 = gameplay::ScriptUtil::getString(3, false);
  610. Model* instance = getInstance(state);
  611. void* returnPtr = (void*)instance->setMaterial(param1, param2);
  612. if (returnPtr)
  613. {
  614. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  615. object->instance = returnPtr;
  616. object->owns = false;
  617. luaL_getmetatable(state, "Material");
  618. lua_setmetatable(state, -2);
  619. }
  620. else
  621. {
  622. lua_pushnil(state);
  623. }
  624. return 1;
  625. }
  626. } while (0);
  627. do
  628. {
  629. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  630. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  631. lua_type(state, 3) == LUA_TNUMBER)
  632. {
  633. // Get parameter 1 off the stack.
  634. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  635. // Get parameter 2 off the stack.
  636. int param2 = (int)luaL_checkint(state, 3);
  637. Model* instance = getInstance(state);
  638. void* returnPtr = (void*)instance->setMaterial(param1, param2);
  639. if (returnPtr)
  640. {
  641. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  642. object->instance = returnPtr;
  643. object->owns = false;
  644. luaL_getmetatable(state, "Material");
  645. lua_setmetatable(state, -2);
  646. }
  647. else
  648. {
  649. lua_pushnil(state);
  650. }
  651. return 1;
  652. }
  653. } while (0);
  654. lua_pushstring(state, "lua_Model_setMaterial - Failed to match the given parameters to a valid function signature.");
  655. lua_error(state);
  656. break;
  657. }
  658. case 4:
  659. {
  660. do
  661. {
  662. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  663. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  664. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  665. (lua_type(state, 4) == LUA_TSTRING || lua_type(state, 4) == LUA_TNIL))
  666. {
  667. // Get parameter 1 off the stack.
  668. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  669. // Get parameter 2 off the stack.
  670. const char* param2 = gameplay::ScriptUtil::getString(3, false);
  671. // Get parameter 3 off the stack.
  672. const char* param3 = gameplay::ScriptUtil::getString(4, false);
  673. Model* instance = getInstance(state);
  674. void* returnPtr = (void*)instance->setMaterial(param1, param2, param3);
  675. if (returnPtr)
  676. {
  677. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  678. object->instance = returnPtr;
  679. object->owns = false;
  680. luaL_getmetatable(state, "Material");
  681. lua_setmetatable(state, -2);
  682. }
  683. else
  684. {
  685. lua_pushnil(state);
  686. }
  687. return 1;
  688. }
  689. } while (0);
  690. lua_pushstring(state, "lua_Model_setMaterial - Failed to match the given parameters to a valid function signature.");
  691. lua_error(state);
  692. break;
  693. }
  694. case 5:
  695. {
  696. do
  697. {
  698. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  699. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  700. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  701. (lua_type(state, 4) == LUA_TSTRING || lua_type(state, 4) == LUA_TNIL) &&
  702. lua_type(state, 5) == LUA_TNUMBER)
  703. {
  704. // Get parameter 1 off the stack.
  705. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  706. // Get parameter 2 off the stack.
  707. const char* param2 = gameplay::ScriptUtil::getString(3, false);
  708. // Get parameter 3 off the stack.
  709. const char* param3 = gameplay::ScriptUtil::getString(4, false);
  710. // Get parameter 4 off the stack.
  711. int param4 = (int)luaL_checkint(state, 5);
  712. Model* instance = getInstance(state);
  713. void* returnPtr = (void*)instance->setMaterial(param1, param2, param3, param4);
  714. if (returnPtr)
  715. {
  716. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  717. object->instance = returnPtr;
  718. object->owns = false;
  719. luaL_getmetatable(state, "Material");
  720. lua_setmetatable(state, -2);
  721. }
  722. else
  723. {
  724. lua_pushnil(state);
  725. }
  726. return 1;
  727. }
  728. } while (0);
  729. lua_pushstring(state, "lua_Model_setMaterial - Failed to match the given parameters to a valid function signature.");
  730. lua_error(state);
  731. break;
  732. }
  733. default:
  734. {
  735. lua_pushstring(state, "Invalid number of parameters (expected 2, 3, 4 or 5).");
  736. lua_error(state);
  737. break;
  738. }
  739. }
  740. return 0;
  741. }
  742. int lua_Model_setNode(lua_State* state)
  743. {
  744. // Get the number of parameters.
  745. int paramCount = lua_gettop(state);
  746. // Attempt to match the parameters to a valid binding.
  747. switch (paramCount)
  748. {
  749. case 2:
  750. {
  751. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  752. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  753. {
  754. // Get parameter 1 off the stack.
  755. bool param1Valid;
  756. gameplay::ScriptUtil::LuaArray<Node> param1 = gameplay::ScriptUtil::getObjectPointer<Node>(2, "Node", false, &param1Valid);
  757. if (!param1Valid)
  758. {
  759. lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'.");
  760. lua_error(state);
  761. }
  762. Model* instance = getInstance(state);
  763. instance->setNode(param1);
  764. return 0;
  765. }
  766. lua_pushstring(state, "lua_Model_setNode - Failed to match the given parameters to a valid function signature.");
  767. lua_error(state);
  768. break;
  769. }
  770. default:
  771. {
  772. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  773. lua_error(state);
  774. break;
  775. }
  776. }
  777. return 0;
  778. }
  779. int lua_Model_setShadowCaster(lua_State* state)
  780. {
  781. // Get the number of parameters.
  782. int paramCount = lua_gettop(state);
  783. // Attempt to match the parameters to a valid binding.
  784. switch (paramCount)
  785. {
  786. case 2:
  787. {
  788. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  789. lua_type(state, 2) == LUA_TBOOLEAN)
  790. {
  791. // Get parameter 1 off the stack.
  792. bool param1 = gameplay::ScriptUtil::luaCheckBool(state, 2);
  793. Model* instance = getInstance(state);
  794. instance->setShadowCaster(param1);
  795. return 0;
  796. }
  797. lua_pushstring(state, "lua_Model_setShadowCaster - Failed to match the given parameters to a valid function signature.");
  798. lua_error(state);
  799. break;
  800. }
  801. default:
  802. {
  803. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  804. lua_error(state);
  805. break;
  806. }
  807. }
  808. return 0;
  809. }
  810. int lua_Model_setShadowReceiver(lua_State* state)
  811. {
  812. // Get the number of parameters.
  813. int paramCount = lua_gettop(state);
  814. // Attempt to match the parameters to a valid binding.
  815. switch (paramCount)
  816. {
  817. case 2:
  818. {
  819. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  820. lua_type(state, 2) == LUA_TBOOLEAN)
  821. {
  822. // Get parameter 1 off the stack.
  823. bool param1 = gameplay::ScriptUtil::luaCheckBool(state, 2);
  824. Model* instance = getInstance(state);
  825. instance->setShadowReceiver(param1);
  826. return 0;
  827. }
  828. lua_pushstring(state, "lua_Model_setShadowReceiver - Failed to match the given parameters to a valid function signature.");
  829. lua_error(state);
  830. break;
  831. }
  832. default:
  833. {
  834. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  835. lua_error(state);
  836. break;
  837. }
  838. }
  839. return 0;
  840. }
  841. int lua_Model_static_create(lua_State* state)
  842. {
  843. // Get the number of parameters.
  844. int paramCount = lua_gettop(state);
  845. // Attempt to match the parameters to a valid binding.
  846. switch (paramCount)
  847. {
  848. case 1:
  849. {
  850. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL))
  851. {
  852. // Get parameter 1 off the stack.
  853. bool param1Valid;
  854. gameplay::ScriptUtil::LuaArray<Mesh> param1 = gameplay::ScriptUtil::getObjectPointer<Mesh>(1, "Mesh", false, &param1Valid);
  855. if (!param1Valid)
  856. {
  857. lua_pushstring(state, "Failed to convert parameter 1 to type 'Mesh'.");
  858. lua_error(state);
  859. }
  860. void* returnPtr = (void*)Model::create(param1);
  861. if (returnPtr)
  862. {
  863. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  864. object->instance = returnPtr;
  865. object->owns = true;
  866. luaL_getmetatable(state, "Model");
  867. lua_setmetatable(state, -2);
  868. }
  869. else
  870. {
  871. lua_pushnil(state);
  872. }
  873. return 1;
  874. }
  875. lua_pushstring(state, "lua_Model_static_create - Failed to match the given parameters to a valid function signature.");
  876. lua_error(state);
  877. break;
  878. }
  879. default:
  880. {
  881. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  882. lua_error(state);
  883. break;
  884. }
  885. }
  886. return 0;
  887. }
  888. }