navMeshSelectTool.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "navMeshSelectTool.h"
  2. #include "console/consoleTypes.h"
  3. #include "gfx/gfxDrawUtil.h"
  4. IMPLEMENT_CONOBJECT(NavMeshSelectTool);
  5. static void renderBoxOutline(const Box3F& box, const ColorI& col)
  6. {
  7. if (box != Box3F::Invalid)
  8. {
  9. GFXStateBlockDesc desc;
  10. desc.setCullMode(GFXCullNone);
  11. desc.setFillModeSolid();
  12. desc.setZReadWrite(true, false);
  13. desc.setBlend(true);
  14. GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 20));
  15. desc.setFillModeWireframe();
  16. desc.setBlend(false);
  17. GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 255));
  18. }
  19. }
  20. NavMeshSelectTool::NavMeshSelectTool()
  21. {
  22. mCurMesh = NULL;
  23. }
  24. void NavMeshSelectTool::onActivated(const Gui3DMouseEvent& evt)
  25. {
  26. Con::executef(this, "onActivated");
  27. }
  28. void NavMeshSelectTool::onDeactivated()
  29. {
  30. Con::executef(this, "onDeactivated");
  31. }
  32. void NavMeshSelectTool::on3DMouseDown(const Gui3DMouseEvent& evt)
  33. {
  34. if (mCurEditor.isNull())
  35. return;
  36. Point3F startPnt = evt.pos;
  37. Point3F endPnt = evt.pos + evt.vec * 1000.0f;
  38. RayInfo ri;
  39. if (gServerContainer.collideBox(startPnt, endPnt, MarkerObjectType, &ri))
  40. {
  41. if (!ri.object)
  42. return;
  43. NavMesh* selNavMesh = dynamic_cast<NavMesh*>(ri.object);
  44. if (selNavMesh)
  45. {
  46. mCurEditor->selectMesh(selNavMesh);
  47. mSelMesh = selNavMesh;
  48. Con::executef(this, "onNavMeshSelected");
  49. return;
  50. }
  51. }
  52. }
  53. void NavMeshSelectTool::on3DMouseMove(const Gui3DMouseEvent& evt)
  54. {
  55. if (mCurEditor.isNull())
  56. return;
  57. Point3F startPnt = evt.pos;
  58. Point3F endPnt = evt.pos + evt.vec * 1000.0f;
  59. RayInfo ri;
  60. if (gServerContainer.collideBox(startPnt, endPnt, MarkerObjectType, &ri))
  61. {
  62. NavMesh* selNavMesh = dynamic_cast<NavMesh*>(ri.object);
  63. if (selNavMesh)
  64. {
  65. mCurMesh = selNavMesh;
  66. }
  67. else
  68. {
  69. mCurMesh = NULL;
  70. }
  71. }
  72. else
  73. {
  74. mCurMesh = NULL;
  75. }
  76. }
  77. void NavMeshSelectTool::onRender3D()
  78. {
  79. if (!mCurMesh.isNull())
  80. renderBoxOutline(mCurMesh->getWorldBox(), ColorI::LIGHT);
  81. if (!mSelMesh.isNull())
  82. renderBoxOutline(mSelMesh->getWorldBox(), ColorI::LIGHT);
  83. }
  84. bool NavMeshSelectTool::updateGuiInfo()
  85. {
  86. SimObject* statusbar;
  87. Sim::findObject("EditorGuiStatusBar", statusbar);
  88. GuiTextCtrl* selectionBar;
  89. Sim::findObject("EWorldEditorStatusBarSelection", selectionBar);
  90. String text;
  91. text = "LMB To select a NavMesh.";
  92. if (statusbar)
  93. Con::executef(statusbar, "setInfo", text.c_str());
  94. text = "";
  95. if(mSelMesh)
  96. text = String::ToString("NavMesh Selected: %d", mSelMesh->getId());
  97. if (selectionBar)
  98. selectionBar->setText(text);
  99. return true;
  100. }