Urho3D
|
Root scene node, represents the whole scene. More...
#include <Scene.h>
Public Member Functions | |
Scene (Context *context) | |
Construct. | |
virtual | ~Scene () |
Destruct. | |
virtual bool | Load (Deserializer &source) |
Load from binary data. Return true if successful. | |
virtual bool | Save (Serializer &dest) |
Save to binary data. Return true if successful. | |
virtual bool | LoadXML (const XMLElement &source) |
Load from XML data. Return true if successful. | |
virtual void | AddReplicationState (NodeReplicationState *state) |
Add a replication state that is tracking this scene. | |
bool | LoadXML (Deserializer &source) |
Load from an XML file. Return true if successful. | |
bool | SaveXML (Serializer &dest) |
Save to an XML file. Return true if successful. | |
bool | LoadAsync (File *file) |
Load from a binary file asynchronously. Return true if started successfully. | |
bool | LoadAsyncXML (File *file) |
Load from an XML file asynchronously. Return true if started successfully. | |
void | StopAsyncLoading () |
Stop asynchronous loading. | |
Node * | Instantiate (Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) |
Instantiate scene content from binary data. Return root node if successful. | |
Node * | InstantiateXML (const XMLElement &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) |
Instantiate scene content from XML data. Return root node if successful. | |
Node * | InstantiateXML (Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) |
Instantiate scene content from XML data. Return root node if successful. | |
void | Clear () |
Clear scene completely of nodes and components. | |
void | SetActive (bool enable) |
Set active flag. Only active scenes will be updated automatically. | |
void | SetTimeScale (float scale) |
Set update time scale. 1.0 = real time (default.) | |
void | SetElapsedTime (float time) |
Set elapsed time in seconds. This can be used to prevent inaccuracy in the timer if the scene runs for a long time. | |
void | SetSmoothingConstant (float constant) |
Set network client motion smoothing constant. | |
void | SetSnapThreshold (float threshold) |
Set network client motion smoothing snap threshold. | |
void | AddRequiredPackageFile (PackageFile *package) |
Add a required package file for networking. To be called on the server. | |
void | ClearRequiredPackageFiles () |
Clear required package files. | |
void | RegisterVar (const String &name) |
Register a node user variable hash reverse mapping (for editing.) | |
void | UnregisterVar (const String &name) |
Unregister a node user variable hash reverse mapping. | |
void | UnregisterAllVars () |
Clear all registered node user variable hash reverse mappings. | |
Node * | GetNode (unsigned id) const |
Return node from the whole scene by ID, or null if not found. | |
Component * | GetComponent (unsigned id) const |
Return component from the whole scene by ID, or null if not found. | |
bool | IsActive () const |
Return active flag. | |
bool | IsAsyncLoading () const |
Return asynchronous loading flag. | |
float | GetAsyncProgress () const |
Return asynchronous loading progress between 0.0 and 1.0, or 1.0 if not in progress. | |
const String & | GetFileName () const |
Return source file name. | |
unsigned | GetChecksum () const |
Return source file checksum. | |
float | GetTimeScale () const |
Return update time scale. | |
float | GetElapsedTime () const |
Return elapsed time in seconds. | |
float | GetSmoothingConstant () const |
Return motion smoothing constant. | |
float | GetSnapThreshold () const |
Return motion smoothing snap threshold. | |
const Vector< SharedPtr < PackageFile > > & | GetRequiredPackageFiles () const |
Return required package files. | |
const String & | GetVarName (ShortStringHash hash) const |
Return a node user variable name, or empty if not registered. | |
void | Update (float timeStep) |
Update scene. Called by HandleUpdate. | |
void | BeginThreadedUpdate () |
Begin a threaded update. During threaded update components can choose to delay dirty processing. | |
void | EndThreadedUpdate () |
End a threaded update. Notify components that marked themselves for delayed dirty processing. | |
void | DelayedMarkedDirty (Component *component) |
Add a component to the delayed dirty notify queue. Is thread-safe. | |
bool | IsThreadedUpdate () const |
Return threaded update flag. | |
unsigned | GetFreeNodeID (CreateMode mode) |
Get free node ID, either non-local or local. | |
unsigned | GetFreeComponentID (CreateMode mode) |
Get free component ID, either non-local or local. | |
void | NodeAdded (Node *node) |
Node added. Assign scene pointer and add to ID map. | |
void | NodeRemoved (Node *node) |
Node removed. Remove from ID map. | |
void | ComponentAdded (Component *component) |
Component added. Add to ID map. | |
void | ComponentRemoved (Component *component) |
Component removed. Remove from ID map. | |
void | SetVarNamesAttr (String value) |
Set node user variable reverse mappings. | |
String | GetVarNamesAttr () const |
Return node user variable reverse mappings. | |
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 (Node *node) |
Mark a node for attribute check on the next network update. | |
void | MarkNetworkUpdate (Component *component) |
Mark a comoponent for attribute check on the next network update. | |
void | MarkReplicationDirty (Node *node) |
Mark a node dirty in scene replication states. The node does not need to have own replication state yet. | |
![]() | |
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 | 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. | |
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. | |
Node * | CreateChild (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. | |
Component * | CreateComponent (ShortStringHash type, CreateMode mode=REPLICATED, unsigned id=0) |
Create a component to this node (with specified ID if provided). | |
Component * | GetOrCreateComponent (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. | |
Node * | Clone (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 String & | GetName () const |
Return name. | |
StringHash | GetNameHash () const |
Return name hash. | |
Node * | GetParent () const |
Return parent scene node. | |
Scene * | GetScene () const |
Return scene. | |
Connection * | GetOwner () const |
Return owner connection in networking. | |
const Vector3 & | GetPosition () const |
Return position relative to parent node. | |
const Quaternion & | GetRotation () const |
Return rotation relative to parent node. | |
Vector3 | GetDirection () const |
Return direction relative to parent node. Identity rotation equals positive Z. | |
const Vector3 & | GetScale () 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 Matrix3x4 & | GetWorldTransform () 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. | |
Node * | GetChild (unsigned index) const |
Return child scene node by index. | |
Node * | GetChild (const String &name, bool recursive=false) const |
Return child scene node by name. | |
Node * | GetChild (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. | |
Component * | GetComponent (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 Variant & | GetVar (ShortStringHash key) const |
Return a user variable. | |
const VariantMap & | GetVars () 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 Vector3 & | GetNetPositionAttr () 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 | MarkNetworkUpdate () |
Mark for attribute check on the next network update. | |
void | MarkReplicationDirty () |
Mark node dirty in scene replication states. | |
Node * | CreateChild (unsigned id, CreateMode mode) |
Create a child node with specific ID. | |
void | AddComponent (Component *component, unsigned id, CreateMode mode) |
Add a pre-created component. | |
![]() | |
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. | |
![]() | |
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 String & | GetTypeName () 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. | |
Context * | GetContext () const |
Return execution context. | |
Object * | GetSubsystem (ShortStringHash type) const |
Return subsystem by type. | |
Object * | GetEventSender () const |
Return active event sender. Null outside event handling. | |
EventHandler * | GetEventHandler () 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. | |
![]() | |
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. | |
RefCount * | RefCountPtr () |
Return pointer to the reference count structure. |
Static Public Member Functions | |
static void | RegisterObject (Context *context) |
Register object factory. Node must be registered first. |
Private Member Functions | |
OBJECT (Scene) | |
void | HandleUpdate (StringHash eventType, VariantMap &eventData) |
Handle the logic update event to update the scene, if active. | |
void | UpdateAsyncLoading () |
Update asynchronous loading. | |
void | FinishAsyncLoading () |
Finish asynchronous loading. | |
void | FinishLoading (Deserializer *source) |
Finish loading. Sets the scene filename and checksum. |
Private Attributes | |
HashMap< unsigned, Node * > | replicatedNodes_ |
Replicated scene nodes by ID. | |
HashMap< unsigned, Node * > | localNodes_ |
Local scene nodes by ID. | |
HashMap< unsigned, Component * > | replicatedComponents_ |
Replicated components by ID. | |
HashMap< unsigned, Component * > | localComponents_ |
Local components by ID. | |
AsyncProgress | asyncProgress_ |
Asynchronous loading progress. | |
SceneResolver | resolver_ |
Node and component ID resolver for asynchronous loading. | |
String | fileName_ |
Source file name. | |
Vector< SharedPtr< PackageFile > > | requiredPackageFiles_ |
Required package files for networking. | |
HashMap< ShortStringHash, String > | varNames_ |
Registered node user variable reverse mappings. | |
HashSet< unsigned > | networkUpdateNodes_ |
Nodes to check for attribute changes on the next network update. | |
HashSet< unsigned > | networkUpdateComponents_ |
Components to check for attribute changes on the next network update. | |
PODVector< Component * > | delayedDirtyComponents_ |
Delayed dirty notification queue for components. | |
Mutex | sceneMutex_ |
Mutex for the delayed dirty notification queue. | |
unsigned | replicatedNodeID_ |
Next free non-local node ID. | |
unsigned | replicatedComponentID_ |
Next free non-local component ID. | |
unsigned | localNodeID_ |
Next free local node ID. | |
unsigned | localComponentID_ |
Next free local component ID. | |
unsigned | checksum_ |
Scene source file checksum. | |
float | timeScale_ |
Scene update time scale. | |
float | elapsedTime_ |
Elapsed time accumulator. | |
float | smoothingConstant_ |
Motion smoothing constant. | |
float | snapThreshold_ |
Motion smoothing snap threshold. | |
bool | active_ |
Active flag. | |
bool | asyncLoading_ |
Asynchronous loading flag. | |
bool | threadedUpdate_ |
Threaded update flag. |
Additional Inherited Members | |
![]() | |
VariantMap | vars_ |
User variables. | |
![]() | |
NetworkState * | networkState_ |
Network attribute state. | |
![]() | |
Context * | context_ |
Execution context. |
Root scene node, represents the whole scene.