public TweenData_RectTransform_AnchorPosSpline(RectTransform inRectTransform, ISpline inSpline, Axis inAxis, SplineTweenSettings inSettings) { m_RectTransform = inRectTransform; m_Spline = inSpline; m_Axis = inAxis; m_SplineSettings = inSettings; }
private RageSvgPathElement() { Spline = null; gO = null; IsClosed = false; IsLinear = false; }
public TweenData_SplineControl_Position(ISpline inSpline, int inIndex, Vector3 inTarget, Axis inAxis) { m_Spline = inSpline; m_Index = inIndex; m_Target = inTarget; m_Axis = inAxis; }
/// <summary> Updates the Outline Width of every element of a RageGroup. </summary> /// <param name="list">Group List</param> /// <param name="outlineWidth">Absolute outline Width or multiplying factor, per path</param> /// <param name="proportional">If proportional, outlineWidth is a multiplying factor to the current value</param> /// <param name="refresh">If false, only updates the AA data, doesn't refresh</param> public static void UpdateOutlineWidth(this List <RageGroupElement> list, float outlineWidth, bool proportional, bool refresh) { if (list == null) { return; } foreach (RageGroupElement rageGroupItem in list) { ISpline path = rageGroupItem.Spline; if (path == null) { continue; } if (proportional) { path.Outline.Width = path.Outline.Width * outlineWidth; } else { path.Outline.Width = outlineWidth; } if (refresh) { path.Rs.RefreshMesh(true, true, true); } } }
private static bool IsInsideSpline(ISpline mainSpline, ISpline subSpline) { if (mainSpline.PointsCount < 3) { return(false); } if (subSpline.PointsCount < 3) { return(false); } bool pointsInSpline = true; for (int i = 0; i < subSpline.PointsCount; i++) { var point = subSpline.GetPointAt(i).Position; pointsInSpline = SplineContainsPoint(mainSpline, point); if (!pointsInSpline) { break; } } if (!pointsInSpline) { return(false); } return(true); }
private static void GetCutPointData(ISpline mainSpline, ISpline subSpline, ref float cutPointSplinePosition, ref float holeCutPointSplinePosition, ref Vector3 cutPointPosition, ref Vector3 holeCutPointPosition, ref float cutPointDistance) { int mainSplineSubdiv = mainSpline.PointsCount > 10 ? mainSpline.PointsCount : 10; int holeSplineSubdiv = subSpline.PointsCount > 10 ? subSpline.PointsCount : 10; float pointStep = 1 / (float)mainSplineSubdiv; float holePointStep = 1 / (float)holeSplineSubdiv; for (float i = 0; i < 1; i += pointStep) { Vector3 splinePointPosition = mainSpline.Rs.spline.GetPoint(i); for (float j = 0; j < 1; j += holePointStep) { Vector3 holePointPosition = subSpline.Rs.spline.GetPoint(j); var currentDist = Vector2.Distance(splinePointPosition, holePointPosition); if ((Mathf.Approximately(i, 0)) && (Mathf.Approximately(j, 0))) { cutPointDistance = currentDist; } if (cutPointDistance <= currentDist) { continue; } cutPointDistance = currentDist; cutPointSplinePosition = i; holeCutPointSplinePosition = j; cutPointPosition = splinePointPosition; holeCutPointPosition = holePointPosition; } } }
private static List <int> ProcessHoles(ISpline mainSpline, Dictionary <int, ISpline> subSplines) { List <ISpline> holes = new List <ISpline>(); List <int> toRemove = new List <int>(); foreach (KeyValuePair <int, ISpline> path in subSplines) { if (!IsInsideSpline(mainSpline, path.Value)) { continue; } if (IsInsideSplines(subSplines, path.Value)) { continue; } holes.Add(path.Value); toRemove.Add(path.Key); } while (holes.Count > 0) { int holeIndex = FindHoleClosestToEdge(mainSpline, holes); MakeHole(mainSpline, holes[holeIndex]); holes.RemoveAt(holeIndex); } return(toRemove); }
/// <summary> /// Interpolates over the whole spline by the specified parametric value. /// </summary> /// <param name="self">The spline instance applied.</param> /// <param name="t"> /// Parametric value ranges from 0 to 1 representing the position along the whole length of the spline. /// </param> public static Vector3 Interpolate(this ISpline self, float t) { float pos = t * (self.PointCount - 1); var index = (int)pos; return(self.Interpolate(index, pos - index)); }
/// <summary> /// Returns info about a segment on the spline. /// </summary> static public SplineSegment GetSegment(this ISpline inSpline, float inPercent) { SplineSegment seg; inSpline.GetSegment(inPercent, out seg); return(seg); }
private static int FindHoleClosestToEdge(ISpline mainSpline, List <ISpline> holes) { int holeIndex = 0; float holeDistance = 0; for (int i = 0; i < holes.Count; i++) { float cutPointSplinePosition = 0; float holeCutPointSplinePosition = 0; Vector3 cutPointPosition = mainSpline.GetPointAt(0).Position; Vector3 holeCutPointPosition = holes[i].GetPointAt(0).Position; float cutPointDistance = 0; GetCutPointData(mainSpline, holes[i], ref cutPointSplinePosition, ref holeCutPointSplinePosition, ref cutPointPosition, ref holeCutPointPosition, ref cutPointDistance); if (i == 0) { holeDistance = cutPointDistance; continue; } if (cutPointDistance >= holeDistance) { continue; } holeIndex = i; holeDistance = cutPointDistance; } return(holeIndex); }
public static Quaternion Twist(ISpline core, float t_core, ISpline guide, float t_guide) { Vector3 corePoint = core.Evaluate(t_core); Vector3 rotationPoint = guide.Evaluate(t_guide); Vector3 tangentBasis = core.Tangent(t_core); tangentBasis = tangentBasis.normalized; Vector3 normalBasis = Vector3.Cross(tangentBasis, rotationPoint - corePoint); normalBasis = normalBasis.normalized; #region Uncomment this region to debug all Twist invocations /* * //Vector3 binormalBasis = Vector3.Cross(normalBasis, tangentBasis); * //binormalBasis = binormalBasis.normalized; * * //Debug.DrawLine(corePoint, corePoint + tangentBasis, Color.blue); * //Debug.DrawLine(corePoint, corePoint + normalBasis, Color.green); * //Debug.DrawLine(corePoint, corePoint + binormalBasis, Color.red); */ #endregion Uncomment this region to debug all Twist invocations return(Quaternion.LookRotation(tangentBasis, normalBasis)); }
/// <summary> /// Generates info about an interpolation along the given spline. /// </summary> static public void GetUpdateInfo(this ISpline inSpline, float inPercent, SplineLerp inLerpMethod, Curve inSegmentEase, out SplineUpdateInfo outInfo) { outInfo.Spline = inSpline; outInfo.Percent = inSpline.TransformPercent(inPercent, inLerpMethod); outInfo.Point = inSpline.GetPoint(outInfo.Percent, inSegmentEase); outInfo.Direction = inSpline.GetDirection(outInfo.Percent, inSegmentEase); }
public Bounds CalculateTransformedBounds(int maxIter = DEF_ITER_BOUND) { ISpline spline = Spline; if (spline == null) { Dbg.LogErr("BaseSplineBehaviour.CalculateTransformedBounds: not set spline yet"); return(new Bounds()); } Bounds bd = new Bounds(); if (maxIter < 0) { maxIter = Mathf.Max((spline.PointCount - 1) * 10, 100); } for (int i = 0; i < maxIter; ++i) { float t = (float)i / (float)maxIter; Vector3 p = GetTransformedPosition(t); bd.Encapsulate(p); } return(bd); }
/// <summary> Updates the Anti-Aliasing on every element of a RageGroup. </summary> /// <param name="list">Group List</param> /// <param name="antiAlias">Absolute AA or multiplying factor, per path</param> /// <param name="proportional">If proportional, antiAlias is a multiplying factor to the default value</param> /// <param name="refresh">If false, only updates the AA data, doesn't refresh</param> public static void UpdateAa(this List <RageGroupElement> list, float antiAlias, bool proportional, bool refresh) { if (list == null) { return; } foreach (RageGroupElement rageGroupItem in list) { if (rageGroupItem == null || rageGroupItem.Spline == null) { continue; } ISpline path = rageGroupItem.Spline; if (path == null) { continue; } if (proportional) { path.Outline.AntialiasingWidth = rageGroupItem.DefaultAa * antiAlias; } else { path.Outline.AntialiasingWidth = antiAlias; } if (refresh) { path.Rs.RefreshMesh(true, true, true); } } }
private void CalculateContainedPoints() { TouchingSplines = null; RageMagnetPoint.RemoveMagnetsFromPoint(this, Points); List <ISpline> splines = new List <ISpline>(); List <RageMagnetPoint> points = new List <RageMagnetPoint>(); foreach (RageGroupElement item in Group.List) { ISpline spline = item.Spline; if (spline == null) { continue; } for (int i = 0; i < (spline).PointsCount; i++) { FeedColliderData(points, spline, i); if (!splines.Contains(spline)) { splines.Add(spline); } } } TouchingSplines = splines.ToArray(); Points = points.ToArray(); }
protected void Reset() { Spline = CreateSpline(); foreach (var point in transform.Cast <Transform>().Select(t => t.localPosition)) { Spline.AddPoint(point); } }
public LineBuilder(IBezierBuilder b, IJointBuilder j, IJointBuilder js, ICapBuilder c, ISpline line) { _bezierDrawer = b; _jointDrawer = j; _capDrawer = c; _line = line; _jointIntersectDrawer = js; }
public EvaluationCache(ISpline spline, int cacheSize) : base(cacheSize) { for (int i = 0; i < this.Values.Length; i++) { this.Values[i] = spline.Evaluate((float)i / (Values.Length - 1)); } }
/// <summary> Finds the geometric center of a spline </summary> private static Vector3 GetSplineCenter(ISpline spline) { var meshFilter = spline.GameObject.GetComponent <MeshFilter>(); return(new Vector3(meshFilter.sharedMesh.bounds.center.x * spline.GameObject.transform.lossyScale.x, meshFilter.sharedMesh.bounds.center.y * spline.GameObject.transform.lossyScale.y, meshFilter.sharedMesh.bounds.center.z * spline.GameObject.transform.lossyScale.z)); }
public TweenData_Transform_PositionSpline(Transform inTransform, ISpline inSpline, Space inSpace, Axis inAxis, SplineTweenSettings inSettings) { m_Transform = inTransform; m_Spline = inSpline; m_Space = inSpace; m_Axis = inAxis; m_SplineSettings = inSettings; }
ISpline GetSpline() { if (_Spline == null) { _Spline = GetComponent <ISpline>(); } return(_Spline); }
protected override IEnumerable <float3> PointData(ISpline spline) { ISpline2D spline3D = (spline as ISpline2D); foreach (float2 point in spline3D.SplineEntityData2D.Value.Points) { yield return(new float3(point, 0f)); } }
protected override int SplineSegmentPointCount(ISpline spline) { ISpline2D spline3D = (spline as ISpline2D); Assert.NotNull(spline3D, "Unable to convert spline"); Assert.NotNull(spline3D.SplineEntityData2D, "spline failed to generate data"); return(spline3D.SplineEntityData2D.Value.Points.Length); }
public static void ClearSpline(ISpline spline) { while (spline.ControlPointCount > 0) { spline.RemoveControlPoint(0); } Assert.AreEqual(0f, spline.Length()); Assert.AreEqual(0, spline.ControlPointCount); }
/// <summary> /// Samples the spline for the given range and outputs to a list. /// </summary> static public void Sample(this ISpline inSpline, List <Vector2> outPoints, float inStart, float inEnd, int inNumSamples, SplineLerp inLerp = SplineLerp.Vertex) { float delta = inEnd - inStart; for (int i = 0; i < inNumSamples; ++i) { float t = (float)i / (inNumSamples - 1); outPoints.Add(inSpline.GetPoint(inSpline.TransformPercent(inStart + t * delta, inLerp))); } }
public Loft(ISpline path, ISpline shape) { if (path == null) throw new ArgumentNullException("path"); if (shape == null) throw new ArgumentNullException("shape"); Path = path; Shape = shape; }
private static void RedrawDraftCheck(ISpline spline, bool draft) { if (draft) { spline.Redraw(false, true, false, true); } else { spline.Redraw(); } }
/// <summary> Caches the original world position of the spline points. Very useful for Pivotools. </summary> private static void CachePointsDefaultData(ISpline path, RageGroupElement item, int pathPointCount) { for (int i = 0; i < pathPointCount; i++) { item.GroupPointCache[i] = new RageGroupPointCache(); ISplinePoint point = path.GetPointAt(i); item.GroupPointCache[i].PointPos = point.Position; item.GroupPointCache[i].InCtrlPos = point.InTangent; item.GroupPointCache[i].OutCtrlPos = point.OutTangent; } }
public static void DrawTestInterpolate(ISpline worldSpline, float t) { Vector3 targetPoint = worldSpline.Evaluate(t); float sphereSize = PathEditorUtility.Nice3DHandleSize(targetPoint); Handles.color = GetTColor(t); Handles.SphereCap(0, targetPoint, Quaternion.identity, sphereSize); Handles.color = Color.cyan; Handles.DrawAAPolyLine(targetPoint, targetPoint + worldSpline.Tangent(t).normalized); }
/// <summary> /// Aligns a RectTransform to a point along the spline, using anchoredPosition. /// </summary> static public void AlignAnchorPos(ISpline inSpline, RectTransform inTransform, float inPercent, Axis inAxis, SplineLerp inLerpMethod, Curve inSegmentEase, SplineOrientationSettings inOrientation) { SplineUpdateInfo info; GetUpdateInfo(inSpline, inPercent, inLerpMethod, inSegmentEase, out info); inTransform.SetAnchorPos(info.Point, inAxis); if (inOrientation != null) { inOrientation.Apply(ref info, inTransform, Space.Self); } }
public static ISpline[] GetSplinesInChildren(GameObject go) { RageSpline[] tmp = go.GetComponentsInChildren <RageSpline>(); ISpline[] result = new ISpline[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { result[i] = Adapt(tmp[i]); } return(result); }
/// <summary> /// Builds a cache from the results of evenly evaluating a spline. /// </summary> public static EvaluationCache EvenEvaluationCache(int cacheSize, ISpline spline, LengthCache splineLengthCache) { var points = new Vector3[cacheSize]; for (int i = 0; i < points.Length; i++) { points[i] = EvenlyEvaluate( spline, (float)i / (points.Length - 1), splineLengthCache); } return new EvaluationCache(points); }
/// <summary> /// Evaluates a spline based on the integrated length of the spline. /// </summary> public static Vector3 EvenlyEvaluate(ISpline spline, float percentLength, LengthCache splineLengthCache) { return spline.Evaluate(t_PercentLength(percentLength, splineLengthCache)); }
public static Mesh GenerateMesh(ISpline path, ISpline shape, uint pathSegments, uint shapeSegments) { return new Loft(path, shape).GenerateMesh(pathSegments, shapeSegments); }