diff --git a/CMakeLists.txt b/CMakeLists.txt index dcc8e65..67024f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ add_subdirectory(external/glfw) add_subdirectory(external/gl3w) add_subdirectory(external/fmt) +include_directories(external/sobol) include_directories(external/pybind11/include) include_directories(external/linalg) include_directories(external/cereal/include) diff --git a/src/core/samplers/sobolmat.hpp b/external/sobol/sobolmat.hpp similarity index 100% rename from src/core/samplers/sobolmat.hpp rename to external/sobol/sobolmat.hpp diff --git a/src/api/graph.h b/src/api/graph.h index 9f9a3d7..ef0b6fb 100644 --- a/src/api/graph.h +++ b/src/api/graph.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,8 @@ namespace miyuki::core { MYK_AUTO_INIT(camera, sampler, integrator, shapes, filmDimension) + MYK_PROP(camera, sampler, integrator) + MYK_DECL_CLASS(SceneGraph, "SceneGraph") void render(const std::string &outImageFile); diff --git a/src/api/property.hpp b/src/api/property.hpp index 4967479..3642bb2 100644 --- a/src/api/property.hpp +++ b/src/api/property.hpp @@ -53,7 +53,10 @@ namespace miyuki { } // namespace detail using IntProperty = detail::BasicProperty; using FloatProperty = detail::BasicProperty; - using Vec3fProperty = detail::BasicProperty; + using Float3Property = detail::BasicProperty; + using Float2Property = detail::BasicProperty; + using Int2Property = detail::BasicProperty; + using EntityProperty = detail::BasicProperty>; // using VectorProperty = detail::BasicProperty>>; using FileProperty = detail::BasicProperty; @@ -63,14 +66,16 @@ namespace miyuki { virtual void visit(Property *prop) { prop->accept(this); } virtual void visit(IntProperty *) = 0; virtual void visit(FloatProperty *) = 0; - virtual void visit(Vec3fProperty *) = 0; + virtual void visit(Float3Property *) = 0; virtual void visit(EntityProperty *) = 0; virtual void visit(FileProperty *) = 0; + virtual void visit(Int2Property *) = 0; + virtual void visit(Float2Property *) = 0; }; struct ReflPropertyVisitor { PropertyVisitor *visitor; - + ReflPropertyVisitor(PropertyVisitor *visitor) : visitor(visitor) {} void visit(int &v, const char *name) { IntProperty prop(name, v); prop.accept(visitor); @@ -82,14 +87,26 @@ namespace miyuki { } void visit(Vec3f &v, const char *name) { - Vec3fProperty prop(name, v); + Float3Property prop(name, v); + prop.accept(visitor); + } + + void visit(Point2f &v, const char *name) { + Float2Property prop(name, v); + prop.accept(visitor); + } + + void visit(Point2i &v, const char *name) { + Int2Property prop(name, v); prop.accept(visitor); } template std::enable_if_t, void> visit(std::shared_ptr &v, const char *name) { - EntityProperty prop(name, v); + std::shared_ptr p = v; + EntityProperty prop(name, p); prop.accept(visitor); + v = std::dynamic_pointer_cast(p); } }; #define MYK_PROP(...) \ diff --git a/src/core/samplers/sobol-sampler.cpp b/src/core/samplers/sobol-sampler.cpp index 7ef2f06..baf27fa 100644 --- a/src/core/samplers/sobol-sampler.cpp +++ b/src/core/samplers/sobol-sampler.cpp @@ -23,7 +23,7 @@ #include #include "sobol-sampler.h" -#include "sobolmat.hpp" +#include namespace miyuki::core { diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index e19aa3e..015e98b 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -21,9 +21,9 @@ // SOFTWARE. #include +#include #include #include -#include #ifndef NOMINMAX #define NOMINMAX @@ -169,11 +169,85 @@ namespace miyuki::ui { ImGui::End(); } - class MainWindow : public AbstractMainWindow, public PropertyVisitor { + + class InspectorPropertyVisitor : public PropertyVisitor { + public: + // Inherited via PropertyVisitor + virtual void visit(IntProperty *prop) override { + auto value = prop->getConstRef(); + if (ImGui::InputInt(prop->name(), &value, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue)) { + prop->getRef() = value; + } + } + + virtual void visit(FloatProperty *prop) override { + auto value = prop->getConstRef(); + if (ImGui::InputFloat(prop->name(), &value, 0.0f, 0.0f, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue)) { + prop->getRef() = value; + } + } + + virtual void visit(Float3Property *prop) override { + auto value = prop->getConstRef(); + if (ImGui::InputFloat3(prop->name(), (float *)&value, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue)) { + prop->getRef() = value; + } + } + + virtual void visit(EntityProperty *prop) override { + if (ImGui::TreeNodeEx(prop->name(), ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::PushID(prop->name()); + + if (prop->getConstRef()) { + prop->getRef()->accept(this); + } + ImGui::TreePop(); + + ImGui::PopID(); + } + } + virtual void visit(FileProperty *prop) override { + ImGui::PushID(prop->name()); + if (ImGui::Button("select")) { + auto filename = GetOpenFileNameWithDialog(nullptr); + if (!filename.empty()) { + prop->getRef() = fs::path(filename); + } + } + ImGui::PopID(); + } + }; + + class ExplorerPropertyVisitor : public PropertyVisitor { + public: + // Inherited via PropertyVisitor + virtual void visit(IntProperty *) override {} + virtual void visit(FloatProperty *) override {} + virtual void visit(Float3Property *) override {} + virtual void visit(EntityProperty *prop) override { + if (ImGui::TreeNodeEx(prop->name(), ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::PushID(prop->name()); + + if (prop->getConstRef()) { + prop->getRef()->accept(this); + } + ImGui::TreePop(); + + ImGui::PopID(); + } + } + virtual void visit(FileProperty *) override {} + virtual void visit(Int2Property *) override {} + virtual void visit(Float2Property *) override {} + }; + class MainWindow : public AbstractMainWindow { std::shared_ptr graph; void showExplorer() { if (ImGui::Begin("Explorer")) { - + if (graph) { + ExplorerPropertyVisitor visitor; + graph->accept(&visitor); + } ImGui::End(); } } @@ -223,50 +297,6 @@ namespace miyuki::ui { showExplorer(); showInspector(); } - - // Inherited via PropertyVisitor - virtual void visit(IntProperty *prop) override { - auto value = prop->getConstRef(); - if (ImGui::InputInt(prop->name(), &value, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue)) { - prop->getRef() = value; - } - } - - virtual void visit(FloatProperty *prop) override { - auto value = prop->getConstRef(); - if (ImGui::InputFloat(prop->name(), &value, 0.0f, 0.0f, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue)) { - prop->getRef() = value; - } - } - - virtual void visit(Vec3fProperty *prop) override { - auto value = prop->getConstRef(); - if (ImGui::InputFloat3(prop->name(), (float *)&value, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue)) { - prop->getRef() = value; - } - } - - virtual void visit(EntityProperty *prop) override { - if (ImGui::TreeNodeEx(prop->name(), ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::PushID(prop->name()); - - if (prop->getConstRef()) { - prop->getRef()->accept(this); - } - - ImGui::PopID(); - } - } - virtual void visit(FileProperty *prop) override { - ImGui::PushID(prop->name()); - if (ImGui::Button("select")) { - auto filename = GetOpenFileNameWithDialog(nullptr); - if (!filename.empty()) { - prop->getRef() = fs::path(filename); - } - } - ImGui::PopID(); - } }; std::shared_ptr MakeMainWindow(int width, int height, const std::string &title) {