Urho3D
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends
Urho3D::Node Class Reference

Scene node that may contain components and child nodes. More...

#include <Node.h>

Inheritance diagram for Urho3D::Node:
Urho3D::Serializable Urho3D::Object Urho3D::RefCounted Urho3D::Scene

List of all members.

Public Member Functions

 Node (Context *context)
 Construct.
virtual ~Node ()
 Destruct. Any child nodes are detached.
virtual void OnSetAttribute (const AttributeInfo &attr, const Variant &src)
 Handle attribute write access.
virtual bool Load (Deserializer &source)
 Load from binary data. Return true if successful.
virtual bool LoadXML (const XMLElement &source)
 Load from XML data. Return true if successful.
virtual bool Save (Serializer &dest)
 Save as binary data. Return true if successful.
virtual bool SaveXML (XMLElement &dest)
 Save as XML data. Return true if successful.
virtual void ApplyAttributes ()
 Apply attribute changes that can not be applied immediately recursively to child nodes and components.
virtual void AddReplicationState (NodeReplicationState *state)
 Add a replication state that is tracking this node.
bool SaveXML (Serializer &dest)
 Save to an XML file. Return true if successful.
void SetName (const String &name)
 Set name.
void SetPosition (const Vector3 &position)
 Set position relative to parent node.
void SetRotation (const Quaternion &rotation)
 Set rotation relative to parent node.
void SetDirection (const Vector3 &direction)
 Set direction relative to parent node. Positive Z equals identity.
void SetScale (float scale)
 Set uniform scale relative to parent node.
void SetScale (const Vector3 &scale)
 Set scale 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 transform relative to parent node.
void SetWorldPosition (const Vector3 &position)
 Set position relative to world space.
void SetWorldRotation (const Quaternion &rotation)
 Set rotation relative to world space.
void SetWorldDirection (const Vector3 &direction)
 Set direction relative to world space.
void SetWorldScale (float scale)
 Set uniform scale relative to world space.
void SetWorldScale (const Vector3 &scale)
 Set scale 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)
 Set transform relative to world space.
void Translate (const Vector3 &delta)
 Move the scene node.
void TranslateRelative (const Vector3 &delta)
 Move the scene node relative to its rotation.
void Rotate (const Quaternion &delta, bool fixedAxis=false)
 Rotate the scene node.
void Pitch (float angle, bool fixedAxis=false)
 Rotate around the X axis.
void Yaw (float angle, bool fixedAxis=false)
 Rotate around the Y axis.
void Roll (float angle, bool fixedAxis=false)
 Rotate around the Z axis.
void LookAt (const Vector3 &target, const Vector3 &upAxis=Vector3::UP, bool worldSpace=false)
 Look at a target position.
void Scale (float scale)
 Modify scale uniformly.
void Scale (const Vector3 &scale)
 Modify scale.
void SetOwner (Connection *owner)
 Set owner connection for networking.
void MarkDirty ()
 Mark node and child nodes to need world transform recalculation. Notify listener components.
NodeCreateChild (const String &name=String::EMPTY, CreateMode mode=REPLICATED)
 Create a child scene node.
void AddChild (Node *node)
 Add a child scene node.
void RemoveChild (Node *node)
 Remove a child scene node.
void RemoveAllChildren ()
 Remove all child scene nodes.
ComponentCreateComponent (ShortStringHash type, CreateMode mode=REPLICATED, unsigned id=0)
 Create a component to this node (with specified ID if provided).
ComponentGetOrCreateComponent (ShortStringHash type, CreateMode mode=REPLICATED)
 Create a component to this node if it does not exist already.
void RemoveComponent (Component *component)
 Remove a component from this node.
void RemoveComponent (ShortStringHash type)
 Remove the first component of specific type from this node.
void RemoveAllComponents ()
 Remove all components from this node.
NodeClone (CreateMode mode=REPLICATED)
 Clone scene node, components and child nodes. Return the clone.
void Remove ()
 Remove from the parent node. If no other shared pointer references exist, causes immediate deletion.
void SetParent (Node *parent)
 Set parent scene node. Retains the world transform.
void SetVar (ShortStringHash key, const Variant &value)
 Set a user variable.
void AddListener (Component *component)
 Add listener component that is notified of node being dirtied. Can either be in the same node or another.
void RemoveListener (Component *component)
 Remove listener component.
template<class T >
T * CreateComponent (CreateMode mode=REPLICATED)
 Template version of creating a component.
template<class T >
T * GetOrCreateComponent (CreateMode mode=REPLICATED)
 Template version of getting or creating a component.
unsigned GetID () const
 Return ID.
const StringGetName () const
 Return name.
StringHash GetNameHash () const
 Return name hash.
NodeGetParent () const
 Return parent scene node.
SceneGetScene () const
 Return scene.
ConnectionGetOwner () const
 Return owner connection in networking.
const Vector3GetPosition () const
 Return position relative to parent node.
const QuaternionGetRotation () const
 Return rotation relative to parent node.
