Skip to content
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

Update from sabresaurus #5

Merged
merged 27 commits into from
Jan 13, 2019
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8239d2e
try to fix Optimize Geometry
guizix Dec 28, 2018
6456030
Update from sabresaurus master
jmickle66666666 Jan 8, 2019
ce22689
Move brush count to CSGModel inspector
jmickle66666666 Jan 8, 2019
ed7d34b
Merge branch 'toolbar-rework' of https://github.com/jmickle66666666/S…
jmickle66666666 Jan 8, 2019
ed17931
Remove Prefs/Disable buttons from toolbar
jmickle66666666 Jan 8, 2019
c42966a
Rework primitive brush menu
jmickle66666666 Jan 8, 2019
ce434ca
Move brush settings to new menu
jmickle66666666 Jan 8, 2019
59d85e8
Move transform settings to brush menu
jmickle66666666 Jan 8, 2019
2e3c58b
Move viewport and grid settings to menu
jmickle66666666 Jan 8, 2019
b15633d
Brush menu tweaks
jmickle66666666 Jan 8, 2019
febe4e2
Fix lightened text when using Pro color scheme
jmickle66666666 Jan 8, 2019
d841e3d
Use toolbar for brush flip commands
jmickle66666666 Jan 8, 2019
727aae7
Added hotkey tooltips to viewport settings
jmickle66666666 Jan 8, 2019
1bfe364
Only show brush settings when in resize mode
jmickle66666666 Jan 8, 2019
ce6cf3c
Use in-built editorstyles instead of creating new ones
jmickle66666666 Jan 8, 2019
b809fd0
Strictly define styles for labels
jmickle66666666 Jan 8, 2019
10657b2
Replace GUILayout.Toggle with EditorGUILayout.Toggle for cleaner ui code
jmickle66666666 Jan 8, 2019
0e4c759
Move brush menu to ResizeEditor
jmickle66666666 Jan 9, 2019
91a9a13
Fix null reference error
jmickle66666666 Jan 9, 2019
8671c41
Fix resize bounds window and viewport settings disappearing
jmickle66666666 Jan 11, 2019
3361b6b
Dynamically resize gridsize field
jmickle66666666 Jan 11, 2019
0b8db1d
Scale new brushes by current grid size
jmickle66666666 Jan 11, 2019
23cb1ac
Merge pull request #211 from jmickle66666666/primitive-brush-grid-scale
Henry00IS Jan 12, 2019
6acee78
Merge pull request #202 from guizix/master
Henry00IS Jan 12, 2019
d9cf768
Fixed black more button gizmo in Unity 5.3.
Henry00IS Jan 12, 2019
0803320
Prevent toolbar menus from allowing selection
jmickle66666666 Jan 12, 2019
f57fca7
Merge pull request #207 from jmickle66666666/toolbar-rework
Henry00IS Jan 12, 2019
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
Prev Previous commit
Next Next commit
Move brush menu to ResizeEditor
Makes more sense in terms of code layout, and fixes an inconsistency with the brush selection information
jmickle66666666 committed Jan 9, 2019

Verified

This commit was signed with the committer’s verified signature.
elliottower Elliot Tower
commit 0e4c7593b3e0771fffe4de591aaa22b2cc693dd2
206 changes: 206 additions & 0 deletions Scripts/Tools/ResizeEditor.cs
Original file line number Diff line number Diff line change
@@ -90,6 +90,18 @@ private enum ActiveMode
new ResizeHandlePair(new Vector3(0,0,1)),
};

private string[] brushModeSettings = new string[] {
"Add",
"Subtract",
"Volume",
"NoCSG"
};

Rect brushMenuRect;

public const int BRUSH_MENU_WIDTH = 130;
public const int BRUSH_MENU_HEIGHT = 132;

