VeCollisionMesh.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #region License information
  2. // ----------------------------------------------------------------------------
  3. //
  4. // libeq2 - A library for analyzing the Everquest II File Format
  5. // Blaz (blaz@blazlabs.com)
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // as published by the Free Software Foundation; either version 2
  10. // of the License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  20. //
  21. // ( The full text of the license can be found in the License.txt file )
  22. //
  23. // ----------------------------------------------------------------------------
  24. #endregion
  25. #region Using directives
  26. using System;
  27. using System.Diagnostics;
  28. #endregion
  29. namespace Everquest2.Visualization
  30. {
  31. public class VeCollisionMesh : VeBase
  32. {
  33. public struct Face
  34. {
  35. public short unk0;
  36. public short unk1;
  37. public byte unk2;
  38. public byte unk3;
  39. }
  40. public struct Leaf
  41. {
  42. public uint unk0;
  43. public short unk1;
  44. }
  45. public struct Branch
  46. {
  47. public float unk0;
  48. public short unk1;
  49. public short unk2;
  50. public byte unk3;
  51. }
  52. public VeCollisionMesh()
  53. {
  54. }
  55. /// <summary>
  56. /// Special constructor used when deserializing the instance of the class.
  57. /// </summary>
  58. /// <param name="reader">Reader used to read the instance data.</param>
  59. protected VeCollisionMesh(Util.Eq2Reader reader, Util.StreamingContext context) : base(reader, context)
  60. {
  61. byte classVersion = context.ClassVersions[typeof(VeCollisionMesh)];
  62. uint chunkId;
  63. uint chunkSize;
  64. chunkId = reader.ReadUInt32();
  65. chunkSize = reader.ReadUInt32();
  66. Debug.Assert(chunkId == 0x20544948 && chunkSize > 0, "Invalid VeCollisionMesh HIT chunk");
  67. chunkId = reader.ReadUInt32();
  68. chunkSize = reader.ReadUInt32();
  69. Debug.Assert(chunkId == 0x58444956 && chunkSize > 0, "Invalid VeCollisionMesh VIDX chunk");
  70. uint vertexIndexCount = chunkSize / 2;
  71. vertexIndices = new ushort[vertexIndexCount];
  72. for (uint i = 0; i < vertexIndexCount; ++i ) vertexIndices[i] = reader.ReadUInt16();
  73. chunkId = reader.ReadUInt32();
  74. chunkSize = reader.ReadUInt32();
  75. Debug.Assert(chunkId == 0x58444945 && chunkSize > 0, "Invalid VeCollisionMesh EIDX chunk");
  76. uint edgeIndexCount = chunkSize / 2;
  77. edgeIndices = new ushort[edgeIndexCount];
  78. for (uint i = 0; i < edgeIndexCount; ++i) edgeIndices[i] = reader.ReadUInt16();
  79. chunkId = reader.ReadUInt32();
  80. if (chunkId == 0x58444946)
  81. {
  82. chunkSize = reader.ReadUInt32();
  83. uint faceIndexCount = chunkSize / 2;
  84. faceIndices = new ushort[faceIndexCount];
  85. for (uint i = 0; i < faceIndexCount; ++i) faceIndices[i] = reader.ReadUInt16();
  86. chunkId = reader.ReadUInt32();
  87. }
  88. chunkSize = reader.ReadUInt32();
  89. Debug.Assert(chunkId == 0x54524556 && chunkSize > 0, "Invalid VeCollisionMesh VERT chunk");
  90. uint vertexCount = chunkSize / 12;
  91. vertices = new float[vertexCount,3];
  92. for (uint i = 0; i < vertexCount; ++i)
  93. {
  94. vertices[i, 0] = reader.ReadSingle();
  95. vertices[i, 1] = reader.ReadSingle();
  96. vertices[i, 2] = reader.ReadSingle();
  97. }
  98. chunkId = reader.ReadUInt32();
  99. chunkSize = reader.ReadUInt32();
  100. Debug.Assert(chunkId == 0x45474445 && chunkSize > 0, "Invalid VeCollisionMesh EDGE chunk");
  101. uint edgeCount = chunkSize / 4;
  102. edges = new ushort[edgeCount,2];
  103. for (uint i = 0; i < edgeCount; ++i)
  104. {
  105. edges[i, 0] = reader.ReadUInt16();
  106. edges[i, 1] = reader.ReadUInt16();
  107. }
  108. chunkId = reader.ReadUInt32();
  109. chunkSize = reader.ReadUInt32();
  110. Debug.Assert(chunkId == 0x45434146 && chunkSize > 0, "Invalid VeCollisionMesh FACE chunk");
  111. uint faceSize = (uint)(classVersion != 6 ? 6 : 5);
  112. uint faceCount = chunkSize / faceSize;
  113. faces = new Face[faceCount];
  114. for (uint i = 0; i < faceCount; ++i)
  115. {
  116. faces[i].unk0 = reader.ReadInt16();
  117. faces[i].unk1 = reader.ReadInt16();
  118. if (classVersion < 5 || classVersion > 6) faces[i].unk2 = reader.ReadByte();
  119. faces[i].unk3 = reader.ReadByte();
  120. }
  121. chunkId = reader.ReadUInt32();
  122. if (chunkId == 0x4641454C)
  123. {
  124. chunkSize = reader.ReadUInt32();
  125. Debug.Assert(chunkSize > 0, "Invalid VeCollisionMesh LEAF chunk");
  126. uint leafCount = chunkSize / 6;
  127. leaves = new Leaf[leafCount];
  128. for (uint i = 0; i < leafCount; ++i)
  129. {
  130. leaves[i].unk0 = reader.ReadUInt32();
  131. leaves[i].unk1 = reader.ReadInt16();
  132. }
  133. chunkId = reader.ReadUInt32();
  134. }
  135. if (chunkId == 0x4E415242)
  136. {
  137. chunkSize = reader.ReadUInt32();
  138. Debug.Assert(chunkSize > 0, "Invalid VeCollisionMesh BRAN chunk");
  139. uint branchCount = chunkSize / 9;
  140. branches = new Branch[branchCount];
  141. for (uint i = 0; i < branchCount; ++i)
  142. {
  143. branches[i].unk0 = reader.ReadSingle();
  144. branches[i].unk1 = reader.ReadInt16();
  145. branches[i].unk2 = reader.ReadInt16();
  146. branches[i].unk3 = reader.ReadByte();
  147. }
  148. chunkId = reader.ReadUInt32();
  149. }
  150. chunkSize = reader.ReadUInt32();
  151. Debug.Assert(chunkId == 0x59524442 && chunkSize > 0, "Invalid VeCollisionMesh BDRY chunk");
  152. uint bdryCount = chunkSize / 4;
  153. bdry = new float[bdryCount];
  154. for (uint i = 0; i < bdryCount; ++i) bdry[i] = reader.ReadSingle();
  155. }
  156. public ushort[] vertexIndices;
  157. public ushort[] edgeIndices;
  158. public ushort[] faceIndices;
  159. public float[,] vertices;
  160. public ushort[,] edges;
  161. public Face[] faces;
  162. public Leaf[] leaves;
  163. public Branch[] branches;
  164. public float[] bdry;
  165. }
  166. }