Vector3 GetDirection () const
 Return direction relative to parent node. Identity rotation equals positive Z.
const Vector3GetScale () const
 Return scale relative to parent node.
Matrix3x4 GetTransform () const
 Return transform matrix relative to parent node.
Vector3 GetWorldPosition () const
 Return position in world space.
Quaternion GetWorldRotation () const
 Return rotation in world space.
Vector3 GetWorldDirection () const
 Return direction in world space.
Vector3 GetWorldScale () const
 Return scale in world space.
const Matrix3x4GetWorldTransform () const
 Return transform matrix in world space.
Vector3 LocalToWorld (const Vector3 &position) const
 Convert a local space position to world space.
Vector3 LocalToWorld (const Vector4 &vector) const
 Convert a local space position or rotation to world space.
Vector3 WorldToLocal (const Vector3 &position) const
 Convert a world space position to local space.
Vector3 WorldToLocal (const Vector4 &vector) const
 Convert a world space position or rotation to local space.
bool IsDirty () const
 Return whether transform has changed and world transform needs recalculation.
unsigned GetNumChildren (bool recursive=false) const
 Return number of child scene nodes.
const Vector< SharedPtr< Node > > & GetChildren () const
 Return immediate child scene nodes.
void GetChildren (PODVector< Node * > &dest, bool recursive=false) const
 Return child scene nodes, optionally recursive.
void GetChildrenWithComponent (PODVector< Node * > &dest, ShortStringHash type, bool recursive=false) const
 Return child scene nodes with a specific component.
NodeGetChild (unsigned index) const
 Return child scene node by index.
NodeGetChild (const String &name, bool recursive=false) const
 Return child scene node by name.
NodeGetChild (StringHash nameHash, bool recursive=false) const
 Return child scene node by name hash.
unsigned GetNumComponents () const
 Return number of components.
unsigned GetNumNetworkComponents () const
 Return number of non-local components.
const Vector< SharedPtr
< Component > > & 
GetComponents () const
 Return all components.
void GetComponents (PODVector< Component * > &dest, ShortStringHash type) const
 Return all components of type.
ComponentGetComponent (ShortStringHash type) const
 Return component by type. If there are several, returns the first.
bool HasComponent (ShortStringHash type) const
 Return whether has a specific component.
const Vector< WeakPtr
< Component > > 
GetListeners () const
 Return listener components.
const VariantGetVar (ShortStringHash key) const
 Return a user variable.
const VariantMapGetVars () const
 Return all user variables.
template<class T >
T * GetDerivedComponent () const
 Return first component derived from class.
template<class T >
void GetDerivedComponents (PODVector< T * > &dest) const
 Return components derived from class.
template<class T >
void GetChildrenWithComponent (PODVector< Node * > &dest, bool recursive=false) const
 Template version of returning child nodes with a specific component.
template<class T >
T * GetComponent () const
 Template version of returning a component by type.
template<class T >
void GetComponents (PODVector< T * > &dest) const
 Template version of returning all components of type.
template<class T >
bool HasComponent () const
 Template version of checking whether has a specific component.
void SetID (unsigned id)
 Set ID. Called by Scene.
void SetScene (Scene *scene)
 Set scene. Called by Scene.
void ResetScene ()
 Reset scene. Called by Scene.
void SetNetPositionAttr (const Vector3 &value)
 Set network position attribute.
void SetNetRotationAttr (const PODVector< unsigned char > &value)
 Set network rotation attribute.
void SetNetParentAttr (const PODVector< unsigned char > &value)
 Set network parent attribute.
const Vector3GetNetPositionAttr () const
 Return network position attribute.
const PODVector< unsigned char > & GetNetRotationAttr () const
 Return network rotation attribute.
const PODVector< unsigned char > & GetNetParentAttr () const
 Return network parent attribute.
bool Load (Deserializer &source, SceneResolver &resolver, bool loadChildren=true, bool rewriteIDs=false, CreateMode mode=REPLICATED)
 Load components and optionally load child nodes.
bool LoadXML (const XMLElement &source, SceneResolver &resolver, bool loadChildren=true, bool rewriteIDs=false, CreateMode mode=REPLICATED)
 Load components from XML data and optionally load child nodes.
const PODVector< Node * > & GetDependencyNodes () const
 Return the depended on nodes to order network updates.
void PrepareNetworkUpdate ()
 Prepare network update by comparing attributes and marking replication states dirty as necessary.
void CleanupConnection (Connection *connection)
 Clean up all references to a network connection that is about to be removed.
void MarkNetworkUpdate ()
 Mark for attribute check on the next network update.
void MarkReplicationDirty ()
 Mark node dirty in scene replication states.
NodeCreateChild (unsigned id, CreateMode mode)
 Create a child node with specific ID.
void AddComponent (Component *component, unsigned id, CreateMode mode)
 Add a pre-created component.
- Public Member Functions inherited from Urho3D::Serializable
 Serializable (Context *context)
 Construct.
