public MainViewModel() { NodeListViewModel.NodeTemplates.AddRange(nodeTemplates); NetworkViewModel.Validator = network => { bool containsLoops = GraphAlgorithms.FindLoops(network).Any(); if (containsLoops) { return(new NetworkValidationResult(false, false, new ErrorMessageViewModel("Network contains loops!"))); } return(new NetworkValidationResult(true, true, null)); }; NetworkViewModel.Nodes.Add(ShaderOutputNode); ShaderOutputNode.ColorInput.ValueChanged .Where(shader => shader != null) //.Where(_ => NetworkViewModel.LatestValidation.IsValid) .Select(shader => { string func = shader.Compile(); return(new[] { "#version 330 core", "", "in vec3 pos;", "in vec3 norm;", "in vec3 cam;", "in float seconds;", "out vec3 outColor;", "", "void main() {", $" outColor = {func};", "}" }); }) .BindTo(this, vm => vm.ShaderPreviewViewModel.FragmentShaderSource); CollapseAllCommand = ReactiveCommand.Create(() => { foreach (var node in NetworkViewModel.Nodes.Items) { node.IsCollapsed = true; } }); SetupContextMenuViewModels(); }
public void TestValidateAfterConnectionsAllUpdated() { NodeInputViewModel input1 = new NodeInputViewModel(); NodeOutputViewModel output1 = new NodeOutputViewModel(); NodeViewModel node1 = new NodeViewModel { Inputs = { input1 }, Outputs = { output1 } }; NodeInputViewModel input2 = new NodeInputViewModel(); NodeOutputViewModel output2 = new NodeOutputViewModel(); NodeViewModel node2 = new NodeViewModel { Inputs = { input2 }, Outputs = { output2 } }; NetworkViewModel network = new NetworkViewModel(); network.Validator = n => { if (GraphAlgorithms.FindLoops(network).Any()) { return(new NetworkValidationResult(false, false, null)); } return(new NetworkValidationResult(true, true, null)); }; network.Nodes.Add(node1); network.Nodes.Add(node2); var conn1 = network.ConnectionFactory(input1, output2); network.Connections.Add(conn1); Assert.IsTrue(network.LatestValidation.IsValid); var conn2 = network.ConnectionFactory(input2, output1); network.Connections.Add(conn2); Assert.IsFalse(network.LatestValidation.IsValid); network.Connections.Remove(conn1); Assert.IsTrue(network.LatestValidation.IsValid); }
public MainViewModel() { NodeListViewModel.AddNodeType(() => new Vec2PackNodeViewModel()); NodeListViewModel.AddNodeType(() => new Vec2UnpackNodeViewModel()); NodeListViewModel.AddNodeType(() => new Vec3PackNodeViewModel()); NodeListViewModel.AddNodeType(() => new Vec3UnpackNodeViewModel()); NodeListViewModel.AddNodeType(() => new ColorNodeViewModel()); NodeListViewModel.AddNodeType(() => new GeometryNodeViewModel()); NodeListViewModel.AddNodeType(() => new TimeNodeViewModel()); NodeListViewModel.AddNodeType(() => new MathNodeViewModel()); NodeListViewModel.AddNodeType(() => new Math2NodeViewModel()); NodeListViewModel.AddNodeType(() => new Vec3MathNodeViewModel()); NetworkViewModel.Validator = network => { bool containsLoops = GraphAlgorithms.FindLoops(network).Any(); if (containsLoops) { return(new NetworkValidationResult(false, false, new ErrorMessageViewModel("Network contains loops!"))); } return(new NetworkValidationResult(true, true, null)); }; NetworkViewModel.Nodes.Add(ShaderOutputNode); ShaderOutputNode.ColorInput.ValueChanged .Where(shader => shader != null) //.Where(_ => NetworkViewModel.LatestValidation.IsValid) .Select(shader => { string func = shader.Compile(); return(new[] { "#version 330 core", "", "in vec3 pos;", "in vec3 norm;", "in vec3 cam;", "in float seconds;", "out vec3 outColor;", "", "void main() {", $" outColor = {func};", "}" }); }) .BindTo(this, vm => vm.ShaderPreviewViewModel.FragmentShaderSource); }
public MainViewModel() { NodeListViewModel.AddNodeType(() => new ImageInputNodeViewModel()); NodeListViewModel.AddNodeType(() => new ImageDisplayNodeViewModel()); NetworkViewModel.Validator = network => { bool containsLoops = GraphAlgorithms.FindLoops(network).Any(); if (containsLoops) { return new NetworkValidationResult(false, false, new ErrorMessageViewModel("Network contains loops!")); } return new NetworkValidationResult(true, true, null); }; NetworkViewModel.Nodes.Add(CodecInputNode); NetworkViewModel.Nodes.Add(CodecOutputNode); }
public MainWindow() { InitializeComponent(); _network = new NetworkViewModel(); _network.Validator = network => { bool containsLoops = GraphAlgorithms.FindLoops(network).Any(); if (containsLoops) { return(new NetworkValidationResult(false, false, new ErrorMessageViewModel("Network contains loops!"))); } return(new NetworkValidationResult(true, true, null)); }; _network.Nodes.Add(CreateNode()); NetworkView.ViewModel = _network; this.WhenAnyValue(v => v.ShowOutputChecky.IsChecked).Subscribe(isChecked => { _network.Nodes.Items.First().Outputs.Items.ElementAt(0).Visibility = isChecked.Value ? EndpointVisibility.AlwaysVisible : EndpointVisibility.AlwaysHidden; }); }