Beispiel #1
0
        public void BulkReadTest()
        {
            var files = Directory.EnumerateFiles(@"E:\MDX", "*.mdx", SearchOption.AllDirectories);

            foreach (var file in files)
            //Parallel.ForEach(files, file =>
            {
                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>();
                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>();
                BPOS  bindpositions           = mdx.Get <BPOS>();
                FAFX  faceFXes                = mdx.Get <FAFX>();
                CORN  particleEmitterPopcorns = mdx.Get <CORN>();
            }
            //);
        }
Beispiel #2
0
        public void BONReader(string file, string ext)
        {
            Data = new BONE {
                Header = new PDHead()
            };
            IO = File.OpenReader(file + ext);

            IO.Format             = Main.Format.F;
            Data.Header.Signature = IO.ReadInt32();
            if (Data.Header.Signature == 0x454E4F42)
            {
                Data.Header = IO.ReadHeader(true);
                Data.POF    = Data.Header.AddPOF();
            }
            if (Data.Header.Signature != 0x09102720)
            {
                return;
            }

            Data.Skeleton            = new SkeletonEntry[IO.ReadInt32Endian()];
            Data.SkeletonsOffset     = IO.ReadUInt32Endian(ref Data.POF);
            Data.SkeletonNamesOffset = IO.ReadUInt32Endian();
            if (Data.SkeletonNamesOffset == 0)
            {
                IO.IsX              = true;
                IO.Format           = Main.Format.X;
                Data.POF.POFOffsets = new List <long>();
                IO.Seek(Data.Header.Lenght, 0);
                IO.LongOffset            = Data.Header.Lenght;
                Data.Header.Signature    = IO.ReadInt32();
                Data.Skeleton            = new SkeletonEntry[IO.ReadInt32Endian()];
                Data.SkeletonsOffset     = IO.ReadInt64();
                Data.SkeletonNamesOffset = IO.ReadInt64(ref Data.POF);
            }
            else
            {
                IO.LongPosition -= 4;
                IO.GetOffset(ref Data.POF);
                IO.LongPosition += 4;
            }

            Data.SkeletonEntryOffset = new long[Data.Skeleton.Length];
            IO.LongPosition          = Data.SkeletonsOffset;
            for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
            {
                Data.SkeletonEntryOffset[i0] = IO.ReadIntX(ref Data.POF);
            }

            for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
            {
                Data.Skeleton[i0] = new SkeletonEntry();
                IO.LongPosition   = Data.SkeletonEntryOffset[i0];

                Data.Skeleton[i0].BoneOffset         = IO.ReadIntX(ref Data.POF);
                Data.Skeleton[i0].Position           = new Vector3 <float> [IO.ReadIntX()];
                Data.Skeleton[i0].PositionOffset     = IO.ReadIntX(ref Data.POF);
                Data.Skeleton[i0].Field02Offset      = IO.ReadIntX(ref Data.POF);
                Data.Skeleton[i0].BoneName1          = new         string[IO.ReadIntX()];
                Data.Skeleton[i0].BoneName1Offset    = IO.ReadIntX(ref Data.POF);
                Data.Skeleton[i0].BoneName2          = new         string[IO.ReadIntX()];
                Data.Skeleton[i0].BoneName2Offset    = IO.ReadIntX(ref Data.POF);
                Data.Skeleton[i0].ParentIndiceOffset = IO.ReadIntX(ref Data.POF);

                IO.LongPosition = Data.SkeletonNamesOffset + i0 << (IO.IsX ? 3 : 2);

                Data.Skeleton[i0].Name = IO.ReadStringAtOffset(ref Data.POF);
                IO.LongPosition        = Data.Skeleton[i0].BoneOffset;

                long   Count = 0;
                string Name  = "";
                while (true)
                {
                    IO.ReadUInt64();
                    Name = IO.ReadStringAtOffset(ref Data.POF);
                    if (Name == "End")
                    {
                        break;
                    }
                    Count++;
                }

                Data.Skeleton[i0].Bone = new BoneEntry[Count];
                for (i = 0; i < Count; i++)
                {
                    Data.Skeleton[i0].Bone[i].Type            = (BoneType)IO.ReadByte();
                    Data.Skeleton[i0].Bone[i].HasParent       = IO.ReadBoolean();
                    Data.Skeleton[i0].Bone[i].ParentNameIndex = IO.ReadByte();
                    Data.Skeleton[i0].Bone[i].Field01         = IO.ReadByte();
                    Data.Skeleton[i0].Bone[i].PairNameIndex   = IO.ReadByte();
                    Data.Skeleton[i0].Bone[i].Field02         = IO.ReadByte();
                    IO.ReadInt16Endian();
                    Data.Skeleton[i0].Bone[i].Name = IO.ReadStringAtOffset(ref Data.POF);
                }

                IO.LongPosition = Data.Skeleton[i0].PositionOffset;
                for (i = 0; i < Data.Skeleton[i0].Position.Length; i++)
                {
                    Data.Skeleton[i0].Position[i] = new Vector3 <float>(IO.ReadSingleEndian(),
                                                                        IO.ReadSingleEndian(), IO.ReadSingleEndian());
                }

                IO.LongPosition           = Data.Skeleton[i0].Field02Offset;
                Data.Skeleton[i0].Field02 = IO.ReadIntX();

                IO.LongPosition = Data.Skeleton[i0].BoneName1Offset;
                for (i = 0; i < Data.Skeleton[i0].BoneName1.Length; i++)
                {
                    Data.Skeleton[i0].BoneName1[i] = IO.ReadStringAtOffset(ref Data.POF);
                }

                IO.LongPosition = Data.Skeleton[i0].BoneName2Offset;
                for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
                {
                    Data.Skeleton[i0].BoneName2[i] = IO.ReadStringAtOffset(ref Data.POF);
                }

                IO.LongPosition = Data.Skeleton[i0].ParentIndiceOffset;
                for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
                {
                    Data.Skeleton[i0].ParentIndice[i] = IO.ReadInt16Endian();
                }
            }
            if (IO.Format > Main.Format.F)
            {
                IO.LongPosition = Data.POF.Offset;
                IO.ReadPOF(ref Data.POF);
            }
            IO.Close();
        }
Beispiel #3
0
 public BoneData()
 {
     Data = new BONE();
 }
        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);
        }