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

Various bugfix from Gabe #571

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ 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).

## Unreleased

### Fixed

- [STO-3427] Fixing a bug where Polyshape creation tool was not working with orthographic camera.
- [STO-3429] Fixing a bug where increment snapping was ignored when drawing ProBuilder shapes.
- [STO-3432] Fixing a bug where Polyshape creation tool was not placing properly the first point on a custom grids.
Comment on lines +12 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [STO-3427] Fixing a bug where Polyshape creation tool was not working with orthographic camera.
- [STO-3429] Fixing a bug where increment snapping was ignored when drawing ProBuilder shapes.
- [STO-3432] Fixing a bug where Polyshape creation tool was not placing properly the first point on a custom grids.
- [STO-3427] Fixed a bug where Polyshape creation tool was not working with orthographic camera.
- [STO-3429] Fixed a bug where increment snapping was ignored when drawing ProBuilder shapes.
- [STO-3432] Fixed a bug where Polyshape creation tool was not placing properly the first point on a custom grids.


## [6.0.4] - 2024-09-12

### Changes
Expand Down
3 changes: 1 addition & 2 deletions Editor/EditorCore/EditorHandleUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ static Vector3 GetBitangent(Vector3 planeNormal)
/// Get a plane suitable for mouse input in a scene view.
/// </summary>
/// <param name="mousePosition"></param>
/// <param name="alignOnGrid"></param>
/// <returns></returns>
internal static Plane FindBestPlane(Vector2 mousePosition)
{
Expand Down Expand Up @@ -660,7 +659,7 @@ static bool GetPlaneFromProGridsAxis(Vector2 mousePosition, out Plane plane)
return true;
}

