예제 #1
0
//----------------------------------------------------------------------------------------------------------------------

        /// <inheritdoc/>
        public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
        {
            base.DrawBackground(clip, region);

            Rect rect = region.position;

            if (rect.width <= SISEditorConstants.MIN_PREVIEW_REGION_WIDTH)
            {
                return;
            }

            ImageFolderPlayableAsset <T> curAsset = clip.asset as ImageFolderPlayableAsset <T>;

            if (null == curAsset)
            {
                return;
            }

            DrawBackgroundTexture(rect, curAsset.GetTimelineBGColor());

            int numImages = curAsset.GetNumImages();

            if (numImages <= 0)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                PreviewClipInfo clipInfo = new PreviewClipInfo()
                {
                    Duration              = clip.duration,
                    TimeScale             = clip.timeScale,
                    ClipIn                = clip.clipIn,
                    FramePerSecond        = clip.GetParentTrack().timelineAsset.editorSettings.GetFPS(),
                    ImageDimensionRatio   = curAsset.GetOrUpdateDimensionRatio(),
                    VisibleLocalStartTime = region.startTime,
                    VisibleLocalEndTime   = region.endTime,
                    VisibleRect           = rect,
                };

                PreviewUtility.EnumeratePreviewImages(ref clipInfo, (PreviewDrawInfo drawInfo) => {
                    DrawPreviewImageV(ref drawInfo, clip, curAsset);
                });

                //For hiding frame marker automatically
                PlayableFrameClipData clipData = curAsset.GetBoundClipData();
                if (null != clipData)
                {
                    clipData.UpdateTimelineWidthPerFrame(rect.width, region.endTime - region.startTime,
                                                         clipInfo.FramePerSecond, clipInfo.TimeScale);
                }
            }
        }
//----------------------------------------------------------------------------------------------------------------------    
    public override void DrawOverlay(IMarker m, MarkerUIStates uiState, MarkerOverlayRegion region)
    {
        FrameMarker marker = m as FrameMarker;
        if (null == marker)
            return;

        SISPlayableFrame playableFrame = marker.GetOwner();
        
        //Check invalid PlayableFrame/ClipData. Perhaps because of unsupported Duplicate operation ?
        PlayableFrameClipData clipData = playableFrame?.GetOwner();
        if (clipData == null)
            return;
        
        PlayableFramePropertyID inspectedPropertyID = clipData.GetInspectedProperty();
        switch (inspectedPropertyID) {
            case PlayableFramePropertyID.USED: {
                
                if (playableFrame.IsLocked()) {
                    //At the moment, all locked frames are regarded as inactive 
                    if (playableFrame.IsUsed()) {
                        Graphics.DrawTexture(region.markerRegion, EditorTextures.GetInactiveCheckedTexture());
                    }
                    Rect lockRegion = region.markerRegion;
                    lockRegion.x -= 5;
                    lockRegion.y -= 8;
                    Graphics.DrawTexture(lockRegion, EditorTextures.GetLockTexture());                    
                } else {
                    if (playableFrame.IsUsed()) {
                        Graphics.DrawTexture(region.markerRegion, EditorTextures.GetCheckedTexture());
                    }
                    
                }
                break;
            }
            case PlayableFramePropertyID.LOCKED: {
                if (playableFrame.IsLocked()) {
                    Graphics.DrawTexture(region.markerRegion, EditorTextures.GetLockTexture());                    
                }
                break;
            }
            
        }
        
    }
        internal static void ToggleMarkerValueByContext(FrameMarker frameMarker)
        {
            SISPlayableFrame        playableFrame       = frameMarker.GetOwner();
            PlayableFrameClipData   clipData            = playableFrame.GetOwner();
            PlayableFramePropertyID inspectedPropertyID = clipData.GetInspectedProperty();

            switch (inspectedPropertyID)
            {
            case PlayableFramePropertyID.USED: {
                playableFrame.SetUsed(!playableFrame.IsUsed());
                break;
            }

            case PlayableFramePropertyID.LOCKED: {
                playableFrame.SetLocked(!playableFrame.IsLocked());
                break;
            }
            }
        }
//----------------------------------------------------------------------------------------------------------------------
        private static void SetMarkerValueByContext(FrameMarker frameMarker, bool value)
        {
            SISPlayableFrame        playableFrame       = frameMarker.GetOwner();
            PlayableFrameClipData   clipData            = playableFrame.GetOwner();
            PlayableFramePropertyID inspectedPropertyID = clipData.GetInspectedProperty();

            switch (inspectedPropertyID)
            {
            case PlayableFramePropertyID.USED: {
                playableFrame.SetUsed(value);
                break;
            }

            case PlayableFramePropertyID.LOCKED: {
                playableFrame.SetLocked(value);
                break;
            }
            }
        }
