Main.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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, false);
  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. private void CheckNode(string temp, object item, bool parentXform)
  358. {
  359. if (item is VeMeshGeometryNode)
  360. {
  361. widgetID = ((VeNode)item).WidgetID;
  362. // testing antonica spires which are not oriented correctly
  363. //if ( widgetID == 2990295910 )
  364. // testing tutorial_island02 boat
  365. //if (widgetID == 1253219127)
  366. Model model = new Model();
  367. model.Initialize(Graphics.Device, (VeMeshGeometryNode)item, temp);
  368. model.Position.X = x;
  369. model.Position.Y = y;
  370. model.Position.Z = z;
  371. model.Rotation.X = yaw;
  372. model.Rotation.Y = pitch;
  373. model.Rotation.Z = roll;
  374. model.Scale = scale;
  375. model.WidgetID = widgetID;
  376. model.GridID = GridID;
  377. m_Models.Add(model);
  378. }
  379. else
  380. {
  381. float x1 = 0.0f;
  382. float y1 = 0.0f;
  383. float z1 = 0.0f;
  384. if (item is VeRoomItemNode)
  385. {
  386. yaw = ((VeRoomItemNode)item).orientation[0];
  387. pitch = ((VeRoomItemNode)item).orientation[1];
  388. roll = ((VeRoomItemNode)item).orientation[2];
  389. GridID = ((VeRoomItemNode)item).myId_grid;
  390. }
  391. else if (item is VeXformNode)
  392. {
  393. VeXformNode tmp = (VeXformNode)item;
  394. x1 = ((VeXformNode)item).position[0];
  395. y1 = ((VeXformNode)item).position[1];
  396. z1 = ((VeXformNode)item).position[2];
  397. if (parentXform)
  398. {
  399. yaw += (((VeXformNode)item).orientation[0]) * (3.141592654f / 180.0f);
  400. pitch += (((VeXformNode)item).orientation[1]) * (3.141592654f / 180.0f);
  401. roll += (((VeXformNode)item).orientation[2]) * (3.141592654f / 180.0f);
  402. }
  403. else
  404. {
  405. yaw = (((VeXformNode)item).orientation[0]) * (3.141592654f / 180.0f);
  406. pitch = (((VeXformNode)item).orientation[1]) * (3.141592654f / 180.0f);
  407. roll = (((VeXformNode)item).orientation[2]) * (3.141592654f / 180.0f);
  408. }
  409. scale = ((VeXformNode)item).scale;
  410. x += x1;
  411. y += y1;
  412. z += z1;
  413. }
  414. if (item != null)
  415. {
  416. float old_x = x, old_y = y, old_z = z;
  417. float old_yaw = yaw, old_pitch = pitch, old_roll = roll;
  418. float old_scale = scale;
  419. System.Collections.IEnumerator enumerator = ((VeNode)item).EnumerateChildren();
  420. bool parentBool = item is VeXformNode;
  421. while (enumerator.MoveNext())
  422. {
  423. CheckNode(temp, enumerator.Current, parentBool);
  424. }
  425. x = old_x;
  426. y = old_y;
  427. z = old_z;
  428. yaw = old_yaw;
  429. pitch = old_pitch;
  430. roll = old_roll;
  431. scale = old_scale;
  432. x -= x1;
  433. y -= y1;
  434. z -= z1;
  435. }
  436. }
  437. }
  438. public static string[] GetTextureFile(string[] spPath, string basePath)
  439. {
  440. string ret = "goblin_ice.dds";
  441. System.Collections.Generic.List<string> strings = new System.Collections.Generic.List<string>();
  442. int i = 0;
  443. while (i < spPath.Length /*&& ret == "goblin_ice.dds"*/)
  444. {
  445. Eq2Reader reader = new Eq2Reader(new System.IO.FileStream(basePath + spPath[i], System.IO.FileMode.Open, System.IO.FileAccess.Read));
  446. VeBase sp = reader.ReadObject();
  447. reader.Close();
  448. if (sp is VeShaderPalette)
  449. {
  450. bool found = false;
  451. for (int s = 0; s < ((VeShaderPalette)sp).shaderNames.Length; s++)
  452. {
  453. String fileName = basePath + ((VeShaderPalette)sp).shaderNames[s];
  454. fileName = fileName.Replace("/", "\\");
  455. System.IO.StreamReader reader2 = new System.IO.StreamReader(fileName);
  456. while (!reader2.EndOfStream)
  457. {
  458. string lineOrig = reader2.ReadLine();
  459. if (lineOrig.Contains("name = \"@tex") && !lineOrig.Contains("Blend") && !lineOrig.Contains("UVSet"))
  460. {
  461. String line = reader2.ReadLine();
  462. while (line.Length < 1)
  463. line = reader2.ReadLine();
  464. line = line.Substring(line.IndexOf('"') + 1);
  465. line = line.Substring(0, line.Length - 1);
  466. ret = basePath + line;
  467. strings.Add(ret);
  468. found = true;
  469. break;
  470. //break;
  471. }
  472. if (found)
  473. break;
  474. }
  475. reader2.Close();
  476. }
  477. }
  478. i++;
  479. }
  480. if (strings.Count == 0)
  481. strings.Add(ret);
  482. return strings.ToArray();
  483. }
  484. private void exportToolStripMenuItem_Click(object sender, EventArgs e)
  485. {
  486. //List<Vector3> MasterVertexList = new List<Vector3>();
  487. Dictionary<UInt32, List<Vector3>> MasterVertexList = new Dictionary<UInt32, List<Vector3>>();
  488. foreach (Model model in m_Models)
  489. {
  490. if (model.WidgetID == 1253219127)
  491. {
  492. int test = 0;
  493. }
  494. List<Vector3> VertexList = model.GetVertices();
  495. UInt32 grid = model.GridID;
  496. if (!MasterVertexList.ContainsKey(grid))
  497. MasterVertexList[grid] = new List<Vector3>();
  498. List<Vector3> convertedVertices = new List<Vector3>();
  499. foreach(Vector3 vect in VertexList)
  500. {
  501. Quaternion rotation = Quaternion.RotationYawPitchRoll(model.Rotation.X, model.Rotation.Y, model.Rotation.Z);
  502. var matrix = Matrix.Identity;
  503. Matrix.RotationQuaternion(ref rotation, out matrix);
  504. Matrix scaled = Matrix.Multiply(matrix, Matrix.Scaling(model.Scale, model.Scale, model.Scale));
  505. Vector3 result = Vector3.Add(Vector3.TransformNormal(vect, scaled), model.Position);
  506. convertedVertices.Add(result);
  507. }
  508. MasterVertexList[grid].AddRange(convertedVertices);
  509. }
  510. float minX = float.NaN;
  511. float minZ = float.NaN;
  512. float maxX = float.NaN;
  513. float maxZ = float.NaN;
  514. foreach (KeyValuePair<UInt32, List<Vector3>> entry in MasterVertexList)
  515. {
  516. foreach (Vector3 v in entry.Value)
  517. {
  518. if (float.IsNaN(minX))
  519. {
  520. minX = v.X;
  521. maxX = v.X;
  522. minZ = v.Z;
  523. maxZ = v.Z;
  524. }
  525. else
  526. {
  527. if (v.X < minX)
  528. minX = v.X;
  529. if (v.X > maxX)
  530. maxX = v.X;
  531. if (v.Z < minZ)
  532. minZ = v.Z;
  533. if (v.Z > maxZ)
  534. maxZ = v.Z;
  535. }
  536. }
  537. }
  538. using (StreamWriter file = new StreamWriter(ZoneFile + ".obj"))
  539. {
  540. // file.WriteLine(ZoneFile);
  541. // file.WriteLine("Min");
  542. // file.WriteLine(minX + " " + minZ);
  543. // file.WriteLine("Max");
  544. // file.WriteLine(maxX + " " + maxZ);
  545. // file.WriteLine("Grid count");
  546. // file.WriteLine(MasterVertexList.Count);
  547. // file.WriteLine();
  548. List<string> indices = new List<string>();
  549. int count = 0;
  550. string buildStr = "";
  551. int curcount = 0;
  552. foreach (KeyValuePair<UInt32, List<Vector3>> entry in MasterVertexList)
  553. {
  554. buildStr = "f ";
  555. // file.WriteLine("Grid");
  556. // file.WriteLine(entry.Key);
  557. // file.WriteLine("Face count");
  558. // file.WriteLine(entry.Value.Count);
  559. foreach (Vector3 v in entry.Value)
  560. {
  561. if (curcount > 2)
  562. {
  563. buildStr += count;
  564. indices.Add(buildStr);
  565. buildStr = "f ";
  566. curcount = 0;
  567. }
  568. else
  569. buildStr += count + " ";
  570. file.WriteLine("v " + v.X.ToString() + " " + v.Y.ToString()
  571. + " " + v.Z.ToString());
  572. count++;
  573. curcount++;
  574. }
  575. }
  576. foreach (string str in indices)
  577. {
  578. file.WriteLine(str);
  579. }
  580. file.Close();
  581. }
  582. using (BinaryWriter file = new BinaryWriter(File.Open(ZoneFile + ".EQ2Map", FileMode.Create)))
  583. {
  584. file.Write(ZoneFile);
  585. file.Write(minX);
  586. file.Write(minZ);
  587. file.Write(maxX);
  588. file.Write(maxZ);
  589. file.Write(MasterVertexList.Count);
  590. foreach (KeyValuePair<UInt32, List<Vector3>> entry in MasterVertexList)
  591. {
  592. file.Write(entry.Key);
  593. file.Write(entry.Value.Count);
  594. foreach (Vector3 v in entry.Value)
  595. {
  596. file.Write(v.X);
  597. file.Write(v.Y);
  598. file.Write(v.Z);
  599. }
  600. }
  601. file.Close();
  602. }
  603. if (sender != null)
  604. MessageBox.Show("Export Complete!");
  605. }
  606. }
  607. }