예제 #1
0
 public void Load(BinaryReader stream, M2.Format version)
 {
     Id = stream.ReadUInt32();
     Bone = stream.ReadUInt32();
     Position = stream.ReadC3Vector();
     AnimateAttached.Load(stream, version);
 }
예제 #2
0
파일: M2Bone.cs 프로젝트: Koward/M2Lib
 public void Save(BinaryWriter stream, M2.Format version)
 {
     Debug.Assert(version != M2.Format.Useless);
     stream.Write((int) KeyBoneId);
     stream.Write((uint) Flags);
     stream.Write(ParentBone);
     stream.Write(SubmeshId);
     if (version > M2.Format.Classic)
     {
         stream.Write(_unknown[0]);
         stream.Write(_unknown[1]);
     }
     Translation.Save(stream, version);
     if (version > M2.Format.Classic)
     {
         _compressedRotation = new M2Track<M2CompQuat>(new M2CompQuat(32767, 32767, 32767, -1));
         _compressedRotation.Sequences = Rotation.Sequences;
         Rotation.Compress(_compressedRotation);
         _compressedRotation.Save(stream, version);
     }
     else
         Rotation.Save(stream, version);
     Scale.Save(stream, version);
     stream.Write(Pivot);
 }
예제 #3
0
 public void Save(BinaryWriter stream, M2.Format version = M2.Format.Useless)
 {
     stream.Write(Flags);
     stream.Write(Flags2);
     stream.Write(_unknown1);
     stream.Write(SubmeshId);
     stream.Write(TextureId);
     stream.Write(ColorId);
     stream.Write(TransparencyId);
 }
예제 #4
0
 public void Load(BinaryReader stream, M2.Format version = M2.Format.Useless)
 {
     Flags = stream.ReadByte();
     Flags2 = stream.ReadByte();
     _unknown1 = stream.ReadUInt16();
     SubmeshId = stream.ReadUInt16();
     TextureId = stream.ReadUInt16();
     ColorId = stream.ReadUInt16();
     TransparencyId = stream.ReadUInt16();
 }
예제 #5
0
 public void Save(BinaryWriter stream, M2.Format version)
 {
     stream.Write(Id);
     stream.Write(Bone);
     stream.Write(Position);
     if (version < M2.Format.LichKing && AnimateAttached.Timestamps.Count == 0)
     {
         AnimateAttached.Timestamps.Add(new M2Array<uint> {0});
         AnimateAttached.Values.Add(new M2Array<bool> {true});
     }
     AnimateAttached.Save(stream, version);
 }
예제 #6
0
파일: M2Bone.cs 프로젝트: Koward/M2Lib
 public void Load(BinaryReader stream, M2.Format version)
 {
     Debug.Assert(version != M2.Format.Useless);
     KeyBoneId = (KeyBone) stream.ReadInt32();
     Flags = (BoneFlags) stream.ReadUInt32();
     ParentBone = stream.ReadInt16();
     SubmeshId = stream.ReadUInt16();
     if (version > M2.Format.Classic)
     {
         _unknown[0] = stream.ReadUInt16();
         _unknown[1] = stream.ReadUInt16();
     }
     Translation.Load(stream, version);
     if (version > M2.Format.Classic)
     {
         _compressedRotation = new M2Track<M2CompQuat>(new M2CompQuat(32767, 32767, 32767, -1));
         _compressedRotation.Sequences = Rotation.Sequences;
         _compressedRotation.Load(stream, version);
     }
     else
         Rotation.Load(stream, version);
     Scale.Load(stream, version);
     Pivot = stream.ReadC3Vector();
 }
예제 #7
0
 public void Load(BinaryReader stream, M2.Format version)
 {
     if (version >= M2.Format.Cataclysm)
     {
         SubmeshId = stream.ReadUInt16();
         Level = stream.ReadUInt16();
     }
     else
     {
         SubmeshId = (ushort) stream.ReadUInt32();
     }
     StartVertex = stream.ReadUInt16();
     NVertices = stream.ReadUInt16();
     StartTriangle = stream.ReadUInt16();
     NTriangles = stream.ReadUInt16();
     NBones = stream.ReadUInt16();
     StartBones = stream.ReadUInt16();
     BoneInfluences = stream.ReadUInt16();
     RootBone = stream.ReadUInt16();
     CenterMass = stream.ReadC3Vector();
     if (version <= M2.Format.Classic) return;
     CenterBoundingBox = stream.ReadC3Vector();
     Radius = stream.ReadSingle();
 }
예제 #8
0
파일: M2Texture.cs 프로젝트: Koward/M2Lib
 public void Load(BinaryReader stream, M2.Format version)
 {
     Type = (TextureType) stream.ReadUInt32();
     Flags = (TextureFlags) stream.ReadUInt32();
     _name.Load(stream, version);
 }
