/// <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; } }
/// <summary> Sets the rotation to zero and scale to one of all Game Objects in the hierarchy, /// while maintaining the points in the same position. </summary> public void FreezeRotationAndScale() { if (!FindRageGroup()) { return; } Group.UpdatePathList(); // Updates Point World Coords Cache var originalScale = transform.lossyScale.y; ResetRotationAndScale(gameObject.transform); if (Group.List != null) { foreach (var groupItem in Group.List) { var spline = groupItem.Spline; for (int i = 0; i < spline.PointsCount; i++) { ISplinePoint point = spline.GetPointAt(i); point.Position = groupItem.GroupPointCache[i].PointPos; point.InTangent = groupItem.GroupPointCache[i].InCtrlPos; point.OutTangent = groupItem.GroupPointCache[i].OutCtrlPos; } if (spline.FillType == Spline.FillType.Gradient) { //scale var gradientScale = spline.FillGradient.Scale; var scaleOffset = 1 / groupItem.ScaleCache.x; spline.FillGradient.Scale = gradientScale * scaleOffset; //rotate spline.FillGradient.Angle += -groupItem.RotationCache.eulerAngles.z; //translate spline.FillGradient.Offset = spline.GameObject.transform.InverseTransformPoint(groupItem.GradientOffsetCache); } spline.Rs.RefreshMeshInEditor(true, true, true); } // Multiply the outline width by the original scale, to keep it visually the same. Group.List.UpdateOutlineWidth(originalScale, true, true); } }
public static void AverageMagnetPoint(this RageMagnetPoint ragePoint) { var pointsData = ragePoint.RelatedData; Vector3 pointPosSum = Vector3.zero; Vector3 inCtrlPosSum = Vector3.zero; Vector3 outCtrlPosSum = Vector3.zero; foreach (var relativeData in pointsData) { pointPosSum += relativeData.AbsolutePointPos; inCtrlPosSum += relativeData.AbsoluteInCtrlPos; outCtrlPosSum += relativeData.AbsoluteOutCtrlPos; } ISplinePoint point = ragePoint.Spline.GetPointAt(ragePoint.Index); point.Position = pointPosSum / pointsData.Length; point.InTangent = inCtrlPosSum / pointsData.Length; point.OutTangent = outCtrlPosSum / pointsData.Length; }
public void RemovePoint(ISplinePoint point) { _rageSpline.RemovePoint(point.Index); }