Node.pkg 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. $#include "File.h"
  2. $#include "LuaFile.h"
  3. $#include "LuaScriptInstance.h"
  4. $#include "Node.h"
  5. $#include "ResourceCache.h"
  6. enum CreateMode
  7. {
  8. REPLICATED = 0,
  9. LOCAL = 1
  10. };
  11. enum TransformSpace
  12. {
  13. TS_LOCAL = 0,
  14. TS_PARENT,
  15. TS_WORLD
  16. };
  17. class Node : public Animatable
  18. {
  19. Node();
  20. virtual ~Node();
  21. tolua_outside bool NodeSaveXML @ SaveXML(File* dest) const;
  22. void SetName(const String name);
  23. void SetPosition(const Vector3& position);
  24. tolua_outside void NodeSetPositionXYZ @ SetPositionXYZ(float x, float y, float z);
  25. void SetRotation(const Quaternion& rotation);
  26. tolua_outside void NodeSetRotationXYZ @ SetRotationXYZ(float x, float y, float z);
  27. void SetDirection(const Vector3& direction);
  28. tolua_outside void NodeSetDirectionXYZ @ SetDirectionXYZ(float x, float y, float z);
  29. void SetScale(float scale);
  30. void SetScale(const Vector3& scale);
  31. tolua_outside void NodeSetScaleXYZ @ SetScaleXYZ(float x, float y, float z);
  32. void SetTransform(const Vector3& position, const Quaternion& rotation);
  33. void SetTransform(const Vector3& position, const Quaternion& rotation, float scale);
  34. void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  35. void SetWorldPosition(const Vector3& position);
  36. tolua_outside void NodeSetWorldPositionXYZ @ SetWorldPositionXYZ(float x, float y, float z);
  37. void SetWorldRotation(const Quaternion& rotation);
  38. tolua_outside void NodeSetWorldRotationXYZ @ SetWorldRotationXYZ(float x, float y, float z);
  39. void SetWorldDirection(const Vector3& direction);
  40. tolua_outside void NodeSetWorldDirectionXYZ @ SetWorldDirectionXYZ(float x, float y, float z);
  41. void SetWorldScale(float scale);
  42. void SetWorldScale(const Vector3& scale);
  43. tolua_outside void NodeSetWorldScaleXYZ @ SetWorldScaleXYZ(float x, float y, float z);
  44. void SetWorldTransform(const Vector3& position, const Quaternion& rotation);
  45. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale);
  46. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  47. void Translate(const Vector3& delta, TransformSpace space = TS_LOCAL);
  48. tolua_outside void NodeTranslateXYZ @ TranslateXYZ(float x, float y, float z, TransformSpace space = TS_LOCAL);
  49. void Rotate(const Quaternion& delta, TransformSpace space = TS_LOCAL);
  50. tolua_outside void NodeRotateXYZ @ RotateXYZ(float x, float y, float z, TransformSpace space = TS_LOCAL);
  51. void RotateAround(const Vector3& point, const Quaternion& delta, TransformSpace space = TS_LOCAL);
  52. tolua_outside void NodeRotateAroundXYZ @ RotateAroundXYZ(float pX, float pY, float pZ, float dX, float dY, float dZ, TransformSpace space = TS_LOCAL);
  53. void Pitch(float angle, TransformSpace space = TS_LOCAL);
  54. void Yaw(float angle, TransformSpace space = TS_LOCAL);
  55. void Roll(float angle, TransformSpace space = TS_LOCAL);
  56. bool LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP, TransformSpace space = TS_WORLD);
  57. tolua_outside bool NodeLookAtXYZ @ LookAtXYZ(float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f, TransformSpace space = TS_WORLD);
  58. void Scale(float scale);
  59. void Scale(const Vector3& scale);
  60. tolua_outside void NodeScaleXYZ @ ScaleXYZ(float x, float y, float z);
  61. void SetEnabled(bool enable);
  62. void SetEnabled(bool enable, bool recursive);
  63. void SetOwner(Connection* owner);
  64. void MarkDirty();
  65. Node* CreateChild(const String name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
  66. void AddChild(Node* node, unsigned index = M_MAX_UNSIGNED);
  67. void RemoveChild(Node* node);
  68. void RemoveAllChildren();
  69. void RemoveChildren(bool removeReplicated, bool removeLocal, bool recursive);
  70. void RemoveComponent(Component* component);
  71. void RemoveComponent(ShortStringHash type);
  72. void RemoveComponent(const String type);
  73. void RemoveAllComponents();
  74. void RemoveComponents(bool removeReplicated, bool removeLocal);
  75. Node* Clone(CreateMode mode = REPLICATED);
  76. void Remove();
  77. void SetParent(Node* parent);
  78. void SetVar(ShortStringHash key, const Variant& value);
  79. void AddListener(Component* component);
  80. void RemoveListener(Component* component);
  81. // template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
  82. Component* CreateComponent(const String type, CreateMode mode = REPLICATED, unsigned id = 0);
  83. int CreateScriptObject(const String scriptObjectType);
  84. int CreateScriptObject(const String fileName, const String scriptObjectType);
  85. int GetScriptObject() const;
  86. int GetScriptObject(const String scriptObjectType) const;
  87. unsigned GetID() const;
  88. const String GetName() const;
  89. StringHash GetNameHash() const;
  90. Node* GetParent() const;
  91. Scene* GetScene() const;
  92. bool IsEnabled() const;
  93. Connection* GetOwner() const;
  94. const Vector3& GetPosition() const;
  95. tolua_outside void NodeGetPositionXYZ @ GetPositionXYZ(float* x = 0.0f, float* y = 0.0f, float* z = 0.0f) const;
  96. const Quaternion& GetRotation() const;
  97. tolua_outside void NodeGetRotationXYZ @ GetRotationXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  98. tolua_outside void NodeGetRotationWXYZ @ GetRotationWXYZ(float* *w = 0.0f, float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  99. Vector3 GetDirection() const;
  100. tolua_outside void NodeGetDirectionXYZ @ GetDirectionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  101. Vector3 GetUp() const;
  102. tolua_outside void NodeGetUpXYZ @ GetUpXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  103. Vector3 GetRight() const;
  104. tolua_outside void NodeGetRightXYZ @ GetRightXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  105. const Vector3& GetScale() const;
  106. tolua_outside void NodeGetScaleXYZ @ GetScaleXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  107. Matrix3x4 GetTransform() const;
  108. Vector3 GetWorldPosition() const;
  109. tolua_outside void NodeGetWorldPositionXYZ @ GetWorldPositionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  110. Quaternion GetWorldRotation() const;
  111. tolua_outside void NodeGetWorldRotationXYZ @ GetWorldRotationXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  112. tolua_outside void NodeGetWorldRotationWXYZ @ GetWorldRotationWXYZ(float* *w = 0.0f, float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  113. Vector3 GetWorldDirection() const;
  114. tolua_outside void NodeGetWorldDirectionXYZ @ GetWorldDirectionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  115. Vector3 GetWorldUp() const;
  116. tolua_outside void NodeGetWorldUpXYZ @ GetWorldUpXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  117. Vector3 GetWorldRight() const;
  118. tolua_outside void NodeGetWorldRightXYZ @ GetWorldRightXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  119. Vector3 GetWorldScale() const;
  120. tolua_outside void NodeGetWorldScaleXYZ @ GetWorldScaleXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  121. const Matrix3x4& GetWorldTransform() const;
  122. Vector3 LocalToWorld(const Vector3& position) const;
  123. Vector3 LocalToWorld(const Vector4& vector) const;
  124. Vector3 WorldToLocal(const Vector3& position) const;
  125. Vector3 WorldToLocal(const Vector4& vector) const;
  126. bool IsDirty() const;
  127. unsigned GetNumChildren(bool recursive = false) const;
  128. Node* GetChild(const String name, bool recursive = false) const;
  129. Node* GetChild(StringHash nameHash, bool recursive = false) const;
  130. Node* GetChild(unsigned index) const;
  131. unsigned GetNumComponents() const;
  132. unsigned GetNumNetworkComponents() const;
  133. bool HasComponent(ShortStringHash type) const;
  134. bool HasComponent(const String type) const;
  135. const Variant& GetVar(ShortStringHash key) const;
  136. const VariantMap& GetVars() const;
  137. // template <class T> T* GetComponent() const;
  138. Component* GetComponent(const String type) const;
  139. void SetID(unsigned id);
  140. void SetScene(Scene* scene);
  141. void ResetScene();
  142. bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  143. bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  144. Node* CreateChild(unsigned id, CreateMode mode);
  145. void AddComponent(Component* component, unsigned id, CreateMode mode);
  146. tolua_property__get_set unsigned ID;
  147. tolua_property__get_set String name;
  148. tolua_readonly tolua_property__get_set StringHash nameHash;
  149. tolua_property__get_set Node* parent;
  150. tolua_property__get_set Scene* scene;
  151. tolua_property__is_set bool enabled;
  152. tolua_property__get_set Connection* owner;
  153. tolua_property__get_set Vector3& position;
  154. tolua_property__get_set Quaternion& rotation;
  155. tolua_property__get_set Vector3 direction;
  156. tolua_readonly tolua_property__get_set Vector3 up;
  157. tolua_readonly tolua_property__get_set Vector3 right;
  158. tolua_property__get_set Vector3& scale;
  159. tolua_readonly tolua_property__get_set Matrix3x4 transform;
  160. tolua_property__get_set Vector3 worldPosition;
  161. tolua_property__get_set Quaternion worldRotation;
  162. tolua_property__get_set Vector3 worldDirection;
  163. tolua_readonly tolua_property__get_set Vector3 worldUp;
  164. tolua_readonly tolua_property__get_set Vector3 worldRight;
  165. tolua_property__get_set Vector3 worldScale;
  166. tolua_readonly tolua_property__get_set Matrix3x4& worldTransform;
  167. tolua_readonly tolua_property__is_set bool dirty;
  168. tolua_readonly tolua_property__get_set unsigned numComponents;
  169. tolua_readonly tolua_property__get_set unsigned numNetworkComponents;
  170. };
  171. ${
  172. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_new00
  173. static int tolua_SceneLuaAPI_Node_new00(lua_State* tolua_S)
  174. {
  175. return ToluaNewObject<Node>(tolua_S);
  176. }
  177. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_new00_local
  178. static int tolua_SceneLuaAPI_Node_new00_local(lua_State* tolua_S)
  179. {
  180. return ToluaNewObjectGC<Node>(tolua_S);
  181. }
  182. static bool NodeSaveXML(const Node* node, File* file)
  183. {
  184. return file ? node->SaveXML(*file) : false;
  185. }
  186. static void NodeSetPositionXYZ(Node* node, float x, float y, float z)
  187. {
  188. node->SetPosition(Vector3(x, y, z));
  189. }
  190. static void NodeSetRotationXYZ(Node* node, float x, float y, float z)
  191. {
  192. node->SetRotation(Quaternion(x, y, z));
  193. }
  194. static void NodeSetDirectionXYZ(Node* node, float x, float y, float z)
  195. {
  196. node->SetDirection(Vector3(x, y, z));
  197. }
  198. static void NodeSetScaleXYZ(Node* node, float x, float y, float z)
  199. {
  200. node->SetScale(Vector3(x, y, z));
  201. }
  202. static void NodeSetWorldPositionXYZ(Node* node, float x, float y, float z)
  203. {
  204. node->SetWorldPosition(Vector3(x, y, z));
  205. }
  206. static void NodeSetWorldRotationXYZ(Node* node, float x, float y, float z)
  207. {
  208. node->SetWorldRotation(Quaternion(x, y, z));
  209. }
  210. static void NodeSetWorldDirectionXYZ(Node* node, float x, float y, float z)
  211. {
  212. node->SetWorldDirection(Vector3(x, y, z));
  213. }
  214. static void NodeSetWorldScaleXYZ(Node* node, float x, float y, float z)
  215. {
  216. node->SetWorldScale(Vector3(x, y, z));
  217. }
  218. static void NodeTranslateXYZ(Node* node, float x, float y, float z, TransformSpace space = TS_LOCAL)
  219. {
  220. node->Translate(Vector3(x, y, z), space);
  221. }
  222. static void NodeRotateXYZ(Node* node, float x, float y, float z, TransformSpace space = TS_LOCAL)
  223. {
  224. node->Rotate(Quaternion(x, y, z), space);
  225. }
  226. static void NodeRotateAroundXYZ(Node* node, float pX, float pY, float pZ, float rX, float rY, float rZ, TransformSpace space = TS_LOCAL)
  227. {
  228. node->RotateAround(Vector3(pX, pY, pZ), Quaternion(rX, rY, rZ), space);
  229. }
  230. static bool NodeLookAtXYZ(Node* node, float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f, TransformSpace space = TS_WORLD)
  231. {
  232. return node->LookAt(Vector3(x, y, z), Vector3(upX, upY, upZ), space);
  233. }
  234. static void NodeScaleXYZ(Node* node, float x, float y, float z)
  235. {
  236. node->Scale(Vector3(x, y, z));
  237. }
  238. static void NodeGetPositionXYZ(const Node* node, float* x, float* y, float* z)
  239. {
  240. const Vector3& position = node->GetPosition();
  241. *x = position.x_;
  242. *y = position.y_;
  243. *z = position.z_;
  244. }
  245. static void NodeGetRotationXYZ(const Node* node, float* x, float* y, float* z)
  246. {
  247. const Quaternion& rotation = node->GetRotation();
  248. *x = rotation.x_;
  249. *y = rotation.y_;
  250. *z = rotation.z_;
  251. }
  252. static void NodeGetRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z)
  253. {
  254. const Quaternion& rotation = node->GetRotation();
  255. *w = rotation.w_;
  256. *x = rotation.x_;
  257. *y = rotation.y_;
  258. *z = rotation.z_;
  259. }
  260. static void NodeGetDirectionXYZ(const Node* node, float* x, float* y, float* z)
  261. {
  262. const Vector3& direction = node->GetDirection();
  263. *x = direction.x_;
  264. *y = direction.y_;
  265. *z = direction.z_;
  266. }
  267. static void NodeGetUpXYZ(const Node* node, float* x, float* y, float* z)
  268. {
  269. const Vector3& up = node->GetUp();
  270. *x = up.x_;
  271. *y = up.y_;
  272. *z = up.z_;
  273. }
  274. static void NodeGetRightXYZ(const Node* node, float* x, float* y, float* z)
  275. {
  276. const Vector3& right = node->GetRight();
  277. *x = right.x_;
  278. *y = right.y_;
  279. *z = right.z_;
  280. }
  281. static void NodeGetScaleXYZ(const Node* node, float* x, float* y, float* z)
  282. {
  283. const Vector3& scale = node->GetScale();
  284. *x = scale.x_;
  285. *y = scale.y_;
  286. *z = scale.z_;
  287. }
  288. static void NodeGetWorldPositionXYZ(const Node* node, float* x, float* y, float* z)
  289. {
  290. Vector3 worldPosition = node->GetWorldPosition();
  291. *x = worldPosition.x_;
  292. *y = worldPosition.y_;
  293. *z = worldPosition.z_;
  294. }
  295. static void NodeGetWorldRotationXYZ(const Node* node, float* x, float* y, float* z)
  296. {
  297. Quaternion worldRotation = node->GetWorldRotation();
  298. *x = worldRotation.x_;
  299. *y = worldRotation.y_;
  300. *z = worldRotation.z_;
  301. }
  302. static void NodeGetWorldRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z)
  303. {
  304. Quaternion worldRotation = node->GetWorldRotation();
  305. *w = worldRotation.w_;
  306. *x = worldRotation.x_;
  307. *y = worldRotation.y_;
  308. *z = worldRotation.z_;
  309. }
  310. static void NodeGetWorldDirectionXYZ(const Node* node, float* x, float* y, float* z)
  311. {
  312. Vector3 worldDirection = node->GetWorldDirection();
  313. *x = worldDirection.x_;
  314. *y = worldDirection.y_;
  315. *z = worldDirection.z_;
  316. }
  317. static void NodeGetWorldUpXYZ(const Node* node, float* x, float* y, float* z)
  318. {
  319. Vector3 worldUp = node->GetWorldUp();
  320. *x = worldUp.x_;
  321. *y = worldUp.y_;
  322. *z = worldUp.z_;
  323. }
  324. static void NodeGetWorldRightXYZ(const Node* node, float* x, float* y, float* z)
  325. {
  326. Vector3 worldRight = node->GetWorldRight();
  327. *x = worldRight.x_;
  328. *y = worldRight.y_;
  329. *z = worldRight.z_;
  330. }
  331. static void NodeGetWorldScaleXYZ(const Node* node, float* x, float* y, float* z)
  332. {
  333. Vector3 worldScale = node->GetWorldScale();
  334. *x = worldScale.x_;
  335. *y = worldScale.y_;
  336. *z = worldScale.z_;
  337. }
  338. // Disable generated CreateComponent function.
  339. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateComponent00
  340. static int tolua_SceneLuaAPI_Node_CreateComponent00(lua_State* tolua_S)
  341. {
  342. #ifndef TOLUA_RELEASE
  343. tolua_Error tolua_err;
  344. if (
  345. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  346. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  347. !tolua_isnumber(tolua_S,3,1,&tolua_err) ||
  348. !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
  349. !tolua_isnoobj(tolua_S,5,&tolua_err)
  350. )
  351. goto tolua_lerror;
  352. else
  353. #endif
  354. {
  355. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  356. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  357. CreateMode mode = ((CreateMode) (int) tolua_tonumber(tolua_S,3,REPLICATED));
  358. unsigned id = ((unsigned) tolua_tonumber(tolua_S,4,0));
  359. #ifndef TOLUA_RELEASE
  360. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateComponent'", NULL);
  361. #endif
  362. {
  363. Component* tolua_ret = (Component*) self->CreateComponent(type,mode,id);
  364. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  365. }
  366. }
  367. return 1;
  368. #ifndef TOLUA_RELEASE
  369. tolua_lerror:
  370. tolua_error(tolua_S,"#ferror in function 'CreateComponent'.",&tolua_err);
  371. return 0;
  372. #endif
  373. }
  374. // Disable generated GetComponent function.
  375. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetComponent00
  376. static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S)
  377. {
  378. #ifndef TOLUA_RELEASE
  379. tolua_Error tolua_err;
  380. if (
  381. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  382. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  383. !tolua_isnoobj(tolua_S,3,&tolua_err)
  384. )
  385. goto tolua_lerror;
  386. else
  387. #endif
  388. {
  389. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  390. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  391. #ifndef TOLUA_RELEASE
  392. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetComponent'", NULL);
  393. #endif
  394. {
  395. Component* tolua_ret = (Component*) self->GetComponent(type);
  396. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  397. }
  398. }
  399. return 1;
  400. #ifndef TOLUA_RELEASE
  401. tolua_lerror:
  402. tolua_error(tolua_S,"#ferror in function 'GetComponent'.",&tolua_err);
  403. return 0;
  404. #endif
  405. }
  406. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00
  407. static int tolua_SceneLuaAPI_Node_CreateScriptObject00(lua_State* tolua_S)
  408. {
  409. #ifndef TOLUA_RELEASE
  410. tolua_Error tolua_err;
  411. if (
  412. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  413. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  414. !tolua_isnoobj(tolua_S,3,&tolua_err)
  415. )
  416. goto tolua_lerror;
  417. else
  418. #endif
  419. {
  420. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  421. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  422. #ifndef TOLUA_RELEASE
  423. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
  424. #endif
  425. {
  426. LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
  427. if (!instance)
  428. lua_pushnil(tolua_S);
  429. else
  430. {
  431. instance->CreateObject(scriptObjectType);
  432. // Push script object to Lua stack.
  433. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  434. }
  435. }
  436. }
  437. return 1;
  438. #ifndef TOLUA_RELEASE
  439. tolua_lerror:
  440. tolua_error(tolua_S,"#ferror in function 'CreateScriptObject'.",&tolua_err);
  441. return 0;
  442. #endif
  443. }
  444. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject01
  445. static int tolua_SceneLuaAPI_Node_CreateScriptObject01(lua_State* tolua_S)
  446. {
  447. tolua_Error tolua_err;
  448. if (
  449. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  450. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  451. !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
  452. !tolua_isnoobj(tolua_S,4,&tolua_err)
  453. )
  454. goto tolua_lerror;
  455. else
  456. {
  457. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  458. const String fileName = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  459. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,3,0));
  460. #ifndef TOLUA_RELEASE
  461. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
  462. #endif
  463. {
  464. ResourceCache* cache = self->GetSubsystem<ResourceCache>();
  465. LuaFile* scriptFile = cache->GetResource<LuaFile>(fileName);
  466. if (!scriptFile)
  467. {
  468. lua_pushnil(tolua_S);
  469. return 1;
  470. }
  471. LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
  472. if (!instance)
  473. lua_pushnil(tolua_S);
  474. else
  475. {
  476. instance->CreateObject(scriptFile, scriptObjectType);
  477. // Push script object to Lua stack.
  478. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  479. }
  480. }
  481. }
  482. return 1;
  483. tolua_lerror:
  484. return tolua_SceneLuaAPI_Node_CreateScriptObject00(tolua_S);
  485. }
  486. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject00
  487. static int tolua_SceneLuaAPI_Node_GetScriptObject00(lua_State* tolua_S)
  488. {
  489. #ifndef TOLUA_RELEASE
  490. tolua_Error tolua_err;
  491. if (
  492. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  493. !tolua_isnoobj(tolua_S,2,&tolua_err)
  494. )
  495. goto tolua_lerror;
  496. else
  497. #endif
  498. {
  499. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  500. #ifndef TOLUA_RELEASE
  501. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
  502. #endif
  503. {
  504. LuaScriptInstance* instance = self->GetComponent<LuaScriptInstance>();
  505. if (!instance)
  506. lua_pushnil(tolua_S);
  507. else
  508. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  509. }
  510. }
  511. return 1;
  512. #ifndef TOLUA_RELEASE
  513. tolua_lerror:
  514. tolua_error(tolua_S,"#ferror in function 'GetScriptObject'.",&tolua_err);
  515. return 0;
  516. #endif
  517. }
  518. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject01
  519. static int tolua_SceneLuaAPI_Node_GetScriptObject01(lua_State* tolua_S)
  520. {
  521. tolua_Error tolua_err;
  522. if (
  523. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  524. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  525. !tolua_isnoobj(tolua_S,3,&tolua_err)
  526. )
  527. goto tolua_lerror;
  528. else
  529. {
  530. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  531. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  532. #ifndef TOLUA_RELEASE
  533. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
  534. #endif
  535. {
  536. int scriptObjectRef = LUA_REFNIL;
  537. PODVector<LuaScriptInstance*> instances;
  538. self->GetComponents<LuaScriptInstance>(instances, false);
  539. for (unsigned i = 0; i < instances.Size(); ++i)
  540. {
  541. if (instances[i]->GetScriptObjectType() == scriptObjectType)
  542. {
  543. scriptObjectRef = instances[i]->GetScriptObjectRef();
  544. break;
  545. }
  546. }
  547. if (scriptObjectRef == LUA_REFNIL)
  548. lua_pushnil(tolua_S);
  549. else
  550. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, scriptObjectRef);
  551. }
  552. }
  553. return 1;
  554. tolua_lerror:
  555. return tolua_SceneLuaAPI_Node_GetScriptObject00(tolua_S);
  556. }
  557. $}