Main.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Windows.Forms;
  4. using System.Collections.Generic;
  5. using SlimDX;
  6. using SlimDX.D3DCompiler;
  7. using SlimDX.Direct3D11;
  8. using SlimDX.DXGI;
  9. using SlimDX.Windows;
  10. using Device = SlimDX.Direct3D11.Device;
  11. using Resource = SlimDX.Direct3D11.Resource;
  12. using Buffer = SlimDX.Direct3D11.Buffer;
  13. using Everquest2.Util;
  14. using Everquest2.Visualization;
  15. using System.IO;
  16. using SlimDX.DirectInput;
  17. namespace EQ2ModelViewer
  18. {
  19. public partial class frmMain : Form
  20. {
  21. private System.Collections.Generic.List<Model> m_Models = new System.Collections.Generic.List<Model>();
  22. private GraphicClass Graphics = new GraphicClass();
  23. public Model SelectedModel = null;
  24. private string ZoneFile;
  25. private bool Render3DAspect = true;
  26. private bool AutoExportOnLoad = false;
  27. private String AutoLoadFileName = "";
  28. public frmMain()
  29. {
  30. InitializeComponent();
  31. }
  32. private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  33. {
  34. Close();
  35. }
  36. private void CleanUp()
  37. {
  38. foreach (Model model in m_Models)
  39. model.ShutDown();
  40. if (Graphics != null)
  41. Graphics.ShutDown();
  42. }
  43. private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
  44. {
  45. CleanUp();
  46. }
  47. private Key hitKey = Key.NoConvert;
  48. double timestamp = 0;
  49. private CameraClass camera;
  50. private void frmMain_Load(object sender, EventArgs e)
  51. {
  52. this.WindowState = FormWindowState.Maximized;
  53. Graphics.Initialize(pGraphics);
  54. /*LightShaderClass lightShader = new LightShaderClass();
  55. lightShader.Initialize(Graphics.Device);*/
  56. camera = new CameraClass();
  57. // Initialize a base view matrix for 2D rendering
  58. camera.SetPosition(0.0f, 0.0f, -1.0f);
  59. camera.Render();
  60. Matrix baseViewMatrix = camera.GetViewMatrix();
  61. // now set the cameras starting position
  62. camera.SetPosition(0.0f, 1.50f, -3.0f);
  63. PositionClass position = new PositionClass();
  64. position.SetPosition(0.0f, 1.50f, -3.0f);
  65. InputClass input = new InputClass();
  66. input.Initialize(this);
  67. TimerClass timer = new TimerClass();
  68. timer.Initialize();
  69. FPSClass fps = new FPSClass();
  70. fps.Initialize();
  71. TextClass text = new TextClass();
  72. text.Initialize(Graphics.Device, Graphics.Context, pGraphics.ClientSize.Width, pGraphics.ClientSize.Height, baseViewMatrix);
  73. BitmapClass bmp = new BitmapClass();
  74. bmp.Initialize(Graphics.Device, pGraphics.ClientSize.Width, pGraphics.ClientSize.Height, "Background.bmp", 145, 220, baseViewMatrix);
  75. string[] args = Environment.GetCommandLineArgs();
  76. if (args.Length > 1)
  77. {
  78. for (int i = 1; i < args.Length; i++)
  79. {
  80. string cmd = args[i].ToLower();
  81. if (cmd.Equals("norender"))
  82. {
  83. Render3DAspect = false;
  84. }
  85. else if (cmd.Equals("export"))
  86. {
  87. AutoExportOnLoad = true;
  88. }
  89. else
  90. {
  91. AutoLoadFileName = args[i];
  92. break;
  93. }
  94. }
  95. }
  96. if (AutoLoadFileName.Length > 0)
  97. LoadZoneFile(AutoLoadFileName);
  98. if (AutoExportOnLoad)
  99. exportToolStripMenuItem_Click(null, EventArgs.Empty);
  100. if (!Render3DAspect)
  101. {
  102. Application.Exit();
  103. return;
  104. }
  105. // FrustumClass frustum = new FrustumClass();
  106. try
  107. {
  108. MessagePump.Run(this, () =>
  109. {
  110. if (!Graphics.SwapChain.Disposed) {
  111. timer.Frame();
  112. fps.Frame();
  113. // Input code
  114. input.Frame();
  115. position.SetFrameTime(timer.GetTime());
  116. if (this.Focused)
  117. {
  118. if (input.IsKeyPressed(SlimDX.DirectInput.Key.LeftShift) ||
  119. input.IsKeyPressed(SlimDX.DirectInput.Key.RightShift))
  120. position.m_ShiftDown = true;
  121. else
  122. position.m_ShiftDown = false;
  123. position.TurnLeft(input.IsLeftPressed());
  124. position.TurnRight(input.IsRightPressed());
  125. position.MoveForward(input.IsUpPressed());
  126. position.MoveBackward(input.IsDownPressed());
  127. position.MoveUpward(input.IsAPressed());
  128. position.MoveDownward(input.IsZPressed());
  129. position.LookUpward(input.IsPgUpPressed());
  130. position.LookDownward(input.IsPgDownPressed());
  131. if (input.IsLeftMousePressed())
  132. {
  133. TestIntersection(input.GetMouseX(), input.GetMouseY());
  134. }
  135. if (SelectedModel != null)
  136. {
  137. if (input.IsKeyPressed(SlimDX.DirectInput.Key.Delete))
  138. {
  139. m_Models.Remove(SelectedModel);
  140. SelectedModel = null;
  141. }
  142. else if (input.IsKeyPressed(SlimDX.DirectInput.Key.Escape))
  143. {
  144. SelectedModel = null;
  145. }
  146. if (input.IsKeyPressed(SlimDX.DirectInput.Key.LeftControl))
  147. {
  148. if (hitKey == Key.NoConvert)
  149. {
  150. if (input.IsKeyPressed(SlimDX.DirectInput.Key.R))
  151. hitKey = Key.R;
  152. else if (input.IsKeyPressed(SlimDX.DirectInput.Key.T))
  153. hitKey = Key.T;
  154. else if (input.IsKeyPressed(SlimDX.DirectInput.Key.Y))
  155. hitKey = Key.Y;
  156. }
  157. double curTime = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
  158. if ((curTime - timestamp) > 50)
  159. {
  160. if (hitKey == Key.R)
  161. {
  162. if (input.IsKeyReleased(SlimDX.DirectInput.Key.R))
  163. hitKey = Key.NoConvert;
  164. SelectedModel.Rotation += new Vector3(0.01f, 0.0f, 0.0f);
  165. timestamp = curTime;
  166. }
  167. else if (hitKey == Key.T)
  168. {
  169. if (input.IsKeyReleased(SlimDX.DirectInput.Key.T))
  170. hitKey = Key.NoConvert;
  171. SelectedModel.Rotation += new Vector3(0.0f, 0.01f, 0.0f);
  172. timestamp = curTime;
  173. }
  174. else if (hitKey == Key.Y)
  175. {
  176. if (input.IsKeyReleased(SlimDX.DirectInput.Key.Y))
  177. hitKey = Key.NoConvert;
  178. SelectedModel.Rotation += new Vector3(0.0f, 0.0f, 0.01f);
  179. timestamp = curTime;
  180. }
  181. if (SelectedModel.Rotation.X > 360.0f)
  182. SelectedModel.Rotation.X = 0.0f;
  183. if (SelectedModel.Rotation.Y > 360.0f)
  184. SelectedModel.Rotation.Y = 0.0f;
  185. if (SelectedModel.Rotation.Z > 360.0f)
  186. SelectedModel.Rotation.Z = 0.0f;
  187. }
  188. }
  189. }
  190. }
  191. camera.SetPosition(position.GetPosition());
  192. camera.SetRotation(position.GetRotation());
  193. // Render Code
  194. Graphics.BeginScene();
  195. // 3D
  196. // View matrix
  197. camera.Render();
  198. //frustum.ConstructFrustum(1000.0f, Graphics.GetProjectionMatrix(), camera.GetViewMatrix());
  199. foreach (Model model in m_Models) {
  200. //if (frustum.CheckSphere(model.Position.X, model.Position.Y, model.Position.Z, 10.0f))
  201. //{
  202. /*Matrix temp = Matrix.Multiply(Graphics.GetWorldMatrix(), Matrix.Scaling(model.Scale, model.Scale, model.Scale));
  203. temp = Matrix.Multiply(temp, Matrix.RotationYawPitchRoll(model.Rotation.X, model.Rotation.Y, model.Rotation.Z));
  204. temp = Matrix.Multiply(temp, Matrix.Translation(model.Position.X, model.Position.Y, model.Position.Z));*/
  205. model.Render(Graphics, camera, (model == SelectedModel)/*Graphics.Context*/);
  206. //lightShader.Render(Graphics.Context, model.GetIndexCount(), temp, camera.GetViewMatrix(), Graphics.GetProjectionMatrix(), model.GetTexture(), new Vector3(0.0f, 0.0f, 0.0f), new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 0.0f, 0.0f), camera.GetPosition(), new Vector4(0.0f, 0.0f, 0.0f, 0.0f), 0.0f);
  207. //}
  208. }
  209. // 2D
  210. Graphics.TurnZBufferOff();
  211. Graphics.TurnOnAlphaBlending();
  212. bmp.Render(Graphics, 10, 10);
  213. text.SetFPS(fps.GetFPS(), Graphics.Context);
  214. text.SetPosition(position.GetPosition(), Graphics.Context);
  215. text.SetSelectedModel(SelectedModel, Graphics.Context);
  216. text.Render(Graphics.Context, Graphics.GetWorldMatrix(), Graphics.GetOrthoMatrix());
  217. Graphics.TurnOffAlphaBlending();
  218. Graphics.TurnZBufferOn();
  219. Graphics.EndScene();
  220. }
  221. });
  222. }
  223. catch (Exception exception) { }
  224. }
  225. public bool TestIntersection(int mouseX, int mouseY) {
  226. float pointX, pointY;
  227. Matrix projectionMatrix, viewMatrix, inverseViewMatrix;
  228. projectionMatrix = Graphics.GetProjectionMatrix();
  229. pointX = (2.0F * (float)mouseX / (float)pGraphics.ClientSize.Width - 1.0f) / projectionMatrix.M11;
  230. pointY = (-2.0f * (float)mouseY / (float)pGraphics.ClientSize.Height + 1.0f) / projectionMatrix.M22;
  231. Ray ray = new Ray(new Vector3(), new Vector3(pointX, pointY, 1.0f));
  232. viewMatrix = camera.GetViewMatrix();
  233. inverseViewMatrix = Matrix.Invert(viewMatrix);
  234. ray = new Ray(Vector3.TransformCoordinate(ray.Position, inverseViewMatrix), Vector3.TransformNormal(ray.Direction, inverseViewMatrix));
  235. ray.Direction.Normalize();
  236. float selectionDistance = 0.0f;
  237. foreach (Model model in m_Models) {
  238. float distance = model.TestIntersection(ray, Graphics);
  239. if (distance > 0.0f && (selectionDistance == 0.0f || distance < selectionDistance)) {
  240. selectionDistance = distance;
  241. SelectedModel = model;
  242. }
  243. }
  244. return false;
  245. }
  246. public static void AppendLoadFile(String txt)
  247. {
  248. StreamWriter sw = File.AppendText("loaded.txt");
  249. sw.WriteLine(txt);
  250. sw.Close();
  251. }
  252. private void loadZoneToolStripMenuItem_Click(object sender, EventArgs e)
  253. {
  254. LoadZoneFile();
  255. }
  256. private void LoadZoneFile(String filename="")
  257. {
  258. bool isDrawFile = false;
  259. string fullName = "";
  260. String dirName = "";
  261. if (filename.Length < 1)
  262. {
  263. OpenFileDialog fd = new OpenFileDialog();
  264. fd.Filter = "lut/draw files (*.lut;*.draw)|*.lut;*.draw|lut files (*.lut)|*.lut|draw files (*.draw)|*.draw";
  265. if (fd.ShowDialog() == DialogResult.OK)
  266. {
  267. AppendLoadFile("===================================================");
  268. AppendLoadFile("Loading " + fd.FileName);
  269. if (fd.FileName.EndsWith(".draw"))
  270. {
  271. isDrawFile = true;
  272. string temp = fd.FileName.Substring(0, fd.FileName.LastIndexOf("\\"));
  273. ZoneFile = fd.SafeFileName.Substring(0, fd.SafeFileName.IndexOf(".draw"));
  274. fullName = ZoneFile;
  275. dirName = temp;
  276. filename = fd.FileName;
  277. }
  278. else
  279. {
  280. string temp = fd.FileName.Substring(0, fd.FileName.IndexOf("zones"));
  281. ZoneFile = fd.SafeFileName.Substring(0, fd.SafeFileName.IndexOf(".lut"));
  282. fullName = ZoneFile;
  283. dirName = temp;
  284. filename = fd.FileName;
  285. }
  286. }
  287. }
  288. else
  289. {
  290. if (filename.EndsWith(".draw"))
  291. {
  292. isDrawFile = true;
  293. string temp = filename.Substring(0, filename.LastIndexOf("\\"));
  294. ZoneFile = filename.Substring(0, filename.IndexOf(".draw"));
  295. fullName = filename;
  296. dirName = temp;
  297. }
  298. else
  299. {
  300. string temp = filename.Substring(0, filename.IndexOf("zones"));
  301. ZoneFile = filename.Substring(0, filename.IndexOf(".lut"));
  302. fullName = filename;
  303. dirName = temp;
  304. }
  305. }
  306. if (isDrawFile)
  307. {
  308. Model tmpModel = new Model();
  309. string[] textures = new string[1];
  310. textures[0] = "goblin_ice.dds";
  311. tmpModel.Initialize(Graphics.Device, filename, textures);
  312. tmpModel.Position.X = 0;
  313. tmpModel.Position.Y = 0;
  314. tmpModel.Position.Z = 0;
  315. tmpModel.Rotation.X = 0;
  316. tmpModel.Rotation.Y = 0;
  317. tmpModel.Rotation.Z = 0;
  318. tmpModel.Scale = 1;
  319. tmpModel.WidgetID = 1;
  320. tmpModel.GridID = 1;
  321. m_Models.Add(tmpModel);
  322. return;
  323. }
  324. if (fullName.Length < 1)
  325. {
  326. MessageBox.Show("No filename provided for loading a zonefile!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  327. return;
  328. }
  329. System.IO.BinaryReader reader2 = new System.IO.BinaryReader(new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read));
  330. // Image(2020): Was ReadUint32, qey_harbor.lut however has 00 1F 00 7A, so that as an int32 is a very large number!
  331. reader2.ReadUInt32();
  332. do
  333. {
  334. if (reader2.BaseStream.Position + 2 >= reader2.BaseStream.Length)
  335. {
  336. break;
  337. }
  338. UInt16 size = reader2.ReadUInt16();
  339. string file = new string(reader2.ReadChars(size));
  340. // was duplicating drive name
  341. file = file.Replace("/", "\\");
  342. file = dirName + file;
  343. AppendLoadFile("VOC Loading: " + file);
  344. Eq2Reader reader = new Eq2Reader(new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read));
  345. VeNode venode = reader.ReadNodeObject();
  346. CheckNode(dirName, venode);
  347. //MessageBox.Show("Done!");
  348. // 16 bytes between file names, grid id's maybe?
  349. reader2.ReadBytes(16);
  350. } while (true);
  351. }
  352. float x, y, z = 0;
  353. float yaw, pitch, roll = 0;
  354. float scale = 0;
  355. UInt32 widgetID;
  356. UInt32 GridID;
  357. bool flipStatus = false;
  358. private void CheckNode(string temp, object item)
  359. {
  360. if (item is VeMeshGeometryNode)
  361. {
  362. widgetID = ((VeNode)item).WidgetID;
  363. // testing antonica spires which are not oriented correctly
  364. if ( widgetID == 2990295910 )
  365. {
  366. int test = 0;
  367. }
  368. Model model = new Model();
  369. model.Initialize(Graphics.Device, (VeMeshGeometryNode)item, temp);
  370. model.Position.X = x;
  371. model.Position.Y = y;
  372. model.Position.Z = z;
  373. model.Rotation.X = yaw;
  374. model.Rotation.Y = pitch;
  375. model.Rotation.Z = roll;
  376. model.Scale = scale;
  377. model.WidgetID = widgetID;
  378. model.GridID = GridID;
  379. m_Models.Add(model);
  380. }
  381. else
  382. {
  383. float x1 = 0.0f;
  384. float y1 = 0.0f;
  385. float z1 = 0.0f;
  386. if (item is VeRoomItemNode)
  387. {
  388. yaw = ((VeRoomItemNode)item).orientation[0];
  389. pitch = ((VeRoomItemNode)item).orientation[1];
  390. roll = ((VeRoomItemNode)item).orientation[2];
  391. GridID = ((VeRoomItemNode)item).myId_grid;
  392. }
  393. else if (item is VeXformNode)
  394. {
  395. VeNode tmp = (VeNode)item;
  396. //resets yaw/pitch/roll to 0,0,0 for next mesh (like antonica spires)
  397. if ( tmp.nodeFlags == 1409875968)
  398. {
  399. if (flipStatus)
  400. flipStatus = false;
  401. else
  402. flipStatus = true;
  403. }
  404. x1 = ((VeXformNode)item).position[0];
  405. y1 = ((VeXformNode)item).position[1];
  406. z1 = ((VeXformNode)item).position[2];
  407. if (flipStatus)
  408. {
  409. yaw = 0;
  410. pitch = 0;
  411. roll = 0;
  412. scale = ((VeXformNode)item).scale;
  413. }
  414. else
  415. {
  416. yaw = (((VeXformNode)item).orientation[0]) * (3.141592654f / 180.0f);
  417. pitch = (((VeXformNode)item).orientation[1]) * (3.141592654f / 180.0f);
  418. roll = (((VeXformNode)item).orientation[2]) * (3.141592654f / 180.0f);
  419. scale = ((VeXformNode)item).scale;
  420. }
  421. x += x1;
  422. y += y1;
  423. z += z1;
  424. }
  425. if (item != null)
  426. {
  427. System.Collections.IEnumerator enumerator = ((VeNode)item).EnumerateChildren();
  428. while (enumerator.MoveNext())
  429. {
  430. CheckNode(temp, enumerator.Current);
  431. }
  432. flipStatus = false;
  433. x -= x1;
  434. y -= y1;
  435. z -= z1;
  436. }
  437. }
  438. }
  439. public static string[] GetTextureFile(string[] spPath, string basePath)
  440. {
  441. string ret = "goblin_ice.dds";
  442. System.Collections.Generic.List<string> strings = new System.Collections.Generic.List<string>();
  443. int i = 0;
  444. while (i < spPath.Length /*&& ret == "goblin_ice.dds"*/)
  445. {
  446. Eq2Reader reader = new Eq2Reader(new System.IO.FileStream(basePath + spPath[i], System.IO.FileMode.Open, System.IO.FileAccess.Read));
  447. VeBase sp = reader.ReadObject();
  448. reader.Close();
  449. if (sp is VeShaderPalette)
  450. {
  451. bool found = false;
  452. for (int s = 0; s < ((VeShaderPalette)sp).shaderNames.Length; s++)
  453. {
  454. String fileName = basePath + ((VeShaderPalette)sp).shaderNames[s];
  455. fileName = fileName.Replace("/", "\\");
  456. System.IO.StreamReader reader2 = new System.IO.StreamReader(fileName);
  457. while (!reader2.EndOfStream)
  458. {
  459. string lineOrig = reader2.ReadLine();
  460. if (lineOrig.Contains("name = \"@tex") && !lineOrig.Contains("Blend") && !lineOrig.Contains("UVSet"))
  461. {
  462. String line = reader2.ReadLine();
  463. while (line.Length < 1)
  464. line = reader2.ReadLine();
  465. line = line.Substring(line.IndexOf('"') + 1);
  466. line = line.Substring(0, line.Length - 1);
  467. ret = basePath + line;
  468. strings.Add(ret);
  469. found = true;
  470. break;
  471. //break;
  472. }
  473. if (found)
  474. break;
  475. }
  476. reader2.Close();
  477. }
  478. }
  479. i++;
  480. }
  481. if (strings.Count == 0)
  482. strings.Add(ret);
  483. return strings.ToArray();
  484. }
  485. private void exportToolStripMenuItem_Click(object sender, EventArgs e)
  486. {
  487. //List<Vector3> MasterVertexList = new List<Vector3>();
  488. Dictionary<UInt32, List<Vector3>> MasterVertexList = new Dictionary<UInt32, List<Vector3>>();
  489. foreach (Model model in m_Models)
  490. {
  491. if (model.WidgetID == 1253219127)
  492. {
  493. int test = 0;
  494. }
  495. List<Vector3> VertexList = model.GetVertices();
  496. UInt32 grid = model.GridID;
  497. if (!MasterVertexList.ContainsKey(grid))
  498. MasterVertexList[grid] = new List<Vector3>();
  499. List<Vector3> convertedVertices = new List<Vector3>();
  500. foreach(Vector3 vect in VertexList)
  501. {
  502. Quaternion rotation = Quaternion.RotationYawPitchRoll(model.Rotation.X, model.Rotation.Y, model.Rotation.Z);
  503. var matrix = Matrix.Identity;
  504. Matrix.RotationQuaternion(ref rotation, out matrix);
  505. Matrix scaled = Matrix.Multiply(matrix, Matrix.Scaling(model.Scale, model.Scale, model.Scale));
  506. Vector3 result = Vector3.Add(Vector3.TransformNormal(vect, scaled), model.Position);
  507. convertedVertices.Add(result);
  508. }
  509. MasterVertexList[grid].AddRange(convertedVertices);
  510. }
  511. float minX = float.NaN;
  512. float minZ = float.NaN;
  513. float maxX = float.NaN;
  514. float maxZ = float.NaN;
  515. foreach (KeyValuePair<UInt32, List<Vector3>> entry in MasterVertexList)
  516. {
  517. foreach (Vector3 v in entry.Value)
  518. {
  519. if (float.IsNaN(minX))
  520. {
  521. minX = v.X;
  522. maxX = v.X;
  523. minZ = v.Z;
  524. maxZ = v.Z;
  525. }
  526. else
  527. {
  528. if (v.X < minX)
  529. minX = v.X;
  530. if (v.X > maxX)
  531. maxX = v.X;
  532. if (v.Z < minZ)
  533. minZ = v.Z;
  534. if (v.Z > maxZ)
  535. maxZ = v.Z;
  536. }
  537. }
  538. }
  539. using (StreamWriter file = new StreamWriter(ZoneFile + ".obj"))
  540. {
  541. // file.WriteLine(ZoneFile);
  542. // file.WriteLine("Min");
  543. // file.WriteLine(minX + " " + minZ);
  544. // file.WriteLine("Max");
  545. // file.WriteLine(maxX + " " + maxZ);
  546. // file.WriteLine("Grid count");
  547. // file.WriteLine(MasterVertexList.Count);
  548. // file.WriteLine();
  549. List<string> indices = new List<string>();
  550. int count = 0;
  551. string buildStr = "";
  552. int curcount = 0;
  553. foreach (KeyValuePair<UInt32, List<Vector3>> entry in MasterVertexList)
  554. {
  555. buildStr = "f ";
  556. // file.WriteLine("Grid");
  557. // file.WriteLine(entry.Key);
  558. // file.WriteLine("Face count");
  559. // file.WriteLine(entry.Value.Count);
  560. foreach (Vector3 v in entry.Value)
  561. {
  562. if (curcount > 2)
  563. {
  564. buildStr += count;
  565. indices.Add(buildStr);
  566. buildStr = "f ";
  567. curcount = 0;
  568. }
  569. else
  570. buildStr += count + " ";
  571. file.WriteLine("v " + v.X.ToString() + " " + v.Y.ToString()
  572. + " " + v.Z.ToString());
  573. count++;
  574. curcount++;
  575. }
  576. }
  577. foreach (string str in indices)
  578. {
  579. file.WriteLine(str);
  580. }
  581. file.Close();
  582. }
  583. using (BinaryWriter file = new BinaryWriter(File.Open(ZoneFile + ".EQ2Map", FileMode.Create)))
  584. {
  585. file.Write(ZoneFile);
  586. file.Write(minX);
  587. file.Write(minZ);
  588. file.Write(maxX);
  589. file.Write(maxZ);
  590. file.Write(MasterVertexList.Count);
  591. foreach (KeyValuePair<UInt32, List<Vector3>> entry in MasterVertexList)
  592. {
  593. file.Write(entry.Key);
  594. file.Write(entry.Value.Count);
  595. foreach (Vector3 v in entry.Value)
  596. {
  597. file.Write(v.X);
  598. file.Write(v.Y);
  599. file.Write(v.Z);
  600. }
  601. }
  602. file.Close();
  603. }
  604. if (sender != null)
  605. MessageBox.Show("Export Complete!");
  606. }
  607. }
  608. }