-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathVec2PackNodeViewModel.cs
More file actions
55 lines (48 loc) · 1.81 KB
/
Vec2PackNodeViewModel.cs
File metadata and controls
55 lines (48 loc) · 1.81 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using DynamicData;
using ExampleShaderEditorApp.Model;
using ExampleShaderEditorApp.ViewModels.Editors;
using NodeNetwork.ViewModels;
using NodeNetwork.Views;
using ReactiveUI;
namespace ExampleShaderEditorApp.ViewModels.Nodes
{
public class Vec2PackNodeViewModel : ShaderNodeViewModel
{
static Vec2PackNodeViewModel()
{
Splat.Locator.CurrentMutable.Register(() => new NodeView(), typeof(IViewFor<Vec2PackNodeViewModel>));
}
public ShaderNodeInputViewModel XInput { get; } = new ShaderNodeInputViewModel(typeof(float));
public ShaderNodeInputViewModel YInput { get; } = new ShaderNodeInputViewModel(typeof(float));
public ShaderNodeOutputViewModel Result { get; } = new ShaderNodeOutputViewModel();
public Vec2PackNodeViewModel()
{
this.Name = "New Vec2";
this.Category = NodeCategory.Vector;
XInput.Name = "X";
XInput.Editor = new FloatEditorViewModel();
EditableInputs().Add(XInput);
YInput.Name = "Y";
YInput.Editor = new FloatEditorViewModel();
EditableInputs().Add(YInput);
Result.Name = "Vec2";
Result.ReturnType = typeof(Vec2);
Result.Value = this.WhenAnyValue(vm => vm.XInput.Value, vm => vm.YInput.Value)
.Select(t =>
{
if (t.Item1 == null || t.Item2 == null)
{
return null;
}
return new ShaderFunc(() => $"vec2(({t.Item1.Compile()}), ({t.Item2.Compile()}))");
});
EditableOutputs().Add(Result);
}
}
}