Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I found a(n easier) way to include addons. #91

Open
Jonathhhan opened this issue Apr 14, 2024 · 9 comments
Open

I found a(n easier) way to include addons. #91

Jonathhhan opened this issue Apr 14, 2024 · 9 comments

Comments

@Jonathhhan
Copy link
Collaborator

Jonathhhan commented Apr 14, 2024

At least with ofxVolumetrics it works quite well. The shaders from the addon need to be put into the C:\Program Files\Pd\bin\data\ofxVolumetrics\shaders\gl... folder, it would be much nicer and more convinient if they can be placed in the externals directory. Any idea how to do that?

Edit: Tried ofSetDataPathRoot(), but not able to locate the relative path of the PD externals folder, only the folder of the patch.

@Jonathhhan Jonathhhan changed the title I found a way to include addons. I found a(n easier) way to include addons. Apr 14, 2024
@Jonathhhan
Copy link
Collaborator Author

Trying to add ofxImGui soon.
Maybe this helps:
https://github.com/ousttrue/SwigImGui
https://github.com/RayquazaGX/swigimgui

@Jonathhhan
Copy link
Collaborator Author

Jonathhhan commented Apr 19, 2024

Here a branch that adds ofxVolumetrics, ofxStableDiffusion and ofxImGui: https://github.com/Jonathhhan/ofxOfelia/tree/ofxAddons/scripts/common
I use the master branch of ofxImGui: https://github.com/jvcleave/ofxImGui,
because I had some issues with the develop branch: https://github.com/jvcleave/ofxImGui/tree/develop.
Maybe thats solvable with editing the swig file? I'll give it another try. The ofxImGui develop branch has some issues with Emscripten, too (probably also solvable).
Other than that are only some small issues left.

Here are some patches for testing the external: https://github.com/Jonathhhan/ofelia-ofxVolumetrics-example

@Jonathhhan
Copy link
Collaborator Author

Jonathhhan commented Apr 20, 2024

Added the ofxImGui develop-branch. Made some changes for VS (only setting the paths): https://github.com/Jonathhhan/ofxImGui/tree/develop-swig
The flag -DGLM_ENABLE_EXPERIMENTAL is needed for both branches - main and develop.

Here a screenshot:

ofxOfelia_ofxStableDiffusion

And thats the code of the example patch:

if type(window) ~= "userdata" then;
window = ofWindow();
end;
;
local a = ofelia;
local clock = ofClock(this, "setup");
local stableDiffusion;
local texture = ofTexture();
local gui = ofxImGuiGui();
local boolArrayValue = ImGuiNew_BoolArray(1);
local intArrayValue = ImGuiNew_IntArray(1);
local prompt = "a skater in the woods, van gogh";
local generate = false;
;
function a.new();
ofWindow.addListener("setup", this);
ofWindow.addListener("update", this);
ofWindow.addListener("draw", this);
ofWindow.addListener("exit", this);
window:setPosition(200, 100);
window:setSize(612, 850);
if ofWindow.exists then;
clock:delay(0);
else;
window:create();
end;
end;
;
function a.free();
window:destroy();
ofWindow.removeListener("setup", this);
ofWindow.removeListener("update", this);
ofWindow.removeListener("draw", this);
ofWindow.removeListener("exit", this);
end;
;
function a.setup();
ofSetWindowTitle("ofxStableDiffusion");
ofBackground(150, 230, 255, 255);
gui:setup();
texture:allocate(512, 512, GL_RGB);
ImGuiBoolArray_setitem(boolArrayValue, 0, true);
ImGuiIntArray_setitem(intArrayValue, 0, 5);
print(ofxSd_get_system_info());
stableDiffusion = ofxNew_sd_ctx("sd_turbo.safetensors", "", "", "", "", "", "", true, false, false, 8, 1, 0, 0, false, false, false);
end;
;
function a.update();
if generate == true then;
local result = ofxTxt2img(stableDiffusion, prompt, "", 0, 1, 512, 512, 0, 5, -1, 1, sd_image_t, 1, 1, false, "");
print("Width:", result.width, "Height:", result.height, "Channel:", result.channel);
texture:loadData(result.data, 512, 512, GL_RGB);
end;
end;
;
function a.draw();
texture:draw(50, 50);
gui:begin();
ImGuiStyleColorsDark();
ImGuiPushStyleVar(ImGuiImGuiStyleVar_WindowMinSize, ImGuiImVec2(512, 120));
ImGuiPushStyleVar(ImGuiImGuiStyleVar_WindowPadding, ImGuiImVec2(10, 10));
ImGuiPushStyleVar(ImGuiImGuiStyleVar_IndentSpacing, 10);
ImGuiPushStyleVar(ImGuiImGuiStyleVar_ItemSpacing, ImGuiImVec2(0, 0));
ImGuiPushStyleVar(ImGuiImGuiStyleVar_ItemInnerSpacing, ImGuiImVec2(5, 0));
--ImGuiSetNextWindowSizeConstraints seems to have no effect;
--ImGuiSetNextWindowSizeConstraints(ImGuiImVec2(200, -1), ImGuiImVec2(200, -1));
ImGuiSetNextWindowPos(ImGuiImVec2(50, 600), ImGuiImGuiCond_Once);
ImGuiBegin_3("ofxStableDiffusion", boolArrayValue, ImGuiImGuiWindowFlags_NoResize);
ImGuiPushItemWidth(420);
ImGuiText("The checkbox below is checked.");
ImGuiDummy(ImGuiImVec2(0, 10));
ImGuiSliderInt("Test", intArrayValue, 1, 16);
ImGuiDummy(ImGuiImVec2(0, 10));
ImGuiCheckbox("Checkbox", boolArrayValue);
ImGuiDummy(ImGuiImVec2(0, 10));
ImGuiRadioButton("Checked", true);
ImGuiDummy(ImGuiImVec2(0, 10));
generate = ImGuiButton("Generate");
ImGuiDummy(ImGuiImVec2(0, 10));
ImGuiInputText( "Prompt", prompt, 60);
ImGuiDummy(ImGuiImVec2(0, 10));
ImGuiEnd();
gui:c_end();
end;
;
function a.exit();
ofxFree_sd_ctx(stableDiffusion);
end;

