summaryrefslogtreecommitdiff
path: root/Valheim_v0.141.2_r202102/Valheim/assembly_sunshafts/UnityStandardAssets.ImageEffects/Triangles.cs
blob: 3a79391bc896e635655860cb737e82eb1e59e20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using UnityEngine;

namespace UnityStandardAssets.ImageEffects;

internal class Triangles
{
	private static Mesh[] meshes;

	private static int currentTris;

	private static bool HasMeshes()
	{
		if (meshes == null)
		{
			return false;
		}
		for (int i = 0; i < meshes.Length; i++)
		{
			if (null == meshes[i])
			{
				return false;
			}
		}
		return true;
	}

	private static void Cleanup()
	{
		if (meshes == null)
		{
			return;
		}
		for (int i = 0; i < meshes.Length; i++)
		{
			if (null != meshes[i])
			{
				Object.DestroyImmediate(meshes[i]);
				meshes[i] = null;
			}
		}
		meshes = null;
	}

	private static Mesh[] GetMeshes(int totalWidth, int totalHeight)
	{
		if (HasMeshes() && currentTris == totalWidth * totalHeight)
		{
			return meshes;
		}
		int num = 21666;
		int num2 = (currentTris = totalWidth * totalHeight);
		meshes = new Mesh[Mathf.CeilToInt(1f * (float)num2 / (1f * (float)num))];
		int num3 = 0;
		int num4 = 0;
		for (num3 = 0; num3 < num2; num3 += num)
		{
			int triCount = Mathf.FloorToInt(Mathf.Clamp(num2 - num3, 0, num));
			meshes[num4] = GetMesh(triCount, num3, totalWidth, totalHeight);
			num4++;
		}
		return meshes;
	}

	private static Mesh GetMesh(int triCount, int triOffset, int totalWidth, int totalHeight)
	{
		Mesh mesh = new Mesh();
		mesh.hideFlags = HideFlags.DontSave;
		Vector3[] array = new Vector3[triCount * 3];
		Vector2[] array2 = new Vector2[triCount * 3];
		Vector2[] array3 = new Vector2[triCount * 3];
		int[] array4 = new int[triCount * 3];
		for (int i = 0; i < triCount; i++)
		{
			int num = i * 3;
			int num2 = triOffset + i;
			float num3 = Mathf.Floor(num2 % totalWidth) / (float)totalWidth;
			float num4 = Mathf.Floor(num2 / totalWidth) / (float)totalHeight;
			array[num + 2] = (array[num + 1] = (array[num] = new Vector3(num3 * 2f - 1f, num4 * 2f - 1f, 1f)));
			array2[num] = new Vector2(0f, 0f);
			array2[num + 1] = new Vector2(1f, 0f);
			array2[num + 2] = new Vector2(0f, 1f);
			array3[num] = new Vector2(num3, num4);
			array3[num + 1] = new Vector2(num3, num4);
			array3[num + 2] = new Vector2(num3, num4);
			array4[num] = num;
			array4[num + 1] = num + 1;
			array4[num + 2] = num + 2;
		}
		mesh.vertices = array;
		mesh.triangles = array4;
		mesh.uv = array2;
		mesh.uv2 = array3;
		return mesh;
	}
}