/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public void Serialise(IwSerialise serialise) { if (serialise.IsReading()) { this.m_IGIDs = new ushort[4]; this.m_U0 = new short[8]; } serialise.UInt32(ref this.m_Flags); int numVerts = 4; if (0 == (this.m_Flags & IW_MODEL_PRIM_QUAD_F) && serialise.IsVersionOlderThen(3, 5, 6)) { numVerts = 3; } serialise.Serialise(ref this.m_IGIDs, numVerts); if (this.IsTextured) { // serialise.Int16(ref this.m_U0[0 * 2]); // serialise.Int16(ref this.m_U0[0 * 2 + 1]); // serialise.Int16(ref this.m_U0[1 * 2]); // serialise.Int16(ref this.m_U0[1 * 2 + 1]); // serialise.Int16(ref this.m_U0[2 * 2]); // serialise.Int16(ref this.m_U0[2 * 2 + 1]); // serialise.Int16(ref this.m_U0[3 * 2]); // serialise.Int16(ref this.m_U0[3 * 2 + 1]); if (0 != (this.m_Flags & IW_MODEL_PRIM_QUAD_F)) { serialise.Int16(ref this.m_U0[0 * 2]); serialise.Int16(ref this.m_U0[0 * 2 + 1]); serialise.Int16(ref this.m_U0[2 * 2]); serialise.Int16(ref this.m_U0[2 * 2 + 1]); serialise.Int16(ref this.m_U0[3 * 2]); serialise.Int16(ref this.m_U0[3 * 2 + 1]); serialise.Int16(ref this.m_U0[1 * 2]); serialise.Int16(ref this.m_U0[1 * 2 + 1]); } else { serialise.Int16(ref this.m_U0[0 * 2]); serialise.Int16(ref this.m_U0[0 * 2 + 1]); serialise.Int16(ref this.m_U0[2 * 2]); serialise.Int16(ref this.m_U0[2 * 2 + 1]); serialise.Int16(ref this.m_U0[1 * 2]); serialise.Int16(ref this.m_U0[1 * 2 + 1]); serialise.Int16(ref this.m_U0[3 * 2]); serialise.Int16(ref this.m_U0[3 * 2 + 1]); } } }
uint m_NumVerts; // number of verts in skin set public override void Serialise(IwSerialise serialise) { base.Serialise(serialise); serialise.UInt32(ref m_NumVerts); if (serialise.IsReading()) { uint dataLen = 0; serialise.UInt32(ref dataLen); long pos = serialise.Position + dataLen; byte boneId = 0; for (; ;) { serialise.UInt8(ref boneId); if (boneId == 0xFF) { break; } boneIds.Add(boneId); } // pad if ((boneIds.Count % 2) == 0) { serialise.UInt8(ref boneId); } vertices = new CIwAnimSkinSetVertex[m_NumVerts]; for (int i = 0; i < m_NumVerts; ++i) { serialise.UInt16(ref vertices[i].VertexId); vertices[i].Bones = new CIwAnimSkinSetVertexBone[boneIds.Count]; for (int j = 0; j < boneIds.Count; j++) { serialise.SVec3(ref vertices[i].Bones[j].BindPose); } for (int j = 0; j < boneIds.Count; j++) { serialise.UInt8(ref vertices[i].Bones[j].Weight); } // pad if (boneIds.Count % 2 == 1) { serialise.UInt8(ref boneId); } } if (serialise.Position != pos) { throw new FormatException("CIwAnimSkinSet"); } } else { throw new ApplicationException(); } }
/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public override void Serialise(IwSerialise serialise) { base.Serialise(serialise); serialise.Serialise(ref this.VertIDOfs); serialise.Serialise(ref this.NormIDOfs); serialise.Serialise(ref this.ColIDOfs); serialise.Serialise(ref this.UV0IDOfs); this.TupleSize = 0; if (this.TupleSize < this.VertIDOfs) { this.TupleSize = this.VertIDOfs; } if (this.TupleSize < this.NormIDOfs) { this.TupleSize = this.NormIDOfs; } if (this.TupleSize < this.ColIDOfs) { this.TupleSize = this.ColIDOfs; } if (this.TupleSize < this.UV0IDOfs) { this.TupleSize = this.UV0IDOfs; } if (serialise.IsReading()) { ++this.TupleSize; this.Tuples = new ushort[this.TupleSize * this.numItems]; } serialise.Serialise(ref this.Tuples); ////var buf = new byte[Math.Min(256, serialise.Length-serialise.Position)]; ////serialise.Serialise(ref buf); ////StringBuilder sb = new StringBuilder(); ////int i = 0; ////foreach (var b in buf) ////{ //// if (b < 16) //// sb.Append("0"); //// sb.Append(string.Format("{0:x} ", b)); //// ++i; //// if (i == 8) //// sb.Append("| "); //// if (i == 16) //// { //// sb.Append("\n"); //// i = 0; //// } ////} ////Debug.WriteLine(sb.ToString()); ////throw new NotImplementedException(); }
public override void Serialise(IwSerialise serialise) { base.Serialise(serialise); serialise.UInt32(ref m_NumVerts); if (serialise.IsReading()) { uint dataLen = 0; serialise.UInt32(ref dataLen); long pos = serialise.Position + dataLen; byte boneId = 0; for (; ; ) { serialise.UInt8(ref boneId); if (boneId == 0xFF) break; boneIds.Add(boneId); } // pad if ((boneIds.Count % 2) == 0) serialise.UInt8(ref boneId); vertices = new CIwAnimSkinSetVertex[m_NumVerts]; for (int i = 0; i < m_NumVerts;++i ) { serialise.UInt16(ref vertices[i].VertexId); vertices[i].Bones = new CIwAnimSkinSetVertexBone[boneIds.Count]; for (int j = 0; j < boneIds.Count; j++) { serialise.SVec3(ref vertices[i].Bones[j].BindPose); } for (int j = 0; j < boneIds.Count; j++) { serialise.UInt8(ref vertices[i].Bones[j].Weight); } // pad if ( boneIds.Count % 2 == 1) serialise.UInt8(ref boneId); } if (serialise.Position != pos) throw new FormatException("CIwAnimSkinSet"); } else { throw new ApplicationException(); } }
/// <summary> /// The serialise header. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public void SerialiseHeader(IwSerialise serialise) { if (serialise.IsReading()) { uint l = 0; serialise.UInt32(ref l); this.Resize(l); } else { uint l = this.size; serialise.UInt32(ref this.size); } }
/// <summary> /// The serialise len str z. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> /// <param name="str"> /// The str. /// </param> /// <exception cref="NotImplementedException"> /// </exception> public static void SerialiseLenStrZ(IwSerialise serialise, ref string str) { if (serialise.IsReading()) { int len = 0; serialise.Int32(ref len); byte[] b = new byte[len + 1]; serialise.Serialise(ref b); str = Encoding.ASCII.GetString(b); } else { throw new NotImplementedException(); } }
/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public void Serialise(IwSerialise serialise) { serialise.Vec3(ref this.center); if (serialise.IsReading()) { int r = 0; serialise.Int32(ref r); this.radius = r; } else { int r = (int)this.radius; serialise.Int32(ref r); } }
/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public override void Serialise(IwSerialise serialise) { base.Serialise(serialise); { uint val = 0x00020000; serialise.UInt32(ref val); } { ushort val = 4; serialise.UInt16(ref val); } { ushort val = 4; serialise.UInt16(ref val); } this.sphere.Serialise(serialise); this.list.Serialise(serialise); this.ext.Serialise(serialise); if (serialise.IsReading()) { uint numMaterials = 0; serialise.UInt32(ref numMaterials); this.materials = new CIwMaterial[numMaterials]; for (int i = 0; i < this.materials.Length; ++i) { CIwManaged m = null; serialise.ManagedHash("CIwMaterial".ToeHash(), ref m); this.materials[i] = (CIwMaterial)m; } } else { uint numMaterials = (uint)this.materials.Length; serialise.UInt32(ref numMaterials); for (int i = 0; i < this.materials.Length; ++i) { CIwManaged m = this.materials[i]; serialise.ManagedHash("CIwMaterial".ToeHash(), ref m); } } }
/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public override void Serialise(IwSerialise serialise) { base.Serialise(serialise); serialise.UInt32(ref this.m_MaterialID); serialise.UInt16(ref this.m_NumTupleIDs); if (serialise.IsReading()) { this.m_TupleIDs = new ushort[this.m_NumTupleIDs]; this.prims = new _IwModelPrim[this.numItems]; } serialise.Serialise(ref this.m_TupleIDs); for (int i = 0; i < this.numItems; ++i) { this.prims[i].Serialise(serialise); } }
/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> /// <exception cref="NotImplementedException"> /// </exception> /// <exception cref="NotImplementedException"> /// </exception> public void Serialise(IwSerialise serialise) { SerialiseLenStr(serialise, ref this.name); serialise.UInt32(ref this.type); serialise.Int32(ref this.arraySize); serialise.UInt32(ref this.flags); if (serialise.IsReading()) { if (this.IsFloat) { this.floatData = new float[this.arraySize * this.NumberOfComponents]; serialise.Serialise(ref this.floatData); } else { throw new NotImplementedException(); } } else { throw new NotImplementedException(); } }