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

Added buttons for rotating slice in slice renderer window #179

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 18 additions & 7 deletions Assets/Editor/SliceRenderingEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class SliceRenderingEditorWindow : EditorWindow
private Texture moveIconTexture;
private Texture inspectIconTexture;
private Texture measureIconTexture;
private Texture lRotateIconTexture;
private Texture rRotateIconTexture;

private InputMode inputMode;

Expand Down Expand Up @@ -45,6 +47,8 @@ private void Awake()
moveIconTexture = Resources.Load<Texture>("Icons/MoveIcon");
inspectIconTexture = Resources.Load<Texture>("Icons/InspectIcon");
measureIconTexture = Resources.Load<Texture>("Icons/MeasureIcon");
lRotateIconTexture = Resources.Load<Texture>("Icons/RotateLeft");
rRotateIconTexture = Resources.Load<Texture>("Icons/RotateRight");
}

private void OnFocus()
Expand All @@ -71,25 +75,32 @@ private void OnGUI()
selectedPlaneIndex = index;
}

if (GUI.Toggle(new Rect(0.0f, 0.0f, 40.0f, 40.0f), inputMode == InputMode.Move, new GUIContent(moveIconTexture, "Move slice"), GUI.skin.button))
inputMode = InputMode.Move;
if (GUI.Toggle(new Rect(40.0f, 0.0f, 40.0f, 40.0f), inputMode == InputMode.Inspect, new GUIContent(inspectIconTexture, "Inspect values"), GUI.skin.button))
inputMode = InputMode.Inspect;
if (GUI.Toggle(new Rect(80.0f, 0.0f, 40.0f, 40.0f), inputMode == InputMode.Measure, new GUIContent(measureIconTexture, "Inspect values"), GUI.skin.button))
inputMode = InputMode.Measure;

Rect bgRect = new Rect(0.0f, 40.0f, 0.0f, 0.0f);

if (selectedPlaneIndex != -1 && spawnedPlanes.Length > 0)
{
SlicingPlane planeObj = spawnedPlanes[System.Math.Min(selectedPlaneIndex, spawnedPlanes.Length - 1)];
Vector3 planeScale = planeObj.transform.lossyScale;
Vector3 planeNormal = -planeObj.transform.up;

float heightWidthRatio = Mathf.Abs(planeScale.z / planeScale.x);
float bgWidth = Mathf.Min(this.position.width - 20.0f, (this.position.height - 50.0f) * 2.0f);
float bgHeight = Mathf.Min(bgWidth, this.position.height - 150.0f);
bgWidth = bgHeight / heightWidthRatio;
bgRect = new Rect(0.0f, 40.0f, bgWidth, bgHeight);

if (GUI.Toggle(new Rect(0.0f, 0.0f, 40.0f, 40.0f), inputMode == InputMode.Move, new GUIContent(moveIconTexture, "Move slice"), GUI.skin.button))
inputMode = InputMode.Move;
if (GUI.Toggle(new Rect(40.0f, 0.0f, 40.0f, 40.0f), inputMode == InputMode.Inspect, new GUIContent(inspectIconTexture, "Inspect values"), GUI.skin.button))
inputMode = InputMode.Inspect;
if (GUI.Toggle(new Rect(80.0f, 0.0f, 40.0f, 40.0f), inputMode == InputMode.Measure, new GUIContent(measureIconTexture, "Inspect values"), GUI.skin.button))
inputMode = InputMode.Measure;

if (GUI.Toggle(new Rect(bgWidth - 80.0f, 0.0f, 40.0f, 40.0f), inputMode == InputMode.Measure, new GUIContent(lRotateIconTexture, "Rotate plane to the right"), GUI.skin.button))
planeObj.transform.Rotate(planeNormal * -90.0f, Space.World);
if (GUI.Toggle(new Rect(bgWidth - 40.0f, 0.0f, 40.0f, 40.0f), inputMode == InputMode.Measure, new GUIContent(rRotateIconTexture, "Rotate plane to the left"), GUI.skin.button))
planeObj.transform.Rotate(planeNormal * 90.0f, Space.World);


// Draw the slice view
Material mat = planeObj.GetComponent<MeshRenderer>().sharedMaterial;
Expand Down
Binary file added Assets/Resources/Icons/RotateLeft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions Assets/Resources/Icons/RotateLeft.png.meta

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

Binary file added Assets/Resources/Icons/RotateRight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions Assets/Resources/Icons/RotateRight.png.meta

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