예제 #1
0
        public void Invalidate(ProcessingNode node)
        {
            int index = m_ProcessingNodes.IndexOf(node);

            if (index != -1)
            {
                m_ProcessingNodes[index].Invalidate();
            }
        }
예제 #2
0
        public ProcessingNode GetNextProcessor(ProcessingNode node)
        {
            int index = m_ProcessingNodes.IndexOf(node);

            if (index < m_ProcessingNodes.Count - 1)
            {
                return(m_ProcessingNodes[index + 1]);
            }
            return(null);
        }
예제 #3
0
        public ProcessingFrameSequence GetInputSequence(ProcessingNode processor)
        {
            int index = m_ProcessingNodes.IndexOf(processor);

            if (index > 0)
            {
                return(m_ProcessingNodes[index - 1].OutputSequence);
            }
            else
            {
                return(m_InputSequence);
            }
        }
예제 #4
0
        public void Invalidate()
        {
            UpdateSequenceLength();
            SetOutputSize(GetOutputWidth(), GetOutputHeight());
            m_OutputSequence.InvalidateAll();

            ProcessingNode next = m_ProcessingNodeStack.GetNextProcessor(this);

            if (next != null)
            {
                next.Invalidate();
            }
        }
        /// <summary>
        /// Restores the visibility and lock of processors (on load or after an undo)
        /// </summary>
        public void RestoreProcessorView()
        {
            if (m_CurrentAsset.inheritSettingsReference != null && !m_IgnoreInheritSettings)
            {
                if (m_ProcessingNodeStack.nodes.Count > 0)
                {
                    if (m_CurrentAsset.editSettings.selectedProcessor > 0)
                    {
                        m_CurrentProcessingNode           = m_ProcessingNodeStack.nodes[m_CurrentAsset.editSettings.selectedProcessor];
                        m_ProcessorsReorderableList.index = m_CurrentAsset.editSettings.selectedProcessor;
                    }
                }
            }
            else
            {
                // index Checks
                m_CurrentAsset.editSettings.lockedProcessor   = Mathf.Clamp(m_CurrentAsset.editSettings.lockedProcessor, -1, m_ProcessingNodeStack.nodes.Count - 1);
                m_CurrentAsset.editSettings.selectedProcessor = Mathf.Clamp(m_CurrentAsset.editSettings.selectedProcessor, -1, m_ProcessingNodeStack.nodes.Count - 1);

                // Locked processor
                if (m_CurrentAsset.editSettings.lockedProcessor != -1)
                {
                    m_ProcessorsReorderableList.index = m_CurrentAsset.editSettings.lockedProcessor;
                    m_LockedPreviewProcessor          = m_ProcessingNodeStack.nodes[m_CurrentAsset.editSettings.lockedProcessor];
                    m_CurrentProcessingNode           = m_ProcessingNodeStack.nodes[m_CurrentAsset.editSettings.lockedProcessor];
                }
                else
                {
                    m_LockedPreviewProcessor = null;
                }

                // Selected Processor
                if (m_CurrentAsset.editSettings.selectedProcessor != -1)
                {
                    m_ProcessorsReorderableList.index = m_CurrentAsset.editSettings.selectedProcessor;

                    if (m_CurrentAsset.editSettings.lockedProcessor != -1)
                    {
                        m_CurrentProcessingNode = m_ProcessingNodeStack.nodes[m_CurrentAsset.editSettings.lockedProcessor];
                    }
                    else
                    {
                        m_CurrentProcessingNode = m_ProcessingNodeStack.nodes[m_CurrentAsset.editSettings.selectedProcessor];
                    }
                }
            }

            m_ProcessingNodeStack.InvalidateAll();
            RefreshCanvas();
        }
예제 #6
0
        public void AddProcessor(ProcessingNode node, ImageSequence asset)
        {
            AddProcessorInfoObjectToAsset(asset, node.ProcessorInfo);
            asset.processorInfos.Add(node.ProcessorInfo);

            ProcessorBase settings = node.GetSettingsAbstract();

            if (settings != null)
            {
                AddSettingsObjectToAsset(asset, settings);
                node.ProcessorInfo.Settings = settings;
            }
            m_ProcessingNodes.Add(node);

            EditorUtility.SetDirty(asset);
        }
