浏览代码

Added bake button

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
90fc49a7
共有 2 个文件被更改,包括 194 次插入2 次删除
  1. 95
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  2. 101
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs

95
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs


using UnityEditorInternal;
using System;
using System.Reflection;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;

true,
CED.Action(Drawer_AdditionalSettings)
);
static readonly CED.IDrawer k_BakingActions = CED.Action(Drawer_BakeActions);
#endregion
static void Drawer_CaptureSettings(UIState s, SerializedReflectionProbe p, Editor owner)

}
}
static readonly string[] k_BakeCustomOptionText = { "Bake as new Cubemap..." };
static readonly string[] k_BakeButtonsText = { "Bake All Reflection Probes" };
static void Drawer_BakeActions(UIState s, SerializedReflectionProbe p, Editor owner)
{
if (p.mode.intValue == (int)ReflectionProbeMode.Realtime)
{
EditorGUILayout.HelpBox("Baking of this reflection probe should be initiated from the scripting API because the type is 'Realtime'", MessageType.Info);
if (!QualitySettings.realtimeReflectionProbes)
EditorGUILayout.HelpBox("Realtime reflection probes are disabled in Quality Settings", MessageType.Warning);
return;
}
if (p.mode.intValue == (int)ReflectionProbeMode.Baked && UnityEditor.Lightmapping.giWorkflowMode != UnityEditor.Lightmapping.GIWorkflowMode.OnDemand)
{
EditorGUILayout.HelpBox("Baking of this reflection probe is automatic because this probe's type is 'Baked' and the Lighting window is using 'Auto Baking'. The cubemap created is stored in the GI cache.", MessageType.Info);
return;
}
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
switch ((ReflectionProbeMode)p.mode.intValue)
{
case ReflectionProbeMode.Custom:
{
if (ButtonWithDropdownList(
CoreEditorUtils.GetContent("Bake|Bakes Reflection Probe's cubemap, overwriting the existing cubemap texture asset (if any)."), k_BakeCustomOptionText,
data =>
{
var mode = (int)data;
var probe = p.so.targetObject as ReflectionProbe;
if (mode == 0)
BakeCustomReflectionProbe(probe, false, true);
},
GUILayout.ExpandWidth(true)))
{
BakeCustomReflectionProbe((ReflectionProbe)p.so.targetObject, true, true);
GUIUtility.ExitGUI();
}
break;
}
case ReflectionProbeMode.Baked:
{
GUI.enabled = ((ReflectionProbe)p.so.targetObject).enabled;
// Bake button in non-continous mode
if (ButtonWithDropdownList(
CoreEditorUtils.GetContent("Bake"),
k_BakeButtonsText,
data =>
{
var mode = (int)data;
if (mode == 0)
BakeAllReflectionProbesSnapshots();
},
GUILayout.ExpandWidth(true)))
{
BakeReflectionProbeSnapshot((ReflectionProbe)p.so.targetObject);
GUIUtility.ExitGUI();
}
GUI.enabled = true;
break;
}
case ReflectionProbeMode.Realtime:
// Not showing bake button in realtime
break;
}
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
}
//static void OnBakeCustomButton(object data)
//{
// var mode = (int)data;
// var p = target as ReflectionProbe;
// if (mode == 0)
// BakeCustomReflectionProbe(p, false, true);
//}
#region Influence Volume
static void Drawer_InfluenceBoxSettings(UIState s, SerializedReflectionProbe p, Editor owner)
{

EditorGUILayout.PropertyField(p.timeSlicingMode, CoreEditorUtils.GetContent("Time Slicing|If enabled this probe will update over several frames, to help reduce the impact on the frame rate"));
}
#endregion
static MethodInfo k_EditorGUI_ButtonWithDropdownList = typeof(EditorGUI).GetMethod("ButtonWithDropdownList", BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any, new [] { typeof(GUIContent), typeof(string[]), typeof(GenericMenu.MenuFunction2), typeof(GUILayoutOption[]) }, new ParameterModifier[0]);
static bool ButtonWithDropdownList(GUIContent content, string[] buttonNames, GenericMenu.MenuFunction2 callback, params GUILayoutOption[] options)
{
return (bool)k_EditorGUI_ButtonWithDropdownList.Invoke(null, new object[] { content, buttonNames, callback, options });
}
}
}

101
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs


