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); }
public void PopulateM2Track <TType>(M2Track <TType> track, IEnumerable <Sequence> seqs) where TType : new() { track.GlobalSequence = (short)GlobalSequenceId; track.InterpolationType = M2Track <TType> .InterpolationTypes.Linear; // (M2Track<TType>.InterpolationTypes)InterpolationType; var type = MDLTRACKTYPE.TRACK_LINEAR; // InterpolationType; int index = 0; foreach (var s in seqs) { var nodes = Nodes.Where(x => x.Time >= s.MinTime && x.Time <= s.MaxTime).OrderBy(x => x.Time); if (track.Timestamps.Count < index + 1) { track.Timestamps.Add(new M2Array <uint>()); } if (track.Values.Count < index + 1) { track.Values.Add(new M2Array <TType>()); } track.Timestamps[index].AddRange(nodes.Select(x => x.Time - (uint)s.MinTime)); track.Values[index].AddRange(nodes.SelectMany(x => x.Convert <TType>(type))); index++; } }
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(); }
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); }
/// <inheritdoc/> public void LoadBinaryData(byte[] inData) { using (var ms = new MemoryStream(inData)) using (var br = new BinaryReader(ms)) { br.ReadUInt32(); // Signature Version = br.ReadUInt32(); Name = br.ReadMD20String(br.ReadUInt32(), br.ReadUInt32()); Flags = br.ReadUInt32(); // TODO: Implement Flags // Global Sequences UInt32 count = br.ReadUInt32(); UInt32 offset = br.ReadUInt32(); long headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { UInt32 value = br.ReadUInt32(); GlobalSequences.Add(value); } br.BaseStream.Position = headerpos; // Sequences count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { M2Sequence seq = new M2Sequence(); seq.AnimationID = br.ReadUInt16(); seq.SubAnimationID = br.ReadUInt16(); seq.Length = br.ReadUInt32(); seq.MovingSpeed = br.ReadSingle(); seq.Flags = br.ReadUInt32(); seq.Probability = br.ReadInt16(); seq.Padding = br.ReadUInt16(); seq.MinimumRepetitions = br.ReadUInt32(); seq.MaximumRepetitions = br.ReadUInt32(); seq.BlendTime = br.ReadUInt32(); seq.BoundsMinimumExtend = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); seq.BoundsMaximumExtend = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); seq.BoundRadius = br.ReadSingle(); seq.NextAnimation = br.ReadInt16(); seq.aliasNext = br.ReadUInt16(); Sequences.Add(seq); } br.BaseStream.Position = headerpos; //SequencesLookups count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { SequencesLookups.Add(br.ReadInt16()); } br.BaseStream.Position = headerpos; // Bones count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { M2Bone bone = new M2Bone(); bone.KeyBoneID = br.ReadInt32(); bone.Flags = br.ReadUInt32(); bone.ParentBone = br.ReadInt16(); bone.SubmeshID = br.ReadUInt16(); bone.CompressData[0] = br.ReadUInt16(); bone.CompressData[1] = br.ReadUInt16(); //translation M2Track translation = new M2Track(); translation.readM2Track(br); bone.translation = translation; // rotation M2Track rotation = new M2Track(); rotation.readM2Track(br); bone.rotation = rotation; // Scale M2Track scale = new M2Track(); scale.readM2Track(br); bone.scale = scale; bone.pivot = new C3Vector(br.ReadUInt32(), br.ReadUInt32(), br.ReadUInt32()); Bones.Add(bone); } br.BaseStream.Position = headerpos; // key_bone_lookup count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { KeyBoneLookup.Add(br.ReadInt16()); } br.BaseStream.Position = headerpos; // Vetices count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { M2Vertex temp = new M2Vertex(); temp.Pos = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); for (int a = 0; a < 4; a++) { temp.BoneWeights.Add(br.ReadByte()); } for (int a = 0; a < 4; a++) { temp.BoneIndices.Add(br.ReadByte()); } temp.Normal = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); temp.TexCords.Add(new C2Vector(br.ReadSingle(), br.ReadSingle())); temp.TexCords.Add(new C2Vector(br.ReadSingle(), br.ReadSingle())); } br.BaseStream.Position = headerpos; // Number of Skin profiles NumberSkinProfiles = br.ReadUInt32(); // Colors count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { M2Color temp = new M2Color(); // Color M2Track color = new M2Track(); color.readM2Track(br); temp.Color = color; // Alpha M2Track alpha = new M2Track(); alpha.readM2Track(br); temp.Alpha = alpha; Color.Add(temp); } br.BaseStream.Position = headerpos; // Textures count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { M2Texture temp = new M2Texture(); temp.Type = br.ReadUInt32(); temp.Flags = br.ReadUInt32(); UInt32 tCount = br.ReadUInt32(); UInt32 tOffset = br.ReadUInt32(); long tHeaderpos = br.BaseStream.Position; br.BaseStream.Position = tOffset; temp.Filename = ""; for (int a = 0; a < tCount; a++) { temp.Filename += br.ReadChar(); } br.BaseStream.Position = tHeaderpos; Texture.Add(temp); } br.BaseStream.Position = headerpos; // Texture Weights count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { M2Track temp = new M2Track(); temp.readM2Track(br); TextureWeights.Add(temp); } br.BaseStream.Position = headerpos; // UV Animations count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { M2TextureTransform temp = new M2TextureTransform(); M2Track translation = new M2Track(); translation.readM2Track(br); temp.Translation = translation; M2Track rotation = new M2Track(); rotation.readM2Track(br); temp.Rotation = rotation; M2Track scaling = new M2Track(); scaling.readM2Track(br); temp.Scaling = scaling; UvAnimations.Add(temp); } br.BaseStream.Position = headerpos; // Texture Replacements count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { TextureReplacements.Add(br.ReadInt16()); } br.BaseStream.Position = headerpos; // Materials count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { M2Material temp = new M2Material(); temp.Flags = br.ReadUInt16(); temp.BlendMode = br.ReadUInt16(); Materials.Add(temp); } br.BaseStream.Position = headerpos; // Bone Lookups count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { BoneLookups.Add(br.ReadUInt16()); } br.BaseStream.Position = headerpos; // Texture Units count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { TextureUnits.Add(br.ReadUInt16()); } br.BaseStream.Position = headerpos; // Texture Weights Lookups count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { TextureWeightsLookups.Add(br.ReadUInt16()); } br.BaseStream.Position = headerpos; // Animation Lookups count = br.ReadUInt32(); offset = br.ReadUInt32(); headerpos = br.BaseStream.Position; br.BaseStream.Position = offset; for (int i = 0; i < count; i++) { UvAnimationLookups.Add(br.ReadInt16()); } br.BaseStream.Position = headerpos; } }