Example #1
0
        /// <inheritdoc/>
        public Task <Dictionary <Guid, FastList <Color3> > > RequestLightProbesStep()
        {
            return(editor.Controller.InvokeAsync(() =>
            {
                editor.ServiceProvider.TryGet <RenderDocManager>()?.StartCapture(game.GraphicsDevice, IntPtr.Zero);

                // Reset lightprobes temporarily (if requested)
                // Note: we only process first LightProbeProcessor
                var runtimeData = game.SceneSystem.SceneInstance.GetProcessor <LightProbeProcessor>()?.VisibilityGroup.Tags.Get(LightProbeRenderer.CurrentLightProbes);
                if (runtimeData == null)
                {
                    return new Dictionary <Guid, FastList <Color3> >();
                }

                var editorCompositor = game.EditorSceneSystem.GraphicsCompositor.Game;
                try
                {
                    // Disable Gizmo
                    game.EditorSceneSystem.GraphicsCompositor.Game = null;

                    // Regenerate lightprobe coefficients (rendering)
                    var lightProbes = LightProbeGenerator.GenerateCoefficients(game);

                    // TODO: Use LightProbe Id instead of entity id once copy/paste and duplicate properly remap them
                    return lightProbes.ToDictionary(x => x.Key.Entity.Id, x => x.Value);
                }
                finally
                {
                    game.EditorSceneSystem.GraphicsCompositor.Game = editorCompositor;

                    editor.ServiceProvider.TryGet <RenderDocManager>()?.EndFrameCapture(game.GraphicsDevice, IntPtr.Zero);
                }
            }));
        }
    public void OnSceneGUI()
    {
        LightProbeGenerator gen = target as LightProbeGenerator;

        if (Tools.current == Tool.Move)
        {
            bool edited = false;

            for (int i = 0; i < gen.LightProbeVolumes.Length; i++)
            {
                Vector3 oldCenter = gen.LightProbeVolumes[i].ProbeVolume.center;
                gen.LightProbeVolumes[i].ProbeVolume.center = Handles.PositionHandle(
                    gen.LightProbeVolumes[i].ProbeVolume.center, Quaternion.identity
                    );

                if (oldCenter != gen.LightProbeVolumes[i].ProbeVolume.center)
                {
                    edited = true;
                }
            }
            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }

            if (edited)
            {
                Undo.SetSnapshotTarget(target, "ProbeGenerator Move");
                Undo.CreateSnapshot();
                Undo.RegisterSnapshot();
            }
        }

        if (Tools.current == Tool.Scale)
        {
            bool edited = false;

            for (int i = 0; i < gen.LightProbeVolumes.Length; i++)
            {
                Vector3 oldScale = gen.LightProbeVolumes[i].ProbeVolume.extents;
                gen.LightProbeVolumes[i].ProbeVolume.extents = Handles.ScaleHandle(
                    gen.LightProbeVolumes[i].ProbeVolume.extents,
                    gen.LightProbeVolumes[i].ProbeVolume.center,
                    Quaternion.identity,
                    5.0f);
                if (oldScale != gen.LightProbeVolumes[i].ProbeVolume.extents)
                {
                    edited = true;
                }
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }

            if (edited)
            {
                Undo.SetSnapshotTarget(target, "ProbeGenerator Scale");
                Undo.CreateSnapshot();
                Undo.RegisterSnapshot();
            }
        }
    }