public void ParseVertex(string lVertexString) { string[] array = lVertexString.Split(new char[] { '/' }, StringSplitOptions.None); int num = array[0].ParseInvariantInt(); OBJFaceVertex oBJFaceVertex = new OBJFaceVertex { m_VertexIndex = num - 1 }; if (array.Length > 1) { num = ((array[1].Length == 0) ? 0 : array[1].ParseInvariantInt()); oBJFaceVertex.m_UVIndex = num - 1; } if (array.Length > 2) { num = ((array[2].Length == 0) ? 0 : array[2].ParseInvariantInt()); oBJFaceVertex.m_NormalIndex = num - 1; } if (array.Length > 3) { num = ((array[3].Length == 0) ? 0 : array[3].ParseInvariantInt()); oBJFaceVertex.m_UV2Index = num - 1; } if (array.Length > 4) { num = ((array[4].Length == 0) ? 0 : array[4].ParseInvariantInt()); oBJFaceVertex.m_ColorIndex = num - 1; } this.AddVertex(oBJFaceVertex); }
public string ToString(int lIndex) { OBJFaceVertex oBJFaceVertex = this.m_Vertices[lIndex]; string text = (oBJFaceVertex.m_VertexIndex + 1).ToString(); if (oBJFaceVertex.m_UVIndex > -1) { text += string.Format("/{0}", (oBJFaceVertex.m_UVIndex + 1).ToString()); } if (oBJFaceVertex.m_NormalIndex > -1) { text += string.Format("/{0}", (oBJFaceVertex.m_NormalIndex + 1).ToString()); } if (oBJFaceVertex.m_UV2Index > -1) { text += string.Format("/{0}", (oBJFaceVertex.m_UV2Index + 1).ToString()); } if (oBJFaceVertex.m_ColorIndex > -1) { text += string.Format("/{0}", (oBJFaceVertex.m_ColorIndex + 1).ToString()); } return(text); }
public static void LoadOBJ(this Mesh lMesh, OBJData lData) { List <Vector3> list = new List <Vector3>(); List <Vector3> list2 = new List <Vector3>(); List <Vector2> list3 = new List <Vector2>(); List <int>[] array = new List <int> [lData.m_Groups.Count]; Dictionary <OBJFaceVertex, int> dictionary = new Dictionary <OBJFaceVertex, int>(); bool flag = lData.m_Normals.Count > 0; bool flag2 = lData.m_UVs.Count > 0; lMesh.subMeshCount = lData.m_Groups.Count; for (int i = 0; i < lData.m_Groups.Count; i++) { OBJGroup oBJGroup = lData.m_Groups[i]; array[i] = new List <int>(); for (int j = 0; j < oBJGroup.Faces.Count; j++) { OBJFace oBJFace = oBJGroup.Faces[j]; for (int k = 1; k < oBJFace.Count - 1; k++) { int[] array2 = new int[] { 0, k, k + 1 }; for (int l = 0; l < array2.Length; l++) { int i2 = array2[l]; OBJFaceVertex oBJFaceVertex = oBJFace[i2]; int item = -1; if (!dictionary.TryGetValue(oBJFaceVertex, out item)) { dictionary[oBJFaceVertex] = list.Count; item = list.Count; list.Add(lData.m_Vertices[oBJFaceVertex.m_VertexIndex]); if (flag2) { list3.Add(lData.m_UVs[oBJFaceVertex.m_UVIndex]); } if (flag) { list2.Add(lData.m_Normals[oBJFaceVertex.m_NormalIndex]); } } array[i].Add(item); } } } } lMesh.triangles = new int[0]; lMesh.vertices = list.ToArray(); lMesh.uv = list3.ToArray(); lMesh.normals = list2.ToArray(); if (!flag) { lMesh.RecalculateNormals(); } lMesh.RecalculateTangents(); for (int m = 0; m < lData.m_Groups.Count; m++) { lMesh.SetTriangles(array[m].ToArray(), m); } }
public static void LoadOBJ(this Mesh lMesh, OBJData lData, string subOject) { List <Vector3> list = new List <Vector3>(); List <Vector3> list2 = new List <Vector3>(); List <Vector2> list3 = new List <Vector2>(); List <int> list4 = new List <int>(); Dictionary <OBJFaceVertex, int> dictionary = new Dictionary <OBJFaceVertex, int>(); bool flag = lData.m_Normals.Count > 0; bool flag2 = lData.m_UVs.Count > 0; for (int i = 0; i < lData.m_Groups.Count; i++) { OBJGroup oBJGroup = lData.m_Groups[i]; if (!(oBJGroup.m_Name != subOject)) { for (int j = 0; j < oBJGroup.Faces.Count; j++) { OBJFace oBJFace = oBJGroup.Faces[j]; for (int k = 1; k < oBJFace.Count - 1; k++) { int[] array = new int[] { 0, k, k + 1 }; for (int l = 0; l < array.Length; l++) { int i2 = array[l]; OBJFaceVertex oBJFaceVertex = oBJFace[i2]; int item = -1; if (!dictionary.TryGetValue(oBJFaceVertex, out item)) { dictionary[oBJFaceVertex] = list.Count; item = list.Count; list.Add(lData.m_Vertices[oBJFaceVertex.m_VertexIndex]); if (flag2) { list3.Add(lData.m_UVs[oBJFaceVertex.m_UVIndex]); } if (flag) { list2.Add(lData.m_Normals[oBJFaceVertex.m_NormalIndex]); } } list4.Add(item); } } } } } if (list4.Count == 0) { return; } lMesh.vertices = list.ToArray(); lMesh.triangles = list4.ToArray(); lMesh.uv = list3.ToArray(); lMesh.normals = list2.ToArray(); if (!flag) { lMesh.RecalculateNormals(); } lMesh.RecalculateTangents(); }
public void AddVertex(OBJFaceVertex lVertex) { this.m_Vertices.Add(lVertex); }