public override void OnSceneGUI(SceneView sceneView, Event e)
{
base.OnSceneGUI(sceneView, e); // Allow the base logic to calculate first
@@ -1276,14 +1288,208 @@ public void OnRepaint(SceneView sceneView, Event e)
style.normal.background = SabreCSGResources.ClearTexture;
Rect rectangle = new Rect(0, 50, 300, 50);
style.fixedHeight = rectangle.height;

brushMenuRect = new Rect(
0,
(sceneView.position.height - Toolbar.bottomToolbarHeight) - BRUSH_MENU_HEIGHT,
BRUSH_MENU_WIDTH,
BRUSH_MENU_HEIGHT
);

GUILayout.Window(140007, rectangle, OnTopToolbarGUI, "", style);

if (primaryTargetBrushBase != null)
{
if (Toolbar.primitiveMenuShowing) {
brushMenuRect.y -= Toolbar.PRIMITIVE_MENU_HEIGHT;
}
style = new GUIStyle(EditorStyles.toolbar);
style.fixedWidth = BRUSH_MENU_WIDTH;
style.fixedHeight = BRUSH_MENU_HEIGHT;
GUILayout.Window(140008, brushMenuRect, OnBrushSettingsGUI, "", style);
}
}

private void OnTopToolbarGUI(int windowID)
{
widgetMode = SabreGUILayout.DrawEnumGrid(widgetMode, GUILayout.Width(67));
}