예제 #5
0
//----------------------------------------------------------------------------------------------------------------------


        private void DrawCaptureSelectedFramesGUI(TimelineClip timelineClip, PlayableFrameClipData clipData)
        {
            TrackAsset track = timelineClip.GetParentTrack();

            GUILayout.BeginHorizontal();
            bool markerVisibility = InspectorUtility.DrawFrameMarkersGUI(m_asset);

            GUILayout.FlexibleSpace();
            EditorGUI.BeginDisabledGroup(!markerVisibility);
            if (GUILayout.Button("Capture All", GUILayout.Width(80)))
            {
                Undo.RegisterCompleteObjectUndo(track, "Capturing all frames");
                clipData.SetAllPlayableFramesProperty(PlayableFramePropertyID.USED, true);
            }
            if (GUILayout.Button("Reset", GUILayout.Width(50)))
            {
                Undo.RegisterCompleteObjectUndo(track, "Capturing no frames");
                clipData.SetAllPlayableFramesProperty(PlayableFramePropertyID.USED, false);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
예제 #6
0
//----------------------------------------------------------------------------------------------------------------------


        private void DrawLockFramesGUI(TimelineClip timelineClip, PlayableFrameClipData clipData)
        {
            TrackAsset track = timelineClip.GetParentTrack();

            using (new EditorGUILayout.HorizontalScope()) {
                EditorGUILayout.PrefixLabel("Lock Frames");

                bool lockMode = GUILayout.Toggle(m_lockMode, EditorTextures.GetLockTexture(), "Button",
                                                 GUILayout.Height(20f), GUILayout.Width(30f));
                if (lockMode != m_lockMode) //lock state changed
                {
                    if (lockMode)
                    {
                        LockSISData(clipData);
                    }
                    else
                    {
                        UnlockSISData();
                    }
                }

                GUILayout.FlexibleSpace();
                EditorGUI.BeginDisabledGroup(!m_lockMode);
                if (GUILayout.Button("Lock All", GUILayout.Width(80)))
                {
                    Undo.RegisterCompleteObjectUndo(track, "Locking all frames");
                    clipData.SetAllPlayableFramesProperty(PlayableFramePropertyID.LOCKED, true);
                }
                if (GUILayout.Button("Reset", GUILayout.Width(50)))
                {
                    Undo.RegisterCompleteObjectUndo(track, "Locking no frames");
                    clipData.SetAllPlayableFramesProperty(PlayableFramePropertyID.LOCKED, false);
                }
                EditorGUI.EndDisabledGroup();
            }
        }
예제 #7
0
//----------------------------------------------------------------------------------------------------------------------

        static void LockSISData(PlayableFrameClipData clipData)
        {
            m_inspectedClipDataForLocking = clipData;
            m_inspectedClipDataForLocking.SetInspectedProperty(PlayableFramePropertyID.LOCKED);
            m_lockMode = true;
        }
예제 #8
0
//----------------------------------------------------------------------------------------------------------------------
        internal static IEnumerator UpdateRenderCacheCoroutine(PlayableDirector director, RenderCachePlayableAsset renderCachePlayableAsset)
        {
            Assert.IsNotNull(director);
            Assert.IsNotNull(renderCachePlayableAsset);

            PlayableFrameClipData clipData = renderCachePlayableAsset.GetBoundClipData();

            if (null == clipData)
            {
                EditorUtility.DisplayDialog("Streaming Image Sequence",
                                            "RenderCachePlayableAsset is not ready",
                                            "Ok");
                yield break;
            }

            TrackAsset         track          = renderCachePlayableAsset.GetBoundClipData().GetOwner().GetParentTrack();
            BaseRenderCapturer renderCapturer = director.GetGenericBinding(track) as BaseRenderCapturer;

            if (null == renderCapturer)
            {
                EditorUtility.DisplayDialog("Streaming Image Sequence",
                                            "Please bind an appropriate RenderCapturer component to the track.",
                                            "Ok");
                yield break;
            }

            //Check output folder
            string outputFolder = renderCachePlayableAsset.GetFolder();

            if (string.IsNullOrEmpty(outputFolder) || !Directory.Exists(outputFolder))
            {
                EditorUtility.DisplayDialog("Streaming Image Sequence",
                                            "Invalid output folder",
                                            "Ok");
                yield break;
            }

            //Check if we can capture
            bool canCapture = renderCapturer.CanCaptureV();

            if (!canCapture)
            {
                EditorUtility.DisplayDialog("Streaming Image Sequence",
                                            renderCapturer.GetLastErrorMessage(),
                                            "Ok");
                yield break;
            }

            //begin capture
            IEnumerator beginCapture = renderCapturer.BeginCaptureV();

            while (beginCapture.MoveNext())
            {
                yield return(beginCapture.Current);
            }

            //Show progress in game view
            Texture capturerTex = renderCapturer.GetInternalTexture();
            RenderCachePlayableAssetEditorConfig editorConfig = renderCachePlayableAsset.GetEditorConfig();
            BaseTextureBlitter blitter         = CreateBlitter(capturerTex);
            Material           blitToScreenMat = renderCapturer.GetOrCreateBlitToScreenEditorMaterialV();

            if (!blitToScreenMat.IsNullRef())
            {
                blitToScreenMat.SetColor(m_bgColorProperty, editorConfig.GetUpdateBGColor());
                blitter.SetBlitMaterial(blitToScreenMat);
            }

            GameObject blitterGO = blitter.gameObject;



            TimelineClip timelineClip = clipData.GetOwner();
            double       timePerFrame = 1.0f / track.timelineAsset.editorSettings.GetFPS();

            //initial calculation of loop vars
            bool captureAllFrames = editorConfig.GetCaptureAllFrames();
            int  fileCounter      = 0;
            int  numFiles         = (int)Math.Ceiling(timelineClip.duration / timePerFrame) + 1;
            int  numDigits        = MathUtility.GetNumDigits(numFiles);

            if (!captureAllFrames)
            {
                fileCounter = editorConfig.GetCaptureStartFrame();
                numFiles    = (editorConfig.GetCaptureEndFrame() - fileCounter) + 1;
                if (numFiles <= 0)
                {
                    EditorUtility.DisplayDialog("Streaming Image Sequence", "Invalid Start/End Frame Settings", "Ok");
                    yield break;
                }
            }
            int captureStartFrame = fileCounter;

            string prefix = $"{timelineClip.displayName}_";
            List <WatchedFileInfo> imageFiles = new List <WatchedFileInfo>(numFiles);

            //Store old files that has the same pattern
            string[]         existingFiles = Directory.GetFiles(outputFolder, $"*.png");
            HashSet <string> filesToDelete = new HashSet <string>(existingFiles);

            RenderCacheOutputFormat outputFormat = renderCachePlayableAsset.GetOutputFormat();
            string outputExt = null;

            switch (outputFormat)
            {
            case RenderCacheOutputFormat.EXR: outputExt = "exr"; break;

            default:                          outputExt = "png"; break;;
            }

            bool cancelled = false;

            while (!cancelled)
            {
                //Always recalculate from start to avoid floating point errors
                double directorTime = timelineClip.start + (fileCounter * timePerFrame);
                if (directorTime > timelineClip.end)
                {
                    break;
                }

                if (!captureAllFrames && fileCounter > editorConfig.GetCaptureEndFrame())
                {
                    break;
                }

                string fileName       = $"{prefix}{fileCounter.ToString($"D{numDigits}")}.{outputExt}";
                string outputFilePath = Path.Combine(outputFolder, fileName);

                SISPlayableFrame playableFrame = clipData.GetPlayableFrame(fileCounter);
                bool             captureFrame  = (!clipData.AreFrameMarkersRequested() || //if markers are not requested, capture
                                                  !File.Exists(outputFilePath) || //if file doesn't exist, capture
                                                  (null != playableFrame && playableFrame.IsUsed() && !playableFrame.IsLocked())
                                                  );

                if (filesToDelete.Contains(outputFilePath))
                {
                    filesToDelete.Remove(outputFilePath);
                }


                if (captureFrame)
                {
                    SetDirectorTime(director, directorTime);

                    //Need at least two frames in order to wait for the TimelineWindow to be updated ?
                    yield return(null);

                    yield return(null);

                    yield return(null);

                    //Unload texture because it may be overwritten
                    StreamingImageSequencePlugin.UnloadImageAndNotify(outputFilePath);
                    renderCapturer.CaptureToFile(outputFilePath, outputFormat);
                }
                Assert.IsTrue(File.Exists(outputFilePath));
                FileInfo fileInfo = new FileInfo(outputFilePath);

                imageFiles.Add(new WatchedFileInfo(fileName, fileInfo.Length));

                ++fileCounter;
                cancelled = EditorUtility.DisplayCancelableProgressBar(
                    "StreamingImageSequence", "Caching render results", ((float)(fileCounter - captureStartFrame) / numFiles));
            }

            if (!cancelled)
            {
                //Delete old files
                if (AssetDatabase.IsValidFolder(outputFolder))
                {
                    foreach (string oldFile in filesToDelete)
                    {
                        AssetDatabase.DeleteAsset(oldFile);
                    }
                }
                else
                {
                    foreach (string oldFile in filesToDelete)
                    {
                        File.Delete(oldFile);
                    }
                }
            }

            //Notify
            FolderContentsChangedNotifier.GetInstance().Notify(outputFolder);

            //Cleanup
            EditorUtility.ClearProgressBar();
            renderCapturer.EndCaptureV();
            ObjectUtility.Destroy(blitterGO);
            AssetDatabase.Refresh();
            renderCachePlayableAsset.Reload();;



            yield return(null);
        }