Skip to content

Commit

Permalink
🔀 Merge remote-tracking branch 'origin/dev/Meshing'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Cool
#	src/App.h
#	src/Module/Module.h
  • Loading branch information
JulesFouchy committed Aug 31, 2024
2 parents 4507580 + 1327fbd commit 94e374d
Show file tree
Hide file tree
Showing 38 changed files with 1,031 additions and 150 deletions.
13 changes: 9 additions & 4 deletions User data Default/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ DockId=0x00000029,1

[Window][  View]
Pos=1325,469
Size=595,268
Size=595,532
Collapsed=0
DockId=0x00000053,0

[Window][  Nodes]
Pos=0,30
Size=1323,412
Size=1323,924
Collapsed=0
DockId=0x0000005A,0

Expand Down Expand Up @@ -527,8 +527,8 @@ Size=507,283
Collapsed=0

[Window][  Export an Image]
Pos=669,356
Size=491,190
Pos=652,339
Size=502,237
Collapsed=0

[Window][  Test all Variable Widgets]
Expand Down Expand Up @@ -657,6 +657,11 @@ Size=1323,300
Collapsed=0
DockId=0x00000059,0

[Window][  Export a 3D Model]
Pos=669,313
Size=514,229
Collapsed=0

[Table][0x4EF0CFBB,2]
Column 0 Weight=1.0000
Column 1 Weight=1.0000
Expand Down
19 changes: 17 additions & 2 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ void App::render(Cool::RenderTarget& render_target, Cool::Time time, Cool::Time
{
_project.modules_graph->render(
render_target,
system_values(render_target.desired_size(), time, delta_time),
_nodes_library_manager.library()
data_to_pass_to_shader(render_target.desired_size(), time, delta_time),
data_to_generate_shader_code()
);
}

Expand Down Expand Up @@ -350,11 +350,21 @@ void App::imgui_window_exporter()
});
}

void App::imgui_window_meshing()
{
_meshing_gui.imgui_window(
_mesh_export_settings,
data_to_pass_to_shader(render_view().render_target().current_size(), _project.clock.time(), _project.clock.delta_time()),
data_to_generate_shader_code()
);
}

void App::imgui_windows()
{
imgui_window_view();
imgui_window_exporter();
imgui_window_console();
imgui_window_meshing();
if (inputs_are_allowed())
imgui_windows_only_when_inputs_are_allowed();
}
Expand Down Expand Up @@ -646,4 +656,9 @@ void App::open_video_exporter()
_project.exporter.video_export_window().open();
}

void App::open_meshing_window_for_node(Cool::NodeId const& node_id)
{
_meshing_gui.open_window(node_id);
}

} // namespace Lab
35 changes: 31 additions & 4 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,38 @@
#include "CommandCore/CommandExecutor_WithoutHistory_Ref.h"
#include "CommandCore/ReversibleCommandExecutor_WithoutHistory_Ref.h"
#include "Commands/Command_SetCameraZoom.h" // For the serialization functions
#include "Cool/AppManager/IApp.h"
#include "Cool/DebugOptions/DebugOptions.h"
#include "Cool/DebugOptions/DebugOptionsManager.h"
#include "Cool/Exporter/Exporter.h"
#include "Cool/Exporter/internal/Polaroid.h"
#include "Cool/Gpu/OpenGL/Texture.h"
#include "Cool/Gpu/RenderTarget.h"
#include "Cool/Mesh/MeshExportSettings.hpp"
#include "Cool/Midi/MidiChannel.h"
#include "Cool/Midi/MidiManager.h"
#include "Cool/Nodes/NodesLibrary.h"
#include "Cool/OSC/OSCManager.h"
#include "Cool/Server/ServerManager.hpp"
#include "Cool/StrongTypes/Camera2D.h"
#include "Cool/Time/Clock_Realtime.h"
#include "Cool/Tips/TipsManager.h"
#include "Cool/View/ForwardingOrRenderView.h"
#include "Cool/View/RenderView.h"
#include "Cool/View/ViewsManager.h"
#include "Cool/Webcam/WebcamsConfigs.h"
#include "Cool/Window/WindowManager.h"
#include "Debug/DebugOptions.h"
#include "Dependencies/History.h"
#include "Gallery/GalleryPoster.h"
#include "Meshing/MeshingGui.hpp"
#include "Module/ShaderBased/DataToGenerateShaderCode.hpp"
#include "Module/ShaderBased/DataToPassToShader.hpp"
#include "Nodes/NodesLibraryManager.h"
#include "Project.h"
#include "ProjectManager/Command_SaveProject.h"
#include "ProjectManager/RecentlyOpened.h"
#include "reg/ser20.hpp"

