-
Notifications
You must be signed in to change notification settings - Fork 861
Hdrp/update decal handles pivot #3001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
8ad03d4
3d189b3
eadb3a1
03fe677
5b48a5f
e42c590
1a5ee32
0b04775
b5bffe0
3bdc6b2
ea4dde4
21d850a
5a89574
0ccf247
f326fef
5a64b78
523adec
e911d2e
98b2060
b27d81b
607f609
054b033
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
||
| 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"); | ||
|
|
||
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) | ||
RSlysz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| baseColor = baseTint; | ||
| } | ||
|
|
||
| /// <summary>Draw the rect.</summary> | ||
| public void DrawRect(bool dottedLine = false, float sickness = .0f, float screenSpaceSize = 5f) | ||
|
||
| { | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think creating a new method will improve readability. |
||
| 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; | ||
| } | ||
|
||
| } | ||
|
|
||
| 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 | ||
|
||
| 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.
Uh oh!
There was an error while loading. Please reload this page.