using System; using UnityEngine; namespace ProBuilder2.Common { // Token: 0x02000045 RID: 69 public class pb_UVUtility { // Token: 0x06000223 RID: 547 RVA: 0x0001D4EC File Offset: 0x0001B8EC public static void PlanarMap2(Vector3[] verts, Vector2[] uvs, int[] indices, pb_UV uvSettings, Vector3 normal) { ProjectionAxis projectionAxis = pb_Projection.VectorToProjectionAxis(normal); pb_Projection.PlanarProject(verts, uvs, indices, normal, projectionAxis); pb_UVUtility.ApplyUVSettings(uvs, indices, uvSettings); } // Token: 0x06000224 RID: 548 RVA: 0x0001D514 File Offset: 0x0001B914 private static void ApplyUVSettings(Vector2[] uvs, int[] indices, pb_UV uvSettings) { int num = indices.Length; pb_UV.Fill fill = uvSettings.fill; if (fill != pb_UV.Fill.Tile) { if (fill != pb_UV.Fill.Fit) { if (fill == pb_UV.Fill.Stretch) { uvs = pb_UVUtility.StretchUVs(uvs, indices); } } else { uvs = pb_UVUtility.NormalizeUVs(uvs, indices); } } if (!uvSettings.useWorldSpace && uvSettings.anchor != pb_UV.Anchor.None) { pb_UVUtility.ApplyUVAnchor(uvs, indices, uvSettings.anchor); } if (uvSettings.scale.x != 1f || uvSettings.scale.y != 1f || uvSettings.rotation != 0f) { Vector2 vector = pb_Bounds2D.Center(uvs, indices); for (int i = 0; i < num; i++) { uvs[indices[i]] = uvs[indices[i]].ScaleAroundPoint(vector, uvSettings.scale); uvs[indices[i]] = uvs[indices[i]].RotateAroundPoint(vector, uvSettings.rotation); } } if (uvSettings.flipU || uvSettings.flipV || uvSettings.swapUV) { for (int j = 0; j < num; j++) { float num2 = uvs[indices[j]].x; float num3 = uvs[indices[j]].y; if (uvSettings.flipU) { num2 = -num2; } if (uvSettings.flipV) { num3 = -num3; } if (!uvSettings.swapUV) { uvs[indices[j]].x = num2; uvs[indices[j]].y = num3; } else { uvs[indices[j]].x = num3; uvs[indices[j]].y = num2; } } } uvSettings.localPivot = pb_Bounds2D.Center(uvs, indices); for (int k = 0; k < indices.Length; k++) { Vector2[] array = uvs; int num4 = indices[k]; array[num4].x = array[num4].x - uvSettings.offset.x; Vector2[] array2 = uvs; int num5 = indices[k]; array2[num5].y = array2[num5].y - uvSettings.offset.y; } } // Token: 0x06000225 RID: 549 RVA: 0x0001D764 File Offset: 0x0001BB64 private static Vector2[] StretchUVs(Vector2[] uvs, int[] indices) { Vector2 vector = pb_Math.LargestVector2(uvs, indices) - pb_Math.SmallestVector2(uvs, indices); for (int i = 0; i < indices.Length; i++) { uvs[i].x = uvs[indices[i]].x / vector.x; uvs[i].y = uvs[indices[i]].y / vector.y; } return uvs; } // Token: 0x06000226 RID: 550 RVA: 0x0001D7E0 File Offset: 0x0001BBE0 private static Vector2[] NormalizeUVs(Vector2[] uvs, int[] indices) { int num = indices.Length; Vector2 vector = pb_Math.SmallestVector2(uvs, indices); for (int i = 0; i < num; i++) { int num2 = indices[i]; uvs[num2].x = uvs[num2].x - vector.x; int num3 = indices[i]; uvs[num3].y = uvs[num3].y - vector.y; } float num4 = pb_Math.LargestValue(pb_Math.LargestVector2(uvs, indices)); for (int i = 0; i < num; i++) { int num5 = indices[i]; uvs[num5].x = uvs[num5].x / num4; int num6 = indices[i]; uvs[num6].y = uvs[num6].y / num4; } return uvs; } // Token: 0x06000227 RID: 551 RVA: 0x0001D890 File Offset: 0x0001BC90 [Obsolete("See ApplyAnchor().")] private static Vector2[] JustifyUVs(Vector2[] uvs, pb_UV.Justify j) { Vector2 vector = new Vector2(0f, 0f); switch (j) { case pb_UV.Justify.Right: vector = new Vector2(pb_Math.LargestVector2(uvs).x - 1f, 0f); break; case pb_UV.Justify.Left: vector = new Vector2(pb_Math.SmallestVector2(uvs).x, 0f); break; case pb_UV.Justify.Top: vector = new Vector2(0f, pb_Math.LargestVector2(uvs).y - 1f); break; case pb_UV.Justify.Center: vector = pb_Math.Average(uvs, null) - new Vector2(0.5f, 0.5f); break; case pb_UV.Justify.Bottom: vector = new Vector2(0f, pb_Math.SmallestVector2(uvs).y); break; } for (int i = 0; i < uvs.Length; i++) { uvs[i] -= vector; } return uvs; } // Token: 0x06000228 RID: 552 RVA: 0x0001D9AC File Offset: 0x0001BDAC private static void ApplyUVAnchor(Vector2[] uvs, int[] indices, pb_UV.Anchor anchor) { pb_UVUtility.tvec2.x = 0f; pb_UVUtility.tvec2.y = 0f; Vector2 vector = pb_Math.SmallestVector2(uvs, indices); Vector2 vector2 = pb_Math.LargestVector2(uvs, indices); if (anchor == pb_UV.Anchor.UpperLeft || anchor == pb_UV.Anchor.MiddleLeft || anchor == pb_UV.Anchor.LowerLeft) { pb_UVUtility.tvec2.x = vector.x; } else if (anchor == pb_UV.Anchor.UpperRight || anchor == pb_UV.Anchor.MiddleRight || anchor == pb_UV.Anchor.LowerRight) { pb_UVUtility.tvec2.x = vector2.x - 1f; } else { pb_UVUtility.tvec2.x = vector.x + (vector2.x - vector.x) * 0.5f - 0.5f; } if (anchor == pb_UV.Anchor.UpperLeft || anchor == pb_UV.Anchor.UpperCenter || anchor == pb_UV.Anchor.UpperRight) { pb_UVUtility.tvec2.y = vector2.y - 1f; } else if (anchor == pb_UV.Anchor.MiddleLeft || anchor == pb_UV.Anchor.MiddleCenter || anchor == pb_UV.Anchor.MiddleRight) { pb_UVUtility.tvec2.y = vector.y + (vector2.y - vector.y) * 0.5f - 0.5f; } else { pb_UVUtility.tvec2.y = vector.y; } int num = indices.Length; for (int i = 0; i < num; i++) { int num2 = indices[i]; uvs[num2].x = uvs[num2].x - pb_UVUtility.tvec2.x; int num3 = indices[i]; uvs[num3].y = uvs[num3].y - pb_UVUtility.tvec2.y; } } // Token: 0x0400019C RID: 412 private static Vector2 tvec2 = Vector2.zero; } }