diff --git a/WickedEngine/WickedEngine.vcxproj b/WickedEngine/WickedEngine.vcxproj
index ca91dc3cd..136f9ea21 100644
--- a/WickedEngine/WickedEngine.vcxproj
+++ b/WickedEngine/WickedEngine.vcxproj
@@ -387,6 +387,7 @@
+
@@ -429,6 +430,7 @@
+
diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters
index 482cd0e15..6a6988519 100644
--- a/WickedEngine/WickedEngine.vcxproj.filters
+++ b/WickedEngine/WickedEngine.vcxproj.filters
@@ -779,6 +779,9 @@
Lua Bindings
+
+ Lua Bindings
+
@@ -1729,6 +1732,9 @@
Lua Bindings
+
+ Lua Bindings
+
diff --git a/WickedEngine/wiLoader_BindLua.cpp b/WickedEngine/wiLoader_BindLua.cpp
new file mode 100644
index 000000000..519766632
--- /dev/null
+++ b/WickedEngine/wiLoader_BindLua.cpp
@@ -0,0 +1,100 @@
+#include "wiLoader_BindLua.h"
+
+namespace wiLoader_BindLua
+{
+ void Bind()
+ {
+ Object_BindLua::Bind();
+ }
+}
+
+const char Object_BindLua::className[] = "Object";
+
+Luna::FunctionType Object_BindLua::methods[] = {
+ lunamethod(Object_BindLua, SetTransparency),
+ lunamethod(Object_BindLua, GetTransparency),
+ lunamethod(Object_BindLua, SetColor),
+ lunamethod(Object_BindLua, GetColor),
+ { NULL, NULL }
+};
+Luna::PropertyType Object_BindLua::properties[] = {
+ { NULL, NULL }
+};
+
+Object_BindLua::Object_BindLua(Object* object) :object(object)
+{
+}
+Object_BindLua::Object_BindLua(lua_State *L)
+{
+ object = nullptr;
+}
+Object_BindLua::~Object_BindLua()
+{
+}
+
+int Object_BindLua::SetTransparency(lua_State *L)
+{
+ if (object == nullptr)
+ {
+ wiLua::SError(L, "SetTransparency(float value) object is null!");
+ return 0;
+ }
+ int argc = wiLua::SGetArgCount(L);
+ if (argc > 1)
+ {
+ object->transparency = wiLua::SGetFloat(L, 2);
+ }
+ else
+ {
+ wiLua::SError(L, "SetTransparency(float value) not enough arguments!");
+ }
+ return 0;
+}
+int Object_BindLua::GetTransparency(lua_State *L)
+{
+ if (object == nullptr)
+ {
+ wiLua::SError(L, "GetTransparency() object is null!");
+ return 0;
+ }
+ wiLua::SSetFloat(L, object->transparency);
+ return 1;
+}
+int Object_BindLua::SetColor(lua_State *L)
+{
+ if (object == nullptr)
+ {
+ wiLua::SError(L, "SetColor(float r, float g, float b) object is null!");
+ return 0;
+ }
+ int argc = wiLua::SGetArgCount(L);
+ if (argc > 3)
+ {
+ object->color = wiLua::SGetFloat3(L, 2);
+ }
+ else
+ {
+ wiLua::SError(L, "SetColor(float r, float g, float b) not enough arguments!");
+ }
+ return 0;
+}
+int Object_BindLua::GetColor(lua_State *L)
+{
+ if (object == nullptr)
+ {
+ wiLua::SError(L, "GetColor() object is null!");
+ return 0;
+ }
+ wiLua::SSetFloat3(L, object->color);
+ return 3;
+}
+
+void Object_BindLua::Bind()
+{
+ static bool initialized = false;
+ if (!initialized)
+ {
+ initialized = true;
+ Luna::Register(wiLua::GetGlobal()->GetLuaState());
+ }
+}
diff --git a/WickedEngine/wiLoader_BindLua.h b/WickedEngine/wiLoader_BindLua.h
new file mode 100644
index 000000000..e85889d77
--- /dev/null
+++ b/WickedEngine/wiLoader_BindLua.h
@@ -0,0 +1,31 @@
+#pragma once
+#include "wiLua.h"
+#include "wiLuna.h"
+#include "wiLoader.h"
+
+namespace wiLoader_BindLua
+{
+ void Bind();
+}
+
+class Object_BindLua
+{
+public:
+ Object* object;
+
+ static const char className[];
+ static Luna::FunctionType methods[];
+ static Luna::PropertyType properties[];
+
+ Object_BindLua(Object* object = nullptr);
+ Object_BindLua(lua_State *L);
+ ~Object_BindLua();
+
+ int SetTransparency(lua_State *L);
+ int GetTransparency(lua_State *L);
+ int SetColor(lua_State *L);
+ int GetColor(lua_State *L);
+
+ static void Bind();
+};
+
diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp
index 4c10263e4..c370b494c 100644
--- a/WickedEngine/wiLua.cpp
+++ b/WickedEngine/wiLua.cpp
@@ -14,6 +14,7 @@
#include "wiImageEffects_BindLua.h"
#include "SpriteAnim_BindLua.h"
#include "wiResourceManager_BindLua.h"
+#include "wiLoader_BindLua.h"
wiLua *wiLua::globalLua = nullptr;
@@ -54,6 +55,7 @@ wiLua* wiLua::GetGlobal()
wiImageEffects_BindLua::Bind();
SpriteAnim_BindLua::Bind();
wiResourceManager_BindLua::Bind();
+ wiLoader_BindLua::Bind();
}
return globalLua;
}
diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp
index eaf743669..d5635b3f6 100644
--- a/WickedEngine/wiRenderer.cpp
+++ b/WickedEngine/wiRenderer.cpp
@@ -1607,6 +1607,43 @@ HitSphere* wiRenderer::getSphereByName(const string& get){
return hs;
return nullptr;
}
+Object* wiRenderer::getObjectByName(const string& name)
+{
+ for (auto& x : objects)
+ {
+ if (!x->name.compare(name))
+ {
+ return x;
+ }
+ }
+ for (auto& x : objects_trans)
+ {
+ if (!x->name.compare(name))
+ {
+ return x;
+ }
+ }
+ for (auto& x : objects_water)
+ {
+ if (!x->name.compare(name))
+ {
+ return x;
+ }
+ }
+
+ return nullptr;
+}
+Light* wiRenderer::getLightByName(const string& name)
+{
+ for (auto& x : lights)
+ {
+ if (!x->name.compare(name))
+ {
+ return x;
+ }
+ }
+ return nullptr;
+}
void wiRenderer::RecursiveBoneTransform(Armature* armature, Bone* bone, const XMMATRIX& parentCombinedMat){
float cf = armature->currentFrame;
diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h
index 93e2c891c..67cb4f3c4 100644
--- a/WickedEngine/wiRenderer.h
+++ b/WickedEngine/wiRenderer.h
@@ -344,11 +344,6 @@ protected:
static Vertex TransformVertex(const Mesh* mesh, const SkinnedVertex& vertex, const XMMATRIX& mat = XMMatrixIdentity());
static XMFLOAT3 VertexVelocity(const Mesh* mesh, const int& vertexI);
- static Armature* getArmatureByName(const string& get);
- static int getActionByName(Armature* armature, const string& get);
- static int getBoneByName(Armature* armature, const string& get);
- static Material* getMaterialByName(const string& get);
- HitSphere* getSphereByName(const string& get);
static float GameSpeed,overrideGameSpeed;
@@ -387,6 +382,15 @@ public:
static TextureView GetEnviromentMap(){ return enviroMap; }
static void SetNoiseTexture(TextureView tex){ noiseTex = tex; }
static TextureView GetNoiseTexture(){ return noiseTex; }
+
+
+ static Armature* getArmatureByName(const string& get);
+ static int getActionByName(Armature* armature, const string& get);
+ static int getBoneByName(Armature* armature, const string& get);
+ static Material* getMaterialByName(const string& get);
+ HitSphere* getSphereByName(const string& get);
+ static Object* getObjectByName(const string& name);
+ static Light* getLightByName(const string& name);
private:
static vector textureSlotsPS;
diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp
index 5549b619b..1a6160f65 100644
--- a/WickedEngine/wiRenderer_BindLua.cpp
+++ b/WickedEngine/wiRenderer_BindLua.cpp
@@ -2,6 +2,7 @@
#include "wiRenderer.h"
#include "wiLoader.h"
#include "wiHelper.h"
+#include "wiLoader_BindLua.h"
namespace wiRenderer_BindLua
{
@@ -14,14 +15,13 @@ namespace wiRenderer_BindLua
initialized = true;
wiLua::GetGlobal()->RegisterFunc("GetArmatures", GetArmatures);
wiLua::GetGlobal()->RegisterFunc("GetObjects", GetObjects);
- wiLua::GetGlobal()->RegisterFunc("GetObjectProp", GetObjectProp);
+ wiLua::GetGlobal()->RegisterFunc("GetObject", GetObjectLua);
wiLua::GetGlobal()->RegisterFunc("GetMeshes", GetMeshes);
wiLua::GetGlobal()->RegisterFunc("GetLights", GetLights);
wiLua::GetGlobal()->RegisterFunc("GetMaterials", GetMaterials);
wiLua::GetGlobal()->RegisterFunc("GetGameSpeed", GetGameSpeed);
wiLua::GetGlobal()->RegisterFunc("GetMaterials", GetMaterials);
- wiLua::GetGlobal()->RegisterFunc("SetObjectProp", SetObjectProp);
wiLua::GetGlobal()->RegisterFunc("SetGameSpeed", SetGameSpeed);
wiLua::GetGlobal()->RegisterFunc("LoadModel", LoadModel);
@@ -58,73 +58,24 @@ namespace wiRenderer_BindLua
wiLua::SSetString(L, ss.str());
return 1;
}
- int GetObjectProp(lua_State* L)
+ int GetObjectLua(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
- if (argc > 1)
+ if (argc > 0)
{
- //name,property
string name = wiLua::SGetString(L, 1);
- string prop = wiHelper::toUpper( wiLua::SGetString(L, 2) );
- Object* found = nullptr;
- for (auto& x : wiRenderer::objects)
+ Object* object = wiRenderer::getObjectByName(name);
+ if (object != nullptr)
{
- if (!x->name.compare(name))
- {
- found = x;
- break;
- }
- }
- if (found == nullptr)
- {
- for (auto& x : wiRenderer::objects_trans)
- {
- if (!x->name.compare(name))
- {
- found = x;
- break;
- }
- }
- if (found == nullptr)
- {
- for (auto& x : wiRenderer::objects_water)
- {
- if (!x->name.compare(name))
- {
- found = x;
- break;
- }
- }
- }
- }
- if (found != nullptr)
- {
- if (prop.find("TRANSP")!=string::npos)
- {
- wiLua::SSetFloat(L, found->transparency);
- return 1;
- }
- else if (prop.find("COLOR")!=string::npos)
- {
- wiLua::SSetFloat3(L, found->color);
- return 3;
- }
- else
- {
- wiLua::SError(L, "GetObjectProp(string name,string property) no such property!");
- return 0;
- }
+ Luna::push(L, new Object_BindLua(object));
+ return 1;
}
else
{
- wiLua::SError(L, "GetObjectProp(string name,string property) no such object!");
+ wiLua::SError(L, "GetObject(String name) object not found!");
return 0;
}
}
- else
- {
- wiLua::SError(L, "GetObjectProp(string name,string property) not enough arguments!");
- }
return 0;
}
int GetMeshes(lua_State* L)
@@ -167,72 +118,6 @@ namespace wiRenderer_BindLua
}
- int SetObjectProp(lua_State* L)
- {
- int argc = wiLua::SGetArgCount(L);
- if (argc > 1)
- {
- //name,property
- string name = wiLua::SGetString(L, 1);
- string prop = wiHelper::toUpper(wiLua::SGetString(L, 2));
- Object* found = nullptr;
- for (auto& x : wiRenderer::objects)
- {
- if (!x->name.compare(name))
- {
- found = x;
- break;
- }
- }
- if (found == nullptr)
- {
- for (auto& x : wiRenderer::objects_trans)
- {
- if (!x->name.compare(name))
- {
- found = x;
- break;
- }
- }
- if (found == nullptr)
- {
- for (auto& x : wiRenderer::objects_water)
- {
- if (!x->name.compare(name))
- {
- found = x;
- break;
- }
- }
- }
- }
- if (found != nullptr)
- {
- if (prop.find("TRANSP") != string::npos)
- {
- found->transparency = wiLua::SGetFloat(L, 3);
- }
- else if (prop.find("COLOR") != string::npos)
- {
- found->color = wiLua::SGetFloat3(L, 3);
- }
- else
- {
- wiLua::SError(L, "GetObjectProp(string name,string property) no such property!");
- }
- }
- else
- {
- wiLua::SError(L, "GetObjectProp(string name,string property) no such object!");
- return 0;
- }
- }
- else
- {
- wiLua::SError(L, "GetObjectProp(string name,string property) not enough arguments!");
- }
- return 0;
- }
int SetGameSpeed(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
diff --git a/WickedEngine/wiRenderer_BindLua.h b/WickedEngine/wiRenderer_BindLua.h
index 51eb5f510..cc4964357 100644
--- a/WickedEngine/wiRenderer_BindLua.h
+++ b/WickedEngine/wiRenderer_BindLua.h
@@ -8,13 +8,12 @@ namespace wiRenderer_BindLua
int GetArmatures(lua_State* L);
int GetObjects(lua_State* L);
- int GetObjectProp(lua_State* L);
+ int GetObjectLua(lua_State* L);
int GetMeshes(lua_State* L);
int GetLights(lua_State* L);
int GetMaterials(lua_State* L);
int GetGameSpeed(lua_State* L);
- int SetObjectProp(lua_State* L);
int SetGameSpeed(lua_State* L);
int LoadModel(lua_State* L);