Skip to content

Node Graph Editors with ImGui #306

Closed

Description

@emoon

Hi,

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:

http://keenleveldesign.com/pimp/protools/shaderfusion/ShaderFusionReleasePromo/shaderfusion01.jpg

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.

Cheers!

Activity

  1. ocornut commented on Aug 24, 2015

    @ocornut
    Owner

    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:

    • 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.

  2. emoon commented on Aug 24, 2015

    @emoon
    ContributorAuthor

    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.

  3. ocornut commented on Aug 25, 2015

    @ocornut
    Owner

    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.

    node_graph_editor

    Code
    https://gist.github.com/ocornut/7e9b3ec566a333d725d4

  4. emoon commented on Aug 25, 2015

    @emoon
    ContributorAuthor

    👍 thanks! :)

  5. emoon commented on Aug 25, 2015

    @emoon
    ContributorAuthor

    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.

  6. NocturnDragon commented on Aug 25, 2015

    @NocturnDragon

    Hi,
    Rectangular links could also be a (simpler) possibility.
    i.e. https://youtu.be/KvExDzISYUc?t=9s

  7. MrSapps commented on Aug 25, 2015

    @MrSapps

    @ocornut nice!! 👍 @NocturnDragon what algorithm does the rect layouts use? I notice it somehow seems to avoid overlapping itself?

  8. ocornut commented on Aug 25, 2015

    @ocornut
    Owner

    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.

  9. dumblob commented on Aug 25, 2015

    @dumblob

    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.

  10. emoon commented on Aug 25, 2015

    @emoon
    ContributorAuthor

    #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.

  11. emoon commented on Aug 25, 2015

    @emoon
    ContributorAuthor

    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.

  12. ocornut commented on Aug 25, 2015

    @ocornut
    Owner

    Yeah they are just dummy values, didn't want to clutter the example with too much things.

    ImGui::SliderFloat("##value", &node->Value, 0.0f, 1.0f, "Alpha %.2f");
    float dummy_color[3] = { node->Pos.x / ImGui::GetWindowWidth(), node->Pos.y / ImGui::GetWindowHeight(), fmodf((float)node->ID * 0.5f, 1.0f) };
    ImGui::ColorEdit3("##color", &dummy_color[0]);
    

    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.

  13. emoon commented on Aug 25, 2015

    @emoon
    ContributorAuthor

    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.

  14. emoon commented on Aug 25, 2015

    @emoon
    ContributorAuthor

    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.

  15. bkaradzic commented on Aug 26, 2015

    @bkaradzic
    Contributor

    Awesome work! 👍

    Rectangular links could also be a (simpler) possibility.

    +1 for rectangular and 45 degree angle links. I find them way more readable than curves/spaghetti stuff. :)

  16. 129 remaining items

  17. Fattorino commented on Feb 1, 2024

    @Fattorino

    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
    ImNodeFlowDemo

  18. ocornut commented on Feb 1, 2024

    @ocornut
    Owner

    Thank you Gabriele, and thanks for adding this the wiki section with an image.

  19. Fattorino commented on Feb 1, 2024

    @Fattorino

    @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?

  20. nem0 commented on Feb 1, 2024

    @nem0
    Contributor
  21. Fattorino commented on Feb 2, 2024

    @Fattorino

    @Fattorino: also here: https://gist.github.com/ChemistAion/0cd64b71711d81661344af040c142c1c#file-nodes-cpp-L5

    @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)

  22. ChemistAion commented on Feb 2, 2024

    @ChemistAion

    @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()

  23. Fattorino commented on Feb 2, 2024

    @Fattorino

    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?

  24. meshula commented on Feb 3, 2024

    @meshula

    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.

            uint32_t text_color = 0xffffff;
            uint32_t text_color_highlighted = 0x00ffff;
            text_color |= (uint32_t)(255 * 2 * (root.canvas.scale - 0.5f)) << 24;
            text_color_highlighted |= (uint32_t)(255 * 2 * (root.canvas.scale - 0.5f)) << 24;
    image image

    For zooming in, I didn't want to spend memory on enormous fonts, so I just let it get blurry.

  25. Fattorino commented on Feb 3, 2024

    @Fattorino

    Yes, I think that is the smartest decision. When I find the time I'll see how it looks. And thanks

  26. ocornut commented on Feb 6, 2024

    @ocornut
    Owner

    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.

  27. Fattorino commented on Feb 14, 2024

    @Fattorino

    New styling system, and therefore new looks for ImNodeFlow, any feedback?
    image

  28. ocornut commented on Dec 9, 2024

    @ocornut
    Owner

    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.

  29. Daandelange commented on Dec 9, 2024

    @Daandelange

    It seems that onurae/core-nodes isn't on the list, so leaving it here. :)
    imgui core-nodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址