浏览代码

Fix InfluenceVolume's offset and offset tool

/main
RSlysz 6 年前
当前提交
aeaafbb9
共有 7 个文件被更改,包括 99 次插入87 次删除
  1. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDProbeUI.Drawers.cs
  2. 33
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDProbeUI.Handles.cs
  3. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDProbeUI.Skin.cs
  4. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.cs
  5. 29
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Drawers.cs
  6. 93
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Handles.cs
  7. 10
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/Volumes/InfluenceVolume.cs

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDProbeUI.Drawers.cs


protected const EditMode.SceneViewEditMode EditBaseShape = EditMode.SceneViewEditMode.ReflectionProbeBox;
protected const EditMode.SceneViewEditMode EditInfluenceShape = EditMode.SceneViewEditMode.GridBox;
protected const EditMode.SceneViewEditMode EditInfluenceNormalShape = EditMode.SceneViewEditMode.Collider;
protected const EditMode.SceneViewEditMode EditCenter = EditMode.SceneViewEditMode.ReflectionProbeOrigin;
protected const EditMode.SceneViewEditMode EditCenter = EditMode.SceneViewEditMode.GridMove;
//Note: EditMode.SceneViewEditMode.ReflectionProbeOrigin is still used
//by legacy reflection probe and have its own mecanism that we don't want
static Dictionary<ToolBar, EditMode.SceneViewEditMode> s_Toolbar_Mode = null;
protected static Dictionary<ToolBar, EditMode.SceneViewEditMode> toolbar_Mode

33
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDProbeUI.Handles.cs


case EditInfluenceNormalShape:
InfluenceVolumeUI.DrawHandles_EditInfluenceNormal(s.influenceVolume, d.influenceVolume, o, mat, d);
break;
//[TODO]
//case EditCenter:
//{
// EditorGUI.BeginChangeCheck();
// var m = Handles.matrix;
// Handles.matrix = mat;
// var p = Handles.PositionHandle(d.captureLocalPosition, d.transform.rotation);
// if (EditorGUI.EndChangeCheck())
// {
// Undo.RecordObject(d, "Translate Capture Position");
// d.captureLocalPosition = p;
// EditorUtility.SetDirty(d);
// }
// Handles.matrix = m;
// break;
//}
case EditCenter:
{
using (new Handles.DrawingScope(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one)))
{
Vector3 offsetWorld = d.transform.position + d.transform.rotation * d.influenceVolume.offset;
EditorGUI.BeginChangeCheck();
var newOffsetWorld = Handles.PositionHandle(offsetWorld, d.transform.rotation);
if (EditorGUI.EndChangeCheck())
{
Vector3 newOffset = Quaternion.Inverse(d.transform.rotation) * (newOffsetWorld - d.transform.position);
Undo.RecordObjects(new Object[] { d, d.transform }, "Translate Capture Position");
d.influenceVolume.offset = newOffset;
EditorUtility.SetDirty(d);
}
}
break;
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDProbeUI.Skin.cs


{
partial class HDProbeUI
{
static readonly Color k_GizmoThemeColorExtent = new Color(255f / 255f, 229f / 255f, 148f / 255f, 80f / 255f);
static readonly Color k_GizmoThemeColorExtentFace = new Color(255f / 255f, 229f / 255f, 148f / 255f, 45f / 255f);
static readonly Color k_GizmoThemeColorInfluenceBlend = new Color(83f / 255f, 255f / 255f, 95f / 255f, 75f / 255f);
static readonly Color k_GizmoThemeColorInfluenceBlendFace = new Color(83f / 255f, 255f / 255f, 95f / 255f, 17f / 255f);
static readonly Color k_GizmoThemeColorInfluenceNormalBlend = new Color(0f / 255f, 229f / 255f, 255f / 255f, 80f / 255f);
static readonly Color k_GizmoThemeColorInfluenceNormalBlendFace = new Color(0f / 255f, 229f / 255f, 255f / 255f, 36f / 255f);
static readonly Color k_GizmoThemeColorProjection = new Color(0x00 / 255f, 0xE5 / 255f, 0xFF / 255f, 0x20 / 255f);
static readonly Color k_GizmoThemeColorProjectionFace = new Color(0x00 / 255f, 0xE5 / 255f, 0xFF / 255f, 0x20 / 255f);
static readonly Color k_GizmoThemeColorDisabled = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x10 / 255f);
static readonly Color k_GizmoThemeColorDisabledFace = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x10 / 255f);
static readonly Color[][] k_handlesColor = new Color[][]
{
new Color[]

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.cs


public static bool IsReflectionProbeEditMode(EditMode.SceneViewEditMode editMode)
{
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox ||
editMode == EditMode.SceneViewEditMode.ReflectionProbeOrigin;
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox
|| editMode == EditMode.SceneViewEditMode.Collider
|| editMode == EditMode.SceneViewEditMode.GridBox
|| editMode == EditMode.SceneViewEditMode.GridMove;
}
}
}

29
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Drawers.cs


if (drawOffset)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(d.offset, offsetContent);
HDProbeUI.Drawer_ToolBarButton(HDProbeUI.ToolBar.CapturePosition, o, GUILayout.Width(28f), GUILayout.MinHeight(22f));
EditorGUILayout.EndHorizontal();
Drawer_Offset(s, d, o);
}
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);

if(drawOffset)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(d.offset, offsetContent);
HDReflectionProbeUI.Drawer_ToolBarButton(HDProbeUI.ToolBar.CapturePosition, o, GUILayout.Width(28f), GUILayout.MinHeight(22f));
EditorGUILayout.EndHorizontal();
Drawer_Offset(s, d, o);
}
EditorGUILayout.Space();

