lua_Model.cpp 29 KB

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