Anonymous Anonymous - 4 months ago
529 0

No description

C#

thingy

Vector2[] GetTextureCoordinates()
	{
		List<Vector3> v = new List<Vector3>();
		List<Vector2> vt = new List<Vector2>();
		Vector2[] texCoords = new Vector2[1024];
		int indexPoint;
		int texIndexPoint;

		string text = TexCoordinatesFile.text;
		string[] lines = text.Split(new[] { "\n" }, System.StringSplitOptions.RemoveEmptyEntries);

		foreach (string line in lines)
		{
			string[] lineSplit = line.Split(' ');

			// ex. "v -22.571495 -26.737658 38.676575"             
			if (lineSplit[0] == "v")
			{
				v.Add(new Vector3((float)Double.Parse(lineSplit[1]), float.Parse(lineSplit[2]), float.Parse(lineSplit[3])));
			}

			// ex. "vt 0.5465 0.2624"
			else if (lineSplit[0] == "vt")
			{
				vt.Add(new Vector2(float.Parse(lineSplit[1]), float.Parse(lineSplit[2])));
			}

			// ex. "f 410/410/413 399/399/413 63/60/413"
			else if (lineSplit[0] == "f")
			{
				int[] indexPoints = { 0, 0, 0 };
				int[] texIndexPoints = { 0, 0, 0 };
				for (int i = 1; i < 4; i++)
				{
					indexPoints[i - 1] = int.Parse(lineSplit[i].Split('/')[0]);
					texIndexPoints[i - 1] = int.Parse(lineSplit[i].Split('/')[1]);
				}

				for (int i = 0; i < 3; i++)
				{
					indexPoint = indexPoints[i];
					texIndexPoint = texIndexPoints[i];

					texCoords[indexPoint - 1].x = vt[texIndexPoint - 1].x;
					texCoords[indexPoint - 1].y = vt[texIndexPoint - 1].y;
				}

			}
		}

		return texCoords;
	}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download