public void ImportObj( string inFile, ref List <TriangleGL> triangleGLs, ref List <TriangleGL> triangleGLAlphas, ref List <TextureData> TextureDataList, ref List <TextureData> TextureDataAlphaList, ref List <TextureSetting> TextureSettings, ref List <TextureSetting> TextureSettingsAlpha, ref float scale) { try { this.originalScale = scale; this.vertScale = scale; this.dir = Path.GetDirectoryName(inFile); this.dir += "\\"; StreamReader streamReader = new StreamReader((Stream)File.Open(inFile, FileMode.Open)); string end = streamReader.ReadToEnd(); streamReader.Close(); this.StripLeadingSpaceAndDoubleSpaces(ref end); this.RipMTL(ref end); this.RipOBJMesh(ref end); this.RipFaces(ref end); this.RipTextureCI(ref TextureDataList, ref TextureDataAlphaList, ref TextureSettings, ref TextureSettingsAlpha); if (TextureDataList.Count == 0) { TextureDataList.Add(new TextureData()); } this.RecenterUVs(); this.SplitAlpha(ref TextureSettingsAlpha); this.CopyVerts(); this.CalcPrecision(1); scale = this.vertScale; for (int index1 = 0; index1 < this.faceVs.Count; ++index1) { VertGL[] verts_ = new VertGL[3]; int num1 = 0; int num2 = 0; int textureSetting_ = -1; for (int index2 = 0; index2 < TextureSettings.Count && textureSetting_ == -1; ++index2) { if (this.faceTextureMap[index1] == TextureSettings[index2].name) { textureSetting_ = index2; num1 = TextureSettings[index2].width; num2 = TextureSettings[index2].height; } } for (int index2 = 0; index2 < 3; ++index2) { double[] numArray1 = new double[2] { this.vertTs[this.faceVTs[index1][index2]][0], this.vertTs[this.faceVTs[index1][index2]][1] }; short u_ = (short)(numArray1[0] * (double)num1 * 256.0 / 4.0); numArray1[1] = numArray1[1] >= 1.0 || numArray1[1] <= 0.0 ? numArray1[1] * -1.0 + 1.0 : 1.0 - numArray1[1] % 1.0; short v_ = (short)(numArray1[1] * (double)num2 * 256.0 / 4.0); byte[] numArray2 = new byte[4] { byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue }; if (this.faceCs[index1][index2] != -1) { numArray2[0] = this.vertColours[this.faceCs[index1][index2]].red; numArray2[1] = this.vertColours[this.faceCs[index1][index2]].green; numArray2[2] = this.vertColours[this.faceCs[index1][index2]].blue; numArray2[3] = this.vertColours[this.faceCs[index1][index2]].alpha; } VertGL vertGl = new VertGL(Convert.ToInt16(this.verts[this.faceVs[index1][index2]][0]), Convert.ToInt16(this.verts[this.faceVs[index1][index2]][1]), Convert.ToInt16(this.verts[this.faceVs[index1][index2]][2]), numArray2[0], numArray2[1], numArray2[2], numArray2[3], u_, v_); verts_[index2] = vertGl; } triangleGLs.Add(new TriangleGL(verts_, textureSetting_)); } for (int index = 0; index < triangleGLs.Count; ++index) { int textureSetting = triangleGLs[index].textureSetting; } for (int index1 = 0; index1 < this.alphaFaceVs.Count; ++index1) { VertGL[] verts_ = new VertGL[3]; int num1 = 0; int num2 = 0; int textureSetting_ = -1; for (int index2 = 0; index2 < TextureSettingsAlpha.Count && textureSetting_ == -1; ++index2) { if (this.alphafaceTextureMap[index1] == TextureSettingsAlpha[index2].name) { textureSetting_ = index2; num1 = TextureSettingsAlpha[index2].width; num2 = TextureSettingsAlpha[index2].height; } } for (int index2 = 0; index2 < 3; ++index2) { double[] alphaVertT = this.alphaVertTs[this.alphaFaceVTs[index1][index2]]; short u_ = (short)(alphaVertT[0] * (double)num1 * 256.0 / 4.0); alphaVertT[1] = alphaVertT[1] >= 1.0 || alphaVertT[1] <= 0.0 ? alphaVertT[1] * -1.0 + 1.0 : 1.0 - alphaVertT[1] % 1.0; short v_ = (short)(alphaVertT[1] * (double)num2 * 256.0 / 4.0); byte[] numArray = new byte[4] { byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue }; if (this.alphaFaceCs[index1][index2] != -1) { numArray[0] = this.alphaVertColours[this.alphaFaceCs[index1][index2]].red; numArray[1] = this.alphaVertColours[this.alphaFaceCs[index1][index2]].green; numArray[2] = this.alphaVertColours[this.alphaFaceCs[index1][index2]].blue; numArray[3] = this.alphaVertColours[this.alphaFaceCs[index1][index2]].alpha; } VertGL vertGl = new VertGL(Convert.ToInt16(this.alphaVerts[this.alphaFaceVs[index1][index2]][0]), Convert.ToInt16(this.alphaVerts[this.alphaFaceVs[index1][index2]][1]), Convert.ToInt16(this.alphaVerts[this.alphaFaceVs[index1][index2]][2]), numArray[0], numArray[1], numArray[2], numArray[3], u_, v_); verts_[index2] = vertGl; } triangleGLAlphas.Add(new TriangleGL(verts_, textureSetting_)); } for (int index1 = 0; index1 < triangleGLs.Count <TriangleGL>(); ++index1) { bool flag1 = false; for (int index2 = 0; index2 < 3 && !flag1; ++index2) { if (triangleGLs[index1].verts[index2].a != byte.MaxValue) { flag1 = true; } } if (flag1) { if (triangleGLs[index1].textureSetting != -1) { TextureSetting t = TextureSetting.clone(TextureSettings[triangleGLs[index1].textureSetting]); bool flag2 = true; if (TextureSettings[triangleGLs[index1].textureSetting].textureData != -1) { for (int index2 = 0; index2 < TextureDataAlphaList.Count & flag2; ++index2) { if (((IEnumerable <byte>)TextureDataList[TextureSettings[triangleGLs[index1].textureSetting].textureData].n64).SequenceEqual <byte>((IEnumerable <byte>)TextureDataAlphaList[index2].n64)) { t.textureData = index2; flag2 = false; } } if (flag2) { TextureDataAlphaList.Add(TextureDataList[TextureSettings[triangleGLs[index1].textureSetting].textureData]); t.textureData = TextureDataAlphaList.Count - 1; TextureSettingsAlpha.Add(t); triangleGLs[index1].textureSetting = TextureSettingsAlpha.Count - 1; } } if (!flag2 || TextureSettings[triangleGLs[index1].textureSetting].textureData == -1) { bool flag3 = true; for (int index2 = 0; index2 < TextureSettingsAlpha.Count & flag3; ++index2) { if (TextureSettingsAlpha[index2].equal(t)) { triangleGLs[index1].textureSetting = index2; flag3 = false; } } if (flag3) { TextureSettingsAlpha.Add(t); triangleGLs[index1].textureSetting = TextureSettingsAlpha.Count - 1; } } } triangleGLAlphas.Insert(0, triangleGLs[index1]); triangleGLs.RemoveAt(index1); --index1; } } } catch (Exception ex) { int num = (int)MessageBox.Show("Unable to convert OBJ file, visit banjosbackpack.com for more help"); } }