virtual ~Serializable ()
 Destruct.
virtual void OnGetAttribute (const AttributeInfo &attr, Variant &dest)
 Handle attribute read access. Default implementation reads the variable at offset, or invokes the get accessor.
bool SetAttribute (unsigned index, const Variant &value)
 Set attribute by index. Return true if successfully set.
bool SetAttribute (const String &name, const Variant &value)
 Set attribute by name. Return true if successfully set.
void AllocateNetworkState ()
 Allocate network attribute state.
void WriteInitialDeltaUpdate (Serializer &dest)
 Write initial delta network update.
void WriteDeltaUpdate (Serializer &dest, const DirtyBits &attributeBits)
 Write a delta network update according to dirty attribute bits.
void WriteLatestDataUpdate (Serializer &dest)
 Write a latest data network update.
void ReadDeltaUpdate (Deserializer &source)
 Read and apply a network delta update.
void ReadLatestDataUpdate (Deserializer &source)
 Read and apply a network latest data update.
Variant GetAttribute (unsigned index)
 Return attribute value by index. Return empty if illegal index.
Variant GetAttribute (const String &name)
 Return attribute value by name. Return empty if not found.
unsigned GetNumAttributes () const
 Return number of attributes.
unsigned GetNumNetworkAttributes () const
 Return number of network replication attributes.
const Vector< AttributeInfo > * GetAttributes () const
 Return attribute descriptions, or null if none defined.
const Vector< AttributeInfo > * GetNetworkAttributes () const
 Return network replication attribute descriptions, or null if none defined.
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
virtual ~Object ()
 Destruct. Clean up self from event sender & receiver structures.
virtual ShortStringHash GetType () const =0
 Return type hash.
virtual const StringGetTypeName () const =0
 Return type name.
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
void SubscribeToEvent (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
void SubscribeToEvent (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
void UnsubscribeFromAllEventsExcept (const PODVector< StringHash > &exceptions, bool onlyUserData)
 Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events.)
void SendEvent (StringHash eventType)
 Send event to all subscribers.
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
ContextGetContext () const
 Return execution context.
ObjectGetSubsystem (ShortStringHash type) const
 Return subsystem by type.
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
void AddRef ()
 Increment reference count. Can also be called outside of a SharedPtr for traditional reference counting.
void ReleaseRef ()
 Decrement reference count and delete self if no more references. Can also be called outside of a SharedPtr for traditional reference counting.
int Refs () const
 Return reference count.
int WeakRefs () const
 Return weak reference count.
RefCountRefCountPtr ()
 Return pointer to the reference count structure.

Static Public Member Functions

static void RegisterObject (Context *context)
 Register object factory.

Protected Attributes

VariantMap vars_
 User variables.
- Protected Attributes inherited from Urho3D::Serializable
NetworkStatenetworkState_
 Network attribute state.
- Protected Attributes inherited from Urho3D::Object
Contextcontext_
 Execution context.

Private Member Functions

 OBJECT (Node)
void UpdateWorldTransform () const
 Recalculate the world transform.
void RemoveChild (Vector< SharedPtr< Node > >::Iterator i)
 Remove child node by iterator.
void GetChildrenRecursive (PODVector< Node * > &dest) const
 Return child nodes recursively.
void GetChildrenWithComponentRecursive (PODVector< Node * > &dest, ShortStringHash type) const
 Return child nodes with a specific component recursively.
NodeCloneRecursive (Node *parent, SceneResolver &resolver, CreateMode mode)
 Clone node recursively.
void RemoveComponent (Vector< SharedPtr< Component > >::Iterator i)
 Remove a component from this node with the specified iterator.

Private Attributes

Matrix3x4 worldTransform_
 World-space transform matrix.
bool dirty_
 World transform needs update flag.
bool networkUpdate_
 Network update queued flag.
unsigned short rotateCount_
 Consecutive rotation count for rotation renormalization.
Nodeparent_
 Parent scene node.
Scenescene_
 Scene (root node.)
unsigned id_
 Unique ID within the scene.
Vector3 position_
 Position.
Quaternion rotation_
 Rotation.
Vector3 scale_
 Scale.
Vector< SharedPtr< Component > > components_
 Components.
Vector< SharedPtr< Node > > children_
 Child scene nodes.
Vector< WeakPtr< Component > > listeners_
 Node listeners.
PODVector< Node * > dependencyNodes_
 Nodes this node depends on for network updates.
Connectionowner_
 Network owner connection.
String name_
 Name.
StringHash nameHash_
 Name hash.
VectorBuffer attrBuffer_
 Attribute buffer for network updates.

Friends

class Connection

Detailed Description

Scene node that may contain components and child nodes.


Member Function Documentation

void Urho3D::Node::RegisterObject ( Context context)
static

Register object factory.

Todo:
When position/rotation updates are received from the network, route to SmoothedTransform if exists

Reimplemented in Urho3D::Scene.


The documentation for this class was generated from the following files: