Example #1
0
        public void AddProperty()
        {
            PendingConnectionViewModel pending = Parent.PendingConnection;

            if (pending == null || pending.Output == null || !(pending.Output.Parent is SubstanceNodeViewModel))
            {
                return;
            }

            SubstanceNodeViewModel sub_view = pending.Output.Parent as SubstanceNodeViewModel;

            NodeInputViewModel new_prop_input = new NodeInputViewModel();

            new_prop_input.Connections.Connect()
            .Subscribe(change => {
                OnPropertyInputChanged(change);
            });

            Inputs.Edit(x => x.Add(new_prop_input));

            ConnectionViewModel new_prop_connection = new ConnectionViewModel(
                Parent,
                new_prop_input,
                sub_view.Outputs.Items.First());

            Parent.Connections.Edit(x => x.Add(new_prop_connection));
        }
Example #2
0
        private void ProcessPropertyInputAdd(ItemChange <ConnectionViewModel> change)
        {
            SubstanceNodeViewModel sub_view = change.Current.Output.Parent as SubstanceNodeViewModel;

            if (sub_view == null)
            {
                return;
            }

            Cut.Properties.Add(sub_view.Substance);
        }
Example #3
0
        public void AddPropertiesToNode()
        {
            System.Windows.Point prop_offset = new System.Windows.Point(Position.X - 200, Position.Y + 70);

            for (int i = 0; i < Cut.Properties.Count; i++)
            {
                Substance s = Cut.Properties[i];

                // If we have enough node inputs already, just grab the one corresponding to this property;
                // Otherwise, add a new input to the input view model.
                NodeInputViewModel prop_input = new NodeInputViewModel();
                if (Inputs.Count > i + 1)
                {
                    prop_input = Inputs.Items.ElementAt(i + 1);
                }
                else
                {
                    Inputs.Edit(x => x.Add(prop_input));
                }

                if (Cut.Properties[i] == null)
                {
                    continue;
                }

                prop_input.Connections.Connect()
                .Subscribe(change => {
                    OnPropertyInputChanged(change);
                });

                // Create a node for the property
                SubstanceNodeViewModel temp_node = new SubstanceNodeViewModel(s);
                temp_node.Position = prop_offset;

                Parent.Nodes.Edit(x => x.Add(temp_node));

                prop_offset.Y = (temp_node.Position.Y + temp_node.Size.Height + 125);

                // Connect the property node to the cut node.
                ConnectionViewModel first_to_begin = new ConnectionViewModel(
                    Parent,
                    prop_input,
                    temp_node.Outputs.Items.First());
                Parent.Connections.Edit(x => x.Add(first_to_begin));
            }

            m_EnableConnectionUpdates = true;
        }
Example #4
0
        private void ProcessPropertyInputRemove(ItemChange <ConnectionViewModel> change)
        {
            SubstanceNodeViewModel sub_view = change.Current.Output.Parent as SubstanceNodeViewModel;

            if (sub_view == null)
            {
                return;
            }

            int substance_index = Cut.Properties.IndexOf(sub_view.Substance);

            Inputs.Edit(x => x[substance_index + 1].Connections.Dispose());
            Inputs.Edit(x => x.RemoveAt(substance_index + 1));

            Cut.Properties.Remove(sub_view.Substance);
        }
Example #5
0
        private void AddProperty(Substance Sub, System.Windows.Point Position)
        {
            SubstanceNodeViewModel sub_view = new SubstanceNodeViewModel(Sub);

            sub_view.Position = Position;

            NodeInputViewModel new_prop_input = new NodeInputViewModel();

            new_prop_input.Connections.Connect()
            .Subscribe(change => {
                OnPropertyInputChanged(change);
            });

            Parent.Nodes.Edit(x => x.Add(sub_view));

            Inputs.Edit(x => x.Add(new_prop_input));

            ConnectionViewModel new_prop_connection = new ConnectionViewModel(
                Parent,
                new_prop_input,
                sub_view.Outputs.Items.First());

            Parent.Connections.Edit(x => x.Add(new_prop_connection));
        }