private void OnBrushSettingsGUI(int windowID) {
GUILayout.BeginHorizontal();
GUILayout.Label("Brush Settings", EditorStyles.boldLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();

EditorGUIUtility.labelWidth = 58f;

GUILayout.Label ("Mode", EditorStyles.label);

GUILayout.FlexibleSpace();

string currentBrushMode = "";

if (primaryTargetBrush.IsNoCSG) {
currentBrushMode = "NoCSG";
} else {
currentBrushMode = primaryTargetBrush.Mode.ToString();
}
int currentModeIndex = System.Array.IndexOf(brushModeSettings, currentBrushMode);

string brushMode = brushModeSettings[EditorGUILayout.Popup("", currentModeIndex, brushModeSettings, GUILayout.Width(60))];
if(brushMode != currentBrushMode)
{
bool anyChanged = false;

foreach (BrushBase brush in targetBrushBases)
{
Undo.RecordObject(brush, "Change Brush To " + brushMode);

switch (brushMode) {
case "Add":
brush.Mode = CSGMode.Add;
brush.IsNoCSG = false;
break;
case "Subtract":
brush.Mode = CSGMode.Subtract;
brush.IsNoCSG = false;
break;
case "Volume":
brush.Mode = CSGMode.Volume;
brush.IsNoCSG = false;
break;
case "NoCSG":
// Volume overrides NoCSG, so it must be changed if you select NoCSG
if (brush.Mode == CSGMode.Volume) {
brush.Mode = CSGMode.Add;
}
brush.IsNoCSG = true;
break;
}
anyChanged = true;
}
if(anyChanged)
{
// Need to update the icon for the csg mode in the hierarchy
EditorApplication.RepaintHierarchyWindow();

foreach (BrushBase b in targetBrushBases)
{
b.Invalidate(true);
}
}
}

GUILayout.EndHorizontal();

bool[] collisionStates = targetBrushBases.Select(item => item.HasCollision).Distinct().ToArray();
bool hasCollision = (collisionStates.Length == 1) ? collisionStates[0] : false;

GUIStyle toggleStyle = new GUIStyle(GUI.skin.toggle);

// TODO: If the brushes are all volumes, the collision and visible checkboxes should be disabled

// bool allVolumes = true;
// foreach (BrushBase brush in selectedBrushes)
// {
// if (brush.Mode != CSGMode.Volume) {
// allVolumes = false;
// }
// }

bool newHasCollision = EditorGUILayout.Toggle("Collision", hasCollision);

if(newHasCollision != hasCollision)
{
foreach (BrushBase brush in targetBrushBases)
{
Undo.RecordObject(brush, "Change Brush Collision Mode");
brush.HasCollision = newHasCollision;
}
// Tell the brushes that they have changed and need to recalc intersections
foreach (BrushBase brush in targetBrushBases)
{
brush.Invalidate(true);
}
}

bool[] visibleStates = targetBrushBases.Select(item => item.IsVisible).Distinct().ToArray();
bool isVisible = (visibleStates.Length == 1) ? visibleStates[0] : false;

bool newIsVisible = EditorGUILayout.Toggle("Visible", isVisible);

if(newIsVisible != isVisible)
{
foreach (BrushBase brush in targetBrushBases)
{
Undo.RecordObject(brush, "Change Brush Visible Mode");
brush.IsVisible = newIsVisible;
}
// Tell the brushes that they have changed and need to recalc intersections
foreach (BrushBase brush in targetBrushBases)
{
brush.Invalidate(true);
}
if(newIsVisible == false)
{
csgModel.NotifyPolygonsRemoved();
}
}

GUILayout.BeginHorizontal();

GUILayout.Label("Flip", EditorStyles.label);
GUILayout.FlexibleSpace();

string[] flipToolbarStrings = {"X","Y","Z"};
int flipIndex = -1;
if(GUILayout.Button("X", EditorStyles.miniButtonLeft, GUILayout.Width(20)))
{
flipIndex = 0;
}
if (GUILayout.Button("Y", EditorStyles.miniButtonMid, GUILayout.Width(20)))
{
flipIndex = 1;
}
if (GUILayout.Button("Z", EditorStyles.miniButtonRight, GUILayout.Width(20)))
{
flipIndex = 2;
}

if (flipIndex != -1)
{
Undo.RecordObjects(targetBrushBases.ToArray(), "Flip Polygons");

bool localToPrimaryBrush = (Tools.pivotRotation == PivotRotation.Local);
BrushUtility.Flip(primaryTargetBrush, targetBrushBases.ToArray(), flipIndex, localToPrimaryBrush, GetBrushesPivotPoint());
}

GUILayout.EndHorizontal();

if (GUILayout.Button("Snap Center", EditorStyles.miniButton))
{
for (int i = 0; i < targetBrushBases.Length; i++)
{
Undo.RecordObject(targetBrushBases[i].transform, "Snap Center");
Undo.RecordObject(targetBrushBases[i], "Snap Center");

Vector3 newPosition = targetBrushBases[i].transform.position;

float snapDistance = CurrentSettings.PositionSnapDistance;
newPosition = MathHelper.RoundVector3(newPosition, snapDistance);
targetBrushBases[i].transform.position = newPosition;
targetBrushBases[i].Invalidate(true);
}
}

GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(targetBrushBases.Length + " selected", EditorStyles.miniLabel);
GUILayout.EndHorizontal();

}

public void RescaleBrush(Vector3 direction, Vector3 translation)
{
if (translation == Vector3.zero)
281 changes: 1 addition & 280 deletions Scripts/UI/Toolbar.cs
Original file line number Diff line number Diff line change
@@ -13,22 +13,11 @@ public static class Toolbar
public const int BOTTOM_TOOLBAR_HEIGHT = 20;
public const int PRIMITIVE_MENU_WIDTH = 200;
public const int PRIMITIVE_MENU_HEIGHT = 70;
public const int BRUSH_MENU_WIDTH = 130;
public const int BRUSH_MENU_HEIGHT = 132;
public const int VIEW_MENU_WIDTH = 220;
public const int VIEW_MENU_HEIGHT = 190;

public static int bottomToolbarHeight;

static BrushBase primaryBrush;
static List<BrushBase> selectedBrushes;
static string[] brushModeSettings = new string[] {
"Add",
"Subtract",
"Volume",
"NoCSG"
};

static string[] gridTypeSettings = new string[] {
"Unity",
"SabreCSG",
@@ -39,7 +28,7 @@ public static class Toolbar

static string warningMessage = "Concave brushes detected";

static bool primitiveMenuShowing = false;
public static bool primitiveMenuShowing = false;
static bool viewMenuShowing = false;

// If the viewport is too squashed to show everything on one line
@@ -94,39 +83,6 @@ private static void OnRepaint(SceneView sceneView, Event e)
style.fixedHeight = bottomToolbarHeight;
GUILayout.Window(140003, rectangle, OnBottomToolbarGUI, "", style);

// Brush menu
if (CurrentSettings.CurrentMode == MainMode.Resize && Selection.activeGameObject != null)
{
style = new GUIStyle(EditorStyles.toolbar);
primaryBrush = Selection.activeGameObject.GetComponent<BrushBase>();
selectedBrushes = new List<BrushBase>();
for (int i = 0; i < Selection.gameObjects.Length; i++)
{
BrushBase brush = Selection.gameObjects[i].GetComponent<BrushBase>();
if (brush != null)
{
selectedBrushes.Add(brush);
}
}
if (primaryBrush != null && primaryBrush.SupportsCsgOperations)
{
Rect brushMenuRect = new Rect(
0,
(sceneView.position.height - bottomToolbarHeight) - BRUSH_MENU_HEIGHT,
BRUSH_MENU_WIDTH,
BRUSH_MENU_HEIGHT
);

if (primitiveMenuShowing) {
brushMenuRect.y -= PRIMITIVE_MENU_HEIGHT;
}

style.fixedWidth = BRUSH_MENU_WIDTH;
style.fixedHeight = BRUSH_MENU_HEIGHT;
GUILayout.Window(140008, brushMenuRect, OnBrushSettingsGUI, "", style);
}
}

if (primitiveMenuShowing) {
style = new GUIStyle(EditorStyles.toolbar);
Rect primitiveMenuRect = new Rect(
@@ -226,68 +182,6 @@ private static void OnWarningToolbar(int windowID)
GUILayout.EndHorizontal();
}

// Calculate the bounds for all selected brushes, respecting the current pivotRotation mode to produce
// bounds aligned to the first selected brush in Local mode, or bounds aligned to the absolute grid in Global
// mode.
static Bounds GetBounds()
{
Bounds bounds;

if(Tools.pivotRotation == PivotRotation.Local)
{
bounds = primaryBrush.GetBounds();

for (int i = 0; i < selectedBrushes.Count; i++)
{
if(selectedBrushes[i] != primaryBrush)
{
bounds.Encapsulate(selectedBrushes[i].GetBoundsLocalTo(primaryBrush.transform));
}
}
}
else // Absolute/Global
{
bounds = primaryBrush.GetBoundsTransformed();
for (int i = 0; i < selectedBrushes.Count; i++)
{
if(selectedBrushes[i] != primaryBrush)
{
bounds.Encapsulate(selectedBrushes[i].GetBoundsTransformed());
}
}
}

return bounds;
}

private static Vector3 GetSelectedBrushesPivotPoint()
{
if (primaryBrush != null)
{
if (Tools.pivotMode == PivotMode.Center)
{
Bounds bounds = GetBounds();
if (Tools.pivotRotation == PivotRotation.Global)
{
return bounds.center;
}
else
{
return primaryBrush.transform.TransformPoint(bounds.center);
}
}
else // Local mode
{
// Just return the position of the primary selected brush
return primaryBrush.transform.position;
}
}
else
{
return Vector3.zero;
}
}

static Vector3 GetPositionForNewBrush()
{
Vector3 newPosition = Vector3.zero;
@@ -529,179 +423,6 @@ static void OnViewMenuGUI(int windowID) {
GUILayout.EndHorizontal();
}

static void OnBrushSettingsGUI(int windowID) {
GUILayout.BeginHorizontal();
GUILayout.Label("Brush Settings", EditorStyles.boldLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();

EditorGUIUtility.labelWidth = 58f;

GUILayout.Label ("Mode", EditorStyles.label);

GUILayout.FlexibleSpace();

string currentBrushMode = "";
if (primaryBrush.IsNoCSG) {
currentBrushMode = "NoCSG";
} else {
currentBrushMode = primaryBrush.Mode.ToString();
}
int currentModeIndex = Array.IndexOf(brushModeSettings, currentBrushMode);

string brushMode = brushModeSettings[EditorGUILayout.Popup("", currentModeIndex, brushModeSettings, GUILayout.Width(60))];
if(brushMode != currentBrushMode)
{
bool anyChanged = false;

foreach (BrushBase brush in selectedBrushes)
{
Undo.RecordObject(brush, "Change Brush To " + brushMode);

switch (brushMode) {
case "Add":
brush.Mode = CSGMode.Add;
brush.IsNoCSG = false;
break;
case "Subtract":
brush.Mode = CSGMode.Subtract;
brush.IsNoCSG = false;
break;
case "Volume":
brush.Mode = CSGMode.Volume;
brush.IsNoCSG = false;
break;
case "NoCSG":
// Volume overrides NoCSG, so it must be changed if you select NoCSG
if (brush.Mode == CSGMode.Volume) {
brush.Mode = CSGMode.Add;
}
brush.IsNoCSG = true;
break;
}
anyChanged = true;
}
if(anyChanged)
{
// Need to update the icon for the csg mode in the hierarchy
EditorApplication.RepaintHierarchyWindow();

foreach (BrushBase b in selectedBrushes)
{
b.Invalidate(true);
}
}
}

GUILayout.EndHorizontal();

bool[] collisionStates = selectedBrushes.Select(item => item.HasCollision).Distinct().ToArray();
bool hasCollision = (collisionStates.Length == 1) ? collisionStates[0] : false;

GUIStyle toggleStyle = new GUIStyle(GUI.skin.toggle);

// TODO: If the brushes are all volumes, the collision and visible checkboxes should be disabled

// bool allVolumes = true;
// foreach (BrushBase brush in selectedBrushes)
// {
// if (brush.Mode != CSGMode.Volume) {
// allVolumes = false;
// }
// }
bool newHasCollision = EditorGUILayout.Toggle("Collision", hasCollision);

if(newHasCollision != hasCollision)
{
foreach (BrushBase brush in selectedBrushes)
{
Undo.RecordObject(brush, "Change Brush Collision Mode");
brush.HasCollision = newHasCollision;
}
// Tell the brushes that they have changed and need to recalc intersections
foreach (BrushBase brush in selectedBrushes)
{
brush.Invalidate(true);
}
}

bool[] visibleStates = selectedBrushes.Select(item => item.IsVisible).Distinct().ToArray();
bool isVisible = (visibleStates.Length == 1) ? visibleStates[0] : false;

bool newIsVisible = EditorGUILayout.Toggle("Visible", isVisible);

if(newIsVisible != isVisible)
{
foreach (BrushBase brush in selectedBrushes)
{
Undo.RecordObject(brush, "Change Brush Visible Mode");
brush.IsVisible = newIsVisible;
}
// Tell the brushes that they have changed and need to recalc intersections
foreach (BrushBase brush in selectedBrushes)
{
brush.Invalidate(true);
}
if(newIsVisible == false)
{
csgModel.NotifyPolygonsRemoved();
}
}

GUILayout.BeginHorizontal();

GUILayout.Label("Flip", EditorStyles.label);
GUILayout.FlexibleSpace();

string[] flipToolbarStrings = {"X","Y","Z"};
int flipIndex = -1;
if(GUILayout.Button("X", EditorStyles.miniButtonLeft, GUILayout.Width(20)))
{
flipIndex = 0;
}
if (GUILayout.Button("Y", EditorStyles.miniButtonMid, GUILayout.Width(20)))
{
flipIndex = 1;
}
if (GUILayout.Button("Z", EditorStyles.miniButtonRight, GUILayout.Width(20)))
{
flipIndex = 2;
}

if (flipIndex != -1)
{
Undo.RecordObjects(selectedBrushes.ToArray(), "Flip Polygons");

bool localToPrimaryBrush = (Tools.pivotRotation == PivotRotation.Local);
BrushUtility.Flip(primaryBrush, selectedBrushes.ToArray(), flipIndex, localToPrimaryBrush, GetSelectedBrushesPivotPoint());
}

GUILayout.EndHorizontal();

if (GUILayout.Button("Snap Center", EditorStyles.miniButton))
{
for (int i = 0; i < selectedBrushes.Count; i++)
{
Undo.RecordObject(selectedBrushes[i].transform, "Snap Center");
Undo.RecordObject(selectedBrushes[i], "Snap Center");

Vector3 newPosition = selectedBrushes[i].transform.position;

float snapDistance = CurrentSettings.PositionSnapDistance;
newPosition = MathHelper.RoundVector3(newPosition, snapDistance);
selectedBrushes[i].transform.position = newPosition;
selectedBrushes[i].Invalidate(true);
}
}

GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(selectedBrushes.Count + " selected", EditorStyles.miniLabel);
GUILayout.EndHorizontal();

}

static void OnPrimitiveMenuGUI(int windowID) {
GUIStyle createBrushStyle = new GUIStyle(EditorStyles.toolbarButton);
createBrushStyle.fixedHeight = 20;