From 3ae00c34e7f8f451c2f3a15a61df0ec1c666feeb Mon Sep 17 00:00:00 2001 From: turanszkij Date: Thu, 20 Sep 2018 18:47:21 +0100 Subject: [PATCH] refactors and start reworking scripting api --- Editor/AnimationWindow.cpp | 2 +- Editor/Editor.cpp | 126 +- Editor/Editor.h | 5 - Editor/ModelImporter_GLTF.cpp | 109 +- Editor/Translator.cpp | 1 - WickedEngine/WickedEngine_SHARED.vcxitems | 4 +- .../WickedEngine_SHARED.vcxitems.filters | 12 +- WickedEngine/wiInputManager.cpp | 28 +- WickedEngine/wiLua.cpp | 4 +- WickedEngine/wiRenderer_BindLua.cpp | 432 +--- WickedEngine/wiSceneComponents_BindLua.cpp | 2049 ----------------- WickedEngine/wiSceneComponents_BindLua.h | 297 --- WickedEngine/wiSceneSystem.cpp | 125 +- WickedEngine/wiSceneSystem.h | 36 +- WickedEngine/wiSceneSystem_BindLua.cpp | 392 ++++ WickedEngine/wiSceneSystem_BindLua.h | 62 + WickedEngine/wiSceneSystem_Serializers.cpp | 81 +- 17 files changed, 778 insertions(+), 2987 deletions(-) delete mode 100644 WickedEngine/wiSceneComponents_BindLua.cpp delete mode 100644 WickedEngine/wiSceneComponents_BindLua.h create mode 100644 WickedEngine/wiSceneSystem_BindLua.cpp create mode 100644 WickedEngine/wiSceneSystem_BindLua.h diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index 5b66301a1..018acab35 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -155,7 +155,7 @@ void AnimationWindow::Update() loopedCheckBox->SetCheck(animation.IsLooped()); - timerSlider->SetRange(0, animation.length); + timerSlider->SetRange(0, animation.GetLength()); timerSlider->SetValue(animation.timer); } } diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 3e116f10c..383f543a5 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -1257,94 +1257,48 @@ void EditorComponent::Update(float dt) { selectAll = true; } - //// Copy - //if (wiInputManager::GetInstance()->press('C')) - //{ - // SAFE_DELETE(clipboard); - // clipboard = new wiArchive(); - // *clipboard << CLIPBOARD_MODEL; - // Model* model = new Model; - // for (auto& x : selected) - // { - // model->Add(x->object); - // model->Add(x->light); - // model->Add(x->decal); - // model->Add(x->forceField); - // model->Add(x->camera); - // } - // model->Serialize(*clipboard); + // Copy + if (wiInputManager::GetInstance()->press('C')) + { + SAFE_DELETE(clipboard); + clipboard = new wiArchive(); + *clipboard << selected.size(); + for (auto& x : selected) + { + scene.Entity_Serialize(*clipboard, x.entity, 0); + } + } + // Paste + if (wiInputManager::GetInstance()->press('V')) + { + auto prevSel = selected; + EndTranslate(); - // model->objects.clear(); - // model->lights.clear(); - // model->decals.clear(); - // model->meshes.clear(); - // model->materials.clear(); - // model->forces.clear(); - // model->armatures.clear(); - // model->cameras.clear(); - // SAFE_DELETE(model); - //} - //// Paste - //if (wiInputManager::GetInstance()->press('V')) - //{ - // clipboard->SetReadModeAndResetPos(true); - // int tmp; - // *clipboard >> tmp; - // ClipboardItemType type = (ClipboardItemType)tmp; - // switch (type) - // { - // case CLIPBOARD_MODEL: - // { - // Model* model = new Model; - // model->Serialize(*clipboard); - // wiRenderer::AddModel(model); - // } - // break; - // case CLIPBOARD_EMPTY: - // break; - // default: - // break; - // } - //} - //// Duplicate Instances - //if (wiInputManager::GetInstance()->press('D')) - //{ - // EndTranslate(); + clipboard->SetReadModeAndResetPos(true); + size_t count; + *clipboard >> count; + for (size_t i = 0; i < count; ++i) + { + Picked picked; + picked.entity = scene.Entity_Serialize(*clipboard, INVALID_ENTITY, wiRandom::getRandom(1, INT_MAX)); + AddSelected(picked); + } - // for (auto& x : selected) - // { - // if (x->object != nullptr) - // { - // Object* o = new Object(*x->object); - // wiRenderer::Add(o); - // x->transform = o; - // x->object = o; - // } - // if (x->light != nullptr) - // { - // Light* l = new Light(*x->light); - // wiRenderer::Add(l); - // x->transform = l; - // x->light = l; - // } - // if (x->forceField != nullptr) - // { - // ForceField* l = new ForceField(*x->forceField); - // wiRenderer::Add(l); - // x->transform = l; - // x->forceField = l; - // } - // if (x->camera != nullptr) - // { - // Camera* l = new Camera(*x->camera); - // wiRenderer::Add(l); - // x->transform = l; - // x->camera = l; - // } - // } - - // BeginTranslate(); - //} + BeginTranslate(); + } + // Duplicate Instances + if (wiInputManager::GetInstance()->press('D')) + { + auto prevSel = selected; + EndTranslate(); + for (auto& x : prevSel) + { + Picked picked; + picked.entity = scene.Entity_Duplicate(x.entity); + AddSelected(picked); + } + BeginTranslate(); + } // Undo if (wiInputManager::GetInstance()->press('Z')) { diff --git a/Editor/Editor.h b/Editor/Editor.h index cfafc10df..c80b5bbf6 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -124,11 +124,6 @@ public: wiArchive *clipboard = nullptr; - enum ClipboardItemType - { - CLIPBOARD_MODEL, - CLIPBOARD_EMPTY - }; std::vector history; int historyPos = -1; diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index e1fa360cd..6f8294570 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -660,6 +660,18 @@ void ImportModel_GLTF(const std::string& fileName) mesh.vertex_boneweights[vertexOffset + i] = ((XMFLOAT4*)data)[i]; } } + else if (!attr_name.compare("COLOR_0")) + { + mesh.vertex_colors.resize(vertexOffset + vertexCount); + assert(stride == 16); + for (size_t i = 0; i < vertexCount; ++i) + { + const XMFLOAT4& color = ((XMFLOAT4*)data)[i]; + uint32_t rgba = wiMath::CompressColor(color); + + mesh.vertex_colors[vertexOffset + i] = rgba; + } + } } @@ -734,13 +746,21 @@ void ImportModel_GLTF(const std::string& fileName) Entity entity = CreateEntity(); state.scene.names.Create(entity) = anim.name; AnimationComponent& animationcomponent = state.scene.animations.Create(entity); + animationcomponent.samplers.resize(anim.samplers.size()); + animationcomponent.channels.resize(anim.channels.size()); - for (auto& channel : anim.channels) + for (size_t i = 0; i < anim.samplers.size(); ++i) { - const tinygltf::AnimationSampler& sam = anim.samplers[channel.sampler]; + auto& sam = anim.samplers[i]; - animationcomponent.channels.push_back(AnimationComponent::AnimationChannel()); - animationcomponent.channels.back().target = state.entityMap[&state.gltfModel.nodes[channel.target_node]]; + if (!sam.interpolation.compare("LINEAR")) + { + animationcomponent.samplers[i].mode = AnimationComponent::AnimationSampler::Mode::LINEAR; + } + else if (!sam.interpolation.compare("STEP")) + { + animationcomponent.samplers[i].mode = AnimationComponent::AnimationSampler::Mode::STEP; + } // AnimationSampler input = keyframe times { @@ -753,18 +773,18 @@ void ImportModel_GLTF(const std::string& fileName) int stride = accessor.ByteStride(bufferView); size_t count = accessor.count; - animationcomponent.channels.back().keyframe_times.resize(count); + animationcomponent.samplers[i].keyframe_times.resize(count); const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; assert(stride == 4); - animationcomponent.length = 0.0f; - for (size_t i = 0; i < count; ++i) + for (size_t j = 0; j < count; ++j) { - float time = ((float*)data)[i]; - animationcomponent.channels.back().keyframe_times[i] = time; - animationcomponent.length = max(animationcomponent.length, time); + float time = ((float*)data)[j]; + animationcomponent.samplers[i].keyframe_times[j] = time; + animationcomponent.start = min(animationcomponent.start, time); + animationcomponent.end = max(animationcomponent.end, time); } } @@ -780,50 +800,60 @@ void ImportModel_GLTF(const std::string& fileName) const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; - if (!channel.target_path.compare("scale")) + switch (accessor.type) + { + case TINYGLTF_TYPE_VEC3: { - animationcomponent.channels.back().type = AnimationComponent::AnimationChannel::Type::SCALE; - animationcomponent.channels.back().keyframe_data.resize(count * 3); - assert(stride == sizeof(XMFLOAT3)); - for (size_t i = 0; i < count; ++i) + animationcomponent.samplers[i].keyframe_data.resize(count * 3); + for (size_t j = 0; j < count; ++j) { - XMFLOAT3 sca = ((XMFLOAT3*)data)[i]; - ((XMFLOAT3*)animationcomponent.channels.back().keyframe_data.data())[i] = sca; + ((XMFLOAT3*)animationcomponent.samplers[i].keyframe_data.data())[j] = ((XMFLOAT3*)data)[j]; } } - else if (!channel.target_path.compare("rotation")) + break; + case TINYGLTF_TYPE_VEC4: { - animationcomponent.channels.back().type = AnimationComponent::AnimationChannel::Type::ROTATION; - animationcomponent.channels.back().keyframe_data.resize(count * 4); - assert(stride == sizeof(XMFLOAT4)); - for (size_t i = 0; i < count; ++i) + animationcomponent.samplers[i].keyframe_data.resize(count * 4); + for (size_t j = 0; j < count; ++j) { - const XMFLOAT4& rot = ((XMFLOAT4*)data)[i]; - ((XMFLOAT4*)animationcomponent.channels.back().keyframe_data.data())[i] = rot; + ((XMFLOAT4*)animationcomponent.samplers[i].keyframe_data.data())[j] = ((XMFLOAT4*)data)[j]; } } - else if (!channel.target_path.compare("translation")) - { - animationcomponent.channels.back().type = AnimationComponent::AnimationChannel::Type::TRANSLATION; - animationcomponent.channels.back().keyframe_data.resize(count * 3); + break; + default: assert(0); break; - assert(stride == sizeof(XMFLOAT3)); - for (size_t i = 0; i < count; ++i) - { - const XMFLOAT3& tra = ((XMFLOAT3*)data)[i]; - ((XMFLOAT3*)animationcomponent.channels.back().keyframe_data.data())[i] = tra; - } - } - else - { - // Not implemented: - animationcomponent.channels.pop_back(); } + } + } + for (size_t i = 0; i < anim.channels.size(); ++i) + { + auto& channel = anim.channels[i]; + + animationcomponent.channels[i].target = state.entityMap[&state.gltfModel.nodes[channel.target_node]]; + assert(channel.sampler >= 0); + animationcomponent.channels[i].samplerIndex = (uint32_t)channel.sampler; + + if (!channel.target_path.compare("scale")) + { + animationcomponent.channels[i].path = AnimationComponent::AnimationChannel::Path::SCALE; + } + else if (!channel.target_path.compare("rotation")) + { + animationcomponent.channels[i].path = AnimationComponent::AnimationChannel::Path::ROTATION; + } + else if (!channel.target_path.compare("translation")) + { + animationcomponent.channels[i].path = AnimationComponent::AnimationChannel::Path::TRANSLATION; + } + else + { + animationcomponent.channels[i].path = AnimationComponent::AnimationChannel::Path::UNKNOWN; + } } } @@ -839,6 +869,7 @@ void ImportModel_GLTF(const std::string& fileName) // Apply every transformation according to root transform, then remove root all together. // We could also keep it, but right now, it seems better to delete and have less hierarchy state.scene.Update(0); + state.scene.Component_DetachChildren(rootEntity); state.scene.Entity_Remove(rootEntity); wiRenderer::GetScene().Merge(state.scene); diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index aef393b1e..1364cdfd0 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -3,7 +3,6 @@ #include "wiRenderer.h" #include "wiInputManager.h" #include "wiMath.h" -#include "wiSceneComponents_BindLua.h" using namespace wiGraphicsTypes; using namespace wiECS; diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems b/WickedEngine/WickedEngine_SHARED.vcxitems index f2053a45b..f3e80a520 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems +++ b/WickedEngine/WickedEngine_SHARED.vcxitems @@ -337,7 +337,7 @@ - + @@ -677,7 +677,7 @@ - + diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems.filters b/WickedEngine/WickedEngine_SHARED.vcxitems.filters index 3f2aa6d83..42a20c67c 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems.filters +++ b/WickedEngine/WickedEngine_SHARED.vcxitems.filters @@ -1122,9 +1122,6 @@ UTILITY - - ENGINE\Scripting\LuaBindings - ENGINE\System @@ -1137,6 +1134,9 @@ ENGINE\Graphics\GPUMapping + + ENGINE\Scripting\LuaBindings + @@ -1919,15 +1919,15 @@ UTILITY - - ENGINE\Scripting\LuaBindings - ENGINE\System ENGINE\System + + ENGINE\Scripting\LuaBindings + diff --git a/WickedEngine/wiInputManager.cpp b/WickedEngine/wiInputManager.cpp index 64670a801..522836b0f 100644 --- a/WickedEngine/wiInputManager.cpp +++ b/WickedEngine/wiInputManager.cpp @@ -39,12 +39,8 @@ wiInputManager::~wiInputManager() wiInputManager* wiInputManager::GetInstance() { - static wiInputManager* instance = nullptr; - if (instance == nullptr) - { - instance = new wiInputManager(); - } - return instance; + static wiInputManager instance; + return &instance; } @@ -78,7 +74,8 @@ void wiInputManager::Update() //rawinput->RetrieveBufferedData(); } - for(InputCollection::iterator iter=inputs.begin();iter!=inputs.end();){ + for (InputCollection::iterator iter = inputs.begin(); iter != inputs.end();) + { InputType type = iter->first.type; DWORD button = iter->first.button; short playerIndex = iter->first.playerIndex; @@ -94,10 +91,12 @@ void wiInputManager::Update() todelete = true; } - if(todelete){ + if (todelete) + { inputs.erase(iter++); } - else{ + else + { ++iter; } } @@ -166,13 +165,14 @@ bool wiInputManager::hold(DWORD button, DWORD frames, bool continuous, InputType return false; Input input = Input(); - input.button=button; - input.type=inputType; - input.playerIndex=playerIndex; + input.button = button; + input.type = inputType; + input.playerIndex = playerIndex; LOCK(); InputCollection::iterator iter = inputs.find(input); - if(iter==inputs.end()){ - inputs.insert(pair(input,0)); + if (iter == inputs.end()) + { + inputs.insert(pair(input, 0)); UNLOCK(); return false; } diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index 20215b982..11bf947bb 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -17,7 +17,7 @@ #include "wiImageEffects_BindLua.h" #include "SpriteAnim_BindLua.h" #include "wiResourceManager_BindLua.h" -#include "wiSceneComponents_BindLua.h" +#include "wiSceneSystem_BindLua.h" #include "Vector_BindLua.h" #include "Matrix_BindLua.h" #include "wiInputManager_BindLua.h" @@ -71,7 +71,7 @@ wiLua* wiLua::GetGlobal() wiImageEffects_BindLua::Bind(); SpriteAnim_BindLua::Bind(); wiResourceManager_BindLua::Bind(); - wiSceneComponents_BindLua::Bind(); + wiSceneSystem_BindLua::Bind(); Vector_BindLua::Bind(); Matrix_BindLua::Bind(); wiInputManager_BindLua::Bind(); diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index fff901917..ccdf53b66 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -1,7 +1,8 @@ #include "wiRenderer_BindLua.h" #include "wiRenderer.h" #include "wiHelper.h" -#include "wiSceneComponents_BindLua.h" +#include "wiSceneSystem.h" +#include "wiSceneSystem_BindLua.h" #include "Vector_BindLua.h" #include "Matrix_BindLua.h" #include "Texture_BindLua.h" @@ -10,274 +11,13 @@ #include "wiPHYSICS.h" using namespace std; +using namespace wiECS; using namespace wiGraphicsTypes; using namespace wiSceneSystem; +using namespace wiSceneSystem_BindLua; namespace wiRenderer_BindLua { - - //void AddTransformName(Transform* root, stringstream& ss) - //{ - // if (root == nullptr) - // return; - // ss << root->name << endl; - // for (auto x : root->children) - // { - // if (x != nullptr) - // { - // AddTransformName(x, ss); - // } - // } - //} - //int GetTransforms(lua_State* L) - //{ - // stringstream ss(""); - // AddTransformName(wiRenderer::GetScene().GetWorldNode(), ss); - // wiLua::SSetString(L, ss.str()); - // return 1; - //} - //int GetTransform(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // string name = wiLua::SGetString(L, 1); - // Transform* transform = wiRenderer::getTransformByName(name); - // if (transform != nullptr) - // { - // Object* object = dynamic_cast(transform); - // if (object != nullptr) - // { - // Luna::push(L, new Object_BindLua(object)); - // return 1; - // } - // Armature* armature = dynamic_cast(transform); - // if (armature != nullptr) - // { - // Luna::push(L, new Armature_BindLua(armature)); - // return 1; - // } - - // Luna::push(L, new Transform_BindLua(transform)); - // return 1; - // } - // else - // { - // wiLua::SError(L, "GetTransform(String name) transform not found!"); - // return 0; - // } - // } - // return 0; - //} - //int GetArmatures(lua_State* L) - //{ - // stringstream ss(""); - // for (auto& m : wiRenderer::GetScene().models) - // { - // for (auto& x : m->armatures) - // { - // ss << x->name << endl; - // } - // } - // wiLua::SSetString(L, ss.str()); - // return 1; - //} - //int GetArmature(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // string name = wiLua::SGetString(L, 1); - // Armature* armature = wiRenderer::getArmatureByName(name); - // if (armature != nullptr) - // { - // Luna::push(L, new Armature_BindLua(armature)); - // return 1; - // } - // else - // { - // wiLua::SError(L, "GetArmature(String name) armature not found!"); - // return 0; - // } - // } - // return 0; - //} - //int GetObjects(lua_State* L) - //{ - // stringstream ss(""); - // for (auto& m : wiRenderer::GetScene().models) - // { - // for (auto& x : m->objects) - // { - // ss << x->name << endl; - // } - // } - // wiLua::SSetString(L, ss.str()); - // return 1; - //} - //int GetObjectLua(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // string name = wiLua::SGetString(L, 1); - // Object* object = wiRenderer::getObjectByName(name); - // if (object != nullptr) - // { - // Luna::push(L, new Object_BindLua(object)); - // return 1; - // } - // else - // { - // wiLua::SError(L, "GetObject(String name) object not found!"); - // return 0; - // } - // } - // return 0; - //} - //int GetEmitters(lua_State* L) - //{ - // stringstream ss(""); - // for (auto& x : wiRenderer::emitterSystems) - // { - // ss << x->name << endl; - // } - // wiLua::SSetString(L, ss.str()); - // return 1; - // return 0; - //} - //int GetEmitter(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // string name = wiLua::SGetString(L, 1); - // int i = 0; - // for (auto& x : wiRenderer::emitterSystems) - // { - // if (!x->name.compare(name)) - // { - // Luna::push(L, new EmittedParticle_BindLua(x)); - // ++i; - // } - // } - // if (i > 0) - // { - // return i; - // } - // wiLua::SError(L, "GetEmitter(string name) no emitter by that name!"); - // } - // else - // { - // wiLua::SError(L, "GetEmitter(string name) not enough arguments!"); - // } - // return 0; - //} - //int GetMeshes(lua_State* L) - //{ - // stringstream ss(""); - // for (auto& m : wiRenderer::GetScene().models) - // { - // for (auto& x : m->meshes) - // { - // ss << x.first << endl; - // } - // } - // wiLua::SSetString(L, ss.str()); - // return 1; - //} - //int GetLights(lua_State* L) - //{ - // stringstream ss(""); - // for (auto& m : wiRenderer::GetScene().models) - // { - // for (auto& x : m->lights) - // { - // ss << x->name << endl; - // } - // } - // wiLua::SSetString(L, ss.str()); - // return 1; - //} - //int GetMaterials(lua_State* L) - //{ - // stringstream ss(""); - // for (auto& m : wiRenderer::GetScene().models) - // { - // for (auto& x : m->materials) - // { - // ss << x.first << endl; - // } - // } - // wiLua::SSetString(L, ss.str()); - // return 1; - //} - //int GetMaterial(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // string name = wiLua::SGetString(L, 1); - // Material* mat = wiRenderer::getMaterialByName(name); - // if (mat != nullptr) - // { - // Luna::push(L, new Material_BindLua(mat)); - // return 1; - // } - // } - // return 0; - //} - //int GetGameSpeed(lua_State* L) - //{ - // wiLua::SSetFloat(L, wiRenderer::GetGameSpeed()); - // return 1; - //} - //int GetScreenWidth(lua_State* L) - //{ - // wiLua::SSetInt(L, wiRenderer::GetDevice()->GetScreenWidth()); - // return 1; - //} - //int GetScreenHeight(lua_State* L) - //{ - // wiLua::SSetInt(L, wiRenderer::GetDevice()->GetScreenHeight()); - // return 1; - //} - //int GetCamera(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // string name = wiLua::SGetString(L, 1); - // Camera* camera = wiRenderer::getCameraByName(name); - // if (camera != nullptr) - // { - // Luna::push(L, new Camera_BindLua(camera)); - // return 1; - // } - // else - // { - // wiLua::SError(L, "GetCamera(opt String name) name was provided but there was no corresponding camera found!"); - // return 0; - // } - // } - - // Luna::push(L, new Camera_BindLua(wiRenderer::getCamera())); - // return 1; - //} - //int GetCameras(lua_State* L) - //{ - // stringstream ss(""); - // for (auto& m : wiRenderer::GetScene().models) - // { - // for (auto& x : m->cameras) - // { - // ss << x->name << endl; - // } - // } - // wiLua::SSetString(L, ss.str()); - // return 1; - //} - int SetResolutionScale(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -318,73 +58,12 @@ namespace wiRenderer_BindLua return 0; } - //int LoadModel(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // string fileName = wiLua::SGetString(L, 1); - // XMMATRIX transform = XMMatrixIdentity(); - // if (argc > 1) - // { - // Matrix_BindLua* matrix = Luna::lightcheck(L, 2); - // if (matrix != nullptr) - // { - // transform = matrix->matrix; - // } - // else - // { - // wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) argument is not a matrix!"); - // } - // } - // Model* model = wiRenderer::LoadModel(fileName, transform); - // Luna::push(L, new Model_BindLua(model)); - // return 1; - // } - // else - // { - // wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) not enough arguments!"); - // } - // return 0; - //} - //int LoadWorldInfo(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // string fileName = wiLua::SGetString(L, 1); - // wiRenderer::LoadWorldInfo(fileName); - // } - // else - // { - // wiLua::SError(L, "LoadWorldInfo(string fileName) not enough arguments!"); - // } - // return 0; - //} - //int DuplicateInstance(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // Object_BindLua* x = Luna::lightcheck(L, 1); - // if (x != nullptr) - // { - // Object* o = new Object(*x->object); - // wiRenderer::Add(o); - // Luna::push(L, new Object_BindLua(o)); - // return 1; - // } - // else - // { - // wiLua::SError(L, "DuplicateInstance(Object object) argument type mismatch!"); - // } - // } - // else - // { - // wiLua::SError(L, "DuplicateInstance(Object object) not enough arguments!"); - // } - // return 0; - //} + int GetScene(lua_State* L) + { + Luna::push(L, new Scene_BindLua(&wiRenderer::GetScene())); + return 1; + } + int SetEnvironmentMap(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -402,25 +81,6 @@ namespace wiRenderer_BindLua wiLua::SError(L, "SetEnvironmentMap(Texture cubemap) not enough arguments!"); return 0; } - //int HairParticleSettings(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // int lod0 = 20, lod1 = 50, lod2 = 200; - // if (argc > 0) - // { - // lod0 = wiLua::SGetInt(L, 1); - // if (argc > 1) - // { - // lod1 = wiLua::SGetInt(L, 2); - // if (argc > 2) - // { - // lod2 = wiLua::SGetInt(L, 3); - // } - // } - // } - // wiHairParticle::Settings(lod0, lod1, lod2); - // return 0; - //} int SetAlphaCompositionEnabled(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -639,53 +299,6 @@ namespace wiRenderer_BindLua return 0; } - //int PutDecal(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // Decal_BindLua* decal = Luna::lightcheck(L, 1); - // if (decal != nullptr) - // { - // wiRenderer::PutDecal(decal->decal); - // } - // else - // { - // wiLua::SError(L, "PutDecal(Decal decal) argument is not a Decal!"); - // } - // } - // else - // { - // wiLua::SError(L, "PutDecal(Decal decal) not enough arguments!"); - // } - // return 0; - //} - - //int PutEnvProbe(lua_State* L) - //{ - // int argc = wiLua::SGetArgCount(L); - // if (argc > 0) - // { - // Vector_BindLua* pos = Luna::lightcheck(L, 1); - // if (pos != nullptr) - // { - // XMFLOAT3 p; - // XMStoreFloat3(&p, pos->vector); - // wiRenderer::PutEnvProbe(p); - // } - // else - // { - // wiLua::SError(L, "PutEnvProbe(Vector pos) argument is not a Vector!"); - // } - // } - // else - // { - // wiLua::SError(L, "PutEnvProbe(Vector pos) not enough arguments!"); - // } - // return 0; - //} - - int ClearWorld(lua_State* L) { wiRenderer::ClearWorld(); @@ -710,33 +323,14 @@ namespace wiRenderer_BindLua if (!initialized) { initialized = true; - //wiLua::GetGlobal()->RegisterFunc("GetTransforms", GetTransforms); - //wiLua::GetGlobal()->RegisterFunc("GetTransform", GetTransform); - //wiLua::GetGlobal()->RegisterFunc("GetArmatures", GetArmatures); - //wiLua::GetGlobal()->RegisterFunc("GetArmature", GetArmature); - //wiLua::GetGlobal()->RegisterFunc("GetObjects", GetObjects); - //wiLua::GetGlobal()->RegisterFunc("GetObject", GetObjectLua); - //wiLua::GetGlobal()->RegisterFunc("GetEmitters", GetEmitters); - //wiLua::GetGlobal()->RegisterFunc("GetEmitter", GetEmitter); - //wiLua::GetGlobal()->RegisterFunc("GetMeshes", GetMeshes); - //wiLua::GetGlobal()->RegisterFunc("GetLights", GetLights); - //wiLua::GetGlobal()->RegisterFunc("GetMaterials", GetMaterials); - //wiLua::GetGlobal()->RegisterFunc("GetMaterial", GetMaterial); - //wiLua::GetGlobal()->RegisterFunc("GetGameSpeed", GetGameSpeed); - //wiLua::GetGlobal()->RegisterFunc("GetScreenWidth", GetScreenWidth); - //wiLua::GetGlobal()->RegisterFunc("GetScreenHeight", GetScreenHeight); - //wiLua::GetGlobal()->RegisterFunc("GetCamera", GetCamera); - //wiLua::GetGlobal()->RegisterFunc("GetCameras", GetCameras); wiLua::GetGlobal()->RegisterFunc("SetResolutionScale", SetResolutionScale); wiLua::GetGlobal()->RegisterFunc("SetGamma", SetGamma); wiLua::GetGlobal()->RegisterFunc("SetGameSpeed", SetGameSpeed); - //wiLua::GetGlobal()->RegisterFunc("LoadModel", LoadModel); - //wiLua::GetGlobal()->RegisterFunc("LoadWorldInfo", LoadWorldInfo); - //wiLua::GetGlobal()->RegisterFunc("DuplicateInstance", DuplicateInstance); + wiLua::GetGlobal()->RegisterFunc("GetScene", GetScene); + wiLua::GetGlobal()->RegisterFunc("SetEnvironmentMap", SetEnvironmentMap); - //wiLua::GetGlobal()->RegisterFunc("HairParticleSettings", HairParticleSettings); wiLua::GetGlobal()->RegisterFunc("SetAlphaCompositionEnabled", SetAlphaCompositionEnabled); wiLua::GetGlobal()->RegisterFunc("SetShadowProps2D", SetShadowProps2D); wiLua::GetGlobal()->RegisterFunc("SetShadowPropsCube", SetShadowPropsCube); @@ -754,8 +348,6 @@ namespace wiRenderer_BindLua //wiLua::GetGlobal()->RegisterFunc("Pick", Pick); wiLua::GetGlobal()->RegisterFunc("DrawLine", DrawLine); wiLua::GetGlobal()->RegisterFunc("PutWaterRipple", PutWaterRipple); - //wiLua::GetGlobal()->RegisterFunc("PutDecal", PutDecal); - //wiLua::GetGlobal()->RegisterFunc("PutEnvProbe", PutEnvProbe); wiLua::GetGlobal()->RunText("PICK_VOID = 0"); diff --git a/WickedEngine/wiSceneComponents_BindLua.cpp b/WickedEngine/wiSceneComponents_BindLua.cpp deleted file mode 100644 index 658a1b916..000000000 --- a/WickedEngine/wiSceneComponents_BindLua.cpp +++ /dev/null @@ -1,2049 +0,0 @@ -#include "wiSceneComponents_BindLua.h" -#include "Vector_BindLua.h" -#include "Matrix_BindLua.h" -#include "wiEmittedParticle.h" -#include "Texture_BindLua.h" - -using namespace std; - -namespace wiSceneComponents_BindLua -{ -void Bind() -{ - //Node_BindLua::Bind(); - //Transform_BindLua::Bind(); - //Cullable_BindLua::Bind(); - //Object_BindLua::Bind(); - //Armature_BindLua::Bind(); - //Ray_BindLua::Bind(); - //AABB_BindLua::Bind(); - //EmittedParticle_BindLua::Bind(); - //Decal_BindLua::Bind(); - //Material_BindLua::Bind(); - //Camera_BindLua::Bind(); - //Model_BindLua::Bind(); -} - - -//const char Node_BindLua::className[] = "Node"; -// -//Luna::FunctionType Node_BindLua::methods[] = { -// lunamethod(Node_BindLua, GetName), -// lunamethod(Node_BindLua, SetName), -// lunamethod(Node_BindLua, SetLayerMask), -// lunamethod(Node_BindLua, GetLayerMask), -// { NULL, NULL } -//}; -//Luna::PropertyType Node_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Node_BindLua::Node_BindLua(Node* node) -//{ -// this->node = node; -//} -//Node_BindLua::Node_BindLua(lua_State *L) -//{ -// node = new Node(); -//} -//Node_BindLua::~Node_BindLua() -//{ -//} -// -//int Node_BindLua::GetName(lua_State* L) -//{ -// if (node == nullptr) -// { -// wiLua::SError(L, "GetName() node is null!"); -// return 0; -// } -// wiLua::SSetString(L, node->name); -// return 1; -//} -//int Node_BindLua::SetName(lua_State* L) -//{ -// if (node == nullptr) -// { -// wiLua::SError(L, "SetName(String name) node is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// node->name = wiLua::SGetString(L, 1); -// } -// else -// { -// wiLua::SError(L, "SetName(String name) not enough arguments!"); -// } -// return 0; -//} -//int Node_BindLua::SetLayerMask(lua_State *L) -//{ -// if (node == nullptr) -// { -// wiLua::SError(L, "SetLayerMask(uint value) object is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// int mask = wiLua::SGetInt(L, 1); -// node->SetLayerMask(*reinterpret_cast(&mask)); -// } -// else -// { -// wiLua::SError(L, "SetLayerMask(uint value) not enough arguments!"); -// } -// return 0; -//} -//int Node_BindLua::GetLayerMask(lua_State *L) -//{ -// if (node == nullptr) -// { -// wiLua::SError(L, "GetLayerMask() object is null!"); -// return 0; -// } -// uint32_t mask = node->GetLayerMask(); -// wiLua::SSetInt(L, *reinterpret_cast(&mask)); -// return 1; -//} -// -//void Node_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -//const char Transform_BindLua::className[] = "Transform"; -// -//Luna::FunctionType Transform_BindLua::methods[] = { -// lunamethod(Node_BindLua, GetName), -// lunamethod(Node_BindLua, SetName), -// lunamethod(Node_BindLua, SetLayerMask), -// lunamethod(Node_BindLua, GetLayerMask), -// -// lunamethod(Transform_BindLua, AttachTo), -// lunamethod(Transform_BindLua, Detach), -// lunamethod(Transform_BindLua, DetachChild), -// lunamethod(Transform_BindLua, ApplyTransform), -// lunamethod(Transform_BindLua, Scale), -// lunamethod(Transform_BindLua, Rotate), -// lunamethod(Transform_BindLua, Translate), -// lunamethod(Transform_BindLua, Lerp), -// lunamethod(Transform_BindLua, CatmullRom), -// lunamethod(Transform_BindLua, MatrixTransform), -// lunamethod(Transform_BindLua, GetMatrix), -// lunamethod(Transform_BindLua, ClearTransform), -// lunamethod(Transform_BindLua, SetTransform), -// lunamethod(Transform_BindLua, GetPosition), -// lunamethod(Transform_BindLua, GetRotation), -// lunamethod(Transform_BindLua, GetScale), -// { NULL, NULL } -//}; -//Luna::PropertyType Transform_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Transform_BindLua::Transform_BindLua(Transform* transform) -//{ -// node = transform; -// this->transform = transform; -//} -//Transform_BindLua::Transform_BindLua(lua_State *L) -//{ -// Node_BindLua(); -// transform = new Transform(); -//} -//Transform_BindLua::~Transform_BindLua() -//{ -//} -// -//int Transform_BindLua::AttachTo(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Transform_BindLua* parent = Luna::lightcheck(L, 1); -// if (parent == nullptr) -// parent = Luna::lightcheck(L, 1); -// if (parent == nullptr) -// parent = Luna::lightcheck(L, 1); -// if (parent != nullptr) -// { -// int s = 1, r = 1, t = 1; -// if (argc > 1) -// { -// t = wiLua::SGetInt(L, 2); -// if (argc > 2) -// { -// r = wiLua::SGetInt(L, 3); -// if (argc > 3) -// { -// s = wiLua::SGetInt(L, 4); -// } -// } -// } -// transform->attachTo(parent->transform,t,r,s); -// } -// else -// { -// wiLua::SError(L, "AttachTo(Transform parent, opt boolean translation,rotation,scale) argument is not a Transform!"); -// } -// } -// else -// { -// wiLua::SError(L, "AttachTo(Transform parent, opt boolean translation,rotation,scale) not enough arguments!"); -// } -// return 0; -//} -//int Transform_BindLua::Detach(lua_State* L) -//{ -// transform->detach(); -// return 0; -//} -//int Transform_BindLua::DetachChild(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Transform_BindLua* child = Luna::lightcheck(L, 1); -// if (child == nullptr) -// child = Luna::lightcheck(L, 1); -// if (child == nullptr) -// child = Luna::lightcheck(L, 1); -// if (child != nullptr) -// { -// transform->detachChild(child->transform); -// return 0; -// } -// } -// transform->detachChild(); -// return 0; -//} -//int Transform_BindLua::ApplyTransform(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// int s = 1, r = 1, t = 1; -// if (argc > 0) -// { -// t = wiLua::SGetInt(L, 1); -// if (argc > 1) -// { -// r = wiLua::SGetInt(L, 2); -// if (argc > 2) -// { -// s = wiLua::SGetInt(L, 3); -// } -// } -// } -// transform->applyTransform(t, r, s); -// return 0; -//} -//int Transform_BindLua::Scale(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Vector_BindLua* v = Luna::lightcheck(L, 1); -// if (v != nullptr) -// { -// XMFLOAT3 scale; -// XMStoreFloat3(&scale, v->vector); -// transform->Scale(scale); -// } -// else -// { -// wiLua::SError(L, "Scale(Vector vector) argument is not a vector!"); -// } -// } -// else -// { -// wiLua::SError(L, "Scale(Vector vector) not enough arguments!"); -// } -// return 0; -//} -//int Transform_BindLua::Rotate(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Vector_BindLua* v = Luna::lightcheck(L, 1); -// if (v != nullptr) -// { -// XMFLOAT3 rollPitchYaw; -// XMStoreFloat3(&rollPitchYaw, v->vector); -// transform->RotateRollPitchYaw(rollPitchYaw); -// } -// else -// { -// wiLua::SError(L, "Rotate(Vector vectorRollPitchYaw) argument is not a vector!"); -// } -// } -// else -// { -// wiLua::SError(L, "Rotate(Vector vectorRollPitchYaw) not enough arguments!"); -// } -// return 0; -//} -//int Transform_BindLua::Translate(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Vector_BindLua* v = Luna::lightcheck(L, 1); -// if (v != nullptr) -// { -// XMFLOAT3 translate; -// XMStoreFloat3(&translate, v->vector); -// transform->Translate(translate); -// } -// else -// { -// wiLua::SError(L, "Translate(Vector vector) argument is not a vector!"); -// } -// } -// else -// { -// wiLua::SError(L, "Translate(Vector vector) not enough arguments!"); -// } -// return 0; -//} -//int Transform_BindLua::Lerp(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 2) -// { -// Transform_BindLua* a = Luna::lightcheck(L, 1); -// if (a != nullptr) -// { -// Transform_BindLua* b = Luna::lightcheck(L, 2); -// -// if (b != nullptr) -// { -// float t = wiLua::SGetFloat(L, 3); -// this->transform->Lerp(a->transform, b->transform, t); -// } -// else -// { -// wiLua::SError(L, "Lerp(Transform a,b, float t) argument (b) is not a Transform!"); -// } -// } -// else -// { -// wiLua::SError(L, "Lerp(Transform a,b, float t) argument (a) is not a Transform!"); -// } -// } -// else -// { -// wiLua::SError(L, "Lerp(Transform a,b, float t) not enough arguments!"); -// } -// return 0; -//} -//int Transform_BindLua::CatmullRom(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 4) -// { -// Transform_BindLua* a = Luna::lightcheck(L, 1); -// if (a != nullptr) -// { -// Transform_BindLua* b = Luna::lightcheck(L, 2); -// -// if (b != nullptr) -// { -// Transform_BindLua* c = Luna::lightcheck(L, 3); -// -// if (c != nullptr) -// { -// Transform_BindLua* d = Luna::lightcheck(L, 4); -// -// if (d != nullptr) -// { -// float t = wiLua::SGetFloat(L, 5); -// this->transform->CatmullRom(a->transform, b->transform, c->transform, d->transform, t); -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (d) is not a Transform!"); -// } -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (c) is not a Transform!"); -// } -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (b) is not a Transform!"); -// } -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (a) is not a Transform!"); -// } -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) not enough arguments!"); -// } -// return 0; -//} -//int Transform_BindLua::MatrixTransform(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Matrix_BindLua* m = Luna::lightcheck(L, 1); -// if (m != nullptr) -// { -// transform->transform(m->matrix); -// } -// else -// { -// wiLua::SError(L, "MatrixTransform(Matrix matrix) argument is not a matrix!"); -// } -// } -// else -// { -// wiLua::SError(L, "MatrixTransform(Matrix matrix) not enough arguments!"); -// } -// return 0; -//} -//int Transform_BindLua::GetMatrix(lua_State* L) -//{ -// Luna::push(L, new Matrix_BindLua(transform->getMatrix())); -// return 1; -//} -//int Transform_BindLua::ClearTransform(lua_State* L) -//{ -// transform->ClearTransform(); -// return 0; -//} -//int Transform_BindLua::SetTransform(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Transform_BindLua* t = Luna::lightcheck(L, 1); -// if (t == nullptr) -// t = Luna::lightcheck(L, 1); -// if (t == nullptr) -// t = Luna::lightcheck(L, 1); -// 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; -//} -//int Transform_BindLua::GetPosition(lua_State* L) -//{ -// Luna::push(L, new Vector_BindLua(XMLoadFloat3(&transform->translation))); -// return 1; -//} -//int Transform_BindLua::GetRotation(lua_State* L) -//{ -// Luna::push(L, new Vector_BindLua(XMLoadFloat4(&transform->rotation))); -// return 1; -//} -//int Transform_BindLua::GetScale(lua_State* L) -//{ -// Luna::push(L, new Vector_BindLua(XMLoadFloat3(&transform->scale))); -// return 1; -//} -// -//void Transform_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -//const char Cullable_BindLua::className[] = "Cullable"; -// -//Luna::FunctionType Cullable_BindLua::methods[] = { -// lunamethod(Cullable_BindLua, Intersects), -// lunamethod(Cullable_BindLua, GetAABB), -// lunamethod(Cullable_BindLua, SetAABB), -// { NULL, NULL } -//}; -//Luna::PropertyType Cullable_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Cullable_BindLua::Cullable_BindLua(Cullable* cullable) -//{ -// if (cullable == nullptr) -// { -// this->cullable = new Cullable(); -// } -// else -// this->cullable = cullable; -//} -//Cullable_BindLua::Cullable_BindLua(lua_State *L) -//{ -// cullable = new Cullable(); -//} -//Cullable_BindLua::~Cullable_BindLua() -//{ -//} -// -//int Cullable_BindLua::Intersects(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Cullable_BindLua* target = Luna::lightcheck(L, 1); -// if (target == nullptr) -// target = Luna::lightcheck(L, 1); -// if (target != nullptr) -// { -// AABB::INTERSECTION_TYPE intersection = cullable->bounds.intersects(target->cullable->bounds); -// wiLua::SSetBool(L, intersection > AABB::INTERSECTION_TYPE::OUTSIDE); -// return 1; -// } -// else -// { -// Ray_BindLua* ray = Luna::lightcheck(L, 1); -// if (ray != nullptr) -// { -// wiLua::SSetBool(L, cullable->bounds.intersects(ray->ray)); -// return 1; -// } -// else -// { -// Vector_BindLua* vec = Luna::lightcheck(L, 1); -// 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 -// { -// wiLua::SError(L, "Intersects(Cullable cullable) not enough arguments!"); -// } -// return 0; -//} -//int Cullable_BindLua::GetAABB(lua_State* L) -//{ -// Luna::push(L, new AABB_BindLua(cullable->bounds)); -// return 1; -//} -//int Cullable_BindLua::SetAABB(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc < 0) -// { -// AABB_BindLua* box = Luna::lightcheck(L, 1); -// if (box) -// { -// -// } -// else -// wiLua::SError(L, "SetAABB(AABB aabb) argument is not an AABB!"); -// } -// else -// wiLua::SError(L, "SetAABB(AABB aabb) not enough arguments!"); -// return 0; -//} -// -//void Cullable_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -//const char Object_BindLua::className[] = "Object"; -// -//Luna::FunctionType Object_BindLua::methods[] = { -// lunamethod(Node_BindLua, GetName), -// lunamethod(Node_BindLua, SetName), -// lunamethod(Node_BindLua, SetLayerMask), -// lunamethod(Node_BindLua, GetLayerMask), -// -// lunamethod(Cullable_BindLua, Intersects), -// lunamethod(Cullable_BindLua, GetAABB), -// lunamethod(Cullable_BindLua, SetAABB), -// -// lunamethod(Transform_BindLua, AttachTo), -// lunamethod(Transform_BindLua, Detach), -// lunamethod(Transform_BindLua, DetachChild), -// lunamethod(Transform_BindLua, ApplyTransform), -// lunamethod(Transform_BindLua, Scale), -// lunamethod(Transform_BindLua, Rotate), -// lunamethod(Transform_BindLua, Translate), -// lunamethod(Transform_BindLua, Lerp), -// lunamethod(Transform_BindLua, CatmullRom), -// lunamethod(Transform_BindLua, MatrixTransform), -// lunamethod(Transform_BindLua, GetMatrix), -// lunamethod(Transform_BindLua, ClearTransform), -// lunamethod(Transform_BindLua, SetTransform), -// lunamethod(Transform_BindLua, GetPosition), -// lunamethod(Transform_BindLua, GetRotation), -// lunamethod(Transform_BindLua, GetScale), -// -// lunamethod(Object_BindLua, EmitTrail), -// lunamethod(Object_BindLua, SetTrailDistortTex), -// lunamethod(Object_BindLua, SetTrailTex), -// lunamethod(Object_BindLua, SetTransparency), -// lunamethod(Object_BindLua, GetTransparency), -// lunamethod(Object_BindLua, SetColor), -// lunamethod(Object_BindLua, GetColor), -// lunamethod(Object_BindLua, GetEmitter), -// lunamethod(Object_BindLua, IsValid), -// { NULL, NULL } -//}; -//Luna::PropertyType Object_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Object_BindLua::Object_BindLua(Object* object) -//{ -// node = object; -// transform = object; -// cullable = object; -// this->object = object; -//} -//Object_BindLua::Object_BindLua(lua_State *L) -//{ -// Transform_BindLua(); -// Cullable_BindLua(); -// object = nullptr; -//} -//Object_BindLua::~Object_BindLua() -//{ -//} -// -//int Object_BindLua::EmitTrail(lua_State *L) -//{ -// if (object == nullptr) -// { -// wiLua::SError(L, "EmitTrail(Vector color, opt float fadeSpeed) object is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Vector_BindLua* color = Luna::lightcheck(L, 1); -// if (color != nullptr) -// { -// XMFLOAT3 col; -// XMStoreFloat3(&col, color->vector); -// float fadeSpeed = 0.06f; -// if (argc > 1) -// { -// fadeSpeed = wiLua::SGetFloat(L, 2); -// } -// object->EmitTrail(col, fadeSpeed); -// } -// else -// { -// wiLua::SError(L, "EmitTrail(Vector color, opt float fadeSpeed) argument is not a Vector!"); -// } -// } -// else -// { -// wiLua::SError(L, "EmitTrail(Vector color, opt float fadeSpeed) not enough arguments!"); -// } -// return 0; -//} -//int Object_BindLua::SetTrailDistortTex(lua_State *L) -//{ -// if (object == nullptr) -// { -// wiLua::SError(L, "SetTrailDistortTex(Texture tex) object is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Texture_BindLua* tex = Luna::lightcheck(L, 1); -// if (tex != nullptr) -// { -// object->trailDistortTex = tex->texture; -// } -// else -// { -// wiLua::SError(L, "SetTrailDistortTex(Texture tex) argument is not a Texture!"); -// } -// } -// else -// { -// wiLua::SError(L, "SetTrailDistortTex(Texture tex) not enough arguments!"); -// } -// return 0; -//} -//int Object_BindLua::SetTrailTex(lua_State *L) -//{ -// if (object == nullptr) -// { -// wiLua::SError(L, "SetTrailTex(Texture tex) object is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Texture_BindLua* tex = Luna::lightcheck(L, 1); -// if (tex != nullptr) -// { -// object->trailTex = tex->texture; -// } -// else -// { -// wiLua::SError(L, "SetTrailTex(Texture tex) argument is not a Texture!"); -// } -// } -// else -// { -// wiLua::SError(L, "SetTrailTex(Texture tex) not enough arguments!"); -// } -// return 0; -//} -//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 > 0) -// { -// object->transparency = wiLua::SGetFloat(L, 1); -// } -// 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(Vector rgb) object is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Vector_BindLua* vec = Luna::lightcheck(L, 1); -// if (vec != nullptr) -// { -// XMStoreFloat3(&object->color, vec->vector); -// } -// else -// { -// wiLua::SError(L, "SetColor(Vector rgb) argument is not a Vector!"); -// } -// } -// else -// { -// wiLua::SError(L, "SetColor(Vector rgb) not enough arguments!"); -// } -// return 0; -//} -//int Object_BindLua::GetColor(lua_State *L) -//{ -// if (object == nullptr) -// { -// wiLua::SError(L, "GetColor() object is null!"); -// return 0; -// } -// Luna::push(L, new Vector_BindLua(XMLoadFloat3(&object->color))); -// return 1; -//} -//int Object_BindLua::GetEmitter(lua_State *L) -//{ -// if (object == nullptr) -// { -// wiLua::SError(L, "GetEmitter(opt int id = 0) object is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// int id = 0; -// if (argc > 0) -// { -// id = wiLua::SGetInt(L, 1); -// } -// if ((int)object->eParticleSystems.size() > id) -// { -// Luna::push(L, new EmittedParticle_BindLua(object->eParticleSystems[id])); -// } -// Luna::push(L, new EmittedParticle_BindLua(L)); -// return 1; -//} -//int Object_BindLua::IsValid(lua_State *L) -//{ -// wiLua::SSetBool(L, object != nullptr); -// return 1; -//} -// -//void Object_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -// -//const char Armature_BindLua::className[] = "Armature"; -// -//Luna::FunctionType Armature_BindLua::methods[] = { -// lunamethod(Node_BindLua, GetName), -// lunamethod(Node_BindLua, SetName), -// lunamethod(Node_BindLua, SetLayerMask), -// lunamethod(Node_BindLua, GetLayerMask), -// -// lunamethod(Transform_BindLua, AttachTo), -// lunamethod(Transform_BindLua, Detach), -// lunamethod(Transform_BindLua, DetachChild), -// lunamethod(Transform_BindLua, ApplyTransform), -// lunamethod(Transform_BindLua, Scale), -// lunamethod(Transform_BindLua, Rotate), -// lunamethod(Transform_BindLua, Translate), -// lunamethod(Transform_BindLua, Lerp), -// lunamethod(Transform_BindLua, CatmullRom), -// lunamethod(Transform_BindLua, MatrixTransform), -// lunamethod(Transform_BindLua, GetMatrix), -// lunamethod(Transform_BindLua, ClearTransform), -// lunamethod(Transform_BindLua, SetTransform), -// lunamethod(Transform_BindLua, GetPosition), -// lunamethod(Transform_BindLua, GetRotation), -// lunamethod(Transform_BindLua, GetScale), -// -// lunamethod(Armature_BindLua, GetAction), -// lunamethod(Armature_BindLua, GetActions), -// lunamethod(Armature_BindLua, GetBones), -// lunamethod(Armature_BindLua, GetBone), -// 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), -// lunamethod(Armature_BindLua, AddAnimLayer), -// lunamethod(Armature_BindLua, DeleteAnimLayer), -// lunamethod(Armature_BindLua, SetAnimLayerWeight), -// lunamethod(Armature_BindLua, SetAnimLayerLooped), -// lunamethod(Armature_BindLua, IsValid), -// { NULL, NULL } -//}; -//Luna::PropertyType Armature_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Armature_BindLua::Armature_BindLua(Armature* armature) -//{ -// node = armature; -// transform = armature; -// this->armature = armature; -//} -//Armature_BindLua::Armature_BindLua(lua_State *L) -//{ -// Transform_BindLua(); -// armature = nullptr; -//} -//Armature_BindLua::~Armature_BindLua() -//{ -//} -// -//int Armature_BindLua::GetAction(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "GetAction(opt string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// wiLua::SSetString(L, armature->actions[armature->GetAnimLayer(wiLua::SGetString(L,1))->activeAction].name); -// } -// else -// { -// wiLua::SSetString(L, armature->actions[armature->GetPrimaryAnimation()->activeAction].name); -// } -// return 1; -//} -//int Armature_BindLua::GetActions(lua_State *L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "GetActions() armature is null!"); -// return 0; -// } -// stringstream ss(""); -// for (auto& x : armature->actions) -// { -// ss << x.name << endl; -// } -// wiLua::SSetString(L, ss.str()); -// return 1; -//} -//int Armature_BindLua::GetBones(lua_State *L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "GetBones() armature is null!"); -// return 0; -// } -// stringstream ss(""); -// for (auto& x : armature->boneCollection) -// { -// ss << x->name << endl; -// } -// wiLua::SSetString(L, ss.str()); -// return 1; -//} -//int Armature_BindLua::GetBone(lua_State *L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "GetBone() armature is null!"); -// return 0; -// } -// string name = wiLua::SGetString(L, 1); -// for (auto& x : armature->boneCollection) -// { -// if (!x->name.compare(name)) -// { -// Luna::push(L, new Transform_BindLua(x)); -// return 1; -// } -// } -// wiLua::SError(L, "GetBone(String name) bone not found!"); -// return 0; -//} -//int Armature_BindLua::GetFrame(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "GetFrame(opt string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// wiLua::SSetFloat(L, armature->GetAnimLayer(wiLua::SGetString(L,1))->currentFrame); -// } -// else -// { -// wiLua::SSetFloat(L, armature->GetPrimaryAnimation()->currentFrame); -// } -// return 1; -//} -//int Armature_BindLua::GetFrameCount(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "GetFrameCount(opt string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// wiLua::SSetFloat(L, (float)armature->actions[armature->GetAnimLayer(wiLua::SGetString(L,1))->activeAction].frameCount); -// } -// else -// { -// wiLua::SSetFloat(L, (float)armature->actions[armature->GetPrimaryAnimation()->activeAction].frameCount); -// } -// return 1; -//} -//int Armature_BindLua::IsValid(lua_State *L) -//{ -// wiLua::SSetBool(L, armature != nullptr); -// return 1; -//} -// -//int Armature_BindLua::ChangeAction(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "ChangeAction(opt string name, opt float blendFrames=0, opt string animLayer) armature is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// string armatureName = wiLua::SGetString(L, 1); -// float blendFrames = 0.0f; -// string layer = ""; -// float weight = 1.0f; -// if (argc > 1) -// { -// blendFrames = wiLua::SGetFloat(L, 2); -// if (argc > 2) -// { -// layer = wiLua::SGetString(L, 3); -// if (argc > 3) -// { -// weight = wiLua::SGetFloat(L, 4); -// } -// } -// } -// armature->ChangeAction(armatureName, blendFrames, layer, weight); -// } -// else -// { -// armature->ChangeAction(); -// } -// return 0; -//} -//int Armature_BindLua::StopAction(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "StopAction(opt string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// armature->GetAnimLayer(wiLua::SGetString(L,1))->StopAction(); -// } -// else -// { -// armature->GetPrimaryAnimation()->StopAction(); -// } -// return 0; -//} -//int Armature_BindLua::PauseAction(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "PauseAction(opt string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// armature->GetAnimLayer(wiLua::SGetString(L,1))->PauseAction(); -// } -// else -// { -// armature->GetPrimaryAnimation()->PauseAction(); -// } -// return 0; -//} -//int Armature_BindLua::PlayAction(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "PlayAction(opt string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// armature->GetAnimLayer(wiLua::SGetString(L, 1))->PlayAction(); -// } -// else -// { -// armature->GetPrimaryAnimation()->PlayAction(); -// } -// return 0; -//} -//int Armature_BindLua::ResetAction(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "ResetAction(opt string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// armature->GetAnimLayer(wiLua::SGetString(L, 1))->ResetAction(); -// } -// else -// { -// armature->GetPrimaryAnimation()->ResetAction(); -// } -// return 0; -//} -//int Armature_BindLua::AddAnimLayer(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "AddAnimLayer(string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// armature->AddAnimLayer(wiLua::SGetString(L, 1)); -// } -// else -// { -// wiLua::SError(L, "AddAnimLayer(string animLayer) not enough arguments!"); -// } -// return 0; -//} -//int Armature_BindLua::DeleteAnimLayer(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "DeleteAnimLayer(string animLayer) armature is null!"); -// return 0; -// } -// if (wiLua::SGetArgCount(L) > 0) -// { -// armature->DeleteAnimLayer(wiLua::SGetString(L, 1)); -// } -// else -// { -// wiLua::SError(L, "DeleteAnimLayer(string animLayer) not enough arguments!"); -// } -// return 0; -//} -//int Armature_BindLua::SetAnimLayerWeight(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "SetAnimLayerWeight(float weight, opt string animLayer) armature is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// if (argc > 1) -// { -// armature->GetAnimLayer(wiLua::SGetString(L, 2))->weight = wiLua::SGetFloat(L, 1); -// } -// else -// { -// armature->GetPrimaryAnimation()->weight = wiLua::SGetFloat(L, 1); -// } -// } -// else -// { -// wiLua::SError(L, "SetAnimLayerWeight(float weight, opt string animLayer) not enough arguments!"); -// } -// return 0; -//} -//int Armature_BindLua::SetAnimLayerLooped(lua_State* L) -//{ -// if (armature == nullptr) -// { -// wiLua::SError(L, "SetAnimLayerLooped(bool looped, opt string animLayer) armature is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// if (argc > 1) -// { -// armature->GetAnimLayer(wiLua::SGetString(L, 2))->looped = wiLua::SGetBool(L, 1); -// } -// else -// { -// armature->GetPrimaryAnimation()->looped = wiLua::SGetBool(L, 1); -// } -// } -// else -// { -// wiLua::SError(L, "SetAnimLayerLooped(bool looped, opt string animLayer) not enough arguments!"); -// } -// return 0; -//} -// -//void Armature_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -// -//const char Decal_BindLua::className[] = "Decal"; -// -//Luna::FunctionType Decal_BindLua::methods[] = { -// lunamethod(Node_BindLua, GetName), -// lunamethod(Node_BindLua, SetName), -// lunamethod(Node_BindLua, SetLayerMask), -// lunamethod(Node_BindLua, GetLayerMask), -// -// lunamethod(Cullable_BindLua, Intersects), -// lunamethod(Cullable_BindLua, GetAABB), -// lunamethod(Cullable_BindLua, SetAABB), -// -// lunamethod(Transform_BindLua, AttachTo), -// lunamethod(Transform_BindLua, Detach), -// lunamethod(Transform_BindLua, DetachChild), -// lunamethod(Transform_BindLua, ApplyTransform), -// lunamethod(Transform_BindLua, Scale), -// lunamethod(Transform_BindLua, Rotate), -// lunamethod(Transform_BindLua, Translate), -// lunamethod(Transform_BindLua, Lerp), -// lunamethod(Transform_BindLua, CatmullRom), -// lunamethod(Transform_BindLua, MatrixTransform), -// lunamethod(Transform_BindLua, GetMatrix), -// lunamethod(Transform_BindLua, ClearTransform), -// lunamethod(Transform_BindLua, SetTransform), -// lunamethod(Transform_BindLua, GetPosition), -// lunamethod(Transform_BindLua, GetRotation), -// lunamethod(Transform_BindLua, GetScale), -// -// lunamethod(Decal_BindLua, SetTexture), -// lunamethod(Decal_BindLua, SetNormal), -// lunamethod(Decal_BindLua, SetLife), -// lunamethod(Decal_BindLua, GetLife), -// lunamethod(Decal_BindLua, SetFadeStart), -// lunamethod(Decal_BindLua, GetFadeStart), -// { NULL, NULL } -//}; -//Luna::PropertyType Decal_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Decal_BindLua::Decal_BindLua(Decal* decal) -//{ -// node = decal; -// transform = decal; -// cullable = decal; -// this->decal = decal; -//} -//Decal_BindLua::Decal_BindLua(lua_State *L) -//{ -// Transform_BindLua(); -// Cullable_BindLua(); -// XMFLOAT3 tra = XMFLOAT3(0, 0, 0); -// XMFLOAT3 sca = XMFLOAT3(1, 1, 1); -// XMFLOAT4 rot = XMFLOAT4(0, 0, 0, 1); -// string tex = ""; -// string nor = ""; -// -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// { -// Vector_BindLua* t = Luna::lightcheck(L, 1); -// if (t != nullptr) -// { -// XMStoreFloat3(&tra, t->vector); -// } -// } -// -// if (argc > 1) -// { -// { -// Vector_BindLua* t = Luna::lightcheck(L, 2); -// if (t != nullptr) -// { -// XMStoreFloat3(&sca, t->vector); -// } -// } -// -// if (argc > 2) -// { -// { -// Vector_BindLua* t = Luna::lightcheck(L, 3); -// if (t != nullptr) -// { -// XMStoreFloat4(&rot, t->vector); -// } -// } -// -// if (argc > 3) -// { -// tex = wiLua::SGetString(L, 4); -// -// if (argc > 4) -// { -// nor = wiLua::SGetString(L, 5); -// } -// } -// } -// } -// } -// -// decal = new Decal(tra,sca,rot,tex,nor); -//} -//Decal_BindLua::~Decal_BindLua() -//{ -//} -// -//int Decal_BindLua::SetTexture(lua_State *L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// decal->addTexture(wiLua::SGetString(L, 1)); -// } -// else -// { -// wiLua::SError(L, "SetTexture(string textureName) not enough arguments!"); -// } -// return 0; -//} -//int Decal_BindLua::SetNormal(lua_State *L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// decal->addNormal(wiLua::SGetString(L, 1)); -// } -// else -// { -// wiLua::SError(L, "SetNormal(string textureName) not enough arguments!"); -// } -// return 0; -//} -//int Decal_BindLua::SetLife(lua_State *L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// decal->life = wiLua::SGetFloat(L, 1); -// } -// else -// { -// wiLua::SError(L, "SetLife(float value) not enough arguments!"); -// } -// return 0; -//} -//int Decal_BindLua::GetLife(lua_State *L) -//{ -// wiLua::SSetFloat(L, decal->life); -// return 1; -//} -//int Decal_BindLua::SetFadeStart(lua_State *L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// decal->fadeStart = wiLua::SGetFloat(L, 1); -// } -// else -// { -// wiLua::SError(L, "SetLife(float value) not enough arguments!"); -// } -// return 0; -//} -//int Decal_BindLua::GetFadeStart(lua_State *L) -//{ -// wiLua::SSetFloat(L, decal->fadeStart); -// return 1; -//} -// -//void Decal_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -//const char Ray_BindLua::className[] = "Ray"; -// -//Luna::FunctionType Ray_BindLua::methods[] = { -// lunamethod(Ray_BindLua, GetOrigin), -// lunamethod(Ray_BindLua, GetDirection), -// { 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()); -// } -//} -// -// -// -// -//const char AABB_BindLua::className[] = "AABB"; -// -//Luna::FunctionType AABB_BindLua::methods[] = { -// lunamethod(AABB_BindLua, Intersects), -// lunamethod(AABB_BindLua, Transform), -// lunamethod(AABB_BindLua, GetMin), -// lunamethod(AABB_BindLua, GetMax), -// { NULL, NULL } -//}; -//Luna::PropertyType AABB_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//AABB_BindLua::AABB_BindLua(const AABB& aabb) :aabb(aabb) -//{ -//} -//AABB_BindLua::AABB_BindLua(lua_State *L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Vector_BindLua* min = Luna::lightcheck(L, 1); -// Vector_BindLua* max = Luna::lightcheck(L, 2); -// if (min && max) -// { -// XMFLOAT3 fmin, fmax; -// XMStoreFloat3(&fmin, min->vector); -// XMStoreFloat3(&fmax, max->vector); -// aabb = AABB(wiMath::Min(fmin, fmax), wiMath::Max(fmin, fmax)); -// } -// else -// wiLua::SError(L, "AABB(Vector min,max) one of the arguments is not an AABB!"); -// } -// else -// aabb = AABB(XMFLOAT3(0, 0, 0), XMFLOAT3(0, 0, 0)); -//} -//AABB_BindLua::~AABB_BindLua() -//{ -//} -// -//int AABB_BindLua::Intersects(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// AABB_BindLua* box = Luna::lightcheck(L, 1); -// if (box) -// { -// wiLua::SSetBool(L, aabb.intersects(box->aabb) != AABB::INTERSECTION_TYPE::OUTSIDE); -// return 1; -// } -// else -// wiLua::SError(L, "Intersects(AABB aabb) argument is not an AABB!"); -// } -// else -// wiLua::SError(L, "Intersects(AABB aabb) not enough arguments!"); -// return 0; -//} -//int AABB_BindLua::Transform(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Matrix_BindLua* mat = Luna::lightcheck(L, 1); -// if (mat) -// { -// Luna::push(L, new AABB_BindLua(aabb.get(mat->matrix))); -// return 1; -// } -// else -// wiLua::SError(L, "Transform(Matrix mat) argument is not a Matrix!"); -// } -// else -// wiLua::SError(L, "Transform(Matrix mat) not enough arguments!"); -// return 0; -//} -//int AABB_BindLua::GetMin(lua_State* L) -//{ -// Luna::push(L, new Vector_BindLua(XMLoadFloat3(&aabb.getMin()))); -// return 1; -//} -//int AABB_BindLua::GetMax(lua_State* L) -//{ -// Luna::push(L, new Vector_BindLua(XMLoadFloat3(&aabb.getMax()))); -// return 1; -//} -// -//void AABB_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -// -//const char EmittedParticle_BindLua::className[] = "Emitter"; -// -//Luna::FunctionType EmittedParticle_BindLua::methods[] = { -// lunamethod(EmittedParticle_BindLua, GetName), -// lunamethod(EmittedParticle_BindLua, SetName), -// lunamethod(EmittedParticle_BindLua, GetMotionBlur), -// lunamethod(EmittedParticle_BindLua, SetMotionBlur), -// lunamethod(EmittedParticle_BindLua, Burst), -// lunamethod(EmittedParticle_BindLua, IsValid), -// { NULL, NULL } -//}; -//Luna::PropertyType EmittedParticle_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//EmittedParticle_BindLua::EmittedParticle_BindLua(wiEmittedParticle* ps) :ps(ps) -//{ -//} -//EmittedParticle_BindLua::EmittedParticle_BindLua(lua_State *L) -//{ -// ps = nullptr; -//} -//EmittedParticle_BindLua::~EmittedParticle_BindLua() -//{ -//} -// -//int EmittedParticle_BindLua::GetName(lua_State* L) -//{ -// if (ps == nullptr) -// { -// wiLua::SError(L, "GetName() particle system is null!"); -// return 0; -// } -// wiLua::SSetString(L, ps->name); -// return 1; -//} -//int EmittedParticle_BindLua::SetName(lua_State* L) -//{ -// if (ps == nullptr) -// { -// wiLua::SError(L, "SetName(string name) particle system is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// ps->name = wiLua::SGetString(L, 1); -// } -// else -// wiLua::SError(L, "SetName(string name) not enough arguments!"); -// return 0; -//} -//int EmittedParticle_BindLua::GetMotionBlur(lua_State* L) -//{ -// if (ps == nullptr) -// { -// wiLua::SError(L, "GetMotionBlur() particle system is null!"); -// return 0; -// } -// wiLua::SSetFloat(L, ps->motionBlurAmount); -// return 1; -//} -//int EmittedParticle_BindLua::SetMotionBlur(lua_State* L) -//{ -// if (ps == nullptr) -// { -// wiLua::SError(L, "SetMotionBlur(float amount) particle system is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// ps->motionBlurAmount = wiLua::SGetFloat(L, 1); -// } -// else -// wiLua::SError(L, "SetMotionBlur(float amount) not enough arguments!"); -// return 0; -//} -//int EmittedParticle_BindLua::Burst(lua_State* L) -//{ -// if (ps == nullptr) -// { -// wiLua::SError(L, "Burst(float num) particle system is null!"); -// return 0; -// } -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// ps->Burst(wiLua::SGetFloat(L, 1)); -// } -// else -// wiLua::SError(L, "Burst(float num) not enough arguments!"); -// return 0; -//} -//int EmittedParticle_BindLua::IsValid(lua_State *L) -//{ -// wiLua::SSetBool(L, ps != nullptr); -// return 1; -//} -// -//void EmittedParticle_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -// -//const char Material_BindLua::className[] = "Emitter"; -// -//Luna::FunctionType Material_BindLua::methods[] = { -// lunamethod(Material_BindLua, GetName), -// lunamethod(Material_BindLua, SetName), -// lunamethod(Material_BindLua, GetColor), -// lunamethod(Material_BindLua, SetColor), -// lunamethod(Material_BindLua, GetAlpha), -// lunamethod(Material_BindLua, SetAlpha), -// lunamethod(Material_BindLua, GetRefractionIndex), -// lunamethod(Material_BindLua, SetRefractionIndex), -// { NULL, NULL } -//}; -//Luna::PropertyType Material_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Material_BindLua::Material_BindLua(Material* material) :material(material) -//{ -//} -//Material_BindLua::Material_BindLua(lua_State *L) -//{ -// material = new Material(); -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// material->name = wiLua::SGetString(L, 1); -// } -//} -//Material_BindLua::~Material_BindLua() -//{ -//} -// -//int Material_BindLua::GetName(lua_State* L) -//{ -// wiLua::SSetString(L, material->name); -// return 1; -//} -//int Material_BindLua::SetName(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// material->name = wiLua::SGetString(L, 1); -// } -// else -// wiLua::SError(L, "SetName(string name) not enough arguments!"); -// return 0; -//} -//int Material_BindLua::GetColor(lua_State* L) -//{ -// Luna::push(L, new Vector_BindLua(XMLoadFloat3(&material->diffuseColor))); -// return 1; -//} -//int Material_BindLua::SetColor(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// Vector_BindLua* vec = Luna::lightcheck(L, 1); -// if (vec != nullptr) -// { -// XMStoreFloat3(&material->diffuseColor, vec->vector); -// } -// else -// { -// wiLua::SError(L, "SetColor(Vector color) argument is not a Vector!"); -// } -// } -// else -// wiLua::SError(L, "SetColor(Vector color) not enough arguments!"); -// return 0; -//} -//int Material_BindLua::GetAlpha(lua_State* L) -//{ -// wiLua::SSetFloat(L, material->alpha); -// return 1; -//} -//int Material_BindLua::SetAlpha(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// material->alpha = wiLua::SGetFloat(L, 1); -// } -// else -// wiLua::SError(L, "SetTransparency(float alpha) not enough arguments!"); -// return 0; -//} -//int Material_BindLua::GetRefractionIndex(lua_State* L) -//{ -// wiLua::SSetFloat(L, material->refractionIndex); -// return 1; -//} -//int Material_BindLua::SetRefractionIndex(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// material->refractionIndex = wiLua::SGetFloat(L, 1); -// } -// else -// wiLua::SError(L, "SetRefractionIndex(float alpha) not enough arguments!"); -// return 0; -//} -// -//void Material_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -// -// -// -// -// -//const char Camera_BindLua::className[] = "Camera"; -// -//Luna::FunctionType Camera_BindLua::methods[] = { -// lunamethod(Node_BindLua, GetName), -// lunamethod(Node_BindLua, SetName), -// lunamethod(Node_BindLua, SetLayerMask), -// lunamethod(Node_BindLua, GetLayerMask), -// -// lunamethod(Transform_BindLua, AttachTo), -// lunamethod(Transform_BindLua, Detach), -// lunamethod(Transform_BindLua, DetachChild), -// lunamethod(Transform_BindLua, ApplyTransform), -// lunamethod(Transform_BindLua, Scale), -// lunamethod(Transform_BindLua, Rotate), -// lunamethod(Transform_BindLua, Translate), -// lunamethod(Transform_BindLua, MatrixTransform), -// lunamethod(Transform_BindLua, GetMatrix), -// lunamethod(Transform_BindLua, ClearTransform), -// lunamethod(Transform_BindLua, SetTransform), -// lunamethod(Transform_BindLua, GetPosition), -// lunamethod(Transform_BindLua, GetRotation), -// lunamethod(Transform_BindLua, GetScale), -// -// lunamethod(Camera_BindLua, SetFarPlane), -// lunamethod(Camera_BindLua, SetNearPlane), -// lunamethod(Camera_BindLua, SetFOV), -// lunamethod(Camera_BindLua, GetFarPlane), -// lunamethod(Camera_BindLua, GetNearPlane), -// lunamethod(Camera_BindLua, GetFOV), -// lunamethod(Camera_BindLua, Lerp), -// lunamethod(Camera_BindLua, CatmullRom), -// { NULL, NULL } -//}; -//Luna::PropertyType Camera_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Camera_BindLua::Camera_BindLua(Camera* cam) -//{ -// node = cam; -// transform = cam; -// this->cam = cam; -//} -//Camera_BindLua::Camera_BindLua(lua_State *L) -//{ -// Transform_BindLua(); -// cam = new Camera; -//} -//Camera_BindLua::~Camera_BindLua() -//{ -//} -// -//int Camera_BindLua::SetFarPlane(lua_State *L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// cam->zFarP = wiLua::SGetFloat(L, 1); -// cam->UpdateProjection(); -// } -// else -// { -// wiLua::SError(L, "SetFarPlane(float val) not enough arguments!"); -// } -// return 0; -//} -//int Camera_BindLua::SetNearPlane(lua_State *L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// cam->zNearP = wiLua::SGetFloat(L, 1); -// cam->UpdateProjection(); -// } -// else -// { -// wiLua::SError(L, "SetNearPlane(float val) not enough arguments!"); -// } -// return 0; -//} -//int Camera_BindLua::SetFOV(lua_State *L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 0) -// { -// cam->fov = wiLua::SGetFloat(L, 1); -// cam->UpdateProjection(); -// } -// else -// { -// wiLua::SError(L, "SetFOV(float val) not enough arguments!"); -// } -// return 0; -//} -//int Camera_BindLua::GetFarPlane(lua_State *L) -//{ -// wiLua::SSetFloat(L, cam->zFarP); -// return 1; -//} -//int Camera_BindLua::GetNearPlane(lua_State *L) -//{ -// wiLua::SSetFloat(L, cam->zNearP); -// return 1; -//} -//int Camera_BindLua::GetFOV(lua_State *L) -//{ -// wiLua::SSetFloat(L, cam->fov); -// return 1; -//} -//int Camera_BindLua::Lerp(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 2) -// { -// Camera_BindLua* a = Luna::lightcheck(L, 1); -// if (a != nullptr) -// { -// Camera_BindLua* b = Luna::lightcheck(L, 2); -// -// if (b != nullptr) -// { -// float t = wiLua::SGetFloat(L, 3); -// this->cam->Lerp(a->cam, b->cam, t); -// } -// else -// { -// wiLua::SError(L, "Lerp(Camera a,b, float t) argument (b) is not a Camera!"); -// } -// } -// else -// { -// wiLua::SError(L, "Lerp(Camera a,b, float t) argument (a) is not a Camera!"); -// } -// } -// else -// { -// wiLua::SError(L, "Lerp(Camera a,b, float t) not enough arguments!"); -// } -// return 0; -//} -//int Camera_BindLua::CatmullRom(lua_State* L) -//{ -// int argc = wiLua::SGetArgCount(L); -// if (argc > 4) -// { -// Camera_BindLua* a = Luna::lightcheck(L, 1); -// if (a != nullptr) -// { -// Camera_BindLua* b = Luna::lightcheck(L, 2); -// -// if (b != nullptr) -// { -// Camera_BindLua* c = Luna::lightcheck(L, 3); -// -// if (c != nullptr) -// { -// Camera_BindLua* d = Luna::lightcheck(L, 4); -// -// if (d != nullptr) -// { -// float t = wiLua::SGetFloat(L, 5); -// this->cam->CatmullRom(a->cam, b->cam, c->cam, d->cam, t); -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Camera a,b,c,d, float t) argument (d) is not a Camera!"); -// } -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Camera a,b,c,d, float t) argument (c) is not a Camera!"); -// } -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Camera a,b,c,d, float t) argument (b) is not a Camera!"); -// } -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Camera a,b,c,d, float t) argument (a) is not a Camera!"); -// } -// } -// else -// { -// wiLua::SError(L, "CatmullRom(Camera a,b,c,d, float t) not enough arguments!"); -// } -// return 0; -//} -// -//void Camera_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} -// -// -// -// -// -// -// -// -//const char Model_BindLua::className[] = "Model"; -// -//Luna::FunctionType Model_BindLua::methods[] = { -// lunamethod(Node_BindLua, GetName), -// lunamethod(Node_BindLua, SetName), -// lunamethod(Node_BindLua, SetLayerMask), -// lunamethod(Node_BindLua, GetLayerMask), -// -// lunamethod(Transform_BindLua, AttachTo), -// lunamethod(Transform_BindLua, Detach), -// lunamethod(Transform_BindLua, DetachChild), -// lunamethod(Transform_BindLua, ApplyTransform), -// lunamethod(Transform_BindLua, Scale), -// lunamethod(Transform_BindLua, Rotate), -// lunamethod(Transform_BindLua, Translate), -// lunamethod(Transform_BindLua, Lerp), -// lunamethod(Transform_BindLua, CatmullRom), -// lunamethod(Transform_BindLua, MatrixTransform), -// lunamethod(Transform_BindLua, GetMatrix), -// lunamethod(Transform_BindLua, ClearTransform), -// lunamethod(Transform_BindLua, SetTransform), -// lunamethod(Transform_BindLua, GetPosition), -// lunamethod(Transform_BindLua, GetRotation), -// lunamethod(Transform_BindLua, GetScale), -// -// { NULL, NULL } -//}; -//Luna::PropertyType Model_BindLua::properties[] = { -// { NULL, NULL } -//}; -// -//Model_BindLua::Model_BindLua(Model* model) -//{ -// node = model; -// transform = model; -// this->model = model; -//} -//Model_BindLua::Model_BindLua(lua_State *L) -//{ -// Transform_BindLua(); -// model = new Model; -//} -//Model_BindLua::~Model_BindLua() -//{ -//} -// -// -//void Model_BindLua::Bind() -//{ -// static bool initialized = false; -// if (!initialized) -// { -// initialized = true; -// Luna::Register(wiLua::GetGlobal()->GetLuaState()); -// } -//} - -} diff --git a/WickedEngine/wiSceneComponents_BindLua.h b/WickedEngine/wiSceneComponents_BindLua.h deleted file mode 100644 index a2099ebaa..000000000 --- a/WickedEngine/wiSceneComponents_BindLua.h +++ /dev/null @@ -1,297 +0,0 @@ -#pragma once -#include "wiLua.h" -#include "wiLuna.h" -#include "wiSceneSystem.h" - -namespace wiSceneComponents_BindLua -{ - void Bind(); - - //class Node_BindLua - //{ - //public: - // Node* node; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // Node_BindLua(Node* node = nullptr); - // Node_BindLua(lua_State *L); - // ~Node_BindLua(); - - // int GetName(lua_State* L); - // int SetName(lua_State* L); - // int SetLayerMask(lua_State *L); - // int GetLayerMask(lua_State *L); - - // static void Bind(); - //}; - - //class Transform_BindLua : public Node_BindLua - //{ - //public: - // Transform * transform; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // Transform_BindLua(Transform* transform = nullptr); - // Transform_BindLua(lua_State *L); - // ~Transform_BindLua(); - - // int AttachTo(lua_State* L); - // int Detach(lua_State* L); - // int DetachChild(lua_State* L); - // int ApplyTransform(lua_State* L); - // int Scale(lua_State* L); - // int Rotate(lua_State* L); - // int Translate(lua_State* L); - // int Lerp(lua_State* L); - // int CatmullRom(lua_State* L); - // int MatrixTransform(lua_State* L); - // int GetMatrix(lua_State* L); - // int ClearTransform(lua_State* L); - // int SetTransform(lua_State* L); - // int GetPosition(lua_State* L); - // int GetRotation(lua_State* L); - // int GetScale(lua_State* L); - - // static void Bind(); - //}; - - //class Cullable_BindLua - //{ - //public: - // Cullable * cullable; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // Cullable_BindLua(Cullable* cullable = nullptr); - // Cullable_BindLua(lua_State *L); - // ~Cullable_BindLua(); - - // int Intersects(lua_State *L); - // int GetAABB(lua_State* L); - // int SetAABB(lua_State* L); - - // static void Bind(); - //}; - - //class Object_BindLua : public Cullable_BindLua, public Transform_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 EmitTrail(lua_State *L); - // int SetTrailDistortTex(lua_State *L); - // int SetTrailTex(lua_State *L); - // int SetTransparency(lua_State *L); - // int GetTransparency(lua_State *L); - // int SetColor(lua_State *L); - // int GetColor(lua_State *L); - // int GetEmitter(lua_State *L); - // int IsValid(lua_State *L); - - // static void Bind(); - //}; - - //class Armature_BindLua : public Transform_BindLua - //{ - //public: - // Armature * armature; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // Armature_BindLua(Armature* armature = nullptr); - // Armature_BindLua(lua_State* L); - // ~Armature_BindLua(); - - // int GetAction(lua_State* L); - // int GetActions(lua_State* L); - // int GetBones(lua_State* L); - // int GetBone(lua_State* L); - // int GetFrame(lua_State* L); - // int GetFrameCount(lua_State* L); - // int IsValid(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); - // int AddAnimLayer(lua_State* L); - // int DeleteAnimLayer(lua_State* L); - // int SetAnimLayerWeight(lua_State* L); - // int SetAnimLayerLooped(lua_State* L); - - // static void Bind(); - //}; - - //class Decal_BindLua : public Cullable_BindLua, public Transform_BindLua - //{ - //public: - // Decal * decal; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // Decal_BindLua(Decal* decal); - // Decal_BindLua(lua_State* L); - // ~Decal_BindLua(); - - // int SetTexture(lua_State* L); - // int SetNormal(lua_State* L); - // int SetLife(lua_State* L); - // int GetLife(lua_State* L); - // int SetFadeStart(lua_State* L); - // int GetFadeStart(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(); - //}; - - //class AABB_BindLua - //{ - //public: - // AABB aabb; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // AABB_BindLua(const AABB& ray); - // AABB_BindLua(lua_State* L); - // ~AABB_BindLua(); - - // int Intersects(lua_State* L); - // int Transform(lua_State* L); - // int GetMin(lua_State* L); - // int GetMax(lua_State* L); - - // static void Bind(); - //}; - - //class EmittedParticle_BindLua - //{ - //public: - // wiEmittedParticle * ps; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // EmittedParticle_BindLua(wiEmittedParticle* ps); - // EmittedParticle_BindLua(lua_State* L); - // ~EmittedParticle_BindLua(); - - // int GetName(lua_State* L); - // int SetName(lua_State* L); - // int GetMotionBlur(lua_State* L); - // int SetMotionBlur(lua_State* L); - // int Burst(lua_State* L); - // int IsValid(lua_State* L); - - // static void Bind(); - //}; - - //class Material_BindLua - //{ - //public: - // Material * material; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // Material_BindLua(Material* material); - // Material_BindLua(lua_State* L); - // ~Material_BindLua(); - - // int GetName(lua_State* L); - // int SetName(lua_State* L); - // int GetColor(lua_State* L); - // int SetColor(lua_State* L); - // int GetAlpha(lua_State* L); - // int SetAlpha(lua_State* L); - // int GetRefractionIndex(lua_State* L); - // int SetRefractionIndex(lua_State* L); - - // static void Bind(); - //}; - - //class Camera_BindLua : public Transform_BindLua - //{ - //public: - // Camera * cam; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // Camera_BindLua(Camera* cam); - // Camera_BindLua(lua_State* L); - // ~Camera_BindLua(); - - // int GetFarPlane(lua_State* L); - // int SetFarPlane(lua_State* L); - // int GetNearPlane(lua_State* L); - // int SetNearPlane(lua_State* L); - // int GetFOV(lua_State* L); - // int SetFOV(lua_State* L); - // int Lerp(lua_State* L); - // int CatmullRom(lua_State* L); - - // static void Bind(); - //}; - - //class Model_BindLua :public Transform_BindLua - //{ - //public: - // Model * model; - - // static const char className[]; - // static Luna::FunctionType methods[]; - // static Luna::PropertyType properties[]; - - // Model_BindLua(Model* model); - // Model_BindLua(lua_State* L); - // ~Model_BindLua(); - - // static void Bind(); - //}; - -} - diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index c7c7e1e86..a70946711 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -424,6 +424,50 @@ namespace wiSceneSystem assert(SUCCEEDED(hr)); } + // vertexBuffer - COLORS + if (!vertex_colors.empty()) + { + GPUBufferDesc bd; + bd.Usage = USAGE_IMMUTABLE; + bd.CPUAccessFlags = 0; + bd.BindFlags = BIND_VERTEX_BUFFER | BIND_SHADER_RESOURCE; + bd.MiscFlags = 0; + bd.StructureByteStride = sizeof(uint32_t); + bd.ByteWidth = (UINT)(bd.StructureByteStride * vertex_colors.size()); + bd.Format = FORMAT_R8G8B8A8_UNORM; + + SubresourceData InitData; + InitData.pSysMem = vertex_colors.data(); + vertexBuffer_COL.reset(new GPUBuffer); + hr = wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, vertexBuffer_COL.get()); + assert(SUCCEEDED(hr)); + } + + // vertexBuffer - ATLAS + if (!vertex_atlas.empty()) + { + std::vector vertices(vertex_atlas.size()); + for (size_t i = 0; i < vertices.size(); ++i) + { + vertices[i].FromFULL(vertex_atlas[i]); + } + + GPUBufferDesc bd; + bd.Usage = USAGE_IMMUTABLE; + bd.CPUAccessFlags = 0; + bd.BindFlags = BIND_VERTEX_BUFFER | BIND_SHADER_RESOURCE; + bd.MiscFlags = 0; + bd.StructureByteStride = sizeof(Vertex_TEX); + bd.ByteWidth = (UINT)(bd.StructureByteStride * vertices.size()); + bd.Format = Vertex_TEX::FORMAT; + + SubresourceData InitData; + InitData.pSysMem = vertices.data(); + vertexBuffer_ATL.reset(new GPUBuffer); + hr = wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, vertexBuffer_ATL.get()); + assert(SUCCEEDED(hr)); + } + } void MeshComponent::ComputeNormals(bool smooth) { @@ -931,6 +975,19 @@ namespace wiSceneSystem } return INVALID_ENTITY; } + Entity Scene::Entity_Duplicate(Entity entity) + { + wiArchive archive; + + // First write the entity to staging area: + archive.SetReadModeAndResetPos(false); + Entity_Serialize(archive, entity, 0); + + // Then deserialize with a unique seed: + archive.SetReadModeAndResetPos(true); + uint32_t seed = wiRandom::getRandom(1, INT_MAX); + return Entity_Serialize(archive, entity, seed); + } Entity Scene::Entity_CreateMaterial( const std::string& name ) @@ -1252,58 +1309,54 @@ namespace wiSceneSystem continue; } - for (auto& channel : animation.channels) + for (const AnimationComponent::AnimationChannel& channel : animation.channels) { - if (channel.keyframe_times.empty()) - { - // No keyframes! - assert(0); - continue; - } + assert(channel.samplerIndex < animation.samplers.size()); + const AnimationComponent::AnimationSampler& sampler = animation.samplers[channel.samplerIndex]; int keyLeft = 0; int keyRight = 0; - if (channel.keyframe_times.back() < animation.timer) + if (sampler.keyframe_times.back() < animation.timer) { // Rightmost keyframe is already outside animation, so just snap to last keyframe: - keyLeft = keyRight = (int)channel.keyframe_times.size() - 1; + keyLeft = keyRight = (int)sampler.keyframe_times.size() - 1; } else { // Search for the right keyframe (greater/equal to anim time): - while (channel.keyframe_times[keyRight++] < animation.timer) {} + while (sampler.keyframe_times[keyRight++] < animation.timer) {} keyRight--; // Left keyframe is just near right: keyLeft = max(0, keyRight - 1); } - float left = channel.keyframe_times[keyLeft]; + float left = sampler.keyframe_times[keyLeft]; TransformComponent& transform = *transforms.GetComponent(channel.target); - if (channel.mode == AnimationComponent::AnimationChannel::Mode::STEP || keyLeft == keyRight) + if (sampler.mode == AnimationComponent::AnimationSampler::Mode::STEP || keyLeft == keyRight) { // Nearest neighbor method (snap to left): - switch (channel.type) + switch (channel.path) { - case AnimationComponent::AnimationChannel::Type::TRANSLATION: + case AnimationComponent::AnimationChannel::Path::TRANSLATION: { - assert(channel.keyframe_data.size() == channel.keyframe_times.size() * 3); - transform.translation_local = ((const XMFLOAT3*)channel.keyframe_data.data())[keyLeft]; + assert(sampler.keyframe_data.size() == sampler.keyframe_times.size() * 3); + transform.translation_local = ((const XMFLOAT3*)sampler.keyframe_data.data())[keyLeft]; } break; - case AnimationComponent::AnimationChannel::Type::ROTATION: + case AnimationComponent::AnimationChannel::Path::ROTATION: { - assert(channel.keyframe_data.size() == channel.keyframe_times.size() * 4); - transform.rotation_local = ((const XMFLOAT4*)channel.keyframe_data.data())[keyLeft]; + assert(sampler.keyframe_data.size() == sampler.keyframe_times.size() * 4); + transform.rotation_local = ((const XMFLOAT4*)sampler.keyframe_data.data())[keyLeft]; } break; - case AnimationComponent::AnimationChannel::Type::SCALE: + case AnimationComponent::AnimationChannel::Path::SCALE: { - assert(channel.keyframe_data.size() == channel.keyframe_times.size() * 3); - transform.scale_local = ((const XMFLOAT3*)channel.keyframe_data.data())[keyLeft]; + assert(sampler.keyframe_data.size() == sampler.keyframe_times.size() * 3); + transform.scale_local = ((const XMFLOAT3*)sampler.keyframe_data.data())[keyLeft]; } break; } @@ -1311,25 +1364,25 @@ namespace wiSceneSystem else { // Linear interpolation method: - float right = channel.keyframe_times[keyRight]; + float right = sampler.keyframe_times[keyRight]; float t = (animation.timer - left) / (right - left); - switch (channel.type) + switch (channel.path) { - case AnimationComponent::AnimationChannel::Type::TRANSLATION: + case AnimationComponent::AnimationChannel::Path::TRANSLATION: { - assert(channel.keyframe_data.size() == channel.keyframe_times.size() * 3); - const XMFLOAT3* data = (const XMFLOAT3*)channel.keyframe_data.data(); + assert(sampler.keyframe_data.size() == sampler.keyframe_times.size() * 3); + const XMFLOAT3* data = (const XMFLOAT3*)sampler.keyframe_data.data(); XMVECTOR vLeft = XMLoadFloat3(&data[keyLeft]); XMVECTOR vRight = XMLoadFloat3(&data[keyRight]); XMVECTOR vAnim = XMVectorLerp(vLeft, vRight, t); XMStoreFloat3(&transform.translation_local, vAnim); } break; - case AnimationComponent::AnimationChannel::Type::ROTATION: + case AnimationComponent::AnimationChannel::Path::ROTATION: { - assert(channel.keyframe_data.size() == channel.keyframe_times.size() * 4); - const XMFLOAT4* data = (const XMFLOAT4*)channel.keyframe_data.data(); + assert(sampler.keyframe_data.size() == sampler.keyframe_times.size() * 4); + const XMFLOAT4* data = (const XMFLOAT4*)sampler.keyframe_data.data(); XMVECTOR vLeft = XMLoadFloat4(&data[keyLeft]); XMVECTOR vRight = XMLoadFloat4(&data[keyRight]); XMVECTOR vAnim = XMQuaternionSlerp(vLeft, vRight, t); @@ -1337,10 +1390,10 @@ namespace wiSceneSystem XMStoreFloat4(&transform.rotation_local, vAnim); } break; - case AnimationComponent::AnimationChannel::Type::SCALE: + case AnimationComponent::AnimationChannel::Path::SCALE: { - assert(channel.keyframe_data.size() == channel.keyframe_times.size() * 3); - const XMFLOAT3* data = (const XMFLOAT3*)channel.keyframe_data.data(); + assert(sampler.keyframe_data.size() == sampler.keyframe_times.size() * 3); + const XMFLOAT3* data = (const XMFLOAT3*)sampler.keyframe_data.data(); XMVECTOR vLeft = XMLoadFloat3(&data[keyLeft]); XMVECTOR vRight = XMLoadFloat3(&data[keyRight]); XMVECTOR vAnim = XMVectorLerp(vLeft, vRight, t); @@ -1359,12 +1412,14 @@ namespace wiSceneSystem animation.timer += dt; } - if (animation.IsLooped() && animation.timer > animation.length) + const float animationLength = animation.GetLength(); + + if (animation.IsLooped() && animation.timer > animationLength) { animation.timer = 0.0f; } - animation.timer = min(animation.timer, animation.length); + animation.timer = min(animation.timer, animationLength); } } void RunPhysicsUpdateSystem( diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index 0d8161b2c..be355d656 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -206,6 +206,8 @@ namespace wiSceneSystem std::vector vertex_texcoords; std::vector vertex_boneindices; std::vector vertex_boneweights; + std::vector vertex_atlas; + std::vector vertex_colors; std::vector indices; struct MeshSubset @@ -226,6 +228,8 @@ namespace wiSceneSystem std::unique_ptr vertexBuffer_POS; std::unique_ptr vertexBuffer_TEX; std::unique_ptr vertexBuffer_BON; + std::unique_ptr vertexBuffer_COL; + std::unique_ptr vertexBuffer_ATL; std::unique_ptr streamoutBuffer_POS; std::unique_ptr streamoutBuffer_PRE; wiRenderTarget impostorTarget; @@ -792,7 +796,9 @@ namespace wiSceneSystem LOOPED = 1 << 1, }; uint32_t _flags = LOOPED; - float length = 0.0f; + float start = 0; + float end = 0; + float timer = 0.0f; struct AnimationChannel { @@ -802,14 +808,26 @@ namespace wiSceneSystem }; uint32_t _flags = EMPTY; - wiECS::Entity target = wiECS::INVALID_ENTITY; - enum Type + enum Path { TRANSLATION, ROTATION, SCALE, + UNKNOWN, TYPE_FORCE_UINT32 = 0xFFFFFFFF - } type = TRANSLATION; + } path = TRANSLATION; + + wiECS::Entity target = wiECS::INVALID_ENTITY; + uint32_t samplerIndex = 0; + }; + struct AnimationSampler + { + enum FLAGS + { + EMPTY = 0, + }; + uint32_t _flags = EMPTY; + enum Mode { LINEAR, @@ -822,12 +840,11 @@ namespace wiSceneSystem }; std::vector channels; - - // Non-serialized attributes: - float timer = 0.0f; + std::vector samplers; inline bool IsPlaying() const { return _flags & PLAYING; } inline bool IsLooped() const { return _flags & LOOPED; } + inline float GetLength() const { return end - start; } inline void Play() { _flags |= PLAYING; } inline void Pause() { _flags &= ~PLAYING; } @@ -895,10 +912,13 @@ namespace wiSceneSystem void Entity_Remove(wiECS::Entity entity); // Finds the first entity by the name (if it exists, otherwise returns INVALID_ENTITY): wiECS::Entity Entity_FindByName(const std::string& name); + // Duplicates all of an entity's components and creates a new entity with them: + wiECS::Entity Entity_Duplicate(wiECS::Entity entity); // Serializes entity and all of its components to archive: // You can specify entity = INVALID_ENTITY when the entity needs to be created from archive // You can specify seed = 0 when the archive is guaranteed to be storing persistent and unique entities - void Entity_Serialize(wiArchive& archive, wiECS::Entity entity = wiECS::INVALID_ENTITY, uint32_t seed = 0); + // Returns either the new entity that was read, or the original entity that was written + wiECS::Entity Entity_Serialize(wiArchive& archive, wiECS::Entity entity = wiECS::INVALID_ENTITY, uint32_t seed = 0); wiECS::Entity Entity_CreateMaterial( const std::string& name diff --git a/WickedEngine/wiSceneSystem_BindLua.cpp b/WickedEngine/wiSceneSystem_BindLua.cpp new file mode 100644 index 000000000..ad23f9cbc --- /dev/null +++ b/WickedEngine/wiSceneSystem_BindLua.cpp @@ -0,0 +1,392 @@ +#include "wiSceneSystem_BindLua.h" +#include "Vector_BindLua.h" +#include "Matrix_BindLua.h" +#include "wiEmittedParticle.h" +#include "Texture_BindLua.h" + +using namespace std; +using namespace wiECS; +using namespace wiSceneSystem; + +namespace wiSceneSystem_BindLua +{ + +void Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} + + + +const char Scene_BindLua::className[] = "Scene"; + +Luna::FunctionType Scene_BindLua::methods[] = { + lunamethod(Scene_BindLua, Update), + lunamethod(Scene_BindLua, Clear), + lunamethod(Scene_BindLua, Entity_FindByName), + lunamethod(Scene_BindLua, Component_GetTransform), + lunamethod(Scene_BindLua, Component_Attach), + lunamethod(Scene_BindLua, Component_Detach), + lunamethod(Scene_BindLua, Component_DetachChildren), + { NULL, NULL } +}; +Luna::PropertyType Scene_BindLua::properties[] = { + { NULL, NULL } +}; + +Scene_BindLua::Scene_BindLua(lua_State *L) +{ +} +Scene_BindLua::~Scene_BindLua() +{ +} + + +int Scene_BindLua::Update(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + float dt = wiLua::SGetFloat(L, 1); + scene->Update(dt); + } + else + { + wiLua::SError(L, "Scene::Update(float dt) not enough arguments!"); + } + return 0; +} +int Scene_BindLua::Clear(lua_State* L) +{ + scene->Clear(); + return 0; +} + +int Scene_BindLua::Entity_FindByName(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + string name = wiLua::SGetString(L, 1); + + Entity entity = scene->Entity_FindByName(name); + + wiLua::SSetInt(L, (int)entity); + return 1; + } + else + { + wiLua::SError(L, "Scene::Entity_FindByName(string name) not enough arguments!"); + } + return 0; +} + +int Scene_BindLua::Component_GetTransform(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wiLua::SGetInt(L, 1); + + TransformComponent* transform = scene->transforms.GetComponent(entity); + Luna::push(L, new TransformComponent_BindLua(transform)); + return 1; + } + else + { + wiLua::SError(L, "Scene::Component_GetTransform(Entity entity) not enough arguments!"); + } + return 0; +} +int Scene_BindLua::Component_Attach(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + Entity entity = (Entity)wiLua::SGetInt(L, 1); + Entity parent = (Entity)wiLua::SGetInt(L, 2); + + scene->Component_Attach(entity, parent); + } + else + { + wiLua::SError(L, "Scene::Component_Attach(Entity entity,parent) not enough arguments!"); + } + return 0; +} +int Scene_BindLua::Component_Detach(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wiLua::SGetInt(L, 1); + + scene->Component_Detach(entity); + } + else + { + wiLua::SError(L, "Scene::Component_Detach(Entity entity) not enough arguments!"); + } + return 0; +} +int Scene_BindLua::Component_DetachChildren(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Entity parent = (Entity)wiLua::SGetInt(L, 1); + + scene->Component_DetachChildren(parent); + } + else + { + wiLua::SError(L, "Scene::Component_DetachChildren(Entity parent) not enough arguments!"); + } + return 0; +} + + + + + +const char TransformComponent_BindLua::className[] = "TransformComponent"; + +Luna::FunctionType TransformComponent_BindLua::methods[] = { + lunamethod(TransformComponent_BindLua, Scale), + lunamethod(TransformComponent_BindLua, Rotate), + lunamethod(TransformComponent_BindLua, Translate), + lunamethod(TransformComponent_BindLua, Lerp), + lunamethod(TransformComponent_BindLua, CatmullRom), + lunamethod(TransformComponent_BindLua, MatrixTransform), + lunamethod(TransformComponent_BindLua, GetMatrix), + lunamethod(TransformComponent_BindLua, ClearTransform), + lunamethod(TransformComponent_BindLua, GetPosition), + lunamethod(TransformComponent_BindLua, GetRotation), + lunamethod(TransformComponent_BindLua, GetScale), + { NULL, NULL } +}; +Luna::PropertyType TransformComponent_BindLua::properties[] = { + { NULL, NULL } +}; + +TransformComponent_BindLua::TransformComponent_BindLua(lua_State *L) +{ +} +TransformComponent_BindLua::~TransformComponent_BindLua() +{ +} + +int TransformComponent_BindLua::Scale(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* v = Luna::lightcheck(L, 1); + if (v != nullptr) + { + XMFLOAT3 value; + XMStoreFloat3(&value, v->vector); + + transform->Scale(value); + } + else + { + wiLua::SError(L, "Scale(Vector vector) argument is not a vector!"); + } + } + else + { + wiLua::SError(L, "Scale(Vector vector) not enough arguments!"); + } + return 0; +} +int TransformComponent_BindLua::Rotate(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* v = Luna::lightcheck(L, 1); + if (v != nullptr) + { + XMFLOAT3 rollPitchYaw; + XMStoreFloat3(&rollPitchYaw, v->vector); + + transform->RotateRollPitchYaw(rollPitchYaw); + } + else + { + wiLua::SError(L, "Rotate(Vector vectorRollPitchYaw) argument is not a vector!"); + } + } + else + { + wiLua::SError(L, "Rotate(Vector vectorRollPitchYaw) not enough arguments!"); + } + return 0; +} +int TransformComponent_BindLua::Translate(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* v = Luna::lightcheck(L, 1); + if (v != nullptr) + { + XMFLOAT3 value; + XMStoreFloat3(&value, v->vector); + + transform->Translate(value); + } + else + { + wiLua::SError(L, "Translate(Vector vector) argument is not a vector!"); + } + } + else + { + wiLua::SError(L, "Translate(Vector vector) not enough arguments!"); + } + return 0; +} +int TransformComponent_BindLua::Lerp(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 2) + { + TransformComponent_BindLua* a = Luna::lightcheck(L, 1); + if (a != nullptr) + { + TransformComponent_BindLua* b = Luna::lightcheck(L, 2); + + if (b != nullptr) + { + float t = wiLua::SGetFloat(L, 3); + + transform->Lerp(*a->transform, *b->transform, t); + } + else + { + wiLua::SError(L, "Lerp(Transform a,b, float t) argument (b) is not a Transform!"); + } + } + else + { + wiLua::SError(L, "Lerp(Transform a,b, float t) argument (a) is not a Transform!"); + } + } + else + { + wiLua::SError(L, "Lerp(Transform a,b, float t) not enough arguments!"); + } + return 0; +} +int TransformComponent_BindLua::CatmullRom(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 4) + { + TransformComponent_BindLua* a = Luna::lightcheck(L, 1); + if (a != nullptr) + { + TransformComponent_BindLua* b = Luna::lightcheck(L, 2); + + if (b != nullptr) + { + TransformComponent_BindLua* c = Luna::lightcheck(L, 3); + + if (c != nullptr) + { + TransformComponent_BindLua* d = Luna::lightcheck(L, 4); + + if (d != nullptr) + { + float t = wiLua::SGetFloat(L, 5); + + transform->CatmullRom(*a->transform, *b->transform, *c->transform, *d->transform, t); + } + else + { + wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (d) is not a Transform!"); + } + } + else + { + wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (c) is not a Transform!"); + } + } + else + { + wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (b) is not a Transform!"); + } + } + else + { + wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (a) is not a Transform!"); + } + } + else + { + wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) not enough arguments!"); + } + return 0; +} +int TransformComponent_BindLua::MatrixTransform(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Matrix_BindLua* m = Luna::lightcheck(L, 1); + if (m != nullptr) + { + transform->MatrixTransform(m->matrix); + } + else + { + wiLua::SError(L, "MatrixTransform(Matrix matrix) argument is not a matrix!"); + } + } + else + { + wiLua::SError(L, "MatrixTransform(Matrix matrix) not enough arguments!"); + } + return 0; +} +int TransformComponent_BindLua::GetMatrix(lua_State* L) +{ + XMMATRIX M = XMLoadFloat4x4(&transform->world); + Luna::push(L, new Matrix_BindLua(M)); + return 1; +} +int TransformComponent_BindLua::ClearTransform(lua_State* L) +{ + transform->ClearTransform(); + return 0; +} +int TransformComponent_BindLua::GetPosition(lua_State* L) +{ + XMVECTOR V = transform->GetPositionV(); + Luna::push(L, new Vector_BindLua(V)); + return 1; +} +int TransformComponent_BindLua::GetRotation(lua_State* L) +{ + XMVECTOR V = transform->GetRotationV(); + Luna::push(L, new Vector_BindLua(V)); + return 1; +} +int TransformComponent_BindLua::GetScale(lua_State* L) +{ + XMVECTOR V = transform->GetScaleV(); + Luna::push(L, new Vector_BindLua(V)); + return 1; +} + + +} diff --git a/WickedEngine/wiSceneSystem_BindLua.h b/WickedEngine/wiSceneSystem_BindLua.h new file mode 100644 index 000000000..5d6495613 --- /dev/null +++ b/WickedEngine/wiSceneSystem_BindLua.h @@ -0,0 +1,62 @@ +#pragma once +#include "wiLua.h" +#include "wiLuna.h" +#include "wiSceneSystem.h" + +namespace wiSceneSystem_BindLua +{ + void Bind(); + + class Scene_BindLua + { + public: + wiSceneSystem::Scene* scene = nullptr; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + Scene_BindLua(wiSceneSystem::Scene* scene) :scene(scene) {} + Scene_BindLua(lua_State *L); + ~Scene_BindLua(); + + int Update(lua_State* L); + int Clear(lua_State* L); + + int Entity_FindByName(lua_State* L); + + int Component_GetTransform(lua_State* L); + + int Component_Attach(lua_State* L); + int Component_Detach(lua_State* L); + int Component_DetachChildren(lua_State* L); + }; + + class TransformComponent_BindLua + { + public: + wiSceneSystem::TransformComponent* transform = nullptr; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + TransformComponent_BindLua(wiSceneSystem::TransformComponent* transform) :transform(transform) {} + TransformComponent_BindLua(lua_State *L); + ~TransformComponent_BindLua(); + + int Scale(lua_State* L); + int Rotate(lua_State* L); + int Translate(lua_State* L); + int Lerp(lua_State* L); + int CatmullRom(lua_State* L); + int MatrixTransform(lua_State* L); + int GetMatrix(lua_State* L); + int ClearTransform(lua_State* L); + int GetPosition(lua_State* L); + int GetRotation(lua_State* L); + int GetScale(lua_State* L); + }; + +} + diff --git a/WickedEngine/wiSceneSystem_Serializers.cpp b/WickedEngine/wiSceneSystem_Serializers.cpp index 7ad58a6ad..049980d19 100644 --- a/WickedEngine/wiSceneSystem_Serializers.cpp +++ b/WickedEngine/wiSceneSystem_Serializers.cpp @@ -43,6 +43,7 @@ namespace wiSceneSystem archive >> translation_local; SetDirty(); + UpdateTransform(); } else { @@ -157,6 +158,8 @@ namespace wiSceneSystem archive >> vertex_texcoords; archive >> vertex_boneindices; archive >> vertex_boneweights; + archive >> vertex_atlas; + archive >> vertex_colors; archive >> indices; size_t subsetCount; @@ -183,6 +186,8 @@ namespace wiSceneSystem archive << vertex_texcoords; archive << vertex_boneindices; archive << vertex_boneweights; + archive << vertex_atlas; + archive << vertex_colors; archive << indices; archive << subsets.size(); @@ -265,18 +270,31 @@ namespace wiSceneSystem if (archive.IsReadMode()) { archive >> _flags; - archive >> boneCollection; - for (Entity& boneID : boneCollection) + + size_t boneCount; + archive >> boneCount; + boneCollection.resize(boneCount); + for (size_t i = 0; i < boneCount; ++i) { + Entity boneID; SerializeEntity(archive, boneID, seed); + boneCollection[i] = boneID; } + archive >> inverseBindMatrices; archive >> remapMatrix; } else { archive << _flags; - archive << boneCollection; + + archive << boneCollection.size(); + for (size_t i = 0; i < boneCollection.size(); ++i) + { + Entity boneID = boneCollection[i]; + SerializeEntity(archive, boneID, seed); + } + archive << inverseBindMatrices; archive << remapMatrix; } @@ -383,7 +401,9 @@ namespace wiSceneSystem if (archive.IsReadMode()) { archive >> _flags; - archive >> length; + archive >> start; + archive >> end; + archive >> timer; size_t channelCount; archive >> channelCount; @@ -391,27 +411,46 @@ namespace wiSceneSystem for (size_t i = 0; i < channelCount; ++i) { archive >> channels[i]._flags; + archive >> (uint32_t&)channels[i].path; SerializeEntity(archive, channels[i].target, seed); - archive >> (uint32_t&)channels[i].type; - archive >> (uint32_t&)channels[i].mode; - archive >> channels[i].keyframe_times; - archive >> channels[i].keyframe_data; + archive >> channels[i].samplerIndex; } + + size_t samplerCount; + archive >> samplerCount; + samplers.resize(samplerCount); + for (size_t i = 0; i < samplerCount; ++i) + { + archive >> samplers[i]._flags; + archive >> (uint32_t&)samplers[i].mode; + archive >> samplers[i].keyframe_times; + archive >> samplers[i].keyframe_data; + } + } else { archive << _flags; - archive << length; + archive << start; + archive << end; + archive << timer; archive << channels.size(); for (size_t i = 0; i < channels.size(); ++i) { archive << channels[i]._flags; + archive << (uint32_t&)channels[i].path; SerializeEntity(archive, channels[i].target, seed); - archive << (uint32_t&)channels[i].type; - archive << (uint32_t&)channels[i].mode; - archive << channels[i].keyframe_times; - archive << channels[i].keyframe_data; + archive << channels[i].samplerIndex; + } + + archive << samplers.size(); + for (size_t i = 0; i < samplers.size(); ++i) + { + archive << samplers[i]._flags; + archive << samplers[i].mode; + archive << samplers[i].keyframe_times; + archive << samplers[i].keyframe_data; } } } @@ -492,14 +531,13 @@ namespace wiSceneSystem } - void Scene::Entity_Serialize(wiArchive& archive, Entity entity, uint32_t seed) + Entity Scene::Entity_Serialize(wiArchive& archive, Entity entity, uint32_t seed) { + SerializeEntity(archive, entity, seed); + if (archive.IsReadMode()) { - archive >> entity; - - // Check for each components if it exists, and if yes, read it: - + // Check for each components if it exists, and if yes, READ it: { bool component_exists; archive >> component_exists; @@ -710,10 +748,7 @@ namespace wiSceneSystem } else { - archive << entity; - - // Find existing components one-by-one and write them out: - + // Find existing components one-by-one and WRITE them out: { auto component = names.GetComponent(entity); if (component != nullptr) @@ -992,6 +1027,8 @@ namespace wiSceneSystem } } + + return entity; } }