tileTool.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "TileTool.h"
  2. #include "navigation/guiNavEditorCtrl.h"
  3. #include "console/consoleTypes.h"
  4. #include "gfx/gfxDrawUtil.h"
  5. #include "scene/sceneManager.h"
  6. #include "math/mathUtils.h"
  7. IMPLEMENT_CONOBJECT(TileTool);
  8. static void renderBoxOutline(const Box3F& box, const ColorI& col)
  9. {
  10. if (box != Box3F::Invalid)
  11. {
  12. GFXStateBlockDesc desc;
  13. desc.setCullMode(GFXCullNone);
  14. desc.setFillModeSolid();
  15. desc.setZReadWrite(true, false);
  16. desc.setBlend(true);
  17. GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 20));
  18. desc.setFillModeWireframe();
  19. desc.setBlend(false);
  20. GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 255));
  21. }
  22. }
  23. void TileTool::onActivated(const Gui3DMouseEvent& lastEvent)
  24. {
  25. Con::executef(this, "onActivated");
  26. }
  27. void TileTool::onDeactivated()
  28. {
  29. Con::executef(this, "onDeactivated");
  30. }
  31. void TileTool::on3DMouseDown(const Gui3DMouseEvent& evt)
  32. {
  33. if (mNavMesh.isNull())
  34. return;
  35. Point3F start = evt.pos;
  36. Point3F end = evt.pos + evt.vec * 1000.0f;
  37. RayInfo ri;
  38. if (gServerContainer.castRay(start, end, StaticObjectType, &ri))
  39. {
  40. mSelTile = mNavMesh->getTile(ri.point);
  41. if (mSelTile != -1)
  42. {
  43. mNavMesh->renderTileData(mNavMesh->mDbgDraw, mSelTile);
  44. //mNavMesh->buildTile(tile); // Immediate rebuild
  45. }
  46. }
  47. }
  48. void TileTool::on3DMouseMove(const Gui3DMouseEvent& evt)
  49. {
  50. if (mNavMesh.isNull())
  51. return;
  52. Point3F startPnt = evt.pos;
  53. Point3F endPnt = evt.pos + evt.vec * 1000.0f;
  54. RayInfo ri;
  55. if (gServerContainer.castRay(startPnt, endPnt, StaticObjectType, &ri))
  56. mCurTile = mNavMesh->getTile(ri.point);
  57. else
  58. mCurTile = -1;
  59. }
  60. void TileTool::onRender3D()
  61. {
  62. if (mNavMesh.isNull())
  63. return;
  64. // Optional: Draw all tile bounds as overlays
  65. //mNavMesh->renderTilesOverlay(DebugDraw::get()->getDD());
  66. if(mCurTile != -1)
  67. renderBoxOutline(mNavMesh->getTileBox(mCurTile), ColorI::BLUE);
  68. if(mSelTile != -1)
  69. renderBoxOutline(mNavMesh->getTileBox(mSelTile), ColorI::GREEN);
  70. }
  71. void TileTool::buildTile()
  72. {
  73. if (!mNavMesh.isNull() && mSelTile != -1)
  74. mNavMesh->buildTile(mSelTile);
  75. }
  76. bool TileTool::updateGuiInfo()
  77. {
  78. GuiTextCtrl* statusbar;
  79. Sim::findObject("EWorldEditorStatusBarInfo", statusbar);
  80. GuiTextCtrl* selectionBar;
  81. Sim::findObject("EWorldEditorStatusBarSelection", selectionBar);
  82. String text;
  83. text = "LMB To select NavMesh Tile";
  84. if (statusbar)
  85. statusbar->setText(text);
  86. if (mSelTile != -1)
  87. text = String::ToString("Selected Tile: %d", mSelTile);
  88. else
  89. text = "";
  90. if (selectionBar)
  91. selectionBar->setText(text);
  92. return true;
  93. }
  94. DefineEngineMethod(TileTool, buildTile, void, (), ,
  95. "@brief Build the currently selected tile.")
  96. {
  97. return object->buildTile();
  98. }