You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I'm thinking of using ImGui for doing a basic node graph that can be used to edit materials. There are lots of programs that does this but for example:
I wonder how one would go about doing something similar with ImGui. Having separate windows for each box is likely (?) the best approach as it would allow the user to move them around and what not.
I guess adding some custom stuff for doing the connections + lines as well shouldn't be too hard but I just wanted your thoughts about it.
You can start with actual ImGui Windows but as you dig into connections and more features they will likely get in your way? It may be more awkward to restrict them within a given spot, etc. One benefit is that they will handle overlapping for you.
Creating your own mini-window not too hard:
do your drawing via the drawlist API
perhaps push a clipping rectangle
use InvisibleButton() + IsItemActive() (or MouseClickedPos and GetMouseDragDelta) to handle moving.
If you can avoid overlapping it'll be simpler. If you can't the next easiest thing would probably be to handle ordering/sorting them yourself.
Reacted by crystalthoughts, Daniel Eke, Martin Hammerchmidt, DzOneManArmy, Teng Wu, Clemens Ulrich, Nikita Biryukov, Matus Zdansky, MasterDrake, rtj and 3 more
Reacted by DzOneManArmy, Zhehao Li , Clemens Ulrich, MasterDrake and Mehmet Emin BAŞOĞLU
Here's a proof of concept demo. It's quite incomplete but shows that it is possible.
You'll need to update to latest because I have fixed a bug with the ImDrawList / channel API. Drawing channels are very convenient to allow out-of-order rendering (here we draw the node background after the nodes are filled with contents).
I'm declaring some ImVec2 operators to make the code simpler. If you have your own math types with conversions via IM_VEC2_CLASS_EXTRA you are probably better off using them.
Sort of work but I'm not very happy with it because it wasn't that trivial to pull off (3 hours including bugfix) and I had to dodge a few non-obvious trap. I'll probably keep massaging that code.
I'll move the hermite curve rendering to new drawing API. Do you know of a good non-stupid reference for API that handle various types of curves? (bezier, hermite, catmull rom. etc.). They are easy to implement but I wonder if there's a way of ordering parameters that's more standard or obvious. An API to handle multiple points should be available so that thick splines can have their end connecting nicely.
Reacted by Lucas Walter, Egor Dorichev, godzillalla, ongamex, Thorsten Sommer, FengDonghai, Leanid Chaika, halvnykterist, Marvel, DzOneManArmy and 7 more
Reacted by matt-trost, Mister-Lemon, Alec Jacobson, Isaac Poulton, Tom Short, nicolasgustafsson, Egor Dorichev, daemoz, godzillalla, Alexander I.Grafov and 12 more
Yeah I have been thinking about what curves to actually use for the lines. I thought about just using b-spline or something similar but I have no idea what "real" editors are using.
I'm not sure those node/graph should or will be a concept of core ImGui by the way. It's more of an example code.
My intuition is the real value will be to keep massaging and improving the lower-level stuff so that it becomes more easier and natural to create this sort of thing from scratch.
Do you know of a good non-stupid reference for API that handle various types of curves? (bezier, hermite, catmull rom. etc.).
I asked the creator of Fog framework who has a lot of experience with vector libraries (Cairo, AGG, etc.) and he told me, that in Fog (and also it's successor Blend 2D) he supports only quad and cubic Bezier curves, because it's enough (and it's much easier to translate these into any other curve needed e.g. by the rendering engine). He also told me, that e.g. Cairo supports only cubic curves.
So, in the name of simplicity, feel free to take a look at the API of Bezier curves in Fog.
Small comment. I tested your prototype and when dragging the color values it seems to always reset back to default. I haven't investigated yet but just wanted to let you know.
If you aren't in a hurry I'll keep working on that in the future, add the linkage, move curves rendering to the main api and generally simplify / clean up / clarify where I can.
Another Node Editor but with a different approach. To be as customizable as possible while requiring very few lines of code to create custom nodes. ImNodeFlow
Reacted by omar, Arn, rtj, Rafael Ristovski and Alberto Pilotto
Reacted by Rokas Kupstys, Arn, Rafael Ristovski and Alberto Pilotto
@ocornut I would like to work on adding Zoom support for ImNodeHandler. I've had a look at imgui-node-editor implementation. But it's quite hefty and doesn't work with combos and similar. Could you point me in the right direction to develop such feature?
@ChemistAion if I understand correctly you do not render the ImGui widgets but only custom graphics, right?
My goal is to allow the user to create the node's body as you create an ordinary ImGui window. (I haven't had the chance to have a look at nem0's project yet)
@Fattorino: yes, my example is shown with exclusively custom graphics - the goal was to build nodes-editor state machine/engine not the frontend.
Regarding your actual question, I wanted only to direct your attention to the foundations of the zoom calculations/idea: ImGuiNodes::UpdateCanvasGeometry()
Thanks for the help, especially @nem0 whose solution was extremely fitting and allowed me to implement an almost identical solution ImNodeFlow Zoom.
I'll take advantage of this conversation to ask one last question tho. Any idea on how to void the blurry or rough rendering when zoomed in or out? And how to block a window from moving without relying on the NoMove flag?
My solution for zooming out was to fade the elements in the nodes at the point they are unusable/illegible. I put a ramp, so there's a threshold at the point the interior elements become more and more transparent.
Note that 1.90 introduced a ImFontConfig::RasterizerDensity field, which is convenient for the situation where you want to load fonts in multiple sizes and yet have their metrics matches. See #6925
This makes it easy to e.g. load one font at 100%, one font at 400% size, and swap between them when you cross over the 200% lines. All other font metrics will appears identical so there's much less juggling with sizes.
Reacted by Srik, Stuart Axon, Aiekick and Alberto Pilotto
Feel free to post if you have generic feedback/discussion on the topic.
As an related note, I'm working on a feature which will facilitate zooming text.
Activity
ocornut commentedon Aug 24, 2015
EDITED 2019
GENERALLY SPEAKING YOU CAN HEAD TO THE WIKI FOR LISTINGS
https://github.com/ocornut/imgui/wiki/Useful-Extensions
Listing relevant links posted the thread. Dig in the thread for details!
https://github.com/thedmd/imgui-node-editor
https://github.com/rokups/ImNodes
https://github.com/Nelarius/imnodes
https://github.com/Flix01/imgui/tree/imgui_with_addons
https://github.com/DCubix/Twist
http://carlivan.com/engine-tools/visual-scripting
http://carlivan.com/engine-tools/blueprints/
https://gist.github.com/ChemistAion/0cd64b71711d81661344af040c142c1c
https://gist.github.com/spacechase0/e2ff2c4820726d62074ec0d3708d61c3
https://github.com/CedricGuillemet/Imogen
https://galloscript.itch.io/texgraph
(Original 2015 answer)
You can start with actual ImGui Windows but as you dig into connections and more features they will likely get in your way? It may be more awkward to restrict them within a given spot, etc. One benefit is that they will handle overlapping for you.
Creating your own mini-window not too hard:
If you can avoid overlapping it'll be simpler. If you can't the next easiest thing would probably be to handle ordering/sorting them yourself.
emoon commentedon Aug 24, 2015
Thanks for the reply. That seems reasonable. I think I will just go for non-overlapping as this is mostly for a prototype so that should be fine.
ocornut commentedon Aug 25, 2015
Here's a proof of concept demo. It's quite incomplete but shows that it is possible.
You'll need to update to latest because I have fixed a bug with the ImDrawList / channel API. Drawing channels are very convenient to allow out-of-order rendering (here we draw the node background after the nodes are filled with contents).
I'm declaring some ImVec2 operators to make the code simpler. If you have your own math types with conversions via IM_VEC2_CLASS_EXTRA you are probably better off using them.
Sort of work but I'm not very happy with it because it wasn't that trivial to pull off (3 hours including bugfix) and I had to dodge a few non-obvious trap. I'll probably keep massaging that code.
I'll move the hermite curve rendering to new drawing API. Do you know of a good non-stupid reference for API that handle various types of curves? (bezier, hermite, catmull rom. etc.). They are easy to implement but I wonder if there's a way of ordering parameters that's more standard or obvious. An API to handle multiple points should be available so that thick splines can have their end connecting nicely.
Code
https://gist.github.com/ocornut/7e9b3ec566a333d725d4
emoon commentedon Aug 25, 2015
👍 thanks! :)
emoon commentedon Aug 25, 2015
Yeah I have been thinking about what curves to actually use for the lines. I thought about just using b-spline or something similar but I have no idea what "real" editors are using.
NocturnDragon commentedon Aug 25, 2015
Hi,
Rectangular links could also be a (simpler) possibility.
i.e. https://youtu.be/KvExDzISYUc?t=9s
MrSapps commentedon Aug 25, 2015
@ocornut nice!! 👍 @NocturnDragon what algorithm does the rect layouts use? I notice it somehow seems to avoid overlapping itself?
ocornut commentedon Aug 25, 2015
I'm not sure those node/graph should or will be a concept of core ImGui by the way. It's more of an example code.
My intuition is the real value will be to keep massaging and improving the lower-level stuff so that it becomes more easier and natural to create this sort of thing from scratch.
dumblob commentedon Aug 25, 2015
I asked the creator of Fog framework who has a lot of experience with vector libraries (Cairo, AGG, etc.) and he told me, that in Fog (and also it's successor Blend 2D) he supports only quad and cubic Bezier curves, because it's enough (and it's much easier to translate these into any other curve needed e.g. by the rendering engine). He also told me, that e.g. Cairo supports only cubic curves.
So, in the name of simplicity, feel free to take a look at the API of Bezier curves in Fog.
emoon commentedon Aug 25, 2015
#306 (comment)
Fully agree that this shouldn't be part of core ImGui but an interesting use-case to support with the API itself as you say.
emoon commentedon Aug 25, 2015
Small comment. I tested your prototype and when dragging the color values it seems to always reset back to default. I haven't investigated yet but just wanted to let you know.
ocornut commentedon Aug 25, 2015
Yeah they are just dummy values, didn't want to clutter the example with too much things.
If you aren't in a hurry I'll keep working on that in the future, add the linkage, move curves rendering to the main api and generally simplify / clean up / clarify where I can.
emoon commentedon Aug 25, 2015
Not in a major hurry no so great stuff here :) I also think it's good in general to have a example that "bends" the regular use-case a bit.
emoon commentedon Aug 25, 2015
Add yeah I agree that general curve rendering would fit good in the API, and getting linkage in the example would be great of course.
bkaradzic commentedon Aug 26, 2015
Awesome work! 👍
+1 for rectangular and 45 degree angle links. I find them way more readable than curves/spaghetti stuff. :)
129 remaining items
Fattorino commentedon Feb 1, 2024
Another Node Editor but with a different approach. To be as customizable as possible while requiring very few lines of code to create custom nodes.

ImNodeFlow
ocornut commentedon Feb 1, 2024
Thank you Gabriele, and thanks for adding this the wiki section with an image.
Fattorino commentedon Feb 1, 2024
@ocornut I would like to work on adding Zoom support for ImNodeHandler. I've had a look at imgui-node-editor implementation. But it's quite hefty and doesn't work with combos and similar. Could you point me in the right direction to develop such feature?
nem0 commentedon Feb 1, 2024
@Fattorino see https://github.com/nem0/LumixEngine/blob/master/external/imgui/imgui_user.inl#L1337 for inspiration
ChemistAion commentedon Feb 2, 2024
@Fattorino: also here: https://gist.github.com/ChemistAion/0cd64b71711d81661344af040c142c1c#file-nodes-cpp-L5
Fattorino commentedon Feb 2, 2024
@ChemistAion if I understand correctly you do not render the ImGui widgets but only custom graphics, right?
My goal is to allow the user to create the node's body as you create an ordinary ImGui window. (I haven't had the chance to have a look at nem0's project yet)
ChemistAion commentedon Feb 2, 2024
@Fattorino: yes, my example is shown with exclusively custom graphics - the goal was to build nodes-editor state machine/engine not the frontend.
Regarding your actual question, I wanted only to direct your attention to the foundations of the zoom calculations/idea:
ImGuiNodes::UpdateCanvasGeometry()Fattorino commentedon Feb 2, 2024
Thanks for the help, especially @nem0 whose solution was extremely fitting and allowed me to implement an almost identical solution ImNodeFlow Zoom.
I'll take advantage of this conversation to ask one last question tho. Any idea on how to void the blurry or rough rendering when zoomed in or out? And how to block a window from moving without relying on the NoMove flag?
meshula commentedon Feb 3, 2024
My solution for zooming out was to fade the elements in the nodes at the point they are unusable/illegible. I put a ramp, so there's a threshold at the point the interior elements become more and more transparent.
For zooming in, I didn't want to spend memory on enormous fonts, so I just let it get blurry.
Fattorino commentedon Feb 3, 2024
Yes, I think that is the smartest decision. When I find the time I'll see how it looks. And thanks
ocornut commentedon Feb 6, 2024
Note that 1.90 introduced a
ImFontConfig::RasterizerDensityfield, which is convenient for the situation where you want to load fonts in multiple sizes and yet have their metrics matches. See #6925This makes it easy to e.g. load one font at 100%, one font at 400% size, and swap between them when you cross over the 200% lines. All other font metrics will appears identical so there's much less juggling with sizes.
Fattorino commentedon Feb 14, 2024
New styling system, and therefore new looks for ImNodeFlow, any feedback?

ocornut commentedon Dec 9, 2024
Closing this as "not sure why it was still open"
As a reminder, node editors are listed here: https://github.com/ocornut/imgui/wiki/Useful-Extensions#node-editors
Feel free to post if you have generic feedback/discussion on the topic.
As an related note, I'm working on a feature which will facilitate zooming text.
Daandelange commentedon Dec 9, 2024
It seems that onurae/core-nodes isn't on the list, so leaving it here. :)