예제 #9
0
파일: M2Texture.cs 프로젝트: Koward/M2Lib
 public void Save(BinaryWriter stream, M2.Format version)
 {
     stream.Write((uint) Type);
     stream.Write((uint) Flags);
     _name.Save(stream, version);
 }
예제 #10
0
파일: M2Bone.cs 프로젝트: Koward/M2Lib
 public void LoadContent(BinaryReader stream, M2.Format version)
 {
     Debug.Assert(version != M2.Format.Useless);
     Translation.LoadContent(stream, version);
     if (version > M2.Format.Classic)
     {
         _compressedRotation.Sequences = Rotation.Sequences;
         _compressedRotation.LoadContent(stream, version);
         _compressedRotation.Decompress(Rotation);
         _compressedRotation = null;
     }
     else
         Rotation.LoadContent(stream, version);
     Scale.LoadContent(stream, version);
 }
예제 #11
0
 public void LoadContent(BinaryReader stream, M2.Format version)
 {
     Weight.LoadContent(stream, version);
 }
예제 #12
0
 public void LoadContent(BinaryReader stream, M2.Format version)
 {
     AnimateAttached.LoadContent(stream, version);
 }
예제 #13
0
파일: Program.cs 프로젝트: Koward/M2Lib
        public static void Main(string[] args)
        {
            /*
            Console.WriteLine("Koward M2 converter prealpha");
            Console.WriteLine("YOU ARE ABOUT TO HACK TIME. ARE YOU SURE? >YES");
            if (args.Length < 1)
            {
                Console.WriteLine("No model was specified.");
                return;
            }
            var model = new M2();
            using (var reader = new BinaryReader(new FileStream(args[0], FileMode.Open)))
                model.Load(reader);
            Debug.WriteLine(model.Name + " loaded.");
            using (var writer = new BinaryWriter(new FileStream(args[0], FileMode.Create)))
                model.Save(writer, M2.Format.Classic);
            Debug.WriteLine(model.Name + " converted.");
            */
            Debug.WriteLine("Debug application for M2Lib");
            const string fileName = "draenor/world/arttest/boxtest/xyz.m2";
            //const string fileName = "draenor/world/generic/activedoodads/chest01/chest01.m2";
            //const string fileName = "lichking/world/arttest/boxtest/xyz.m2";
            //const string fileName = "Draenor/Character/Human/Male/HumanMale_HD.m2";
            //const string fileName = "Draenor/Creature/Frog/Frog.m2";
            //const string fileName = "Legion/Character/Naga_/Male/Naga_Male.m2";
            //const string fileName2 = "Output/Naga_Male.m2";
            //const string fileName2 = "Output/Frog.m2";
            //const string fileName = "BurningCrusade/FrogGenuine.m2";
            //const string fileName = "Legion/Creature/Bear2/Bear2.m2";
            //const string fileName2 = "Output/Bear2CSharp.m2";
            //const string fileName = "Classic/BogBeast.m2";
            //const string fileName = "Legion/Interface/Glues/Models/ui_orc/ui_orc.m2";
            //const string fileName2 = "Output/ui_orc.m2";
            var model = new M2();
            using (var reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
                model.Load(reader);
            Debug.WriteLine(model.Name + " loaded");
            Debug.WriteLine(model.BoneLookup);
            Debug.WriteLine(model.Views);
            /*
            foreach (var view in model.Views)
            {
                var goodSubmeshes = new List<M2SkinSection>();
                foreach (var geoset in view.Submeshes)
                {
                    if(geoset.SubmeshId == 0 || geoset.SubmeshId == 401) goodSubmeshes.Add(geoset);
                }
                view.Submeshes.Clear();
                view.Submeshes.AddRange(goodSubmeshes);
            }
            */
            /*
            using (var writer = new BinaryWriter(new FileStream(fileName2, FileMode.Create)))
                model.Save(writer, M2.Format.Classic);
            Debug.WriteLine(model.Name + " written.");

            /*
            Debug.WriteLine("Submeshes number : " + model.Views[0].Submeshes.Count);
            Debug.WriteLine("BoneInfluences : " + model.Views[0].Submeshes[0].BoneInfluences);
            //KOWARD method
            var max = 0;
            const int submeshNumber = 1;
            for (var i = model.Views[0].Submeshes[submeshNumber].StartVertex;
                i < model.Views[0].Submeshes[submeshNumber].StartVertex + model.Views[0].Submeshes[submeshNumber].NVertices;
                i++)
            {
                var vertex = model.GlobalVertexList[model.Views[0].Indices[i]];
                var localMax = 0;
                for(var j = 0; j < vertex.BoneWeights.Length; j++)
                {
                    var weight = vertex.BoneWeights[j];
                    Debug.Write(" "+weight+" ");
                    var relatedBone = model.Bones[model.BoneLookup[vertex.BoneIndices[j]]];
                    if (weight > 0 && relatedBone.Flags.HasFlag(M2Bone.BoneFlags.Transformed)) localMax++;
                }
                if (localMax > max) max = localMax;
                Debug.WriteLine("");
            }
            Debug.WriteLine("\tComputed number : " + max);
            /*
            //DEAMON method
            Debug.WriteLine("Method 2 (Deamon)");
                var boneSet = new HashSet<M2Bone>();
                for (var i = model.Views[0].Submeshes[0].StartVertex;
                    i < model.Views[0].Submeshes[0].StartVertex + model.Views[0].Submeshes[0].NVertices;
                    i++)
                {
                    var vertex = model.GlobalVertexList[model.Views[0].Indices[i]];
                    foreach (var index in vertex.BoneIndices)
                    {
                        Debug.Assert(model.Bones.Count > index);
                        if ((!boneSet.Contains(model.Bones[index])) && (model.Bones[index].KeyBoneId != (M2Bone.KeyBone) (-1))) boneSet.Add(model.Bones[index]);
                    }
                }
                Debug.WriteLine("\tNumber : " + boneSet.Count);
            /*
            /*
            BinaryReader stream = null;
            Func<BinaryReader, C3Vector> testFunc = i => i.ReadC3Vector();
            var result = testFunc(stream);
            */
            /*
            using (var writer = new StreamWriter("Test.iqe"))
            {
                writer.WriteLine("# Inter-Quake Export");
                writer.WriteLine("");
                foreach (var bone in model.Bones)
                {
                    if(bone.KeyBoneId != M2Bone.KeyBone.Other) writer.WriteLine("joint \""+ bone.KeyBoneId + "\" " + bone.ParentBone);
                    else writer.WriteLine("joint \"\" " + bone.ParentBone);
                }
                writer.WriteLine("");
                foreach (var bone in model.Bones)
                {
                    writer.WriteLine("pq "+bone.Pivot.X+" "+bone.Pivot.Y+" "+bone.Pivot.Z);
                }
                writer.WriteLine("");
                writer.WriteLine("vertexarray position float 3");
                writer.WriteLine("vertexarray texcoord float 2");
                writer.WriteLine("vertexarray normal float 3");
                //writer.WriteLine("vertexarray tangent float 4");//TODO Tangents ?
                writer.WriteLine("vertexarray normal float 3");
                writer.WriteLine("");
                writer.WriteLine("mesh \""+"Test"+"\"");
                writer.WriteLine("material \""+"Texture.tga"+"\"");
                writer.WriteLine("");
                writer.WriteLine("");
                writer.WriteLine("");
            }
            */
        }
예제 #14
0
 public void SaveContent(BinaryWriter stream, M2.Format version)
 {
     Translation.SaveContent(stream, version);
     Rotation.SaveContent(stream, version);
     Scale.SaveContent(stream, version);
 }
예제 #15
0
 public void LoadContent(BinaryReader stream, M2.Format version)
 {
     Translation.LoadContent(stream, version);
     Rotation.LoadContent(stream, version);
     Scale.LoadContent(stream, version);
 }
예제 #16
0
파일: M2Color.cs 프로젝트: Koward/M2Lib
 public void LoadContent(BinaryReader stream, M2.Format version)
 {
     Color.LoadContent(stream, version);
     Alpha.LoadContent(stream, version);
 }
예제 #17
0
파일: M2Color.cs 프로젝트: Koward/M2Lib
 public void SaveContent(BinaryWriter stream, M2.Format version)
 {
     Color.SaveContent(stream, version);
     Alpha.SaveContent(stream, version);
 }
예제 #18
0
 public void SaveContent(BinaryWriter stream, M2.Format version)
 {
     AnimateAttached.SaveContent(stream, version);
 }
예제 #19
0
 public void SaveContent(BinaryWriter stream, M2.Format version)
 {
     Weight.SaveContent(stream, version);
 }
예제 #20
0
        public void Save(BinaryWriter stream, M2.Format version)
        {
            if (version < M2.Format.Cataclysm && BoneInfluences == 0) BoneInfluences = 1; //@author Mjollna

            if (version >= M2.Format.Cataclysm)
            {
                stream.Write(SubmeshId);
                stream.Write(Level);
            }
            else
            {
                if (Level > 0) throw new Exception("This model has too many polygons to be saved in this version.");
                stream.Write((uint) SubmeshId);
            }
            stream.Write(StartVertex);
            stream.Write(NVertices);
            stream.Write(StartTriangle);
            stream.Write(NTriangles);
            stream.Write(NBones);
            stream.Write(StartBones);
            stream.Write(BoneInfluences);
            stream.Write(RootBone);
            stream.Write(CenterMass);
            if (version <= M2.Format.Classic) return;
            stream.Write(CenterBoundingBox);
            stream.Write(Radius);
        }