Skip to content

Handle refactor #2

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

Merged
merged 30 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b41e08d
initial commit
Oct 18, 2018
f850c3f
support translate in world and model space
Oct 18, 2018
b70ff8b
wip - use new tool classes for rotate and scale
Oct 18, 2018
19d0585
move action implementations to their menu class instead of a monolith…
Oct 19, 2018
f5bfcb5
remove MenuCommands class
Oct 19, 2018
59fd1fa
include missing reference
Oct 19, 2018
3b87eed
change internal storage of mesh selection to list
Oct 19, 2018
c36a712
Merge branch 'remove-menucommands' into handle-refactor
Oct 19, 2018
33f53bf
show a gizmo with the object orientation when moving handles in pivot…
Oct 19, 2018
d1ca332
wip - applying handle transforms in correct coordinate space
Oct 19, 2018
ccbc830
Get rotate tool working with world/pivot and handle orientation
Oct 24, 2018
fc331ee
remove debug code
Oct 24, 2018
93c730b
draw handle guide in world coordinates too
Oct 24, 2018
f5c5d7e
move vertex manipulation tools to their own files
Oct 24, 2018
cf362ed
pivot + normal orientation uses face selection groups for coordinate …
Oct 24, 2018
85d6fbc
support vertex snapping in move tool
Oct 25, 2018
dc14fa2
Merge branch 'rename-settingscopes-2019-1' into handle-refactor
Oct 26, 2018
fefc8fc
Enable relative snapping when progrids is enabled with move tool
Oct 26, 2018
1f0f788
support progrids snapping to world space when possible
Oct 26, 2018
e952047
fix scene not moving handle to correct position after changing orient…
Oct 26, 2018
d940206
Fix bug where selected face groups wouldn't gather correctly
Oct 26, 2018
ae7db72
wip - adding texture manipulation tools
Oct 29, 2018
54680eb
implement texture tools
Oct 30, 2018
66ed617
Merge branch 'master' of https://github.com/Unity-Technologies/com.un…
Nov 3, 2018
d0781dc
fix minor compile errors after trunk merge
Nov 3, 2018
beead49
fix tests sometimes not creating temporary directories
Nov 3, 2018
c02cf5d
fix null ref in cases where window layout is reloaded
Nov 4, 2018
f954a1e
Fix mesh element gizmos not repainting when changing selectmode
Nov 4, 2018
9e7b60d
fix compile error on 2018.3
Nov 5, 2018
820cea2
bump changelog 4.0.0-preview.28
Nov 5, 2018
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
4 changes: 3 additions & 1 deletion com.unity.probuilder.tests/Tests/Framework/TestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@

