Esempio n. 1
0
        private void LoadThumbnail(OperatorPreset preset, bool useCache = true)
        {
            var imagePath = preset.BuildImagePath();

            if (useCache && _cache.ContainsKey(imagePath))
            {
                XImage.Source = _cache[imagePath];
                return;
            }

            if (File.Exists(imagePath))
            {
                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(imagePath, UriKind.RelativeOrAbsolute);
                //bitmap.CacheOption = BitmapCacheOption.OnLoad;
                //bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                bitmap.EndInit();
                bitmap.Freeze();
                XImage.Source     = bitmap;
                _cache[imagePath] = bitmap;
            }
            else
            {
                XImage.Source = null;
                Logger.Info("Failed to load thumbnail {0}", imagePath);
                _cache[imagePath] = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="preset"></param>
        /// <returns>false if preview was refused</returns>
        public bool PreviewPreset(OperatorPreset preset)
        {
            App.Current.MainWindow.CompositionView.XTimeView.XAnimationCurveEditor.DisableCurveUpdatesOnModifiedEvent = true;

            if (_blending)
            {
                return(false);
            }

            var entries = new List <SetValueGroupCommand.Entry>();

            Operator op = App.Current.MainWindow.XParameterView.ShownOperator;

            if (op != null && op.Definition.ID == preset.MetaOperatorID)
            {
                _tempOperatorPresetBeforePreview = CreatePresetFromOperator(op);

                foreach (var input in op.Inputs)
                {
                    var metaInput = input.Parent.GetMetaInput(input);
                    if (preset.ValuesByParameterID.ContainsKey(metaInput.ID))
                    {
                        entries.Add(new SetValueGroupCommand.Entry {
                            OpPart = input, Value = new Float(preset.ValuesByParameterID[metaInput.ID])
                        });
                    }
                }
                App.Current.UpdateRequiredAfterUserInteraction = true;
            }
            _setValueGroupCommand = new SetValueGroupCommand(entries, App.Current.Model.GlobalTime);
            _setValueGroupCommand.Do();
            SelectActivePreset();
            return(true);
        }
Esempio n. 3
0
        public void BlendPreset(OperatorPreset preset, float factor)
        {
            Operator op = App.Current.MainWindow.XParameterView.ShownOperator;

            if (op == null || op.Definition.ID != preset.MetaOperatorID || _setValueGroupCommand == null)
            {
                return;
            }

            var index = 0;

            foreach (var input in op.Inputs)
            {
                var metaInput = input.Parent.GetMetaInput(input);
                if (preset.ValuesByParameterID.ContainsKey(metaInput.ID) && _tempOperatorPresetBeforePreview != null)
                {
                    float presetValue   = preset.ValuesByParameterID[metaInput.ID];
                    float opValue       = _tempOperatorPresetBeforePreview.ValuesByParameterID[metaInput.ID];
                    var   newFloatValue = opValue + factor * (presetValue - opValue);
                    _setValueGroupCommand.UpdateFloatValueAtIndex(index, newFloatValue);
                    index++;
                }
            }

            _setValueGroupCommand.Do();
            App.Current.UpdateRequiredAfterUserInteraction = true;
        }
Esempio n. 4
0
 private void AddPreset(OperatorPreset newPreset, int idx)
 {
     if (!_operatorPresetsByMetaOpID.ContainsKey(newPreset.MetaOperatorID))
     {
         _operatorPresetsByMetaOpID[newPreset.MetaOperatorID] = new List <OperatorPreset>();
     }
     _operatorPresetsByMetaOpID[newPreset.MetaOperatorID].Insert(idx, newPreset);
 }
Esempio n. 5
0
        public void CompleteBlendPreset(OperatorPreset preset)
        {
            App.Current.MainWindow.CompositionView.XTimeView.XAnimationCurveEditor.DisableCurveUpdatesOnModifiedEvent = false;
            _blending = false;
            SelectActivePreset();
            if (_setValueGroupCommand == null)
            {
                return;
            }

            App.Current.UndoRedoStack.Add(_setValueGroupCommand);
            _tempOperatorPresetBeforePreview = null;
        }
Esempio n. 6
0
        public void RenderAndSaveThumbnail(OperatorPreset preset)
        {
            var op = App.Current.MainWindow.XParameterView.ShownOperator; // todo: remove access to parameter view!

            if (op == null || !op.Outputs.Any())
            {
                return;
            }

            var output = op.Outputs.First();

            if (LivePreviewEnabled)
            {
                if (App.Current.MainWindow.XRenderView.Operator != null && App.Current.MainWindow.XRenderView.Operator.Outputs.Any())
                {
                    output = App.Current.MainWindow.XRenderView.Operator.Outputs[0];
                }
            }

            var currentTime = App.Current.Model.GlobalTime;
            var filePath    = preset.BuildImagePath();
            var result      = Regex.Match(filePath, @"(.*)/(.*)\.png");

            if (result == null)
            {
                throw new Exception("Invalid filepath format for thumbnails:" + filePath);
            }

            var directory = result.Groups[1].Value;
            var filename  = result.Groups[2].Value;

            using (var sequenceCreator = new SequenceCreator())
            {
                sequenceCreator.Setup(output,
                                      height: THUMB_HEIGHT,
                                      width: THUMB_WIDTH,
                                      startTime: currentTime,
                                      endTime: currentTime,
                                      frameRate: 10000,
                                      fileExtension: "png",
                                      skipExistingFiles: false,
                                      directory: directory,
                                      filenameFormat: filename);
                sequenceCreator.RenderFrame();
            }
        }
Esempio n. 7
0
        private OperatorPreset CreatePresetFromOperator(Operator op)
        {
            var newPreset = new OperatorPreset {
                MetaOperatorID = op.Definition.ID
            };

            foreach (var input in op.Inputs)
            {
                if (input.Type == FunctionType.Float)
                {
                    var metaInput    = input.Parent.GetMetaInput(input);
                    var currentValue = OperatorPartUtilities.GetInputFloatValue(input);
                    newPreset.ValuesByParameterID[metaInput.ID] = currentValue;
                }
            }
            return(newPreset);
        }
Esempio n. 8
0
        public void DeletePreset(OperatorPreset preset)
        {
            Operator op = App.Current.MainWindow.XParameterView.ShownOperator; // todo: remove access to parameter view

            if (op != null && op.Definition.ID == preset.MetaOperatorID)
            {
                _blending = false;
                RestorePreviewPreset();

                if (_operatorPresetsByMetaOpID.ContainsKey(op.Definition.ID))
                {
                    _operatorPresetsByMetaOpID[op.Definition.ID].Remove(preset);
                    FilterPresetsForSelectedOperator();
                    SavePresets();
                    App.Current.UpdateRequiredAfterUserInteraction = true;
                }
            }
        }
Esempio n. 9
0
        // Called after click
        public void ApplyPreset(OperatorPreset preset)
        {
            App.Current.MainWindow.CompositionView.XTimeView.XAnimationCurveEditor.DisableCurveUpdatesOnModifiedEvent = true;

            _blending = false;
            Operator op = App.Current.MainWindow.XParameterView.ShownOperator;

            if (op == null || _setValueGroupCommand == null || op.Definition.ID != preset.MetaOperatorID)
            {
                return;
            }

            App.Current.UndoRedoStack.Add(_setValueGroupCommand);
            _tempOperatorPresetBeforePreview = null;
            _setValueGroupCommand            = null;
            App.Current.UpdateRequiredAfterUserInteraction = true;
            SelectActivePreset();
        }
Esempio n. 10
0
        public void CopyPresetsOfOpToAnother(MetaOperator source, MetaOperator target)
        {
            int idx = 0;

            if (_operatorPresetsByMetaOpID.ContainsKey(source.ID))
            {
                foreach (var srcPreset in _operatorPresetsByMetaOpID[source.ID])
                {
                    var newPreset = new OperatorPreset {
                        MetaOperatorID = target.ID
                    };
                    foreach (var srcEntry in srcPreset.ValuesByParameterID)
                    {
                        try
                        {
                            var srcInputIdx = (from input in source.Inputs
                                               where input.ID == srcEntry.Key
                                               select source.Inputs.IndexOf(input)).Single();
                            newPreset.ValuesByParameterID[target.Inputs[srcInputIdx].ID] = srcEntry.Value;
                        }
                        catch (Exception)
                        {
                            Logger.Warn("Could not copy preset parameter. This can happen when the preset contains obsolete parameters.");
                        }
                    }
                    if (newPreset.ValuesByParameterID.Count > 0)
                    {
                        AddPreset(newPreset, idx++);
                    }
                    else
                    {
                        Logger.Debug("Skipped a preset without any matching parameters");
                    }
                }
            }
            FilterPresetsForSelectedOperator();
            SavePresets();
        }