| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- $#include "File.h"
- $#include "Node.h"
- $#include "LuaScriptInstance.h"
- enum CreateMode
- {
- REPLICATED = 0,
- LOCAL = 1
- };
- class Node : public Serializable
- {
- Node(Context* context);
- 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);
- tolua_outside void NodeTranslateXYZ @ TranslateXYZ(float x, float y, float z);
-
- void TranslateRelative(const Vector3& delta);
- tolua_outside void NodeTranslateRelativeXYZ @ TranslateRelativeXYZ(float x, float y, float z);
-
- void Rotate(const Quaternion& delta, bool fixedAxis = false);
- tolua_outside void NodeRotateXYZ @ RotateXYZ(float x, float y, float z, bool fixedAxis = false);
-
- void Pitch(float angle, bool fixedAxis = false);
- void Yaw(float angle, bool fixedAxis = false);
- void Roll(float angle, bool fixedAxis = false);
-
- void LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP);
- tolua_outside void NodeLookAtXYZ @ LookAtXYZ(float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f);
-
- 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);
- 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 <class T> 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;
-
- 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 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(unsigned index) const;
- Node* GetChild(const String name, bool recursive = false) const;
- Node* GetChild(StringHash nameHash, bool recursive = false) 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 <class T> 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_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_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;
- };
- ${
- 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)
- {
- node->Translate(Vector3(x, y, z));
- }
- static void NodeTranslateRelativeXYZ(Node* node, float x, float y, float z)
- {
- node->TranslateRelative(Vector3(x, y, z));
- }
- static void NodeRotateXYZ(Node* node, float x, float y, float z, bool fixedAxis = false)
- {
- node->Rotate(Quaternion(x, y, z), fixedAxis);
- }
- static void NodeLookAtXYZ(Node* node, float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f)
- {
- node->LookAt(Vector3(x, y, z), Vector3(upX, upY, upZ));
- }
- 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 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 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<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
- {
- LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
- if (!instance)
- lua_pushnil(tolua_S);
- else
- {
- instance->CreateObject(fileName, 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);
- }
- $}
|