/// <summary> /// Gets metadata for a certain TF /// </summary> /// <param name="type">Metadata type interfacing ICurvyMetadata</param> /// <param name="tf">TF value reflecting position on spline (0..1)</param> /// <returns>the metadata</returns> public override Component GetMetadata(System.Type type, float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return((spl) ? spl.GetMetadata(type, localTF) : null); }
// <summary> /// Gets an interpolated Metadata value for a certain TF /// </summary> /// <typeparam name="T">Metadata type interfacing ICurvyInterpolatableMetadata</typeparam> /// <typeparam name="U">Return Value type of T</typeparam> /// <param name="tf">TF value reflecting position on spline (0..1)</param> /// <returns>the interpolated value</returns> public override U InterpolateMetadata <T, U>(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return((spl) ? spl.InterpolateMetadata <T, U>(localTF) : default(U)); }
/// <summary> /// Gets the normalized tangent for a certain TF /// </summary> /// <param name="tf">TF value identifying position in the group (0..1)</param> /// <returns>a tangent vector</returns> public override Vector3 GetTangent(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return((spl) ? spl.GetTangent(localTF) : Vector3.zero); }
/// <summary> /// Converts a distance to a TF value /// </summary> /// <param name="distance">distance in the range 0..Length</param> /// <param name="clamping">Clamping to use</param> /// <returns>a TF value in the range 0..1</returns> public override float DistanceToTF(float distance, CurvyClamping clamping) { float localDistance; CurvySpline spl = DistanceToSpline(distance, out localDistance, clamping); return((spl) ? SplineToTF(spl, spl.DistanceToTF(localDistance)) : 0); }
public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline, Crosshair crosshair) { if (!init && spline.IsInitialized) { init = true; } if (!init) { return; } Vector3 theCenter = Vector3.zero; Vector3 theVelocity = Vector3.zero; flockSize = _boids.Count; // transform.position = player.transform.position + Camera.main.transform.forward * 10.0f; for (int i = 0; i < _boids.Count; i++) { theCenter += _boids [i].transform.position; theVelocity += _boids [i].GetComponent <Rigidbody> ().velocity; } flockCenter = theCenter / flockSize; //AxKDebugLines.AddFancySphere(flockCenter, 1f, Color.red, 0); flockVelocity = theVelocity / flockSize; //AxKDebugLines.AddLine(flockCenter, flockCenter + flockVelocity, Color.red, 0); for (int i = 0; i < _boids.Count; i++) { _boids[i].GetComponent <BoidFlocking> ().UpdateATL(_boids, this, player, spline, crosshair); } }
/// <summary> /// Gets the interpolated position for a certain group TF using a linear approximation /// </summary> /// <remarks>TF (Total Fragment) relates to the total length of the group</remarks> /// <param name="tf">TF value reflecting position in the group (0..1)</param> /// <returns>the interpolated position</returns> public override Vector3 InterpolateFast(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return((spl) ? spl.InterpolateFast(localTF) : Vector3.zero); }
void OnPostRender() { if (Splines.Length == 0) { return; } for (int s = 0; s < Splines.Length; s++) { CurvySpline spline = Splines[s]; Color lineColor = (s < Colors.Length) ? Colors[s] : Color.green; if (spline && spline.IsInitialized) { Points = spline.GetApproximation(); CreateLineMaterial(); lineMaterial.SetPass(0); GL.Begin(GL.LINES); GL.Color(lineColor); for (int i = 1; i < Points.Length; i++) { GL.Vertex(Points[i - 1]); GL.Vertex(Points[i]); } GL.End(); } } }
/// <summary> /// Gets a rotation looking to Tangent with the head upwards along the Up-Vector /// </summary> /// <param name="tf">TF value reflecting position in the group (0..1)</param> /// <returns>a rotation</returns> public override UnityEngine.Quaternion GetOrientationFast(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return(spl.GetOrientationFast(localTF)); }
/// <summary> /// Gets the interpolated position for a certain group TF using a linear approximation /// </summary> /// <remarks>TF (Total Fragment) relates to the total length of the group</remarks> /// <param name="tf">TF value reflecting position in the group (0..1)</param> /// <returns>the interpolated position</returns> public override UnityEngine.Vector3 InterpolateFast(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return(spl.InterpolateFast(localTF)); }
/// <summary> /// Gets an interpolated Metadata value for a certain TF /// </summary> /// <param name="type">Metadata type interfacing ICurvyInterpolatableMetadata</param> /// <param name="tf">TF value reflecting position on spline (0..1)</param> /// <returns>the interpolated value</returns> public override object InterpolateMetadata(System.Type type, float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return((spl) ? spl.InterpolateMetadata(type, localTF) : null); }
/// <summary> /// Undo-complient version of CurvyUtility.JoinSpline() /// </summary> /// <param name="sourceCP">a Control Point of the source spline</param> /// <param name="destCP">the Control Point of the destination spline</param> public static void UndoJoinSpline(CurvySplineSegment sourceCP, CurvySplineSegment destCP) { #if !OLD_UNDO if (!sourceCP || !destCP) { return; } CurvySpline src = sourceCP.Spline; CurvySpline dst = destCP.Spline; if (src == dst) { return; } for (int i = 0; i < src.ControlPointCount; i++) { Undo.RecordObject(src.ControlPoints[i].gameObject, "Join Spline"); Undo.SetTransformParent(src.ControlPoints[i].Transform, dst.Transform, "Join Spline"); src.ControlPoints[i]._ReSettle(); } dst.ControlPoints.InsertRange(destCP.ControlPointIndex + 1, src.ControlPoints); dst._RenameControlPointsByIndex(); dst.RefreshImmediately(true, true, false); Undo.DestroyObjectImmediate(src.gameObject); #endif }
public static void UndoRegisterSplineControlPoints(CurvySpline spl, string name) { #if !OLD_UNDO for (int i = 0; i < spl.ControlPointCount; i++) Undo.RecordObject(spl.ControlPoints[i].gameObject, name); #endif }
// Use this for initialization void Start() { mSpline = GetComponent <CurvySpline>(); Walker = GameObject.FindObjectOfType(typeof(SplineWalkerDistance)) as SplineWalkerDistance; //while (!mSpline.IsInitialized) // yield return null; }
void addRandomCP(ref CurvySpline spline, int count, int totalLength) { Vector3[] pos = new Vector3[count]; float segLength = totalLength / (float)(count - 1); pos[0] = Vector3.zero; for (int i = 1; i < count; i++) { int dir = Random.Range(0, 2); int sign = Random.Range(0f, 1f) > 0.5f ? 1 : -1; switch (dir) { case 0: pos[i] = pos[i - 1] + new Vector3(segLength * sign, 0, 0); break; case 1: pos[i] = pos[i - 1] + new Vector3(0, segLength * sign, 0); break; case 2: pos[i] = pos[i - 1] + new Vector3(0, 0, segLength * sign); break; } } spline.Add(pos); spline.Refresh(); }
} //centerLine of PlayerCar in PCH public void DrawCenterLine(GameObject car, float carTf, CurvySpline curvySpline, Texture2D lineRendererTxt) { Vector3 heading = curvySpline.Interpolate(0) - car.transform.position; float increaseAmount = 1f / (curvySpline.Length * SPLINE_GIZMO_SMOOTHNESS); if (Vector3.Dot(heading, car.transform.forward) > 0) //starting point is in front of me { for (float i = carTf; i > 0; i -= increaseAmount) { Vector3 pos = curvySpline.Interpolate(i); CenterPoints.Add(pos); } } else //starting point is behind me { for (float i = carTf; i < 1; i += increaseAmount) { Vector3 pos = curvySpline.Interpolate(i); CenterPoints.Add(pos); } } lineRenderer2.positionCount = CenterPoints.Count; lineRenderer2.SetPositions(CenterPoints.ToArray()); lineRenderer2.colorGradient = MakeLineRendererGradient(centerLineColor); lineRenderer2.material.SetColor("_Color", CenterLineColor); //set tint color of lineRenderer Texture2D txt = UpdateParams(centerLineColor, lineRendererTxt); lineRenderer2.material.SetTexture("_MainTex", txt); CenterPoints.Clear(); } //centerLine of PlayerCar in SF
/// <summary> /// Start a spline switch /// </summary> /// <param name="target">the target spline to switch to</param> /// <param name="targetTF">the target TF</param> /// <param name="duration">duration of the switch phase</param> public virtual void SwitchTo(CurvySpline target, float targetTF, float duration) { mSwitchStartTime = Time.time; mSwitchDuration = duration; mSwitchEventArgs = new CurvySplineMoveEventArgs(this, target, null, targetTF, 0, Direction); mSwitchEventArgs.Data = 0f; }
void setController(SplineController c, CurvySpline spline, float speed) { c.Spline = spline; c.Speed = speed; c.OnControlPointReached.AddListenerOnce(OnCPReached); c.OnEndReached.AddListenerOnce(CurvyDefaultEventHandler.UseFollowUpStatic); }
IEnumerator Fall(float delay, CurvySpline spline) { print("now falling"); yield return(new WaitForSeconds(delay)); Vector3 targetPosition = new Vector3(transform.position.x, lastPos.y + 50.0f, transform.position.z); //AxKDebugLines.AddFancySphere (targetPosition, 1.0f, Color.blue, 0.0f); //AxKDebugLines.AddFancySphere (lastPos, 1.0f, Color.red, 0.0f); //AxKDebugLines.AddFancySphere ( new Vector3(lastPos.x, lastPos.y + 5.0f, lastPos.z) , 1.0f, Color.green, 0.0f); //AxKDebugLines.AddFancySphere (transform.position, 1.0f, Color.magenta, 0.0f); print("now rising above"); while (transform.position.y < targetPosition.y - 1.0f) { transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((targetPosition - transform.position).normalized, new Vector3(0, 1, 0)), Time.deltaTime); } print("now landing to spline"); Vector3 splineForward = spline.GetTangent(t); while (transform.position.y > lastPos.y + 10.0f) { transform.position = Vector3.Lerp(transform.position, lastPos, Time.deltaTime); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(splineForward), Time.deltaTime); } print("now done"); Camera.main.GetComponent <CameraController_three> ().falling = false; }
/// <summary> /// Gets the normalized tangent for a certain TF with a known position for TF /// </summary> /// <remarks>This saves one interpolation</remarks> /// <param name="tf">TF value identifying position in the group (0..1)</param> /// <param name="position">The interpolated position for TF</param> /// <returns>a tangent vector</returns> public override Vector3 GetTangent(float tf, Vector3 position) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return(spl.GetTangent(localTF, position)); }
/// <summary> /// Undo-complient version of CurvyUtility.SplitSpline() /// </summary> /// <param name="firstCP">the first Control Point of the new spline</param> /// <returns>the new spline</returns> public static CurvySpline UndoSplitSpline(CurvySplineSegment firstCP) { #if OLD_UNDO Undo.RegisterSceneUndo("Split Spline"); return(CurvyUtility.SplitSpline(firstCP)); #else CurvySpline old = firstCP.Spline; CurvySpline spl = CurvySpline.Create(old); Undo.RegisterCreatedObjectUndo(spl.gameObject, "Split Spline"); spl.name = old.name + "_parted"; // Move CPs var affected = old.ControlPoints.GetRange(firstCP.ControlPointIndex, old.ControlPointCount - firstCP.ControlPointIndex); for (int i = 0; i < affected.Count; i++) { Undo.RecordObject(affected[i].gameObject, "Split Spline"); Undo.SetTransformParent(affected[i].Transform, spl.Transform, "Split Spline"); affected[i]._ReSettle(); } old.ControlPoints.Clear(); old.RefreshImmediately(true, true, false); spl._RenameControlPointsByIndex(); spl.RefreshImmediately(true, true, false); return(spl); #endif }
/// <summary> /// Gets the normalized tangent for a certain TF using a linear approximation /// </summary> /// <param name="tf">TF value identifying position in the group (0..1)</param> /// <returns>a tangent vector</returns> public override Vector3 GetTangentFast(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return(spl.GetTangentFast(localTF)); }
/// <summary> /// Checks if the curve is planar /// </summary> /// <param name="spline">a CurvySpline</param> /// <param name="xplanar">whether the x-axis is planar</param> /// <param name="yplanar">whether the y-axis is planar</param> /// <param name="zplanar">whether the z-axis is planar</param> /// <returns>true if at least on axis is planar</returns> public static bool isPlanar(CurvySpline spline, out bool xplanar, out bool yplanar, out bool zplanar) { xplanar = true; yplanar = true; zplanar = true; if (spline.ControlPointCount == 0) { return(false); } Vector3 p = spline.ControlPoints[0].Position; for (int i = 1; i < spline.ControlPointCount; i++) { if (!Mathf.Approximately(spline.ControlPoints[i].Position.x, p.x)) { xplanar = false; } if (!Mathf.Approximately(spline.ControlPoints[i].Position.y, p.y)) { yplanar = false; } if (!Mathf.Approximately(spline.ControlPoints[i].Position.z, p.z)) { zplanar = false; } if (xplanar == false && yplanar == false && zplanar == false) { return(false); } } return(true); }
/// <summary> /// Converts a distance to a TF value /// </summary> /// <param name="distance">distance in the range 0..Length</param> /// <returns>a TF value in the range 0..1</returns> public override float DistanceToTF(float distance) { float localDistance; CurvySpline spl = DistanceToSpline(distance, out localDistance); return(SplineToTF(spl, spl.DistanceToTF(localDistance))); }
// Code that runs on entering the state. public override void OnEnter() { GameObject go = Fsm.GetOwnerDefaultTarget(GameObject); if (go) { CurvySpline spl = go.GetComponent <CurvySpline>(); if (spl) { if (GetSegment.Value) { if (spl.Count > 0) { StoreObject.Value = spl[Mathf.Clamp(Index.Value, 0, spl.Count - 1)].gameObject; } } else if (spl.ControlPointCount > 0) { StoreObject.Value = spl.ControlPointsList[Mathf.Clamp(Index.Value, 0, spl.ControlPointCount - 1)].gameObject; } } } Finish(); }
void OnSplineRefresh(CurvySpline spline) { Planar = CurvyUtility.isPlanar(Spline, out IgnoreAxis); if (Planar) Triangulate(); Repaint(); }
public CurvySplineEventArgs(MonoBehaviour sender, CurvySpline spline = null, object data = null) { Sender = sender; Spline = spline; Data = data; }
/// <summary> /// Gets a rotation looking to Tangent with the head upwards along the Up-Vector /// </summary> /// <param name="tf">TF value reflecting position in the group (0..1)</param> /// <param name="inverse">whether the orientation should be inversed or not</param> /// <returns>a rotation</returns> public override Quaternion GetOrientationFast(float tf, bool inverse) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return(spl.GetOrientationFast(localTF, inverse)); }
/// <summary> /// Gets an interpolated Scale for a certain group TF /// </summary> /// <remarks>TF (Total Fragment) relates to the total length of the group</remarks> /// <param name="tf">TF value reflecting position in the group(0..1)</param> /// <returns>the interpolated value</returns> public override Vector3 InterpolateScale(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return(spl.InterpolateScale(localTF)); }
IEnumerator NavigationLine(float waitTime) { while (true) { yield return(new WaitForSeconds(waitTime)); CurvySpline curvySpline = pathEnhanced.GetComponent <CurvySpline>(); segmentsToSearch.Add(curSegment); segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex + 1].GetComponent <CurvySplineSegment>()); segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex - 1].GetComponent <CurvySplineSegment>()); //float carTf = curvySpline.GetNearestPointTFExt(transform.position, segmentsToSearch.ToArray()); float carTf = curvySpline.GetNearestPointTF(transform.position); Lane lane = MonitorLane(curvySpline.GetTangentFast(carTf)); if (lane == Lane.RIGHT) { linesUtilsAlt.DrawLine(gameObject, curvySpline, carTf); } else { linesUtilsAlt.LineRend.positionCount = 0; //delete the LineRenderer } curSegment = curvySpline.TFToSegment(carTf); segmentsToSearch.Clear(); } }
/// <summary> /// Gets an interpolated User Value for a certain group TF /// </summary> /// <remarks>TF (Total Fragment) relates to the total length of the group</remarks> /// <param name="tf">TF value reflecting position in the group (0..1)</param> /// <param name="index">the UserValue array index</param> /// <returns>the interpolated value</returns> public override Vector3 InterpolateUserValue(float tf, int index) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return(spl.InterpolateUserValue(localTF, index)); }
// Use this for initialization IEnumerator Start() { mSpline = GetComponent<CurvySpline>(); Walker = GameObject.FindObjectOfType(typeof(FollowSpline)) as FollowSpline; while (!mSpline.IsInitialized) yield return null; }
public void UpdateATL(CurvySpline spline) { t = spline.GetNearestPointTF(transform.position); Vector3 splineAtT = spline.Interpolate(t); if (transform.position.y < splineAtT.y) { lastPos = splineAtT; Camera.main.GetComponent <CameraController_three> ().falling = true; //SceneManager.LoadScene ("three"); StartCoroutine(Fall(5.0f, spline)); //pass in length of fall } else { Camera.main.GetComponent <CameraController_three> ().falling = false; } if (!m_Jump) { m_Jump = Input.GetButtonDown("Jump"); } //disabling jump m_Jump = false; }
/// <summary> /// Interpolates position for a local F /// </summary> /// <param name="localF">a local F in the range 0..1</param> /// <param name="interpolation">the interpolation to use</param> /// <returns>the interpolated position</returns> public Vector3 Interpolate(float localF, CurvyInterpolation interpolation) { localF = Mathf.Clamp01(localF); switch (interpolation) { case CurvyInterpolation.Bezier: return(CurvySpline.Bezier(HandleOutScaled, Transform.position, NextTransform.position, NextControlPoint.HandleInScaled, localF)); case CurvyInterpolation.CatmulRom: //return CurvySpline.CatmulRom(PreviousTransform.position, Transform.position, NextTransform.position, NextControlPoint.NextTransform.position, localF); return(CurvySpline.CatmulRom(GetPrevPosition(), Transform.position, GetNextPosition(), GetNextNextPosition(), localF)); case CurvyInterpolation.TCB: float t0 = StartTension; float t1 = EndTension; float c0 = StartContinuity; float c1 = EndContinuity; float b0 = StartBias; float b1 = EndBias; if (!OverrideGlobalTension) { t0 = t1 = Spline.Tension; } if (!OverrideGlobalContinuity) { c0 = c1 = Spline.Continuity; } if (!OverrideGlobalBias) { b0 = b1 = Spline.Bias; } return(CurvySpline.TCB(PreviousTransform.position, Transform.position, NextTransform.position, NextControlPoint.NextTransform.position, localF, t0, c0, b0, t1, c1, b1)); default: // LINEAR return(Vector3.Lerp(Transform.position, NextTransform.position, localF)); } }
// Use this for initialization IEnumerator Start () { mBuilder = GetComponent<SplinePathCloneBuilder>(); mSpline = (CurvySpline)mBuilder.Spline; while (!mSpline.IsInitialized) yield return 0; mCPToMove = mSpline.ControlPoints[1].Transform; UpdateClones(); }
void checkForSpline() { if (Spline == null) { Spline = CurvySpline.Create(); Camera.main.GetComponent<CurvyGLRenderer>().Add(Spline); for (int i = 0; i < 4; i++) AddCP(); } }
void Init(CurvySpline spline) { Spline = spline; splMatrix = spline.Transform.localToWorldMatrix; Planar = CurvyUtility.isPlanar(Spline,out IgnoreAxis); if (Planar) Triangulate(); Repaint(); Spline.OnRefresh += OnSplineRefresh; }
void getRange(CurvySpline spline, CGDataRequestRasterization raster, out float startDist, out float endDist) { if (StartCP) { float l = getPathLength(spline); startDist = StartCP.Distance + l * raster.Start; endDist = StartCP.Distance + l * (raster.Start + raster.Length); } else { startDist = spline.Length * raster.Start; endDist = spline.Length * (raster.Start + raster.Length); } }
void OnSelectionChange() { if (Spline) Spline.OnRefresh -= OnSplineRefresh; Spline = null; if (Selection.activeGameObject) { var spl = Selection.activeGameObject.GetComponent<CurvySpline>(); if (spl) Init(spl); var cp = Selection.activeGameObject.GetComponent<CurvySplineSegment>(); if (cp) Init(cp.Spline); } Repaint(); }
void Init(CurvySpline spline) { Spline = spline; }
MetaCGOptions findNextReferenceCPOptions(CurvySpline spline, float tf, out CurvySplineSegment cp) { MetaCGOptions options; float localF; cp = spline.TFToSegment(tf, out localF); do { cp = cp.NextControlPoint; options = cp.GetMetadata<MetaCGOptions>(true); if (!spline.Closed && cp.IsLastVisibleControlPoint) return options; } while (!options.UVEdge && !options.ExplicitU && !options.HasDifferentMaterial && !cp.IsFirstSegment); return options; }
void Awake() { // for this example we assume the component is attached to a GameObject holding a spline mSpline = GetComponent<CurvySpline>(); }
/// <summary> /// Equalize one axis of a spline to match the first control points's value /// </summary> /// <param name="spline">a CurvySpline</param> /// <param name="axis">the axis to equalize (0=x,1=y,2=z)</param> public static void makePlanar(CurvySpline spline, int axis) { Vector3 p = spline.ControlPoints[0].Position; for (int i = 1; i < spline.ControlPointCount; i++) { Vector3 pi = spline.ControlPoints[i].Position; switch (axis) { case 0: pi.x = p.x; break; case 1: pi.y = p.y; break; case 2: pi.z = p.z; break; } spline.ControlPoints[i].Position = pi; } spline.Refresh(); }
/// <summary> /// Gets the part of the connection belonging to the spline /// </summary> /// <param name="spline">a spline</param> /// <returns>the Control Point belonging to spline that is part of this connection or null</returns> public CurvySplineSegment GetFromSpline(CurvySpline spline) { if (Owner && Owner.Spline == spline) return Owner; else if (Other && Other.Spline == spline) return Other; else return null; }
/// <summary> /// Called before starting to move in editor preview /// </summary> /// <remarks> /// Use this to store settings, e.g. the initial VirtualPosition /// </remarks> public override void BeginPreview() { mInitialSpline = Spline; base.BeginPreview(); }
/// <summary> /// Alter TF to reflect a movement over a certain portion of the spline, using connections if conditions match. Unlike MoveConnection() a linear approximation will be used /// </summary> /// <param name="spline">the current spline</param> /// <param name="tf">the current TF value</param> /// <param name="direction">the current direction, 1 or -1</param> /// <param name="fDistance">the percentage of the spline to move</param> /// <param name="clamping">clamping mode</param> /// <param name="minMatchesNeeded">minimum number of tags that must match to use a connection</param> /// <param name="tags">list of tags to match</param> /// <returns>the interpolated position</returns> public Vector3 MoveConnectionFast(ref CurvySpline spline, ref float tf, ref int direction, float fDistance, CurvyClamping clamping, int minMatchesNeeded, params string[] tags) { List<CurvyConnection> cons = GetConnectionsWithin(tf, direction, fDistance, minMatchesNeeded,true, tags); if (cons.Count > 0) { CurvyConnection con; if (cons.Count == 1) con = cons[0]; else con = CurvyConnection.GetBestMatchingConnection(cons, tags); CurvySplineSegment cp = con.GetFromSpline(this); float cptf = SegmentToTF(cp); fDistance -= cptf - tf; CurvySplineSegment counterp = con.GetCounterpart(cp); tf = counterp.LocalFToTF(0); spline = counterp.Spline; return spline.MoveConnectionFast(ref spline, ref tf, ref direction, fDistance, clamping, minMatchesNeeded, tags); } else return MoveFast(ref tf, ref direction, fDistance, clamping); }
/// <summary> /// Creates an empty spline with the same settings as another spline /// </summary> /// <param name="takeOptionsFrom">another spline</param> public static CurvySpline Create(CurvySpline takeOptionsFrom) { CurvySpline spl = Create(); if (takeOptionsFrom) { spl.Interpolation = takeOptionsFrom.Interpolation; spl.Closed = takeOptionsFrom.Closed; spl.AutoEndTangents = takeOptionsFrom.AutoEndTangents; spl.Granularity = takeOptionsFrom.Granularity; spl.Orientation = takeOptionsFrom.Orientation; spl.InitialUpVector = takeOptionsFrom.InitialUpVector; spl.Swirl = takeOptionsFrom.Swirl; spl.SwirlTurns = takeOptionsFrom.SwirlTurns; spl.AutoRefresh = takeOptionsFrom.AutoRefresh; spl.AutoRefreshLength = takeOptionsFrom.AutoRefreshLength; spl.AutoRefreshOrientation = takeOptionsFrom.AutoRefreshOrientation; spl.UserValueSize = takeOptionsFrom.UserValueSize; } return spl; }
void OnSplineRefresh(CurvySpline sender) { if (Time.realtimeSinceStartup - mLastRefresh > AutoRefreshSpeed) { mLastRefresh = Time.realtimeSinceStartup; Refresh(false); } }
/// <summary> /// Builds a mesh from a spline (2D), taking interpolated points based on curvation angle /// </summary> /// <param name="spline">the spline to use</param> /// <param name="ignoreAxis">the axis to ignore (0=x,1=y,2=z)</param> /// <param name="close">True to create a mesh with triangles, False to create a vertex line mesh</param> /// <param name="angleDiff">the curvation angle used to interpolate points</param> public static Mesh CreateSplineMesh(CurvySpline spline, int ignoreAxis, bool close, float angleDiff) { float tf = 0; int dir = 1; List<Vector3> verts = new List<Vector3>(); verts.Add(spline.Transform.worldToLocalMatrix.MultiplyPoint3x4(spline.Interpolate(0))); while (tf < 1) { verts.Add(spline.Transform.worldToLocalMatrix.MultiplyPoint3x4(spline.MoveByAngle(ref tf, ref dir, angleDiff, CurvyClamping.Clamp, 0.005f))); } return buildSplineMesh(verts.ToArray(), ignoreAxis, !close); }
/// <summary> /// Builds a mesh from a spline's approximation points (2D) /// </summary> /// <param name="spline">the spline to use</param> /// <param name="ignoreAxis">the axis to ignore (0=x,1=y,2=z)</param> /// <param name="close">True to create a mesh with triangles, False to create a vertex line mesh</param> /// <param name="msh"></param> public static Mesh CreateSplineMesh(CurvySpline spline, int ignoreAxis, bool close, Mesh msh = null) { Vector3[] verts = spline.GetApproximation(true); if (spline.Closed) CurvySplineSegment.Resize(ref verts, verts.Length - 1); return buildSplineMesh(verts, ignoreAxis, !close, msh); }
public CurvyMeshSegmentInfo(SplinePathMeshBuilder mb, float tf, float distance, Vector3 scale) { Spline = mb.Spline; TF = tf; mDistance = distance; Vector3 p = (mb.FastInterpolation) ? Spline.InterpolateFast(TF) : Spline.Interpolate(TF); if (mb.UseWorldPosition) Matrix = Matrix4x4.TRS(mb.Transform.InverseTransformPoint(p), Spline.GetOrientationFast(TF), scale); else Matrix = Matrix4x4.TRS(Spline.Transform.InverseTransformPoint(p), Spline.GetOrientationFast(TF), scale); }
/// <summary> /// Centers Control Points around Spline transform /// </summary> /// <param name="spline">The spline to address</param> public static void centerPivot(CurvySpline spline) { Bounds b = spline.GetBounds(false); Vector3 off = spline.Transform.position - b.center; foreach (CurvySplineSegment cp in spline.ControlPoints) cp.Transform.position += off; spline.transform.position -= off; spline.Refresh(); }
MetaCGOptions findPreviousReferenceCPOptions(CurvySpline spline, float tf, out CurvySplineSegment cp) { MetaCGOptions options; cp = spline.TFToSegment(tf); do { options = cp.GetMetadata<MetaCGOptions>(true); if (cp.IsFirstVisibleControlPoint) return options; cp = cp.PreviousSegment; } while (cp && !options.UVEdge && !options.ExplicitU &&!options.HasDifferentMaterial); return options; }
/// <summary> /// Alter TF to reflect a movement over a certain distance, using connections if conditions match. Unlike MoveByConnection() a linear approximation will be used. /// </summary> /// <param name="spline">the current spline</param> /// <param name="tf">the current TF value</param> /// <param name="direction">the current direction, 1 or -1</param> /// <param name="distance">the distance in world units to move</param> /// <param name="clamping">clamping mode</param> /// <param name="minMatchesNeeded">minimum number of tags that must match to use a connection</param> /// <param name="stepSize">stepSize defines the accuracy</param> /// <param name="tags">list of tags to match</param> /// <returns>the interpolated position</returns> public Vector3 MoveByConnectionFast(ref CurvySpline spline, ref float tf, ref int direction, float distance, CurvyClamping clamping, int minMatchesNeeded, float stepSize, params string[] tags) { return MoveConnectionFast(ref spline, ref tf, ref direction, ExtrapolateDistanceToTFFast(tf, distance, stepSize), clamping, minMatchesNeeded, tags); }
/// <summary> /// Alter TF to reflect a movement over a certain distance using a default stepSize of 0.002, using connections if conditions match. /// Unlike MoveByConnection() a linear approximation will be used. /// </summary> /// <param name="spline">the current spline</param> /// <param name="tf">the current TF value</param> /// <param name="direction">the current direction, 1 or -1</param> /// <param name="distance">the distance in world units to move</param> /// <param name="clamping">clamping mode</param> /// <param name="minMatchesNeeded">minimum number of tags that must match to use a connection</param> /// <param name="tags">list of tags to match</param> /// <returns>the interpolated position</returns> public Vector3 MoveByConnectionFast(ref CurvySpline spline, ref float tf, ref int direction, float distance, CurvyClamping clamping, int minMatchesNeeded, params string[] tags) { return MoveByConnectionFast(ref spline, ref tf, ref direction, distance, clamping, minMatchesNeeded, 0.002f, tags); }
void addRandomCP(ref CurvySpline spline, int count, int totalLength) { Vector3[] pos=new Vector3[count]; float segLength = totalLength / (float)(count - 1); pos[0] = Vector3.zero; for (int i = 1; i < count; i++) { int dir = Random.Range(0, 2); int sign=Random.Range(0f,1f)>0.5f ? 1 : -1; switch (dir) { case 0: pos[i] = pos[i - 1] + new Vector3(segLength * sign, 0, 0); break; case 1: pos[i] = pos[i - 1] + new Vector3(0,segLength * sign,0); break; case 2: pos[i] = pos[i - 1] + new Vector3(0,0,segLength * sign); break; } } spline.Add(pos); spline.Refresh(); }
protected float getPathLength(CurvySpline spline) { if (!spline) return 0; if (StartCP) { if (EndCP) { return EndCP.Distance - StartCP.Distance; } } return spline.Length; }
/// <summary> /// Checks if the curve is planar /// </summary> /// <param name="spline">a CurvySpline</param> /// <param name="xplanar">whether the x-axis is planar</param> /// <param name="yplanar">whether the y-axis is planar</param> /// <param name="zplanar">whether the z-axis is planar</param> /// <returns>true if at least on axis is planar</returns> public static bool isPlanar(CurvySpline spline, out bool xplanar, out bool yplanar, out bool zplanar) { xplanar = true; yplanar = true; zplanar = true; if (spline.ControlPointCount == 0) return false; Vector3 p = spline.ControlPoints[0].Position; for (int i = 1; i < spline.ControlPointCount; i++) { if (!Mathf.Approximately(spline.ControlPoints[i].Position.x, p.x)) xplanar = false; if (!Mathf.Approximately(spline.ControlPoints[i].Position.y, p.y)) yplanar = false; if (!Mathf.Approximately(spline.ControlPoints[i].Position.z, p.z)) zplanar = false; if (xplanar == false && yplanar == false && zplanar == false) return false; } return true; }
/// <summary> /// Checks if the curve is planar /// </summary> /// <param name="spline">a CurvySpline</param> /// <param name="ignoreAxis">returns the axis that can be ignored (0=x,1=y,2=z)</param> /// <returns>true if a planar axis was found</returns> public static bool isPlanar(CurvySpline spline, out int ignoreAxis) { bool xp, yp, zp; bool res = isPlanar(spline, out xp, out yp, out zp); if (xp) ignoreAxis = 0; else if (yp) ignoreAxis = 1; else ignoreAxis = 2; return res; }