namespace UnityEngine.ProBuilder.Tests.Framework
{
abstract class TemporaryAssetTest : IPrebuildSetup, IPostBuildCleanup
abstract class TemporaryAssetTest
{
[SetUp]
public void Setup()
{
if (!Directory.Exists(TestUtility.TemporarySavedAssetsDirectory))
Directory.CreateDirectory(TestUtility.TemporarySavedAssetsDirectory);
}

[TearDown]
public void Cleanup()
{
if (Directory.Exists(TestUtility.TemporarySavedAssetsDirectory))
Expand Down
15 changes: 10 additions & 5 deletions com.unity.probuilder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

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

### Features

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

### Changes since 4.0.0-preview.26
### Changes since 4.0.0-preview.27

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

## [3.0.8] - 2018-05-07

Expand Down
3 changes: 2 additions & 1 deletion com.unity.probuilder/Content/Shader/FaceHighlight.shader
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Shader "Hidden/ProBuilder/FaceHighlight"
{
_Color ("Color Tint", Color) = (1,1,1,1)
_Dither ("Dithering", float) = 0
_HandleZTest ("_HandleZTest", Int) = 8
}

SubShader
{
Tags { "IgnoreProjector"="True" "RenderType"="Geometry" }
Lighting Off
ZTest LEqual
ZTest [_HandleZTest]
ZWrite On
Cull Off
Blend Off
Expand Down
3 changes: 2 additions & 1 deletion com.unity.probuilder/Content/Shader/LineBillboard.shader
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
_Color ("Color", Color) = (1,1,1,1)
_Scale ("Scale", Range(0, 20)) = 7
_HandleZTest ("_HandleZTest", Int) = 8
}

SubShader
Expand All @@ -19,7 +20,7 @@
}

Lighting Off
ZTest LEqual
ZTest [_HandleZTest]
ZWrite On
Cull Off
Blend Off
Expand Down
7 changes: 0 additions & 7 deletions com.unity.probuilder/Debug/Editor/TempMenuItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ class TempMenuItems : EditorWindow
[MenuItem("Tools/Temp Menu Item &d", false, 1000)]
static void MenuInit()
{
string[] search = new[]
{
"Assets/Temp.cs",
"Assets/*.cs",
"*.cs"
};


}

Expand Down
80 changes: 77 additions & 3 deletions com.unity.probuilder/Editor/EditorCore/BooleanEditor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using UnityEngine;
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.Experimental.CSG;
using UnityEngine.ProBuilder.MeshOperations;

namespace UnityEditor.ProBuilder
{
Expand Down Expand Up @@ -155,15 +157,15 @@ void OnGUI()
switch(operation)
{
case BooleanOp.Union:
MenuCommands.MenuUnion(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
MenuUnion(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
break;

case BooleanOp.Intersection:
MenuCommands.MenuIntersect(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
MenuIntersect(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
break;

case BooleanOp.Subtraction:
MenuCommands.MenuSubtract(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
MenuSubtract(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
break;
}
}
Expand Down Expand Up @@ -291,5 +293,77 @@ bool ListenForDragAndDrop()
}
return false;
}

enum BooleanOperation
{
Union,
Subtract,
Intersect
}

static ActionResult MenuBooleanOperation(BooleanOperation operation, ProBuilderMesh lhs, ProBuilderMesh rhs)
{
if(lhs == null || rhs == null)
return new ActionResult(ActionResult.Status.Failure, "Must Select 2 Objects");

string op_string = operation == BooleanOperation.Union ? "Union" : (operation == BooleanOperation.Subtract ? "Subtract" : "Intersect");

ProBuilderMesh[] sel = new ProBuilderMesh[] { lhs, rhs };

UndoUtility.RecordSelection(sel, op_string);

Mesh c;

switch(operation)
{
case BooleanOperation.Union:
c = CSG.Union(lhs.gameObject, rhs.gameObject);
break;

case BooleanOperation.Subtract:
c = CSG.Subtract(lhs.gameObject, rhs.gameObject);
break;

default:
c = CSG.Intersect(lhs.gameObject, rhs.gameObject);
break;
}

GameObject go = new GameObject();

go.AddComponent<MeshRenderer>().sharedMaterial = EditorUtility.GetUserMaterial();
go.AddComponent<MeshFilter>().sharedMesh = c;

ProBuilderMesh pb = InternalMeshUtility.CreateMeshWithTransform(go.transform, false);
DestroyImmediate(go);

Selection.objects = new Object[] { pb.gameObject };

return new ActionResult(ActionResult.Status.Success, op_string);
}

/**
* Union operation between two ProBuilder objects.
*/
public static ActionResult MenuUnion(ProBuilderMesh lhs, ProBuilderMesh rhs)
{
return MenuBooleanOperation(BooleanOperation.Union, lhs, rhs);
}

/**
* Subtract boolean operation between two pb_Objects.
*/
public static ActionResult MenuSubtract(ProBuilderMesh lhs, ProBuilderMesh rhs)
{
return MenuBooleanOperation(BooleanOperation.Subtract, lhs, rhs);
}

/**
* Intersect boolean operation between two pb_Objects.
*/
public static ActionResult MenuIntersect(ProBuilderMesh lhs, ProBuilderMesh rhs)
{
return MenuBooleanOperation(BooleanOperation.Intersect, lhs, rhs);
}
}
}
23 changes: 0 additions & 23 deletions com.unity.probuilder/Editor/EditorCore/EditorEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@ enum SceneToolbarLocation
BottomRight
}

/// <summary>
/// How the handle gizmo is oriented with regards to the current element selection.
/// </summary>
/// <remarks>
/// This overrides the Unity Pivot / Global setting when editing vertices, faces, or edges.
/// </remarks>
/// <remarks>Editor only.</remarks>
public enum HandleOrientation
{
/// <summary>
/// The gizmo is aligned in world space.
/// </summary>
World = 0,
/// <summary>
/// The gizmo is aligned relative to the mesh transform. Also called coordinate or model space.
/// </summary>
Local = 1,
/// <summary>
/// The gizmo is aligned relative to the currently selected face. When editing vertices or edges, this falls back to <see cref="Local"/> alignment.
/// </summary>
Normal = 2
}

/// <summary>
/// When drag selecting mesh elements, this defines how the Shift key will modify the selection.
/// </summary>
Expand Down
86 changes: 86 additions & 0 deletions com.unity.probuilder/Editor/EditorCore/EditorGUIUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,43 @@ namespace UnityEditor.ProBuilder.UI
/// </summary>
static class EditorGUIUtility
{
static class Styles
{
static bool s_Initialized;

public static GUIStyle command = "command";
public static GUIContent[] selectModeIcons;

public static void Init()
{
if (s_Initialized)
return;

s_Initialized = true;

var object_Graphic_off = IconUtility.GetIcon("Modes/Mode_Object");
var face_Graphic_off = IconUtility.GetIcon("Modes/Mode_Face");
var vertex_Graphic_off = IconUtility.GetIcon("Modes/Mode_Vertex");
var edge_Graphic_off = IconUtility.GetIcon("Modes/Mode_Edge");

selectModeIcons = new GUIContent[]
{
object_Graphic_off != null
? new GUIContent(object_Graphic_off, "Object Selection")
: new GUIContent("OBJ", "Object Selection"),
vertex_Graphic_off != null
? new GUIContent(vertex_Graphic_off, "Vertex Selection")
: new GUIContent("VRT", "Vertex Selection"),
edge_Graphic_off != null
? new GUIContent(edge_Graphic_off, "Edge Selection")
: new GUIContent("EDG", "Edge Selection"),
face_Graphic_off != null
? new GUIContent(face_Graphic_off, "Face Selection")
: new GUIContent("FCE", "Face Selection"),
};
}
}

static readonly Color TOOL_SETTINGS_COLOR = UnityEditor.EditorGUIUtility.isProSkin
? Color.green
: new Color(.2f, .2f, .2f, .2f);
Expand Down Expand Up @@ -379,5 +416,54 @@ public static void SceneLabel(string text, Vector2 position)

GUI.Label(sceneLabelRect, gc, sceneBoldLabel);
}

public static SelectMode DoElementModeToolbar(Rect rect, SelectMode mode)
{
Styles.Init();

EditorGUI.BeginChangeCheck();

var textureMode = mode.ContainsFlag(SelectMode.TextureVertex | SelectMode.TextureEdge | SelectMode.TextureFace);

int currentSelectionMode = -1;

switch (mode)
{
case SelectMode.Object:
currentSelectionMode = 0;
break;
case SelectMode.Vertex:
case SelectMode.TextureVertex:
currentSelectionMode = 1;
break;
case SelectMode.Edge:
case SelectMode.TextureEdge:
currentSelectionMode = 2;
break;
case SelectMode.Face:
case SelectMode.TextureFace:
currentSelectionMode = 3;
break;
default:
currentSelectionMode = -1;
break;
}

currentSelectionMode = GUI.Toolbar(rect, currentSelectionMode, Styles.selectModeIcons, Styles.command);

if (EditorGUI.EndChangeCheck())
{
if (currentSelectionMode == 0)
mode = SelectMode.Object;
else if (currentSelectionMode == 1)
mode = textureMode ? SelectMode.TextureVertex : SelectMode.Vertex;
else if (currentSelectionMode == 2)
mode = textureMode ? SelectMode.TextureEdge : SelectMode.Edge;
else if (currentSelectionMode == 3)
mode = textureMode ? SelectMode.TextureFace : SelectMode.Face;
}

return mode;
}
}
}
47 changes: 47 additions & 0 deletions com.unity.probuilder/Editor/EditorCore/EditorHandleUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace UnityEditor.ProBuilder
/// </summary>
static class EditorHandleUtility
{
static Stack<Matrix4x4> s_HandleMatrix = new Stack<Matrix4x4>();

public static bool SceneViewInUse(Event e)
{
return e.alt
Expand Down Expand Up @@ -521,5 +523,50 @@ public static Vector3 ClosestPointToPolyLine(List<Vector3> vertices, out int ind

return trs != null ? trs.InverseTransformPoint(p) : p;
}

internal static HandleOrientation ProBuilderHandleOrientation(this PivotRotation rotation)
{
if (rotation == PivotRotation.Global)
return HandleOrientation.World;

if (rotation == PivotRotation.Local)
return HandleOrientation.Local;

return HandleOrientation.Normal;
}

internal static PivotRotation UnityPivotRotation(this HandleOrientation orientation)
{
if (orientation == HandleOrientation.World)
return PivotRotation.Global;

return PivotRotation.Local;
}

internal static PivotMode UnityPivot(this PivotPoint pivotPoint)
{
if (pivotPoint == PivotPoint.WorldBoundingBoxCenter)
return PivotMode.Center;

return PivotMode.Pivot;
}

internal static PivotPoint ProBuilderPivot(this PivotMode pivotMode)
{
if (pivotMode == PivotMode.Center)
return PivotPoint.WorldBoundingBoxCenter;

return PivotPoint.ModelBoundingBoxCenter;
}

internal static void PushMatrix()
{
s_HandleMatrix.Push(Handles.matrix);
}

internal static void PopMatrix()
{
Handles.matrix = s_HandleMatrix.Pop();
}
}
}
Loading