From a047032f8657afc395f57b49bb0bb48ddee2a2a3 Mon Sep 17 00:00:00 2001 From: antopilo Date: Mon, 13 Sep 2021 06:47:05 -0400 Subject: [PATCH] Maths functions scripting api --- Editor/resources/Scripts/Math.wren | 13 ++++++++-- Editor/src/FileSystemUI.cpp | 32 ++++++++++++++++-------- Nuake/src/Resource/MaterialCollection.h | 21 ++++++++++++++++ Nuake/src/Scripting/Modules/MathModule.h | 24 ++++++++++++++++++ Nuake/src/UI/Nodes/TextInput.h | 31 +++++++++++++++++++++++ 5 files changed, 108 insertions(+), 13 deletions(-) create mode 100644 Nuake/src/Resource/MaterialCollection.h create mode 100644 Nuake/src/UI/Nodes/TextInput.h diff --git a/Editor/resources/Scripts/Math.wren b/Editor/resources/Scripts/Math.wren index 7b254fec..477a0bc8 100644 --- a/Editor/resources/Scripts/Math.wren +++ b/Editor/resources/Scripts/Math.wren @@ -10,11 +10,16 @@ class Math { return Vector3.new(result[0], result[1], result[2]) } + static Dot(vec1, vec2) { + return this.Dot_(vec1.x, vec1.y, vec1.z, vec2.x, vec2.y, vec2.z) + } + + foreign static Dot_(x, y, z, x1, y2, z2) foreign static Cross_(x, y, z, x1, y2, z2) + foreign static Length_(x, y, z) } class Vector3 { - x {_x} y {_y} z {_z} @@ -113,7 +118,11 @@ class Vector3 { this.Normalize() * vec.Normalize() } + Dot(vec) { + return Math.Dot(this, vec) + } + Length() { - this.Sqrt() + return Math.Length_(_x, _y, _z) } } \ No newline at end of file diff --git a/Editor/src/FileSystemUI.cpp b/Editor/src/FileSystemUI.cpp index 184d8423..c60b9b2d 100644 --- a/Editor/src/FileSystemUI.cpp +++ b/Editor/src/FileSystemUI.cpp @@ -24,7 +24,6 @@ namespace Nuake { { } - void FileSystemUI::EditorInterfaceDrawFiletree(Ref dir) { ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth; @@ -53,7 +52,7 @@ namespace Nuake { void FileSystemUI::DrawDirectory(Ref directory) { ImGui::PushFont(EditorInterface::bigIconFont); - std::string id = ICON_FA_FOLDER + std::string("##") + directory->name; + std::string id = directory->name; if (ImGui::Button(id.c_str(), ImVec2(100, 100))) m_CurrentDirectory = directory; @@ -131,9 +130,9 @@ namespace Nuake { ImGui::EndDragDropSource(); } } + ImGui::Text(file->name.c_str()); ImGui::PopFont(); - } bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f) @@ -147,6 +146,7 @@ namespace Nuake { bb.Max = bb.Min + CalcItemSize(split_vertically ? ImVec2(thickness, splitter_long_axis_size) : ImVec2(splitter_long_axis_size, thickness), 0.0f, 0.0f); return SplitterBehavior(bb, id, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 0.0f); } + float h = 200; static float sz1 = 300; static float sz2 = 300; @@ -168,17 +168,19 @@ namespace Nuake { bool is_selected = m_CurrentDirectory == FileSystem::RootDirectory; if (is_selected) base_flags |= ImGuiTreeNodeFlags_Selected; - std::string icon = ICON_FA_FOLDER; + std::string icon = ICON_FA_FOLDER; bool open = ImGui::TreeNodeEx((icon + " " + "Project files").c_str(), base_flags); if (ImGui::IsItemClicked()) { m_CurrentDirectory = FileSystem::RootDirectory; } + if (open) { for(auto& d : rootDirectory->Directories) EditorInterfaceDrawFiletree(d); + ImGui::TreePop(); } @@ -192,6 +194,7 @@ namespace Nuake { Ref currentParent = m_CurrentDirectory; paths.push_back(m_CurrentDirectory); + while (currentParent != nullptr) { paths.push_back(currentParent); @@ -206,14 +209,19 @@ namespace Nuake { if (ImGui::BeginChild("Path", avail)) { if (ImGui::Button("Refresh")) + { FileSystem::Scan(); + m_CurrentDirectory = FileSystem::RootDirectory; + } + ImGui::SameLine(); - for (int i = paths.size() - 1; i > 0; i--) { + for (int i = paths.size() - 1; i > 0; i--) + { if (i != paths.size()) ImGui::SameLine(); - if (ImGui::Button(paths[i]->name.c_str())) { + + if (ImGui::Button(paths[i]->name.c_str())) m_CurrentDirectory = paths[i]; - } ImGui::SameLine(); ImGui::Text("/"); @@ -226,9 +234,9 @@ namespace Nuake { if (ImGui::BeginChild("Content", avail)) { - int width = ImGui::GetWindowWidth() * 0.8f; + int width = avail.x; ImVec2 buttonSize = ImVec2(80, 80); - int amount = (int)(width / 100); + int amount = (int)(width / 200); if (amount <= 0) amount = 1; int i = 1; // current amount of item per row. @@ -246,13 +254,15 @@ namespace Nuake { if (m_CurrentDirectory && m_CurrentDirectory->Directories.size() > 0) { - for (auto d : m_CurrentDirectory->Directories) + for (Ref& d : m_CurrentDirectory->Directories) { DrawDirectory(d); - if (i - 1 % amount != 0) + + if (i + 1 % amount != 0) ImGui::TableNextColumn(); else ImGui::TableNextRow(); + i++; } } diff --git a/Nuake/src/Resource/MaterialCollection.h b/Nuake/src/Resource/MaterialCollection.h new file mode 100644 index 00000000..9295f43b --- /dev/null +++ b/Nuake/src/Resource/MaterialCollection.h @@ -0,0 +1,21 @@ +#pragma once +#include "src/Core/Core.h" +#include "src/Rendering/Materials/Material.h" + +#include + +namespace Nuake { + class MaterialCollection + { + + private: + std::vector> m_Materials; + public: + + std::string Path; + MaterialCollection(const std::string path) + { + + } + }; +} \ No newline at end of file diff --git a/Nuake/src/Scripting/Modules/MathModule.h b/Nuake/src/Scripting/Modules/MathModule.h index 311a1846..d64b90a4 100644 --- a/Nuake/src/Scripting/Modules/MathModule.h +++ b/Nuake/src/Scripting/Modules/MathModule.h @@ -26,6 +26,8 @@ namespace Nuake { RegisterMethod("Radians(_)", (void*)Radians); RegisterMethod("Degrees(_)", (void*)Degrees); RegisterMethod("Cross_(_,_,_,_,_,_)", (void*)Cross); + RegisterMethod("Dot_(_,_,_,_,_,_)", (void*)Dot); + RegisterMethod("Length_(_,_,_)", (void*)Length); } static void Sqrt(WrenVM* vm) @@ -85,6 +87,28 @@ namespace Nuake { wrenInsertInList(vm, 0, -1, 2); wrenInsertInList(vm, 0, -1, 3); } + + static void Dot(WrenVM* vm) + { + Vector3 v1 = Vector3(wrenGetSlotDouble(vm, 1), + wrenGetSlotDouble(vm, 2), + wrenGetSlotDouble(vm, 3)); + Vector3 v2 = Vector3(wrenGetSlotDouble(vm, 4), + wrenGetSlotDouble(vm, 5), + wrenGetSlotDouble(vm, 6)); + float dot = glm::dot(v1, v2); + + wrenSetSlotDouble(vm, 0, dot); + } + + static void Length(WrenVM* vm) + { + Vector3 v1 = Vector3(wrenGetSlotDouble(vm, 1), + wrenGetSlotDouble(vm, 2), + wrenGetSlotDouble(vm, 3)); + + wrenSetSlotDouble(vm, 0, v1.length()); + } }; } } \ No newline at end of file diff --git a/Nuake/src/UI/Nodes/TextInput.h b/Nuake/src/UI/Nodes/TextInput.h new file mode 100644 index 00000000..9d45b485 --- /dev/null +++ b/Nuake/src/UI/Nodes/TextInput.h @@ -0,0 +1,31 @@ +#include +#include "Node.h" + +namespace Nuake +{ + namespace UI + { + class TextInput : public Node + { + private: + std::string content = ""; + bool IsFocus = false; + + Ref Background; + public: + TextInput() + { + Background = CreateRef(); + Background->NormalStyle.MinWidth = {200, Layout::Unit::PIXEL }; + Background->NormalStyle.MinHeight = { 30, Layout::Unit::PIXEL }; + + Childrens.push_back(Background); + } + + void Draw() + { + Renderer2D::DrawRect() + } + }; + } +} \ No newline at end of file