static Plane GetPlaneFromSceneView()
internal static Plane GetPlaneFromSceneView()
{
Plane plane;
Vector3 normal = Vector3.up;
Expand Down
83 changes: 53 additions & 30 deletions Editor/EditorCore/PolyShapeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ public override void OnWillBeDeactivated()

public override void OnToolGUI(EditorWindow window)
{
if (m_PolyShape == null)
if (m_PolyShape == null || polygon == null)
{
if(m_PolyShape)
m_LastPolyShape = m_PolyShape.gameObject;

if (!TryCreatePolyShape())
{
ToolManager.RestorePreviousTool();
Expand All @@ -63,13 +66,9 @@ public override void OnToolGUI(EditorWindow window)
if (evt.type == EventType.MouseUp && evt.button == 0 && !EditorHandleUtility.IsAppendModifier(evt.modifiers))
{
evt.Use();
UndoUtility.RecordObject(polygon, "Set Height");

SetPolyEditMode(PolyShape.PolyEditMode.None);
polygon.gameObject.hideFlags = HideFlags.None;
m_LastPolyShape = polygon.gameObject;
polygon = null;

SetShapeHeight();
if (!TryCreatePolyShape())
{
ToolManager.RestorePreviousTool();
Expand Down Expand Up @@ -210,15 +209,17 @@ Plane plane
}
get
{
if(polygon.m_Points.Count >= 3 &&
m_Plane.distance.Equals(0) &&
m_Plane.normal.Equals(Vector3.up))
if (polygon.m_Points.Count >= 3 &&
m_Plane.distance.Equals(0) &&
m_Plane.normal.Equals(Vector3.up))
{
Transform trs = polygon.transform;
m_Plane = new Plane(trs.TransformPoint(polygon.m_Points[0]),
trs.TransformPoint(polygon.m_Points[1]),
trs.TransformPoint(polygon.m_Points[2]));
}
else
m_Plane = EditorHandleUtility.GetPlaneFromSceneView();

return m_Plane;
}
Expand Down Expand Up @@ -350,10 +351,7 @@ public override void OnToolGUI(EditorWindow window)
evt.Use();
m_NextMouseUpAdvancesMode = false;

if (SceneCameraIsAlignedWithPolyUp())
SetPolyEditMode(PolyShape.PolyEditMode.Edit);
else
SetPolyEditMode(PolyShape.PolyEditMode.Height);
SetPolyEditMode(PolyShape.PolyEditMode.Height);
}

if (m_IsModifyingVertices && (
Expand Down Expand Up @@ -472,6 +470,16 @@ void OnOverlayGUI(UObject target, SceneView view)
EditorGUILayout.EndVertical();
}

internal void SetShapeHeight()
{
UndoUtility.RecordObject(polygon, "Set Height");
Copy link
Contributor

@modrimkus-unity modrimkus-unity Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some manual testing around Undo (as Undo was touched) and seems there's issues:

Screen.Recording.2024-10-10.at.4.51.47.PM.mov


RebuildPolyShapeMesh(polygon);
polygon.gameObject.hideFlags = HideFlags.None;
SetPolyEditMode(PolyShape.PolyEditMode.None);
polygon = null;
}

internal void SetPolyEditMode(PolyShape.PolyEditMode mode)
{
if(polygon == null)
Expand All @@ -480,6 +488,7 @@ internal void SetPolyEditMode(PolyShape.PolyEditMode mode)
PolyShape.PolyEditMode old = polygon.polyEditMode;
if (mode != old)
{
Debug.Log($"PolyShape: {old} -> {mode}");
GUIUtility.hotControl = 0;

// Entering edit mode after the shape has been finalized once before, which means
Expand All @@ -500,10 +509,20 @@ internal void SetPolyEditMode(PolyShape.PolyEditMode mode)
{
Vector3 up = polygon.transform.up;
Vector3 origin = polygon.transform.TransformPoint(Math.Average(polygon.m_Points));
Ray r = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
Vector3 p = Math.GetNearestPointRayRay(origin, up, r.origin, r.direction);
float extrude = Vector3.Distance(origin, p) * Mathf.Sign(Vector3.Dot(p - origin, up));
s_HeightMouseOffset = polygon.extrude - EditorSnapping.MoveSnap(extrude);

if (SceneCameraIsAlignedWithPolyUp())
{
s_HeightMouseOffset = polygon.extrude;
SetShapeHeight();
return;
}
else
{
Ray r = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
Vector3 p = Math.GetNearestPointRayRay(origin, up, r.origin, r.direction);
float extrude = Vector3.Distance(origin, p) * Mathf.Sign(Vector3.Dot(p - origin, up));
s_HeightMouseOffset = polygon.extrude - EditorSnapping.MoveSnap(extrude);
}
}
else if(old == PolyShape.PolyEditMode.Path && mode == PolyShape.PolyEditMode.None)
{
Expand Down Expand Up @@ -537,7 +556,7 @@ public void RebuildPolyShapeMesh(bool vertexCountChanged = false)
// renderer enable/disable, material re-apply, etc.
if (polygon.polyEditMode == PolyShape.PolyEditMode.Height && polygon.m_Points != null && polygon.m_Points.Count >= 3)
polygon.mesh.renderer.sharedMaterial = EditorMaterialUtility.GetUserMaterial();

var result = polygon.CreateShapeFromPolygon();
if(result.status == ActionResult.Status.Failure)
{
Expand Down Expand Up @@ -576,6 +595,19 @@ Vector3 GetPointInLocalSpace(Vector3 point)
return trs.InverseTransformPoint(point);
}

Vector3 GetPointFromHit(Vector3 hit)
{
// this monstrosity exists so that grid and incremental snap work when possible, and
// incremental is enabled when grid is not available.
var point = m_Polygon.isOnGrid
? EditorSnapping.MoveSnap(hit)
: EditorSnapping.snapMode == SnapMode.Relative
? ProBuilderSnapping.Snap(hit, EditorSnapping.incrementalSnapMoveValue)
: hit;

return point;
}

void DoPointPlacement()
{
Event evt = Event.current;
Expand Down Expand Up @@ -627,13 +659,7 @@ void DoPointPlacement()

if (polygon.m_Points.Count < 1)
{
// this monstrosity exists so that grid and incremental snap work when possible, and
// incremental is enabled when grid is not available.
polygon.transform.position = m_Polygon.isOnGrid
? EditorSnapping.MoveSnap(hit)
: EditorSnapping.snapMode == SnapMode.Relative
? ProBuilderSnapping.Snap(hit, EditorSnapping.incrementalSnapMoveValue)
: hit;
polygon.transform.position = GetPointFromHit(hit);

Vector3 cameraFacingPlaneNormal = plane.normal;
if (Vector3.Dot(cameraFacingPlaneNormal, SceneView.lastActiveSceneView.camera.transform.forward) > 0f)
Expand Down Expand Up @@ -803,6 +829,7 @@ void DoExistingPointsGUI()
evt.Use();
UndoUtility.RecordObject(polygon, "Set Height");
SetPolyEditMode(PolyShape.PolyEditMode.Edit);
return;
}

bool sceneInUse = EditorHandleUtility.SceneViewInUse(evt);
Expand Down Expand Up @@ -978,11 +1005,7 @@ void HandleKeyEvent(Event evt)
{
if (polygon.polyEditMode == PolyShape.PolyEditMode.Path)
{
if (SceneCameraIsAlignedWithPolyUp())
SetPolyEditMode(PolyShape.PolyEditMode.Edit);
else
SetPolyEditMode(PolyShape.PolyEditMode.Height);

SetPolyEditMode(PolyShape.PolyEditMode.Height);
evt.Use();
}
else if (polygon.polyEditMode == PolyShape.PolyEditMode.Height
Expand Down
2 changes: 1 addition & 1 deletion Editor/StateMachines/ShapeState_DrawBaseShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void UpdateShapeBase(Ray ray, float distance)
{
var deltaPoint = ray.GetPoint(distance) - tool.m_BB_Origin;
deltaPoint = Quaternion.Inverse(tool.m_PlaneRotation) * deltaPoint;
deltaPoint = tool.GetPoint(deltaPoint, Event.current.control);
deltaPoint = tool.GetPoint(deltaPoint, EditorSnapSettings.snapEnabled);
tool.m_BB_OppositeCorner = tool.m_PlaneRotation * deltaPoint + tool.m_BB_Origin;
tool.m_BB_HeightCorner = tool.m_BB_OppositeCorner;
tool.RebuildShape();
Expand Down
2 changes: 1 addition & 1 deletion Editor/StateMachines/ShapeState_DrawHeightShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override ShapeState DoState(Event evt)
{
var deltaPoint = (dot == 0 ? ray.origin - tool.m_Plane.ClosestPointOnPlane(ray.origin) : heightPoint - tool.m_BB_OppositeCorner);
deltaPoint = Quaternion.Inverse(tool.m_PlaneRotation) * deltaPoint;
deltaPoint = tool.GetPoint(deltaPoint, evt.control);
deltaPoint = tool.GetPoint(deltaPoint, EditorSnapSettings.snapEnabled);
tool.m_BB_HeightCorner = tool.m_PlaneRotation * deltaPoint + tool.m_BB_OppositeCorner;
tool.RebuildShape();
}
Expand Down