diff --git a/README.md b/README.md index 5f6b2bc..1ae5b7b 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ optional 1. Add pull down menu for resolution override option, have default, 100x100, 256x256,512x512 2. Add outputname override 3. Add pulldown to select camera, only available after scene is queried +4. currently using c++ 20 using bella sdk 25.3.0 so silencing the warnings, update to c++23 and latest bella sdk or match c++ to correct version of bella sdk # Build ``` diff --git a/joomer-ftxui-bsz-browser.cpp b/joomer-ftxui-bsz-browser.cpp index 66f18f5..a8291a4 100644 --- a/joomer-ftxui-bsz-browser.cpp +++ b/joomer-ftxui-bsz-browser.cpp @@ -5,8 +5,15 @@ #include #include +#include "bella_sdk/bella_engine.h" // Core rendering engine +#include "bella_sdk/bella_scene.h" // Scene management +#include "dl_core/dl_logging.h" // Logging utilities +#include // For std::this_thread (C++ standard library) +#include // For timing operations (C++ standard library) + std::string directory_path = "."; int selected_index = -1; // Global variable to hold the selected index +dl::String currentRender; void CleanTrailingSlash(std::string& path) { // Only strip if it's longer than a root path (e.g., "/" or "C:\") @@ -31,6 +38,83 @@ std::string FormatSize(uintmax_t size) { return ss.str(); } +/* + * MyEngineObserver Class + * This class receives callbacks from the Bella rendering engine to track rendering progress. + * It implements the EngineObserver interface and provides methods to: + * - Handle render start/stop events + * - Track rendering progress + * - Handle error conditions + * - Store and retrieve the current progress state + */ +struct MyEngineObserver : public dl::bella_sdk::EngineObserver +{ +public: + // Called when a rendering pass starts + void onStarted(dl::String pass) override + { + std::cout << "Started pass " << pass.buf() << std::endl; + dl::logInfo("Started pass %s", pass.buf()); + } + + // Called to update the current status of rendering + //void onStatus(String pass, String status) override + //{ + // logInfo("%s [%s]", status.buf(), pass.buf()); + //} + + // Called to update rendering progress (percentage, time remaining, etc) + void onProgress(dl::String pass, dl::bella_sdk::Progress progress) override + { + std::cout << progress.toString().buf() << std::endl; + setString(new std::string(progress.toString().buf())); + dl::logInfo("%s [%s]", progress.toString().buf(), pass.buf()); + } + + //void onImage(String pass, Image image) override + //{ + // logInfo("We got an image %d x %d.", (int)image.width(), (int)image.height()); + //} + + // Called when an error occurs during rendering + void onError(dl::String pass, dl::String msg) override + { + dl::logError("%s [%s]", msg.buf(), pass.buf()); + } + + // Called when a rendering pass completes + void onStopped(dl::String pass) override + { + dl::logInfo("Stopped %s", pass.buf()); + std::atomic_bool active_render = false; + } + + // Returns the current progress as a string + std::string getProgress() const { + std::string* currentProgress = progressPtr.load(); + if (currentProgress) { + return *currentProgress; + } + else { + return ""; + } + } + + // Cleanup resources in destructor + ~MyEngineObserver() { + setString(nullptr); + } +private: + // Thread-safe pointer to current progress string + std::atomic progressPtr{ nullptr }; + + // Helper function to safely update the progress string + void setString(std::string* newStatus) { + std::string* oldStatus = progressPtr.exchange(newStatus); + delete oldStatus; // Clean up old string if it exists + } +}; + // Note: You must pass the ScreenInteractive object to trigger a redraw. void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::path& new_path, std::vector& entries, std::vector& clean_names) { if (!std::filesystem::exists(new_path) || !std::filesystem::is_directory(new_path)) return; @@ -78,6 +162,36 @@ void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::pa } } } +// Replace this line in renderImage(): +// engine.render(); + + +void renderSynchronous(dl::bella_sdk::Engine& engine, MyEngineObserver& engineObserver, std::string selected_name) { + dl::String belPath = dl::String(directory_path.c_str()) + "\\"; + engine.loadScene(belPath + dl::String(selected_name.c_str())); + + if (!engine.scene().read(dl::String(selected_name.c_str()))) return; + + dl::bella_sdk::Node bPass = engine.scene().beautyPass(); + + // Create the mandatory output node type + dl::bella_sdk::Node pathNode = engine.scene().createNode("outputImagePath"); + pathNode["dir"] = dl::String(directory_path.c_str()); + pathNode["name"] = "render_result"; + pathNode["ext"] = ".png"; + + // Link the node to the beauty pass + bPass["overridePath"] = pathNode; + bPass["timeLimit"] = 30.0f; + + // This call will now "freeze" the UI until finished + engine.start(); + + // Explicitly wait until the engine is done to ensure the file is written + while (engine.rendering()) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } +} int main(int argc, char* argv[]) { // Define a variable to hold the final selection index @@ -113,13 +227,10 @@ int main(int argc, char* argv[]) { return 1; } - auto screen = ftxui::ScreenInteractive::TerminalOutput(); + ftxui::ScreenInteractive screen = ftxui::ScreenInteractive::TerminalOutput(); ReloadDirectory(screen, start_path, entries, clean_names); int selected = 0; - auto menu = ftxui::Menu({ - .entries = &entries, - .selected = &selected, - }); + auto menu = ftxui::Menu(&entries,&selected); std::string input_buffer = ""; // Stores digits as the user types them @@ -168,17 +279,21 @@ int main(int argc, char* argv[]) { new_path = std::filesystem::absolute(new_path).lexically_normal(); - new_path.make_preferred(); - - - + new_path.make_preferred(); CleanTrailingSlash(current_path); + // std::string normalized = std::filesystem::path(current_path).generic_string(); directory_path = current_path; // Update global variable if (std::filesystem::is_regular_file(new_path)) { selected_index = selected; // Update global selected index final_selected_index = selected; // Store the final selection index - // screen.Exit(); // Exit the application + if (selected_name.substr(selected_name.length() - 3) == "bsz") { + dl::bella_sdk::Engine engine; // The renderer itself + + MyEngineObserver engineObserver; + engine.subscribe(&engineObserver); + renderSynchronous(engine, engineObserver, selected_name); + } } else { @@ -203,7 +318,7 @@ int main(int argc, char* argv[]) { }); // Create a renderer that defines the layout of your application - auto main_renderer = ftxui::Renderer(menu_with_event_handler, [&] { + ftxui::Component main_renderer = ftxui::Renderer(menu_with_event_handler, [&] { return ftxui::vbox({ // Header showing the current directory diff --git a/joomer-ftxui-bsz-browser.vcxproj b/joomer-ftxui-bsz-browser.vcxproj index 6d67fb3..6271c85 100644 --- a/joomer-ftxui-bsz-browser.vcxproj +++ b/joomer-ftxui-bsz-browser.vcxproj @@ -55,9 +55,9 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - stdcpp20 + stdcpp17 MultiThreadedDebugDLL - $(SolutionDir)\..\FTXUI\include;%(AdditionalIncludeDirectories) + $(SolutionDir)\..\FTXUI\include;..\bella_engine_sdk\src;%(AdditionalIncludeDirectories) Console @@ -73,16 +73,27 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - stdcpp20 + false + stdcpp17 MultiThreadedDLL - $(SolutionDir)\..\FTXUI\include;%(AdditionalIncludeDirectories) + $(SolutionDir)\..\FTXUI\include;..\bella_engine_sdk\src;%(AdditionalIncludeDirectories) Console false - $(SolutionDir)\..\FTXUI\build\Release;%(AdditionalLibraryDirectories) - ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;msvcprt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)..\FTXUI\build\Release;$(SolutionDir)..\bella_engine_sdk\lib;%(AdditionalLibraryDirectories) + bella_engine_sdk.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;msvcprt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + echo Copying Bella SDK DLLs... + copy "$(ProjectDir)..\bella_engine_sdk\lib\bella_engine_sdk.dll" "$(TargetDir)" + copy "$(ProjectDir)..\bella_engine_sdk\lib\dl_core.dll" "$(TargetDir)" + copy "$(ProjectDir)..\bella_engine_sdk\lib\dl_oidn_core.dll" "$(TargetDir)" + copy "$(ProjectDir)..\bella_engine_sdk\lib\dl_usd_ms.dll" "$(TargetDir)" + echo DLL copy finished. + +