lua_MeshSkin.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_MeshSkin.h"
  4. #include "Animation.h"
  5. #include "AnimationTarget.h"
  6. #include "Base.h"
  7. #include "Game.h"
  8. #include "Joint.h"
  9. #include "MeshSkin.h"
  10. #include "Node.h"
  11. #include "ScriptController.h"
  12. #include "ScriptTarget.h"
  13. #include "Transform.h"
  14. #include "lua_CurveInterpolationType.h"
  15. namespace gameplay
  16. {
  17. void luaRegister_MeshSkin()
  18. {
  19. const luaL_Reg lua_members[] =
  20. {
  21. {"getBindShape", lua_MeshSkin_getBindShape},
  22. {"getJoint", lua_MeshSkin_getJoint},
  23. {"getJointCount", lua_MeshSkin_getJointCount},
  24. {"getJointIndex", lua_MeshSkin_getJointIndex},
  25. {"getMatrixPalette", lua_MeshSkin_getMatrixPalette},
  26. {"getMatrixPaletteSize", lua_MeshSkin_getMatrixPaletteSize},
  27. {"getModel", lua_MeshSkin_getModel},
  28. {"getRootJoint", lua_MeshSkin_getRootJoint},
  29. {"setBindShape", lua_MeshSkin_setBindShape},
  30. {"setRootJoint", lua_MeshSkin_setRootJoint},
  31. {"transformChanged", lua_MeshSkin_transformChanged},
  32. {NULL, NULL}
  33. };
  34. const luaL_Reg* lua_statics = NULL;
  35. std::vector<std::string> scopePath;
  36. gameplay::ScriptUtil::registerClass("MeshSkin", lua_members, NULL, NULL, lua_statics, scopePath);
  37. }
  38. static MeshSkin* getInstance(lua_State* state)
  39. {
  40. void* userdata = luaL_checkudata(state, 1, "MeshSkin");
  41. luaL_argcheck(state, userdata != NULL, 1, "'MeshSkin' expected.");
  42. return (MeshSkin*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  43. }
  44. int lua_MeshSkin_getBindShape(lua_State* state)
  45. {
  46. // Get the number of parameters.
  47. int paramCount = lua_gettop(state);
  48. // Attempt to match the parameters to a valid binding.
  49. switch (paramCount)
  50. {
  51. case 1:
  52. {
  53. if ((lua_type(state, 1) == LUA_TUSERDATA))
  54. {
  55. MeshSkin* instance = getInstance(state);
  56. void* returnPtr = (void*)&(instance->getBindShape());
  57. if (returnPtr)
  58. {
  59. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  60. object->instance = returnPtr;
  61. object->owns = false;
  62. luaL_getmetatable(state, "Matrix");
  63. lua_setmetatable(state, -2);
  64. }
  65. else
  66. {
  67. lua_pushnil(state);
  68. }
  69. return 1;
  70. }
  71. lua_pushstring(state, "lua_MeshSkin_getBindShape - Failed to match the given parameters to a valid function signature.");
  72. lua_error(state);
  73. break;
  74. }
  75. default:
  76. {
  77. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  78. lua_error(state);
  79. break;
  80. }
  81. }
  82. return 0;
  83. }
  84. int lua_MeshSkin_getJoint(lua_State* state)
  85. {
  86. // Get the number of parameters.
  87. int paramCount = lua_gettop(state);
  88. // Attempt to match the parameters to a valid binding.
  89. switch (paramCount)
  90. {
  91. case 2:
  92. {
  93. do
  94. {
  95. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  96. lua_type(state, 2) == LUA_TNUMBER)
  97. {
  98. // Get parameter 1 off the stack.
  99. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  100. MeshSkin* instance = getInstance(state);
  101. void* returnPtr = (void*)instance->getJoint(param1);
  102. if (returnPtr)
  103. {
  104. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  105. object->instance = returnPtr;
  106. object->owns = false;
  107. luaL_getmetatable(state, "Joint");
  108. lua_setmetatable(state, -2);
  109. }
  110. else
  111. {
  112. lua_pushnil(state);
  113. }
  114. return 1;
  115. }
  116. } while (0);
  117. do
  118. {
  119. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  120. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  121. {
  122. // Get parameter 1 off the stack.
  123. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  124. MeshSkin* instance = getInstance(state);
  125. void* returnPtr = (void*)instance->getJoint(param1);
  126. if (returnPtr)
  127. {
  128. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  129. object->instance = returnPtr;
  130. object->owns = false;
  131. luaL_getmetatable(state, "Joint");
  132. lua_setmetatable(state, -2);
  133. }
  134. else
  135. {
  136. lua_pushnil(state);
  137. }
  138. return 1;
  139. }
  140. } while (0);
  141. lua_pushstring(state, "lua_MeshSkin_getJoint - Failed to match the given parameters to a valid function signature.");
  142. lua_error(state);
  143. break;
  144. }
  145. default:
  146. {
  147. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  148. lua_error(state);
  149. break;
  150. }
  151. }
  152. return 0;
  153. }
  154. int lua_MeshSkin_getJointCount(lua_State* state)
  155. {
  156. // Get the number of parameters.
  157. int paramCount = lua_gettop(state);
  158. // Attempt to match the parameters to a valid binding.
  159. switch (paramCount)
  160. {
  161. case 1:
  162. {
  163. if ((lua_type(state, 1) == LUA_TUSERDATA))
  164. {
  165. MeshSkin* instance = getInstance(state);
  166. unsigned int result = instance->getJointCount();
  167. // Push the return value onto the stack.
  168. lua_pushunsigned(state, result);
  169. return 1;
  170. }
  171. lua_pushstring(state, "lua_MeshSkin_getJointCount - Failed to match the given parameters to a valid function signature.");
  172. lua_error(state);
  173. break;
  174. }
  175. default:
  176. {
  177. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  178. lua_error(state);
  179. break;
  180. }
  181. }
  182. return 0;
  183. }
  184. int lua_MeshSkin_getJointIndex(lua_State* state)
  185. {
  186. // Get the number of parameters.
  187. int paramCount = lua_gettop(state);
  188. // Attempt to match the parameters to a valid binding.
  189. switch (paramCount)
  190. {
  191. case 2:
  192. {
  193. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  194. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  195. {
  196. // Get parameter 1 off the stack.
  197. bool param1Valid;
  198. gameplay::ScriptUtil::LuaArray<Joint> param1 = gameplay::ScriptUtil::getObjectPointer<Joint>(2, "Joint", false, &param1Valid);
  199. if (!param1Valid)
  200. {
  201. lua_pushstring(state, "Failed to convert parameter 1 to type 'Joint'.");
  202. lua_error(state);
  203. }
  204. MeshSkin* instance = getInstance(state);
  205. int result = instance->getJointIndex(param1);
  206. // Push the return value onto the stack.
  207. lua_pushinteger(state, result);
  208. return 1;
  209. }
  210. lua_pushstring(state, "lua_MeshSkin_getJointIndex - Failed to match the given parameters to a valid function signature.");
  211. lua_error(state);
  212. break;
  213. }
  214. default:
  215. {
  216. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  217. lua_error(state);
  218. break;
  219. }
  220. }
  221. return 0;
  222. }
  223. int lua_MeshSkin_getMatrixPalette(lua_State* state)
  224. {
  225. // Get the number of parameters.
  226. int paramCount = lua_gettop(state);
  227. // Attempt to match the parameters to a valid binding.
  228. switch (paramCount)
  229. {
  230. case 1:
  231. {
  232. if ((lua_type(state, 1) == LUA_TUSERDATA))
  233. {
  234. MeshSkin* instance = getInstance(state);
  235. void* returnPtr = (void*)instance->getMatrixPalette();
  236. if (returnPtr)
  237. {
  238. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  239. object->instance = returnPtr;
  240. object->owns = false;
  241. luaL_getmetatable(state, "Vector4");
  242. lua_setmetatable(state, -2);
  243. }
  244. else
  245. {
  246. lua_pushnil(state);
  247. }
  248. return 1;
  249. }
  250. lua_pushstring(state, "lua_MeshSkin_getMatrixPalette - Failed to match the given parameters to a valid function signature.");
  251. lua_error(state);
  252. break;
  253. }
  254. default:
  255. {
  256. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  257. lua_error(state);
  258. break;
  259. }
  260. }
  261. return 0;
  262. }
  263. int lua_MeshSkin_getMatrixPaletteSize(lua_State* state)
  264. {
  265. // Get the number of parameters.
  266. int paramCount = lua_gettop(state);
  267. // Attempt to match the parameters to a valid binding.
  268. switch (paramCount)
  269. {
  270. case 1:
  271. {
  272. if ((lua_type(state, 1) == LUA_TUSERDATA))
  273. {
  274. MeshSkin* instance = getInstance(state);
  275. unsigned int result = instance->getMatrixPaletteSize();
  276. // Push the return value onto the stack.
  277. lua_pushunsigned(state, result);
  278. return 1;
  279. }
  280. lua_pushstring(state, "lua_MeshSkin_getMatrixPaletteSize - Failed to match the given parameters to a valid function signature.");
  281. lua_error(state);
  282. break;
  283. }
  284. default:
  285. {
  286. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  287. lua_error(state);
  288. break;
  289. }
  290. }
  291. return 0;
  292. }
  293. int lua_MeshSkin_getModel(lua_State* state)
  294. {
  295. // Get the number of parameters.
  296. int paramCount = lua_gettop(state);
  297. // Attempt to match the parameters to a valid binding.
  298. switch (paramCount)
  299. {
  300. case 1:
  301. {
  302. if ((lua_type(state, 1) == LUA_TUSERDATA))
  303. {
  304. MeshSkin* instance = getInstance(state);
  305. void* returnPtr = (void*)instance->getModel();
  306. if (returnPtr)
  307. {
  308. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  309. object->instance = returnPtr;
  310. object->owns = false;
  311. luaL_getmetatable(state, "Model");
  312. lua_setmetatable(state, -2);
  313. }
  314. else
  315. {
  316. lua_pushnil(state);
  317. }
  318. return 1;
  319. }
  320. lua_pushstring(state, "lua_MeshSkin_getModel - Failed to match the given parameters to a valid function signature.");
  321. lua_error(state);
  322. break;
  323. }
  324. default:
  325. {
  326. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  327. lua_error(state);
  328. break;
  329. }
  330. }
  331. return 0;
  332. }
  333. int lua_MeshSkin_getRootJoint(lua_State* state)
  334. {
  335. // Get the number of parameters.
  336. int paramCount = lua_gettop(state);
  337. // Attempt to match the parameters to a valid binding.
  338. switch (paramCount)
  339. {
  340. case 1:
  341. {
  342. if ((lua_type(state, 1) == LUA_TUSERDATA))
  343. {
  344. MeshSkin* instance = getInstance(state);
  345. void* returnPtr = (void*)instance->getRootJoint();
  346. if (returnPtr)
  347. {
  348. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  349. object->instance = returnPtr;
  350. object->owns = false;
  351. luaL_getmetatable(state, "Joint");
  352. lua_setmetatable(state, -2);
  353. }
  354. else
  355. {
  356. lua_pushnil(state);
  357. }
  358. return 1;
  359. }
  360. lua_pushstring(state, "lua_MeshSkin_getRootJoint - Failed to match the given parameters to a valid function signature.");
  361. lua_error(state);
  362. break;
  363. }
  364. default:
  365. {
  366. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  367. lua_error(state);
  368. break;
  369. }
  370. }
  371. return 0;
  372. }
  373. int lua_MeshSkin_setBindShape(lua_State* state)
  374. {
  375. // Get the number of parameters.
  376. int paramCount = lua_gettop(state);
  377. // Attempt to match the parameters to a valid binding.
  378. switch (paramCount)
  379. {
  380. case 2:
  381. {
  382. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  383. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
  384. {
  385. // Get parameter 1 off the stack.
  386. gameplay::ScriptUtil::LuaArray<float> param1 = gameplay::ScriptUtil::getFloatPointer(2);
  387. MeshSkin* instance = getInstance(state);
  388. instance->setBindShape(param1);
  389. return 0;
  390. }
  391. lua_pushstring(state, "lua_MeshSkin_setBindShape - Failed to match the given parameters to a valid function signature.");
  392. lua_error(state);
  393. break;
  394. }
  395. default:
  396. {
  397. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  398. lua_error(state);
  399. break;
  400. }
  401. }
  402. return 0;
  403. }
  404. int lua_MeshSkin_setRootJoint(lua_State* state)
  405. {
  406. // Get the number of parameters.
  407. int paramCount = lua_gettop(state);
  408. // Attempt to match the parameters to a valid binding.
  409. switch (paramCount)
  410. {
  411. case 2:
  412. {
  413. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  414. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  415. {
  416. // Get parameter 1 off the stack.
  417. bool param1Valid;
  418. gameplay::ScriptUtil::LuaArray<Joint> param1 = gameplay::ScriptUtil::getObjectPointer<Joint>(2, "Joint", false, &param1Valid);
  419. if (!param1Valid)
  420. {
  421. lua_pushstring(state, "Failed to convert parameter 1 to type 'Joint'.");
  422. lua_error(state);
  423. }
  424. MeshSkin* instance = getInstance(state);
  425. instance->setRootJoint(param1);
  426. return 0;
  427. }
  428. lua_pushstring(state, "lua_MeshSkin_setRootJoint - Failed to match the given parameters to a valid function signature.");
  429. lua_error(state);
  430. break;
  431. }
  432. default:
  433. {
  434. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  435. lua_error(state);
  436. break;
  437. }
  438. }
  439. return 0;
  440. }
  441. int lua_MeshSkin_transformChanged(lua_State* state)
  442. {
  443. // Get the number of parameters.
  444. int paramCount = lua_gettop(state);
  445. // Attempt to match the parameters to a valid binding.
  446. switch (paramCount)
  447. {
  448. case 3:
  449. {
  450. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  451. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  452. lua_type(state, 3) == LUA_TNUMBER)
  453. {
  454. // Get parameter 1 off the stack.
  455. bool param1Valid;
  456. gameplay::ScriptUtil::LuaArray<Transform> param1 = gameplay::ScriptUtil::getObjectPointer<Transform>(2, "Transform", false, &param1Valid);
  457. if (!param1Valid)
  458. {
  459. lua_pushstring(state, "Failed to convert parameter 1 to type 'Transform'.");
  460. lua_error(state);
  461. }
  462. // Get parameter 2 off the stack.
  463. long param2 = (long)luaL_checklong(state, 3);
  464. MeshSkin* instance = getInstance(state);
  465. instance->transformChanged(param1, param2);
  466. return 0;
  467. }
  468. lua_pushstring(state, "lua_MeshSkin_transformChanged - Failed to match the given parameters to a valid function signature.");
  469. lua_error(state);
  470. break;
  471. }
  472. default:
  473. {
  474. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  475. lua_error(state);
  476. break;
  477. }
  478. }
  479. return 0;
  480. }
  481. }