| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- $#include "IO/File.h"
- $#include "LuaScript/LuaFile.h"
- $#include "LuaScript/LuaScriptInstance.h"
- $#include "Scene/Node.h"
- $#include "Resource/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 String indentation = "\t") const;
- tolua_outside bool NodeSaveJSON @ SaveJSON(File* dest, const String indentation = "\t") const;
- void SetName(const String name);
- void AddTag(const String tag);
- void AddTags(const String tags, char separator);
- bool RemoveTag(const String tag);
- void RemoveAllTags();
- 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 SetTransform(const Matrix3x4& transform);
- 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, bool temporary = false);
- Node* CreateTemporaryChild(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 RemoveComponents(bool removeReplicated, bool removeLocal);
- void RemoveComponents(const String type);
- void RemoveAllComponents();
- void ReorderComponent(Component* component, unsigned index);
- 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 <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
- Component* CreateComponent(const String type, CreateMode mode = REPLICATED, unsigned id = 0);
- // template <class T> T* GetOrCreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
- Component* GetOrCreateComponent(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 IsChildOf(Node* node) 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;
- Vector3 GetSignedWorldScale() 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 <class T> T* GetComponent() const;
- Component* GetComponent(const String type, bool recursive = false) const;
- // template <class T> T* GetParentComponent() const;
- Component* GetParentComponent(const String type, bool recursive = false) const;
- // template <class T> void GetComponents(PODVector<T*>& dest, bool recursive = false) const;
- tolua_outside const PODVector<Component*>& NodeGetComponentsWithType @ GetComponents(const String type, bool recursive = false);
- // void GetChildren(PODVector<Node*>& dest, bool recursive = false) const;
- tolua_outside const PODVector<Node*>& NodeGetChildren @ GetChildren(bool recursive = false);
- // template <class T> void GetChildrenWithComponent(PODVector<Node*>& dest, bool recursive = false) const;
- tolua_outside const PODVector<Node*>& NodeGetChildrenWithComponent @ GetChildrenWithComponent(const String type, bool recursive = false);
- 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);
- bool LoadJSON(const JSONValue& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
- Node* CreateChild(unsigned id, CreateMode mode, bool temporary = false);
- void AddComponent(Component* component, unsigned id, CreateMode mode);
- bool HasTag(const String tag) const;
- const StringVector& GetTags() const;
- // void GetChildrenWithTag(PODVector<Node*>& dest, const String& tag, bool recursive = false) const;
- tolua_outside const PODVector<Node*>& NodeGetChildrenWithTag @ GetChildrenWithTag(const String& tag, bool recursive = false) const;
- void SetID(unsigned id);
- tolua_readonly 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_readonly 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_readonly tolua_property__get_set Vector3 signedWorldScale;
- 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<Node>(tolua_S);
- }
- #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_new00_local
- static int tolua_SceneLuaAPI_Node_new00_local(lua_State* tolua_S)
- {
- return ToluaNewObjectGC<Node>(tolua_S);
- }
- static bool NodeSaveXML(const Node* node, File* file, const String& indentation)
- {
- return file ? node->SaveXML(*file, indentation) : false;
- }
- static bool NodeSaveJSON(const Node* node, File* file, const String& indentation)
- {
- return file ? node->SaveJSON(*file, indentation) : 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<LuaScriptInstance>();
- 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<ResourceCache>();
- LuaFile* scriptFile = cache->GetResource<LuaFile>(fileName);
- if (!scriptFile)
- {
- lua_pushnil(tolua_S);
- return 1;
- }
- LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
- 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<LuaScriptInstance>();
- 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<LuaScriptInstance*> instances;
- self->GetComponents<LuaScriptInstance>(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);
- }
- static const PODVector<Component*>& NodeGetComponentsWithType(Node* node, String type, bool recursive)
- {
- static PODVector<Component*> result;
- result.Clear();
- node->GetComponents(result, type, recursive);
- return result;
- }
- static const PODVector<Node*>& NodeGetChildren(Node* node, bool recursive)
- {
- static PODVector<Node*> result;
- result.Clear();
- node->GetChildren(result, recursive);
- return result;
- }
- static const PODVector<Node*>& NodeGetChildrenWithComponent(Node* node, String type, bool recursive)
- {
- static PODVector<Node*> result;
- result.Clear();
- node->GetChildrenWithComponent(result, type, recursive);
- return result;
- }
- static const PODVector<Node*>& NodeGetChildrenWithTag(const Node* node, const String& tag, bool recursive)
- {
- static PODVector<Node*> result;
- result.Clear();
- node->GetChildrenWithTag(result, tag, recursive);
- return result;
- }
- $}
|