public void Load(string mypath, ClientType myclientType) { this.path = mypath; BinaryReader binaryReader = new BinaryReader(File.Open(mypath, FileMode.Open)); string text = RoseFile.ReadFString(ref binaryReader, 8); if (!text.Equals("ZMO0002\0")) { throw new Exception("wrong file header"); } this.FPS = binaryReader.ReadInt32(); this.frameCount = binaryReader.ReadInt32(); this.channelCount = binaryReader.ReadInt32(); for (int i = 0; i < this.channelCount; i++) { ZMO.Channel channel = new ZMO.Channel(); channel.trackType = (ZMO.TrackType)binaryReader.ReadInt32(); channel.trackID = binaryReader.ReadInt32(); if (channel.trackType == ZMO.TrackType.TRACK_TYPE_NORMAL) { channel.normal = new List <Vector3>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_ROTATION) { channel.rotation = new List <Vector4>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_POSITION) { channel.position = new List <Vector3>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_ALPHA) { channel.alpha = new List <float>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_UV1) { channel.uv1 = new List <Vector2>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_UV2) { channel.uv2 = new List <Vector2>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_UV3) { channel.uv3 = new List <Vector2>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_UV4) { channel.uv4 = new List <Vector2>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_TEXTUREANIM) { channel.textureAnim = new List <float>(); } else if (channel.trackType == ZMO.TrackType.TRACK_TYPE_SCALE) { channel.scale = new List <float>(); } this.listChannel.Add(channel); } for (int i = 0; i < this.frameCount; i++) { for (int j = 0; j < this.channelCount; j++) { if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_NORMAL) { this.listChannel[j].normal[i] = RoseFile.ReadVector3(ref binaryReader); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_ROTATION) { this.listChannel[j].rotation[i] = RoseFile.ReadVector4(ref binaryReader); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_POSITION) { this.listChannel[j].position.Add(RoseFile.ReadVector3(ref binaryReader)); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_ALPHA) { this.listChannel[j].alpha[i] = binaryReader.ReadSingle(); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_UV1) { this.listChannel[j].uv1[i] = RoseFile.ReadVector2(ref binaryReader); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_UV2) { this.listChannel[j].uv2[i] = RoseFile.ReadVector2(ref binaryReader); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_UV3) { this.listChannel[j].uv3[i] = RoseFile.ReadVector2(ref binaryReader); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_UV4) { this.listChannel[j].uv4[i] = RoseFile.ReadVector2(ref binaryReader); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_TEXTUREANIM) { this.listChannel[j].textureAnim[i] = binaryReader.ReadSingle(); } else if (this.listChannel[j].trackType == ZMO.TrackType.TRACK_TYPE_SCALE) { this.listChannel[j].scale[i] = binaryReader.ReadSingle(); } } } binaryReader.Close(); }
public void Load(string Path, ClientType myClientType) { this.path = Path; this.clientType = myClientType; BinaryReader binaryReader = new BinaryReader(File.Open(this.path, FileMode.Open)); binaryReader.BaseStream.Seek(8L, SeekOrigin.Begin); int num = binaryReader.ReadInt32(); binaryReader.BaseStream.Seek(24L, SeekOrigin.Current); this.boneCount = binaryReader.ReadInt16(); this.boneLookUp = new short[(int)this.boneCount]; for (int i = 0; i < (int)this.boneCount; i++) { this.boneLookUp[i] = binaryReader.ReadInt16(); } this.vertCount = binaryReader.ReadInt16(); this.vertex = new ObjectVertex[(int)this.vertCount]; if ((num & 2) > 0) { for (int i = 0; i < (int)this.vertCount; i++) { this.vertex[i].Position = RoseFile.ReadVector3(ref binaryReader); } } if ((num & 4) > 0) { binaryReader.BaseStream.Seek((long)(12 * this.vertCount), SeekOrigin.Current); } if ((num & 8) > 0) { binaryReader.BaseStream.Seek((long)(4 * this.vertCount), SeekOrigin.Current); } if ((num & 16) > 0 && (num & 32) > 0) { this.vertexWeight = new ZMS.Weight[(int)this.vertCount]; this.vertexBoneID = new ZMS.BoneID[(int)this.vertCount]; for (int i = 0; i < (int)this.vertCount; i++) { this.vertexWeight[i].Weight1 = binaryReader.ReadSingle(); this.vertexWeight[i].Weight2 = binaryReader.ReadSingle(); this.vertexWeight[i].Weight3 = binaryReader.ReadSingle(); this.vertexWeight[i].Weight4 = binaryReader.ReadSingle(); this.vertexBoneID[i].BoneId1 = binaryReader.ReadInt16(); this.vertexBoneID[i].BoneId2 = binaryReader.ReadInt16(); this.vertexBoneID[i].BoneId3 = binaryReader.ReadInt16(); this.vertexBoneID[i].BoneId4 = binaryReader.ReadInt16(); } } if ((num & 64) > 0) { binaryReader.BaseStream.Seek((long)(12 * this.vertCount), SeekOrigin.Current); } if ((num & 128) > 0) { for (int i = 0; i < (int)this.vertCount; i++) { this.vertex[i].TextureCoordinate = RoseFile.ReadVector2(ref binaryReader); } } if ((num & 256) > 0) { binaryReader.BaseStream.Seek((long)(8 * this.vertCount), SeekOrigin.Current); } if ((num & 512) > 0) { } if ((num & 1024) > 0) { } this.faceCount = binaryReader.ReadInt16(); this.indices = new short[(int)(this.faceCount * 3)]; for (int i = 0; i < (int)this.faceCount; i++) { this.indices[i * 3] = binaryReader.ReadInt16(); this.indices[i * 3 + 1] = binaryReader.ReadInt16(); this.indices[i * 3 + 2] = binaryReader.ReadInt16(); } this.vertexBuffer = new VertexBuffer(this.graphics, (int)(20 * this.vertCount), BufferUsage.WriteOnly); this.vertexBuffer.SetData <ObjectVertex>(this.vertex); this.indexBuffer = new IndexBuffer(this.graphics, typeof(short), this.indices.Length, BufferUsage.None); this.indexBuffer.SetData <short>(this.indices); binaryReader.Close(); }