generate png

This commit is contained in:
Jason Ly 2026-01-18 10:45:48 -05:00
parent 7b33c5e990
commit 40c2227690
3 changed files with 144 additions and 17 deletions

View File

@ -28,6 +28,7 @@ optional
1. Add pull down menu for resolution override option, have default, 100x100, 256x256,512x512 1. Add pull down menu for resolution override option, have default, 100x100, 256x256,512x512
2. Add outputname override 2. Add outputname override
3. Add pulldown to select camera, only available after scene is queried 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 # Build
``` ```

View File

@ -5,8 +5,15 @@
#include <iostream> #include <iostream>
#include <filesystem> #include <filesystem>
#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 <thread> // For std::this_thread (C++ standard library)
#include <chrono> // For timing operations (C++ standard library)
std::string directory_path = "."; std::string directory_path = ".";
int selected_index = -1; // Global variable to hold the selected index int selected_index = -1; // Global variable to hold the selected index
dl::String currentRender;
void CleanTrailingSlash(std::string& path) { void CleanTrailingSlash(std::string& path) {
// Only strip if it's longer than a root path (e.g., "/" or "C:\") // 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(); 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<std::string*> 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. // Note: You must pass the ScreenInteractive object to trigger a redraw.
void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::path& new_path, std::vector<std::string>& entries, std::vector<std::string>& clean_names) { void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::path& new_path, std::vector<std::string>& entries, std::vector<std::string>& clean_names) {
if (!std::filesystem::exists(new_path) || !std::filesystem::is_directory(new_path)) return; 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[]) { int main(int argc, char* argv[]) {
// Define a variable to hold the final selection index // Define a variable to hold the final selection index
@ -113,13 +227,10 @@ int main(int argc, char* argv[]) {
return 1; return 1;
} }
auto screen = ftxui::ScreenInteractive::TerminalOutput(); ftxui::ScreenInteractive screen = ftxui::ScreenInteractive::TerminalOutput();
ReloadDirectory(screen, start_path, entries, clean_names); ReloadDirectory(screen, start_path, entries, clean_names);
int selected = 0; int selected = 0;
auto menu = ftxui::Menu({ auto menu = ftxui::Menu(&entries,&selected);
.entries = &entries,
.selected = &selected,
});
std::string input_buffer = ""; // Stores digits as the user types them std::string input_buffer = ""; // Stores digits as the user types them
@ -169,16 +280,20 @@ int main(int argc, char* argv[]) {
new_path = std::filesystem::absolute(new_path).lexically_normal(); new_path = std::filesystem::absolute(new_path).lexically_normal();
new_path.make_preferred(); new_path.make_preferred();
CleanTrailingSlash(current_path); CleanTrailingSlash(current_path);
// std::string normalized = std::filesystem::path(current_path).generic_string();
directory_path = current_path; // Update global variable directory_path = current_path; // Update global variable
if (std::filesystem::is_regular_file(new_path)) if (std::filesystem::is_regular_file(new_path))
{ {
selected_index = selected; // Update global selected index selected_index = selected; // Update global selected index
final_selected_index = selected; // Store the final selection 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 else
{ {
@ -203,7 +318,7 @@ int main(int argc, char* argv[]) {
}); });
// Create a renderer that defines the layout of your application // 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({ return ftxui::vbox({
// Header showing the current directory // Header showing the current directory

View File

@ -55,9 +55,9 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)\..\FTXUI\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)\..\FTXUI\include;..\bella_engine_sdk\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -73,16 +73,27 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard> <TreatWarningAsError>false</TreatWarningAsError>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)\..\FTXUI\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)\..\FTXUI\include;..\bella_engine_sdk\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\..\FTXUI\build\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(SolutionDir)..\FTXUI\build\Release;$(SolutionDir)..\bella_engine_sdk\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>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)</AdditionalDependencies> <AdditionalDependencies>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)</AdditionalDependencies>
</Link> </Link>
<PostBuildEvent>
<Command>
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.
</Command>
</PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="joomer-ftxui-bsz-browser.cpp" /> <ClCompile Include="joomer-ftxui-bsz-browser.cpp" />