$#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); tolua_outside void NodeSetPositionXYZ @ SetPositionXYZ(float x, float y, float z); void SetRotation(const Quaternion& rotation); tolua_outside void NodeSetRotationXYZ @ SetRotationXYZ(float x, float y, float z); void SetDirection(const Vector3& direction); tolua_outside void NodeSetDirectionXYZ @ SetDirectionXYZ(float x, float y, float z); void SetScale(float scale); void SetScale(const Vector3& scale); tolua_outside void NodeSetScaleXYZ @ SetScaleXYZ(float x, float y, float z); void SetTransform(const Vector3& position, const Quaternion& rotation); void SetTransform(const Vector3& position, const Quaternion& rotation, float scale); void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale); void SetWorldPosition(const Vector3& position); tolua_outside void NodeSetWorldPositionXYZ @ SetWorldPositionXYZ(float x, float y, float z); void SetWorldRotation(const Quaternion& rotation); tolua_outside void NodeSetWorldRotationXYZ @ SetWorldRotationXYZ(float x, float y, float z); void SetWorldDirection(const Vector3& direction); tolua_outside void NodeSetWorldDirectionXYZ @ SetWorldDirectionXYZ(float x, float y, float z); void SetWorldScale(float scale); void SetWorldScale(const Vector3& scale); tolua_outside void NodeSetWorldScaleXYZ @ SetWorldScaleXYZ(float x, float y, float z); void SetWorldTransform(const Vector3& position, const Quaternion& rotation); void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale); void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale); void Translate(const Vector3& delta, TransformSpace space = TS_LOCAL); tolua_outside void NodeTranslateXYZ @ TranslateXYZ(float x, float y, float z, TransformSpace space = TS_LOCAL); void Rotate(const Quaternion& delta, TransformSpace space = TS_LOCAL); tolua_outside void NodeRotateXYZ @ RotateXYZ(float x, float y, float z, TransformSpace space = TS_LOCAL); void RotateAround(const Vector3& point, const Quaternion& delta, TransformSpace space = TS_LOCAL); tolua_outside void NodeRotateAroundXYZ @ RotateAroundXYZ(float pX, float pY, float pZ, float dX, float dY, float dZ, 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); tolua_outside bool NodeLookAtXYZ @ LookAtXYZ(float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f, TransformSpace space = TS_WORLD); void Scale(float scale); void Scale(const Vector3& scale); tolua_outside void NodeScaleXYZ @ ScaleXYZ(float x, float y, float z); void SetEnabled(bool enable); void SetEnabled(bool enable, bool recursive); 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(ShortStringHash 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(ShortStringHash 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); 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; Connection* GetOwner() const; const Vector3& GetPosition() const; tolua_outside void NodeGetPositionXYZ @ GetPositionXYZ(float* x = 0.0f, float* y = 0.0f, float* z = 0.0f) const; const Quaternion& GetRotation() const; tolua_outside void NodeGetRotationXYZ @ GetRotationXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; tolua_outside void NodeGetRotationWXYZ @ GetRotationWXYZ(float* *w = 0.0f, float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Vector3 GetDirection() const; tolua_outside void NodeGetDirectionXYZ @ GetDirectionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Vector3 GetUp() const; tolua_outside void NodeGetUpXYZ @ GetUpXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Vector3 GetRight() const; tolua_outside void NodeGetRightXYZ @ GetRightXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; const Vector3& GetScale() const; tolua_outside void NodeGetScaleXYZ @ GetScaleXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Matrix3x4 GetTransform() const; Vector3 GetWorldPosition() const; tolua_outside void NodeGetWorldPositionXYZ @ GetWorldPositionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Quaternion GetWorldRotation() const; tolua_outside void NodeGetWorldRotationXYZ @ GetWorldRotationXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; tolua_outside void NodeGetWorldRotationWXYZ @ GetWorldRotationWXYZ(float* *w = 0.0f, float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Vector3 GetWorldDirection() const; tolua_outside void NodeGetWorldDirectionXYZ @ GetWorldDirectionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Vector3 GetWorldUp() const; tolua_outside void NodeGetWorldUpXYZ @ GetWorldUpXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Vector3 GetWorldRight() const; tolua_outside void NodeGetWorldRightXYZ @ GetWorldRightXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; Vector3 GetWorldScale() const; tolua_outside void NodeGetWorldScaleXYZ @ GetWorldScaleXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const; const Matrix3x4& GetWorldTransform() const; Vector3 LocalToWorld(const Vector3& position) const; Vector3 LocalToWorld(const Vector4& vector) const; Vector3 WorldToLocal(const Vector3& position) const; Vector3 WorldToLocal(const Vector4& 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(ShortStringHash type) const; bool HasComponent(const String type) const; const Variant& GetVar(ShortStringHash 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_property__get_set Connection* owner; tolua_property__get_set Vector3& position; tolua_property__get_set Quaternion& rotation; 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_readonly tolua_property__get_set Matrix3x4 transform; tolua_property__get_set Vector3 worldPosition; tolua_property__get_set Quaternion worldRotation; 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_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; } static void NodeSetPositionXYZ(Node* node, float x, float y, float z) { node->SetPosition(Vector3(x, y, z)); } static void NodeSetRotationXYZ(Node* node, float x, float y, float z) { node->SetRotation(Quaternion(x, y, z)); } static void NodeSetDirectionXYZ(Node* node, float x, float y, float z) { node->SetDirection(Vector3(x, y, z)); } static void NodeSetScaleXYZ(Node* node, float x, float y, float z) { node->SetScale(Vector3(x, y, z)); } static void NodeSetWorldPositionXYZ(Node* node, float x, float y, float z) { node->SetWorldPosition(Vector3(x, y, z)); } static void NodeSetWorldRotationXYZ(Node* node, float x, float y, float z) { node->SetWorldRotation(Quaternion(x, y, z)); } static void NodeSetWorldDirectionXYZ(Node* node, float x, float y, float z) { node->SetWorldDirection(Vector3(x, y, z)); } static void NodeSetWorldScaleXYZ(Node* node, float x, float y, float z) { node->SetWorldScale(Vector3(x, y, z)); } static void NodeTranslateXYZ(Node* node, float x, float y, float z, TransformSpace space = TS_LOCAL) { node->Translate(Vector3(x, y, z), space); } static void NodeRotateXYZ(Node* node, float x, float y, float z, TransformSpace space = TS_LOCAL) { node->Rotate(Quaternion(x, y, z), space); } static void NodeRotateAroundXYZ(Node* node, float pX, float pY, float pZ, float rX, float rY, float rZ, TransformSpace space = TS_LOCAL) { node->RotateAround(Vector3(pX, pY, pZ), Quaternion(rX, rY, rZ), space); } static bool NodeLookAtXYZ(Node* node, float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f, TransformSpace space = TS_WORLD) { return node->LookAt(Vector3(x, y, z), Vector3(upX, upY, upZ), space); } static void NodeScaleXYZ(Node* node, float x, float y, float z) { node->Scale(Vector3(x, y, z)); } static void NodeGetPositionXYZ(const Node* node, float* x, float* y, float* z) { const Vector3& position = node->GetPosition(); *x = position.x_; *y = position.y_; *z = position.z_; } static void NodeGetRotationXYZ(const Node* node, float* x, float* y, float* z) { const Quaternion& rotation = node->GetRotation(); *x = rotation.x_; *y = rotation.y_; *z = rotation.z_; } static void NodeGetRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z) { const Quaternion& rotation = node->GetRotation(); *w = rotation.w_; *x = rotation.x_; *y = rotation.y_; *z = rotation.z_; } static void NodeGetDirectionXYZ(const Node* node, float* x, float* y, float* z) { const Vector3& direction = node->GetDirection(); *x = direction.x_; *y = direction.y_; *z = direction.z_; } static void NodeGetUpXYZ(const Node* node, float* x, float* y, float* z) { const Vector3& up = node->GetUp(); *x = up.x_; *y = up.y_; *z = up.z_; } static void NodeGetRightXYZ(const Node* node, float* x, float* y, float* z) { const Vector3& right = node->GetRight(); *x = right.x_; *y = right.y_; *z = right.z_; } static void NodeGetScaleXYZ(const Node* node, float* x, float* y, float* z) { const Vector3& scale = node->GetScale(); *x = scale.x_; *y = scale.y_; *z = scale.z_; } static void NodeGetWorldPositionXYZ(const Node* node, float* x, float* y, float* z) { Vector3 worldPosition = node->GetWorldPosition(); *x = worldPosition.x_; *y = worldPosition.y_; *z = worldPosition.z_; } static void NodeGetWorldRotationXYZ(const Node* node, float* x, float* y, float* z) { Quaternion worldRotation = node->GetWorldRotation(); *x = worldRotation.x_; *y = worldRotation.y_; *z = worldRotation.z_; } static void NodeGetWorldRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z) { Quaternion worldRotation = node->GetWorldRotation(); *w = worldRotation.w_; *x = worldRotation.x_; *y = worldRotation.y_; *z = worldRotation.z_; } static void NodeGetWorldDirectionXYZ(const Node* node, float* x, float* y, float* z) { Vector3 worldDirection = node->GetWorldDirection(); *x = worldDirection.x_; *y = worldDirection.y_; *z = worldDirection.z_; } static void NodeGetWorldUpXYZ(const Node* node, float* x, float* y, float* z) { Vector3 worldUp = node->GetWorldUp(); *x = worldUp.x_; *y = worldUp.y_; *z = worldUp.z_; } static void NodeGetWorldRightXYZ(const Node* node, float* x, float* y, float* z) { Vector3 worldRight = node->GetWorldRight(); *x = worldRight.x_; *y = worldRight.y_; *z = worldRight.z_; } static void NodeGetWorldScaleXYZ(const Node* node, float* x, float* y, float* z) { Vector3 worldScale = node->GetWorldScale(); *x = worldScale.x_; *y = worldScale.y_; *z = worldScale.z_; } // Disable generated CreateComponent function. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateComponent00 static int tolua_SceneLuaAPI_Node_CreateComponent00(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_isnumber(tolua_S,3,1,&tolua_err) || !tolua_isnumber(tolua_S,4,1,&tolua_err) || !tolua_isnoobj(tolua_S,5,&tolua_err) ) goto tolua_lerror; else #endif { Node* self = (Node*) tolua_tousertype(tolua_S,1,0); const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0)); CreateMode mode = ((CreateMode) (int) tolua_tonumber(tolua_S,3,REPLICATED)); unsigned id = ((unsigned) tolua_tonumber(tolua_S,4,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateComponent'", NULL); #endif { Component* tolua_ret = (Component*) self->CreateComponent(type,mode,id); tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString()); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'CreateComponent'.",&tolua_err); return 0; #endif } // Disable generated GetComponent function. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetComponent00 static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE 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 #endif { const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0); const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetComponent'", NULL); #endif { Component* tolua_ret = (Component*) self->GetComponent(type); tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString()); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'GetComponent'.",&tolua_err); return 0; #endif } #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); } $}