Example #6
0
        public void CopySettingsFromCamera(WCamera Camera, bool IsStart)
        {
            string EyeName    = IsStart ? "StartEye" : "Eye";
            string CenterName = IsStart ? "StartCenter" : "Center";
            string FovyName   = IsStart ? "StartFovy" : "Fovy";

            List <NodeInputViewModel> ViewModelList = Inputs.Items.ToList();

            ViewModelList.RemoveAt(0); // First input is always the execution input, so skip it because it doesn't matter for properties.

            NodeInputViewModel     EyeNodeInput = ViewModelList.Find(x => x.Connections.Items.First().Output.Parent.Name.ToLower() == EyeName.ToLower());
            SubstanceNodeViewModel EyeNode      = EyeNodeInput != null?EyeNodeInput.Connections.Items.First().Output.Parent as SubstanceNodeViewModel : null;

            NodeInputViewModel     CenterNodeInput = ViewModelList.Find(x => x.Connections.Items.First().Output.Parent.Name.ToLower() == CenterName.ToLower());
            SubstanceNodeViewModel CenterNode      = CenterNodeInput != null?CenterNodeInput.Connections.Items.First().Output.Parent as SubstanceNodeViewModel : null;

            NodeInputViewModel     FovyNodeInput = ViewModelList.Find(x => x.Connections.Items.First().Output.Parent.Name.ToLower() == FovyName.ToLower());
            SubstanceNodeViewModel FovyNode      = FovyNodeInput != null?FovyNodeInput.Connections.Items.First().Output.Parent as SubstanceNodeViewModel : null;

            System.Windows.Point Offset = new System.Windows.Point(Position.X - 375, Position.Y + 50);

            // EyeNode was already attached to this cut
            if (EyeNode != null)
            {
                Substance <ObservableCollection <BindingVector3> > EyeSub = EyeNode.Substance as Substance <ObservableCollection <BindingVector3> >;
                EyeSub.Data = new ObservableCollection <BindingVector3>()
                {
                    new BindingVector3(Camera.Transform.Position)
                };
            }
            // EyeNode needs to be added
            else
            {
                Substance <ObservableCollection <BindingVector3> > EyeSub = new Substance <ObservableCollection <BindingVector3> >(EyeName, SubstanceType.Vec3);
                EyeSub.Data = new ObservableCollection <BindingVector3>()
                {
                    new BindingVector3(Camera.Transform.Position)
                };

                AddProperty(EyeSub, Offset);
            }

            Offset.Y += 125;

            // CenterNode was already attached to this cut
            if (CenterNode != null)
            {
                Substance <ObservableCollection <BindingVector3> > CenterSub = CenterNode.Substance as Substance <ObservableCollection <BindingVector3> >;
                Vector3 CenterPos = Camera.Transform.Position + (Camera.Transform.Forward * -1000.0f);
                CenterSub.Data = new ObservableCollection <BindingVector3>()
                {
                    new BindingVector3(CenterPos)
                };
            }
            // CenterNode needs to be added
            else
            {
                Substance <ObservableCollection <BindingVector3> > CenterSub = new Substance <ObservableCollection <BindingVector3> >(CenterName, SubstanceType.Vec3);
                Vector3 CenterPos = Camera.Transform.Position + (Camera.Transform.Forward * -1000.0f);
                CenterSub.Data = new ObservableCollection <BindingVector3>()
                {
                    new BindingVector3(CenterPos)
                };

                AddProperty(CenterSub, Offset);
            }

            Offset.Y += 125;

            // FovyNode was already attached to this cut
            if (FovyNode != null)
            {
                Substance <ObservableCollection <PrimitiveBinding <float> > > FovySub = FovyNode.Substance as Substance <ObservableCollection <PrimitiveBinding <float> > >;
                FovySub.Data = new ObservableCollection <PrimitiveBinding <float> >()
                {
                    new PrimitiveBinding <float>(Camera.FieldOfView)
                };
            }
            // FovyNode needs to be added
            else
            {
                Substance <ObservableCollection <PrimitiveBinding <float> > > FovySub = new Substance <ObservableCollection <PrimitiveBinding <float> > >(FovyName, SubstanceType.Float);
                FovySub.Data = new ObservableCollection <PrimitiveBinding <float> >()
                {
                    new PrimitiveBinding <float>(Camera.FieldOfView)
                };

                AddProperty(FovySub, Offset);
            }
        }
Example #7
0
        private void OnRequestCreatePropertyNode(Tuple <string, string, SubstanceType> args)
        {
            Substance new_sub = null;

            switch (args.Item3)
            {
            case SubstanceType.Float:
                float FloatDefault = 0.0f;
                float.TryParse(args.Item2, out FloatDefault);

                new_sub = new Substance <ObservableCollection <PrimitiveBinding <float> > >(args.Item1, args.Item3)
                {
                    Data = new ObservableCollection <PrimitiveBinding <float> >()
                    {
                        new PrimitiveBinding <float>(FloatDefault)
                    }
                };
                break;

            case SubstanceType.Int:
                int IntDefault = 0;
                int.TryParse(args.Item2, out IntDefault);

                new_sub = new Substance <ObservableCollection <PrimitiveBinding <int> > >(args.Item1, args.Item3)
                {
                    Data = new ObservableCollection <PrimitiveBinding <int> >()
                    {
                        new PrimitiveBinding <int>(IntDefault)
                    }
                };
                break;

            case SubstanceType.String:
                new_sub = new Substance <PrimitiveBinding <string> >(args.Item1, args.Item3)
                {
                    Data = new PrimitiveBinding <string>(args.Item2)
                };
                break;

            case SubstanceType.Vec3:
                new_sub = new Substance <ObservableCollection <BindingVector3> >(args.Item1, args.Item3)
                {
                    Data = new ObservableCollection <BindingVector3>()
                    {
                        new BindingVector3(new OpenTK.Vector3(0, 0, 0))
                    }
                };
                break;
            }

            SubstanceNodeViewModel temp_node = new SubstanceNodeViewModel(new_sub);

            temp_node.Position = Position;

            Parent.Nodes.Edit(x => x.Add(temp_node));

            NodeInputViewModel new_prop_input = new NodeInputViewModel();

            new_prop_input.Connections.Connect()
            .Subscribe(change => {
                OnPropertyInputChanged(change);
            });

            Inputs.Edit(x => x.Add(new_prop_input));

            ConnectionViewModel new_prop_connection = new ConnectionViewModel(
                Parent,
                new_prop_input,
                temp_node.Outputs.Items.First());

            Parent.Connections.Edit(x => x.Add(new_prop_connection));
        }