예제 #7
0
        public void SetCurrentFrameProcessor(ProcessingNode node, bool wantLock)
        {
            if (wantLock)
            {
                m_LockedPreviewProcessor = node;
                if (node != null)
                {
                    Undo.RecordObject(m_CurrentAsset, "Lock Processor");
                    m_CurrentProcessingNode = node;
                    m_CurrentAsset.editSettings.lockedProcessor = m_ProcessingNodeStack.nodes.IndexOf(node);
                }
                else
                {
                    Undo.RecordObject(m_CurrentAsset, "Unlock Processor");
                    if (m_ProcessorsReorderableList.index != -1)
                    {
                        m_CurrentProcessingNode = m_ProcessingNodeStack.nodes[Mathf.Min(m_ProcessorsReorderableList.index, m_ProcessingNodeStack.nodes.Count - 1)];
                    }
                    m_CurrentAsset.editSettings.lockedProcessor = -1;
                }
            }
            else
            {
                bool needChange = (m_CurrentProcessingNode != node);

                if (needChange)
                {
                    Undo.RecordObject(m_CurrentAsset, "Select Processor");
                }

                if (m_LockedPreviewProcessor == null)
                {
                    m_CurrentProcessingNode = node;
                }
                else
                {
                    m_CurrentProcessingNode = m_LockedPreviewProcessor;
                }
            }

            m_CurrentAsset.editSettings.selectedProcessor = m_ProcessingNodeStack.nodes.IndexOf(node);
            RefreshCanvas();
            EditorUtility.SetDirty(m_CurrentAsset);
        }
        public void AddProcessor(ProcessorElement element)
        {
            var settingType = element.m_ProcessorSettingType;

            // Add Element
            Undo.RecordObject(m_CurrentAsset, "Add Processor");

            ProcessingNode processor = null;

            // Reflection Stuff here
            ProcessorAttribute attribute = m_ProcessingNodeStack.settingsDefinitions[settingType];

            var info = ProcessorInfo.CreateDefault(attribute.name, true, settingType);

            processor = (ProcessingNode)Activator.CreateInstance(typeof(ProcessingNode), m_ProcessingNodeStack, info);

            if (processor != null)
            {
                m_ProcessingNodeStack.AddProcessor(processor, m_CurrentAsset);
                m_ProcessingNodeStack.InvalidateAll();
            }
        }
        public void LoadAsset(ImageSequence asset)
        {
            m_CurrentAsset = asset;

            m_InputFramesReorderableList = null;
            m_ProcessorsReorderableList  = null;
            m_LockedPreviewProcessor     = null;
            m_CurrentProcessingNode      = null;

            // Free resources if any
            if (m_ProcessingNodeStack != null)
            {
                m_ProcessingNodeStack.Dispose();
            }

            InitializeGUI();

            if (m_CurrentAsset != null)
            {
                m_ProcessingNodeStack = new ProcessingNodeStack(new ProcessingFrameSequence(null), this);

                m_CurrentAssetSerializedObject = new SerializedObject(m_CurrentAsset);

                VFXToolboxGUIUtility.DisplayProgressBar("Image Sequencer", "Loading asset....", 0.0f);

                m_LockedPreviewProcessor = null;

                VFXToolboxGUIUtility.DisplayProgressBar("Image Sequencer", "Loading Frames", 0.333333f);

                m_ProcessingNodeStack.LoadFramesFromAsset(m_CurrentAsset);
                UpdateInputTexturesHash();

                m_InputFramesReorderableList = new ReorderableList(m_ProcessingNodeStack.inputSequence.frames, typeof(Texture2D), true, false, true, true);
                m_InputFramesReorderableList.onAddCallback       = AddInputFrame;
                m_InputFramesReorderableList.onRemoveCallback    = RemoveInputFrame;
                m_InputFramesReorderableList.onReorderCallback   = ReorderInputFrame;
                m_InputFramesReorderableList.drawElementCallback = DrawInputFrameRListElement;
                m_InputFramesReorderableList.onSelectCallback    = SelectInputFrameRListElement;

                VFXToolboxGUIUtility.DisplayProgressBar("Image Sequencer", "Loading Processors", 0.66666f);

                ImageSequence inheritedSettingReference = m_CurrentAsset;

                // Loading other settings if inheriting settings
                if (m_CurrentAsset.inheritSettingsReference != null)
                {
                    var dependencyList = new List <ImageSequence>();
                    var referenceAsset = FindSettingsReference(m_CurrentAsset.inheritSettingsReference, ref dependencyList);
                    if (referenceAsset == null)
                    {
                        Debug.LogWarning("Dependency Loop detected, ignoring using external settings");
                        m_IgnoreInheritSettings = true;
                    }
                    else
                    {
                        inheritedSettingReference = referenceAsset;
                        m_IgnoreInheritSettings   = false;
                    }
                }

                m_ProcessingNodeStack.LoadProcessorsFromAsset(inheritedSettingReference);
                m_ProcessorDataProvider = new ProcessorDataProvider(m_ProcessingNodeStack, m_CurrentAsset);

                // Construct the RList
                if (m_CurrentAsset.inheritSettingsReference == null)
                {
#if UNITY_2020_1_OR_NEWER
                    m_ProcessorsReorderableList = new ReorderableList(m_CurrentAsset.processorInfos, typeof(ProcessorInfo), true, false, true, true);
#else
                    m_ProcessorsReorderableList = new ReorderableList(m_CurrentAssetSerializedObject, m_CurrentAssetSerializedObject.FindProperty("processorInfos"), true, false, true, true);
#endif
                    m_ProcessorsReorderableList.onAddCallback       = ShowAddProcessorMenu;
                    m_ProcessorsReorderableList.onRemoveCallback    = MenuRemoveProcessor;
                    m_ProcessorsReorderableList.onReorderCallback   = ReorderProcessor;
                    m_ProcessorsReorderableList.onSelectCallback    = MenuSelectProcessor;
                    m_ProcessorsReorderableList.drawElementCallback = DrawRListProcessorElement;
                    m_SettingsReferenceSerializedObject             = null;
                }
                else
                {
                    m_SettingsReferenceSerializedObject             = new SerializedObject(inheritedSettingReference);
                    m_ProcessorsReorderableList                     = new ReorderableList(m_SettingsReferenceSerializedObject, m_SettingsReferenceSerializedObject.FindProperty("processorInfos"), false, false, false, false);
                    m_ProcessorsReorderableList.drawElementCallback = DrawRListPreviewProcessorElement;
                    m_ProcessorsReorderableList.onSelectCallback    = MenuSelectProcessor;
                }

                m_PreviewCanvas.sequence = m_ProcessingNodeStack.inputSequence;
                if (m_PreviewCanvas.sequence.length > 0)
                {
                    m_PreviewCanvas.currentFrameIndex = 0;
                }
                else
                {
                    m_PreviewCanvas.currentFrameIndex = -1;
                }

                VFXToolboxGUIUtility.DisplayProgressBar("Image Sequencer", "Finalizing...", 1.0f);

                m_ProcessingNodeStack.InvalidateAll();
                RestoreProcessorView();

                EditorUtility.ClearProgressBar();
            }
        }
