public static float GetLengthAS(this SplineBase spline, int curve, float error) { Vector3[] v = new Vector3[4]; v[0] = spline.GetControlPoint(curve * 3); v[1] = spline.GetControlPoint(curve * 3 + 1); v[2] = spline.GetControlPoint(curve * 3 + 2); v[3] = spline.GetControlPoint(curve * 3 + 3); float length = 0.0f; AddIfClose(v, ref length, error); /* kick off recursion */ return(length); }
public static Vector3[] Slice(this SplineBase spline, int curve, float t) { Vector3 p1 = spline.GetControlPoint(curve * 3); Vector3 p2 = spline.GetControlPoint(curve * 3 + 1); Vector3 p3 = spline.GetControlPoint(curve * 3 + 2); Vector3 p4 = spline.GetControlPoint(curve * 3 + 3); Vector3 p12 = (p2 - p1) * t + p1; Vector3 p23 = (p3 - p2) * t + p2; Vector3 p34 = (p4 - p3) * t + p3; Vector3 p123 = (p23 - p12) * t + p12; Vector3 p234 = (p34 - p23) * t + p23; Vector3 p1234 = (p234 - p123) * t + p123; return(new[] { p1, p12, p123, p1234, p234, p34, p4 }); }
private void Spawn() { int index = 0; int nextIndex = index + 1; Twist twist = m_spline.GetTwist(index); Vector3 ptPrev = m_spline.GetControlPoint(index); Vector3 pt = m_spline.GetControlPoint(nextIndex); GameObject paperplaneGo = (GameObject)Instantiate(PaperplanePrefab, m_spline.GetPoint(0.0f), Quaternion.AngleAxis(twist.Data, pt - ptPrev) * Quaternion.LookRotation(pt - ptPrev)); SplineFollow splineFollow = paperplaneGo.GetComponent <SplineFollow>(); splineFollow.Spline = m_spline; if (!SmoothFollow.enabled) { SmoothFollow.SetTarget(paperplaneGo.transform); SmoothFollow.enabled = true; } }
public static float GetLengthAS(this SplineBase spline, float error) { float totalLength = 0.0f; Vector3[] v = new Vector3[4]; int curveCount = spline.CurveCount; for (int curve = 0; curve < curveCount; ++curve) { v[0] = spline.GetControlPoint(curve * 3); v[1] = spline.GetControlPoint(curve * 3 + 1); v[2] = spline.GetControlPoint(curve * 3 + 2); v[3] = spline.GetControlPoint(curve * 3 + 3); float length = 0.0f; AddIfClose(v, ref length, error); totalLength += length; } return(totalLength); }
private int HitTest(SplineBase spline, out float minDistance) { minDistance = float.PositiveInfinity; if (Camera == null) { Debug.LogError("Camera is null"); return(-1); } if (RuntimeSelection.gameObjects == null) { return(-1); } Vector3[] controlPoints = new Vector3[spline.ControlPointCount]; for (int j = 0; j < controlPoints.Length; j++) { controlPoints[j] = spline.GetControlPoint(j); } minDistance = SelectionMargin * SelectionMargin; int selectedIndex = -1; Vector2 mousePositon = Input.mousePosition; for (int i = 0; i < controlPoints.Length; ++i) { Vector3 ctrlPoint = controlPoints[i]; if (spline.IsControlPointLocked(i)) { continue; } Vector2 pt = Camera.WorldToScreenPoint(ctrlPoint); float mag = (pt - mousePositon).sqrMagnitude; if (mag < minDistance) { minDistance = mag; selectedIndex = i; } } return(selectedIndex); }
private void ShowPoints(SplineBase spline) { if (!spline.IsSelected) { return; } Quaternion handleRotation = Tools.pivotRotation == PivotRotation.Local ? spline.transform.rotation : Quaternion.identity; int firstPointIndex = 0; if (spline.IsControlPointLocked(firstPointIndex)) { firstPointIndex++; if (spline.IsControlPointLocked(firstPointIndex)) { firstPointIndex++; } } int lastPointIndex = spline.ControlPointCount - 1; if (spline.IsControlPointLocked(lastPointIndex)) { lastPointIndex--; if (spline.IsControlPointLocked(lastPointIndex)) { lastPointIndex--; } } if (ConvergingSpline) { if (spline.Loop) { if (firstPointIndex == 0) { firstPointIndex++; } if (lastPointIndex == spline.ControlPointCount - 1) { lastPointIndex--; } } for (int i = firstPointIndex; i <= lastPointIndex; i++) { if (i % 3 == 0 && spline != m_splineBase) { Vector3 p = spline.GetControlPoint(i); ShowPoint(spline, i, p, handleRotation); } } } else { for (int i = firstPointIndex; i <= lastPointIndex; i++) { Vector3 p = spline.GetControlPoint(i); ShowPoint(spline, i, p, handleRotation); } } if (m_selectedIndex == -1 && spline == m_splineBase) { ShowSplineLength(m_splineBase, m_greenLabelStyle); } }
private void Update() { if (m_spline == null) { return; } if (transform.localPosition != m_localPosition) { if (m_spline.SetControlPointLocal(m_index, transform.localPosition)) { m_localPosition = transform.localPosition; } else { transform.localPosition = m_localPosition; } } if (transform.rotation != m_rotation) { if (m_index % 3 == 0) { Vector3 v = Vector3.back; int prevIndex = m_index - 1; if (prevIndex < 0) { prevIndex = m_index + 1; v = Vector3.forward; } Vector3 prevPt = m_spline.GetControlPoint(prevIndex); Vector3 pt = m_spline.GetControlPoint(m_index); Vector3 toPrev = (transform.rotation * v).normalized * (pt - prevPt).magnitude; Twist twist = m_spline.GetTwist(m_index); m_rotation = transform.rotation; twist.Data = transform.eulerAngles.z; m_updateAngle = false; m_spline.SetTwist(m_index, twist); m_spline.SetControlPoint(prevIndex, pt + toPrev); m_updateAngle = true; } else { transform.rotation = m_rotation; } } Thickness thickness = m_spline.GetThickness(m_index); Vector3 thicknessData = thickness.Data; if (transform.localScale != thicknessData) { thickness.Data = transform.localScale; m_spline.SetThickness(m_index, thickness); } }