public static Mesh ImportFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                Debug.LogError("No file was found at '" + filePath + "'");
                return(null);
            }
            ObjImporter.meshStruct meshStruct = ObjImporter.createMeshStruct(filePath);
            ObjImporter.populateMeshStruct(ref meshStruct);
            Vector3[] array  = new Vector3[meshStruct.faceData.Length];
            Vector2[] array2 = new Vector2[meshStruct.faceData.Length];
            Vector3[] array3 = new Vector3[meshStruct.faceData.Length];
            int       num    = 0;

            Vector3[] faceData = meshStruct.faceData;
            for (int i = 0; i < faceData.Length; i++)
            {
                Vector3 vector = faceData[i];
                array[num] = meshStruct.vertices[(int)vector.x - 1];
                if (vector.y >= 1f)
                {
                    array2[num] = meshStruct.uv[(int)vector.y - 1];
                }
                if (vector.z >= 1f)
                {
                    array3[num] = meshStruct.normals[(int)vector.z - 1];
                }
                num++;
            }
            Mesh mesh = new Mesh();

            mesh.vertices  = array;
            mesh.uv        = array2;
            mesh.normals   = array3;
            mesh.triangles = meshStruct.triangles;
            mesh.RecalculateBounds();
            return(mesh);
        }
        private static ObjImporter.meshStruct createMeshStruct(string filename)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;
            int num5 = 0;

            ObjImporter.meshStruct result = default(ObjImporter.meshStruct);
            result.fileName = filename;
            StreamReader streamReader = File.OpenText(filename);
            string       text         = streamReader.ReadToEnd();

            streamReader.Dispose();
            using (StringReader stringReader = new StringReader(text))
            {
                string text2 = stringReader.ReadLine();
                char[] array = new char[]
                {
                    ' '
                };
                while (text2 != null)
                {
                    if (!text2.StartsWith("f ") && !text2.StartsWith("v ") && !text2.StartsWith("vt ") && !text2.StartsWith("vn "))
                    {
                        text2 = stringReader.ReadLine();
                        if (text2 != null)
                        {
                            text2 = text2.Replace("  ", " ");
                        }
                    }
                    else
                    {
                        text2 = text2.Trim();
                        string[] array2 = text2.Split(array, 50);
                        string   text3  = array2[0];
                        string   text4  = text3;
                        if (text4 != null)
                        {
                            if (ObjImporter.< > f__switch$map1 == null)
                            {
                                Dictionary <string, int> dictionary = new Dictionary <string, int>(4);
                                dictionary.Add("v", 0);
                                dictionary.Add("vt", 1);
                                dictionary.Add("vn", 2);
                                dictionary.Add("f", 3);
                                ObjImporter.< > f__switch$map1 = dictionary;
                            }
                            int num6;
                            if (ObjImporter.< > f__switch$map1.TryGetValue(text4, ref num6))
                            {
                                switch (num6)
                                {
                                case 0:
                                    num2++;
                                    break;

                                case 1:
                                    num3++;
                                    break;

                                case 2:
                                    num4++;
                                    break;

                                case 3:
                                    num5 = num5 + array2.Length - 1;
                                    num += 3 * (array2.Length - 2);
                                    break;
                                }
                            }
                        }
                        text2 = stringReader.ReadLine();
                        if (text2 != null)
                        {
                            text2 = text2.Replace("  ", " ");
                        }
                    }
                }
            }
            result.triangles = new int[num];
            result.vertices  = new Vector3[num2];
            result.uv        = new Vector2[num3];
            result.normals   = new Vector3[num4];
            result.faceData  = new Vector3[num5];
            return(result);
        }
        private static void populateMeshStruct(ref ObjImporter.meshStruct mesh)
        {
            StreamReader streamReader = File.OpenText(mesh.fileName);
            string       text         = streamReader.ReadToEnd();

            streamReader.Close();
            using (StringReader stringReader = new StringReader(text))
            {
                string text2 = stringReader.ReadLine();
                char[] array = new char[]
                {
                    ' '
                };
                char[] array2 = new char[]
                {
                    '/'
                };
                int num  = 0;
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                int num5 = 0;
                int num6 = 0;
                int num7 = 0;
                while (text2 != null)
                {
                    if (!text2.StartsWith("f ") && !text2.StartsWith("v ") && !text2.StartsWith("vt ") && !text2.StartsWith("vn ") && !text2.StartsWith("g ") && !text2.StartsWith("usemtl ") && !text2.StartsWith("mtllib ") && !text2.StartsWith("vt1 ") && !text2.StartsWith("vt2 ") && !text2.StartsWith("vc ") && !text2.StartsWith("usemap "))
                    {
                        text2 = stringReader.ReadLine();
                        if (text2 != null)
                        {
                            text2 = text2.Replace("  ", " ");
                        }
                    }
                    else
                    {
                        text2 = text2.Trim();
                        string[] array3 = text2.Split(array, 50);
                        string   text3  = array3[0];
                        string   text4  = text3;
                        if (text4 != null)
                        {
                            if (ObjImporter.< > f__switch$map2 == null)
                            {
                                Dictionary <string, int> dictionary = new Dictionary <string, int>(6);
                                dictionary.Add("v", 0);
                                dictionary.Add("vt", 1);
                                dictionary.Add("vt1", 2);
                                dictionary.Add("vt2", 3);
                                dictionary.Add("vn", 4);
                                dictionary.Add("f", 5);
                                ObjImporter.< > f__switch$map2 = dictionary;
                            }
                            int num8;
                            if (ObjImporter.< > f__switch$map2.TryGetValue(text4, ref num8))
                            {
                                switch (num8)
                                {
                                case 0:
                                    mesh.vertices[num3] = new Vector3(Convert.ToSingle(array3[1]), Convert.ToSingle(array3[2]), Convert.ToSingle(array3[3]));
                                    num3++;
                                    break;

                                case 1:
                                    mesh.uv[num5] = new Vector2(Convert.ToSingle(array3[1]), Convert.ToSingle(array3[2]));
                                    num5++;
                                    break;

                                case 2:
                                    mesh.uv[num6] = new Vector2(Convert.ToSingle(array3[1]), Convert.ToSingle(array3[2]));
                                    num6++;
                                    break;

                                case 3:
                                    mesh.uv[num7] = new Vector2(Convert.ToSingle(array3[1]), Convert.ToSingle(array3[2]));
                                    num7++;
                                    break;

                                case 4:
                                    mesh.normals[num4] = new Vector3(Convert.ToSingle(array3[1]), Convert.ToSingle(array3[2]), Convert.ToSingle(array3[3]));
                                    num4++;
                                    break;

                                case 5:
                                {
                                    int        num9 = 1;
                                    List <int> list = new List <int>();
                                    while (num9 < array3.Length && (string.Empty + array3[num9]).get_Length() > 0)
                                    {
                                        Vector3  vector = default(Vector3);
                                        string[] array4 = array3[num9].Split(array2, 3);
                                        vector.x = (float)Convert.ToInt32(array4[0]);
                                        if (array4.Length > 1)
                                        {
                                            if (array4[1] != string.Empty)
                                            {
                                                vector.y = (float)Convert.ToInt32(array4[1]);
                                            }
                                            vector.z = (float)Convert.ToInt32(array4[2]);
                                        }
                                        num9++;
                                        mesh.faceData[num2] = vector;
                                        list.Add(num2);
                                        num2++;
                                    }
                                    num9 = 1;
                                    while (num9 + 2 < array3.Length)
                                    {
                                        mesh.triangles[num] = list.get_Item(0);
                                        num++;
                                        mesh.triangles[num] = list.get_Item(num9);
                                        num++;
                                        mesh.triangles[num] = list.get_Item(num9 + 1);
                                        num++;
                                        num9++;
                                    }
                                    break;
                                }
                                }
                            }
                        }
                        text2 = stringReader.ReadLine();
                        if (text2 != null)
                        {
                            text2 = text2.Replace("  ", " ");
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private static ObjImporter.meshStruct createMeshStruct(string filename)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;
            int num5 = 0;

            ObjImporter.meshStruct result = default(ObjImporter.meshStruct);
            result.fileName = filename;
            StreamReader streamReader = File.OpenText(filename);
            string       s            = streamReader.ReadToEnd();

            streamReader.Dispose();
            using (StringReader stringReader = new StringReader(s))
            {
                string text      = stringReader.ReadLine();
                char[] separator = new char[]
                {
                    ' '
                };
                while (text != null)
                {
                    if (!text.StartsWith("f ") && !text.StartsWith("v ") && !text.StartsWith("vt ") && !text.StartsWith("vn "))
                    {
                        text = stringReader.ReadLine();
                        if (text != null)
                        {
                            text = text.Replace("  ", " ");
                        }
                    }
                    else
                    {
                        text = text.Trim();
                        string[] array = text.Split(separator, 50);
                        string   text2 = array[0];
                        if (text2 != null)
                        {
                            if (!(text2 == "v"))
                            {
                                if (!(text2 == "vt"))
                                {
                                    if (!(text2 == "vn"))
                                    {
                                        if (text2 == "f")
                                        {
                                            num5 = num5 + array.Length - 1;
                                            num += 3 * (array.Length - 2);
                                        }
                                    }
                                    else
                                    {
                                        num4++;
                                    }
                                }
                                else
                                {
                                    num3++;
                                }
                            }
                            else
                            {
                                num2++;
                            }
                        }
                        text = stringReader.ReadLine();
                        if (text != null)
                        {
                            text = text.Replace("  ", " ");
                        }
                    }
                }
            }
            result.triangles = new int[num];
            result.vertices  = new Vector3[num2];
            result.uv        = new Vector2[num3];
            result.normals   = new Vector3[num4];
            result.faceData  = new Vector3[num5];
            return(result);
        }
Ejemplo n.º 5
0
        private static void populateMeshStruct(ref ObjImporter.meshStruct mesh)
        {
            StreamReader streamReader = File.OpenText(mesh.fileName);
            string       s            = streamReader.ReadToEnd();

            streamReader.Close();
            using (StringReader stringReader = new StringReader(s))
            {
                string text      = stringReader.ReadLine();
                char[] separator = new char[]
                {
                    ' '
                };
                char[] separator2 = new char[]
                {
                    '/'
                };
                int num  = 0;
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                int num5 = 0;
                int num6 = 0;
                int num7 = 0;
                while (text != null)
                {
                    if (!text.StartsWith("f ") && !text.StartsWith("v ") && !text.StartsWith("vt ") && !text.StartsWith("vn ") && !text.StartsWith("g ") && !text.StartsWith("usemtl ") && !text.StartsWith("mtllib ") && !text.StartsWith("vt1 ") && !text.StartsWith("vt2 ") && !text.StartsWith("vc ") && !text.StartsWith("usemap "))
                    {
                        text = stringReader.ReadLine();
                        if (text != null)
                        {
                            text = text.Replace("  ", " ");
                        }
                    }
                    else
                    {
                        text = text.Trim();
                        string[] array = text.Split(separator, 50);
                        string   text2 = array[0];
                        switch (text2)
                        {
                        case "v":
                            mesh.vertices[num3] = new Vector3(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]), Convert.ToSingle(array[3]));
                            num3++;
                            break;

                        case "vt":
                            mesh.uv[num5] = new Vector2(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]));
                            num5++;
                            break;

                        case "vt1":
                            mesh.uv[num6] = new Vector2(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]));
                            num6++;
                            break;

                        case "vt2":
                            mesh.uv[num7] = new Vector2(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]));
                            num7++;
                            break;

                        case "vn":
                            mesh.normals[num4] = new Vector3(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]), Convert.ToSingle(array[3]));
                            num4++;
                            break;

                        case "f":
                        {
                            int        num9 = 1;
                            List <int> list = new List <int>();
                            while (num9 < array.Length && (string.Empty + array[num9]).Length > 0)
                            {
                                Vector3  vector = default(Vector3);
                                string[] array2 = array[num9].Split(separator2, 3);
                                vector.x = (float)Convert.ToInt32(array2[0]);
                                if (array2.Length > 1)
                                {
                                    if (array2[1] != string.Empty)
                                    {
                                        vector.y = (float)Convert.ToInt32(array2[1]);
                                    }
                                    vector.z = (float)Convert.ToInt32(array2[2]);
                                }
                                num9++;
                                mesh.faceData[num2] = vector;
                                list.Add(num2);
                                num2++;
                            }
                            num9 = 1;
                            while (num9 + 2 < array.Length)
                            {
                                mesh.triangles[num] = list[0];
                                num++;
                                mesh.triangles[num] = list[num9];
                                num++;
                                mesh.triangles[num] = list[num9 + 1];
                                num++;
                                num9++;
                            }
                            break;
                        }
                        }
                        text = stringReader.ReadLine();
                        if (text != null)
                        {
                            text = text.Replace("  ", " ");
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static void populateMeshStruct(ref ObjImporter.meshStruct mesh)
        {
            StreamReader streamReader = File.OpenText(mesh.fileName);
            string       s            = streamReader.ReadToEnd();

            streamReader.Close();
            using (StringReader stringReader = new StringReader(s))
            {
                string text      = stringReader.ReadLine();
                char[] separator = new char[]
                {
                    ' '
                };
                char[] separator2 = new char[]
                {
                    '/'
                };
                int num  = 0;
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                int num5 = 0;
                int num6 = 0;
                int num7 = 0;
                while (text != null)
                {
                    if (!text.StartsWith("f ") && !text.StartsWith("v ") && !text.StartsWith("vt ") && !text.StartsWith("vn ") && !text.StartsWith("g ") && !text.StartsWith("usemtl ") && !text.StartsWith("mtllib ") && !text.StartsWith("vt1 ") && !text.StartsWith("vt2 ") && !text.StartsWith("vc ") && !text.StartsWith("usemap "))
                    {
                        text = stringReader.ReadLine();
                        if (text != null)
                        {
                            text = text.Replace("  ", " ");
                        }
                    }
                    else
                    {
                        text = text.Trim();
                        string[] array = text.Split(separator, 50);
                        string   text2 = array[0];
                        uint     num8  = < PrivateImplementationDetails >.ComputeStringHash(text2);
                        if (num8 <= 1179241374u)
                        {
                            if (num8 <= 1128908517u)
                            {
                                if (num8 != 990293175u)
                                {
                                    if (num8 == 1128908517u)
                                    {
                                        if (text2 == "vn")
                                        {
                                            mesh.normals[num4] = new Vector3(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]), Convert.ToSingle(array[3]));
                                            num4++;
                                        }
                                    }
                                }
                                else if (!(text2 == "mtllib"))
                                {
                                }
                            }
                            else if (num8 != 1146808303u)
                            {
                                if (num8 != 1163585922u)
                                {
                                    if (num8 == 1179241374u)
                                    {
                                        if (!(text2 == "vc"))
                                        {
                                        }
                                    }
                                }
                                else if (text2 == "vt1")
                                {
                                    mesh.uv[num6] = new Vector2(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]));
                                    num6++;
                                }
                            }
                            else if (text2 == "vt2")
                            {
                                mesh.uv[num7] = new Vector2(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]));
                                num7++;
                            }
                        }
                        else if (num8 <= 1498016135u)
                        {
                            if (num8 != 1297068826u)
                            {
                                if (num8 != 1328799683u)
                                {
                                    if (num8 == 1498016135u)
                                    {
                                        if (text2 == "vt")
                                        {
                                            mesh.uv[num5] = new Vector2(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]));
                                            num5++;
                                        }
                                    }
                                }
                                else if (!(text2 == "usemtl"))
                                {
                                }
                            }
                            else if (!(text2 == "usemap"))
                            {
                            }
                        }
                        else if (num8 != 3792446982u)
                        {
                            if (num8 != 3809224601u)
                            {
                                if (num8 == 4077666505u)
                                {
                                    if (text2 == "v")
                                    {
                                        mesh.vertices[num3] = new Vector3(Convert.ToSingle(array[1]), Convert.ToSingle(array[2]), Convert.ToSingle(array[3]));
                                        num3++;
                                    }
                                }
                            }
                            else if (text2 == "f")
                            {
                                int        num9 = 1;
                                List <int> list = new List <int>();
                                while (num9 < array.Length && (array[num9] ?? "").Length > 0)
                                {
                                    Vector3  vector = default(Vector3);
                                    string[] array2 = array[num9].Split(separator2, 3);
                                    vector.x = (float)Convert.ToInt32(array2[0]);
                                    if (array2.Length > 1)
                                    {
                                        if (array2[1] != "")
                                        {
                                            vector.y = (float)Convert.ToInt32(array2[1]);
                                        }
                                        vector.z = (float)Convert.ToInt32(array2[2]);
                                    }
                                    num9++;
                                    mesh.faceData[num2] = vector;
                                    list.Add(num2);
                                    num2++;
                                }
                                num9 = 1;
                                while (num9 + 2 < array.Length)
                                {
                                    mesh.triangles[num] = list[0];
                                    num++;
                                    mesh.triangles[num] = list[num9];
                                    num++;
                                    mesh.triangles[num] = list[num9 + 1];
                                    num++;
                                    num9++;
                                }
                            }
                        }
                        else if (!(text2 == "g"))
                        {
                        }
                        text = stringReader.ReadLine();
                        if (text != null)
                        {
                            text = text.Replace("  ", " ");
                        }
                    }
                }
            }
        }