예제 #10
0
        private void DrawExportPanelContent()
        {
            int length = m_ProcessingNodeStack.outputSequence.length;

            if (length > 0)
            {
                m_CurrentAssetSerializedObject.Update();
                EditorGUI.BeginChangeCheck();

                ImageSequence.ExportSettings prevState = m_CurrentAsset.exportSettings;

                using (new VFXToolboxGUIUtility.HeaderSectionScope("File Export Options"))
                {
                    ImageSequence.ExportMode prevMode = m_CurrentAsset.exportSettings.exportMode;

                    m_CurrentAsset.exportSettings.exportMode = (ImageSequence.ExportMode)EditorGUILayout.Popup(VFXToolboxGUIUtility.Get("Export Format"), (int)m_CurrentAsset.exportSettings.exportMode, GetExportModeFriendlyNames());

                    if (prevMode != m_CurrentAsset.exportSettings.exportMode)
                    {
                        m_CurrentAsset.exportSettings.fileName = "";
                    }

                    switch (m_CurrentAsset.exportSettings.exportMode)
                    {
                    case ImageSequence.ExportMode.EXR:
                        m_CurrentAsset.exportSettings.highDynamicRange = true;
                        m_CurrentAsset.exportSettings.sRGB             = false;
                        break;

                    case ImageSequence.ExportMode.PNG:
                    case ImageSequence.ExportMode.Targa:
                        m_CurrentAsset.exportSettings.highDynamicRange = false;
                        break;
                    }


                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.TextField(VFXToolboxGUIUtility.Get("File Name|File name or pattern of the export sequence, using # characters will add frame number to the file name, use multiple ### to ensure leading zeroes."), m_CurrentAsset.exportSettings.fileName);
                    EditorGUI.EndDisabledGroup();

                    Rect r = GUILayoutUtility.GetLastRect();
                    r.width += EditorGUIUtility.fieldWidth;

                    if (Event.current.rawType == EventType.MouseDown && r.Contains(Event.current.mousePosition))
                    {
                        PingOutputTexture(m_CurrentAsset.exportSettings.fileName);
                    }

                    if (!m_CurrentAsset.exportSettings.highDynamicRange)
                    {
                        m_CurrentAsset.exportSettings.sRGB = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("sRGB (Color Data)|Whether the texture contains color (or not), HDR Data is always non sRGB."), m_CurrentAsset.exportSettings.sRGB);
                    }

                    EditorGUI.BeginDisabledGroup(m_CurrentAsset.exportSettings.compress && m_CurrentAsset.exportSettings.highDynamicRange);
                    m_CurrentAsset.exportSettings.exportAlpha = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Export Alpha|Whether to export the alpha channel"), m_CurrentAsset.exportSettings.exportAlpha);
                    EditorGUI.EndDisabledGroup();

                    m_CurrentAsset.exportSettings.exportSeparateAlpha = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Separate Alpha|Export the alpha channel as a separate TGA Grayscale file with a \"_alpha\" suffix."), m_CurrentAsset.exportSettings.exportSeparateAlpha);
                }

                using (new VFXToolboxGUIUtility.HeaderSectionScope("Texture Import Options"))
                {
                    m_CurrentAsset.exportSettings.outputShape = (ImageSequence.OutputMode)EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Output Shape|Selects whether export as simple 2D Texture, flipbook as 2D texture, or full sequence as 2D texture"), m_CurrentAsset.exportSettings.outputShape);
                    if (m_CurrentAsset.exportSettings.outputShape == ImageSequence.OutputMode.Texture2DArray)
                    {
                        ProcessingNode n = m_ProcessingNodeStack.nodes[m_ProcessingNodeStack.nodes.Count - 1];
                        if (((float)n.OutputWidth / n.NumU) % 1.0f > 0.0f || ((float)n.OutputHeight / n.NumV) % 1.0f > 0.0f)
                        {
                            EditorGUILayout.HelpBox("Row and Column Counts are not exact multiples of the resolution, some padding will occur in the export", MessageType.Warning);
                        }
                        else if ((!Mathf.IsPowerOfTwo(n.OutputWidth / n.NumU) || !Mathf.IsPowerOfTwo(n.OutputHeight / n.NumV)) && m_CurrentAsset.exportSettings.compress && m_CurrentAsset.exportSettings.generateMipMaps)
                        {
                            EditorGUILayout.HelpBox("Texture 2D Arrays with mip maps cannot be compressed if U and V dimensions are not power of two", MessageType.Warning);
                        }
                    }

                    m_CurrentAsset.exportSettings.dataContents = (ImageSequence.DataContents)EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Import as|Sets the importer mode"), m_CurrentAsset.exportSettings.dataContents);
                    if (m_CurrentAsset.exportSettings.dataContents == ImageSequence.DataContents.Sprite)
                    {
                        ProcessingNode n = m_ProcessingNodeStack.nodes[m_ProcessingNodeStack.nodes.Count - 1];
                        if (((float)n.OutputWidth % n.NumU) != 0 || ((float)n.OutputHeight % n.NumV) != 0)
                        {
                            EditorGUILayout.HelpBox("Warning : texture size is not a multiplier of rows (" + n.NumU + ") and columns (" + n.NumV + ") count, this will lead to incorrect rendering of the sprite animation", MessageType.Warning);
                        }
                    }

                    switch (m_CurrentAsset.exportSettings.dataContents)
                    {
                    case ImageSequence.DataContents.NormalMapFromGrayscale:
                    case ImageSequence.DataContents.NormalMap:
                        m_CurrentAsset.exportSettings.sRGB        = false;
                        m_CurrentAsset.exportSettings.exportAlpha = false;
                        break;

                    default: break;
                    }

                    if (!m_CurrentAsset.exportSettings.highDynamicRange)
                    {
                        m_CurrentAsset.exportSettings.sRGB = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("sRGB (Color Data)|Whether the texture contains color (or not), HDR Data is always non sRGB."), m_CurrentAsset.exportSettings.sRGB);
                    }

                    m_CurrentAsset.exportSettings.compress        = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Compress|Whether to apply texture compression (HDR Compressed Data does not support alpha channel)"), m_CurrentAsset.exportSettings.compress);
                    m_CurrentAsset.exportSettings.generateMipMaps = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Generate MipMaps|Whether generate mipmaps."), m_CurrentAsset.exportSettings.generateMipMaps);
                    m_CurrentAsset.exportSettings.wrapMode        = (TextureWrapMode)EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Wrap Mode|Texture Wrap mode"), m_CurrentAsset.exportSettings.wrapMode);
                    m_CurrentAsset.exportSettings.filterMode      = (FilterMode)EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Filter Mode|Texture Filter mode"), m_CurrentAsset.exportSettings.filterMode);

                    if (m_CurrentAsset.exportSettings.compress && m_CurrentAsset.exportSettings.highDynamicRange)
                    {
                        m_CurrentAsset.exportSettings.exportAlpha = false;
                    }
                }

                if (GUILayout.Button("Export as New...", GUILayout.Height(24)))
                {
                    string fileName = "";

                    fileName = ExportToFile(false);

                    if (fileName != "")
                    {
                        m_CurrentAsset.exportSettings.fileName   = fileName;
                        m_CurrentAsset.exportSettings.frameCount = (ushort)m_ProcessingNodeStack.outputSequence.frames.Count;
                    }
                }
                // Export Again
                if (m_CurrentAsset.exportSettings.fileName != null &&
                    ((m_CurrentAsset.exportSettings.fileName.EndsWith(".tga") && m_CurrentAsset.exportSettings.exportMode == ImageSequence.ExportMode.Targa) ||
                     (m_CurrentAsset.exportSettings.fileName.EndsWith(".exr") && m_CurrentAsset.exportSettings.exportMode == ImageSequence.ExportMode.EXR) ||
                     (m_CurrentAsset.exportSettings.fileName.EndsWith(".png") && m_CurrentAsset.exportSettings.exportMode == ImageSequence.ExportMode.PNG)
                    ))
                {
                    if (GUILayout.Button("Update Exported Assets", GUILayout.Height(24)))
                    {
                        UpdateExportedAssets();
                    }
                }

                if (m_CurrentAsset.exportSettings.dataContents == ImageSequence.DataContents.NormalMap)
                {
                    EditorGUILayout.HelpBox("The selected import mode assumes that the frame data is a normal map. To generate a normal map from grayscale, use Normal Map From Grayscale instead.", MessageType.Info);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    ImageSequence.ExportSettings curState = m_CurrentAsset.exportSettings;
                    m_CurrentAsset.exportSettings = prevState;
                    Undo.RecordObject(m_CurrentAsset, "Update Export Settings");
                    m_CurrentAsset.exportSettings = curState;
                    m_CurrentAssetSerializedObject.ApplyModifiedProperties();
                    EditorUtility.SetDirty(m_CurrentAsset);

                    AssetDatabase.Refresh();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("You do not have any frames to export.", MessageType.Warning);
            }
        }
예제 #11
0
 public ProcessingFrame(ProcessingNode node)
 {
     dirty            = true;
     m_ProcessingNode = node;
     ResetTexture();
 }
예제 #12
0
 public ProcessingFrame(Texture texture)
 {
     m_Texture        = texture;
     dirty            = false;
     m_ProcessingNode = null;
 }
예제 #13
0
 internal void AttachTo(ProcessingNode processor)
 {
     this.processingNode = processor;
 }
 public ProcessingFrameSequence(ProcessingNode node)
 {
     m_Frames         = new List <ProcessingFrame>();
     m_ProcessingNode = node;
 }