The main issue is, that some of the objects have a double ImGuiImGui prefix name. For example ImGuiImGuiStyleVar_WindowMinSize, but also ImGuiImVec2 would be better named ImVec2.
ImGuiSetNextWindowSizeConstraints does not seem to have any effect.

Most of the Imgui swig stuff is from here: https://github.com/RayquazaGX/swigimgui/blob/master/imgui.i
https://github.com/Jonathhhan/ofxOfelia/blob/ofxAddons/scripts/common/ofxOfeliaImGuiBindings.i

@Jonathhhan
Copy link
Collaborator Author

Jonathhhan commented Apr 25, 2024

@danomatika maybe you know a solution for my issue?

The main issue is, that some of the objects have a double ImGuiImGui prefix name.
For example ImGuiImGuiStyleVar_WindowMinSize, but also ImGuiImVec2 would be better named ImVec2.

https://github.com/Jonathhhan/ofxOfelia/blob/ofxAddons/scripts/common/ofxOfeliaImGuiBindings.i

@danomatika
Copy link

danomatika commented Apr 25, 2024 via email

@Jonathhhan
Copy link
Collaborator Author

@danomatika thanks. I actually forgot to strip the names in that file. Did that already here (after having a look at swig-open frameworks): https://github.com/Jonathhhan/ofxOfelia/blob/ofxAddons/scripts/common/ofxOfeliaOfxBindings.i
Will give it a try this evening.

@Jonathhhan
Copy link
Collaborator Author

Jonathhhan commented Apr 25, 2024

Another SWIG issue with some ofxGui objects like ofxSlider: https://github.com/openframeworks/openFrameworks/blob/master/addons/ofxGui/src/ofxToggle.cpp
It has more than one typedef and they are not recognized by SWIG:

typedef ofxSlider<float> ofxFloatSlider;
typedef ofxSlider<int> ofxIntSlider;

Is there a way to recognize those objects?

Another question: Is it possible to use ofThreads (or threads in general) with SWIG?
Tried that, but without success yet...
swig/swig#2893

@Jonathhhan
Copy link
Collaborator Author

Jonathhhan commented Apr 25, 2024

Found a solution for the ImGui naming. Because it is a namespace I only needed it for constants and enums:

// strip "ImGui" from constants & enums
%rename("%(strip:[ImGui])s", %$isconstant) "";
%rename("%(strip:[ImGui])s", %$isenumitem) "";

@Jonathhhan
Copy link
Collaborator Author

Jonathhhan commented May 3, 2024

Here an update: https://github.com/Jonathhhan/ofxOfeliaExtended
Implemented internal Addons are:

ofxAssimpModelLoade
ofxOpenCv
ofxSvg
ofxVectorGraphics

Implemented external Addons are:

ofxImGui
ofxVolumetrics
ofxStableDiffusion
srtparser

I tried some other Addons which do not work (out of the box):

ofxGui
ofxMidi

A problem with ofxMidi and ofxGui is, that I do not know how to implement additional callbacks (should be possible, because ofKeyPressed etc. are also callbacks). ofxMidi only needs one call back, while ofxGui's ofParameter needs more (one per GUI element).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants