Torque3D/Engine/source/navigation/navMeshTools/tileTool.cpp
marauder2k7 d1771756c2 updated drawmodes and rendering
DebugDraw for recast now caches the results
We now have a drawmode dropdown selector
drawmode changes come from the gui itself no longer from console values
all recast drawmodes are supported with the exception of drawmodes that add abilities like navqueries until the nav tester tool is imlpemented.
2025-07-24 14:25:02 +01:00

119 lines
2.6 KiB
C++

#include "tileTool.h"
#include "navigation/guiNavEditorCtrl.h"
#include "console/consoleTypes.h"
#include "gfx/gfxDrawUtil.h"
#include "scene/sceneManager.h"
#include "math/mathUtils.h"
IMPLEMENT_CONOBJECT(TileTool);
static void renderBoxOutline(const Box3F& box, const ColorI& col)
{
if (box != Box3F::Invalid)
{
GFXStateBlockDesc desc;
desc.setCullMode(GFXCullNone);
desc.setFillModeSolid();
desc.setZReadWrite(true, false);
desc.setBlend(true);
GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 20));
desc.setFillModeWireframe();
desc.setBlend(false);
GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 255));
}
}
void TileTool::onActivated(const Gui3DMouseEvent& lastEvent)
{
Con::executef(this, "onActivated");
}
void TileTool::onDeactivated()
{
Con::executef(this, "onDeactivated");
}
void TileTool::on3DMouseDown(const Gui3DMouseEvent& evt)
{
if (mNavMesh.isNull())
return;
Point3F start = evt.pos;
Point3F end = evt.pos + evt.vec * 1000.0f;
RayInfo ri;
if (gServerContainer.castRay(start, end, StaticObjectType, &ri))
{
mSelTile = mNavMesh->getTile(ri.point);
}
}
void TileTool::on3DMouseMove(const Gui3DMouseEvent& evt)
{
if (mNavMesh.isNull())
return;
Point3F startPnt = evt.pos;
Point3F endPnt = evt.pos + evt.vec * 1000.0f;
RayInfo ri;
if (gServerContainer.castRay(startPnt, endPnt, StaticObjectType, &ri))
mCurTile = mNavMesh->getTile(ri.point);
else
mCurTile = -1;
}
void TileTool::onRender3D()
{
if (mNavMesh.isNull())
return;
// Optional: Draw all tile bounds as overlays
//mNavMesh->renderTilesOverlay(DebugDraw::get()->getDD());
if(mCurTile != -1)
renderBoxOutline(mNavMesh->getTileBox(mCurTile), ColorI::BLUE);
if(mSelTile != -1)
renderBoxOutline(mNavMesh->getTileBox(mSelTile), ColorI::GREEN);
}
void TileTool::buildTile()
{
if (!mNavMesh.isNull() && mSelTile != -1)
mNavMesh->buildTile(mSelTile);
}
bool TileTool::updateGuiInfo()
{
GuiTextCtrl* statusbar;
Sim::findObject("EWorldEditorStatusBarInfo", statusbar);
GuiTextCtrl* selectionBar;
Sim::findObject("EWorldEditorStatusBarSelection", selectionBar);
String text;
text = "LMB To select NavMesh Tile";
if (statusbar)
statusbar->setText(text);
if (mSelTile != -1)
text = String::ToString("Selected Tile: %d", mSelTile);
else
text = "";
if (selectionBar)
selectionBar->setText(text);
return true;
}
DefineEngineMethod(TileTool, buildTile, void, (), ,
"@brief Build the currently selected tile.")
{
return object->buildTile();
}