Пример #1
0
        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);
        }
Пример #2
0
        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);
        }