private void _AddPoint(CatmullRomUniform spline) { MUndo.RecordObject(target, "add point"); MUndo.RecordObject(this, "add point"); if (m_curPtIdx < 0) { m_curPtIdx = spline.PointCount - 1; } if (m_curPtIdx != spline.PointCount - 1) { float v = (float)m_curPtIdx + 0.5f; Vector3 newPos = spline.Interp(v / (spline.PointCount - 1)); spline.InsertPointAfter(m_curPtIdx, newPos); } else { float unitLen = spline.CurveLength / (spline.PointCount - 1); Vector3 dir = spline.Tangent(1f); spline.InsertPointAfter(m_curPtIdx, spline[m_curPtIdx] + dir * unitLen); } m_curPtIdx++; }
private void DrawPoints(CatmullRomUniform 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); } }