using UnityEditor.Experimental.Rendering;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor.Experimental.Rendering;
using UnityEngine.SceneManagement;
namespace UnityEditor.Experimental.Rendering
{

k_SeparateProjectionVolumeSection.Draw(s, p, this);
k_CaptureSection.Draw(s, p, this);
k_AdditionalSection.Draw(s, p, this);
k_BakingActions.Draw(s, p, this);
HideAdditionalComponents(false);
}
void PerformOperations(UIState s, SerializedReflectionProbe p, HDReflectionProbeEditor o)

}
void HideAdditionalComponents(bool visible)
{
var adds = CoreEditorUtils.GetAdditionalData<HDAdditionalReflectionData>(targets);
for (var i = 0 ; i < targets.Length; ++i)
{
var target = targets[i];
var addData = adds[i];
var p = (ReflectionProbe)target;
var meshRenderer = p.GetComponent<MeshRenderer>();
var meshFilter = p.GetComponent<MeshFilter>();
addData.hideFlags = visible ? HideFlags.None : HideFlags.HideInInspector;
meshRenderer.hideFlags = visible ? HideFlags.None : HideFlags.HideInInspector;
meshFilter.hideFlags = visible ? HideFlags.None : HideFlags.HideInInspector;
}
}
void UpdateOldLocalSpace()

center = b.center;
size = b.size;
return true;
}
static void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath, bool custom)
{
if (!custom && probe.bakedTexture != null)
probe.customBakedTexture = probe.bakedTexture;
string path = "";
if (usePreviousAssetPath)
path = AssetDatabase.GetAssetPath(probe.customBakedTexture);
string targetExtension = probe.hdr ? "exr" : "png";
if (string.IsNullOrEmpty(path) || Path.GetExtension(path) != "." + targetExtension)
{
// We use the path of the active scene as the target path
var targetPath = SceneManager.GetActiveScene().path;
targetPath = Path.Combine(Path.GetDirectoryName(targetPath), Path.GetFileNameWithoutExtension(targetPath));
if (string.IsNullOrEmpty(targetPath))
targetPath = "Assets";
else if (Directory.Exists(targetPath) == false)
Directory.CreateDirectory(targetPath);
string fileName = probe.name + (probe.hdr ? "-reflectionHDR" : "-reflection") + "." + targetExtension;
fileName = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName)));
path = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", fileName, targetExtension, "", targetPath);
if (string.IsNullOrEmpty(path))
return;
ReflectionProbe collidingProbe;
if (IsCollidingWithOtherProbes(path, probe, out collidingProbe))
{
if (!EditorUtility.DisplayDialog("Cubemap is used by other reflection probe",
string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?",
path, collidingProbe.name), "Yes", "No"))
{
return;
}
}
}
EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + path, 0.5f);
if (!UnityEditor.Lightmapping.BakeReflectionProbe(probe, path))
Debug.LogError("Failed to bake reflection probe to " + path);
EditorUtility.ClearProgressBar();
}
static bool IsCollidingWithOtherProbes(string targetPath, ReflectionProbe targetProbe, out ReflectionProbe collidingProbe)
{
ReflectionProbe[] probes = FindObjectsOfType<ReflectionProbe>().ToArray();
collidingProbe = null;
foreach (var probe in probes)
{
if (probe == targetProbe || probe.customBakedTexture == null)
continue;
string path = AssetDatabase.GetAssetPath(probe.customBakedTexture);
if (path == targetPath)
{
collidingProbe = probe;
return true;
}
}
return false;
}
static MethodInfo k_Lightmapping_BakeReflectionProbeSnapshot = typeof(UnityEditor.Lightmapping).GetMethod("BakeReflectionProbeSnapshot", BindingFlags.Static | BindingFlags.NonPublic);
static bool BakeReflectionProbeSnapshot(ReflectionProbe probe)
{
return (bool)k_Lightmapping_BakeReflectionProbeSnapshot.Invoke(null, new object[] { probe });
}
static MethodInfo k_Lightmapping_BakeAllReflectionProbesSnapshots = typeof(UnityEditor.Lightmapping).GetMethod("BakeAllReflectionProbesSnapshots", BindingFlags.Static | BindingFlags.NonPublic);
static bool BakeAllReflectionProbesSnapshots()
{
return (bool)k_Lightmapping_BakeAllReflectionProbesSnapshots.Invoke(null, new object[0]);
}
}
}
正在加载...
取消
保存