private void DrawPath(BezierNode[] nodes) { CacheIfDirty(); Gizmos.color = Color.magenta; for (int i = 0; i < nodes.Length - 1; ++i) { BezierNode prev = nodes[i]; BezierNode next = nodes[i + 1]; Vector3 lastPos = prev.transform.position; Vector3 nextPos; float t = 0; for (int j = 0; j < _previewSegments; ++j) { t += 1f / _previewSegments; nextPos = Curve(t, prev.transform.position, prev.h2, next.h1, next.transform.position); Gizmos.color = Color.magenta; Gizmos.DrawLine(lastPos, nextPos); if (_showTangents) { Vector3 tang = (_sectors[i].TanLocal(t, false)) * _tangentScale * 0.1f; Gizmos.color = Color.cyan; Gizmos.DrawLine(nextPos, tang + nextPos); } lastPos = nextPos; } } }
public Sector(BezierNode start, BezierNode end, float offset, int integrationSegments) { _start = start; _end = end; _offset = offset; _segmentT1s = new float[integrationSegments]; Vector3 a = _start.transform.position; Vector3 b = _start.h2; Vector3 c = _end.h1; Vector3 d = _end.transform.position; // Get constant coefficients _c1 = (d - (3 * c) + (3 * b) - a); _c2 = ((3 * c) - (6 * b) + (3 * a)); _c3 = ((3 * b) - (3 * a)); _c4 = a; // Calculate segment lengths Vector3 s = _start.transform.position; Vector3 e = _end.transform.position; Vector3 h2 = _start.h2; Vector3 h1 = _end.h1; Vector3 p0 = _start.transform.position; Vector3 p1 = _start.transform.position; float t = 0; // Loop over integration segments along sector for (int i = 0; i < _segmentT1s.Length; ++i) { p1 = BezierSpline.Curve(t, s, h2, h1, e); // Store local length _segmentT1s[i] = Vector3.Distance(p1, p0); length += _segmentT1s[i]; // Move to next segment p0 = p1; t += 1f / (float)_segmentT1s.Length; } // Get each local length as fraction, for approximate t remapping for (int i = 0; i < _segmentT1s.Length; ++i) { _segmentT1s[i] /= length; } }