Jump to content

Realtime Node Framework (like Blenders Node Interface)


minxomat
 Share

Recommended Posts

First, what would one generally use bezier nodes for?

To visualize a flow or connection of elements with different properties. Take a look at the Blender node system. This kind of visualisation is also used in a Color Grading (Davinci Resolve), Music Production (various synths) and VFX apps.

 

And second what is a bezier node?

A bezier connecting two nodes. It's control points are fixed at 50% width or height of the bezier.

Edited by minx

I will answer every single PM, and you are free to ask anything anytime.

Link to comment
Share on other sites

Minx, I attempted to change it a bit to make it On Event, but without success.

I added:

 $aMovables[$Bound][0] = GUICtrlCreateButton($sText, $iLeft, $iTop, $iWidth, $iHeight, 0x2000)
 GUICtrlSetOnEvent(-1, "NodeControl")
 

and the NodeControl out of the main loop:

Func NodeControl()
    $cur = GUIGetCursorInfo()
    If Not IsArray($cur) Then Return
    If $cur[2] = 1 Then
        For $nCtrl = 0 To UBound($aMovables) - 1
            If $cur[4] = $aMovables[$nCtrl][0] Then
                $end = GUIGetCursorInfo()
                If Not IsArray($end) Then ContinueLoop
                $dx = $end[0] - $aMovables[$nCtrl][1]
                $dy = $end[1] - $aMovables[$nCtrl][2]
                $iDrawn = 0
                $iTimer = TimerInit()
                Do
                    $end = GUIGetCursorInfo()
                    $aMovables[$nCtrl][1] = $end[0] - $dx
                    $aMovables[$nCtrl][2] = $end[1] - $dy
                    If $aMovables[$nCtrl][1] <= 6 Then $aMovables[$nCtrl][1] = 6
                    If $aMovables[$nCtrl][2] <= 6 Then $aMovables[$nCtrl][2] = 6
                    If $aMovables[$nCtrl][1] + $aMovables[$nCtrl][3] >= ($iGUIWidth - 6) Then $aMovables[$nCtrl][1] = ($iGUIWidth - 6) - $aMovables[$nCtrl][3]
                    If $aMovables[$nCtrl][2] + $aMovables[$nCtrl][4] >= ($iGUIWidth - 26) Then $aMovables[$nCtrl][2] = ($iGUIHeight - 26) - $aMovables[$nCtrl][4]
                    $aMovables[$nCtrl][6] = 0x00FF00
                    $back = $g
                    $g = GUICtrlCreateGraphic(0, 0)
                    GUICtrlSetState(-1, 128)
                    DrawBounds()
                    For $tCtrl = 0 To UBound($aMovables) - 1
                        If $aMovables[$tCtrl][5] <> "" Then
                            $aNodes = StringSplit($aMovables[$tCtrl][5], ",", 3)
                            For $nConnection = 0 To UBound($aNodes) - 1
                                If Not IsNodeInObject($aNodes[$nConnection], $tCtrl) Then DrawConnection($tCtrl, $aNodes[$nConnection], $aMovables)
                                $iDrawn += 1
                            Next
                        EndIf
                    Next
                    GUICtrlDelete($back)
                    GUICtrlSetPos($aMovables[$nCtrl][0], $aMovables[$nCtrl][1], $aMovables[$nCtrl][2])
                    $aMovables[$nCtrl][6] = 0xFFFFFF
                Until $end[2] = 0
            EndIf
        Next
    EndIf
EndFunc   ;==>NodeControl
Link to comment
Share on other sites

Why would you do that? You can use OnEvent just fine with the handler in the main loop. If the user doesn't click anything, nothing will be redrawn (== no CPU time wasted).

I will answer every single PM, and you are free to ask anything anytime.

Link to comment
Share on other sites

Very cool Minx!  I noticed the CPU is heavy when dragging nodes.  I inserted a sleep(10) (on line 120) after the for loops and it does not seem to have any major lag effect, but drops the CPU usage significantly.  I know a band-aid like this isn't desirable, but just thought I'd try and see what happens.  Regardless, Well done!

 

Link to comment
Share on other sites

-snip-

Well, I altered the script already to make it easier to handle for the CPU. Eventually, it completely broke down under the load of a realistic Node layout. Thus, I'm redesigning it using OpenGL and chunk-based refreshing now.

Before (pure AutoIt (also no GDI+)):

old3e08.png

After (early prototype, using a better spring algorithm). OpenGL

new5b38.png

Edited by minx

I will answer every single PM, and you are free to ask anything anytime.

Link to comment
Share on other sites

Before (pure AutoIt (also no GDI+)):

 source share please

