Node.pkg 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. $#include "Node.h"
  2. enum CreateMode
  3. {
  4. REPLICATED = 0,
  5. LOCAL = 1
  6. };
  7. class Node : public Serializable
  8. {
  9. Node(Context* context);
  10. virtual ~Node();
  11. bool SaveXML(Serializer& dest) const;
  12. void SetName(const String& name);
  13. void SetPosition(const Vector3& position);
  14. void SetRotation(const Quaternion& rotation);
  15. void SetDirection(const Vector3& direction);
  16. void SetScale(float scale);
  17. void SetScale(const Vector3& scale);
  18. void SetTransform(const Vector3& position, const Quaternion& rotation);
  19. void SetTransform(const Vector3& position, const Quaternion& rotation, float scale);
  20. void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  21. void SetWorldPosition(const Vector3& position);
  22. void SetWorldRotation(const Quaternion& rotation);
  23. void SetWorldDirection(const Vector3& direction);
  24. void SetWorldScale(float scale);
  25. void SetWorldScale(const Vector3& scale);
  26. void SetWorldTransform(const Vector3& position, const Quaternion& rotation);
  27. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale);
  28. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  29. void Translate(const Vector3& delta);
  30. void TranslateRelative(const Vector3& delta);
  31. void Rotate(const Quaternion& delta, bool fixedAxis = false);
  32. void Pitch(float angle, bool fixedAxis = false);
  33. void Yaw(float angle, bool fixedAxis = false);
  34. void Roll(float angle, bool fixedAxis = false);
  35. void LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP);
  36. void Scale(float scale);
  37. void Scale(const Vector3& scale);
  38. void SetEnabled(bool enable);
  39. void SetEnabled(bool enable, bool recursive);
  40. void SetOwner(Connection* owner);
  41. void MarkDirty();
  42. Node* CreateChild(const String& name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
  43. void AddChild(Node* node);
  44. void RemoveChild(Node* node);
  45. void RemoveAllChildren();
  46. void RemoveChildren(bool removeReplicated, bool removeLocal, bool recursive);
  47. void RemoveComponent(Component* component);
  48. void RemoveComponent(ShortStringHash type);
  49. void RemoveComponent(const char* type);
  50. void RemoveAllComponents();
  51. void RemoveComponents(bool removeReplicated, bool removeLocal);
  52. Node* Clone(CreateMode mode = REPLICATED);
  53. void Remove();
  54. void SetParent(Node* parent);
  55. void SetVar(ShortStringHash key, const Variant& value);
  56. void AddListener(Component* component);
  57. void RemoveListener(Component* component);
  58. // template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
  59. Component* CreateComponent(const char* type, CreateMode mode = REPLICATED, unsigned id = 0);
  60. unsigned GetID() const;
  61. const String& GetName() const;
  62. StringHash GetNameHash() const;
  63. Node* GetParent() const;
  64. Scene* GetScene() const;
  65. bool IsEnabled() const;
  66. Connection* GetOwner() const;
  67. const Vector3& GetPosition() const;
  68. const Quaternion& GetRotation() const;
  69. Vector3 GetDirection() const;
  70. const Vector3& GetScale() const;
  71. Matrix3x4 GetTransform() const;
  72. Vector3 GetWorldPosition() const;
  73. Quaternion GetWorldRotation() const;
  74. Vector3 GetWorldDirection() const;
  75. Vector3 GetWorldScale() const;
  76. const Matrix3x4& GetWorldTransform() const;
  77. Vector3 LocalToWorld(const Vector3& position) const;
  78. Vector3 LocalToWorld(const Vector4& vector) const;
  79. Vector3 WorldToLocal(const Vector3& position) const;
  80. Vector3 WorldToLocal(const Vector4& vector) const;
  81. bool IsDirty() const;
  82. unsigned GetNumChildren(bool recursive = false) const;
  83. Node* GetChild(unsigned index) const;
  84. Node* GetChild(const String& name, bool recursive = false) const;
  85. Node* GetChild(const char* name, bool recursive = false) const;
  86. Node* GetChild(StringHash nameHash, bool recursive = false) const;
  87. unsigned GetNumComponents() const;
  88. unsigned GetNumNetworkComponents() const;
  89. bool HasComponent(ShortStringHash type) const;
  90. bool HasComponent(const char* type) const;
  91. const Variant& GetVar(ShortStringHash key) const;
  92. const VariantMap& GetVars() const;
  93. // template <class T> T* GetComponent() const;
  94. Component* GetComponent(const char* type) const;
  95. void SetID(unsigned id);
  96. void SetScene(Scene* scene);
  97. void ResetScene();
  98. bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  99. bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  100. Node* CreateChild(unsigned id, CreateMode mode);
  101. void AddComponent(Component* component, unsigned id, CreateMode mode);
  102. tolua_property__get_set unsigned ID;
  103. tolua_property__get_set String& name;
  104. tolua_readonly tolua_property__get_set StringHash nameHash;
  105. tolua_property__get_set Node* parent;
  106. tolua_property__get_set Scene* scene;
  107. tolua_property__is_set bool enabled;
  108. tolua_property__get_set Connection* owner;
  109. tolua_property__get_set Vector3& position;
  110. tolua_property__get_set Quaternion& rotation;
  111. tolua_property__get_set Vector3 direction;
  112. tolua_property__get_set Vector3& scale;
  113. tolua_readonly tolua_property__get_set Matrix3x4 transform;
  114. tolua_property__get_set Vector3 worldPosition;
  115. tolua_property__get_set Quaternion worldRotation;
  116. tolua_property__get_set Vector3 worldDirection;
  117. tolua_property__get_set Vector3 worldScale;
  118. tolua_readonly tolua_property__get_set Matrix3x4& worldTransform;
  119. tolua_readonly tolua_property__is_set bool dirty;
  120. tolua_readonly tolua_property__get_set unsigned numComponents;
  121. tolua_readonly tolua_property__get_set unsigned numNetworkComponents;
  122. };
  123. ${
  124. // Disable generated CreateComponent funciton.
  125. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateComponent00
  126. static int tolua_SceneLuaAPI_Node_CreateComponent00(lua_State* tolua_S)
  127. {
  128. #ifndef TOLUA_RELEASE
  129. tolua_Error tolua_err;
  130. if (
  131. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  132. !tolua_isstring(tolua_S,2,0,&tolua_err) ||
  133. !tolua_isnumber(tolua_S,3,1,&tolua_err) ||
  134. !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
  135. !tolua_isnoobj(tolua_S,5,&tolua_err)
  136. )
  137. goto tolua_lerror;
  138. else
  139. #endif
  140. {
  141. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  142. const char* type = ((const char*) tolua_tostring(tolua_S,2,0));
  143. CreateMode mode = ((CreateMode) (int) tolua_tonumber(tolua_S,3,REPLICATED));
  144. unsigned id = ((unsigned) tolua_tonumber(tolua_S,4,0));
  145. #ifndef TOLUA_RELEASE
  146. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateComponent'", NULL);
  147. #endif
  148. {
  149. Component* tolua_ret = (Component*) self->CreateComponent(type,mode,id);
  150. tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
  151. }
  152. }
  153. return 1;
  154. #ifndef TOLUA_RELEASE
  155. tolua_lerror:
  156. tolua_error(tolua_S,"#ferror in function 'CreateComponent'.",&tolua_err);
  157. return 0;
  158. #endif
  159. }
  160. // Disable generated GetComponent funciton.
  161. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetComponent00
  162. static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S)
  163. {
  164. #ifndef TOLUA_RELEASE
  165. tolua_Error tolua_err;
  166. if (
  167. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  168. !tolua_isstring(tolua_S,2,0,&tolua_err) ||
  169. !tolua_isnoobj(tolua_S,3,&tolua_err)
  170. )
  171. goto tolua_lerror;
  172. else
  173. #endif
  174. {
  175. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  176. const char* type = ((const char*) tolua_tostring(tolua_S,2,0));
  177. #ifndef TOLUA_RELEASE
  178. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetComponent'", NULL);
  179. #endif
  180. {
  181. Component* tolua_ret = (Component*) self->GetComponent(type);
  182. tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
  183. }
  184. }
  185. return 1;
  186. #ifndef TOLUA_RELEASE
  187. tolua_lerror:
  188. tolua_error(tolua_S,"#ferror in function 'GetComponent'.",&tolua_err);
  189. return 0;
  190. #endif
  191. }
  192. $}