namespace Lab {

Expand All @@ -54,6 +73,7 @@ class App : public Cool::IApp {

void open_image_exporter();
void open_video_exporter();
void open_meshing_window_for_node(Cool::NodeId const& node_id);

auto nodes_library() const -> Cool::NodesLibrary const& { return _nodes_library_manager.library(); }

Expand All @@ -69,14 +89,16 @@ class App : public Cool::IApp {
void check_inputs__timeline();

// clang-format off
auto make_reversible_commands_context () { return MakeReversibleCommandContext_Ref{{ _project.camera_3D_manager, *_project.modules_graph}}; }
auto make_reversible_commands_context () const { return MakeReversibleCommandContext_Ref{{ _project.camera_3D_manager, *_project.modules_graph}}; }
auto command_execution_context () -> CommandExecutionContext_Ref { return CommandExecutionContext_Ref{{*this, _main_window, _project, _current_project_path, command_executor_top_level(), _recently_opened_projects }}; }
auto reversible_command_executor_without_history() { return ReversibleCommandExecutor_WithoutHistory_Ref{command_execution_context()}; }
auto command_executor_without_history () { return CommandExecutor_WithoutHistory_Ref{}; }
auto command_executor_without_history () const { return CommandExecutor_WithoutHistory_Ref{}; }
auto command_executor_top_level () -> CommandExecutor_TopLevel { return CommandExecutor_TopLevel{command_executor_without_history(), _project.history, make_reversible_commands_context()}; }
auto command_executor () { return CommandExecutor{command_execution_context()}; }
auto system_values (img::Size render_target_size, Cool::Time time, Cool::Time delta_time) { return SystemValues{render_target_size, time, delta_time, _project.camera_2D_manager.camera(), _project.camera_3D_manager.camera(), _project.audio}; }
auto system_values (img::Size render_target_size, Cool::Time time, Cool::Time delta_time) const { return SystemValues{render_target_size, time, delta_time, _project.camera_2D_manager.camera(), _project.camera_3D_manager.camera(), _project.audio}; }
auto ui () { return Ui_Ref{command_executor()}; }
auto data_to_pass_to_shader (img::Size render_target_size, Cool::Time time, Cool::Time delta_time) const { return DataToPassToShader{system_values(render_target_size, time, delta_time), _project.modules_graph->graph(), _project.modules_graph->compositing_module().feedback_double_buffer() }; }
auto data_to_generate_shader_code () const { return DataToGenerateShaderCode{_project.modules_graph->graph(), Cool::GetNodeDefinition_Ref<NodeDefinition>{_nodes_library_manager.library()} }; }
// clang-format on

Cool::Polaroid polaroid();
Expand All @@ -95,6 +117,7 @@ class App : public Cool::IApp {
void imgui_window_cameras();
void imgui_window_view();
void imgui_window_exporter();
void imgui_window_meshing();

void compile_all_is0_nodes();

Expand All @@ -113,6 +136,8 @@ class App : public Cool::IApp {
NodesLibraryManager _nodes_library_manager{};
bool _is_first_frame{true};
bool _is_shutting_down{false};
Cool::MeshExportSettings _mesh_export_settings{};
MeshingGui _meshing_gui{};

private:
// Serialization
Expand All @@ -128,7 +153,9 @@ class App : public Cool::IApp {
ser20::make_nvp("Webcams config", Cool::WebcamsConfigs::instance()),
ser20::make_nvp("MIDI config", Cool::midi_manager()),
ser20::make_nvp("OSC config", Cool::osc_manager()),
ser20::make_nvp("Server config", Cool::server_manager())
ser20::make_nvp("Server config", Cool::server_manager()),
ser20::make_nvp("3D Model export settings", app._mesh_export_settings),
ser20::make_nvp("3D Model generation", app._meshing_gui)
);
}
template<class Archive>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "CommandExecutionContext_Ref.h"
#include "ConcreteReversibleCommand.h"
#include "Cool/Log/ToUser.h"

namespace Lab {

Expand Down
19 changes: 19 additions & 0 deletions src/Commands/Command_Meshing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "Command_Meshing.h"
#include "App.h"

namespace Lab {

auto Command_Meshing::to_string() const -> std::string
{
return fmt::format("Convert SDF to Mesh, from node {}", reg::to_string(node_id));
}

void Command_Meshing::execute(CommandExecutionContext_Ref const& ctx) const
{
ctx.app().open_meshing_window_for_node(node_id);
}

} // namespace Lab

#include "CommandCore/LAB_REGISTER_COMMAND.h"
LAB_REGISTER_COMMAND(Lab::Command_Meshing)
26 changes: 26 additions & 0 deletions src/Commands/Command_Meshing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include <Cool/Nodes/NodeId.h>
#include "CommandCore/CommandExecutionContext_Ref.h"

namespace Lab {

struct Command_Meshing {
Cool::NodeId node_id;

void execute(CommandExecutionContext_Ref const& ctx) const;

auto to_string() const -> std::string;

private:
// Serialization
friend class ser20::access;
template<class Archive>
void serialize(Archive& archive)
{
archive(
ser20::make_nvp("Node id", node_id)
);
}
};

} // namespace Lab
2 changes: 1 addition & 1 deletion src/Gallery/GalleryPoster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void GalleryPoster::imgui_open_sharing_form(std::optional<Cool::AspectRatio> con

void GalleryPoster::imgui_window(std::function<std::string(img::Size)> const& render_png)
{
_window.show([&]() {
_window.show([&](bool /*is_opening*/) {
Cool::ImGuiExtras::markdown("Your image will be visible on [Coollab's gallery](https://coollab-art.com/Gallery).");
Cool::ImGuiExtras::markdown("If you want to edit or remove it, send an email at [[email protected]](mailto:[email protected]) from the email address that you will provide below.");
Cool::ImGuiExtras::separator_text("Artwork");
Expand Down
54 changes: 54 additions & 0 deletions src/Meshing/MeshingGui.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "MeshingGui.hpp"
#include <Cool/ImGui/ImGuiExtras.h>
#include <Cool/Path/Path.h>
#include "Cool/ImGui/IcoMoonCodepoints.h"
#include "Cool/ImGui/icon_fmt.h"
#include "Cool/Mesh/export_mesh.hpp"
#include "Nodes/Node.h"
#include "gen_mesh_from_sdf.hpp"

namespace Lab {

MeshingGui::MeshingGui()
: _window{Cool::icon_fmt("Export a 3D Model", ICOMOON_COGS), Cool::ImGuiWindowConfig{.is_modal = true}}
{
}

void MeshingGui::open_window(Cool::NodeId const& main_node_id)
{
_main_node_id = main_node_id;
_window.open();
}

static void gen_and_export_mesh(Cool::NodeId const& main_node_id, MeshingSettings const& meshing_settings, Cool::MeshExportSettings const& mesh_export_settings, DataToPassToShader const& data_to_pass_to_shader, DataToGenerateShaderCode const& data_to_generate_shader_code)
{
// auto const maybe_node = data_to_generate_shader_code.nodes_graph.try_get_node<Node>(main_node_id);
// auto const node_def = data_to_generate_shader_code.get_node_definition(maybe_node->id_names());
// is_shape_3D(node_def->signature());

auto const maybe_mesh = gen_mesh_from_sdf(main_node_id, meshing_settings, data_to_pass_to_shader, data_to_generate_shader_code);
if (!maybe_mesh)
return; // TODO(Meshing) Error message should be handled here
export_mesh(*maybe_mesh, mesh_export_settings);
}

void MeshingGui::imgui_window(Cool::MeshExportSettings& mesh_export_settings, DataToPassToShader const& data_to_pass_to_shader, DataToGenerateShaderCode const& data_to_generate_shader_code)
{
_window.show([&](bool is_opening) {
if (is_opening)
mesh_export_settings.set_file_name_to_an_unused_name();

_meshing_settings.imgui();
ImGui::Separator();
mesh_export_settings.imgui();

Cool::ImGuiExtras::before_export_button(mesh_export_settings.path);
if (ImGui::Button(Cool::icon_fmt("Export 3D Model", ICOMOON_UPLOAD2).c_str()))
{
gen_and_export_mesh(_main_node_id, _meshing_settings, mesh_export_settings, data_to_pass_to_shader, data_to_generate_shader_code);
_window.close();
}
});
}

} // namespace Lab
34 changes: 34 additions & 0 deletions src/Meshing/MeshingGui.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once
#include "Cool/ImGui/ImGuiWindow.h"
#include "Cool/Mesh/MeshExportSettings.hpp"
#include "MeshingSettings.hpp"
#include "Module/ShaderBased/DataToGenerateShaderCode.hpp"
#include "Module/ShaderBased/DataToPassToShader.hpp"

namespace Lab {

class MeshingGui {
public:
MeshingGui();

void open_window(Cool::NodeId const& main_node_id);
void imgui_window(Cool::MeshExportSettings&, DataToPassToShader const&, DataToGenerateShaderCode const&);

private:
Cool::ImGuiWindow _window;
MeshingSettings _meshing_settings{};
Cool::NodeId _main_node_id{};

private:
// Serialization
friend class ser20::access;
template<class Archive>
void serialize(Archive& archive)
{
archive(
ser20::make_nvp("Settings", _meshing_settings)
);
}
};

} // namespace Lab
17 changes: 17 additions & 0 deletions src/Meshing/MeshingSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "MeshingSettings.hpp"
#include "Cool/ImGui/ImGuiExtras.h"

namespace Lab {

void MeshingSettings::imgui()
{
// TODO(Meshing) GUI for the other settings
if (ImGui::InputScalarN("Samples Count", ImGuiDataType_U32, glm::value_ptr(samples_count), 3, nullptr, nullptr, "%u"))
{
// Ensure that the sampling count is at least 1
samples_count = glm::max(samples_count, glm::uvec3(1));
}
Cool::ImGuiExtras::help_marker("The number of samples to take along each axis of the volume.\nIncreasing it will increase the precision of the mesh, but will take longer to export and add more vertices.");
}

} // namespace Lab
26 changes: 26 additions & 0 deletions src/Meshing/MeshingSettings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

namespace Lab {

struct MeshingSettings {
glm::vec3 box_size{2.f}; // TODO(Meshing) Clarify : is this the radius or diameter of the box?
glm::uvec3 samples_count{75}; /// Must always be >= 1 on each axis
// TODO(Meshing) expose step_size in the GUI, and deduce samples_count from it
auto step_size() const -> glm::vec3 { return box_size / static_cast<glm::vec3>(samples_count - glm::uvec3{1}); }

void imgui();

private:
// Serialization
friend class ser20::access;
template<class Archive>
void serialize(Archive& archive)
{
archive(
ser20::make_nvp("Box size", box_size),
ser20::make_nvp("Samples count", samples_count)
);
}
};

} // namespace Lab
Loading

0 comments on commit 94e374d

Please sign in to comment.