void Delayed() { //wmoHandler.AddToQueue(@"world\wmo\zuldazar\troll\8tr_zandalari_pyramid.wmo", -1, Vector3.zero, Quaternion.identity, Vector3.one); //wmoHandler.AddToQueue(@"world\wmo\azeroth\buildings\duskwood_barn\duskwood_barn.wmo", -1, Vector3.zero, Quaternion.identity, Vector3.one); //wmoHandler.AddToQueue(@"world\wmo\azeroth\buildings\stormwind\stormwind2_016.wmo", -1, Vector3.zero, Quaternion.identity, Vector3.one); try { //M2.Load(@"character\draenei\female\draeneifemale.m2", -1, Vector3.zero, Quaternion.identity, Vector3.one); //M2.Load(@"world\expansion05\doodads\ashran\6as_rock_c01.m2", -1, new Vector3 (.5f,0,0), Quaternion.identity, new Vector3(.1f,.1f,.1f)); //M2.Load(@"creature\anduin\anduin.m2", -1, Vector3.zero, Quaternion.identity, Vector3.one); M2.Load(@"creature\\ammunae\\ammunae.m2", -1, Vector3.zero, Quaternion.identity, Vector3.one); } catch (Exception ex) { Debug.Log(ex.Message); } }
static void Main(string[] args) { { var model = new M2(); model.Load(File.OpenRead(@"E:\m2work\legion\Character\Tauren\Male\TaurenMale_HD.M2")); return; } return; { var stream = new MemoryStream(); var e = new E(); e.F = 1; e.G = 2; var e2 = new E(); e2.F = 3; e2.G = 4; var b = new B(); b.C = 5; b.D = 6; b.E.Elements.Add(e); var b2 = new B(); b2.C = 7; b2.D = 8; b2.E.Elements.Add(e2); var t = new TestStruct(); t.A = 9; t.B.Elements.Add(b); t.B.Elements.Add(b2); var writer = new MyBinaryWriter(stream); t.Write(writer); stream.Seek(0, SeekOrigin.Begin); var reader = new BinaryReader(stream); var t2 = new TestStruct(); t2.Read(reader); return; } { var model = new M2(); model.Load(File.OpenRead(@"E:\m2work\new\PandarenYetiMount\PandarenYetiMount.m2")); } }
public static void Compare() { M2 comparison = new M2(); using (var reader = new BinaryReader(new FileStream(@"Files\Boar.m2", FileMode.Open))) comparison.Load(reader); var mdxnsfsdfew = new Model(Path.Combine(DESKTOP, "models2", "Boar.mdx")); File.WriteAllText($"2SidedPickAxe.mdx.json", Newtonsoft.Json.JsonConvert.SerializeObject(mdxnsfsdfew.Chunks, Newtonsoft.Json.Formatting.Indented)); foreach (var file in known) { var mdxold = new Model(@"C:\Users\TomSpearman\Desktop\models\" + file); var mdxnew = new Model(@"C:\Users\TomSpearman\Desktop\models2\" + file); var format = Newtonsoft.Json.Formatting.Indented; File.WriteAllText($"{file}_old.json", Newtonsoft.Json.JsonConvert.SerializeObject(mdxold.Chunks, format)); File.WriteAllText($"{file}_new.json", Newtonsoft.Json.JsonConvert.SerializeObject(mdxnew.Chunks, format)); } }
public void ParseM2Block() { M2.Load(currentM2datapath, currentM2uniqueID, currentM2position, currentM2rotation, currentM2scale); }
public (Mesh, Texture2D[]) M2ToMesh(CASCFile file) { Mesh m2Mesh = new Mesh(); BinaryReader br = new BinaryReader(new MemoryStream(CascFileBytes(file))); // New BinaryReader for the file in MemoryStream br.BaseStream.Seek(0, SeekOrigin.Begin); // Go the the beginning of the stream // Manually Parsing the File /* * while (br.BaseStream.Position < br.BaseStream.Length) { // Advance the reader position until the end of the file * //string chunkID = System.Text.Encoding.UTF8.GetString(br.ReadBytes(4)); // Reading first 4 bytes of a chunk will give us the ID * //int chunkID = (int)br.ReadUInt32(); // Maybe better to use INT for performance, opting for string for readability * ChunkID chunkID = (ChunkID)br.ReadUInt32(); * long chunkSize = (long)br.ReadUInt32(); // Get the size in bytes of the current chunk * long nextChunkPos = br.BaseStream.Position + chunkSize; // The next chunk will be from the current reader's position + size of current chunk * * // Process current chunk * switch (chunkID) { * case ChunkID.MD21: // MD21 Header * ParseChunkMD21(); * break; * case ChunkID.SFID: // Skin File IDs * ParseChunkSFID(); * break; * case ChunkID.TXID: // Texture File IDs * ParseChunkTXID(); * break; * } * br.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); // Advance the reader position to the the next chunk and proceed with loop * Debug.Log("Processed ChunkID: " + chunkID); // Name of current chunk * }*/ var model = new M2(); model.Load(br); //Debug.Log(model.Name + " loaded"); //Debug.Log(model.Version); Debug.Log("nViews: " + model.nViews); Debug.Log("Texture Count: " + model.Textures.Count); Texture2D[] textures = new Texture2D[model.Textures.Count]; for (int i = 0; i < model.Textures.Count; i++) { Debug.Log("Texture File: " + model.Textures[i].Name + "FileDataID: " + model.Textures[i].FileDataID); Texture2D tex = BlpToTexture2d(GetCascFile(model.Textures[i].FileDataID)); textures[i] = tex; } if (model.Views.Count > 0) { for (int i = 0; i < model.Views.Count; i++) { //var substream = stream.BaseStream as Substream; //var path = substream != null ? ((FileStream)substream.GetInnerStream()).Name : ((FileStream)stream.BaseStream).Name; //using (var skinFile = new BinaryReader(new FileStream(M2SkinProfile.SkinFileName(path, i), FileMode.Open))) using (var skinFile = new BinaryReader(new MemoryStream(CascFileBytes(GetCascFile(model.Views[i].FileDataID))))) { model.Views[i].Load(skinFile, model.Version); model.Views[i].LoadContent(skinFile, model.Version); } Debug.Log("Skin File: " + model.Views[i].FileDataID); } } Vector3[] vertices = new Vector3[model.GlobalVertexList.Count]; Vector3[] normals = new Vector3[model.GlobalVertexList.Count]; Vector2[] uv1 = new Vector2[model.GlobalVertexList.Count]; Vector2[] uv2 = new Vector2[model.GlobalVertexList.Count]; int index = 0; foreach (M2Vertex v in model.GlobalVertexList) { vertices[index] = new Vector3(v.Position.y, v.Position.z, -v.Position.x); normals[index] = new Vector3(v.Normal.y, v.Normal.z, -v.Normal.x); uv1[index] = v.TexCoords[0]; uv2[index] = v.TexCoords[1]; index++; } int[] triangles = new int[model.Views[0].Triangles.Count]; for (int i = 0; i < model.Views[0].Triangles.Count; i++) { triangles[i] = (int)model.Views[0].Triangles[i]; } // Compltely Wrong /* * for (int i = 0; i < model.Views[0].Submeshes.Count; i++) { * M2SkinSection sub = model.Views[0].Submeshes[i]; * SubMeshDescriptor smd = new SubMeshDescriptor(); * smd.baseVertex = sub.StartVertex; * Bounds bounds = new Bounds(sub.CenterBoundingBox, new Vector3(sub.Radius, sub.Radius, sub.Radius)); // radius isn't correct * smd.bounds = bounds; * smd.firstVertex = 0; ///? * smd.indexCount = 3; * smd.indexStart = sub.StartVertex; * smd.topology = MeshTopology.Triangles; * smd.vertexCount = sub.NVertices; * m2Mesh.SetSubMesh(i, smd, MeshUpdateFlags.Default); * }*/ m2Mesh.vertices = vertices; m2Mesh.normals = normals; m2Mesh.triangles = triangles.Reverse().ToArray(); // Reverses the faces m2Mesh.uv = uv1; m2Mesh.uv2 = uv2; return(m2Mesh, textures); }
public void ParseM2Block() => M2.Load(currentM2FileDataId, currentM2uniqueID, currentM2position, currentM2rotation, currentM2scale, CascHandler);
static void Main(string[] args) { //Tests.BulkParse(); M2 comparison = new M2(); using (var reader = new BinaryReader(new FileStream(@"Files\Boar.m2", FileMode.Open))) comparison.Load(reader); string file = @"Files\Boar.mdx"; if (args.Length > 0 && File.Exists(args[0])) { file = args[0]; } Model mdx = new Model(file); VERS version = mdx.Get <VERS>(); MODL modl = mdx.Get <MODL>(); SEQS sequences = mdx.Get <SEQS>(); MTLS materials = mdx.Get <MTLS>(); TEXS textures = mdx.Get <TEXS>(); GEOS geosets = mdx.Get <GEOS>(); GEOA geosetanims = mdx.Get <GEOA>(); HELP helpers = mdx.Get <HELP>(); ATCH attachments = mdx.Get <ATCH>(); PIVT pivotpoints = mdx.Get <PIVT>(); CAMS cameras = mdx.Get <CAMS>(); EVTS events = mdx.Get <EVTS>(); HTST hittestshapes = mdx.Get <HTST>(); CLID collisions = mdx.Get <CLID>(); GLBS globalsequences = mdx.Get <GLBS>(); PRE2 particleemitter2s = mdx.Get <PRE2>(); RIBB ribbonemitters = mdx.Get <RIBB>(); LITE lights = mdx.Get <LITE>(); TXAN textureanimations = mdx.Get <TXAN>(); BONE bones = mdx.Get <BONE>(); M2Converter converter = new M2Converter(mdx, M2.Format.LichKing); var m2 = converter.Model; m2.Attachments = converter.GetAttachments(); m2.Bones = converter.GetBones(); m2.BoundingBox = converter.GetBoundingBox(); m2.BoundingSphereRadius = converter.GetBoundingSphereRadius(); m2.Cameras = converter.GetCameras(); m2.Colors = converter.GetColors(); m2.Events = converter.GetEvents(); m2.GlobalSequences = converter.GetGlobalSequences(); m2.GlobalVertexList = converter.GetVertices(); m2.Materials = converter.GetMaterials(); m2.Textures = converter.GetTextures(); m2.Sequences = converter.GetSequences(); m2.TexLookup = converter.GetTextureLookup(); m2.TexUnitLookup = converter.GetTexUnitLookup(); m2.TextureTransforms = converter.GetTextureTransform(); m2.Transparencies = converter.GetTextureWeights(); m2.UvAnimLookup.Add(-1); m2.GlobalVertexList.ForEach(x => x.TexCoords[0] = new C2Vector(x.TexCoords[0].X, x.TexCoords[0].Y * -1f)); m2.Views.Add(converter.GetSkin()); m2.BoneLookup = converter.GetBoneLookup(); converter.UpdateCollisions(); using (var fs = new FileStream(Path.ChangeExtension(file, "m2"), FileMode.Create)) using (var bw = new BinaryWriter(fs)) m2.Save(bw, M2.Format.LichKing); }