Example #1
0
        public static float GetCurrentValueAtTime(OperatorPart opPart, double time)
        {
            OperatorPartContext context = new OperatorPartContext()
            {
                Time = (float)time
            };

            return(opPart.Eval(context).Value);
        }
Example #2
0
        public void PreEvaluate(OperatorPart opPart)
        {
            if (!_uniqueOpParts.Contains(opPart))
            {
                opPart.Eval(_context);
                _uniqueOpParts.Add(opPart);

                if (_uniqueOpParts.Count % 100 == 0)
                {
                    float progress = Math.Min((float)_uniqueOpParts.Count / _totalNumOpParts, 1.0f);
                    _progressVisualizer.Update(0.3f + 0.7f * progress);
                }
            }
        }
        void PickFileButton_Click(object sender, RoutedEventArgs e)
        {
            if (IsConnected)
            {
                return;
            }

            var defaultPath = ".\\assets";
            var tmpContext  = new OperatorPartContext();
            var startPath   = ValueHolder.Eval(tmpContext).Text;
            var dialogTitle = "Select file";

            var pickedFilePath = UIHelper.PickFileWithDialog(defaultPath, startPath, dialogTitle);

            if (pickedFilePath != "")
            {
                if (_updateValueCommand == null)
                {
                    XTextEdit_EditingStarted();
                }
                XTextEdit.XTextEdit.Text = pickedFilePath;
                XTextEdit_EditingCompleted();
            }
        }
Example #4
0
        private void UpdateGUI()
        {
            float newValue = 0;

            if (IsAnimated)
            {
                newValue = (float)_animationCurve.GetSampledValue((double)App.Current.Model.GlobalTime);
            }
            else if (IsConnected)
            {
                newValue = ValueHolder.Eval(new Core.OperatorPartContext()).Value;
            }
            else
            {
                var func = ValueHolder.Func as Utilities.ValueFunction;
                if (func == null)
                {
                    Logger.Error("FloatParameterControl has invalid value func");
                    return;
                }
                var floatValue = func.Value as Float;
                if (floatValue != null)
                {
                    newValue = floatValue.Val;
                }
            }

            UpdateDropdownSelection(newValue);

            var color = Brushes.White;

            if (IsAnimated)
            {
                color = Brushes.Orange;
            }
            else if (ValueHolder.Connections.Count > 0)
            {
                color = Brushes.DodgerBlue;
            }
            else if (ValueHolder.IsDefaultFuncSet)
            {
                color         = Brushes.White.Clone();
                color.Opacity = 0.3;
            }
            XComboBox.Foreground = color;
        }
Example #5
0
        private List <ICommand> SetupSingleAnimation(OperatorPart opPart, double keyframeTime)
        {
            var context = new OperatorPartContext()
            {
                Time = (float)keyframeTime
            };
            float currentValue = opPart.Eval(context).Value;

            // this command is needed to restore the original value correctly when undoing this, for doing it it's redundant
            var setValueCommand = new SetFloatValueCommand(opPart, currentValue);

            var compOp            = opPart.Parent.Parent;
            var addCurveOpCommand = new AddOperatorCommand(compOp, CurveID, 100, 100, 100, false);
            var curveOpInstanceId = addCurveOpCommand.AddedInstanceID;
            var addTimeOpCommand  = new AddOperatorCommand(compOp, CurrentTimeID, 100, 100, 100, false);

            var curveMetaOp = MetaManager.Instance.GetMetaOperator(CurveID);
            var timeMetaOp  = MetaManager.Instance.GetMetaOperator(CurrentTimeID);

            var timeToCurve = new MetaConnection(addTimeOpCommand.AddedInstanceID, timeMetaOp.Outputs[0].ID,
                                                 addCurveOpCommand.AddedInstanceID, curveMetaOp.Inputs[0].ID);
            var connectionTimeToCurveCommand = new InsertConnectionCommand(compOp.Definition, timeToCurve, 0);

            var curveToCurrent = new MetaConnection(addCurveOpCommand.AddedInstanceID, curveMetaOp.Outputs[0].ID,
                                                    opPart.Parent.ID, opPart.ID);
            var connectionCurveToCurrentCommand = new InsertConnectionCommand(compOp.Definition, curveToCurrent, 0);

            var addKeyframeCommand = new AddOrUpdateKeyframeCommand(keyframeTime, currentValue, compOp, curveOpInstanceId, curveMetaOp.Inputs[0].ID);

            return(new List <ICommand>()
            {
                setValueCommand,
                addCurveOpCommand,
                addTimeOpCommand,
                connectionTimeToCurveCommand,
                connectionCurveToCurrentCommand,
                addKeyframeCommand
            });
        }
Example #6
0
 public Vector3 EvaluateOrDefault(OperatorPartContext context, Vector3 fallBack)
 {
     return(Valid ? new Vector3(X.Eval(context).Value, Y.Eval(context).Value, Z.Eval(context).Value)
                  : fallBack);
 }
Example #7
0
        public TextParameterValue(OperatorPart valueHolder)
        {
            InitializeComponent();
            ValueHolder = valueHolder;

            ValueHolder.ChangedEvent += ValueHolder_ChangedEvent;

            var context = new OperatorPartContext();

            MouseUp += HandleMouseUp;

            // Insert Path Picker button
            if (valueHolder.Name.EndsWith("Path"))
            {
                var pickFileButton = new Button();
                pickFileButton.Focusable = true;
                pickFileButton.Content   = "...";
                XGrid.Children.Add(pickFileButton);
                Grid.SetColumn(pickFileButton, 0);

                pickFileButton.Click += new RoutedEventHandler(PickFileButton_Click);
            }
            else
            {
                XFirstColumDefinition.Width = new GridLength(0);
            }


            XTextEdit = new TextButtonEdit();
            XGrid.Children.Add(XTextEdit);
            Grid.SetColumn(XTextEdit, 1);
            if (valueHolder.Name.EndsWith("Code"))
            {
                XTextEdit.Text = "Code stuff";
            }
            else
            {
                XTextEdit.Text = valueHolder.Eval(context).Text;
                XTextEdit.XTextEdit.TextChanged += TextChangedHandler;
                XTextEdit.EditingStartedEvent   += XTextEdit_EditingStarted;
                XTextEdit.EditingCompletedEvent += XTextEdit_EditingCompleted;
            }

            if (valueHolder.Name.EndsWith("Text"))
            {
                XTextEdit.EnableLineBreaks();
            }



            var parent     = valueHolder.Parent;
            var parentMeta = parent.Definition;
            int index      = parent.Inputs.IndexOf(valueHolder);

            if (index >= 0)
            {
                var metaInput = parentMeta.Inputs[index];
                var valueType = metaInput.DefaultValue as Value <string>;
                if (valueType != null)
                {
                    string defaultValue = valueType.Val;
                    XTextEdit.Default = defaultValue;
                }
            }
        }