private static void ShowHandles(Path2D aPathRaw, int aIndex, Matrix4x4 aTransform, Matrix4x4 aInvTransform, SerializedProperty aPath, bool aShowMeta, bool aUnlock, Path2D.Plane aPlane, Plane aEditPlane, PathEditorVisuals aVisuals) { PointControl ctrl = aPathRaw.GetControls(aIndex); bool locked = ctrl.type == PointType.Locked; Vector3 at = aTransform.MultiplyPoint3x4(Plane(aPathRaw[aIndex], aPlane)); if (ctrl.type == PointType.Auto || ctrl.type == PointType.AutoSymmetrical || ctrl.type == PointType.Sharp) { } else if (ctrl.type == PointType.CircleCorner) { if (aPathRaw.Closed || (aIndex != 0 && aIndex != aPathRaw.Count - 1)) { float size = HandleUtility.GetHandleSize(at); float radiusOffset = .2f; Vector3 end1 = PathUtil.GetRoundedCornerEnd(aIndex, aPathRaw.GetPathRaw(), aPathRaw.GetControls(), aPathRaw.Closed, ctrl.radius, true); Vector3 end2 = PathUtil.GetRoundedCornerEnd(aIndex, aPathRaw.GetPathRaw(), aPathRaw.GetControls(), aPathRaw.Closed, ctrl.radius, false); Vector3 normal = Vector2.Lerp(end1.xy() - aPathRaw[aIndex], end2.xy() - aPathRaw[aIndex], 0.5f).normalized; Vector3 v = aTransform.MultiplyVector(Plane(normal * (ctrl.radius + radiusOffset), aPlane)) + at; Vector3 nV = Handles.FreeMoveHandle(v, SceneView.lastActiveSceneView.camera.transform.rotation, size * aVisuals.sizeControlHandle, Vector3.zero, aVisuals.capControlHandle); if (nV != v) { SerializedProperty radius = aPath.FindPropertyRelative("_pointControls").GetArrayElementAtIndex(aIndex).FindPropertyRelative("radius"); nV = EditorTools.ProjectPoint(nV, aEditPlane); nV -= at; nV = aInvTransform.MultiplyVector(nV); Vector2 newPos = Deplane(nV, aPlane); radius.floatValue = SnapScale(radius.floatValue, Mathf.Max(0, newPos.magnitude - radiusOffset), PathSnap.World); _recentInteract = aIndex; GUI.changed = true; } if (aShowMeta) { string txt = Math.Round(ctrl.radius, 2).ToString(); Handles.Label(v, txt, ShadowStyle); Handles.Label(v, txt, LabelStyle); } } } else { Vector2 newPos; Vector3 v = aTransform.MultiplyVector(Plane(ctrl.controlPrev, aPlane)) + at; Vector3 nV = Handles.FreeMoveHandle(v, SceneView.lastActiveSceneView.camera.transform.rotation, HandleUtility.GetHandleSize(v) * aVisuals.sizeControlHandle, Vector3.zero, aVisuals.capControlHandle); if (nV != v) { SerializedProperty controlProp = aPath.FindPropertyRelative("_pointControls").GetArrayElementAtIndex(aIndex); SerializedProperty type = controlProp.FindPropertyRelative("type"); SerializedProperty prev = controlProp.FindPropertyRelative("controlPrev"); nV = EditorTools.ProjectPoint(nV, aEditPlane); nV -= at; nV = aInvTransform.MultiplyVector(nV); newPos = Deplane(nV, aPlane); prev.vector2Value = SnapRadial(v, prev.vector2Value, newPos, aTransform, aInvTransform, PathSnap.World); if (aUnlock) { ctrl.type = PointType.Free; type.enumValueIndex = (int)ctrl.type; } _recentInteract = aIndex; GUI.changed = true; } if (ctrl.type == PointType.Locked) { v = -aTransform.MultiplyVector(Plane(ctrl.controlPrev, aPlane)) + at; } else { v = aTransform.MultiplyVector(Plane(ctrl.controlNext, aPlane)) + at; } nV = Handles.FreeMoveHandle(v, SceneView.lastActiveSceneView.camera.transform.rotation, HandleUtility.GetHandleSize(v) * aVisuals.sizeControlHandle, Vector3.zero, aVisuals.capControlHandle); if (nV != v) { SerializedProperty controlProp = aPath.FindPropertyRelative("_pointControls").GetArrayElementAtIndex(aIndex); SerializedProperty type = controlProp.FindPropertyRelative("type"); SerializedProperty prev = controlProp.FindPropertyRelative("controlPrev"); SerializedProperty next = controlProp.FindPropertyRelative("controlNext"); nV = EditorTools.ProjectPoint(nV, aEditPlane); nV -= at; nV = aInvTransform.MultiplyVector(nV); if (aUnlock) { ctrl.type = PointType.Free; type.enumValueIndex = (int)ctrl.type; } if (ctrl.type == PointType.Locked) { newPos = Deplane(-nV, aPlane); prev.vector2Value = SnapRadial(v, prev.vector2Value, newPos, aTransform, aInvTransform, PathSnap.World); } else { newPos = Deplane(nV, aPlane); next.vector2Value = SnapRadial(v, next.vector2Value, newPos, aTransform, aInvTransform, PathSnap.World); } _recentInteract = aIndex; GUI.changed = true; } if (aShowMeta) { bool xz = aPlane == Path2D.Plane.XZ; Vector2 prop2 = (locked?ctrl.controlPrev:ctrl.controlNext); Vector3 handle1 = aTransform.MultiplyVector(Plane(ctrl.controlPrev, aPlane)) + at; Vector3 handle2 = (locked?-1:1) * aTransform.MultiplyVector(Plane((locked?ctrl.controlPrev:ctrl.controlNext), aPlane)) + at; float ang1 = PathUtil.ClockwiseAngle(ctrl.controlPrev, Vector2.right); //Vector2.Angle(prev.vector2Value, Vector2.right); float ang2 = PathUtil.ClockwiseAngle((locked?-1:1) * prop2, Vector2.right); //Vector2.Angle(prop2.vector2Value, Vector2.right); float mag1 = ctrl.controlPrev.magnitude; float mag2 = prop2.magnitude; Vector3 pos = Vector3.Lerp(handle1, at, 0.5f); string txt = Math.Round(mag1, 2).ToString(); Handles.Label(pos, txt, ShadowStyle); Handles.Label(pos, txt, LabelStyle); pos = Vector3.Lerp(handle2, at, 0.5f); txt = Math.Round(mag2, 2).ToString(); Handles.Label(pos, txt, ShadowStyle); Handles.Label(pos, txt, LabelStyle); pos = handle1; txt = "\u00B0" + Mathf.Round(ang1); Handles.Label(pos, txt, ShadowStyle); Handles.Label(pos, txt, LabelStyle); pos = handle2; txt = "\u00B0" + Mathf.Round(ang2); Handles.Label(pos, txt, ShadowStyle); Handles.Label(pos, txt, LabelStyle); if (ctrl.type == PointType.Free) { if (ang2 < ang1) { ang2 += 360; } float ang = ang2 - ang1; float halfAng = ang1 + ang / 2; float arcRadius = HandleUtility.GetHandleSize(at) * aVisuals.sizeVertex * 1.75f; Vector3 centerArc = new Vector3(Mathf.Cos(halfAng * Mathf.Deg2Rad), Mathf.Sin(halfAng * Mathf.Deg2Rad), 0); if (xz) { centerArc = new Vector3(centerArc.x, 0, centerArc.y); } centerArc = aTransform.MultiplyVector(centerArc); var centeredStyle = new GUIStyle(GUI.skin.label); centeredStyle.contentOffset = new Vector2(-9, -9); centeredStyle.normal.textColor = new Color(0, 0, 0, 0.5f); Handles.Label(at + centerArc * arcRadius * 2f, "\u00B0" + Mathf.Round(ang), centeredStyle); centeredStyle.contentOffset = new Vector2(-10, -10); centeredStyle.normal.textColor = Color.white; Handles.Label(at + centerArc * arcRadius * 2f, "\u00B0" + Mathf.Round(ang), centeredStyle); Handles.DrawWireArc(at, aPlane == Path2D.Plane.XY?Vector3.forward:Vector3.up, ((xz?handle2:handle1) - at).normalized, ang, arcRadius); } } } }
private static bool TransformHandles(SuperCube aBox, Vector3 aRtb, Vector3 aLbf) { Vector3 rtb = aRtb; Vector3 lbf = aLbf; Vector3 snap = EditorTools.GetUnitySnap(); bool rebuild = false; EditorTools.capDir = Matrix4x4.TRS(Vector3.zero, aBox.transform.rotation, Vector3.one); // Bottom Handles.color = Color.Lerp(Color.green, Color.white, 0.5f); SuperCubeEditorUtil.Handle(PivotType.Bottom, aBox.transform, false, true, false, snap, ref lbf, ref rtb, EditorTools.ArrowCapYN); Handles.color = Color.Lerp(Color.red, Color.white, 0.5f); SuperCubeEditorUtil.Handle(PivotType.Right, aBox.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.ArrowCapXP); SuperCubeEditorUtil.Handle(PivotType.Left, aBox.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.ArrowCapXN); Handles.color = Color.Lerp(Color.blue, Color.white, 0.5f); SuperCubeEditorUtil.Handle(PivotType.Back, aBox.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.ArrowCapZP); SuperCubeEditorUtil.Handle(PivotType.Front, aBox.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.ArrowCapZN); Handles.color = Color.Lerp(Color.green, Color.white, 0.5f); SuperCubeEditorUtil.Handle(PivotType.Top, aBox.transform, false, true, false, snap, ref lbf, ref rtb, EditorTools.ArrowCapYP); if (!SuperCubeSettings.HideYRing) { Handles.color = Color.Lerp(Color.Lerp(Color.red, Color.white, 0.5f), Color.Lerp(Color.blue, Color.white, 0.5f), .5f); SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Right, aBox.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapY); SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Left, aBox.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapY); SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Right, aBox.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapY); SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Left, aBox.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapY); } if (!SuperCubeSettings.HideZRing) { Handles.color = Color.Lerp(Color.Lerp(Color.red, Color.white, 0.5f), Color.Lerp(Color.green, Color.white, 0.5f), .5f); SuperCubeEditorUtil.Handle(PivotType.Left | PivotType.Top, aBox.transform, true, true, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ); SuperCubeEditorUtil.Handle(PivotType.Left | PivotType.Bottom, aBox.transform, true, true, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ); SuperCubeEditorUtil.Handle(PivotType.Right | PivotType.Top, aBox.transform, true, true, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ); SuperCubeEditorUtil.Handle(PivotType.Right | PivotType.Bottom, aBox.transform, true, true, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ); } if (!SuperCubeSettings.HideXRing) { Handles.color = Color.Lerp(Color.Lerp(Color.blue, Color.white, 0.5f), Color.Lerp(Color.green, Color.white, 0.5f), .5f); SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Top, aBox.transform, false, true, true, snap, ref lbf, ref rtb, EditorTools.BarCapX); SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Bottom, aBox.transform, false, true, true, snap, ref lbf, ref rtb, EditorTools.BarCapX); SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Top, aBox.transform, false, true, true, snap, ref lbf, ref rtb, EditorTools.BarCapX); SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Bottom, aBox.transform, false, true, true, snap, ref lbf, ref rtb, EditorTools.BarCapX); } // Check if there was an edit, and notify an update to the mesh! Vector3 newExtents = new Vector3(Mathf.Abs(rtb.x - lbf.x), Mathf.Abs(rtb.y - lbf.y), Mathf.Abs(rtb.z - lbf.z)); if (aBox.SliceFaces) { float maxSize = SuperCubeSettings.MaxSize; if (newExtents.x > maxSize) { newExtents.x = aBox.Extents.x; lbf.x = aLbf.x; rtb.x = aRtb.x; } if (newExtents.y > maxSize) { newExtents.y = aBox.Extents.y; lbf.y = aLbf.y; rtb.y = aRtb.y; } if (newExtents.z > maxSize) { newExtents.z = aBox.Extents.z; lbf.z = aLbf.z; rtb.z = aRtb.z; } } if (aBox.Extents != newExtents) { aBox.transform.position += aBox.transform.TransformDirection(lbf + new Vector3((rtb.x - lbf.x) / 2, (rtb.y - lbf.y) / 2, (rtb.z - lbf.z) / 2)); aBox.Extents = newExtents; rebuild = true; } return(rebuild); }