HDProbeUI.Drawer_ToolBarButton(HDProbeUI.ToolBar.NormalBlend, o, GUILayout.ExpandHeight(true), GUILayout.Width(28f), GUILayout.MinHeight(22f), GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight + 3));
EditorGUILayout.EndHorizontal();
}
}
static void Drawer_Offset(InfluenceVolumeUI s, SerializedInfluenceVolume d, Editor o)
{
HDProbeEditor editor = (HDProbeEditor)o;
InfluenceVolume influenceVolume = editor.GetTarget(editor.target).influenceVolume;
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(d.offset, offsetContent);
if(EditorGUI.EndChangeCheck())
{
//call the offset setter as it will update legacy reflection probe
influenceVolume.offset = d.offset.vector3Value;
d.Apply();
}
HDProbeUI.Drawer_ToolBarButton(HDProbeUI.ToolBar.CapturePosition, o, GUILayout.Width(28f), GUILayout.MinHeight(22f));
EditorGUILayout.EndHorizontal();
}
}
}

93
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Handles.cs


public static void DrawHandles_EditInfluence(InfluenceVolumeUI s, InfluenceVolume d, Editor o, Matrix4x4 matrix, Object sourceAsset)
{
var mat = Handles.matrix;
var c = Handles.color;
Handles.matrix = matrix;
Handles.color = k_GizmoThemeColorInfluence;
switch (d.shape)
using (new Handles.DrawingScope(k_GizmoThemeColorInfluence, matrix))
case InfluenceShape.Box:
{
var positive = d.boxBlendDistancePositive;
var negative = d.boxBlendDistanceNegative;
DrawBoxFadeHandle(
s, d, o, sourceAsset,
s1 => s1.boxInfluenceHandle,
d.offset, d.boxSize,
ref positive,
ref negative);
s.data.boxBlendDistancePositive.vector3Value = positive;
s.data.boxBlendDistanceNegative.vector3Value = negative;
switch (d.shape)
{
case InfluenceShape.Box:
{
var positive = d.boxBlendDistancePositive;
var negative = d.boxBlendDistanceNegative;
DrawBoxFadeHandle(
s, d, o, sourceAsset,
s1 => s1.boxInfluenceHandle,
d.offset, d.boxSize,
ref positive,
ref negative);
s.data.boxBlendDistancePositive.vector3Value = positive;
s.data.boxBlendDistanceNegative.vector3Value = negative;
//save advanced/simplified saved data
if (s.data.editorAdvancedModeEnabled.boolValue)
{
s.data.editorAdvancedModeBlendDistancePositive.vector3Value = positive;
s.data.editorAdvancedModeBlendDistanceNegative.vector3Value = negative;
////save advanced/simplified saved data
if (s.data.editorAdvancedModeEnabled.boolValue)
{
s.data.editorAdvancedModeBlendDistancePositive.vector3Value = positive;
s.data.editorAdvancedModeBlendDistanceNegative.vector3Value = negative;
}
else
{
s.data.editorSimplifiedModeBlendDistance.floatValue = positive.x;
}
s.data.Apply();
break;
else
case InfluenceShape.Sphere:
s.data.editorSimplifiedModeBlendDistance.floatValue = positive.x;
var fade = d.sphereBlendDistance;
DrawSphereFadeHandle(
s, d, o, sourceAsset,
s1 => s1.sphereInfluenceHandle,
d.offset, d.sphereRadius,
ref fade);
d.sphereBlendDistance = fade;
break;
s.data.Apply();
break;
}
case InfluenceShape.Sphere:
{
var fade = d.sphereBlendDistance;
DrawSphereFadeHandle(
s, d, o, sourceAsset,
s1 => s1.sphereInfluenceHandle,
d.offset, d.sphereRadius,
ref fade);
d.sphereBlendDistance = fade;
break;
}
}
Handles.matrix = mat;
Handles.color = c;
}
public static void DrawHandles_EditInfluenceNormal(InfluenceVolumeUI s, InfluenceVolume d, Editor o, Matrix4x4 matrix, Object sourceAsset)

{
Undo.RecordObject(sourceAsset, "Modified Influence Volume");
var center = baseOffset;
var influenceSize = baseSize;
var influenceCenter = baseOffset;
var halfInfluenceSize = baseSize * .5f;
var diff = 2 * (b.center - center);
var sum = influenceSize - b.size;
var positiveNew = (sum - diff) * 0.5f;
var negativeNew = (sum + diff) * 0.5f;
var blendDistancePositive = Vector3.Max(Vector3.zero, Vector3.Min(positiveNew, influenceSize * .5f));
var blendDistanceNegative = Vector3.Max(Vector3.zero, Vector3.Min(negativeNew, influenceSize * .5f));
var centerDiff = b.center - influenceCenter;
var halfSizeDiff = halfInfluenceSize - b.size * .5f;
var positiveNew = halfSizeDiff - centerDiff;
var negativeNew = halfSizeDiff + centerDiff;
var blendDistancePositive = Vector3.Max(Vector3.zero, Vector3.Min(positiveNew, halfInfluenceSize));
var blendDistanceNegative = Vector3.Max(Vector3.zero, Vector3.Min(negativeNew, halfInfluenceSize));
positive = blendDistancePositive;
negative = blendDistanceNegative;

10
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/Volumes/InfluenceVolume.cs


}
/// <summary>Offset of this influence volume to the component handling him.</summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
public Vector3 offset
{
get { return m_Offset; }
set
{
m_Offset = value;
m_Probe.UpdatedInfluenceVolumeShape(boxSize, m_Offset);
}
}
/// <summary>Size of the InfluenceVolume in Box Mode.</summary>
public Vector3 boxSize

正在加载...
取消
保存