-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubContextNodes.cs
197 lines (171 loc) · 7.24 KB
/
SubContextNodes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using md.stdl.Boolean;
using md.stdl.Interaction;
using Notui;
using md.stdl.Mathematics;
using mp.pddn;
using VVVV.DX11.Nodes.Renderers.Graphics.Touch;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.IO;
using VVVV.Utils.VMath;
using VMatrix = VVVV.Utils.VMath.Matrix4x4;
using SMatrix = System.Numerics.Matrix4x4;
namespace Notuiv
{
[PluginInfo(
Name = "SubContextOptions",
Category = "Notui",
Author = "microdee",
Version = "Join",
AutoEvaluate = true
)]
public class SubContextOptionsNode : IPluginEvaluate
{
[Input("Include Hitting Touches Too")]
public IDiffSpread<bool> FIncludeHitting;
[Input("Touch Coordinate Source")]
public IDiffSpread<SubContextOptions.IntersectionSpaceSelection> FTouchCoordSrc;
[Output("Output")]
public ISpread<SubContextOptions> FOut;
public void Evaluate(int SpreadMax)
{
FOut.Stream.IsChanged = false;
if (FIncludeHitting.IsChanged || FTouchCoordSrc.IsChanged)
{
FOut.SliceCount = SpreadMax;
for (int i = 0; i < SpreadMax; i++)
{
if (FOut[i] == null)
FOut[i] = new SubContextOptions();
FOut[i].IncludeHitting = FIncludeHitting[i];
FOut[i].TouchSpaceSource = FTouchCoordSrc[i];
FOut[i].UpdateOnlyChangeFlagged = true;
}
FOut.Stream.IsChanged = true;
}
}
}
[PluginInfo(
Name = "SubContext",
Category = "Notui",
Author = "microdee",
Version = "Split",
AutoEvaluate = true
)]
public class SubContextNode : IPluginEvaluate, IPluginFeedbackLoop
{
[Import] public IPluginHost2 PluginHost;
[Import] public IHDEHost Host;
[Input("Hosting Element")]
public Pin<NotuiElement> FHostElements;
[Input("Element Prototypes")]
public IDiffSpread<ISpread<ElementPrototype>> FElements;
private Spread<Spread<ElementPrototype>> _prevElements = new Spread<Spread<ElementPrototype>>();
[Input("Force Update Elements", IsBang = true, Visibility = PinVisibility.Hidden)]
public ISpread<bool> FUpdateElements;
[Input("Auto Update Elements", DefaultBoolean = true, Visibility = PinVisibility.Hidden)]
public ISpread<bool> FAutoUpdateElements;
[Input("Minimum Force for Interaction", DefaultValue = 0.5)]
public IDiffSpread<float> FMinForce;
[Input("Consider Touch New Before", DefaultValue = 1)]
public ISpread<int> FConsiderNew;
[Input("Consider Touch Released After", DefaultValue = 1)]
public ISpread<int> FConsiderReleased;
[Input("View")]
public Pin<VMatrix> FViewTr;
[Input("Projection")]
public Pin<VMatrix> FProjTr;
[Input("Aspect Ratio")]
public Pin<VMatrix> FAspTr;
[Output("Context")]
public ISpread<ISpread<NotuiContext>> FContext;
[Output("Hierarchical Elements")]
public ISpread<ISpread<NotuiElement>> FElementsOut;
[Output("Flat Elements")]
public ISpread<ISpread<NotuiElement>> FFlatElements;
[Output("Touches")]
public ISpread<ISpread<Touch>> FTouches;
private int _areElementsChanged = 0;
public void Evaluate(int SpreadMax)
{
if (FHostElements.IsConnected && FHostElements.SliceCount > 0 && FHostElements[0] != null)
{
if (FElements.IsChanged) _areElementsChanged = 2;
_prevElements.SliceCount = FHostElements.SliceCount;
FContext.SliceCount = FHostElements.SliceCount;
FElementsOut.SliceCount = FHostElements.SliceCount;
FFlatElements.SliceCount = FHostElements.SliceCount;
FTouches.SliceCount = FHostElements.SliceCount;
for (int i = 0; i < FHostElements.SliceCount; i++)
{
var hostel = FHostElements[i];
if (hostel.SubContext == null)
{
FContext[i].SliceCount = 0;
FElementsOut[i].SliceCount = 0;
FFlatElements[i].SliceCount = 0;
FTouches[i].SliceCount = 0;
continue;
}
var context = hostel.SubContext.Context;
context.View = FViewTr[i].AsSystemMatrix4X4();
context.Projection = FProjTr[i].AsSystemMatrix4X4();
context.AspectRatio = FAspTr[i].AsSystemMatrix4X4();
for (int j = 0; j < FElements[i].SliceCount; j++)
{
if (FElements[i][j] == null) continue;
if (_prevElements[i]?.Contains(FElements[i][j]) ?? true) continue;
FElements[i][j].IsChanged = ElementNodeUtils.ChangedFrames;
}
if(_prevElements[i] == null) _prevElements[i] = new Spread<ElementPrototype>();
_prevElements[i].AssignFrom(FElements[i]);
if (_areElementsChanged > 0 && FAutoUpdateElements[i] || FUpdateElements[i])
{
context.AddOrUpdateElements(true, FElements[i].Where(el => el != null).ToArray());
}
FContext[i].SliceCount = 1;
FContext[i][0] = context;
FFlatElements[i].SliceCount = context.FlatElements.Count;
for (int j = 0; j < context.FlatElements.Count; j++)
{
var element = context.FlatElements[j];
FFlatElements[i][j] = element;
switch (element.EnvironmentObject)
{
case null:
element.EnvironmentObject = new VEnvironmentData(element);
break;
case VEnvironmentData venvdat:
if (venvdat.FlattenedEvents != null) continue;
venvdat.FlattenedEvents = new ElementEventFlattener(Host);
venvdat.FlattenedEvents.Subscribe(element);
break;
}
}
FElementsOut[i].AssignFrom(context.RootElements.Values);
FTouches[i].AssignFrom(context.Touches.Values);
}
}
else
{
FContext.SliceCount = 0;
FElementsOut.SliceCount = 0;
FFlatElements.SliceCount = 0;
FTouches.SliceCount = 0;
}
if(_areElementsChanged > 0) _areElementsChanged--;
}
public bool OutputRequiresInputEvaluation(IPluginIO inputPin, IPluginIO outputPin)
{
return false;
}
}
}