| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- $#include "AnimationController.h"
- $#include "AnimatedModel.h"
- $#include "Camera.h"
- $#include "CollisionShape.h"
- $#include "Constraint.h"
- $#include "DebugRenderer.h"
- $#include "DecalSet.h"
- $#include "Drawable.h"
- $#include "Light.h"
- $#include "Navigable.h"
- $#include "NavigationMesh.h"
- $#include "NetworkPriority.h"
- $#include "Node.h"
- $#include "Octree.h"
- $#include "OffMeshConnection.h"
- $#include "PhysicsWorld.h"
- $#include "RigidBody.h"
- $#include "SmoothedTransform.h"
- $#include "SoundListener.h"
- $#include "SoundSource.h"
- $#include "StaticModel.h"
- $#include "Terrain.h"
- $#include "Zone.h"
- /// Component and child node creation mode for networking.
- enum CreateMode
- {
- REPLICATED = 0,
- LOCAL = 1
- };
- /// %Scene node that may contain components and child nodes.
- class Node
- {
- public:
- /// Construct.
- Node(Context* context);
- /// Destruct. Any child nodes are detached.
- virtual ~Node();
-
- /// Set name.
- void SetName(const String& name);
- /// Set position relative to parent node.
- void SetPosition(const Vector3& position);
- /// Set rotation relative to parent node.
- void SetRotation(const Quaternion& rotation);
- /// Set direction relative to parent node. Positive Z equals identity.
- void SetDirection(const Vector3& direction);
- /// Set uniform scale relative to parent node.
- void SetScale(float scale);
- /// Set scale relative to parent node.
- void SetScale(const Vector3& scale);
- /// Set transform relative to parent node.
- void SetTransform(const Vector3& position, const Quaternion& rotation);
- /// Set transform relative to parent node.
- void SetTransform(const Vector3& position, const Quaternion& rotation, float scale);
- /// Set transform relative to parent node.
- void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
- /// Set position relative to world space.
- void SetWorldPosition(const Vector3& position);
- /// Set rotation relative to world space.
- void SetWorldRotation(const Quaternion& rotation);
- /// Set direction relative to world space.
- void SetWorldDirection(const Vector3& direction);
- /// Set uniform scale relative to world space.
- void SetWorldScale(float scale);
- /// Set scale relative to world space.
- void SetWorldScale(const Vector3& scale);
- /// Set transform relative to world space.
- void SetWorldTransform(const Vector3& position, const Quaternion& rotation);
- /// Set transform relative to world space.
- void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale);
- /// Set transform relative to world space.
- void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
- /// Move the scene node.
- void Translate(const Vector3& delta);
- /// Move the scene node relative to its rotation.
- void TranslateRelative(const Vector3& delta);
- /// Rotate the scene node.
- void Rotate(const Quaternion& delta, bool fixedAxis = false);
- /// Rotate around the X axis.
- void Pitch(float angle, bool fixedAxis = false);
- /// Rotate around the Y axis.
- void Yaw(float angle, bool fixedAxis = false);
- /// Rotate around the Z axis.
- void Roll(float angle, bool fixedAxis = false);
- /// Look at a target world position.
- void LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP);
- /// Modify scale uniformly.
- void Scale(float scale);
- /// Modify scale.
- void Scale(const Vector3& scale);
- /// Set enabled/disabled state without recursion. Components in a disabled node become effectively disabled regardless of their own enable/disable state.
- void SetEnabled(bool enable);
- /// Set enabled/disabled state with optional recursion.
- void SetEnabled(bool enable, bool recursive);
- /// Set owner connection for networking.
- void SetOwner(Connection* owner);
- /// Mark node and child nodes to need world transform recalculation. Notify listener components.
- void MarkDirty();
- /// Create a child scene node (with specified ID if provided).
- Node* CreateChild(const String& name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
- /// Add a child scene node.
- void AddChild(Node* node);
- /// Remove a child scene node.
- void RemoveChild(Node* node);
- /// Remove all child scene nodes.
- void RemoveAllChildren();
- /// Create a component to this node (with specified ID if provided).
- Component* CreateComponent(ShortStringHash type, CreateMode mode = REPLICATED, unsigned id = 0);
- /// Create a component to this node if it does not exist already.
- Component* GetOrCreateComponent(ShortStringHash type, CreateMode mode = REPLICATED, unsigned id = 0);
-
- /// Remove a component from this node.
- void RemoveComponent(Component* component);
- /// Remove the first component of specific type from this node.
- // void RemoveComponent(ShortStringHash type);
- tolua_outside void NodeRemoveComponent @ RemoveComponent(const char* type);
- /// Remove all components from this node.
- void RemoveAllComponents();
- /// Clone scene node, components and child nodes. Return the clone.
- Node* Clone(CreateMode mode = REPLICATED);
- /// Remove from the parent node. If no other shared pointer references exist, causes immediate deletion.
- void Remove();
- /// Set parent scene node. Retains the world transform.
- void SetParent(Node* parent);
- /// Set a user variable.
- void SetVar(ShortStringHash key, const Variant& value);
- /// Add listener component that is notified of node being dirtied. Can either be in the same node or another.
- void AddListener(Component* component);
- /// Remove listener component.
- void RemoveListener(Component* component);
-
- /// Template version of creating a component.
- // template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
-
- AnimationController* CreateComponent<AnimationController> @ CreateAnimationController();
- AnimatedModel* CreateComponent<AnimatedModel> @ CreateAnimatedModel();
- Camera* CreateComponent<Camera> @ CreateCamera();
- CollisionShape* CreateComponent<CollisionShape> @ CreateCollisionShape();
- Constraint* CreateComponent<Constraint> @ CreateConstraint();
- DebugRenderer* CreateComponent<DebugRenderer> @ CreateDebugRenderer();
- DecalSet* CreateComponent<DecalSet> @ CreateDecalSet();
- Drawable* CreateComponent<Drawable> @ CreateDrawable();
- Light* CreateComponent<Light> @ CreateLight();
- Navigable* CreateComponent<Navigable> @ CreateNavigable();
- NavigationMesh* CreateComponent<NavigationMesh> @ CreateNavigationMesh();
- NetworkPriority* CreateComponent<NetworkPriority> @ CreateNetworkPriority();
- Octree* CreateComponent<Octree> @ CreateOctree();
- OffMeshConnection* CreateComponent<OffMeshConnection> @ CreateOffMeshConnection();
- PhysicsWorld* CreateComponent<PhysicsWorld> @ CreatePhysicsWorld();
- RigidBody* CreateComponent<RigidBody> @ CreateRigidBody();
- SmoothedTransform* CreateComponent<SmoothedTransform> @ CreateSmoothedTransform();
- SoundListener* CreateComponent<SoundListener> @ CreateSoundListener();
- SoundSource* CreateComponent<SoundSource> @ CreateSoundSource();
- StaticModel* CreateComponent<StaticModel> @ CreateStaticModel();
- Terrain* CreateComponent<Terrain> @ CreateTerrain();
- Zone* CreateComponent<Zone> @ CreateZone();
-
- AnimationController* CreateComponent<AnimationController> @ CreateAnimationController(CreateMode mode);
- AnimatedModel* CreateComponent<AnimatedModel> @ CreateAnimatedModel(CreateMode mode);
- Camera* CreateComponent<Camera> @ CreateCamera(CreateMode mode);
- CollisionShape* CreateComponent<CollisionShape> @ CreateCollisionShape(CreateMode mode);
- Constraint* CreateComponent<Constraint> @ CreateConstraint(CreateMode mode);
- DebugRenderer* CreateComponent<DebugRenderer> @ CreateDebugRenderer(CreateMode mode);
- DecalSet* CreateComponent<DecalSet> @ CreateDecalSet(CreateMode mode);
- Drawable* CreateComponent<Drawable> @ CreateDrawable(CreateMode mode);
- Light* CreateComponent<Light> @ CreateLight(CreateMode mode);
- Navigable* CreateComponent<Navigable> @ CreateNavigable(CreateMode mode);
- NavigationMesh* CreateComponent<NavigationMesh> @ CreateNavigationMesh(CreateMode mode);
- NetworkPriority* CreateComponent<NetworkPriority> @ CreateNetworkPriority(CreateMode mode);
- Octree* CreateComponent<Octree> @ CreateOctree(CreateMode mode);
- OffMeshConnection* CreateComponent<OffMeshConnection> @ CreateOffMeshConnection(CreateMode mode);
- PhysicsWorld* CreateComponent<PhysicsWorld> @ CreatePhysicsWorld(CreateMode mode);
- RigidBody* CreateComponent<RigidBody> @ CreateRigidBody(CreateMode mode);
- SmoothedTransform* CreateComponent<SmoothedTransform> @ CreateSmoothedTransform(CreateMode mode);
- SoundListener* CreateComponent<SoundListener> @ CreateSoundListener(CreateMode mode);
- SoundSource* CreateComponent<SoundSource> @ CreateSoundSource(CreateMode mode);
- StaticModel* CreateComponent<StaticModel> @ CreateStaticModel(CreateMode mode);
- Terrain* CreateComponent<Terrain> @ CreateTerrain(CreateMode mode);
- Zone* CreateComponent<Zone> @ CreateZone(CreateMode mode);
-
- AnimationController* CreateComponent<AnimationController> @ CreateAnimationController(CreateMode mode, unsigned id);
- AnimatedModel* CreateComponent<AnimatedModel> @ CreateAnimatedModel(CreateMode mode, unsigned id);
- Camera* CreateComponent<Camera> @ CreateCamera(CreateMode mode, unsigned id);
- CollisionShape* CreateComponent<CollisionShape> @ CreateCollisionShape(CreateMode mode, unsigned id);
- Constraint* CreateComponent<Constraint> @ CreateConstraint(CreateMode mode, unsigned id);
- DebugRenderer* CreateComponent<DebugRenderer> @ CreateDebugRenderer(CreateMode mode, unsigned id);
- DecalSet* CreateComponent<DecalSet> @ CreateDecalSet(CreateMode mode, unsigned id);
- Drawable* CreateComponent<Drawable> @ CreateDrawable(CreateMode mode, unsigned id);
- Light* CreateComponent<Light> @ CreateLight(CreateMode mode, unsigned id);
- Navigable* CreateComponent<Navigable> @ CreateNavigable(CreateMode mode, unsigned id);
- NavigationMesh* CreateComponent<NavigationMesh> @ CreateNavigationMesh(CreateMode mode, unsigned id);
- NetworkPriority* CreateComponent<NetworkPriority> @ CreateNetworkPriority(CreateMode mode, unsigned id);
- Octree* CreateComponent<Octree> @ CreateOctree(CreateMode mode, unsigned id);
- OffMeshConnection* CreateComponent<OffMeshConnection> @ CreateOffMeshConnection(CreateMode mode, unsigned id);
- PhysicsWorld* CreateComponent<PhysicsWorld> @ CreatePhysicsWorld(CreateMode mode, unsigned id);
- RigidBody* CreateComponent<RigidBody> @ CreateRigidBody(CreateMode mode, unsigned id);
- SmoothedTransform* CreateComponent<SmoothedTransform> @ CreateSmoothedTransform(CreateMode mode, unsigned id);
- SoundListener* CreateComponent<SoundListener> @ CreateSoundListener(CreateMode mode, unsigned id);
- SoundSource* CreateComponent<SoundSource> @ CreateSoundSource(CreateMode mode, unsigned id);
- StaticModel* CreateComponent<StaticModel> @ CreateStaticModel(CreateMode mode, unsigned id);
- Terrain* CreateComponent<Terrain> @ CreateTerrain(CreateMode mode, unsigned id);
- Zone* CreateComponent<Zone> @ CreateZone(CreateMode mode, unsigned id);
- /// Template version of getting or creating a component.
- // template <class T> T* GetOrCreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
-
- /// Return ID.
- unsigned GetID() const { return id_; }
- /// Return name.
- const String& GetName() const { return name_; }
- /// Return name hash.
- StringHash GetNameHash() const { return nameHash_; }
- /// Return parent scene node.
- Node* GetParent() const { return parent_; }
- /// Return scene.
- Scene* GetScene() const { return scene_; }
- /// Return whether is enabled. Disables nodes effectively disable all their components.
- bool IsEnabled() const { return enabled_; }
- /// Return owner connection in networking.
- Connection* GetOwner() const { return owner_; }
- /// Return position relative to parent node.
- const Vector3& GetPosition() const { return position_; }
- /// Return rotation relative to parent node.
- const Quaternion& GetRotation() const { return rotation_; }
- /// Return direction relative to parent node. Identity rotation equals positive Z.
- Vector3 GetDirection() const { return rotation_ * Vector3::FORWARD; }
- /// Return scale relative to parent node.
- const Vector3& GetScale() const { return scale_; }
- /// Return transform matrix relative to parent node.
- Matrix3x4 GetTransform() const { return Matrix3x4(position_, rotation_, scale_); }
- /// Return position in world space.
- Vector3 GetWorldPosition() const
- {
- if (dirty_)
- UpdateWorldTransform();
-
- return worldTransform_.Translation();
- }
- /// Return rotation in world space.
- Quaternion GetWorldRotation() const
- {
- if (dirty_)
- UpdateWorldTransform();
-
- return worldRotation_;
- }
- /// Return direction in world space.
- Vector3 GetWorldDirection() const
- {
- if (dirty_)
- UpdateWorldTransform();
-
- return worldRotation_ * Vector3::FORWARD;
- }
- /// Return scale in world space.
- Vector3 GetWorldScale() const
- {
- if (dirty_)
- UpdateWorldTransform();
-
- return worldTransform_.Scale();
- }
- /// Return transform matrix in world space.
- const Matrix3x4& GetWorldTransform() const
- {
- if (dirty_)
- UpdateWorldTransform();
-
- return worldTransform_;
- }
- /// Convert a local space position to world space.
- Vector3 LocalToWorld(const Vector3& position) const;
- /// Convert a local space position or rotation to world space.
- Vector3 LocalToWorld(const Vector4& vector) const;
- /// Convert a world space position to local space.
- Vector3 WorldToLocal(const Vector3& position) const;
- /// Convert a world space position or rotation to local space.
- Vector3 WorldToLocal(const Vector4& vector) const;
- /// Return whether transform has changed and world transform needs recalculation.
- bool IsDirty() const { return dirty_; }
- /// Return number of child scene nodes.
- unsigned GetNumChildren(bool recursive = false) const;
- /// Return child scene node by index.
- Node* GetChild(unsigned index) const;
- /// Return child scene node by name.
- Node* GetChild(const String& name, bool recursive = false) const;
- /// Return child scene node by name.
- Node* GetChild(const char* name, bool recursive = false) const;
- /// Return child scene node by name hash.
- Node* GetChild(StringHash nameHash, bool recursive = false) const;
- /// Return number of components.
- unsigned GetNumComponents() const { return components_.Size(); }
- /// Return number of non-local components.
- unsigned GetNumNetworkComponents() const;
- /// Return component by type. If there are several, returns the first.
- // Component* GetComponent(ShortStringHash type) const;
- /// Return whether has a specific component.
- // bool HasComponent(ShortStringHash type) const;
- tolua_outside bool NodeHasComponent @ HasComponent(const char* type) const;
-
- /// Template version of returning a component by type.
- // template <class T> T* GetComponent() const;
- AnimationController* GetComponent<AnimationController> @ GetAnimationController() const;
- AnimatedModel* GetComponent<AnimatedModel> @ GetAnimatedModel() const;
- Camera* GetComponent<Camera> @ GetCamera() const;
- CollisionShape* GetComponent<CollisionShape> @ GetCollisionShape() const;
- Constraint* GetComponent<Constraint> @ GetConstraint() const;
- DebugRenderer* GetComponent<DebugRenderer> @ GetDebugRenderer() const;
- DecalSet* GetComponent<DecalSet> @ GetDecalSet() const;
- Drawable* GetComponent<Drawable> @ GetDrawable() const;
- Light* GetComponent<Light> @ GetLight() const;
- Navigable* GetComponent<Navigable> @ GetNavigable() const;
- NavigationMesh* GetComponent<NavigationMesh> @ GetNavigationMesh() const;
- NetworkPriority* GetComponent<NetworkPriority> @ GetNetworkPriority() const;
- Octree* GetComponent<Octree> @ GetOctree() const;
- OffMeshConnection* GetComponent<OffMeshConnection> @ GetOffMeshConnection() const;
- PhysicsWorld* GetComponent<PhysicsWorld> @ GetPhysicsWorld() const;
- RigidBody* GetComponent<RigidBody> @ GetRigidBody() const;
- SmoothedTransform* GetComponent<SmoothedTransform> @ GetSmoothedTransform() const;
- SoundListener* GetComponent<SoundListener> @ GetSoundListener() const;
- SoundSource* GetComponent<SoundSource> @ GetSoundSource() const;
- StaticModel* GetComponent<StaticModel> @ GetStaticModel() const;
- Terrain* GetComponent<Terrain> @ GetTerrain() const;
- Zone* GetComponent<Zone> @ GetZone() const;
- };
- ${
- void NodeRemoveComponent(Node* node, const char* type)
- {
- return node->RemoveComponent(ShortStringHash(type));
- }
- bool NodeHasComponent(const Node* node, const char* type)
- {
- return node->HasComponent(ShortStringHash(type));
- }
- $}
|