private void DrawPoints(CatmullRomCentripetal spline, Transform tr) { if (!ms_drawPts) { return; } Camera sceneViewCam = Camera.current; Transform camTr = sceneViewCam.transform; // draw point and selection EUtil.PushHandleColor(SplineConst.SplinePtColor); for (int i = 0; i < spline.PointCount; ++i) { if (spline.Cycle && i == spline.PointCount - 1) //don't draw button for last point if is cycle { continue; } bool isSelPoint = false; if (i == m_curPtIdx) { isSelPoint = true; EUtil.PushHandleColor(Handles.selectedColor); } Vector3 pt = tr.TransformPoint(spline[i]); if (Handles.Button(pt, camTr.rotation, ms_ptSize, ms_ptSize, Handles.DotCap)) { m_curPtIdx = i; Repaint(); } if (isSelPoint) { EUtil.PopHandleColor(); } } EUtil.PopHandleColor(); if (ms_foldoutTSlider) { Vector3 tPos = tr.TransformPoint(spline.Interp(m_tSlider)); Handles.CircleCap(GUIUtility.GetControlID(FocusType.Passive), tPos, camTr.rotation, ms_ptSize); } }
void OnSceneGUI() { CCDSolverMB cp = (CCDSolverMB)target; CCDSolver solver = cp.GetSolver(); if (solver == null || solver.Count < 1) { return; } if (cp.ShowGizmos) { var joints = solver.GetJoints(); Camera sceneCam = EUtil.GetSceneViewCamera(); Transform camTr = sceneCam.transform; EUtil.PushHandleColor(Pref.IKBoneLinkColor); //1. draw bone line for (int i = 0; i < joints.Length - 1; ++i) { var p0 = joints[i].position; var p1 = joints[i + 1].position; Handles.DrawAAPolyLine(3f, p0, p1); Handles.DotCap(0, p0, camTr.rotation, m_markerSize.val); } if (joints.Length > 0) { Handles.DotCap(0, joints.Last().position, camTr.rotation, m_markerSize.val); } EUtil.PopHandleColor(); //1.5 draw line from end-joint to target pos { var p0 = joints.Last().position; var p1 = solver.Target; Handles.DrawDottedLine(p0, p1, 5f); } //2. call each constraint's OnSceneGUI for (int i = 0; i < joints.Length - 1; ++i) { var cons = solver.GetConstraint(i); foreach (var con in cons) { if (!con || !con.enabled) { continue; } Editor e = EUtil.GetEditor(con); IOnSceneGUI igui = e as IOnSceneGUI; if (igui != null) { igui.OnSceneGUI(); } } } } //3. debug draw if (!cp.Target) { if (m_panel != EPanel.Normal) { Tools.current = Tool.None; // move handle if (m_panel == EPanel.Continuous) { EditorGUI.BeginChangeCheck(); } solver.Target = Handles.PositionHandle(solver.Target, Quaternion.identity); if (m_panel == EPanel.Continuous && EditorGUI.EndChangeCheck()) { Undo.RecordObjects(solver.GetJoints(), "IK execute"); solver.Execute(); } // hotkeys Event e = Event.current; if (e.type == EventType.KeyUp && Tools.viewTool != ViewTool.FPS) { if (e.keyCode == KeyCode.E) { Tools.current = Tool.Rotate; m_panel = EPanel.Normal; } else if (e.keyCode == KeyCode.R) { Tools.current = Tool.Scale; m_panel = EPanel.Normal; } else if (e.keyCode == KeyCode.Q) { Tools.current = Tool.View; m_panel = EPanel.Normal; } } } } }