protected virtual void OnEnable() { this.point = (BezierPoint3D)this.target; this.handleType = this.serializedObject.FindProperty("handleType"); this.leftHandleLocalPosition = this.serializedObject.FindProperty("leftHandleLocalPosition"); this.rightHandleLocalPosition = this.serializedObject.FindProperty("rightHandleLocalPosition"); }
private static void AddDefaultPoints(BezierCurve3D curve) { BezierPoint3D startPoint = curve.AddKeyPoint(); startPoint.LocalPosition = new Vector3(-1f, 0f, 0f); startPoint.LeftHandleLocalPosition = new Vector3(-0.35f, -0.35f, 0f); BezierPoint3D endPoint = curve.AddKeyPoint(); endPoint.LocalPosition = new Vector3(1f, 0f, 0f); endPoint.LeftHandleLocalPosition = new Vector3(-0.35f, 0.35f, 0f); }
public static void DrawPointsSceneGUI(BezierCurve3D curve, BezierPoint3D exclude = null) { for (int i = 0; i < curve.KeyPointsCount; i++) { if (curve.KeyPoints[i] == exclude) { continue; } BezierPoint3DEditor.handleCapSize = BezierPoint3DEditor.CircleCapSize; BezierPoint3DEditor.DrawPointSceneGUI(curve.KeyPoints[i]); } }
public static void DrawPointSceneGUI(BezierPoint3D point, Handles.DrawCapFunction drawPointFunc, Handles.DrawCapFunction drawHandleFunc) { // Draw a label for the point Handles.color = Color.black; Handles.Label(point.Position + new Vector3(0f, HandleUtility.GetHandleSize(point.Position) * 0.4f, 0f), point.gameObject.name); // Draw the center of the control point Handles.color = Color.yellow; Vector3 newPointPosition = Handles.FreeMoveHandle(point.Position, point.transform.rotation, HandleUtility.GetHandleSize(point.Position) * BezierPoint3DEditor.pointCapSize, Vector3.one * 0.5f, drawPointFunc); if (point.Position != newPointPosition) { Undo.RegisterCompleteObjectUndo(point.transform, "Move Point"); point.Position = newPointPosition; } // Draw the left and right handles Handles.color = Color.white; Handles.DrawLine(point.Position, point.LeftHandlePosition); Handles.DrawLine(point.Position, point.RightHandlePosition); Handles.color = Color.cyan; Vector3 newLeftHandlePosition = Handles.FreeMoveHandle(point.LeftHandlePosition, point.transform.rotation, HandleUtility.GetHandleSize(point.LeftHandlePosition) * BezierPoint3DEditor.handleCapSize, Vector3.zero, drawHandleFunc); if (point.LeftHandlePosition != newLeftHandlePosition) { Undo.RegisterCompleteObjectUndo(point, "Move Left Handle"); point.LeftHandlePosition = newLeftHandlePosition; } Vector3 newRightHandlePosition = Handles.FreeMoveHandle(point.RightHandlePosition, point.transform.rotation, HandleUtility.GetHandleSize(point.RightHandlePosition) * BezierPoint3DEditor.handleCapSize, Vector3.zero, drawHandleFunc); if (point.RightHandlePosition != newRightHandlePosition) { Undo.RegisterCompleteObjectUndo(point, "Move Right Handle"); point.RightHandlePosition = newRightHandlePosition; } }
public void GetCubicSegment(float time, out BezierPoint3D startPoint, out BezierPoint3D endPoint, out float timeRelativeToSegment) { startPoint = null; endPoint = null; timeRelativeToSegment = 0f; float subCurvePercent = 0f; float totalPercent = 0f; float approximateLength = GetApproximateLength(); int subCurveSampling = (Sampling / (KeyPointsCount - 1)) + 1; for (int i = 0; i < KeyPointsCount - 1; i++) { subCurvePercent = GetApproximateLengthOfCubicCurve(KeyPoints[i], KeyPoints[i + 1], subCurveSampling) / approximateLength; if (subCurvePercent + totalPercent > time) { startPoint = KeyPoints[i]; endPoint = KeyPoints[i + 1]; break; } totalPercent += subCurvePercent; } if (endPoint == null) { // If the evaluated point is very near to the end of the curve we are in the last segment startPoint = KeyPoints[KeyPointsCount - 2]; endPoint = KeyPoints[KeyPointsCount - 1]; // We remove the percentage of the last sub-curve totalPercent -= subCurvePercent; } timeRelativeToSegment = (time - totalPercent) / subCurvePercent; }
public static Quaternion GetRotationOnCubicCurve(float time, Vector3 up, BezierPoint3D startPoint, BezierPoint3D endPoint) { return GetRotationOnCubicCurve(time, up, startPoint.Position, endPoint.Position, startPoint.RightHandlePosition, endPoint.LeftHandlePosition); }
public static void DrawPointSceneGUI(BezierPoint3D point) { DrawPointSceneGUI(point, Handles.RectangleCap, Handles.CircleCap); }
public void GetCubicSegment(float time, out BezierPoint3D startPoint, out BezierPoint3D endPoint, out float timeRelativeToSegment) { startPoint = null; endPoint = null; timeRelativeToSegment = 0f; float subCurvePercent = 0f; float totalPercent = 0f; float approximateLength = this.GetApproximateLength(); int subCurveSampling = (this.Sampling / (this.KeyPointsCount - 1)) + 1; for (int i = 0; i < this.KeyPointsCount - 1; i++) { subCurvePercent = BezierCurve3D.GetApproximateLengthOfCubicCurve(this.KeyPoints[i], this.KeyPoints[i + 1], subCurveSampling) / approximateLength; if (subCurvePercent + totalPercent > time) { startPoint = this.KeyPoints[i]; endPoint = this.KeyPoints[i + 1]; break; } totalPercent += subCurvePercent; } if (endPoint == null) { // If the evaluated point is very near to the end of the curve startPoint = this.KeyPoints[this.KeyPointsCount - 2]; endPoint = this.KeyPoints[this.KeyPointsCount - 1]; totalPercent -= subCurvePercent; // We remove the percentage of the last sub-curve } timeRelativeToSegment = (time - totalPercent) / subCurvePercent; }
public static float GetApproximateLengthOfCubicCurve(BezierPoint3D startPoint, BezierPoint3D endPoint, int sampling) { return GetApproximateLengthOfCubicCurve(startPoint.Position, endPoint.Position, startPoint.RightHandlePosition, endPoint.LeftHandlePosition, sampling); }
public static Vector3 GetNormalOnCubicCurve(float time, Vector3 up, BezierPoint3D startPoint, BezierPoint3D endPoint) { return GetNormalOnCubicCurve(time, up, startPoint.Position, endPoint.Position, startPoint.RightHandlePosition, endPoint.LeftHandlePosition); }
public static Quaternion GetRotationOnCubicCurve(float time, Vector3 up, BezierPoint3D startPoint, BezierPoint3D endPoint) { return(GetRotationOnCubicCurve(time, up, startPoint.Position, endPoint.Position, startPoint.RightHandlePosition, endPoint.LeftHandlePosition)); }
public static Vector3 GetTangentOnCubicCurve(float time, BezierPoint3D startPoint, BezierPoint3D endPoint) { return(GetTangentOnCubicCurve(time, startPoint.Position, endPoint.Position, startPoint.RightHandlePosition, endPoint.LeftHandlePosition)); }
public static Vector3 GetTangentOnCubicCurve(float time, BezierPoint3D startPoint, BezierPoint3D endPoint) { return GetTangentOnCubicCurve(time, startPoint.Position, endPoint.Position, startPoint.RightHandlePosition, endPoint.LeftHandlePosition); }
public static Vector3 GetBinormalOnCubicCurve(float time, Vector3 up, BezierPoint3D startPoint, BezierPoint3D endPoint) { return GetBinormalOnCubicCurve(time, up, startPoint.Position, endPoint.Position, startPoint.RightHandlePosition, endPoint.LeftHandlePosition); }