From ed55d6a7f2ed5e2449bfc47f8a217adfae885c7c Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 7 Jun 2023 23:35:40 +0900 Subject: [PATCH] for unity3d --- src/DotRecast.Recast.Demo/RecastDemo.cs | 1 + src/DotRecast.Recast.Demo/Tools/AgentData.cs | 15 ------ src/DotRecast.Recast.Demo/Tools/AgentTrail.cs | 7 --- src/DotRecast.Recast.Demo/Tools/AgentType.cs | 8 --- .../Tools/CrowdProfilingTool.cs | 49 ++++++++++--------- src/DotRecast.Recast.Demo/Tools/CrowdTool.cs | 20 ++++---- .../Tools/CrowdToolMode.cs | 29 ----------- .../Tools/CrowdToolParams.cs | 46 ----------------- .../Tools/DemoObjImporter.cs | 14 ------ .../Tools/DynamicUpdateTool.cs | 1 + .../Tools/DynamicUpdateToolMode.cs | 23 --------- .../Tools/JumpLinkBuilderTool.cs | 1 + .../Tools/JumpLinkBuilderToolParams.cs | 43 ---------------- .../Tools/TestNavmeshTool.cs | 1 + .../Tools/TestNavmeshToolMode.cs | 38 -------------- src/DotRecast.Recast.Demo/Tools/Tool.cs | 7 ++- .../CrowdAgentData.cs | 16 ++++++ .../CrowdAgentTrail.cs | 9 ++++ .../CrowdAgentType.cs | 9 ++++ .../CrowdToolMode.cs | 30 ++++++++++++ .../CrowdToolParams.cs | 47 ++++++++++++++++++ .../DemoObjImporter.cs | 15 ++++++ .../DynamicUpdateToolMode.cs | 24 +++++++++ .../JumpLinkBuilderToolParams.cs | 44 +++++++++++++++++ .../TestNavmeshToolMode.cs | 39 +++++++++++++++ 25 files changed, 275 insertions(+), 261 deletions(-) delete mode 100644 src/DotRecast.Recast.Demo/Tools/AgentData.cs delete mode 100644 src/DotRecast.Recast.Demo/Tools/AgentTrail.cs delete mode 100644 src/DotRecast.Recast.Demo/Tools/AgentType.cs delete mode 100644 src/DotRecast.Recast.Demo/Tools/CrowdToolMode.cs delete mode 100644 src/DotRecast.Recast.Demo/Tools/CrowdToolParams.cs delete mode 100644 src/DotRecast.Recast.Demo/Tools/DemoObjImporter.cs delete mode 100644 src/DotRecast.Recast.Demo/Tools/DynamicUpdateToolMode.cs delete mode 100644 src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderToolParams.cs delete mode 100644 src/DotRecast.Recast.Demo/Tools/TestNavmeshToolMode.cs create mode 100644 src/DotRecast.Recast.DemoTool/CrowdAgentData.cs create mode 100644 src/DotRecast.Recast.DemoTool/CrowdAgentTrail.cs create mode 100644 src/DotRecast.Recast.DemoTool/CrowdAgentType.cs create mode 100644 src/DotRecast.Recast.DemoTool/CrowdToolMode.cs create mode 100644 src/DotRecast.Recast.DemoTool/CrowdToolParams.cs create mode 100644 src/DotRecast.Recast.DemoTool/DemoObjImporter.cs create mode 100644 src/DotRecast.Recast.DemoTool/DynamicUpdateToolMode.cs create mode 100644 src/DotRecast.Recast.DemoTool/JumpLinkBuilderToolParams.cs create mode 100644 src/DotRecast.Recast.DemoTool/TestNavmeshToolMode.cs diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 4de0193..fb5b824 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -40,6 +40,7 @@ using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.DemoTool.Geom; using DotRecast.Recast.Demo.Tools; using DotRecast.Recast.Demo.UI; +using DotRecast.Recast.DemoTool; using static DotRecast.Core.RcMath; using Window = Silk.NET.Windowing.Window; diff --git a/src/DotRecast.Recast.Demo/Tools/AgentData.cs b/src/DotRecast.Recast.Demo/Tools/AgentData.cs deleted file mode 100644 index 50c530c..0000000 --- a/src/DotRecast.Recast.Demo/Tools/AgentData.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DotRecast.Core; - -namespace DotRecast.Recast.Demo.Tools; - -public class AgentData -{ - public readonly AgentType type; - public readonly RcVec3f home = new RcVec3f(); - - public AgentData(AgentType type, RcVec3f home) - { - this.type = type; - this.home = home; - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/AgentTrail.cs b/src/DotRecast.Recast.Demo/Tools/AgentTrail.cs deleted file mode 100644 index 57586dc..0000000 --- a/src/DotRecast.Recast.Demo/Tools/AgentTrail.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace DotRecast.Recast.Demo.Tools; - -public class AgentTrail -{ - public float[] trail = new float[CrowdTool.AGENT_MAX_TRAIL * 3]; - public int htrail; -}; \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/AgentType.cs b/src/DotRecast.Recast.Demo/Tools/AgentType.cs deleted file mode 100644 index b97dec8..0000000 --- a/src/DotRecast.Recast.Demo/Tools/AgentType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace DotRecast.Recast.Demo.Tools; - -public enum AgentType -{ - VILLAGER, - TRAVELLER, - MOB, -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs index dbd1152..e4f046c 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs @@ -26,6 +26,7 @@ using DotRecast.Detour.Crowd; using DotRecast.Detour.QueryResults; using DotRecast.Recast.DemoTool.Builder; using DotRecast.Recast.Demo.Draw; +using DotRecast.Recast.DemoTool; using ImGuiNET; using Silk.NET.Windowing; using static DotRecast.Recast.Demo.Draw.DebugDraw; @@ -87,7 +88,7 @@ public class CrowdProfilingTool for (int i = 0; i < agents; i++) { float tr = rnd.Next(); - AgentType type = AgentType.MOB; + CrowdAgentType type = CrowdAgentType.MOB; float mobsPcnt = percentMobs / 100f; if (tr > mobsPcnt) { @@ -95,24 +96,24 @@ public class CrowdProfilingTool float travellerPcnt = percentTravellers / 100f; if (tr > travellerPcnt) { - type = AgentType.VILLAGER; + type = CrowdAgentType.VILLAGER; } else { - type = AgentType.TRAVELLER; + type = CrowdAgentType.TRAVELLER; } } RcVec3f? pos = null; switch (type) { - case AgentType.MOB: + case CrowdAgentType.MOB: pos = GetMobPosition(navquery, filter); break; - case AgentType.VILLAGER: + case CrowdAgentType.VILLAGER: pos = GetVillagerPosition(navquery, filter); break; - case AgentType.TRAVELLER: + case CrowdAgentType.TRAVELLER: pos = GetVillagerPosition(navquery, filter); break; } @@ -257,17 +258,17 @@ public class CrowdProfilingTool { if (NeedsNewTarget(ag)) { - AgentData agentData = (AgentData)ag.option.userData; - switch (agentData.type) + CrowdAgentData crowAgentData = (CrowdAgentData)ag.option.userData; + switch (crowAgentData.type) { - case AgentType.MOB: - MoveMob(navquery, filter, ag, agentData); + case CrowdAgentType.MOB: + MoveMob(navquery, filter, ag, crowAgentData); break; - case AgentType.VILLAGER: - MoveVillager(navquery, filter, ag, agentData); + case CrowdAgentType.VILLAGER: + MoveVillager(navquery, filter, ag, crowAgentData); break; - case AgentType.TRAVELLER: - MoveTraveller(navquery, filter, ag, agentData); + case CrowdAgentType.TRAVELLER: + MoveTraveller(navquery, filter, ag, crowAgentData); break; } } @@ -277,14 +278,14 @@ public class CrowdProfilingTool crowdUpdateTime = (endTime - startTime) / TimeSpan.TicksPerMillisecond; } - private void MoveMob(NavMeshQuery navquery, IQueryFilter filter, CrowdAgent ag, AgentData agentData) + private void MoveMob(NavMeshQuery navquery, IQueryFilter filter, CrowdAgent ag, CrowdAgentData crowAgentData) { // Move somewhere Result nearestPoly = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter); if (nearestPoly.Succeeded()) { Result result = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(), - agentData.home, zoneRadius * 2f, filter, rnd); + crowAgentData.home, zoneRadius * 2f, filter, rnd); if (result.Succeeded()) { crowd.RequestMoveTarget(ag, result.result.GetRandomRef(), result.result.GetRandomPt()); @@ -292,14 +293,14 @@ public class CrowdProfilingTool } } - private void MoveVillager(NavMeshQuery navquery, IQueryFilter filter, CrowdAgent ag, AgentData agentData) + private void MoveVillager(NavMeshQuery navquery, IQueryFilter filter, CrowdAgent ag, CrowdAgentData crowAgentData) { // Move somewhere close Result nearestPoly = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter); if (nearestPoly.Succeeded()) { Result result = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(), - agentData.home, zoneRadius * 0.2f, filter, rnd); + crowAgentData.home, zoneRadius * 0.2f, filter, rnd); if (result.Succeeded()) { crowd.RequestMoveTarget(ag, result.result.GetRandomRef(), result.result.GetRandomPt()); @@ -307,7 +308,7 @@ public class CrowdProfilingTool } } - private void MoveTraveller(NavMeshQuery navquery, IQueryFilter filter, CrowdAgent ag, AgentData agentData) + private void MoveTraveller(NavMeshQuery navquery, IQueryFilter filter, CrowdAgent ag, CrowdAgentData crowAgentData) { // Move to another zone List potentialTargets = new(); @@ -369,19 +370,19 @@ public class CrowdProfilingTool foreach (CrowdAgent ag in crowd.GetActiveAgents()) { - AgentData agentData = (AgentData)ag.option.userData; + CrowdAgentData crowAgentData = (CrowdAgentData)ag.option.userData; float height = ag.option.height; float radius = ag.option.radius; RcVec3f pos = ag.npos; int col = DuRGBA(220, 220, 220, 128); - if (agentData.type == AgentType.TRAVELLER) + if (crowAgentData.type == CrowdAgentType.TRAVELLER) { col = DuRGBA(100, 160, 100, 128); } - if (agentData.type == AgentType.VILLAGER) + if (crowAgentData.type == CrowdAgentType.VILLAGER) { col = DuRGBA(120, 80, 160, 128); } @@ -404,10 +405,10 @@ public class CrowdProfilingTool dd.DepthMask(true); } - private CrowdAgent AddAgent(RcVec3f p, AgentType type) + private CrowdAgent AddAgent(RcVec3f p, CrowdAgentType type) { CrowdAgentParams ap = agentParamsSupplier.Invoke(); - ap.userData = new AgentData(type, p); + ap.userData = new CrowdAgentData(type, p); return crowd.AddAgent(p, ap); } diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index 85a8b93..100e9fc 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -29,6 +29,7 @@ using DotRecast.Detour.Crowd.Tracking; using DotRecast.Detour.QueryResults; using DotRecast.Recast.DemoTool.Builder; using DotRecast.Recast.Demo.Draw; +using DotRecast.Recast.DemoTool; using DotRecast.Recast.DemoTool.Geom; using ImGuiNET; using static DotRecast.Recast.Demo.Draw.DebugDraw; @@ -46,8 +47,7 @@ public class CrowdTool : Tool private readonly CrowdProfilingTool profilingTool; private readonly CrowdAgentDebugInfo m_agentDebug = new CrowdAgentDebugInfo(); - public static readonly int AGENT_MAX_TRAIL = 64; - private readonly Dictionary m_trails = new(); + private readonly Dictionary m_trails = new(); private RcVec3f m_targetPos; private long m_targetRef; private CrowdToolMode m_mode = CrowdToolMode.CREATE; @@ -197,11 +197,11 @@ public class CrowdTool : Tool // Init trail if (!m_trails.TryGetValue(ag.idx, out var trail)) { - trail = new AgentTrail(); + trail = new CrowdAgentTrail(); m_trails.Add(ag.idx, trail); } - for (int i = 0; i < AGENT_MAX_TRAIL; ++i) + for (int i = 0; i < CrowdAgentTrail.AGENT_MAX_TRAIL; ++i) { trail.trail[i * 3] = p.x; trail.trail[i * 3 + 1] = p.y; @@ -394,18 +394,18 @@ public class CrowdTool : Tool // Trail foreach (CrowdAgent ag in crowd.GetActiveAgents()) { - AgentTrail trail = m_trails[ag.idx]; + CrowdAgentTrail trail = m_trails[ag.idx]; RcVec3f pos = ag.npos; dd.Begin(LINES, 3.0f); RcVec3f prev = new RcVec3f(); float preva = 1; prev = pos; - for (int j = 0; j < AGENT_MAX_TRAIL - 1; ++j) + for (int j = 0; j < CrowdAgentTrail.AGENT_MAX_TRAIL - 1; ++j) { - int idx = (trail.htrail + AGENT_MAX_TRAIL - j) % AGENT_MAX_TRAIL; + int idx = (trail.htrail + CrowdAgentTrail.AGENT_MAX_TRAIL - j) % CrowdAgentTrail.AGENT_MAX_TRAIL; int v = idx * 3; - float a = 1 - j / (float)AGENT_MAX_TRAIL; + float a = 1 - j / (float)CrowdAgentTrail.AGENT_MAX_TRAIL; dd.Vertex(prev.x, prev.y + 0.1f, prev.z, DuRGBA(0, 0, 0, (int)(128 * preva))); dd.Vertex(trail.trail[v], trail.trail[v + 1] + 0.1f, trail.trail[v + 2], DuRGBA(0, 0, 0, (int)(128 * a))); preva = a; @@ -650,9 +650,9 @@ public class CrowdTool : Tool // Update agent trails foreach (CrowdAgent ag in crowd.GetActiveAgents()) { - AgentTrail trail = m_trails[ag.idx]; + CrowdAgentTrail trail = m_trails[ag.idx]; // Update agent movement trail. - trail.htrail = (trail.htrail + 1) % AGENT_MAX_TRAIL; + trail.htrail = (trail.htrail + 1) % CrowdAgentTrail.AGENT_MAX_TRAIL; trail.trail[trail.htrail * 3] = ag.npos.x; trail.trail[trail.htrail * 3 + 1] = ag.npos.y; trail.trail[trail.htrail * 3 + 2] = ag.npos.z; diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdToolMode.cs b/src/DotRecast.Recast.Demo/Tools/CrowdToolMode.cs deleted file mode 100644 index 38ac056..0000000 --- a/src/DotRecast.Recast.Demo/Tools/CrowdToolMode.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Immutable; - -namespace DotRecast.Recast.Demo.Tools; - -public class CrowdToolMode -{ - public static readonly CrowdToolMode CREATE = new(0, "Create Agents"); - public static readonly CrowdToolMode MOVE_TARGET = new(1, "Move Target"); - public static readonly CrowdToolMode SELECT = new(2, "Select Agent"); - public static readonly CrowdToolMode TOGGLE_POLYS = new(3, "Toggle Polys"); - public static readonly CrowdToolMode PROFILING = new(4, "Profiling"); - - public static readonly ImmutableArray Values = ImmutableArray.Create( - CREATE, - MOVE_TARGET, - SELECT, - TOGGLE_POLYS, - PROFILING - ); - - public int Idx { get; } - public string Label { get; } - - private CrowdToolMode(int idx, string label) - { - Idx = idx; - Label = label; - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdToolParams.cs b/src/DotRecast.Recast.Demo/Tools/CrowdToolParams.cs deleted file mode 100644 index aa1f029..0000000 --- a/src/DotRecast.Recast.Demo/Tools/CrowdToolParams.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* -recast4j copyright (c) 2020-2021 Piotr Piastucki piotr@jtilia.org - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -namespace DotRecast.Recast.Demo.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; -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/DemoObjImporter.cs b/src/DotRecast.Recast.Demo/Tools/DemoObjImporter.cs deleted file mode 100644 index 2b8730b..0000000 --- a/src/DotRecast.Recast.Demo/Tools/DemoObjImporter.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.IO; -using DotRecast.Recast.DemoTool.Geom; - -namespace DotRecast.Recast.Demo.Tools; - -public static class DemoObjImporter -{ - public static DemoInputGeomProvider Load(byte[] chunk) - { - var context = ObjImporter.LoadContext(chunk); - return new DemoInputGeomProvider(context.vertexPositions, context.meshFaces); - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs index bcdf803..75370fd 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs @@ -35,6 +35,7 @@ using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.DemoTool.Geom; using DotRecast.Recast.Demo.Tools.Gizmos; using DotRecast.Recast.Demo.UI; +using DotRecast.Recast.DemoTool; using ImGuiNET; using Silk.NET.OpenAL; using Silk.NET.Windowing; diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateToolMode.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateToolMode.cs deleted file mode 100644 index bae2853..0000000 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateToolMode.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Immutable; - -namespace DotRecast.Recast.Demo.Tools; - -public class DynamicUpdateToolMode -{ - public static readonly DynamicUpdateToolMode BUILD = new(0, "Build"); - public static readonly DynamicUpdateToolMode COLLIDERS = new(1, "Colliders"); - public static readonly DynamicUpdateToolMode RAYCAST = new(2, "Raycast"); - - public static readonly ImmutableArray Values = ImmutableArray.Create( - BUILD, COLLIDERS, RAYCAST - ); - - public int Idx { get; } - public string Label { get; } - - private DynamicUpdateToolMode(int idx, string label) - { - Idx = idx; - Label = label; - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs index d003208..1a40435 100644 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs @@ -23,6 +23,7 @@ using Silk.NET.Windowing; using DotRecast.Detour.Extras.Jumplink; using DotRecast.Recast.DemoTool.Builder; using DotRecast.Recast.Demo.Draw; +using DotRecast.Recast.DemoTool; using DotRecast.Recast.DemoTool.Geom; using ImGuiNET; using static DotRecast.Core.RcMath; diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderToolParams.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderToolParams.cs deleted file mode 100644 index ad09c05..0000000 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderToolParams.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* -recast4j copyright (c) 2020-2021 Piotr Piastucki piotr@jtilia.org - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -using DotRecast.Detour.Extras.Jumplink; - -namespace DotRecast.Recast.Demo.Tools; - -public class JumpLinkBuilderToolParams -{ - public const int DRAW_WALKABLE_SURFACE = 1 << 0; - public const int DRAW_WALKABLE_BORDER = 1 << 1; - public const int DRAW_SELECTED_EDGE = 1 << 2; - public const int DRAW_ANIM_TRAJECTORY = 1 << 3; - public const int DRAW_LAND_SAMPLES = 1 << 4; - public const int DRAW_COLLISION_SLICES = 1 << 5; - public const int DRAW_ANNOTATIONS = 1 << 6; - - public int flags = DRAW_WALKABLE_SURFACE | DRAW_WALKABLE_BORDER | DRAW_SELECTED_EDGE | DRAW_ANIM_TRAJECTORY | DRAW_LAND_SAMPLES | DRAW_ANNOTATIONS; - public float groundTolerance = 0.3f; - public float climbDownDistance = 0.4f; - public float climbDownMaxHeight = 3.2f; - public float climbDownMinHeight = 1.5f; - public float edgeJumpEndDistance = 2f; - public float edgeJumpHeight = 0.4f; - public float edgeJumpDownMaxHeight = 2.5f; - public float edgeJumpUpMaxHeight = 0.3f; - public int buildTypes = JumpLinkType.EDGE_CLIMB_DOWN.Bit | JumpLinkType.EDGE_JUMP.Bit; -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 181e503..6ae9edd 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -5,6 +5,7 @@ using DotRecast.Detour; using DotRecast.Detour.QueryResults; using DotRecast.Recast.DemoTool.Builder; using DotRecast.Recast.Demo.Draw; +using DotRecast.Recast.DemoTool; using ImGuiNET; using static DotRecast.Core.RcMath; using static DotRecast.Recast.Demo.Draw.DebugDraw; diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshToolMode.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshToolMode.cs deleted file mode 100644 index 71bc62d..0000000 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshToolMode.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections.Immutable; - -namespace DotRecast.Recast.Demo.Tools; - -public class TestNavmeshToolMode -{ - public static readonly TestNavmeshToolMode PATHFIND_FOLLOW = new(0, "Pathfind Follow"); - public static readonly TestNavmeshToolMode PATHFIND_STRAIGHT = new(1, "Pathfind Straight"); - public static readonly TestNavmeshToolMode PATHFIND_SLICED = new(2, "Pathfind Sliced"); - public static readonly TestNavmeshToolMode DISTANCE_TO_WALL = new(3, "Distance to Wall"); - public static readonly TestNavmeshToolMode RAYCAST = new(4, "Raycast"); - public static readonly TestNavmeshToolMode FIND_POLYS_IN_CIRCLE = new(5, "Find Polys in Circle"); - public static readonly TestNavmeshToolMode FIND_POLYS_IN_SHAPE = new(6, "Find Polys in Shape"); - public static readonly TestNavmeshToolMode FIND_LOCAL_NEIGHBOURHOOD = new(7, "Find Local Neighbourhood"); - public static readonly TestNavmeshToolMode RANDOM_POINTS_IN_CIRCLE = new(8, "Random Points in Circle"); - - public static readonly ImmutableArray Values = ImmutableArray.Create( - PATHFIND_FOLLOW, - PATHFIND_STRAIGHT, - PATHFIND_SLICED, - DISTANCE_TO_WALL, - RAYCAST, - FIND_POLYS_IN_CIRCLE, - FIND_POLYS_IN_SHAPE, - FIND_LOCAL_NEIGHBOURHOOD, - RANDOM_POINTS_IN_CIRCLE - ); - - - public int Idx { get; } - public string Label { get; } - - private TestNavmeshToolMode(int idx, string label) - { - Idx = idx; - Label = label; - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/Tool.cs b/src/DotRecast.Recast.Demo/Tools/Tool.cs index a1fdbe8..be8078f 100644 --- a/src/DotRecast.Recast.Demo/Tools/Tool.cs +++ b/src/DotRecast.Recast.Demo/Tools/Tool.cs @@ -26,6 +26,9 @@ namespace DotRecast.Recast.Demo.Tools; public abstract class Tool { + public abstract string GetName(); + public abstract void Layout(); + public abstract void SetSample(Sample m_sample); public abstract void HandleClick(RcVec3f s, RcVec3f p, bool shift); @@ -34,10 +37,6 @@ public abstract class Tool public abstract void HandleUpdate(float dt); - public abstract void Layout(); - - public abstract string GetName(); - public virtual void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) { // ... diff --git a/src/DotRecast.Recast.DemoTool/CrowdAgentData.cs b/src/DotRecast.Recast.DemoTool/CrowdAgentData.cs new file mode 100644 index 0000000..019784d --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/CrowdAgentData.cs @@ -0,0 +1,16 @@ +using DotRecast.Core; + +namespace DotRecast.Recast.DemoTool +{ + public class CrowdAgentData + { + public readonly CrowdAgentType type; + public readonly RcVec3f home = new RcVec3f(); + + public CrowdAgentData(CrowdAgentType type, RcVec3f home) + { + this.type = type; + this.home = home; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/CrowdAgentTrail.cs b/src/DotRecast.Recast.DemoTool/CrowdAgentTrail.cs new file mode 100644 index 0000000..b06bb37 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/CrowdAgentTrail.cs @@ -0,0 +1,9 @@ +namespace DotRecast.Recast.DemoTool +{ + public class CrowdAgentTrail + { + public const int AGENT_MAX_TRAIL = 64; + public float[] trail = new float[AGENT_MAX_TRAIL * 3]; + public int htrail; + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/CrowdAgentType.cs b/src/DotRecast.Recast.DemoTool/CrowdAgentType.cs new file mode 100644 index 0000000..9a81600 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/CrowdAgentType.cs @@ -0,0 +1,9 @@ +namespace DotRecast.Recast.DemoTool +{ + public enum CrowdAgentType + { + VILLAGER, + TRAVELLER, + MOB, + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/CrowdToolMode.cs b/src/DotRecast.Recast.DemoTool/CrowdToolMode.cs new file mode 100644 index 0000000..1296ccd --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/CrowdToolMode.cs @@ -0,0 +1,30 @@ +using System.Collections.Immutable; + +namespace DotRecast.Recast.DemoTool +{ + public class CrowdToolMode + { + public static readonly CrowdToolMode CREATE = new CrowdToolMode(0, "Create Agents"); + public static readonly CrowdToolMode MOVE_TARGET = new CrowdToolMode(1, "Move Target"); + public static readonly CrowdToolMode SELECT = new CrowdToolMode(2, "Select Agent"); + public static readonly CrowdToolMode TOGGLE_POLYS = new CrowdToolMode(3, "Toggle Polys"); + public static readonly CrowdToolMode PROFILING = new CrowdToolMode(4, "Profiling"); + + public static readonly ImmutableArray Values = ImmutableArray.Create( + CREATE, + MOVE_TARGET, + SELECT, + TOGGLE_POLYS, + PROFILING + ); + + public int Idx { get; } + public string Label { get; } + + private CrowdToolMode(int idx, string label) + { + Idx = idx; + Label = label; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/CrowdToolParams.cs b/src/DotRecast.Recast.DemoTool/CrowdToolParams.cs new file mode 100644 index 0000000..2e04e14 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/CrowdToolParams.cs @@ -0,0 +1,47 @@ +/* +recast4j copyright (c) 2020-2021 Piotr Piastucki piotr@jtilia.org + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +namespace DotRecast.Recast.DemoTool +{ + 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; + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/DemoObjImporter.cs b/src/DotRecast.Recast.DemoTool/DemoObjImporter.cs new file mode 100644 index 0000000..36152bf --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/DemoObjImporter.cs @@ -0,0 +1,15 @@ +using System; +using System.IO; +using DotRecast.Recast.DemoTool.Geom; + +namespace DotRecast.Recast.DemoTool +{ + public static class DemoObjImporter + { + public static DemoInputGeomProvider Load(byte[] chunk) + { + var context = ObjImporter.LoadContext(chunk); + return new DemoInputGeomProvider(context.vertexPositions, context.meshFaces); + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/DynamicUpdateToolMode.cs b/src/DotRecast.Recast.DemoTool/DynamicUpdateToolMode.cs new file mode 100644 index 0000000..0b7e9cf --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/DynamicUpdateToolMode.cs @@ -0,0 +1,24 @@ +using System.Collections.Immutable; + +namespace DotRecast.Recast.DemoTool +{ + public class DynamicUpdateToolMode + { + public static readonly DynamicUpdateToolMode BUILD = new DynamicUpdateToolMode(0, "Build"); + public static readonly DynamicUpdateToolMode COLLIDERS = new DynamicUpdateToolMode(1, "Colliders"); + public static readonly DynamicUpdateToolMode RAYCAST = new DynamicUpdateToolMode(2, "Raycast"); + + public static readonly ImmutableArray Values = ImmutableArray.Create( + BUILD, COLLIDERS, RAYCAST + ); + + public int Idx { get; } + public string Label { get; } + + private DynamicUpdateToolMode(int idx, string label) + { + Idx = idx; + Label = label; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/JumpLinkBuilderToolParams.cs b/src/DotRecast.Recast.DemoTool/JumpLinkBuilderToolParams.cs new file mode 100644 index 0000000..5277dc8 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/JumpLinkBuilderToolParams.cs @@ -0,0 +1,44 @@ +/* +recast4j copyright (c) 2020-2021 Piotr Piastucki piotr@jtilia.org + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +using DotRecast.Detour.Extras.Jumplink; + +namespace DotRecast.Recast.DemoTool +{ + public class JumpLinkBuilderToolParams + { + public const int DRAW_WALKABLE_SURFACE = 1 << 0; + public const int DRAW_WALKABLE_BORDER = 1 << 1; + public const int DRAW_SELECTED_EDGE = 1 << 2; + public const int DRAW_ANIM_TRAJECTORY = 1 << 3; + public const int DRAW_LAND_SAMPLES = 1 << 4; + public const int DRAW_COLLISION_SLICES = 1 << 5; + public const int DRAW_ANNOTATIONS = 1 << 6; + + public int flags = DRAW_WALKABLE_SURFACE | DRAW_WALKABLE_BORDER | DRAW_SELECTED_EDGE | DRAW_ANIM_TRAJECTORY | DRAW_LAND_SAMPLES | DRAW_ANNOTATIONS; + public float groundTolerance = 0.3f; + public float climbDownDistance = 0.4f; + public float climbDownMaxHeight = 3.2f; + public float climbDownMinHeight = 1.5f; + public float edgeJumpEndDistance = 2f; + public float edgeJumpHeight = 0.4f; + public float edgeJumpDownMaxHeight = 2.5f; + public float edgeJumpUpMaxHeight = 0.3f; + public int buildTypes = JumpLinkType.EDGE_CLIMB_DOWN.Bit | JumpLinkType.EDGE_JUMP.Bit; + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/TestNavmeshToolMode.cs b/src/DotRecast.Recast.DemoTool/TestNavmeshToolMode.cs new file mode 100644 index 0000000..e2efb23 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/TestNavmeshToolMode.cs @@ -0,0 +1,39 @@ +using System.Collections.Immutable; + +namespace DotRecast.Recast.DemoTool +{ + public class TestNavmeshToolMode + { + public static readonly TestNavmeshToolMode PATHFIND_FOLLOW = new TestNavmeshToolMode(0, "Pathfind Follow"); + public static readonly TestNavmeshToolMode PATHFIND_STRAIGHT = new TestNavmeshToolMode(1, "Pathfind Straight"); + public static readonly TestNavmeshToolMode PATHFIND_SLICED = new TestNavmeshToolMode(2, "Pathfind Sliced"); + public static readonly TestNavmeshToolMode DISTANCE_TO_WALL = new TestNavmeshToolMode(3, "Distance to Wall"); + public static readonly TestNavmeshToolMode RAYCAST = new TestNavmeshToolMode(4, "Raycast"); + public static readonly TestNavmeshToolMode FIND_POLYS_IN_CIRCLE = new TestNavmeshToolMode(5, "Find Polys in Circle"); + public static readonly TestNavmeshToolMode FIND_POLYS_IN_SHAPE = new TestNavmeshToolMode(6, "Find Polys in Shape"); + public static readonly TestNavmeshToolMode FIND_LOCAL_NEIGHBOURHOOD = new TestNavmeshToolMode(7, "Find Local Neighbourhood"); + public static readonly TestNavmeshToolMode RANDOM_POINTS_IN_CIRCLE = new TestNavmeshToolMode(8, "Random Points in Circle"); + + public static readonly ImmutableArray Values = ImmutableArray.Create( + PATHFIND_FOLLOW, + PATHFIND_STRAIGHT, + PATHFIND_SLICED, + DISTANCE_TO_WALL, + RAYCAST, + FIND_POLYS_IN_CIRCLE, + FIND_POLYS_IN_SHAPE, + FIND_LOCAL_NEIGHBOURHOOD, + RANDOM_POINTS_IN_CIRCLE + ); + + + public int Idx { get; } + public string Label { get; } + + private TestNavmeshToolMode(int idx, string label) + { + Idx = idx; + Label = label; + } + } +} \ No newline at end of file