public static bool ReadFile(string FileName) { pMesh = new tMeshContainer(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(File.ReadAllBytes(FileName)))) { pMesh.HeaderInfo = new tHeaderInfo { Format = binaryReader.ReadBytes(4), //WriteID_t(CChunkID(MESH_ID)) //MESH_ID - "MESH" Version = binaryReader.ReadInt32(), //(INDEX)MESH_NEW_VER MeshDataSize = binaryReader.ReadInt32(), //slInvalidSize MeshCount = binaryReader.ReadUInt32(), //EncodeSimpleMesh(ctmlod, checker) VertexCount = binaryReader.ReadUInt32(), //mlod_aVertexWeights JointCount = binaryReader.ReadUInt32(), //mlod_aWeightMaps TextureMaps = binaryReader.ReadUInt32(), //mlod_aUVMaps NormalCount = binaryReader.ReadUInt32(), //mlod_aVertices ObjCount = binaryReader.ReadUInt32(), //mlod_aSurfaces UnknownCount = binaryReader.ReadUInt32() //mlod_aMorphMaps }; pMesh.FileName = binaryReader.ReadBytes(binaryReader.ReadInt32()); //mlod_fnSourceFile pMesh.Scale = binaryReader.ReadSingle(); //mlod_fMaxDistance pMesh.Value1 = binaryReader.ReadUInt32(); //mlod.mlod_ulFlags pMesh.FilePath = FileName; if (pMesh.HeaderInfo.Version != (int)MESH_VERSION.MESH_OLD_VERSION && pMesh.HeaderInfo.Version != (int)MESH_VERSION.MESH_NEW_VERSION) { return(false); } // call to read mesh function and return true if succeed { if (pMesh.HeaderInfo.Version == (int)MESH_VERSION.MESH_OLD_VERSION && ReadMesh(binaryReader, false)) { return(true); } else if (pMesh.HeaderInfo.Version == (int)MESH_VERSION.MESH_NEW_VERSION && ReadMesh(binaryReader, true)) { return(true); } } } return(false); }
private void MakeLCModels(string SMCFile) { System.Collections.Generic.List <float> source1 = new System.Collections.Generic.List <float>(); System.Collections.Generic.List <float> source2 = new System.Collections.Generic.List <float>(); System.Collections.Generic.List <float> source3 = new System.Collections.Generic.List <float>(); System.Collections.Generic.List <float> floatList1 = new System.Collections.Generic.List <float>(); System.Collections.Generic.List <float> floatList2 = new System.Collections.Generic.List <float>(); System.Collections.Generic.List <float> floatList3 = new System.Collections.Generic.List <float>(); _Models = new System.Collections.Generic.List <tMesh>(); try { System.Collections.Generic.List <smcMesh> source4 = SMCReader.ReadFile(SMCFile); for (int index1 = 0; index1 < source4.Count(); ++index1) { if (LCMeshReader.ReadFile(source4[index1].FileName)) { tMeshContainer pMesh = LCMeshReader.pMesh; source1.Add((pMesh.Vertices).Max((p => p.X))); source2.Add((pMesh.Vertices).Max((p => p.Y))); source3.Add((pMesh.Vertices).Max((p => p.Z))); floatList1.Add((pMesh.Vertices).Min((p => p.X))); floatList2.Add((pMesh.Vertices).Min((p => p.Y))); floatList3.Add((pMesh.Vertices).Min(p => p.Z)); for (int index2 = 0; index2 < (pMesh.Objects).Count(); ++index2) { int toVert = (int)pMesh.Objects[index2].ToVert; int faceCount = (int)pMesh.Objects[index2].FaceCount; short[] faces = pMesh.Objects[index2].GetFaces(); CustomVertex.PositionNormalTextured[] data = new CustomVertex.PositionNormalTextured[toVert]; int fromVert = (int)pMesh.Objects[index2].FromVert; for (int index3 = 0; index3 < pMesh.Objects[index2].ToVert; ++index3) { data[index3].Position = new Vector3(pMesh.Vertices[fromVert].X, pMesh.Vertices[fromVert].Y, pMesh.Vertices[fromVert].Z); data[index3].Normal = new Vector3(pMesh.Normals[fromVert].X, pMesh.Normals[fromVert].Y, pMesh.Normals[fromVert].Z); try { data[index3].Texture = new Vector2(pMesh.UVMaps[0].Coords[fromVert].U, pMesh.UVMaps[0].Coords[fromVert].V); } catch { data[index3].Texture = new Vector2(0.0f, 0.0f); } ++fromVert; } VertexBuffer vertexBuffer = new VertexBuffer(_Device, (data).Count() * 32, Usage.None, VertexFormat.PositionNormal | VertexFormat.Texture1, Pool.Default); Mesh mesh = new Mesh(_Device, (faces).Count() / 3, (data).Count(), MeshFlags.Managed, VertexFormat.PositionNormal | VertexFormat.Texture1); DataStream dataStream1; using (dataStream1 = mesh.VertexBuffer.Lock(0, (data).Count() * 32, LockFlags.None)) { dataStream1.WriteRange(data); mesh.VertexBuffer.Unlock(); } DataStream dataStream2; using (dataStream2 = mesh.IndexBuffer.Lock(0, (faces).Count() * 2, LockFlags.None)) { dataStream2.WriteRange(faces); mesh.IndexBuffer.Unlock(); } if ((uint)(pMesh.Weights).Count() > 0U) { string[] strArray = new string[(pMesh.Weights).Count()]; System.Collections.Generic.List <int>[] intListArray = new System.Collections.Generic.List <int> [(pMesh.Weights).Count()]; System.Collections.Generic.List <float>[] floatListArray = new System.Collections.Generic.List <float> [(pMesh.Weights).Count()]; for (int index3 = 0; index3 < (pMesh.Weights).Count(); ++index3) { strArray[index3] = _Enc.GetString(pMesh.Weights[index3].JointName); intListArray[index3] = new System.Collections.Generic.List <int>(); floatListArray[index3] = new System.Collections.Generic.List <float>(); for (int index4 = 0; index4 < (pMesh.Weights[index3].WeightsMap).Count(); ++index4) { intListArray[index3].Add(pMesh.Weights[index3].WeightsMap[index4].Index); floatListArray[index3].Add(pMesh.Weights[index3].WeightsMap[index4].Weight); } } mesh.SkinInfo = new SkinInfo((data).Count(), VertexFormat.PositionNormal | VertexFormat.Texture1, (int)pMesh.HeaderInfo.JointCount); for (int bone = 0; bone < (intListArray).Count(); ++bone) { mesh.SkinInfo.SetBoneName(bone, strArray[bone]); mesh.SkinInfo.SetBoneInfluence(bone, intListArray[bone].ToArray(), floatListArray[bone].ToArray()); } } mesh.GenerateAdjacency(0.5f); mesh.ComputeNormals(); Texture texture = null; string objName = _Enc.GetString(pMesh.Objects[index2].Textures[0].InternalName); int index5 = source4[index1].Object.FindIndex(x => x.Name.Equals(objName)); if (index5 != -1) { texture = GetTextureFromFile(source4[index1].Object[index5].Texture); } _Models.Add(new tMesh(mesh, texture)); } } } } catch { } try { _Zoom = (new float[3] { source1.Max(), source2.Max(), source3.Max() }).Max() * 3f; } catch { } slideZoom.Value = (int)_Zoom * 100; }
private void MakeLCModels(string SMCFile) { int num = -1; int ID = this.GetIDFromList(); int num2 = ItemList.FindIndex((ItemContainer p) => p.ItemID.Equals(ID)); if (num2 != -1) { int arg_42_0 = ItemList[num2].JobFlag; num = ItemList[num2].Position; } try { List <smcMesh> list = SMCReader.ReadFile(SMCFile); for (int i = 0; i < list.Count <smcMesh>(); i++) { bool flag = (num != 0 || !list[i].FileName.Contains("_hair_000")) && (num != 1 || !list[i].FileName.Contains("_bu_000")) && (num != 3 || !list[i].FileName.Contains("_bd_000")) && (num != 5 || !list[i].FileName.Contains("_hn_000")) && (num != 6 || !list[i].FileName.Contains("_ft_000")); if (flag && LCMeshReader.ReadFile(list[i].FileName)) { tMeshContainer pMesh = LCMeshReader.pMesh; for (int j = 0; j < pMesh.Objects.Count <tMeshObject>(); j++) { int toVert = (int)pMesh.Objects[j].ToVert; uint arg_16B_0 = pMesh.Objects[j].FaceCount; short[] faces = pMesh.Objects[j].GetFaces(); CustomVertex.PositionNormalTextured[] array = new CustomVertex.PositionNormalTextured[toVert]; int num3 = (int)pMesh.Objects[j].FromVert; int k = 0; while ((long)k < (long)((ulong)pMesh.Objects[j].ToVert)) { array[k].Position = new Vector3(pMesh.Vertices[num3].X, pMesh.Vertices[num3].Y, pMesh.Vertices[num3].Z); array[k].Normal = new Vector3(pMesh.Normals[num3].X, pMesh.Normals[num3].Y, pMesh.Normals[num3].Z); try { array[k].Texture = new Vector2(pMesh.UVMaps[0].Coords[num3].U, pMesh.UVMaps[0].Coords[num3].V); } catch { array[k].Texture = new Vector2(0f, 0f); } num3++; k++; } new VertexBuffer(this.device, array.Count <CustomVertex.PositionNormalTextured>() * 32, Usage.None, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Normal, Pool.Default); Mesh mesh = new Mesh(this.device, faces.Count <short>() / 3, array.Count <CustomVertex.PositionNormalTextured>(), MeshFlags.Managed, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Normal); DataStream dataStream2; DataStream dataStream = dataStream2 = mesh.VertexBuffer.Lock(0, array.Count <CustomVertex.PositionNormalTextured>() * 32, LockFlags.None); try { dataStream.WriteRange <CustomVertex.PositionNormalTextured>(array); mesh.VertexBuffer.Unlock(); } finally { if (dataStream2 != null) { ((IDisposable)dataStream2).Dispose(); } } DataStream dataStream3; dataStream = (dataStream3 = mesh.IndexBuffer.Lock(0, faces.Count <short>() * 2, LockFlags.None)); try { dataStream.WriteRange <short>(faces); mesh.IndexBuffer.Unlock(); } finally { if (dataStream3 != null) { ((IDisposable)dataStream3).Dispose(); } } if (pMesh.Weights.Count <tMeshJointWeights>() != 0) { string[] array2 = new string[pMesh.Weights.Count <tMeshJointWeights>()]; List <int>[] array3 = new List <int> [pMesh.Weights.Count <tMeshJointWeights>()]; List <float>[] array4 = new List <float> [pMesh.Weights.Count <tMeshJointWeights>()]; for (int l = 0; l < pMesh.Weights.Count <tMeshJointWeights>(); l++) { array2[l] = this.Enc.GetString(pMesh.Weights[l].JointName); array3[l] = new List <int>(); array4[l] = new List <float>(); for (int m = 0; m < pMesh.Weights[l].WeightsMap.Count <tMeshWeightsMap>(); m++) { array3[l].Add(pMesh.Weights[l].WeightsMap[m].Index); array4[l].Add(pMesh.Weights[l].WeightsMap[m].Weight); } } mesh.SkinInfo = new SkinInfo(array.Count <CustomVertex.PositionNormalTextured>(), VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Normal, (int)pMesh.HeaderInfo.JointCount); for (k = 0; k < array3.Count <List <int> >(); k++) { mesh.SkinInfo.SetBoneName(k, array2[k]); mesh.SkinInfo.SetBoneInfluence(k, array3[k].ToArray(), array4[k].ToArray()); } } mesh.GenerateAdjacency(0.5f); mesh.ComputeNormals(); Texture texture = null; string objName = this.Enc.GetString(pMesh.Objects[j].Textures[0].InternalName); int num4 = list[i].Object.FindIndex((smcObject x) => x.Name.Equals(objName)); if (num4 != -1) { texture = this.GetTextureFromFile(list[i].Object[num4].Texture); } this.models.Add(new tMesh(mesh, texture)); } } } } catch { } this.zoom = 4f; }