Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions com.unity.render-pipelines.core/Editor/Gizmo/HierarchicalBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,27 @@ public Color baseColor
set
{
value.a = 8f / 255;
m_MonochromeFillColor = value;
material.color = m_MonochromeFillColor;
value.a = 1f;
m_MonochromeHandleColor = value;
value.a = 0.7f;
m_WireframeColor = value;
value.a = 0.2f;
m_WireframeColorBehind = value;
SetBaseColorWithoutIntensityChange(value);
}
}

/// <summary>
/// Set the baseColor used to fill hull. All other colors are deduced from it except specific handle colors.
/// Instead of <see cref="baseColor">baseColor</see> set, this will not force the opacity and keep what is provided for the filled faces.
/// </summary>
/// <param name="color">The color to use</param>
public void SetBaseColorWithoutIntensityChange(Color color)
{
m_MonochromeFillColor = color;
material.color = m_MonochromeFillColor;
color.a = 1f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In DisplacableRectHandles.baseColor we also have the same alpha values, can have them declared somewhere? Just in case we want to change them will be equal in both places. Maybe a static function SetAlphaHandleValues()?

m_MonochromeHandleColor = color;
color.a = 0.7f;
m_WireframeColor = color;
color.a = 0.2f;
m_WireframeColorBehind = color;
}

//Note: Handles.Slider not allow to use a specific ControlID.
//Thus Slider1D is used (with reflection)
static Type k_Slider1D = Type.GetType("UnityEditorInternal.Slider1D, UnityEditor");
Expand Down
7 changes: 7 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [11.0.0] - 2020-10-21

### Added

- Added pivot point manipulation for Decals (inspector and edit mode).
- Added UV manipulation for Decals (edit mode).
- Added color and intensity customization for Decals.

### Changed

- Removed the material pass probe volumes evaluation mode.

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,8 @@ partial class DecalProjectorEditor
static readonly GUIContent k_UVBiasContent = EditorGUIUtility.TrTextContent("Offset", "Sets the offset for the decal Material. Moves the decal along its UV axes.");
static readonly GUIContent k_FadeFactorContent = EditorGUIUtility.TrTextContent("Fade Factor", "Controls the transparency of the decal.");
static readonly GUIContent k_AffectTransparentContent = EditorGUIUtility.TrTextContent("Affects Transparent", "When enabled, HDRP draws this projector's decal on top of transparent surfaces.");
static readonly GUIContent k_Offset = EditorGUIUtility.TrTextContent("Pivot", "Controls the position of the pivot point of the decal.");

public static readonly Color k_GizmoColorBase = Color.white;
public static readonly Color[] k_BaseHandlesColor = new Color[]
{
Color.white,
Color.white,
Color.white,
Color.white,
Color.white,
Color.white
};
public static readonly Color k_GizmoColorBase = new Color(1, 1, 1, 8f/255);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
using System;
using System.Linq;
using System.Reflection;
using UnityEngine;

