From 8ac25f7fb3e2bdd08124aa59488ee85189fbfc19 Mon Sep 17 00:00:00 2001 From: Harvey Fong Date: Sat, 5 Apr 2025 01:51:29 -0600 Subject: [PATCH] third party licenses are in exe, added bella slider previews, branched to vmaxtui which will generalize fileQueue in a header file will switch to std::string since we want header files not be be dl depenedent --- LICENSE | 62 ------- bellatui.cpp | 444 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 416 insertions(+), 90 deletions(-) diff --git a/LICENSE b/LICENSE index 126a67d..eaa5acd 100644 --- a/LICENSE +++ b/LICENSE @@ -19,65 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -==== - -Bella SDK (Software Development Kit) - -Copyright Diffuse Logic SCP, all rights reserved. - -Permission is hereby granted to any person obtaining a copy of this software -(the "Software"), to use, copy, publish, distribute, sublicense, and/or sell -copies of the Software. - -THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ALL -IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF MERCHANTABILITY -ARE HEREBY DISCLAIMED. - -==== - -CppZMQ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal in the Software without restriction, including without limitation the -rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -IN THE SOFTWARE. - -==== - -libsodium - - -ISC License - -Copyright (c) 2013-2025 -Frank Denis - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - - ===== - - libzmq is free software; you can redistribute it and/or modify it under the terms of the Mozilla Public License Version 2.0. \ No newline at end of file diff --git a/bellatui.cpp b/bellatui.cpp index 057b0a9..84f982c 100644 --- a/bellatui.cpp +++ b/bellatui.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include // For sprintf #include #include // For string streams @@ -52,6 +54,10 @@ using namespace dl; using namespace dl::bella_sdk; +//Forward declarations +std::string bellaSliderPreviewsHTML(); +//dl::Mat4 oomer_orbit(dl::Mat4 beginCamXform, int currentFrame, int totalFrames); + /// A class that manages a queue of files to render with both FIFO order and fast lookups class RenderQueue { public: @@ -151,10 +157,10 @@ private: }; std::atomic active_render(false); -RenderQueue renderQueue; // Replace the old vector and map with our new class -std::mutex renderQueueMutex; // Add mutex for thread safety -std::vector renderDelete; // This is the efsw queue for when we delete a file -std::mutex renderDeleteMutex; // Add mutex for thread safety +//RenderQueue renderQueue; // Replace the old vector and map with our new class +//std::mutex renderQueueMutex; // Add mutex for thread safety +//std::vector renderDelete; // This is the efsw queue for when we delete a file +//std::mutex renderDeleteMutex; // Add mutex for thread safety dl::String currentRender; std::mutex currentRenderMutex; // Add mutex for thread safety @@ -165,8 +171,7 @@ RenderQueue incomingRenderQueue; std::mutex incomingDeleteQueueMutex; // Add mutex for thread safety std::mutex incomingRenderQueueMutex; // Add mutex for thread safety - -/// Processes a file action +/// Processes a file action libefsw class UpdateListener : public efsw::FileWatchListener { public: UpdateListener() : should_stop_(false) {} @@ -217,8 +222,16 @@ class UpdateListener : public efsw::FileWatchListener { } if (actionName == "Add" || actionName == "Modified") { dl::String belPath = (dir + filename).c_str(); + dl::String parentPath = dir.c_str(); + //std::cout << "parentPath: " << parentPath.buf() << std::endl; if (should_stop_) return; // Check again before starting render - if (belPath.endsWith(".bsz")) { + + if (parentPath.endsWith("download")) { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + return; + } + + if (belPath.endsWith(".bsz") || belPath.endsWith(".zip") && !parentPath.endsWith("download/")) { { std::lock_guard lock(incomingRenderQueueMutex); if (!incomingRenderQueue.contains(belPath)) { @@ -339,17 +352,17 @@ public: //} // Called to update rendering progress (percentage, time remaining, etc) - void onProgress(String pass, Progress progress) override - { - std::cout << progress.toString().buf() << std::endl; - setString(new std::string(progress.toString().buf())); - logInfo("%s [%s]", progress.toString().buf(), pass.buf()); - } + //void onProgress(String pass, Progress progress) override + //{ + // std::cout << progress.toString().buf() << std::endl; + // setString(new std::string(progress.toString().buf())); + // 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()); - } + //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(String pass, String msg) override @@ -555,6 +568,7 @@ void file_watcher_thread(const std::string& watch_path = "") { * --licenseinfo : Show license information */ #include "dl_core/dl_main.inl" + #include "dl_core/dl_args.h" int DL_main(Args& args) { // Default configuration values @@ -1181,6 +1195,7 @@ void server_thread( std::string server_skey, ctx.close(); } + void render_thread( Engine& engine, MyEngineObserver& engineObserver) { // Create persistent instances outside the loop @@ -1188,10 +1203,9 @@ void render_thread( Engine& engine, RenderQueue renderThreadDeleteQueue; while (true) { - // Append items from incoming queues to our persistent queues + // Append items from incoming queues to our persistent queues for thread safety { std::lock_guard lock(incomingRenderQueueMutex); - // Process each item in the incoming queue and add it to our persistent queue dl::String path; while (incomingRenderQueue.pop(path)) { renderThreadQueue.push(path); @@ -1201,7 +1215,6 @@ void render_thread( Engine& engine, { std::lock_guard lock(incomingDeleteQueueMutex); - // Process each item in the incoming queue and add it to our persistent queue dl::String path; while (incomingDeleteQueue.pop(path)) { renderThreadDeleteQueue.push(path); @@ -1227,12 +1240,106 @@ void render_thread( Engine& engine, // We successfully got the render slot - no one else is rendering if (renderThreadQueue.pop(belPath)) { std::cout << "\n==" << "RENDERING: " << belPath.buf() << "\n==" << std::endl; - engine.loadScene(belPath); - //engine.scene().camera()["resolution"]= Vec2 {100, 100}; - engine.start(); - { - std::lock_guard lock(currentRenderMutex); - currentRender = belPath; + if (belPath.endsWith(".bsz")) { + engine.loadScene(belPath); + //engine.scene().camera()["resolution"]= Vec2 {100, 100}; + engine.start(); + { + std::lock_guard lock(currentRenderMutex); + currentRender = belPath; + } + } else if (belPath.endsWith(".zip")) { + dl::Path fooPath = dl::Path(belPath); + dl::String justDir = fooPath.dir(); + dl::String justName = fooPath.file(false); + //auto previewPath = args.iPath().canonical();; + dl::String previewPath = bella_sdk::previewPath(); + engine.loadScene(previewPath); + auto oomerOutputPath = engine.scene().createNode("outputImagePath", "oomerOutputPath"); + oomerOutputPath["ext"] = ".jpg"; + auto oomerPBR = engine.scene().createNode("pbr", "oomerPBR"); + oomerPBR["file"] = justName; + oomerPBR["ext"] = ".zip"; + oomerPBR["dir"] = justDir; + auto oomerPreview = engine.scene().findNode("__preview__"); + auto oomerCamXform = engine.scene().findNode("__camera__"); + oomerPreview["material"] = oomerPBR; + std::filesystem::path dirPath = std::string(justDir.buf())+"/"+std::string(justName.buf()); + bool success = std::filesystem::create_directory(dirPath); + oomerOutputPath["dir"] = dirPath.string().c_str(); + //engine.scene().beautyPass()["outputExt"] = ".jpg"; + engine.scene().beautyPass()["targetNoise"] = dl::Int(10); + engine.scene().beautyPass()["saveImage"] = dl::Int(0); + engine.scene().beautyPass()["overridePath"] = oomerOutputPath; + engine.scene().camera()["resolution"]= Vec2 {320, 320}; + + std::ofstream outFile(dirPath.string()+"/bella.js"); + outFile << std::string("bellaScene=\"") << justName.buf() << std::string("\";") << std::endl; + outFile << std::string("bellaNodeType=\"") << "foo1" << std::string("\";") << std::endl; + outFile << std::string("bellaNode=\"") << "foo2" << std::string("\";") << std::endl; + outFile << std::string("bellaNodeAttribute=\"") << "hhh" << std::string("\";") << std::endl; + outFile << std::string("bellaSteps=[];") << std::endl; + outFile << std::string("bellaSteps[1]=\"") << -1.00000f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[2]=\"") << -0.93104f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[3]=\"") << -0.86208f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[4]=\"") << -0.79312f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[5]=\"") << -0.72414f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[6]=\"") << -0.65518f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[7]=\"") << -0.58622f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[8]=\"") << -0.51726f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[9]=\"") << -0.44828f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[10]=\"") << -0.37932f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[11]=\"") << -0.31036f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[12]=\"") << -0.24138f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[13]=\"") << -0.17242f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[14]=\"") << -0.10346f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[15]=\"") << -0.03450f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[16]=\"") << 0.03448f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[17]=\"") << 0.10344f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[18]=\"") << 0.17240f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[19]=\"") << 0.24136f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[20]=\"") << 0.31034f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[21]=\"") << 0.37930f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[22]=\"") << 0.44826f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[23]=\"") << 0.51724f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[24]=\"") << 0.58620f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[25]=\"") << 0.65516f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[26]=\"") << 0.72412f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[27]=\"") << 0.79310f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[28]=\"") << 0.86206f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[29]=\"") << 0.93102f << std::string("\";") << std::endl; + outFile << std::string("bellaSteps[30]=\"") << 1.00000f << std::string("\";") << std::endl; + outFile << std::string("bellaQueue=[];") << std::endl; + outFile.close(); + std::ofstream outFile2(dirPath.string()+"/index.html"); + outFile2 << bellaSliderPreviewsHTML(); + outFile2.close(); + + dl::Mat4 beginCamXform = oomerCamXform["steps"][0]["xform"].asMat4(); + for (int i = 1; i <= 30; i++) { + auto offset = dl::Vec2 {i*0.1, 0.0}; + dl::bella_sdk::orbitCamera(engine.scene().cameraPath(),offset); + + char buffer[50]; + sprintf(buffer, "%04d", i); + + // Set the output filename with frame number + //oomerOutputPath["file"] = fooPath.file(false) + dl::String("_") + dl::String(buffer); + oomerOutputPath["file"] = dl::String("bella") + dl::String(buffer); + + // Start rendering + engine.start(); + while (engine.rendering()) { //blocking + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + engine.stop(); + } + { + std::lock_guard lock(currentRenderMutex); + currentRender = belPath; + } + } else { + active_render = false; // Release the render slot } } else { active_render = false; // Release the render slot @@ -1389,7 +1496,7 @@ ARE HEREBY DISCLAIMED. ==== -CppZMQ +cppZMQ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to @@ -1462,4 +1569,285 @@ THE SOFTWARE. This software is a fork of the "simplefilewatcher" by James Wynn (james@jameswynn.com) http://code.google.com/p/simplefilewatcher/ also MIT licensed. -)"; } \ No newline at end of file +)"; } + + +std::string bellaSliderPreviewsHTML() { +return R"HTML( + + + + + + + + +
+
+   >   +   >   +   >   + +
+ +
+
+ + + + + + + + + +
+

+      
+
+ + +)HTML"; } \ No newline at end of file