From 7159a7751850ffaf4abb42d85a88ae3c5399e935 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Tue, 1 Sep 2015 00:53:42 +0200 Subject: [PATCH] updated lua bindings --- .../DeferredRenderableComponent_BindLua.cpp | 13 ++ .../ForwardRenderableComponent_BindLua.cpp | 13 ++ .../Renderable3DComponent_BindLua.cpp | 172 ++++++++++++++++ WickedEngine/Renderable3DComponent_BindLua.h | 13 ++ WickedEngine/Vector_BindLua.cpp | 12 ++ WickedEngine/Vector_BindLua.h | 2 + WickedEngine/wiLoader.h | 37 +++- WickedEngine/wiLoader_BindLua.cpp | 193 +++++++++++++++++- WickedEngine/wiLoader_BindLua.h | 29 +++ WickedEngine/wiRenderer.cpp | 43 ++-- WickedEngine/wiRenderer.h | 1 + WickedEngine/wiRenderer_BindLua.cpp | 20 ++ WickedEngine/wiRenderer_BindLua.h | 2 + 13 files changed, 524 insertions(+), 26 deletions(-) diff --git a/WickedEngine/DeferredRenderableComponent_BindLua.cpp b/WickedEngine/DeferredRenderableComponent_BindLua.cpp index d1c97f65c..213d69b27 100644 --- a/WickedEngine/DeferredRenderableComponent_BindLua.cpp +++ b/WickedEngine/DeferredRenderableComponent_BindLua.cpp @@ -12,6 +12,19 @@ Luna::FunctionType DeferredRenderableCompon lunamethod(DeferredRenderableComponent_BindLua, Update), lunamethod(DeferredRenderableComponent_BindLua, Render), lunamethod(DeferredRenderableComponent_BindLua, Compose), + + lunamethod(Renderable3DComponent_BindLua, SetSSAOEnabled), + lunamethod(Renderable3DComponent_BindLua, SetSSREnabled), + lunamethod(Renderable3DComponent_BindLua, SetShadowsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetReflectionsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetFXAAEnabled), + lunamethod(Renderable3DComponent_BindLua, SetBloomEnabled), + lunamethod(Renderable3DComponent_BindLua, SetColorGradingEnabled), + lunamethod(Renderable3DComponent_BindLua, SetEmitterParticlesEnabled), + lunamethod(Renderable3DComponent_BindLua, SetHairParticlesEnabled), + lunamethod(Renderable3DComponent_BindLua, SetVolumeLightsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetLightShaftsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetLensFlareEnabled), { NULL, NULL } }; Luna::PropertyType DeferredRenderableComponent_BindLua::properties[] = { diff --git a/WickedEngine/ForwardRenderableComponent_BindLua.cpp b/WickedEngine/ForwardRenderableComponent_BindLua.cpp index b3c7ce705..ce2e1adb2 100644 --- a/WickedEngine/ForwardRenderableComponent_BindLua.cpp +++ b/WickedEngine/ForwardRenderableComponent_BindLua.cpp @@ -12,6 +12,19 @@ Luna::FunctionType ForwardRenderableComponen lunamethod(ForwardRenderableComponent_BindLua, Update), lunamethod(ForwardRenderableComponent_BindLua, Render), lunamethod(ForwardRenderableComponent_BindLua, Compose), + + lunamethod(Renderable3DComponent_BindLua, SetSSAOEnabled), + lunamethod(Renderable3DComponent_BindLua, SetSSREnabled), + lunamethod(Renderable3DComponent_BindLua, SetShadowsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetReflectionsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetFXAAEnabled), + lunamethod(Renderable3DComponent_BindLua, SetBloomEnabled), + lunamethod(Renderable3DComponent_BindLua, SetColorGradingEnabled), + lunamethod(Renderable3DComponent_BindLua, SetEmitterParticlesEnabled), + lunamethod(Renderable3DComponent_BindLua, SetHairParticlesEnabled), + lunamethod(Renderable3DComponent_BindLua, SetVolumeLightsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetLightShaftsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetLensFlareEnabled), { NULL, NULL } }; Luna::PropertyType ForwardRenderableComponent_BindLua::properties[] = { diff --git a/WickedEngine/Renderable3DComponent_BindLua.cpp b/WickedEngine/Renderable3DComponent_BindLua.cpp index d927b3916..6082911a8 100644 --- a/WickedEngine/Renderable3DComponent_BindLua.cpp +++ b/WickedEngine/Renderable3DComponent_BindLua.cpp @@ -13,6 +13,19 @@ Luna::FunctionType Renderable3DComponent_BindLua: lunamethod(Renderable3DComponent_BindLua, Update), lunamethod(Renderable3DComponent_BindLua, Render), lunamethod(Renderable3DComponent_BindLua, Compose), + + lunamethod(Renderable3DComponent_BindLua, SetSSAOEnabled), + lunamethod(Renderable3DComponent_BindLua, SetSSREnabled), + lunamethod(Renderable3DComponent_BindLua, SetShadowsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetReflectionsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetFXAAEnabled), + lunamethod(Renderable3DComponent_BindLua, SetBloomEnabled), + lunamethod(Renderable3DComponent_BindLua, SetColorGradingEnabled), + lunamethod(Renderable3DComponent_BindLua, SetEmitterParticlesEnabled), + lunamethod(Renderable3DComponent_BindLua, SetHairParticlesEnabled), + lunamethod(Renderable3DComponent_BindLua, SetVolumeLightsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetLightShaftsEnabled), + lunamethod(Renderable3DComponent_BindLua, SetLensFlareEnabled), { NULL, NULL } }; Luna::PropertyType Renderable3DComponent_BindLua::properties[] = { @@ -33,6 +46,165 @@ Renderable3DComponent_BindLua::~Renderable3DComponent_BindLua() { } + +int Renderable3DComponent_BindLua::SetSSAOEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetSSAOEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setSSAOEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetSSAOEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetSSREnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetSSREnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setSSREnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetSSREnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetShadowsEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetShadowsEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setShadowsEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetShadowsEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetReflectionsEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetShadowsEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setShadowsEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetShadowsEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetFXAAEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetFXAAEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setFXAAEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetFXAAEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetBloomEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetBloomEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setBloomEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetBloomEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetColorGradingEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetColorGradingEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setColorGradingEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetColorGradingEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetEmitterParticlesEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetEmitterParticlesEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setEmitterParticlesEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetEmitterParticlesEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetHairParticlesEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetHairParticlesEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setHairParticlesEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetHairParticlesEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetVolumeLightsEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetVolumeLightsEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setVolumeLightsEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetVolumeLightsEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetLightShaftsEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetLightShaftsEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setLightShaftsEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetLightShaftsEnabled(bool value) not enough arguments!"); + return 0; +} +int Renderable3DComponent_BindLua::SetLensFlareEnabled(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetLensFlareEnabled(bool value) component is null!"); + return 0; + } + if (wiLua::SGetArgCount(L) > 1) + ((Renderable3DComponent*)component)->setLensFlareEnabled(wiLua::SGetBool(L, 2)); + else + wiLua::SError(L, "SetLensFlareEnabled(bool value) not enough arguments!"); + return 0; +} + + void Renderable3DComponent_BindLua::Bind() { static bool initialized = false; diff --git a/WickedEngine/Renderable3DComponent_BindLua.h b/WickedEngine/Renderable3DComponent_BindLua.h index 0c09a3dda..754ca29f1 100644 --- a/WickedEngine/Renderable3DComponent_BindLua.h +++ b/WickedEngine/Renderable3DComponent_BindLua.h @@ -15,6 +15,19 @@ public: Renderable3DComponent_BindLua(lua_State* L); ~Renderable3DComponent_BindLua(); + int SetSSAOEnabled(lua_State* L); + int SetSSREnabled(lua_State* L); + int SetShadowsEnabled(lua_State* L); + int SetReflectionsEnabled(lua_State* L); + int SetFXAAEnabled(lua_State* L); + int SetBloomEnabled(lua_State* L); + int SetColorGradingEnabled(lua_State* L); + int SetEmitterParticlesEnabled(lua_State* L); + int SetHairParticlesEnabled(lua_State* L); + int SetVolumeLightsEnabled(lua_State* L); + int SetLightShaftsEnabled(lua_State* L); + int SetLensFlareEnabled(lua_State* L); + static void Bind(); }; diff --git a/WickedEngine/Vector_BindLua.cpp b/WickedEngine/Vector_BindLua.cpp index b1c193b83..4ef0a3243 100644 --- a/WickedEngine/Vector_BindLua.cpp +++ b/WickedEngine/Vector_BindLua.cpp @@ -16,6 +16,8 @@ Luna::FunctionType Vector_BindLua::methods[] = { lunamethod(Vector_BindLua, SetZ), lunamethod(Vector_BindLua, SetW), lunamethod(Vector_BindLua, Transform), + lunamethod(Vector_BindLua, Length), + lunamethod(Vector_BindLua, Normalize), { NULL, NULL } }; Luna::PropertyType Vector_BindLua::properties[] = { @@ -138,6 +140,16 @@ int Vector_BindLua::Transform(lua_State* L) wiLua::SError(L, "Transform(Matrix matrix) not enough arguments!"); return 0; } +int Vector_BindLua::Length(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMVector3Length(vector))); + return 1; +} +int Vector_BindLua::Normalize(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMVector3Normalize(vector))); + return 1; +} diff --git a/WickedEngine/Vector_BindLua.h b/WickedEngine/Vector_BindLua.h index 4f2b69c98..61fedc5ac 100644 --- a/WickedEngine/Vector_BindLua.h +++ b/WickedEngine/Vector_BindLua.h @@ -28,6 +28,8 @@ public: int SetW(lua_State* L); int Transform(lua_State* L); + int Length(lua_State* L); + int Normalize(lua_State* L); static int Dot(lua_State* L); static int Cross(lua_State* L); diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index 6410ce5b9..220bd1f1f 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -414,13 +414,7 @@ struct Transform : public Node, public Load_Debug_Properties int copyParentT,copyParentR,copyParentS; Transform():Node(){ - parent=nullptr; - copyParentT=copyParentR=copyParentS=1; - boneRelativity=boneRelativityPrev=nullptr; - translation_rest=translation=translationPrev=XMFLOAT3(0,0,0); - scale_rest=scale=scalePrev=XMFLOAT3(1,1,1); - rotation_rest=rotation=rotationPrev=XMFLOAT4(0,0,0,1); - world_rest=world=worldPrev=parent_inv_rest=XMFLOAT4X4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1); + Clear(); } ~Transform(){ if(boneRelativity!=nullptr){ @@ -432,6 +426,16 @@ struct Transform : public Node, public Load_Debug_Properties boneRelativityPrev=nullptr; } }; + void Clear() + { + parent = nullptr; + copyParentT = copyParentR = copyParentS = 1; + boneRelativity = boneRelativityPrev = nullptr; + translation_rest = translation = translationPrev = XMFLOAT3(0, 0, 0); + scale_rest = scale = scalePrev = XMFLOAT3(1, 1, 1); + rotation_rest = rotation = rotationPrev = XMFLOAT4(0, 0, 0, 1); + world_rest = world = worldPrev = parent_inv_rest = XMFLOAT4X4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + } virtual XMMATRIX getTransform(int getTranslation = 1, int getRotation = 1, int getScale = 1); //attach to parent @@ -633,6 +637,7 @@ public: float currentFrame, prevActionResolveFrame; vector actions; + bool playing; Armature(){} Armature(string newName,string identifier):Transform(){ @@ -647,6 +652,7 @@ public: prevActionResolveFrame=0; actions.resize(0); XMStoreFloat4x4(&world,XMMatrixIdentity()); + playing = true; } void CleanUp(){ actions.clear(); @@ -671,6 +677,23 @@ public: } return false; } + void ResetAction() + { + currentFrame = 1; + } + void PauseAction() + { + playing = false; + } + void StopAction() + { + ResetAction(); + PauseAction(); + } + void PlayAction() + { + playing = true; + } }; struct SHCAM{ XMFLOAT4X4 View,Projection; diff --git a/WickedEngine/wiLoader_BindLua.cpp b/WickedEngine/wiLoader_BindLua.cpp index 5c0ed0497..4bb186f65 100644 --- a/WickedEngine/wiLoader_BindLua.cpp +++ b/WickedEngine/wiLoader_BindLua.cpp @@ -11,6 +11,7 @@ namespace wiLoader_BindLua Cullable_BindLua::Bind(); Object_BindLua::Bind(); Armature_BindLua::Bind(); + Ray_BindLua::Bind(); } } @@ -97,6 +98,8 @@ Luna::FunctionType Transform_BindLua::methods[] = { lunamethod(Transform_BindLua, Translate), lunamethod(Transform_BindLua, MatrixTransform), lunamethod(Transform_BindLua, GetMatrix), + lunamethod(Transform_BindLua, ClearTransform), + lunamethod(Transform_BindLua, SetTransform), { NULL, NULL } }; Luna::PropertyType Transform_BindLua::properties[] = { @@ -299,6 +302,36 @@ int Transform_BindLua::GetMatrix(lua_State* L) Luna::push(L, new Matrix_BindLua(transform->getTransform())); return 1; } +int Transform_BindLua::ClearTransform(lua_State* L) +{ + transform->Clear(); + return 0; +} +int Transform_BindLua::SetTransform(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + Transform_BindLua* t = Luna::lightcheck(L, 2); + if (t == nullptr) + t = Luna::lightcheck(L, 2); + if (t == nullptr) + t = Luna::lightcheck(L, 2); + if (t != nullptr) + { + *transform = *t->transform; + } + else + { + wiLua::SError(L, "SetTransform(Transform t) argument is not a Transform!"); + } + } + else + { + wiLua::SError(L, "SetTransform(Transform t) not enough arguments!"); + } + return 0; +} void Transform_BindLua::Bind() { @@ -355,7 +388,25 @@ int Cullable_BindLua::Intersects(lua_State* L) } else { - wiLua::SError(L, "Intersects(Cullable cullable) argument is not a Cullable!"); + Ray_BindLua* ray = Luna::lightcheck(L, 2); + if (ray != nullptr) + { + wiLua::SSetBool(L, cullable->bounds.intersects(ray->ray)); + return 1; + } + else + { + Vector_BindLua* vec = Luna::lightcheck(L, 2); + if (vec != nullptr) + { + XMFLOAT3 point; + XMStoreFloat3(&point, vec->vector); + wiLua::SSetBool(L, cullable->bounds.intersects(point)); + return 1; + } + else + wiLua::SError(L, "Intersects(Cullable cullable) argument is not a Cullable!"); + } } } else @@ -394,6 +445,8 @@ Luna::FunctionType Object_BindLua::methods[] = { lunamethod(Transform_BindLua, Translate), lunamethod(Transform_BindLua, MatrixTransform), lunamethod(Transform_BindLua, GetMatrix), + lunamethod(Transform_BindLua, ClearTransform), + lunamethod(Transform_BindLua, SetTransform), lunamethod(Object_BindLua, SetTransparency), lunamethod(Object_BindLua, GetTransparency), @@ -506,10 +559,19 @@ Luna::FunctionType Armature_BindLua::methods[] = { lunamethod(Transform_BindLua, Translate), lunamethod(Transform_BindLua, MatrixTransform), lunamethod(Transform_BindLua, GetMatrix), + lunamethod(Transform_BindLua, ClearTransform), + lunamethod(Transform_BindLua, SetTransform), + lunamethod(Armature_BindLua, GetAction), lunamethod(Armature_BindLua, GetActions), lunamethod(Armature_BindLua, GetBones), + lunamethod(Armature_BindLua, GetFrame), + lunamethod(Armature_BindLua, GetFrameCount), lunamethod(Armature_BindLua, ChangeAction), + lunamethod(Armature_BindLua, StopAction), + lunamethod(Armature_BindLua, PauseAction), + lunamethod(Armature_BindLua, PlayAction), + lunamethod(Armature_BindLua, ResetAction), { NULL, NULL } }; Luna::PropertyType Armature_BindLua::properties[] = { @@ -531,6 +593,16 @@ Armature_BindLua::~Armature_BindLua() { } +int Armature_BindLua::GetAction(lua_State* L) +{ + if (armature == nullptr) + { + wiLua::SError(L, "GetAction() armature is null!"); + return 0; + } + wiLua::SSetString(L, armature->actions[armature->activeAction].name); + return 1; +} int Armature_BindLua::GetActions(lua_State *L) { if (armature == nullptr) @@ -561,6 +633,27 @@ int Armature_BindLua::GetBones(lua_State *L) wiLua::SSetString(L, ss.str()); return 1; } +int Armature_BindLua::GetFrame(lua_State* L) +{ + if (armature == nullptr) + { + wiLua::SError(L, "GetFrame() armature is null!"); + return 0; + } + wiLua::SSetFloat(L, armature->currentFrame); + return 1; +} +int Armature_BindLua::GetFrameCount(lua_State* L) +{ + if (armature == nullptr) + { + wiLua::SError(L, "GetFrameCount() armature is null!"); + return 0; + } + wiLua::SSetFloat(L, armature->actions[armature->activeAction].frameCount); + return 1; +} + int Armature_BindLua::ChangeAction(lua_State* L) { if (armature == nullptr) @@ -583,6 +676,46 @@ int Armature_BindLua::ChangeAction(lua_State* L) } return 0; } +int Armature_BindLua::StopAction(lua_State* L) +{ + if (armature == nullptr) + { + wiLua::SError(L, "StopAction() armature is null!"); + return 0; + } + armature->StopAction(); + return 0; +} +int Armature_BindLua::PauseAction(lua_State* L) +{ + if (armature == nullptr) + { + wiLua::SError(L, "PauseAction() armature is null!"); + return 0; + } + armature->PauseAction(); + return 0; +} +int Armature_BindLua::PlayAction(lua_State* L) +{ + if (armature == nullptr) + { + wiLua::SError(L, "PlayAction() armature is null!"); + return 0; + } + armature->PlayAction(); + return 0; +} +int Armature_BindLua::ResetAction(lua_State* L) +{ + if (armature == nullptr) + { + wiLua::SError(L, "ResetAction() armature is null!"); + return 0; + } + armature->ResetAction(); + return 0; +} void Armature_BindLua::Bind() { @@ -593,3 +726,61 @@ void Armature_BindLua::Bind() Luna::Register(wiLua::GetGlobal()->GetLuaState()); } } + + + + +const char Ray_BindLua::className[] = "Ray"; + +Luna::FunctionType Ray_BindLua::methods[] = { + { NULL, NULL } +}; +Luna::PropertyType Ray_BindLua::properties[] = { + { NULL, NULL } +}; + +Ray_BindLua::Ray_BindLua(const RAY& ray) :ray(ray) +{ +} +Ray_BindLua::Ray_BindLua(lua_State *L) +{ + int argc = wiLua::SGetArgCount(L); + XMVECTOR origin = XMVectorSet(0, 0, 0, 0), direction = XMVectorSet(0, 0, 1, 0); + if (argc > 0) + { + Vector_BindLua* v1 = Luna::lightcheck(L, 1); + if (v1) + origin = v1->vector; + if (argc > 1) + { + Vector_BindLua* v2 = Luna::lightcheck(L, 2); + if (v2) + direction = v2->vector; + } + } + ray = RAY(origin, direction); +} +Ray_BindLua::~Ray_BindLua() +{ +} + +int Ray_BindLua::GetOrigin(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat3(&ray.origin))); + return 1; +} +int Ray_BindLua::GetDirection(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat3(&ray.direction))); + return 1; +} + +void Ray_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 index 618accefd..fd6b346ea 100644 --- a/WickedEngine/wiLoader_BindLua.h +++ b/WickedEngine/wiLoader_BindLua.h @@ -49,6 +49,8 @@ public: int Translate(lua_State* L); int MatrixTransform(lua_State* L); int GetMatrix(lua_State* L); + int ClearTransform(lua_State* L); + int SetTransform(lua_State* L); static void Bind(); }; @@ -105,10 +107,37 @@ public: Armature_BindLua(lua_State* L); ~Armature_BindLua(); + int GetAction(lua_State* L); int GetActions(lua_State* L); int GetBones(lua_State* L); + int GetFrame(lua_State* L); + int GetFrameCount(lua_State* L); int ChangeAction(lua_State* L); + int StopAction(lua_State* L); + int PauseAction(lua_State* L); + int PlayAction(lua_State* L); + int ResetAction(lua_State* L); static void Bind(); }; + +class Ray_BindLua +{ +public: + RAY ray; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + Ray_BindLua(const RAY& ray); + Ray_BindLua(lua_State* L); + ~Ray_BindLua(); + + int GetOrigin(lua_State* L); + int GetDirection(lua_State* L); + + static void Bind(); +}; + diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 90cf1346e..802c7a7a6 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -1878,10 +1878,13 @@ void wiRenderer::Update(float amount) int activeAction = armature->activeAction; int prevAction = armature->prevAction; - cf = armature->currentFrame += amount; + cf = armature->currentFrame += (armature->playing ? amount : 0.f); maxCf = armature->actions[activeAction].frameCount; - if((int)cf>maxCf) - cf = armature->currentFrame = 1; + if ((int)cf > maxCf) + { + armature->ResetAction(); + cf = armature->currentFrame; + } { for (unsigned int j = 0; jrootbones.size(); ++j){ @@ -3836,42 +3839,40 @@ void wiRenderer::UpdateLights() } } -wiRenderer::Picked wiRenderer::Pick(long cursorX, long cursorY, PICKTYPE pickType) +wiRenderer::Picked wiRenderer::Pick(RAY& ray, PICKTYPE pickType) { - RAY ray = getPickRay(cursorX, cursorY); - CulledCollection culledwiRenderer; CulledList culledObjects; wiSPTree* searchTree = nullptr; switch (pickType) { case wiRenderer::PICK_OPAQUE: - searchTree=spTree; + searchTree = spTree; break; case wiRenderer::PICK_TRANSPARENT: - searchTree=spTree_trans; + searchTree = spTree_trans; break; case wiRenderer::PICK_WATER: - searchTree=spTree_water; + searchTree = spTree_water; break; default: break; } - if(searchTree) + if (searchTree) { - wiSPTree::getVisible(searchTree->root,ray,culledObjects); + wiSPTree::getVisible(searchTree->root, ray, culledObjects); vector pickPoints; RayIntersectMeshes(ray, culledObjects, pickPoints); - if(!pickPoints.empty()){ + if (!pickPoints.empty()){ Picked min = pickPoints.front(); - float mini = wiMath::DistanceSquared(min.position,ray.origin); - for(unsigned int i=1;i& points, bool dynamicObjects = true); static void CalculateVertexAO(Object* object); diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 1181acab4..8ec9f1192 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -3,6 +3,7 @@ #include "wiLoader.h" #include "wiHelper.h" #include "wiLoader_BindLua.h" +#include "Vector_BindLua.h" #include "Matrix_BindLua.h" namespace wiRenderer_BindLua @@ -34,6 +35,7 @@ namespace wiRenderer_BindLua wiLua::GetGlobal()->RegisterFunc("LoadModel", LoadModel); wiLua::GetGlobal()->RegisterFunc("FinishLoading", FinishLoading); + wiLua::GetGlobal()->RegisterFunc("Pick", Pick); } } @@ -255,4 +257,22 @@ namespace wiRenderer_BindLua wiRenderer::FinishLoading(); return 0; } + + int Pick(lua_State* L) + { + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Ray_BindLua* ray = Luna::lightcheck(L, 1); + if (ray != nullptr) + { + wiRenderer::Picked pick = wiRenderer::Pick(ray->ray, wiRenderer::PICKTYPE::PICK_OPAQUE); + Luna::push(L, new Object_BindLua(pick.object)); + Luna::push(L, new Vector_BindLua(XMLoadFloat3(&pick.position))); + Luna::push(L, new Vector_BindLua(XMLoadFloat3(&pick.normal))); + return 3; + } + } + return 0; + } }; diff --git a/WickedEngine/wiRenderer_BindLua.h b/WickedEngine/wiRenderer_BindLua.h index c041a44af..ebe6ab7f4 100644 --- a/WickedEngine/wiRenderer_BindLua.h +++ b/WickedEngine/wiRenderer_BindLua.h @@ -25,5 +25,7 @@ namespace wiRenderer_BindLua int LoadModel(lua_State* L); int FinishLoading(lua_State* L); + + int Pick(lua_State* L); };