namespace UnityEditor.Rendering.HighDefinition
{
class DisplacableRectHandles
{
const float k_HandleSizeCoef = 0.05f;

enum NamedEdge { Right, Top, Left, Bottom, None }

int[] m_ControlIDs = new int[4] { 0, 0, 0, 0 };
Color m_MonochromeHandleColor;
Color m_WireframeColor;
Color m_WireframeColorBehind;

/// <summary>The position of the center of the box in Handle.matrix space. On plane z=0.</summary>
public Vector2 center { get; set; }

/// <summary>The size of the box in Handle.matrix space. On plane z=0.</summary>
public Vector2 size { get; set; }

//Note: Handles.Slider not allow to use a specific ControlID.
//Thus Slider1D is used (with reflection)
static Type k_Slider1D = Type.GetType("UnityEditorInternal.Slider1D, UnityEditor");
static MethodInfo k_Slider1D_Do = k_Slider1D
.GetMethod(
"Do",
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public,
null,
CallingConventions.Any,
new[] { typeof(int), typeof(Vector3), typeof(Vector3), typeof(float), typeof(Handles.CapFunction), typeof(float) },
null);
static void Slider1D(int controlID, ref Vector3 handlePosition, Vector3 handleOrientation, float snapScale)
{
handlePosition = (Vector3)k_Slider1D_Do.Invoke(null, new object[]
{
controlID,
handlePosition,
handleOrientation,
HandleUtility.GetHandleSize(handlePosition) * k_HandleSizeCoef,
new Handles.CapFunction(Handles.DotHandleCap),
snapScale
});
}

/// <summary>The baseColor used to draw the rect.</summary>
public Color baseColor
{
get { return m_MonochromeHandleColor; }
set
{
value.a = 1f;
m_MonochromeHandleColor = value;
value.a = 0.7f;
m_WireframeColor = value;
value.a = 0.2f;
m_WireframeColorBehind = value;
}
}

public DisplacableRectHandles(Color baseTint)
{
baseColor = baseTint;
}

/// <summary>Draw the rect.</summary>
public void DrawRect(bool dottedLine = false, float sickness = .0f, float screenSpaceSize = 5f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant thickness instead of sickness ?

{
Vector2 start = center - size * .5f;
Vector3[] positions = new Vector3[]
{
start,
start + size * Vector2.right,
start + size,
start + size * Vector2.up
};
Vector3[] edges = new Vector3[]
{
positions[0], positions[1],
positions[1], positions[2],
positions[2], positions[3],
positions[3], positions[0],
};

void Draw()
{
if (dottedLine)
Handles.DrawDottedLines(edges, screenSpaceSize);
else
{
Handles.DrawLine(positions[0], positions[1], sickness);
Handles.DrawLine(positions[1], positions[2], sickness);
Handles.DrawLine(positions[2], positions[3], sickness);
Handles.DrawLine(positions[3], positions[0], sickness);
}
}

Color previousColor = Handles.color;
Handles.color = m_WireframeColor;
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Draw();
Handles.color = m_WireframeColorBehind;
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Draw();
Handles.zTest = UnityEngine.Rendering.CompareFunction.Always;
Handles.color = previousColor;
}

/// <summary>Draw the manipulable handles</summary>
public void DrawHandle()
{
Event evt = Event.current;
bool useHomothety = evt.shift;
bool useSymetry = evt.alt || evt.command;
// Note: snapping is handled natively on ctrl for each Slider1D

for (int i = 0, count = m_ControlIDs.Length; i < count; ++i)
m_ControlIDs[i] = GUIUtility.GetControlID("DisplacableRectHandles".GetHashCode() + i, FocusType.Passive);

Vector3 leftPosition = center + size.x * .5f * Vector2.left;
Vector3 rightPosition = center + size.x * .5f * Vector2.right;
Vector3 topPosition = center + size.y * .5f * Vector2.up;
Vector3 bottomPosition = center + size.y * .5f * Vector2.down;

var theChangedEdge = NamedEdge.None;

EditorGUI.BeginChangeCheck();
using (new Handles.DrawingScope(m_MonochromeHandleColor))
{
EditorGUI.BeginChangeCheck();
Slider1D(m_ControlIDs[(int)NamedEdge.Left], ref leftPosition, Vector3.left, EditorSnapSettings.scale);
if (EditorGUI.EndChangeCheck())
theChangedEdge = NamedEdge.Left;

EditorGUI.BeginChangeCheck();
Slider1D(m_ControlIDs[(int)NamedEdge.Right], ref rightPosition, Vector3.right, EditorSnapSettings.scale);
if (EditorGUI.EndChangeCheck())
theChangedEdge = NamedEdge.Right;

EditorGUI.BeginChangeCheck();
Slider1D(m_ControlIDs[(int)NamedEdge.Top], ref topPosition, Vector3.up, EditorSnapSettings.scale);
if (EditorGUI.EndChangeCheck())
theChangedEdge = NamedEdge.Top;

EditorGUI.BeginChangeCheck();
Slider1D(m_ControlIDs[(int)NamedEdge.Bottom], ref bottomPosition, Vector3.down, EditorSnapSettings.scale);
if (EditorGUI.EndChangeCheck())
theChangedEdge = NamedEdge.Bottom;
}
Comment on lines +113 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think creating a new method will improve readability.

var theChangedEdge = GetChangedEdge(ref leftPosition, ref rightPosition, ref topPosition,  ref bottomPosition);

if (EditorGUI.EndChangeCheck())
{
float delta = 0f;
switch (theChangedEdge)
{
case NamedEdge.Left: delta = ((Vector2)leftPosition - center - size.x * .5f * Vector2.left).x; break;
case NamedEdge.Right: delta = -((Vector2)rightPosition - center - size.x * .5f * Vector2.right).x; break;
case NamedEdge.Top: delta = -((Vector2)topPosition - center - size.y * .5f * Vector2.up).y; break;
case NamedEdge.Bottom: delta = ((Vector2)bottomPosition - center - size.y * .5f * Vector2.down).y; break;
}

if (useHomothety && useSymetry)
{
var tempSize = size - Vector2.one * delta;

//ensure that the rect edges are still facing outside
for (int axis = 0; axis < 3; ++axis)
{
if (tempSize[axis] < 0)
{
delta += tempSize[axis];
tempSize = size - Vector2.one * delta;
}
}

size = tempSize;
}
else
{
if (useSymetry)
{
switch (theChangedEdge)
{
case NamedEdge.Left: rightPosition.x -= delta; break;
case NamedEdge.Right: leftPosition.x += delta; break;
case NamedEdge.Top: bottomPosition.y += delta; break;
case NamedEdge.Bottom: topPosition.y -= delta; break;
}

//ensure that the rect edges are still facing outside
switch (theChangedEdge)
{
case NamedEdge.Left:
case NamedEdge.Right:
if (rightPosition.x < leftPosition.x)
rightPosition.x = leftPosition.x = center.x;
break;
case NamedEdge.Top:
case NamedEdge.Bottom:
if (topPosition.y < bottomPosition.y)
topPosition.y = bottomPosition.y = center.y;
break;
}
}

if (useHomothety)
{
float halfDelta = delta * 0.5f;
switch (theChangedEdge)
{
case NamedEdge.Left:
case NamedEdge.Right:
bottomPosition.y += halfDelta;
topPosition.y -= halfDelta;
break;
case NamedEdge.Top:
case NamedEdge.Bottom:
rightPosition.x -= halfDelta;
leftPosition.x += halfDelta;
break;
}

//ensure that the rect edges are still facing outside
switch (theChangedEdge)
{
case NamedEdge.Left:
if (rightPosition.x < leftPosition.x)
leftPosition.x = rightPosition.x;
if (topPosition.y < bottomPosition.y)
topPosition.y = bottomPosition.y = center.y;
break;
case NamedEdge.Right:
if (rightPosition.x < leftPosition.x)
rightPosition.x = leftPosition.x;
if (topPosition.y < bottomPosition.y)
topPosition.y = bottomPosition.y = center.y;
break;
case NamedEdge.Top:
if (topPosition.y < bottomPosition.y)
topPosition.y = bottomPosition.y;
if (rightPosition.x < leftPosition.x)
rightPosition.x = leftPosition.x = center.x;
break;
case NamedEdge.Bottom:
if (topPosition.y < bottomPosition.y)
bottomPosition.y = topPosition.y;
if (rightPosition.x < leftPosition.x)
rightPosition.x = leftPosition.x = center.x;
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, another method will improve readability

EnsureEdgesFacingOutside();

}

var max = new Vector2(rightPosition.x, topPosition.y);
var min = new Vector2(leftPosition.x, bottomPosition.y);

if (!useSymetry && !useHomothety)
{
//ensure that the rect edges are still facing outside
for (int axis = 0; axis < 2; ++axis)
{
if (min[axis] > max[axis])
{
// Control IDs in m_ControlIDs[0-3[ are for positive axes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo on the comment: [0-3]

if (GUIUtility.hotControl == m_ControlIDs[axis])
max[axis] = min[axis];
else
min[axis] = max[axis];
}
}
}

center = (max + min) * .5f;
size = max - min;
}
}
}


internal string debug => $"center:({center.x},{center.y}) size:({size.x},{size.y})";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading