$#include "File.h" $#include "LuaFile.h" $#include "LuaScriptInstance.h" $#include "Node.h" $#include "ResourceCache.h" enum CreateMode { REPLICATED = 0, LOCAL = 1 }; enum TransformSpace { TS_LOCAL = 0, TS_PARENT, TS_WORLD }; class Node : public Animatable { Node(); virtual ~Node(); tolua_outside bool NodeSaveXML @ SaveXML(File* dest) const; void SetName(const String name); void SetPosition(const Vector3& position); void SetPosition2D(const Vector2& position); void SetPosition2D(float x, float y); void SetRotation(const Quaternion& rotation); void SetRotation2D(float rotation); void SetDirection(const Vector3& direction); void SetScale(float scale); void SetScale(const Vector3& scale); void SetScale2D(const Vector2& scale); void SetScale2D(float x, float y); void SetTransform(const Vector3& position, const Quaternion& rotation); void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale); void SetTransform(const Vector3& position, const Quaternion& rotation, float scale); void SetTransform2D(const Vector2& position, float rotation); void SetTransform2D(const Vector2& position, float rotation, const Vector2& scale); void SetTransform2D(const Vector2& position, float rotation, float scale); void SetWorldPosition(const Vector3& position); void SetWorldPosition2D(const Vector2& position); void SetWorldPosition2D(float x, float y); void SetWorldRotation(const Quaternion& rotation); void SetWorldRotation2D(float rotation); void SetWorldDirection(const Vector3& direction); void SetWorldScale(float scale); void SetWorldScale(const Vector3& scale); void SetWorldScale2D(const Vector2& scale); void SetWorldScale2D(float x, float y); void SetWorldTransform(const Vector3& position, const Quaternion& rotation); void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale); void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale); void SetWorldTransform2D(const Vector2& position, float rotation); void SetWorldTransform2D(const Vector2& position, float rotation, const Vector2& scale); void SetWorldTransform2D(const Vector2& position, float rotation, float scale); void Translate(const Vector3& delta, TransformSpace space = TS_LOCAL); void Translate2D(const Vector2& delta, TransformSpace space = TS_LOCAL); void Rotate(const Quaternion& delta, TransformSpace space = TS_LOCAL); void Rotate2D(float delta, TransformSpace space = TS_LOCAL); void RotateAround(const Vector3& point, const Quaternion& delta, TransformSpace space = TS_LOCAL); void RotateAround2D(const Vector2& point, float delta, TransformSpace space = TS_LOCAL); void Pitch(float angle, TransformSpace space = TS_LOCAL); void Yaw(float angle, TransformSpace space = TS_LOCAL); void Roll(float angle, TransformSpace space = TS_LOCAL); bool LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP, TransformSpace space = TS_WORLD); void Scale(float scale); void Scale(const Vector3& scale); void Scale2D(const Vector2& scale); void SetEnabled(bool enable); void SetDeepEnabled(bool enable); void ResetDeepEnabled(); void SetEnabledRecursive(bool enable); void SetOwner(Connection* owner); void MarkDirty(); Node* CreateChild(const String name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0); void AddChild(Node* node, unsigned index = M_MAX_UNSIGNED); void RemoveChild(Node* node); void RemoveAllChildren(); void RemoveChildren(bool removeReplicated, bool removeLocal, bool recursive); void RemoveComponent(Component* component); void RemoveComponent(StringHash type); void RemoveComponent(const String type); void RemoveAllComponents(); void RemoveComponents(bool removeReplicated, bool removeLocal); Node* Clone(CreateMode mode = REPLICATED); void Remove(); void SetParent(Node* parent); void SetVar(StringHash key, const Variant& value); void AddListener(Component* component); void RemoveListener(Component* component); // template T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0); Component* CreateComponent(const String type, CreateMode mode = REPLICATED, unsigned id = 0); Component* CloneComponent(Component* component, unsigned id = 0); Component* CloneComponent(Component* component, CreateMode mode, unsigned id = 0); int CreateScriptObject(const String scriptObjectType); int CreateScriptObject(const String fileName, const String scriptObjectType); int GetScriptObject() const; int GetScriptObject(const String scriptObjectType) const; unsigned GetID() const; const String GetName() const; StringHash GetNameHash() const; Node* GetParent() const; Scene* GetScene() const; bool IsEnabled() const; bool IsEnabledSelf() const; Connection* GetOwner() const; const Vector3& GetPosition() const; Vector2 GetPosition2D() const; const Quaternion& GetRotation() const; float GetRotation2D() const; Vector3 GetDirection() const; Vector3 GetUp() const; Vector3 GetRight() const; const Vector3& GetScale() const; Vector2 GetScale2D() const; Matrix3x4 GetTransform() const; Vector3 GetWorldPosition() const; Vector2 GetWorldPosition2D() const; Quaternion GetWorldRotation() const; float GetWorldRotation2D() const; Vector3 GetWorldDirection() const; Vector3 GetWorldUp() const; Vector3 GetWorldRight() const; Vector3 GetWorldScale() const; Vector2 GetWorldScale2D() const; const Matrix3x4& GetWorldTransform() const; Vector3 LocalToWorld(const Vector3& position) const; Vector3 LocalToWorld(const Vector4& vector) const; Vector2 LocalToWorld2D(const Vector2& vector) const; Vector3 WorldToLocal(const Vector3& position) const; Vector3 WorldToLocal(const Vector4& vector) const; Vector2 WorldToLocal2D(const Vector2& vector) const; bool IsDirty() const; unsigned GetNumChildren(bool recursive = false) const; Node* GetChild(const String name, bool recursive = false) const; Node* GetChild(StringHash nameHash, bool recursive = false) const; Node* GetChild(unsigned index) const; unsigned GetNumComponents() const; unsigned GetNumNetworkComponents() const; bool HasComponent(StringHash type) const; bool HasComponent(const String type) const; const Variant& GetVar(StringHash key) const; const VariantMap& GetVars() const; // template T* GetComponent() const; Component* GetComponent(const String type) const; void SetID(unsigned id); void SetScene(Scene* scene); void ResetScene(); bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED); bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED); Node* CreateChild(unsigned id, CreateMode mode); void AddComponent(Component* component, unsigned id, CreateMode mode); tolua_property__get_set unsigned ID; tolua_property__get_set String name; tolua_readonly tolua_property__get_set StringHash nameHash; tolua_property__get_set Node* parent; tolua_property__get_set Scene* scene; tolua_property__is_set bool enabled; tolua_readonly tolua_property__is_set bool enabledSelf; tolua_property__get_set Connection* owner; tolua_property__get_set Vector3& position; tolua_property__get_set Vector2 position2D; tolua_property__get_set Quaternion& rotation; tolua_property__get_set float rotation2D; tolua_property__get_set Vector3 direction; tolua_readonly tolua_property__get_set Vector3 up; tolua_readonly tolua_property__get_set Vector3 right; tolua_property__get_set Vector3& scale; tolua_property__get_set Vector2 scale2D; tolua_readonly tolua_property__get_set Matrix3x4 transform; tolua_property__get_set Vector3 worldPosition; tolua_property__get_set Vector2 worldPosition2D; tolua_property__get_set Quaternion worldRotation; tolua_property__get_set float worldRotation2D; tolua_property__get_set Vector3 worldDirection; tolua_readonly tolua_property__get_set Vector3 worldUp; tolua_readonly tolua_property__get_set Vector3 worldRight; tolua_property__get_set Vector3 worldScale; tolua_property__get_set Vector2 worldScale2D; tolua_readonly tolua_property__get_set Matrix3x4& worldTransform; tolua_readonly tolua_property__is_set bool dirty; tolua_readonly tolua_property__get_set unsigned numComponents; tolua_readonly tolua_property__get_set unsigned numNetworkComponents; }; ${ #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_new00 static int tolua_SceneLuaAPI_Node_new00(lua_State* tolua_S) { return ToluaNewObject(tolua_S); } #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_new00_local static int tolua_SceneLuaAPI_Node_new00_local(lua_State* tolua_S) { return ToluaNewObjectGC(tolua_S); } static bool NodeSaveXML(const Node* node, File* file) { return file ? node->SaveXML(*file) : false; } #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00 static int tolua_SceneLuaAPI_Node_CreateScriptObject00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) || !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else #endif { Node* self = (Node*) tolua_tousertype(tolua_S,1,0); const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL); #endif { LuaScriptInstance* instance = self->CreateComponent(); if (!instance) lua_pushnil(tolua_S); else { instance->CreateObject(scriptObjectType); // Push script object to Lua stack. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef()); } } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'CreateScriptObject'.",&tolua_err); return 0; #endif } #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject01 static int tolua_SceneLuaAPI_Node_CreateScriptObject01(lua_State* tolua_S) { tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) || !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) || !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) ) goto tolua_lerror; else { Node* self = (Node*) tolua_tousertype(tolua_S,1,0); const String fileName = ((const String) tolua_tourho3dstring(tolua_S,2,0)); const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL); #endif { ResourceCache* cache = self->GetSubsystem(); LuaFile* scriptFile = cache->GetResource(fileName); if (!scriptFile) { lua_pushnil(tolua_S); return 1; } LuaScriptInstance* instance = self->CreateComponent(); if (!instance) lua_pushnil(tolua_S); else { instance->CreateObject(scriptFile, scriptObjectType); // Push script object to Lua stack. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef()); } } } return 1; tolua_lerror: return tolua_SceneLuaAPI_Node_CreateScriptObject00(tolua_S); } #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject00 static int tolua_SceneLuaAPI_Node_GetScriptObject00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL); #endif { LuaScriptInstance* instance = self->GetComponent(); if (!instance) lua_pushnil(tolua_S); else lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef()); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'GetScriptObject'.",&tolua_err); return 0; #endif } #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject01 static int tolua_SceneLuaAPI_Node_GetScriptObject01(lua_State* tolua_S) { tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) || !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else { const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0); const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL); #endif { int scriptObjectRef = LUA_REFNIL; PODVector instances; self->GetComponents(instances, false); for (unsigned i = 0; i < instances.Size(); ++i) { if (instances[i]->GetScriptObjectType() == scriptObjectType) { scriptObjectRef = instances[i]->GetScriptObjectRef(); break; } } if (scriptObjectRef == LUA_REFNIL) lua_pushnil(tolua_S); else lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, scriptObjectRef); } } return 1; tolua_lerror: return tolua_SceneLuaAPI_Node_GetScriptObject00(tolua_S); } $}