komorra / NodeEditorWinforms

Node based user control / editor for Windows Forms
MIT License
507 stars 142 forks source link

Proposal and Question #15

Closed EzeKees closed 3 years ago

EzeKees commented 3 years ago

Hi, first of all I want to thank you for this great library, I am using it in my project and have expanded it to use Direct2D for graphics rendering (among other things). I have only one question: How can I make or create a node that has multiple outputs? For example, fork a Boolean value. I can not find ways to do it at the moment, any help will be greatly appreciated, it is more if you want it, I can give you my expanded code.

komorra commented 3 years ago

Hi, multiple outputs are achieved via out method arguments. For example consider such node:

[Node("Separate Vector", Menu = "Convert", IsCallable = false)]
public void SeparateVector(NVector3 input, out float x, out float y, out float z)
{
    x = input.Value.X;
    y = input.Value.Y;
    z = input.Value.Z;
}

Node above will produce 3 outputs x, y, and z. In your case, just use "out bool something". Hope it helps :)

EzeKees commented 3 years ago

Thanks a lot. I have the last question: can you achieve something like this?: Branch_Example

If you can't, more or less, how could you achieve it? thanks again

komorra commented 3 years ago

Yes, it should be possible. The type that is represented by execution connections is named: ExecutionPath . Please look at example below:

[Node("Loop", Menu = "Flow", Width = 200)]
public void Loop(ExecutionPath iteration, int firstIndex, int lastIndex, out int iterationIndex, out ExecutionPath completed)
{            
    completed = new ExecutionPath();
    if(!loopCounter.ContainsKey(CurrentProcessingNode))
    {
        loopCounter.Add(CurrentProcessingNode, 0);
    }
    iterationIndex = loopCounter[CurrentProcessingNode] + firstIndex;
    loopCounter[CurrentProcessingNode]++;
    if(iterationIndex > lastIndex)
    {
        completed.Signal();
        loopCounter[CurrentProcessingNode] = 0;
    }            
}

Types of ExecutionPath need to be signaled, to tell the system, which path to take, via Signal() method.

EzeKees commented 3 years ago

many thanks!!!

ntmessagebox commented 8 months ago

Hello, i want to use the ExecutionPath in a "Bool" control where it will take the "Exit" path on true and another "ExecutionPath" on false. The problem is that it loop to that Node at the end of the "ExecutionPath" path.

Any suggestion on how to accomplish that please? Thank you for the great lib tho.