crowd option

This commit is contained in:
ikpil 2023-09-09 12:49:11 +09:00
parent be1dad863f
commit c76d87380a
4 changed files with 114 additions and 112 deletions

View File

@ -40,7 +40,7 @@ public class CrowdProfilingSampleTool : ISampleTool
private DemoSample _sample; private DemoSample _sample;
private DtNavMesh m_nav; private DtNavMesh m_nav;
private readonly CrowdToolParams toolParams = new CrowdToolParams(); private readonly CrowdOption _option = new CrowdOption();
private RcCrowdProfilingTool _tool; private RcCrowdProfilingTool _tool;
private int expandSimOptions = 1; private int expandSimOptions = 1;
@ -95,8 +95,8 @@ public class CrowdProfilingSampleTool : ISampleTool
ap.collisionQueryRange = ap.radius * 12.0f; ap.collisionQueryRange = ap.radius * 12.0f;
ap.pathOptimizationRange = ap.radius * 30.0f; ap.pathOptimizationRange = ap.radius * 30.0f;
ap.updateFlags = GetUpdateFlags(); ap.updateFlags = GetUpdateFlags();
ap.obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType; ap.obstacleAvoidanceType = _option.obstacleAvoidanceType;
ap.separationWeight = toolParams.m_separationWeight; ap.separationWeight = _option.separationWeight;
return ap; return ap;
} }
@ -104,27 +104,27 @@ public class CrowdProfilingSampleTool : ISampleTool
private int GetUpdateFlags() private int GetUpdateFlags()
{ {
int updateFlags = 0; int updateFlags = 0;
if (toolParams.m_anticipateTurns) if (_option.anticipateTurns)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_ANTICIPATE_TURNS; updateFlags |= DtCrowdAgentParams.DT_CROWD_ANTICIPATE_TURNS;
} }
if (toolParams.m_optimizeVis) if (_option.optimizeVis)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_VIS; updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_VIS;
} }
if (toolParams.m_optimizeTopo) if (_option.optimizeTopo)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_TOPO; updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_TOPO;
} }
if (toolParams.m_obstacleAvoidance) if (_option.obstacleAvoidance)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_OBSTACLE_AVOIDANCE; updateFlags |= DtCrowdAgentParams.DT_CROWD_OBSTACLE_AVOIDANCE;
} }
if (toolParams.m_separation) if (_option.separation)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_SEPARATION; updateFlags |= DtCrowdAgentParams.DT_CROWD_SEPARATION;
} }
@ -142,27 +142,27 @@ public class CrowdProfilingSampleTool : ISampleTool
{ {
ImGui.Text("Options"); ImGui.Text("Options");
ImGui.Separator(); ImGui.Separator();
bool m_optimizeVis = toolParams.m_optimizeVis; bool m_optimizeVis = _option.optimizeVis;
bool m_optimizeTopo = toolParams.m_optimizeTopo; bool m_optimizeTopo = _option.optimizeTopo;
bool m_anticipateTurns = toolParams.m_anticipateTurns; bool m_anticipateTurns = _option.anticipateTurns;
bool m_obstacleAvoidance = toolParams.m_obstacleAvoidance; bool m_obstacleAvoidance = _option.obstacleAvoidance;
bool m_separation = toolParams.m_separation; bool m_separation = _option.separation;
int m_obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType; int m_obstacleAvoidanceType = _option.obstacleAvoidanceType;
float m_separationWeight = toolParams.m_separationWeight; float m_separationWeight = _option.separationWeight;
ImGui.Checkbox("Optimize Visibility", ref toolParams.m_optimizeVis); ImGui.Checkbox("Optimize Visibility", ref _option.optimizeVis);
ImGui.Checkbox("Optimize Topology", ref toolParams.m_optimizeTopo); ImGui.Checkbox("Optimize Topology", ref _option.optimizeTopo);
ImGui.Checkbox("Anticipate Turns", ref toolParams.m_anticipateTurns); ImGui.Checkbox("Anticipate Turns", ref _option.anticipateTurns);
ImGui.Checkbox("Obstacle Avoidance", ref toolParams.m_obstacleAvoidance); ImGui.Checkbox("Obstacle Avoidance", ref _option.obstacleAvoidance);
ImGui.SliderInt("Avoidance Quality", ref toolParams.m_obstacleAvoidanceType, 0, 3); ImGui.SliderInt("Avoidance Quality", ref _option.obstacleAvoidanceType, 0, 3);
ImGui.Checkbox("Separation", ref toolParams.m_separation); ImGui.Checkbox("Separation", ref _option.separation);
ImGui.SliderFloat("Separation Weight", ref toolParams.m_separationWeight, 0f, 20f, "%.2f"); ImGui.SliderFloat("Separation Weight", ref _option.separationWeight, 0f, 20f, "%.2f");
ImGui.NewLine(); ImGui.NewLine();
if (m_optimizeVis != toolParams.m_optimizeVis || m_optimizeTopo != toolParams.m_optimizeTopo if (m_optimizeVis != _option.optimizeVis || m_optimizeTopo != _option.optimizeTopo
|| m_anticipateTurns != toolParams.m_anticipateTurns || m_obstacleAvoidance != toolParams.m_obstacleAvoidance || m_anticipateTurns != _option.anticipateTurns || m_obstacleAvoidance != _option.obstacleAvoidance
|| m_separation != toolParams.m_separation || m_separation != _option.separation
|| m_obstacleAvoidanceType != toolParams.m_obstacleAvoidanceType || m_obstacleAvoidanceType != _option.obstacleAvoidanceType
|| m_separationWeight != toolParams.m_separationWeight) || m_separationWeight != _option.separationWeight)
{ {
UpdateAgentParams(); UpdateAgentParams();
} }
@ -188,11 +188,11 @@ public class CrowdProfilingSampleTool : ISampleTool
StartProfiling(); StartProfiling();
} }
if (m_optimizeVis != toolParams.m_optimizeVis || m_optimizeTopo != toolParams.m_optimizeTopo if (m_optimizeVis != _option.optimizeVis || m_optimizeTopo != _option.optimizeTopo
|| m_anticipateTurns != toolParams.m_anticipateTurns || m_obstacleAvoidance != toolParams.m_obstacleAvoidance || m_anticipateTurns != _option.anticipateTurns || m_obstacleAvoidance != _option.obstacleAvoidance
|| m_separation != toolParams.m_separation || m_separation != _option.separation
|| m_obstacleAvoidanceType != toolParams.m_obstacleAvoidanceType || m_obstacleAvoidanceType != _option.obstacleAvoidanceType
|| m_separationWeight != toolParams.m_separationWeight) || m_separationWeight != _option.separationWeight)
{ {
UpdateAgentParams(); UpdateAgentParams();
} }
@ -552,8 +552,8 @@ public class CrowdProfilingSampleTool : ISampleTool
option.queryFilterType = ag.option.queryFilterType; option.queryFilterType = ag.option.queryFilterType;
option.userData = ag.option.userData; option.userData = ag.option.userData;
option.updateFlags = updateFlags; option.updateFlags = updateFlags;
option.obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType; option.obstacleAvoidanceType = _option.obstacleAvoidanceType;
option.separationWeight = toolParams.m_separationWeight; option.separationWeight = _option.separationWeight;
crowd.UpdateAgentParameters(ag, option); crowd.UpdateAgentParameters(ag, option);
} }
} }

