mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-26 15:49:30 +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
7 changed files with 203 additions and 70 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue