private void SaveSceneryModel(SceneryModelStruct ptr, BinaryWriter writer) { writer.Write(ptr.Header); if (ptr.Header == 0x1613) { short modelCount = 0; for (int i = 0; i < ptr.Models.Count; i++) { if (ptr.Models[i].isSpecial) { break; } modelCount++; } short specialModelCount = (short)(ptr.Models.Count - modelCount); writer.Write(modelCount); writer.Write(specialModelCount); if (ptr.Models.Count != 0) { for (int i = 0; i < ptr.Models.Count; i++) { writer.Write(ptr.Models[i].ModelBoundingBoxVector1.X); writer.Write(ptr.Models[i].ModelBoundingBoxVector1.Y); writer.Write(ptr.Models[i].ModelBoundingBoxVector1.Z); writer.Write(ptr.Models[i].ModelBoundingBoxVector1.W); writer.Write(ptr.Models[i].ModelBoundingBoxVector2.X); writer.Write(ptr.Models[i].ModelBoundingBoxVector2.Y); writer.Write(ptr.Models[i].ModelBoundingBoxVector2.Z); writer.Write(ptr.Models[i].ModelBoundingBoxVector2.W); } for (int i = 0; i < ptr.Models.Count; i++) { writer.Write(ptr.Models[i].ModelID); } for (int i = 0; i < ptr.Models.Count; i++) { for (int d = 0; d < ptr.Models[i].ModelMatrix.Length; d++) { writer.Write(ptr.Models[i].ModelMatrix[d].X); writer.Write(ptr.Models[i].ModelMatrix[d].Y); writer.Write(ptr.Models[i].ModelMatrix[d].Z); writer.Write(ptr.Models[i].ModelMatrix[d].W); } } } } for (int i = 0; i < ptr.UnkPos.Length; i++) { writer.Write(ptr.UnkPos[i].X); writer.Write(ptr.UnkPos[i].Y); writer.Write(ptr.UnkPos[i].Z); writer.Write(ptr.UnkPos[i].W); } }
private SceneryModelStruct LoadSceneryModel(BinaryReader reader) { SceneryModelStruct scenery = new SceneryModelStruct(); scenery.Header = reader.ReadUInt32(); scenery.Models = new List <ScenerySubModel>(); if (scenery.Header == 0x1613) { ushort modelCount = reader.ReadUInt16(); ushort specialModelCount = reader.ReadUInt16(); if (modelCount + specialModelCount != 0) { for (int i = 0; i < modelCount + specialModelCount; i++) { ScenerySubModel newModel = new ScenerySubModel(); newModel.ModelMatrix = new Pos[4]; newModel.ModelBoundingBoxVector1 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); newModel.ModelBoundingBoxVector2 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); scenery.Models.Add(newModel); } for (int i = 0; i < modelCount + specialModelCount; i++) { if (i > modelCount - 1) { scenery.Models[i].ModelID = reader.ReadUInt32(); scenery.Models[i].isSpecial = true; } else { scenery.Models[i].ModelID = reader.ReadUInt32(); scenery.Models[i].isSpecial = false; } } for (int i = 0; i < modelCount + specialModelCount; i++) { scenery.Models[i].ModelMatrix[0] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); scenery.Models[i].ModelMatrix[1] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); scenery.Models[i].ModelMatrix[2] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); scenery.Models[i].ModelMatrix[3] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); } } } scenery.UnkPos = new Pos[5]; scenery.UnkPos[0] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); scenery.UnkPos[1] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); scenery.UnkPos[2] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); scenery.UnkPos[3] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); scenery.UnkPos[4] = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); return(scenery); }
private void CountSceneryModel(SceneryModelStruct ptr, ref int count) { count += 4; if (ptr.Header == 0x1613) { count += 4; if (ptr.Models.Count != 0) { for (int i = 0; i < ptr.Models.Count; i++) { count += 32; count += 4; count += 16 * ptr.Models[i].ModelMatrix.Length; } } } count += ptr.UnkPos.Length * 16; }