Node.pkg 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. $#include "AnimationController.h"
  2. $#include "AnimatedModel.h"
  3. $#include "Camera.h"
  4. $#include "CollisionShape.h"
  5. $#include "Constraint.h"
  6. $#include "DebugRenderer.h"
  7. $#include "DecalSet.h"
  8. $#include "Drawable.h"
  9. $#include "Light.h"
  10. $#include "Navigable.h"
  11. $#include "NavigationMesh.h"
  12. $#include "NetworkPriority.h"
  13. $#include "Node.h"
  14. $#include "Octree.h"
  15. $#include "OffMeshConnection.h"
  16. $#include "PhysicsWorld.h"
  17. $#include "RigidBody.h"
  18. $#include "SmoothedTransform.h"
  19. $#include "SoundListener.h"
  20. $#include "SoundSource.h"
  21. $#include "StaticModel.h"
  22. $#include "Terrain.h"
  23. $#include "Zone.h"
  24. enum CreateMode
  25. {
  26. REPLICATED = 0,
  27. LOCAL = 1
  28. };
  29. class Node : public Serializable
  30. {
  31. Node(Context* context);
  32. virtual ~Node();
  33. bool SaveXML(Serializer& dest) const;
  34. void SetName(const String& name);
  35. void SetPosition(const Vector3& position);
  36. void SetRotation(const Quaternion& rotation);
  37. void SetDirection(const Vector3& direction);
  38. void SetScale(float scale);
  39. void SetScale(const Vector3& scale);
  40. void SetTransform(const Vector3& position, const Quaternion& rotation);
  41. void SetTransform(const Vector3& position, const Quaternion& rotation, float scale);
  42. void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  43. void SetWorldPosition(const Vector3& position);
  44. void SetWorldRotation(const Quaternion& rotation);
  45. void SetWorldDirection(const Vector3& direction);
  46. void SetWorldScale(float scale);
  47. void SetWorldScale(const Vector3& scale);
  48. void SetWorldTransform(const Vector3& position, const Quaternion& rotation);
  49. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale);
  50. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  51. void Translate(const Vector3& delta);
  52. void TranslateRelative(const Vector3& delta);
  53. void Rotate(const Quaternion& delta, bool fixedAxis = false);
  54. void Pitch(float angle, bool fixedAxis = false);
  55. void Yaw(float angle, bool fixedAxis = false);
  56. void Roll(float angle, bool fixedAxis = false);
  57. void LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP);
  58. void Scale(float scale);
  59. void Scale(const Vector3& scale);
  60. void SetEnabled(bool enable);
  61. void SetEnabled(bool enable, bool recursive);
  62. void SetOwner(Connection* owner);
  63. void MarkDirty();
  64. Node* CreateChild(const String& name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
  65. void AddChild(Node* node);
  66. void RemoveChild(Node* node);
  67. void RemoveAllChildren();
  68. void RemoveChildren(bool removeReplicated, bool removeLocal, bool recursive);
  69. void RemoveComponent(Component* component);
  70. void RemoveComponent(ShortStringHash type);
  71. void RemoveComponent(const char* type);
  72. void RemoveAllComponents();
  73. void RemoveComponents(bool removeReplicated, bool removeLocal);
  74. Node* Clone(CreateMode mode = REPLICATED);
  75. void Remove();
  76. void SetParent(Node* parent);
  77. void SetVar(ShortStringHash key, const Variant& value);
  78. void AddListener(Component* component);
  79. void RemoveListener(Component* component);
  80. // template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
  81. AnimationController* CreateComponent<AnimationController> @ CreateAnimationController(CreateMode mode = REPLICATED, unsigned id = 0);
  82. AnimatedModel* CreateComponent<AnimatedModel> @ CreateAnimatedModel(CreateMode mode = REPLICATED, unsigned id = 0);
  83. Camera* CreateComponent<Camera> @ CreateCamera(CreateMode mode = REPLICATED, unsigned id = 0);
  84. CollisionShape* CreateComponent<CollisionShape> @ CreateCollisionShape(CreateMode mode = REPLICATED, unsigned id = 0);
  85. Constraint* CreateComponent<Constraint> @ CreateConstraint(CreateMode mode = REPLICATED, unsigned id = 0);
  86. DebugRenderer* CreateComponent<DebugRenderer> @ CreateDebugRenderer(CreateMode mode = REPLICATED, unsigned id = 0);
  87. DecalSet* CreateComponent<DecalSet> @ CreateDecalSet(CreateMode mode = REPLICATED, unsigned id = 0);
  88. Drawable* CreateComponent<Drawable> @ CreateDrawable(CreateMode mode = REPLICATED, unsigned id = 0);
  89. Light* CreateComponent<Light> @ CreateLight(CreateMode mode = REPLICATED, unsigned id = 0);
  90. Navigable* CreateComponent<Navigable> @ CreateNavigable(CreateMode mode = REPLICATED, unsigned id = 0);
  91. NavigationMesh* CreateComponent<NavigationMesh> @ CreateNavigationMesh(CreateMode mode = REPLICATED, unsigned id = 0);
  92. NetworkPriority* CreateComponent<NetworkPriority> @ CreateNetworkPriority(CreateMode mode = REPLICATED, unsigned id = 0);
  93. Octree* CreateComponent<Octree> @ CreateOctree(CreateMode mode = REPLICATED, unsigned id = 0);
  94. OffMeshConnection* CreateComponent<OffMeshConnection> @ CreateOffMeshConnection(CreateMode mode = REPLICATED, unsigned id = 0);
  95. PhysicsWorld* CreateComponent<PhysicsWorld> @ CreatePhysicsWorld(CreateMode mode = REPLICATED, unsigned id = 0);
  96. RigidBody* CreateComponent<RigidBody> @ CreateRigidBody(CreateMode mode = REPLICATED, unsigned id = 0);
  97. SmoothedTransform* CreateComponent<SmoothedTransform> @ CreateSmoothedTransform(CreateMode mode = REPLICATED, unsigned id = 0);
  98. SoundListener* CreateComponent<SoundListener> @ CreateSoundListener(CreateMode mode = REPLICATED, unsigned id = 0);
  99. SoundSource* CreateComponent<SoundSource> @ CreateSoundSource(CreateMode mode = REPLICATED, unsigned id = 0);
  100. StaticModel* CreateComponent<StaticModel> @ CreateStaticModel(CreateMode mode = REPLICATED, unsigned id = 0);
  101. Terrain* CreateComponent<Terrain> @ CreateTerrain(CreateMode mode = REPLICATED, unsigned id = 0);
  102. Zone* CreateComponent<Zone> @ CreateZone(CreateMode mode = REPLICATED, unsigned id = 0);
  103. unsigned GetID() const;
  104. const String& GetName() const;
  105. StringHash GetNameHash() const;
  106. Node* GetParent() const;
  107. Scene* GetScene() const;
  108. bool IsEnabled() const;
  109. Connection* GetOwner() const;
  110. const Vector3& GetPosition() const;
  111. const Quaternion& GetRotation() const;
  112. Vector3 GetDirection() const;
  113. const Vector3& GetScale() const;
  114. Matrix3x4 GetTransform() const;
  115. Vector3 GetWorldPosition() const;
  116. Quaternion GetWorldRotation() const;
  117. Vector3 GetWorldDirection() const;
  118. Vector3 GetWorldScale() const;
  119. const Matrix3x4& GetWorldTransform() const;
  120. Vector3 LocalToWorld(const Vector3& position) const;
  121. Vector3 LocalToWorld(const Vector4& vector) const;
  122. Vector3 WorldToLocal(const Vector3& position) const;
  123. Vector3 WorldToLocal(const Vector4& vector) const;
  124. bool IsDirty() const;
  125. unsigned GetNumChildren(bool recursive = false) const;
  126. Node* GetChild(unsigned index) const;
  127. Node* GetChild(const String& name, bool recursive = false) const;
  128. Node* GetChild(const char* name, bool recursive = false) const;
  129. Node* GetChild(StringHash nameHash, bool recursive = false) const;
  130. unsigned GetNumComponents() const;
  131. unsigned GetNumNetworkComponents() const;
  132. bool HasComponent(ShortStringHash type) const;
  133. bool HasComponent(const char* type) const;
  134. const Variant& GetVar(ShortStringHash key) const;
  135. const VariantMap& GetVars() const;
  136. // template <class T> T* GetComponent() const;
  137. AnimationController* GetComponent<AnimationController> @ GetAnimationController() const;
  138. AnimatedModel* GetComponent<AnimatedModel> @ GetAnimatedModel() const;
  139. Camera* GetComponent<Camera> @ GetCamera() const;
  140. CollisionShape* GetComponent<CollisionShape> @ GetCollisionShape() const;
  141. Constraint* GetComponent<Constraint> @ GetConstraint() const;
  142. DebugRenderer* GetComponent<DebugRenderer> @ GetDebugRenderer() const;
  143. DecalSet* GetComponent<DecalSet> @ GetDecalSet() const;
  144. Drawable* GetComponent<Drawable> @ GetDrawable() const;
  145. Light* GetComponent<Light> @ GetLight() const;
  146. Navigable* GetComponent<Navigable> @ GetNavigable() const;
  147. NavigationMesh* GetComponent<NavigationMesh> @ GetNavigationMesh() const;
  148. NetworkPriority* GetComponent<NetworkPriority> @ GetNetworkPriority() const;
  149. Octree* GetComponent<Octree> @ GetOctree() const;
  150. OffMeshConnection* GetComponent<OffMeshConnection> @ GetOffMeshConnection() const;
  151. PhysicsWorld* GetComponent<PhysicsWorld> @ GetPhysicsWorld() const;
  152. RigidBody* GetComponent<RigidBody> @ GetRigidBody() const;
  153. SmoothedTransform* GetComponent<SmoothedTransform> @ GetSmoothedTransform() const;
  154. SoundListener* GetComponent<SoundListener> @ GetSoundListener() const;
  155. SoundSource* GetComponent<SoundSource> @ GetSoundSource() const;
  156. StaticModel* GetComponent<StaticModel> @ GetStaticModel() const;
  157. Terrain* GetComponent<Terrain> @ GetTerrain() const;
  158. Zone* GetComponent<Zone> @ GetZone() const;
  159. void SetID(unsigned id);
  160. void SetScene(Scene* scene);
  161. void ResetScene();
  162. bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  163. bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  164. Node* CreateChild(unsigned id, CreateMode mode);
  165. void AddComponent(Component* component, unsigned id, CreateMode mode);
  166. tolua_property__get_set unsigned ID;
  167. tolua_property__get_set String& name;
  168. tolua_readonly tolua_property__get_set StringHash nameHash;
  169. tolua_property__get_set Node* parent;
  170. tolua_property__get_set Scene* scene;
  171. tolua_property__is_set bool enabled;
  172. tolua_property__get_set Connection* owner;
  173. tolua_property__get_set Vector3& position;
  174. tolua_property__get_set Quaternion& rotation;
  175. tolua_property__get_set Vector3 direction;
  176. tolua_property__get_set Vector3& scale;
  177. tolua_readonly tolua_property__get_set Matrix3x4 transform;
  178. tolua_property__get_set Vector3 worldPosition;
  179. tolua_property__get_set Quaternion worldRotation;
  180. tolua_property__get_set Vector3 worldDirection;
  181. tolua_property__get_set Vector3 worldScale;
  182. tolua_readonly tolua_property__get_set Matrix3x4& worldTransform;
  183. tolua_readonly tolua_property__is_set bool dirty;
  184. tolua_readonly tolua_property__get_set unsigned numComponents;
  185. tolua_readonly tolua_property__get_set unsigned numNetworkComponents;
  186. };