View File

@ -41,7 +41,7 @@ public class CrowdampleTool : ISampleTool
private DemoSample _sample; private DemoSample _sample;
private readonly RcCrowdTool _tool; private readonly RcCrowdTool _tool;
private readonly CrowdToolParams toolParams = new CrowdToolParams(); private readonly CrowdOption _option = new CrowdOption();
private DtNavMesh m_nav; private DtNavMesh m_nav;
private DtCrowd crowd; private DtCrowd crowd;
private readonly DtCrowdAgentDebugInfo m_agentDebug = new DtCrowdAgentDebugInfo(); private readonly DtCrowdAgentDebugInfo m_agentDebug = new DtCrowdAgentDebugInfo();
@ -53,6 +53,22 @@ public class CrowdampleTool : ISampleTool
private int m_modeIdx = CrowdToolMode.CREATE.Idx; private int m_modeIdx = CrowdToolMode.CREATE.Idx;
private long crowdUpdateTime; private long crowdUpdateTime;
private int m_expandSelectedDebugDraw = 1;
private bool m_showCorners;
private bool m_showCollisionSegments;
private bool m_showPath;
private bool m_showVO;
private bool m_showOpt;
private bool m_showNeis;
private int m_expandDebugDraw = 0;
private bool m_showLabels;
private bool m_showGrid;
private bool m_showNodes;
private bool m_showPerfGraph;
private bool m_showDetailAll;
public CrowdampleTool() public CrowdampleTool()
{ {
m_agentDebug.vod = new DtObstacleAvoidanceDebugData(2048); m_agentDebug.vod = new DtObstacleAvoidanceDebugData(2048);
@ -222,8 +238,8 @@ public class CrowdampleTool : ISampleTool
ap.collisionQueryRange = ap.radius * 12.0f; ap.collisionQueryRange = ap.radius * 12.0f;
ap.pathOptimizationRange = ap.radius * 30.0f; ap.pathOptimizationRange = ap.radius * 30.0f;
ap.updateFlags = GetUpdateFlags(); ap.updateFlags = GetUpdateFlags();
ap.obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType; ap.obstacleAvoidanceType = _option.obstacleAvoidanceType;
ap.separationWeight = toolParams.m_separationWeight; ap.separationWeight = _option.separationWeight;
return ap; return ap;
} }
@ -324,7 +340,7 @@ public class CrowdampleTool : ISampleTool
if (nav == null || crowd == null) if (nav == null || crowd == null)
return; return;
if (toolParams.m_showNodes && crowd.GetPathQueue() != null) if (m_showNodes && crowd.GetPathQueue() != null)
{ {
// NavMeshQuery navquery = crowd.GetPathQueue().GetNavQuery(); // NavMeshQuery navquery = crowd.GetPathQueue().GetNavQuery();
// if (navquery != null) { // if (navquery != null) {
@ -335,12 +351,13 @@ public class CrowdampleTool : ISampleTool
dd.DepthMask(false); dd.DepthMask(false);
// Draw paths // Draw paths
if (toolParams.m_showPath) if (m_showPath)
{ {
foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) foreach (DtCrowdAgent ag in crowd.GetActiveAgents())
{ {
if (!toolParams.m_showDetailAll && ag != m_agentDebug.agent) if (!m_showDetailAll && ag != m_agentDebug.agent)
continue; continue;
List<long> path = ag.corridor.GetPath(); List<long> path = ag.corridor.GetPath();
int npath = ag.corridor.GetPathCount(); int npath = ag.corridor.GetPathCount();
for (int j = 0; j < npath; ++j) for (int j = 0; j < npath; ++j)
@ -354,7 +371,7 @@ public class CrowdampleTool : ISampleTool
dd.DebugDrawCross(m_targetPos.x, m_targetPos.y + 0.1f, m_targetPos.z, rad, DuRGBA(255, 255, 255, 192), 2.0f); dd.DebugDrawCross(m_targetPos.x, m_targetPos.y + 0.1f, m_targetPos.z, rad, DuRGBA(255, 255, 255, 192), 2.0f);
// Occupancy grid. // Occupancy grid.
if (toolParams.m_showGrid) if (m_showGrid)
{ {
float gridy = -float.MaxValue; float gridy = -float.MaxValue;
foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) foreach (DtCrowdAgent ag in crowd.GetActiveAgents())
@ -411,13 +428,13 @@ public class CrowdampleTool : ISampleTool
// Corners & co // Corners & co
foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) foreach (DtCrowdAgent ag in crowd.GetActiveAgents())
{ {
if (toolParams.m_showDetailAll == false && ag != m_agentDebug.agent) if (m_showDetailAll == false && ag != m_agentDebug.agent)
continue; continue;
float radius = ag.option.radius; float radius = ag.option.radius;
RcVec3f pos = ag.npos; RcVec3f pos = ag.npos;
if (toolParams.m_showCorners) if (m_showCorners)
{ {
if (0 < ag.corners.Count) if (0 < ag.corners.Count)
{ {
@ -440,7 +457,7 @@ public class CrowdampleTool : ISampleTool
dd.End(); dd.End();
if (toolParams.m_anticipateTurns) if (_option.anticipateTurns)
{ {
/* float dvel[3], pos[3]; /* float dvel[3], pos[3];
CalcSmoothSteerDirection(ag.pos, ag.cornerVerts, ag.ncorners, dvel); CalcSmoothSteerDirection(ag.pos, ag.cornerVerts, ag.ncorners, dvel);
@ -465,7 +482,7 @@ public class CrowdampleTool : ISampleTool
} }
} }
if (toolParams.m_showCollisionSegments) if (m_showCollisionSegments)
{ {
RcVec3f center = ag.boundary.GetCenter(); RcVec3f center = ag.boundary.GetCenter();
dd.DebugDrawCross(center.x, center.y + radius, center.z, 0.2f, DuRGBA(192, 0, 128, 255), 2.0f); dd.DebugDrawCross(center.x, center.y + radius, center.z, 0.2f, DuRGBA(192, 0, 128, 255), 2.0f);
@ -487,7 +504,7 @@ public class CrowdampleTool : ISampleTool
dd.End(); dd.End();
} }
if (toolParams.m_showNeis) if (m_showNeis)
{ {
dd.DebugDrawCircle(pos.x, pos.y + radius, pos.z, ag.option.collisionQueryRange, DuRGBA(0, 192, 128, 128), dd.DebugDrawCircle(pos.x, pos.y + radius, pos.z, ag.option.collisionQueryRange, DuRGBA(0, 192, 128, 128),
2.0f); 2.0f);
@ -506,7 +523,7 @@ public class CrowdampleTool : ISampleTool
dd.End(); dd.End();
} }
if (toolParams.m_showOpt) if (m_showOpt)
{ {
dd.Begin(LINES, 2.0f); dd.Begin(LINES, 2.0f);
dd.Vertex(m_agentDebug.optStart.x, m_agentDebug.optStart.y + 0.3f, m_agentDebug.optStart.z, dd.Vertex(m_agentDebug.optStart.x, m_agentDebug.optStart.y + 0.3f, m_agentDebug.optStart.z,
@ -550,11 +567,11 @@ public class CrowdampleTool : ISampleTool
pos.z + radius, col); pos.z + radius, col);
} }
if (toolParams.m_showVO) if (m_showVO)
{ {
foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) foreach (DtCrowdAgent ag in crowd.GetActiveAgents())
{ {
if (toolParams.m_showDetailAll == false && ag != m_agentDebug.agent) if (m_showDetailAll == false && ag != m_agentDebug.agent)
continue; continue;
// Draw detail about agent sela // Draw detail about agent sela
@ -675,27 +692,27 @@ public class CrowdampleTool : ISampleTool
ImGui.Text("Options"); ImGui.Text("Options");
ImGui.Separator(); ImGui.Separator();
bool m_optimizeVis = toolParams.m_optimizeVis; bool m_optimizeVis = _option.optimizeVis;
bool m_optimizeTopo = toolParams.m_optimizeTopo; bool m_optimizeTopo = _option.optimizeTopo;
bool m_anticipateTurns = toolParams.m_anticipateTurns; bool m_anticipateTurns = _option.anticipateTurns;
bool m_obstacleAvoidance = toolParams.m_obstacleAvoidance; bool m_obstacleAvoidance = _option.obstacleAvoidance;
bool m_separation = toolParams.m_separation; bool m_separation = _option.separation;
int m_obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType; int m_obstacleAvoidanceType = _option.obstacleAvoidanceType;
float m_separationWeight = toolParams.m_separationWeight; float m_separationWeight = _option.separationWeight;
ImGui.Checkbox("Optimize Visibility", ref toolParams.m_optimizeVis); ImGui.Checkbox("Optimize Visibility", ref _option.optimizeVis);
ImGui.Checkbox("Optimize Topology", ref toolParams.m_optimizeTopo); ImGui.Checkbox("Optimize Topology", ref _option.optimizeTopo);
ImGui.Checkbox("Anticipate Turns", ref toolParams.m_anticipateTurns); ImGui.Checkbox("Anticipate Turns", ref _option.anticipateTurns);
ImGui.Checkbox("Obstacle Avoidance", ref toolParams.m_obstacleAvoidance); ImGui.Checkbox("Obstacle Avoidance", ref _option.obstacleAvoidance);
ImGui.SliderInt("Avoidance Quality", ref toolParams.m_obstacleAvoidanceType, 0, 3); ImGui.SliderInt("Avoidance Quality", ref _option.obstacleAvoidanceType, 0, 3);
ImGui.Checkbox("Separation", ref toolParams.m_separation); ImGui.Checkbox("Separation", ref _option.separation);
ImGui.SliderFloat("Separation Weight", ref toolParams.m_separationWeight, 0f, 20f, "%.2f"); ImGui.SliderFloat("Separation Weight", ref _option.separationWeight, 0f, 20f, "%.2f");
ImGui.NewLine(); ImGui.NewLine();
if (m_optimizeVis != toolParams.m_optimizeVis || m_optimizeTopo != toolParams.m_optimizeTopo if (m_optimizeVis != _option.optimizeVis || m_optimizeTopo != _option.optimizeTopo
|| m_anticipateTurns != toolParams.m_anticipateTurns || m_obstacleAvoidance != toolParams.m_obstacleAvoidance || m_anticipateTurns != _option.anticipateTurns || m_obstacleAvoidance != _option.obstacleAvoidance
|| m_separation != toolParams.m_separation || m_separation != _option.separation
|| m_obstacleAvoidanceType != toolParams.m_obstacleAvoidanceType || m_obstacleAvoidanceType != _option.obstacleAvoidanceType
|| m_separationWeight != toolParams.m_separationWeight) || m_separationWeight != _option.separationWeight)
{ {
UpdateAgentParams(); UpdateAgentParams();
} }
@ -703,18 +720,18 @@ public class CrowdampleTool : ISampleTool
ImGui.Text("Selected Debug Draw"); ImGui.Text("Selected Debug Draw");
ImGui.Separator(); ImGui.Separator();
ImGui.Checkbox("Show Corners", ref toolParams.m_showCorners); ImGui.Checkbox("Show Corners", ref m_showCorners);
ImGui.Checkbox("Show Collision Segs", ref toolParams.m_showCollisionSegments); ImGui.Checkbox("Show Collision Segs", ref m_showCollisionSegments);
ImGui.Checkbox("Show Path", ref toolParams.m_showPath); ImGui.Checkbox("Show Path", ref m_showPath);
ImGui.Checkbox("Show VO", ref toolParams.m_showVO); ImGui.Checkbox("Show VO", ref m_showVO);
ImGui.Checkbox("Show Path Optimization", ref toolParams.m_showOpt); ImGui.Checkbox("Show Path Optimization", ref m_showOpt);
ImGui.Checkbox("Show Neighbours", ref toolParams.m_showNeis); ImGui.Checkbox("Show Neighbours", ref m_showNeis);
ImGui.NewLine(); ImGui.NewLine();
ImGui.Text("Debug Draw"); ImGui.Text("Debug Draw");
ImGui.Separator(); ImGui.Separator();
ImGui.Checkbox("Show Proximity Grid", ref toolParams.m_showGrid); ImGui.Checkbox("Show Proximity Grid", ref m_showGrid);
ImGui.Checkbox("Show Nodes", ref toolParams.m_showNodes); ImGui.Checkbox("Show Nodes", ref m_showNodes);
ImGui.Text($"Update Time: {crowdUpdateTime} ms"); ImGui.Text($"Update Time: {crowdUpdateTime} ms");
} }
@ -739,8 +756,8 @@ public class CrowdampleTool : ISampleTool
option.queryFilterType = ag.option.queryFilterType; option.queryFilterType = ag.option.queryFilterType;
option.userData = ag.option.userData; option.userData = ag.option.userData;
option.updateFlags = updateFlags; option.updateFlags = updateFlags;
option.obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType; option.obstacleAvoidanceType = _option.obstacleAvoidanceType;
option.separationWeight = toolParams.m_separationWeight; option.separationWeight = _option.separationWeight;
crowd.UpdateAgentParameters(ag, option); crowd.UpdateAgentParameters(ag, option);
} }
} }
@ -748,27 +765,27 @@ public class CrowdampleTool : ISampleTool
private int GetUpdateFlags() private int GetUpdateFlags()
{ {
int updateFlags = 0; int updateFlags = 0;
if (toolParams.m_anticipateTurns) if (_option.anticipateTurns)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_ANTICIPATE_TURNS; updateFlags |= DtCrowdAgentParams.DT_CROWD_ANTICIPATE_TURNS;
} }
if (toolParams.m_optimizeVis) if (_option.optimizeVis)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_VIS; updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_VIS;
} }
if (toolParams.m_optimizeTopo) if (_option.optimizeTopo)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_TOPO; updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_TOPO;
} }
if (toolParams.m_obstacleAvoidance) if (_option.obstacleAvoidance)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_OBSTACLE_AVOIDANCE; updateFlags |= DtCrowdAgentParams.DT_CROWD_OBSTACLE_AVOIDANCE;
} }
if (toolParams.m_separation) if (_option.separation)
{ {
updateFlags |= DtCrowdAgentParams.DT_CROWD_SEPARATION; updateFlags |= DtCrowdAgentParams.DT_CROWD_SEPARATION;
} }

View File

@ -0,0 +1,14 @@
namespace DotRecast.Recast.Toolset.Tools
{
public class CrowdOption
{
public int expandOptions = 1;
public bool anticipateTurns = true;
public bool optimizeVis = true;
public bool optimizeTopo = true;
public bool obstacleAvoidance = true;
public int obstacleAvoidanceType = 3;
public bool separation;
public float separationWeight = 2f;
}
}

View File

@ -1,29 +0,0 @@
namespace DotRecast.Recast.Toolset.Tools
{
public class CrowdToolParams
{
public int m_expandSelectedDebugDraw = 1;
public bool m_showCorners;
public bool m_showCollisionSegments;
public bool m_showPath;
public bool m_showVO;
public bool m_showOpt;
public bool m_showNeis;
public int m_expandDebugDraw = 0;
public bool m_showLabels;
public bool m_showGrid;
public bool m_showNodes;
public bool m_showPerfGraph;
public bool m_showDetailAll;
public int m_expandOptions = 1;
public bool m_anticipateTurns = true;
public bool m_optimizeVis = true;
public bool m_optimizeTopo = true;
public bool m_obstacleAvoidance = true;
public int m_obstacleAvoidanceType = 3;
public bool m_separation;
public float m_separationWeight = 2f;
}
}