It's a mess. Not my usual mess, a messy mess. Using 5 Nodes already pushes the limit. I implemented auto-resizing canvas, canvas dragging, Node selection etc. before givin up on this approach. The new version won't be much different, but the performance will be (a whole) lot better.

I will answer every single PM, and you are free to ask anything anytime.

Link to comment
Share on other sites

Hello Minx,

This is really great !!  :king:

I see lot's of applications using this in practice.

Speed and performance improvements are always welcome. 

I can imaging that the GDI wizard (UEZ) can be of big help here.

Great addition for AU3.

Thanks a lot for sharing, looking forward for the next release

rgds

ptrex

Link to comment
Share on other sites

Nah, OpenGL is the way to go here. There are inbuilt tools for chunk management. GDI+ is slower than GDI in most cases, which is why it doesn't make much sense here.

I will answer every single PM, and you are free to ask anything anytime.

Link to comment
Share on other sites

Very cool script, Minx.  ^_^

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • 1 month later...

@ minx,

Hi, I was amazed when I came across your posting. :sorcerer:

I didn't know that AutoIt was capable of doing this sort of thing at all.

It seemed like it may be the answer to what I have been looking for for some time now.

I downloaded it and played about with it and then I realised "Whoa! I am like a caveman playing about with a smartphone, I can see what it is doing but am unable to comprehend how it does what it does." :(

But picking my way through it I tried to see if it would do as I would like it to and it wouldn't (or more probably, I stuffed up and cannot get it to do what I want!)

 

Perhaps you could tell me if the following is possible? :idea:

* To have the bezier curve change colour depending upon which direction the link goes in.

 i.e. in your example clicking on 'Render Framework' node lights up green to 3 nodes (SunX, AmbientLight &SunRed) going 'down' from 'Init' but if I click on any of the 3 nodes they go down further (green) and while I would still like to show those further 'down' links as green etc I would also like to show the 'upward' (back) links as say red or what ever.

My Very Limited understanding of the way it behaved when I tinkered with it suggests that it can only display one-way links.

I would need it to be able to display 3 types of links (3 colours) 1 for 'Up' links, 2 for 'Down' links & 3 for (Sideways/Parallel) links to a node that has an equivalent weight or value as the node being clicked on.

e.g. If it was for instance to display a family tree like the following:

[Mam]----[son1]----[Grandson]

|                  |

|              [son2]

[Dad]

Then Clicking on:

Mam should link blue to Dad, green to Son1 & Son2

Dad should link blue to Mam, green to Son1 & Son2

Son1 should link green to Grandson, Red back to Mam & Dad, then blue to Son2

(My usage will Not be for family trees but it seemed the simplest example of what linking I would like to perform.)

Hopefully I have explained it clearly enough.

* If the above is possible, how difficult would it be to create a UDF that could be called with the details and it would then display the linkages and return the ID of the node clicked on?

Say you had the above data in an array:

  ID     txt       Up       Same       Dwn

+----+------+-------+-----------+---------+

|   0  | Mam|          |       1      |   2, 3    |

+----+------+-------+-----------+---------+

|   1  | Dad |          |       0      |   2, 3    |

+----+------+-------+-----------+---------+

|   2  |Son1|   0, 1 |        3     |     4      |

+----+------+-------+-----------+---------+

|   3  |Son2|  0, 1  |        2     |             |

+----+------+-------+-----------+---------+

|   4  |Gson|     2   |               |             |

+----+------+-------+-----------+---------+

Then calling the UDF with array ID = 2 would read the array row 2 and populate the node freamework with the title 'Son1' and the other nodes 0, 1, 3, & 4. and colour the link apporpriately.

Thank You for the script and for letting me know if the above is possible.

br. DeMo.

Quote of the week:"BASIC programmers never die, they GOSUB and don't RETURN." -- UnknownWisdom of the ages:

  

  • I'd be unstoppable... if not for law enforcement and physics.
  • Marriage, the number 1 cause of divorce.
  • Don't steal... the government hates competition.
  • Irish Government Motto: We’ve got what it takes to take what you’ve got.
  • Birthdays are good for you. Statistics show that the people who have the most live the longest.
  • Failure is not an option. It comes bundled with your Microsoft product.-- Ferenc Mantfeld
  • If you learn from your mistakes, then why ain't I a genius?! -- Anonymous
  • Remember, live every day as if it was your last day! one day you will be right.
  • How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?
  • Sure my system is secure, it just locked up again.
  • I haven't lost my mind; I have a tape back-up somewhere.  ~Author Unknown
Link to comment
Share on other sites

It is absolutely wonderful.
Surprising as it is simple and small.
Many times I thought about something like that, but there was no time to implement.
 
Thanks for sharing.
5*
 
Best regards,
mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...