Node.pkg 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 RemoveComponent(Component* component);
  69. void RemoveComponent(ShortStringHash type);
  70. void RemoveComponent(const char* type);
  71. void RemoveAllComponents();
  72. Node* Clone(CreateMode mode = REPLICATED);
  73. void Remove();
  74. void SetParent(Node* parent);
  75. void SetVar(ShortStringHash key, const Variant& value);
  76. void AddListener(Component* component);
  77. void RemoveListener(Component* component);
  78. // template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
  79. AnimationController* CreateComponent<AnimationController> @ CreateAnimationController(CreateMode mode = REPLICATED, unsigned id = 0);
  80. AnimatedModel* CreateComponent<AnimatedModel> @ CreateAnimatedModel(CreateMode mode = REPLICATED, unsigned id = 0);
  81. Camera* CreateComponent<Camera> @ CreateCamera(CreateMode mode = REPLICATED, unsigned id = 0);
  82. CollisionShape* CreateComponent<CollisionShape> @ CreateCollisionShape(CreateMode mode = REPLICATED, unsigned id = 0);
  83. Constraint* CreateComponent<Constraint> @ CreateConstraint(CreateMode mode = REPLICATED, unsigned id = 0);
  84. DebugRenderer* CreateComponent<DebugRenderer> @ CreateDebugRenderer(CreateMode mode = REPLICATED, unsigned id = 0);
  85. DecalSet* CreateComponent<DecalSet> @ CreateDecalSet(CreateMode mode = REPLICATED, unsigned id = 0);
  86. Drawable* CreateComponent<Drawable> @ CreateDrawable(CreateMode mode = REPLICATED, unsigned id = 0);
  87. Light* CreateComponent<Light> @ CreateLight(CreateMode mode = REPLICATED, unsigned id = 0);
  88. Navigable* CreateComponent<Navigable> @ CreateNavigable(CreateMode mode = REPLICATED, unsigned id = 0);
  89. NavigationMesh* CreateComponent<NavigationMesh> @ CreateNavigationMesh(CreateMode mode = REPLICATED, unsigned id = 0);
  90. NetworkPriority* CreateComponent<NetworkPriority> @ CreateNetworkPriority(CreateMode mode = REPLICATED, unsigned id = 0);
  91. Octree* CreateComponent<Octree> @ CreateOctree(CreateMode mode = REPLICATED, unsigned id = 0);
  92. OffMeshConnection* CreateComponent<OffMeshConnection> @ CreateOffMeshConnection(CreateMode mode = REPLICATED, unsigned id = 0);
  93. PhysicsWorld* CreateComponent<PhysicsWorld> @ CreatePhysicsWorld(CreateMode mode = REPLICATED, unsigned id = 0);
  94. RigidBody* CreateComponent<RigidBody> @ CreateRigidBody(CreateMode mode = REPLICATED, unsigned id = 0);
  95. SmoothedTransform* CreateComponent<SmoothedTransform> @ CreateSmoothedTransform(CreateMode mode = REPLICATED, unsigned id = 0);
  96. SoundListener* CreateComponent<SoundListener> @ CreateSoundListener(CreateMode mode = REPLICATED, unsigned id = 0);
  97. SoundSource* CreateComponent<SoundSource> @ CreateSoundSource(CreateMode mode = REPLICATED, unsigned id = 0);
  98. StaticModel* CreateComponent<StaticModel> @ CreateStaticModel(CreateMode mode = REPLICATED, unsigned id = 0);
  99. Terrain* CreateComponent<Terrain> @ CreateTerrain(CreateMode mode = REPLICATED, unsigned id = 0);
  100. Zone* CreateComponent<Zone> @ CreateZone(CreateMode mode = REPLICATED, unsigned id = 0);
  101. unsigned GetID() const;
  102. const String& GetName() const;
  103. StringHash GetNameHash() const;
  104. Node* GetParent() const;
  105. Scene* GetScene() const;
  106. bool IsEnabled() const;
  107. Connection* GetOwner() const;
  108. const Vector3& GetPosition() const;
  109. const Quaternion& GetRotation() const;
  110. Vector3 GetDirection() const;
  111. const Vector3& GetScale() const;
  112. Matrix3x4 GetTransform() const;
  113. Vector3 GetWorldPosition() const;
  114. Quaternion GetWorldRotation() const;
  115. Vector3 GetWorldDirection() const;
  116. Vector3 GetWorldScale() const;
  117. const Matrix3x4& GetWorldTransform() const;
  118. Vector3 LocalToWorld(const Vector3& position) const;
  119. Vector3 LocalToWorld(const Vector4& vector) const;
  120. Vector3 WorldToLocal(const Vector3& position) const;
  121. Vector3 WorldToLocal(const Vector4& vector) const;
  122. bool IsDirty() const;
  123. unsigned GetNumChildren(bool recursive = false) const;
  124. Node* GetChild(unsigned index) const;
  125. Node* GetChild(const String& name, bool recursive = false) const;
  126. Node* GetChild(const char* name, bool recursive = false) const;
  127. Node* GetChild(StringHash nameHash, bool recursive = false) const;
  128. unsigned GetNumComponents() const;
  129. unsigned GetNumNetworkComponents() const;
  130. bool HasComponent(ShortStringHash type) const;
  131. bool HasComponent(const char* type) const;
  132. const Variant& GetVar(ShortStringHash key) const;
  133. const VariantMap& GetVars() const;
  134. // template <class T> T* GetComponent() const;
  135. AnimationController* GetComponent<AnimationController> @ GetAnimationController() const;
  136. AnimatedModel* GetComponent<AnimatedModel> @ GetAnimatedModel() const;
  137. Camera* GetComponent<Camera> @ GetCamera() const;
  138. CollisionShape* GetComponent<CollisionShape> @ GetCollisionShape() const;
  139. Constraint* GetComponent<Constraint> @ GetConstraint() const;
  140. DebugRenderer* GetComponent<DebugRenderer> @ GetDebugRenderer() const;
  141. DecalSet* GetComponent<DecalSet> @ GetDecalSet() const;
  142. Drawable* GetComponent<Drawable> @ GetDrawable() const;
  143. Light* GetComponent<Light> @ GetLight() const;
  144. Navigable* GetComponent<Navigable> @ GetNavigable() const;
  145. NavigationMesh* GetComponent<NavigationMesh> @ GetNavigationMesh() const;
  146. NetworkPriority* GetComponent<NetworkPriority> @ GetNetworkPriority() const;
  147. Octree* GetComponent<Octree> @ GetOctree() const;
  148. OffMeshConnection* GetComponent<OffMeshConnection> @ GetOffMeshConnection() const;
  149. PhysicsWorld* GetComponent<PhysicsWorld> @ GetPhysicsWorld() const;
  150. RigidBody* GetComponent<RigidBody> @ GetRigidBody() const;
  151. SmoothedTransform* GetComponent<SmoothedTransform> @ GetSmoothedTransform() const;
  152. SoundListener* GetComponent<SoundListener> @ GetSoundListener() const;
  153. SoundSource* GetComponent<SoundSource> @ GetSoundSource() const;
  154. StaticModel* GetComponent<StaticModel> @ GetStaticModel() const;
  155. Terrain* GetComponent<Terrain> @ GetTerrain() const;
  156. Zone* GetComponent<Zone> @ GetZone() const;
  157. void SetID(unsigned id);
  158. void SetScene(Scene* scene);
  159. void ResetScene();
  160. bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  161. bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  162. Node* CreateChild(unsigned id, CreateMode mode);
  163. void AddComponent(Component* component, unsigned id, CreateMode mode);
  164. tolua_property__get_set unsigned ID;
  165. tolua_property__get_set String& name;
  166. tolua_readonly tolua_property__get_set StringHash nameHash;
  167. tolua_property__get_set Node* parent;
  168. tolua_property__get_set Scene* scene;
  169. tolua_property__is_set bool enabled;
  170. tolua_property__get_set Connection* owner;
  171. tolua_property__get_set Vector3& position;
  172. tolua_property__get_set Quaternion& rotation;
  173. tolua_property__get_set Vector3 direction;
  174. tolua_property__get_set Vector3& scale;
  175. tolua_readonly tolua_property__get_set Matrix3x4 transform;
  176. tolua_property__get_set Vector3 worldPosition;
  177. tolua_property__get_set Quaternion worldRotation;
  178. tolua_property__get_set Vector3 worldDirection;
  179. tolua_property__get_set Vector3 worldScale;
  180. tolua_readonly tolua_property__get_set Matrix3x4& worldTransform;
  181. tolua_readonly tolua_property__is_set bool dirty;
  182. tolua_readonly tolua_property__get_set unsigned numComponents;
  183. tolua_readonly tolua_property__get_set unsigned numNetworkComponents;
  184. };