mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
add radius controls
update the scripts for the offmeshcontool radius controlled by slider ctrl
This commit is contained in:
parent
a0b4b8627f
commit
496e427d76
|
|
@ -405,7 +405,7 @@ void NavMesh::setScale(const VectorF &scale)
|
|||
Parent::setScale(scale);
|
||||
}
|
||||
|
||||
S32 NavMesh::addLink(const Point3F &from, const Point3F &to, bool biDir, U32 flags)
|
||||
S32 NavMesh::addLink(const Point3F &from, const Point3F &to, bool biDir, F32 rad, U32 flags)
|
||||
{
|
||||
Point3F rcFrom = DTStoRC(from), rcTo = DTStoRC(to);
|
||||
mLinkVerts.push_back(rcFrom.x);
|
||||
|
|
@ -415,7 +415,7 @@ S32 NavMesh::addLink(const Point3F &from, const Point3F &to, bool biDir, U32 fla
|
|||
mLinkVerts.push_back(rcTo.y);
|
||||
mLinkVerts.push_back(rcTo.z);
|
||||
mLinksUnsynced.push_back(true);
|
||||
mLinkRads.push_back(mWalkableRadius);
|
||||
mLinkRads.push_back(rad);
|
||||
mLinkDirs.push_back(biDir ? 1 : 0);
|
||||
mLinkAreas.push_back(OffMeshArea);
|
||||
if (flags == 0) {
|
||||
|
|
@ -490,6 +490,14 @@ bool NavMesh::getLinkDir(U32 idx)
|
|||
}
|
||||
}
|
||||
|
||||
F32 NavMesh::getLinkRadius(U32 idx)
|
||||
{
|
||||
if (idx < mLinkIDs.size())
|
||||
{
|
||||
return mLinkRads[idx];
|
||||
}
|
||||
}
|
||||
|
||||
void NavMesh::setLinkDir(U32 idx, bool biDir)
|
||||
{
|
||||
if (idx < mLinkIDs.size())
|
||||
|
|
@ -499,6 +507,14 @@ void NavMesh::setLinkDir(U32 idx, bool biDir)
|
|||
}
|
||||
}
|
||||
|
||||
void NavMesh::setLinkRadius(U32 idx, F32 rad)
|
||||
{
|
||||
if (idx < mLinkIDs.size())
|
||||
{
|
||||
mLinkRads[idx] = rad;
|
||||
}
|
||||
}
|
||||
|
||||
DefineEngineMethod(NavMesh, getLinkFlags, S32, (U32 id),,
|
||||
"Get the flags set for a particular off-mesh link.")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ public:
|
|||
/// @{
|
||||
|
||||
/// Add an off-mesh link.
|
||||
S32 addLink(const Point3F &from, const Point3F &to, bool biDir, U32 flags = 0);
|
||||
S32 addLink(const Point3F &from, const Point3F &to, bool biDir, F32 rad, U32 flags = 0);
|
||||
|
||||
/// Get the ID of the off-mesh link near the point.
|
||||
S32 getLink(const Point3F &pos);
|
||||
|
|
@ -170,8 +170,12 @@ public:
|
|||
|
||||
bool getLinkDir(U32 idx);
|
||||
|
||||
F32 getLinkRadius(U32 idx);
|
||||
|
||||
void setLinkDir(U32 idx, bool biDir);
|
||||
|
||||
void setLinkRadius(U32 idx, F32 rad);
|
||||
|
||||
/// Set flags used by a link.
|
||||
void setLinkFlags(U32 idx, const LinkData &d);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ void OffMeshConnectionTool::on3DMouseDown(const Gui3DMouseEvent& evt)
|
|||
{
|
||||
LinkData d = mNavMesh->getLinkFlags(mLink);
|
||||
bool biDir = mNavMesh->getLinkDir(mLink);
|
||||
Con::executef(this, "onLinkSelected", Con::getIntArg(d.getFlags()), Con::getBoolArg(biDir));
|
||||
F32 linkRad = mNavMesh->getLinkRadius(mLink);
|
||||
Con::executef(this, "onLinkSelected", Con::getIntArg(d.getFlags()), Con::getBoolArg(biDir), Con::getFloatArg(linkRad));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -65,7 +66,7 @@ void OffMeshConnectionTool::on3DMouseDown(const Gui3DMouseEvent& evt)
|
|||
|
||||
if (mLinkStart != Point3F::Max)
|
||||
{
|
||||
mLink = mNavMesh->addLink(mLinkStart, ri.point, mBiDir);
|
||||
mLink = mNavMesh->addLink(mLinkStart, ri.point, mBiDir, mLinkRadius);
|
||||
mNavMesh->selectLink(mLink, true, false);
|
||||
|
||||
if (shift)
|
||||
|
|
@ -73,7 +74,7 @@ void OffMeshConnectionTool::on3DMouseDown(const Gui3DMouseEvent& evt)
|
|||
else
|
||||
mLinkStart = Point3F::Max;
|
||||
|
||||
Con::executef(this, "onLinkSelected", Con::getIntArg(mLinkCache.getFlags()), Con::getBoolArg(mBiDir));
|
||||
Con::executef(this, "onLinkSelected", Con::getIntArg(mLinkCache.getFlags()), Con::getBoolArg(mBiDir), Con::getFloatArg(mLinkRadius));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -141,7 +142,7 @@ void OffMeshConnectionTool::onRender3D()
|
|||
Point3F rcFrom = DTStoRC(mLinkStart);
|
||||
dd.begin(DU_DRAW_LINES);
|
||||
dd.depthMask(false);
|
||||
duAppendCircle(&dd, rcFrom.x, rcFrom.y, rcFrom.z, mNavMesh->mWalkableRadius, duRGBA(0, 255, 0, 255));
|
||||
duAppendCircle(&dd, rcFrom.x, rcFrom.y, rcFrom.z, mLinkRadius, duRGBA(0, 255, 0, 255));
|
||||
dd.end();
|
||||
}
|
||||
|
||||
|
|
@ -178,20 +179,22 @@ bool OffMeshConnectionTool::updateGuiInfo()
|
|||
return true;
|
||||
}
|
||||
|
||||
void OffMeshConnectionTool::setLinkProperties(const LinkData& d, bool biDir)
|
||||
void OffMeshConnectionTool::setLinkProperties(const LinkData& d, bool biDir, F32 rad)
|
||||
{
|
||||
if (!mNavMesh.isNull() && mLink != -1)
|
||||
{
|
||||
mNavMesh->setLinkFlags(mLink, d);
|
||||
mNavMesh->setLinkDir(mLink, biDir);
|
||||
mNavMesh->setLinkRadius(mLink, rad);
|
||||
}
|
||||
|
||||
mLinkCache = d;
|
||||
mBiDir = biDir;
|
||||
mLinkRadius = rad;
|
||||
}
|
||||
|
||||
DefineEngineMethod(OffMeshConnectionTool, setLinkProperties, void, (U32 flags, bool biDir), ,
|
||||
DefineEngineMethod(OffMeshConnectionTool, setLinkProperties, void, (U32 flags, bool biDir, F32 rad), ,
|
||||
"@Brief Set properties of the selected link.")
|
||||
{
|
||||
object->setLinkProperties(LinkData(flags), biDir);
|
||||
object->setLinkProperties(LinkData(flags), biDir, rad);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class OffMeshConnectionTool : public NavMeshTool
|
|||
S32 mCurLink;
|
||||
Point3F mLinkStart;
|
||||
LinkData mLinkCache;
|
||||
F32 mLinkRadius;
|
||||
public:
|
||||
|
||||
DECLARE_CONOBJECT(OffMeshConnectionTool);
|
||||
|
|
@ -26,9 +27,17 @@ public:
|
|||
mCurLink = -1;
|
||||
mLinkStart = Point3F::Max;
|
||||
mLinkCache = LinkData(0);
|
||||
mLinkRadius = 1.0;
|
||||
}
|
||||
virtual ~OffMeshConnectionTool() {}
|
||||
|
||||
void setActiveNavMesh(NavMesh* nav_mesh) override {
|
||||
mNavMesh = nav_mesh;
|
||||
|
||||
if (!mNavMesh.isNull())
|
||||
mLinkRadius = mNavMesh->mWalkableRadius;
|
||||
}
|
||||
|
||||
void onActivated(const Gui3DMouseEvent& evt) override;
|
||||
void onDeactivated() override;
|
||||
|
||||
|
|
@ -38,7 +47,7 @@ public:
|
|||
|
||||
bool updateGuiInfo() override;
|
||||
|
||||
void setLinkProperties(const LinkData& d, bool biDir);
|
||||
void setLinkProperties(const LinkData& d, bool biDir, F32 rad);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -573,7 +573,44 @@ $guiContent = new GuiNavEditorCtrl(NavEditorGui, EditorGuiGroup) {
|
|||
position = "7 21";
|
||||
extent = "186 64";
|
||||
padding = "2 2 2 2";
|
||||
|
||||
new GuiTextEditSliderCtrl() {
|
||||
internalName = "LinkRadius";
|
||||
class = "NavMeshLinkRadius";
|
||||
extent = "50 15";
|
||||
format = "%3.2f";
|
||||
range = "0 1e+03";
|
||||
increment = "0.1";
|
||||
focusOnMouseWheel = "0";
|
||||
historySize = "0";
|
||||
password = "0";
|
||||
tabComplete = "0";
|
||||
sinkAllKeyEvents = "0";
|
||||
profile = "ToolsGuiCheckBoxProfile";
|
||||
tooltipProfile = "GuiToolTipProfile";
|
||||
toolTip = "The radius for this link.";
|
||||
AltCommand = "NavMeshTools->LinkTool.updateRadius();";
|
||||
};
|
||||
new GuiCheckBoxCtrl() {
|
||||
internalName = "LinkBiDirection";
|
||||
class = "NavMeshLinkBiDirection";
|
||||
text = " Link Bi-Directional";
|
||||
buttonType = "ToggleButton";
|
||||
useMouseEvents = "0";
|
||||
extent = "159 15";
|
||||
minExtent = "8 2";
|
||||
horizSizing = "right";
|
||||
vertSizing = "bottom";
|
||||
profile = "ToolsGuiCheckBoxProfile";
|
||||
visible = "1";
|
||||
active = "0";
|
||||
tooltipProfile = "GuiToolTipProfile";
|
||||
toolTip = "This link is bidirectional.";
|
||||
hovertime = "1000";
|
||||
isContainer = "0";
|
||||
canSave = "1";
|
||||
canSaveDynamicFields = "0";
|
||||
};
|
||||
|
||||
new GuiCheckBoxCtrl() {
|
||||
internalName = "LinkWalkFlag";
|
||||
class = "NavMeshLinkFlagButton";
|
||||
|
|
|
|||
|
|
@ -59,6 +59,13 @@ function initializeNavEditor()
|
|||
|
||||
new SimSet(NavMeshTools)
|
||||
{
|
||||
new OffMeshConnectionTool()
|
||||
{
|
||||
internalName = "LinkTool";
|
||||
toolTip = "Link tool";
|
||||
buttonImage = "ToolsModule:nav_link_n_image";
|
||||
};
|
||||
|
||||
new TileTool()
|
||||
{
|
||||
internalName = "TileTool";
|
||||
|
|
@ -130,7 +137,7 @@ function EditorGui::SetNavPalletBar()
|
|||
//Adds a button to the pallete stack
|
||||
//Name Icon Click Command Tooltip text Keybind
|
||||
EWToolsPaletteWindow.addButton("ViewNavMesh", "ToolsModule:visibility_toggle_n_image", "NavEditorGui.prepSelectionMode();", "", "View NavMesh", "1");
|
||||
// EWToolsPaletteWindow.addButton("LinkMode", "ToolsModule:nav_link_n_image", "NavEditorGui.setMode(\"LinkMode\");", "", "Create off-mesh links", "2");
|
||||
EWToolsPaletteWindow.addButton("LinkMode", "ToolsModule:nav_link_n_image", "NavEditorGui.setActiveTool(NavMeshTools->LinkTool);", "", "Create off-mesh links", "2");
|
||||
// EWToolsPaletteWindow.addButton("CoverMode", "ToolsModule:nav_cover_n_image", "NavEditorGui.setMode(\"CoverMode\");", "","Edit cover", "3");
|
||||
// EWToolsPaletteWindow.addButton("TileMode", "ToolsModule:select_bounds_n_image", "NavEditorGui.setMode(\"TileMode\");", "", "View tiles", "4");
|
||||
// EWToolsPaletteWindow.addButton("TestMode", "ToolsModule:3rd_person_camera_n_image", "NavEditorGui.setMode(\"TestMode\");", "", "Test pathfinding", "5");
|
||||
|
|
|
|||
|
|
@ -298,6 +298,119 @@ function NavEditorGui::showSidePanel()
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function OffMeshConnectionTool::onActivated(%this)
|
||||
{
|
||||
NavInspector.setVisible(false);
|
||||
|
||||
%actions = NavEditorOptionsWindow->ActionsBox;
|
||||
%actions->SelectActions.setVisible(false);
|
||||
%actions->LinkActions.setVisible(false);
|
||||
%actions->CoverActions.setVisible(false);
|
||||
%actions->TileActions.setVisible(false);
|
||||
%actions->TestActions.setVisible(false);
|
||||
|
||||
%properties = NavEditorOptionsWindow->PropertiesBox;
|
||||
%properties->LinkProperties.setVisible(false);
|
||||
%properties->TileProperties.setVisible(false);
|
||||
%properties->TestProperties.setVisible(false);
|
||||
|
||||
%actions->LinkActions.setVisible(true);
|
||||
%properties->LinkProperties.setVisible(true);
|
||||
}
|
||||
|
||||
function OffMeshConnectionTool::onDeactivated(%this)
|
||||
{
|
||||
NavInspector.setVisible(false);
|
||||
|
||||
%actions = NavEditorOptionsWindow->ActionsBox;
|
||||
%actions->SelectActions.setVisible(false);
|
||||
%actions->LinkActions.setVisible(false);
|
||||
%actions->CoverActions.setVisible(false);
|
||||
%actions->TileActions.setVisible(false);
|
||||
%actions->TestActions.setVisible(false);
|
||||
|
||||
%properties = NavEditorOptionsWindow->PropertiesBox;
|
||||
%properties->LinkProperties.setVisible(false);
|
||||
%properties->TileProperties.setVisible(false);
|
||||
%properties->TestProperties.setVisible(false);
|
||||
}
|
||||
|
||||
function OffMeshConnectionTool::updateLinkFlags(%this)
|
||||
{
|
||||
%properties = NavEditorOptionsWindow-->LinkProperties;
|
||||
%this.setLinkProperties(getLinkFlags(%properties), %properties->LinkBiDirection.isStateOn(), %properties->LinkRadius.getValue());
|
||||
}
|
||||
|
||||
function updateLinkData(%control, %flags, %biDir, %radius)
|
||||
{
|
||||
%control->LinkRadius.setActive(true);
|
||||
%control->LinkBiDirection.setActive(true);
|
||||
%control->LinkWalkFlag.setActive(true);
|
||||
%control->LinkJumpFlag.setActive(true);
|
||||
%control->LinkDropFlag.setActive(true);
|
||||
%control->LinkLedgeFlag.setActive(true);
|
||||
%control->LinkClimbFlag.setActive(true);
|
||||
%control->LinkTeleportFlag.setActive(true);
|
||||
|
||||
%control->LinkRadius.setValue(%radius);
|
||||
%control->LinkBiDirection.setStateOn(%biDir);
|
||||
%control->LinkWalkFlag.setStateOn(%flags & $Nav::WalkFlag);
|
||||
%control->LinkJumpFlag.setStateOn(%flags & $Nav::JumpFlag);
|
||||
%control->LinkDropFlag.setStateOn(%flags & $Nav::DropFlag);
|
||||
%control->LinkLedgeFlag.setStateOn(%flags & $Nav::LedgeFlag);
|
||||
%control->LinkClimbFlag.setStateOn(%flags & $Nav::ClimbFlag);
|
||||
%control->LinkTeleportFlag.setStateOn(%flags & $Nav::TeleportFlag);
|
||||
}
|
||||
|
||||
function getLinkFlags(%control)
|
||||
{
|
||||
return (%control->LinkWalkFlag.isStateOn() ? $Nav::WalkFlag : 0) |
|
||||
(%control->LinkJumpFlag.isStateOn() ? $Nav::JumpFlag : 0) |
|
||||
(%control->LinkDropFlag.isStateOn() ? $Nav::DropFlag : 0) |
|
||||
(%control->LinkLedgeFlag.isStateOn() ? $Nav::LedgeFlag : 0) |
|
||||
(%control->LinkClimbFlag.isStateOn() ? $Nav::ClimbFlag : 0) |
|
||||
(%control->LinkTeleportFlag.isStateOn() ? $Nav::TeleportFlag : 0);
|
||||
}
|
||||
|
||||
function disableLinkData(%control)
|
||||
{
|
||||
%control->LinkRadius.setActive(false);
|
||||
%control->LinkBiDirection.setActive(false);
|
||||
%control->LinkWalkFlag.setActive(false);
|
||||
%control->LinkJumpFlag.setActive(false);
|
||||
%control->LinkDropFlag.setActive(false);
|
||||
%control->LinkLedgeFlag.setActive(false);
|
||||
%control->LinkClimbFlag.setActive(false);
|
||||
%control->LinkTeleportFlag.setActive(false);
|
||||
}
|
||||
|
||||
function OffMeshConnectionTool::onLinkSelected(%this, %flags, %biDir, %radius)
|
||||
{
|
||||
updateLinkData(NavEditorOptionsWindow-->LinkProperties, %flags, %biDir, %radius);
|
||||
}
|
||||
|
||||
function OffMeshConnectionTool::onLinkDeselected(%this)
|
||||
{
|
||||
disableLinkData(NavEditorOptionsWindow-->LinkProperties);
|
||||
}
|
||||
|
||||
function OffMeshConnectionTool::updateRadius(%this)
|
||||
{
|
||||
%this.updateLinkFlags();
|
||||
}
|
||||
|
||||
function NavMeshLinkFlagButton::onClick(%this)
|
||||
{
|
||||
NavMeshTools->LinkTool.updateLinkFlags();
|
||||
}
|
||||
|
||||
function NavMeshLinkBiDirection::onClick(%this)
|
||||
{
|
||||
NavMeshTools->LinkTool.updateLinkFlags();
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
function TileTool::onActivated(%this)
|
||||
{
|
||||
NavInspector.setVisible(false);
|
||||
|
|
@ -335,6 +448,7 @@ function TileTool::onDeactivated(%this)
|
|||
%properties->TestProperties.setVisible(false);
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
function NavEditorGui::onModeSet(%this, %mode)
|
||||
{
|
||||
|
|
@ -453,43 +567,6 @@ function NavEditorGui::buildLinks(%this)
|
|||
}
|
||||
}
|
||||
|
||||
function updateLinkData(%control, %flags)
|
||||
{
|
||||
%control->LinkWalkFlag.setActive(true);
|
||||
%control->LinkJumpFlag.setActive(true);
|
||||
%control->LinkDropFlag.setActive(true);
|
||||
%control->LinkLedgeFlag.setActive(true);
|
||||
%control->LinkClimbFlag.setActive(true);
|
||||
%control->LinkTeleportFlag.setActive(true);
|
||||
|
||||
%control->LinkWalkFlag.setStateOn(%flags & $Nav::WalkFlag);
|
||||
%control->LinkJumpFlag.setStateOn(%flags & $Nav::JumpFlag);
|
||||
%control->LinkDropFlag.setStateOn(%flags & $Nav::DropFlag);
|
||||
%control->LinkLedgeFlag.setStateOn(%flags & $Nav::LedgeFlag);
|
||||
%control->LinkClimbFlag.setStateOn(%flags & $Nav::ClimbFlag);
|
||||
%control->LinkTeleportFlag.setStateOn(%flags & $Nav::TeleportFlag);
|
||||
}
|
||||
|
||||
function getLinkFlags(%control)
|
||||
{
|
||||
return (%control->LinkWalkFlag.isStateOn() ? $Nav::WalkFlag : 0) |
|
||||
(%control->LinkJumpFlag.isStateOn() ? $Nav::JumpFlag : 0) |
|
||||
(%control->LinkDropFlag.isStateOn() ? $Nav::DropFlag : 0) |
|
||||
(%control->LinkLedgeFlag.isStateOn() ? $Nav::LedgeFlag : 0) |
|
||||
(%control->LinkClimbFlag.isStateOn() ? $Nav::ClimbFlag : 0) |
|
||||
(%control->LinkTeleportFlag.isStateOn() ? $Nav::TeleportFlag : 0);
|
||||
}
|
||||
|
||||
function disableLinkData(%control)
|
||||
{
|
||||
%control->LinkWalkFlag.setActive(false);
|
||||
%control->LinkJumpFlag.setActive(false);
|
||||
%control->LinkDropFlag.setActive(false);
|
||||
%control->LinkLedgeFlag.setActive(false);
|
||||
%control->LinkClimbFlag.setActive(false);
|
||||
%control->LinkTeleportFlag.setActive(false);
|
||||
}
|
||||
|
||||
function NavEditorGui::onLinkSelected(%this, %flags)
|
||||
{
|
||||
updateLinkData(NavEditorOptionsWindow-->LinkProperties, %flags);
|
||||
|
|
@ -508,16 +585,6 @@ function NavEditorGui::onPlayerSelected(%this, %flags)
|
|||
updateLinkData(NavEditorOptionsWindow-->TestProperties, %flags);
|
||||
}
|
||||
|
||||
function NavEditorGui::updateLinkFlags(%this)
|
||||
{
|
||||
if(isObject(%this.getMesh()))
|
||||
{
|
||||
%properties = NavEditorOptionsWindow-->LinkProperties;
|
||||
%this.setLinkFlags(getLinkFlags(%properties));
|
||||
%this.isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
function NavEditorGui::updateTestFlags(%this)
|
||||
{
|
||||
if(isObject(%this.getPlayer()))
|
||||
|
|
@ -536,11 +603,6 @@ function NavEditorGui::updateTestFlags(%this)
|
|||
}
|
||||
}
|
||||
|
||||
function NavEditorGui::onLinkDeselected(%this)
|
||||
{
|
||||
disableLinkData(NavEditorOptionsWindow-->LinkProperties);
|
||||
}
|
||||
|
||||
function NavEditorGui::onPlayerDeselected(%this)
|
||||
{
|
||||
disableLinkData(NavEditorOptionsWindow-->TestProperties);
|
||||
|
|
@ -656,11 +718,6 @@ function ENavEditorPaletteButton::onClick(%this)
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function NavMeshLinkFlagButton::onClick(%this)
|
||||
{
|
||||
NavEditorGui.updateLinkFlags();
|
||||
}
|
||||
|
||||
function NavMeshTestFlagButton::onClick(%this)
|
||||
{
|
||||
NavEditorGui.updateTestFlags();
|
||||
|
|
|
|||
Loading…
Reference in a new issue