浏览代码

Added gizmos

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
60688864
共有 3 个文件被更改,包括 169 次插入21 次删除
  1. 6
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  2. 149
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  3. 35
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs

6
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs


m_InfluenceShapeDisplays[i].target = i == value;
}
static bool IsReflectionProbeEditMode(EditMode.SceneViewEditMode editMode)
{
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox ||
editMode == EditMode.SceneViewEditMode.ReflectionProbeOrigin;
}
internal void UpdateOldLocalSpace(ReflectionProbe target)
{
oldLocalSpace = GetLocalSpace(target);

149
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs


using UnityEditor.IMGUI.Controls;
using UnityEditorInternal;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

{
internal static Color kGizmoReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0x94 / 255f, 0x80 / 255f);
internal static Color kGizmoReflectionProbeDisabled = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x60 / 255f);
internal static Color kGizmoHandleReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0xAA / 255f, 0xFF / 255f);
void OnSceneGUI()
{
serializedObject.Update();

{
case EditMode.SceneViewEditMode.ReflectionProbeBox:
if (p.influenceShape.enumValueIndex == 0)
DoInfluenceBoxEditing(s, p, o);
Handle_InfluenceBoxEditing(s, p, o);
DoInfluenceSphereEditing(s, p, o);
Handle_InfluenceSphereEditing(s, p, o);
DoProjectionBoxEditing(s, p, o);
Handle_ProjectionBoxEditing(s, p, o);
DoProjectionSphereEditing(s, p, o);
Handle_ProjectionSphereEditing(s, p, o);
DoOriginEditing(s, p, o);
Handle_OriginEditing(s, p, o);
break;
}

m_AdditionalDataSerializedObject.ApplyModifiedProperties();
}
static void DoInfluenceBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
static void Handle_InfluenceBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;

}
}
static void DoProjectionBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
static void Handle_ProjectionBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();

}
}
static void DoInfluenceSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
static void Handle_InfluenceSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();

}
}
static void DoProjectionSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
static void Handle_ProjectionSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();

}
}
static void DoOriginEditing(UIState s, SerializedReflectionProbe sp, Editor o)
static void Handle_OriginEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;
var transformPosition = p.transform.position;

if (changed || s.oldLocalSpace != GetLocalSpace(p))
{
Vector3 localNewPosition = s.oldLocalSpace.inverse.MultiplyPoint3x4(newPostion);
var localNewPosition = s.oldLocalSpace.inverse.MultiplyPoint3x4(newPostion);
Bounds b = new Bounds(p.center, size);
var b = new Bounds(p.center, size);
localNewPosition = b.ClosestPoint(localNewPosition);
Undo.RecordObject(p.transform, "Modified Reflection Probe Origin");

EditorUtility.SetDirty(p);
s.AddOperation(Operation.UpdateOldLocalSpace);
}
}
[DrawGizmo(GizmoType.Active)]
static void RenderGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
{
var e = GetEditorFor(reflectionProbe);
if (e == null)
return;
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>();
if (e.sceneViewEditing && EditMode.editMode == EditMode.SceneViewEditMode.ReflectionProbeBox)
{
var oldColor = Gizmos.color;
Gizmos.color = kGizmoReflectionProbe;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
Gizmos.DrawCube(reflectionProbe.center, -1f * reflectionProbe.size);
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius);
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
}
}
[DrawGizmo(GizmoType.Selected)]
static void DrawSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
{
Color oldColor = Gizmos.color;
Gizmos.color = reflectionProbe.isActiveAndEnabled ? kGizmoReflectionProbe : kGizmoReflectionProbeDisabled;
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>();
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
{
DrawBoxInfluenceGizmo(reflectionProbe, oldColor);
}
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
{
DrawSphereInfluenceGizmo(reflectionProbe, oldColor, reflectionData);
}
if (reflectionData.m_UseSeparateProjectionVolume)
{
DrawReprojectionVolumeGizmo(reflectionProbe, reflectionData);
}
Gizmos.color = oldColor;
DrawVerticalRay(reflectionProbe.transform);
reflectionData.ChangeVisibility(true);
}
[DrawGizmo(GizmoType.NonSelected)]
static void DrawNonSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
{
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>();
if (reflectionData != null)
reflectionData.ChangeVisibility(false);
}
static void DrawBoxInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor)
{
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireCube(reflectionProbe.center, reflectionProbe.size);
if (reflectionProbe.blendDistance > 0)
{
Gizmos.color = new Color(Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 0.3f);
Gizmos.DrawWireCube(reflectionProbe.center, new Vector3(reflectionProbe.size.x - reflectionProbe.blendDistance * 2, reflectionProbe.size.y - reflectionProbe.blendDistance * 2, reflectionProbe.size.z - reflectionProbe.blendDistance * 2));
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
}
static void DrawSphereInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor, HDAdditionalReflectionData reflectionData)
{
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius);
if (reflectionProbe.blendDistance > 0)
{
Gizmos.color = new Color(Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 0.3f);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius - 2 * reflectionProbe.blendDistance);
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
}
static void DrawReprojectionVolumeGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData)
{
Color reprojectionColor = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, 0.3f);
Gizmos.color = reprojectionColor;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
{
Gizmos.DrawWireCube(reflectionData.m_BoxReprojectionVolumeCenter, reflectionData.m_BoxReprojectionVolumeSize);
}
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
{
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_SphereReprojectionVolumeRadius);
}
Gizmos.matrix = Matrix4x4.identity;
}
static void DrawVerticalRay(Transform transform)
{
Ray ray = new Ray(transform.position, Vector3.down);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Handles.color = Color.green;
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.DrawLine(transform.position - Vector3.up * 0.5f, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
Handles.color = Color.red;
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.DrawLine(transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
}
}
}

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


using System.IO;
using System.Collections.Generic;
using System.IO;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;

[CanEditMultipleObjects]
partial class HDReflectionProbeEditor : Editor
{
static Dictionary<ReflectionProbe, HDReflectionProbeEditor> s_ReflectionProbeEditors = new Dictionary<ReflectionProbe, HDReflectionProbeEditor>();
static HDReflectionProbeEditor GetEditorFor(ReflectionProbe p)
{
HDReflectionProbeEditor e;
if (s_ReflectionProbeEditors.TryGetValue(p, out e)
&& e != null
&& !e.Equals(null)
&& ArrayUtility.IndexOf(e.targets, p) != -1)
return e;
return null;
}
public bool sceneViewEditing
{
get { return IsReflectionProbeEditMode(EditMode.editMode) && EditMode.IsOwner(this); }
}
void OnEnable()
{
var additionalData = CoreEditorUtils.GetAdditionalData<HDAdditionalReflectionData>(targets);

this,
Repaint,
m_SerializedReflectionProbe);
foreach (var t in targets)
{
var p = (ReflectionProbe)t;
s_ReflectionProbeEditors[p] = this;
}
}
public override void OnInspectorGUI()

}
}
return false;
}
static bool IsReflectionProbeEditMode(EditMode.SceneViewEditMode editMode)
{
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox ||
editMode == EditMode.SceneViewEditMode.ReflectionProbeOrigin;
}
static MethodInfo k_Lightmapping_BakeReflectionProbeSnapshot = typeof(UnityEditor.Lightmapping).GetMethod("BakeReflectionProbeSnapshot", BindingFlags.Static | BindingFlags.NonPublic);

正在加载...
取消
保存