lua_MeshSkin.cpp 17 KB

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