Skip to content

Commit 8fa2853

Browse files
authored
Merge pull request #2 from Unity-Technologies/handle-refactor
Handle refactor
2 parents 3f26d50 + 820cea2 commit 8fa2853

File tree

106 files changed

+3117
-2074
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+3117
-2074
lines changed

com.unity.probuilder.tests/Tests/Framework/TestUtility.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212

1313
namespace UnityEngine.ProBuilder.Tests.Framework
1414
{
15-
abstract class TemporaryAssetTest : IPrebuildSetup, IPostBuildCleanup
15+
abstract class TemporaryAssetTest
1616
{
17+
[SetUp]
1718
public void Setup()
1819
{
1920
if (!Directory.Exists(TestUtility.TemporarySavedAssetsDirectory))
2021
Directory.CreateDirectory(TestUtility.TemporarySavedAssetsDirectory);
2122
}
2223

24+
[TearDown]
2325
public void Cleanup()
2426
{
2527
if (Directory.Exists(TestUtility.TemporarySavedAssetsDirectory))

com.unity.probuilder/CHANGELOG.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8-
## [4.0.0-preview.27] - 2018-10-09
8+
## [4.0.0-preview.28] - 2018-11-05
99

1010
### Features
1111

@@ -70,11 +70,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7070
- Include third party dependencies as source code with assembly definitions instead of pre-compiled DLLs.
7171
- Performance optimization for selection changes in editor.
7272

73-
### Changes since 4.0.0-preview.26
73+
### Changes since 4.0.0-preview.27
7474

75-
- Fix lightmap unit test instabilities.
76-
- Refactor settings code to be more modular.
77-
- Remove hard-coded `#define PROGRIDS_ENABLED` from ProGrids unit tests.
75+
- Add support for `Pivot` and `Center` handle position toggle.
76+
- Handles now support operating in selection space (Position: Pivot + Orientation: Normal).
77+
- Texture scene tool now supports vertices and edges.
78+
- Improve performance of mesh rebuild functions.
79+
- Improve performance of vertex, edge, and face gizmos.
80+
- Make auto-resizing colliders opt-in instead of on by default.
81+
- Fix tests sometimes not creating temporary directories.
82+
- Fix occasional null reference error in cases where window layout is reloaded.
7883

7984
## [3.0.8] - 2018-05-07
8085

com.unity.probuilder/Content/Shader/FaceHighlight.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ Shader "Hidden/ProBuilder/FaceHighlight"
44
{
55
_Color ("Color Tint", Color) = (1,1,1,1)
66
_Dither ("Dithering", float) = 0
7+
_HandleZTest ("_HandleZTest", Int) = 8
78
}
89

910
SubShader
1011
{
1112
Tags { "IgnoreProjector"="True" "RenderType"="Geometry" }
1213
Lighting Off
13-
ZTest LEqual
14+
ZTest [_HandleZTest]
1415
ZWrite On
1516
Cull Off
1617
Blend Off

com.unity.probuilder/Content/Shader/LineBillboard.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
_Color ("Color", Color) = (1,1,1,1)
66
_Scale ("Scale", Range(0, 20)) = 7
7+
_HandleZTest ("_HandleZTest", Int) = 8
78
}
89

910
SubShader
@@ -19,7 +20,7 @@
1920
}
2021

2122
Lighting Off
22-
ZTest LEqual
23+
ZTest [_HandleZTest]
2324
ZWrite On
2425
Cull Off
2526
Blend Off

com.unity.probuilder/Debug/Editor/TempMenuItems.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ class TempMenuItems : EditorWindow
1010
[MenuItem("Tools/Temp Menu Item &d", false, 1000)]
1111
static void MenuInit()
1212
{
13-
string[] search = new[]
14-
{
15-
"Assets/Temp.cs",
16-
"Assets/*.cs",
17-
"*.cs"
18-
};
19-
2013

2114
}
2215

com.unity.probuilder/Editor/EditorCore/BooleanEditor.cs

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using UnityEngine;
22
using UnityEngine.ProBuilder;
3+
using UnityEngine.ProBuilder.Experimental.CSG;
4+
using UnityEngine.ProBuilder.MeshOperations;
35

46
namespace UnityEditor.ProBuilder
57
{
@@ -155,15 +157,15 @@ void OnGUI()
155157
switch(operation)
156158
{
157159
case BooleanOp.Union:
158-
MenuCommands.MenuUnion(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
160+
MenuUnion(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
159161
break;
160162

161163
case BooleanOp.Intersection:
162-
MenuCommands.MenuIntersect(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
164+
MenuIntersect(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
163165
break;
164166

165167
case BooleanOp.Subtraction:
166-
MenuCommands.MenuSubtract(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
168+
MenuSubtract(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
167169
break;
168170
}
169171
}
@@ -291,5 +293,77 @@ bool ListenForDragAndDrop()
291293
}
292294
return false;
293295
}
296+
297+
enum BooleanOperation
298+
{
299+
Union,
300+
Subtract,
301+
Intersect
302+
}
303+
304+
static ActionResult MenuBooleanOperation(BooleanOperation operation, ProBuilderMesh lhs, ProBuilderMesh rhs)
305+
{
306+
if(lhs == null || rhs == null)
307+
return new ActionResult(ActionResult.Status.Failure, "Must Select 2 Objects");
308+
309+
string op_string = operation == BooleanOperation.Union ? "Union" : (operation == BooleanOperation.Subtract ? "Subtract" : "Intersect");
310+
311+
ProBuilderMesh[] sel = new ProBuilderMesh[] { lhs, rhs };
312+
313+
UndoUtility.RecordSelection(sel, op_string);
314+
315+
Mesh c;
316+
317+
switch(operation)
318+
{
319+
case BooleanOperation.Union:
320+
c = CSG.Union(lhs.gameObject, rhs.gameObject);
321+
break;
322+
323+
case BooleanOperation.Subtract:
324+
c = CSG.Subtract(lhs.gameObject, rhs.gameObject);
325+
break;
326+
327+
default:
328+
c = CSG.Intersect(lhs.gameObject, rhs.gameObject);
329+
break;
330+
}
331+
332+
GameObject go = new GameObject();
333+
334+
go.AddComponent<MeshRenderer>().sharedMaterial = EditorUtility.GetUserMaterial();
335+
go.AddComponent<MeshFilter>().sharedMesh = c;
336+
337+
ProBuilderMesh pb = InternalMeshUtility.CreateMeshWithTransform(go.transform, false);
338+
DestroyImmediate(go);
339+
340+
Selection.objects = new Object[] { pb.gameObject };
341+
342+
return new ActionResult(ActionResult.Status.Success, op_string);
343+
}
344+
345+
/**
346+
* Union operation between two ProBuilder objects.
347+
*/
348+
public static ActionResult MenuUnion(ProBuilderMesh lhs, ProBuilderMesh rhs)
349+
{
350+
return MenuBooleanOperation(BooleanOperation.Union, lhs, rhs);
351+
}
352+
353+
/**
354+
* Subtract boolean operation between two pb_Objects.
355+
*/
356+
public static ActionResult MenuSubtract(ProBuilderMesh lhs, ProBuilderMesh rhs)
357+
{
358+
return MenuBooleanOperation(BooleanOperation.Subtract, lhs, rhs);
359+
}
360+
361+
/**
362+
* Intersect boolean operation between two pb_Objects.
363+
*/
364+
public static ActionResult MenuIntersect(ProBuilderMesh lhs, ProBuilderMesh rhs)
365+
{
366+
return MenuBooleanOperation(BooleanOperation.Intersect, lhs, rhs);
367+
}
294368
}
295369
}

com.unity.probuilder/Editor/EditorCore/EditorEnum.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,6 @@ enum SceneToolbarLocation
1616
BottomRight
1717
}
1818

19-
/// <summary>
20-
/// How the handle gizmo is oriented with regards to the current element selection.
21-
/// </summary>
22-
/// <remarks>
23-
/// This overrides the Unity Pivot / Global setting when editing vertices, faces, or edges.
24-
/// </remarks>
25-
/// <remarks>Editor only.</remarks>
26-
public enum HandleOrientation
27-
{
28-
/// <summary>
29-
/// The gizmo is aligned in world space.
30-
/// </summary>
31-
World = 0,
32-
/// <summary>
33-
/// The gizmo is aligned relative to the mesh transform. Also called coordinate or model space.
34-
/// </summary>
35-
Local = 1,
36-
/// <summary>
37-
/// The gizmo is aligned relative to the currently selected face. When editing vertices or edges, this falls back to <see cref="Local"/> alignment.
38-
/// </summary>
39-
Normal = 2
40-
}
41-
4219
/// <summary>
4320
/// When drag selecting mesh elements, this defines how the Shift key will modify the selection.
4421
/// </summary>

com.unity.probuilder/Editor/EditorCore/EditorGUIUtility.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,43 @@ namespace UnityEditor.ProBuilder.UI
1313
/// </summary>
1414
static class EditorGUIUtility
1515
{
16+
static class Styles
17+
{
18+
static bool s_Initialized;
19+
20+
public static GUIStyle command = "command";
21+
public static GUIContent[] selectModeIcons;
22+
23+
public static void Init()
24+
{
25+
if (s_Initialized)
26+
return;
27+
28+
s_Initialized = true;
29+
30+
var object_Graphic_off = IconUtility.GetIcon("Modes/Mode_Object");
31+
var face_Graphic_off = IconUtility.GetIcon("Modes/Mode_Face");
32+
var vertex_Graphic_off = IconUtility.GetIcon("Modes/Mode_Vertex");
33+
var edge_Graphic_off = IconUtility.GetIcon("Modes/Mode_Edge");
34+
35+
selectModeIcons = new GUIContent[]
36+
{
37+
object_Graphic_off != null
38+
? new GUIContent(object_Graphic_off, "Object Selection")
39+
: new GUIContent("OBJ", "Object Selection"),
40+
vertex_Graphic_off != null
41+
? new GUIContent(vertex_Graphic_off, "Vertex Selection")
42+
: new GUIContent("VRT", "Vertex Selection"),
43+
edge_Graphic_off != null
44+
? new GUIContent(edge_Graphic_off, "Edge Selection")
45+
: new GUIContent("EDG", "Edge Selection"),
46+
face_Graphic_off != null
47+
? new GUIContent(face_Graphic_off, "Face Selection")
48+
: new GUIContent("FCE", "Face Selection"),
49+
};
50+
}
51+
}
52+
1653
static readonly Color TOOL_SETTINGS_COLOR = UnityEditor.EditorGUIUtility.isProSkin
1754
? Color.green
1855
: new Color(.2f, .2f, .2f, .2f);
@@ -379,5 +416,54 @@ public static void SceneLabel(string text, Vector2 position)
379416

380417
GUI.Label(sceneLabelRect, gc, sceneBoldLabel);
381418
}
419+
420+
public static SelectMode DoElementModeToolbar(Rect rect, SelectMode mode)
421+
{
422+
Styles.Init();
423+
424+
EditorGUI.BeginChangeCheck();
425+
426+
var textureMode = mode.ContainsFlag(SelectMode.TextureVertex | SelectMode.TextureEdge | SelectMode.TextureFace);
427+
428+
int currentSelectionMode = -1;
429+
430+
switch (mode)
431+
{
432+
case SelectMode.Object:
433+
currentSelectionMode = 0;
434+
break;
435+
case SelectMode.Vertex:
436+
case SelectMode.TextureVertex:
437+
currentSelectionMode = 1;
438+
break;
439+
case SelectMode.Edge:
440+
case SelectMode.TextureEdge:
441+
currentSelectionMode = 2;
442+
break;
443+
case SelectMode.Face:
444+
case SelectMode.TextureFace:
445+
currentSelectionMode = 3;
446+
break;
447+
default:
448+
currentSelectionMode = -1;
449+
break;
450+
}
451+
452+
currentSelectionMode = GUI.Toolbar(rect, currentSelectionMode, Styles.selectModeIcons, Styles.command);
453+
454+
if (EditorGUI.EndChangeCheck())
455+
{
456+
if (currentSelectionMode == 0)
457+
mode = SelectMode.Object;
458+
else if (currentSelectionMode == 1)
459+
mode = textureMode ? SelectMode.TextureVertex : SelectMode.Vertex;
460+
else if (currentSelectionMode == 2)
461+
mode = textureMode ? SelectMode.TextureEdge : SelectMode.Edge;
462+
else if (currentSelectionMode == 3)
463+
mode = textureMode ? SelectMode.TextureFace : SelectMode.Face;
464+
}
465+
466+
return mode;
467+
}
382468
}
383469
}

com.unity.probuilder/Editor/EditorCore/EditorHandleUtility.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace UnityEditor.ProBuilder
1414
/// </summary>
1515
static class EditorHandleUtility
1616
{
17+
static Stack<Matrix4x4> s_HandleMatrix = new Stack<Matrix4x4>();
18+
1719
public static bool SceneViewInUse(Event e)
1820
{
1921
return e.alt
@@ -521,5 +523,50 @@ public static Vector3 ClosestPointToPolyLine(List<Vector3> vertices, out int ind
521523

522524
return trs != null ? trs.InverseTransformPoint(p) : p;
523525
}
526+
527+
internal static HandleOrientation ProBuilderHandleOrientation(this PivotRotation rotation)
528+
{
529+
if (rotation == PivotRotation.Global)
530+
return HandleOrientation.World;
531+
532+
if (rotation == PivotRotation.Local)
533+
return HandleOrientation.Local;
534+
535+
return HandleOrientation.Normal;
536+
}
537+
538+
internal static PivotRotation UnityPivotRotation(this HandleOrientation orientation)
539+
{
540+
if (orientation == HandleOrientation.World)
541+
return PivotRotation.Global;
542+
543+
return PivotRotation.Local;
544+
}
545+
546+
internal static PivotMode UnityPivot(this PivotPoint pivotPoint)
547+
{
548+
if (pivotPoint == PivotPoint.WorldBoundingBoxCenter)
549+
return PivotMode.Center;
550+
551+
return PivotMode.Pivot;
552+
}
553+
554+
internal static PivotPoint ProBuilderPivot(this PivotMode pivotMode)
555+
{
556+
if (pivotMode == PivotMode.Center)
557+
return PivotPoint.WorldBoundingBoxCenter;
558+
559+
return PivotPoint.ModelBoundingBoxCenter;
560+
}
561+
562+
internal static void PushMatrix()
563+
{
564+
s_HandleMatrix.Push(Handles.matrix);
565+
}
566+
567+
internal static void PopMatrix()
568+
{
569+
Handles.matrix = s_HandleMatrix.Pop();
570+
}
524571
}
525572
}

0 commit comments

Comments
 (0)