public static OBJData EncodeOBJ(this Mesh lMesh) { OBJData oBJData = new OBJData { m_Vertices = new List <Vector3>(lMesh.vertices), m_UVs = new List <Vector2>(lMesh.uv), m_Normals = new List <Vector3>(lMesh.normals), m_UV2s = new List <Vector2>(lMesh.uv2), m_Colors = new List <Color>(lMesh.colors) }; for (int i = 0; i < lMesh.subMeshCount; i++) { int[] triangles = lMesh.GetTriangles(i); OBJGroup oBJGroup = new OBJGroup(lMesh.name + "_" + i.ToString()); for (int j = 0; j < triangles.Length; j += 3) { OBJFace oBJFace = new OBJFace(); oBJFace.AddVertex(new OBJFaceVertex { m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j] : -1, m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j] : -1, m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j] : -1, m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j] : -1, m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j] : -1 }); oBJFace.AddVertex(new OBJFaceVertex { m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j + 1] : -1, m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j + 1] : -1, m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j + 1] : -1, m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j + 1] : -1, m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j + 1] : -1 }); oBJFace.AddVertex(new OBJFaceVertex { m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j + 2] : -1, m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j + 2] : -1, m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j + 2] : -1, m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j + 2] : -1, m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j + 2] : -1 }); oBJGroup.AddFace(oBJFace); } oBJData.m_Groups.Add(oBJGroup); } return(oBJData); }
private static void PushOBJFace(string lFaceLine) { OBJLoader.PushOBJGroupIfNeeded(); string[] array = lFaceLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); OBJFace oBJFace = new OBJFace(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string lVertexString = array2[i]; oBJFace.ParseVertex(lVertexString); } OBJLoader.m_CurrentGroup.AddFace(oBJFace); }
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 static OBJData EncodeOBJ(this Mesh lMesh) { OBJData oBJData = new OBJData { m_Vertices = new List<Vector3>(lMesh.vertices), m_UVs = new List<Vector2>(lMesh.uv), m_Normals = new List<Vector3>(lMesh.normals), m_UV2s = new List<Vector2>(lMesh.uv2), m_Colors = new List<Color>(lMesh.colors) }; for (int i = 0; i < lMesh.subMeshCount; i++) { int[] triangles = lMesh.GetTriangles(i); OBJGroup oBJGroup = new OBJGroup(lMesh.name + "_" + i.ToString()); for (int j = 0; j < triangles.Length; j += 3) { OBJFace oBJFace = new OBJFace(); oBJFace.AddVertex(new OBJFaceVertex { m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j] : -1, m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j] : -1, m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j] : -1, m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j] : -1, m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j] : -1 }); oBJFace.AddVertex(new OBJFaceVertex { m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j + 1] : -1, m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j + 1] : -1, m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j + 1] : -1, m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j + 1] : -1, m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j + 1] : -1 }); oBJFace.AddVertex(new OBJFaceVertex { m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j + 2] : -1, m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j + 2] : -1, m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j + 2] : -1, m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j + 2] : -1, m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j + 2] : -1 }); oBJGroup.AddFace(oBJFace); } oBJData.m_Groups.Add(oBJGroup); } return oBJData; }
public void AddFace(OBJFace lFace) { this.m_Faces.Add(lFace); }