lua_MeshSkin.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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. 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*)((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. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(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. else
  72. {
  73. lua_pushstring(state, "lua_MeshSkin_getBindShape - Failed to match the given parameters to a valid function signature.");
  74. lua_error(state);
  75. }
  76. break;
  77. }
  78. default:
  79. {
  80. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  81. lua_error(state);
  82. break;
  83. }
  84. }
  85. return 0;
  86. }
  87. int lua_MeshSkin_getJoint(lua_State* state)
  88. {
  89. // Get the number of parameters.
  90. int paramCount = lua_gettop(state);
  91. // Attempt to match the parameters to a valid binding.
  92. switch (paramCount)
  93. {
  94. case 2:
  95. {
  96. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  97. lua_type(state, 2) == LUA_TNUMBER)
  98. {
  99. // Get parameter 1 off the stack.
  100. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  101. MeshSkin* instance = getInstance(state);
  102. void* returnPtr = (void*)instance->getJoint(param1);
  103. if (returnPtr)
  104. {
  105. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  106. object->instance = returnPtr;
  107. object->owns = false;
  108. luaL_getmetatable(state, "Joint");
  109. lua_setmetatable(state, -2);
  110. }
  111. else
  112. {
  113. lua_pushnil(state);
  114. }
  115. return 1;
  116. }
  117. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  118. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  119. {
  120. // Get parameter 1 off the stack.
  121. const char* param1 = ScriptUtil::getString(2, false);
  122. MeshSkin* instance = getInstance(state);
  123. void* returnPtr = (void*)instance->getJoint(param1);
  124. if (returnPtr)
  125. {
  126. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  127. object->instance = returnPtr;
  128. object->owns = false;
  129. luaL_getmetatable(state, "Joint");
  130. lua_setmetatable(state, -2);
  131. }
  132. else
  133. {
  134. lua_pushnil(state);
  135. }
  136. return 1;
  137. }
  138. else
  139. {
  140. lua_pushstring(state, "lua_MeshSkin_getJoint - Failed to match the given parameters to a valid function signature.");
  141. lua_error(state);
  142. }
  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. else
  172. {
  173. lua_pushstring(state, "lua_MeshSkin_getJointCount - 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 1).");
  181. lua_error(state);
  182. break;
  183. }
  184. }
  185. return 0;
  186. }
  187. int lua_MeshSkin_getJointIndex(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 2:
  195. {
  196. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  197. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  198. {
  199. // Get parameter 1 off the stack.
  200. Joint* param1 = ScriptUtil::getObjectPointer<Joint>(2, "Joint", false);
  201. MeshSkin* instance = getInstance(state);
  202. int result = instance->getJointIndex(param1);
  203. // Push the return value onto the stack.
  204. lua_pushinteger(state, result);
  205. return 1;
  206. }
  207. else
  208. {
  209. lua_pushstring(state, "lua_MeshSkin_getJointIndex - Failed to match the given parameters to a valid function signature.");
  210. lua_error(state);
  211. }
  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. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(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. else
  251. {
  252. lua_pushstring(state, "lua_MeshSkin_getMatrixPalette - Failed to match the given parameters to a valid function signature.");
  253. lua_error(state);
  254. }
  255. break;
  256. }
  257. default:
  258. {
  259. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  260. lua_error(state);
  261. break;
  262. }
  263. }
  264. return 0;
  265. }
  266. int lua_MeshSkin_getMatrixPaletteSize(lua_State* state)
  267. {
  268. // Get the number of parameters.
  269. int paramCount = lua_gettop(state);
  270. // Attempt to match the parameters to a valid binding.
  271. switch (paramCount)
  272. {
  273. case 1:
  274. {
  275. if ((lua_type(state, 1) == LUA_TUSERDATA))
  276. {
  277. MeshSkin* instance = getInstance(state);
  278. unsigned int result = instance->getMatrixPaletteSize();
  279. // Push the return value onto the stack.
  280. lua_pushunsigned(state, result);
  281. return 1;
  282. }
  283. else
  284. {
  285. lua_pushstring(state, "lua_MeshSkin_getMatrixPaletteSize - Failed to match the given parameters to a valid function signature.");
  286. lua_error(state);
  287. }
  288. break;
  289. }
  290. default:
  291. {
  292. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  293. lua_error(state);
  294. break;
  295. }
  296. }
  297. return 0;
  298. }
  299. int lua_MeshSkin_getModel(lua_State* state)
  300. {
  301. // Get the number of parameters.
  302. int paramCount = lua_gettop(state);
  303. // Attempt to match the parameters to a valid binding.
  304. switch (paramCount)
  305. {
  306. case 1:
  307. {
  308. if ((lua_type(state, 1) == LUA_TUSERDATA))
  309. {
  310. MeshSkin* instance = getInstance(state);
  311. void* returnPtr = (void*)instance->getModel();
  312. if (returnPtr)
  313. {
  314. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  315. object->instance = returnPtr;
  316. object->owns = false;
  317. luaL_getmetatable(state, "Model");
  318. lua_setmetatable(state, -2);
  319. }
  320. else
  321. {
  322. lua_pushnil(state);
  323. }
  324. return 1;
  325. }
  326. else
  327. {
  328. lua_pushstring(state, "lua_MeshSkin_getModel - Failed to match the given parameters to a valid function signature.");
  329. lua_error(state);
  330. }
  331. break;
  332. }
  333. default:
  334. {
  335. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  336. lua_error(state);
  337. break;
  338. }
  339. }
  340. return 0;
  341. }
  342. int lua_MeshSkin_getRootJoint(lua_State* state)
  343. {
  344. // Get the number of parameters.
  345. int paramCount = lua_gettop(state);
  346. // Attempt to match the parameters to a valid binding.
  347. switch (paramCount)
  348. {
  349. case 1:
  350. {
  351. if ((lua_type(state, 1) == LUA_TUSERDATA))
  352. {
  353. MeshSkin* instance = getInstance(state);
  354. void* returnPtr = (void*)instance->getRootJoint();
  355. if (returnPtr)
  356. {
  357. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  358. object->instance = returnPtr;
  359. object->owns = false;
  360. luaL_getmetatable(state, "Joint");
  361. lua_setmetatable(state, -2);
  362. }
  363. else
  364. {
  365. lua_pushnil(state);
  366. }
  367. return 1;
  368. }
  369. else
  370. {
  371. lua_pushstring(state, "lua_MeshSkin_getRootJoint - Failed to match the given parameters to a valid function signature.");
  372. lua_error(state);
  373. }
  374. break;
  375. }
  376. default:
  377. {
  378. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  379. lua_error(state);
  380. break;
  381. }
  382. }
  383. return 0;
  384. }
  385. int lua_MeshSkin_setBindShape(lua_State* state)
  386. {
  387. // Get the number of parameters.
  388. int paramCount = lua_gettop(state);
  389. // Attempt to match the parameters to a valid binding.
  390. switch (paramCount)
  391. {
  392. case 2:
  393. {
  394. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  395. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
  396. {
  397. // Get parameter 1 off the stack.
  398. float* param1 = ScriptUtil::getFloatPointer(2);
  399. MeshSkin* instance = getInstance(state);
  400. instance->setBindShape(param1);
  401. return 0;
  402. }
  403. else
  404. {
  405. lua_pushstring(state, "lua_MeshSkin_setBindShape - Failed to match the given parameters to a valid function signature.");
  406. lua_error(state);
  407. }
  408. break;
  409. }
  410. default:
  411. {
  412. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  413. lua_error(state);
  414. break;
  415. }
  416. }
  417. return 0;
  418. }
  419. int lua_MeshSkin_setRootJoint(lua_State* state)
  420. {
  421. // Get the number of parameters.
  422. int paramCount = lua_gettop(state);
  423. // Attempt to match the parameters to a valid binding.
  424. switch (paramCount)
  425. {
  426. case 2:
  427. {
  428. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  429. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  430. {
  431. // Get parameter 1 off the stack.
  432. Joint* param1 = ScriptUtil::getObjectPointer<Joint>(2, "Joint", false);
  433. MeshSkin* instance = getInstance(state);
  434. instance->setRootJoint(param1);
  435. return 0;
  436. }
  437. else
  438. {
  439. lua_pushstring(state, "lua_MeshSkin_setRootJoint - Failed to match the given parameters to a valid function signature.");
  440. lua_error(state);
  441. }
  442. break;
  443. }
  444. default:
  445. {
  446. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  447. lua_error(state);
  448. break;
  449. }
  450. }
  451. return 0;
  452. }
  453. int lua_MeshSkin_transformChanged(lua_State* state)
  454. {
  455. // Get the number of parameters.
  456. int paramCount = lua_gettop(state);
  457. // Attempt to match the parameters to a valid binding.
  458. switch (paramCount)
  459. {
  460. case 3:
  461. {
  462. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  463. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  464. lua_type(state, 3) == LUA_TNUMBER)
  465. {
  466. // Get parameter 1 off the stack.
  467. Transform* param1 = ScriptUtil::getObjectPointer<Transform>(2, "Transform", false);
  468. // Get parameter 2 off the stack.
  469. long param2 = (long)luaL_checklong(state, 3);
  470. MeshSkin* instance = getInstance(state);
  471. instance->transformChanged(param1, param2);
  472. return 0;
  473. }
  474. else
  475. {
  476. lua_pushstring(state, "lua_MeshSkin_transformChanged - Failed to match the given parameters to a valid function signature.");
  477. lua_error(state);
  478. }
  479. break;
  480. }
  481. default:
  482. {
  483. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  484. lua_error(state);
  485. break;
  486. }
  487. }
  488. return 0;
  489. }
  490. }